Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3703677

Browse files
author
yannick.le.ny.56
committed
replace DuinOS IDE 0018 patched files with DuinOS IDE 0021 patched files
git-svn-id: http://duinos.googlecode.com/svn/trunk@9 542b9b23-42aa-b9a1-add2-148d3e16e5b3
1 parent 241e0d7 commit 3703677

File tree

5 files changed

+76
-33
lines changed

5 files changed

+76
-33
lines changed

arduino.DuinOS/WProgram.h

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99

1010
#include "wiring.h"
1111

12-
// DiunOS is include here, because it's part of the core:
12+
// DuinOS is include here, because it's part of the core:
1313
#include "DuinOS.h"
1414

1515
#ifdef __cplusplus
16+
#include "WString.h"
1617
#include "HardwareSerial.h"
1718

1819
uint16_t makeWord(uint16_t w);
@@ -30,6 +31,35 @@ long random(long);
3031
long random(long, long);
3132
void randomSeed(unsigned int);
3233
long map(long, long, long, long, long);
34+
35+
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
36+
const static uint8_t A0 = 54;
37+
const static uint8_t A1 = 55;
38+
const static uint8_t A2 = 56;
39+
const static uint8_t A3 = 57;
40+
const static uint8_t A4 = 58;
41+
const static uint8_t A5 = 59;
42+
const static uint8_t A6 = 60;
43+
const static uint8_t A7 = 61;
44+
const static uint8_t A8 = 62;
45+
const static uint8_t A9 = 63;
46+
const static uint8_t A10 = 64;
47+
const static uint8_t A11 = 65;
48+
const static uint8_t A12 = 66;
49+
const static uint8_t A13 = 67;
50+
const static uint8_t A14 = 68;
51+
const static uint8_t A15 = 69;
52+
#else
53+
const static uint8_t A0 = 14;
54+
const static uint8_t A1 = 15;
55+
const static uint8_t A2 = 16;
56+
const static uint8_t A3 = 17;
57+
const static uint8_t A4 = 18;
58+
const static uint8_t A5 = 19;
59+
const static uint8_t A6 = 20;
60+
const static uint8_t A7 = 21;
61+
#endif
62+
3363
#endif
3464

3565
#endif

arduino.DuinOS/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <WProgram.h>
2+
// add DuinOS support
23
#include "DuinOS.h"
34

45
unsigned portBASE_TYPE mainLoopPriority;

arduino.DuinOS/wiring.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
2020
Boston, MA 02111-1307 USA
2121
22-
$Id: wiring.c 808 2009-12-18 17:44:08Z dmellis $
22+
$Id$
2323
*/
2424

2525
#include "wiring_private.h"
@@ -96,13 +96,18 @@ unsigned long micros() {
9696
}
9797

9898
// DuinOS overrides this function with a macro (DuinOS.h)
99-
/*void delay(unsigned long ms)
99+
/* void delay(unsigned long ms)
100100
{
101-
unsigned long start = millis();
102-
103-
while (millis() - start <= ms)
104-
;
105-
}*/
101+
uint16_t start = (uint16_t)micros();
102+
103+
while (ms > 0) {
104+
if (((uint16_t)micros() - start) >= 1000) {
105+
ms--;
106+
start += 1000;
107+
}
108+
}
109+
}
110+
*/
106111

107112
/* Delay for the given number of microseconds. Assumes a 8 or 16 MHz clock. */
108113
void delayMicroseconds(unsigned int us)
@@ -182,20 +187,22 @@ void init()
182187
sbi(TIMSK0, TOIE0);
183188
#endif
184189

185-
// DuinOS: This commented code is the only difference with the standard init() function
186-
// (DuinOS uses the timer 1 for the preemptive kernel):
187-
/*
188190
// timers 1 and 2 are used for phase-correct hardware pwm
189191
// this is better for motors as it ensures an even waveform
190192
// note, however, that fast pwm mode can achieve a frequency of up
191193
// 8 MHz (with a 16 MHz clock) at 50% duty cycle
194+
195+
// DuinOS: This commented code is the only difference with the standard init() function
196+
// (DuinOS uses the timer 1 for the preemptive kernel):
197+
/* TCCR1B = 0;
192198
193199
// set timer 1 prescale factor to 64
194200
sbi(TCCR1B, CS11);
195201
sbi(TCCR1B, CS10);
196202
// put timer 1 in 8-bit phase correct pwm mode
197-
sbi(TCCR1A, WGM10);
198-
*/
203+
sbi(TCCR1A, WGM10); */
204+
205+
199206
// set timer 2 prescale factor to 64
200207
#if defined(__AVR_ATmega8__)
201208
sbi(TCCR2, CS22);
@@ -209,7 +216,7 @@ void init()
209216
sbi(TCCR2A, WGM20);
210217
#endif
211218

212-
#if defined(__AVR_ATmega1280__)
219+
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
213220
// set timer 3, 4, 5 prescale factor to 64
214221
sbi(TCCR3B, CS31); sbi(TCCR3B, CS30);
215222
sbi(TCCR4B, CS41); sbi(TCCR4B, CS40);

arduino.DuinOS/wiring.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
2020
Boston, MA 02111-1307 USA
2121
22-
$Id: wiring.h 804 2009-12-18 16:05:52Z dmellis $
22+
$Id$
2323
*/
2424

2525
#ifndef Wiring_h
2626
#define Wiring_h
2727

2828
#include <avr/io.h>
29+
#include <stdlib.h>
2930
#include "binary.h"
3031

3132
#ifdef __cplusplus
@@ -57,7 +58,12 @@ extern "C"{
5758
#define FALLING 2
5859
#define RISING 3
5960

61+
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
62+
#define INTERNAL1V1 2
63+
#define INTERNAL2V56 3
64+
#else
6065
#define INTERNAL 3
66+
#endif
6167
#define DEFAULT 1
6268
#define EXTERNAL 0
6369

@@ -106,12 +112,6 @@ int analogRead(uint8_t);
106112
void analogReference(uint8_t mode);
107113
void analogWrite(uint8_t, int);
108114

109-
void beginSerial(long);
110-
void serialWrite(unsigned char);
111-
int serialAvailable(void);
112-
int serialRead(void);
113-
void serialFlush(void);
114-
115115
unsigned long millis(void);
116116
unsigned long micros(void);
117117

@@ -123,7 +123,8 @@ void delay(unsigned long);
123123
void delayMicroseconds(unsigned int us);
124124
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
125125

126-
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val);
126+
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
127+
uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
127128

128129
void attachInterrupt(uint8_t, void (*)(void), int mode);
129130
void detachInterrupt(uint8_t);

arduino.DuinOS/wiring_analog.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,20 @@ int analogRead(uint8_t pin)
3939
{
4040
uint8_t low, high;
4141

42-
// set the analog reference (high two bits of ADMUX) and select the
43-
// channel (low 4 bits). this also sets ADLAR (left-adjust result)
44-
// to 0 (the default).
45-
ADMUX = (analog_reference << 6) | (pin & 0x07);
46-
47-
#if defined(__AVR_ATmega1280__)
42+
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
43+
if (pin >= 54) pin -= 54; // allow for channel or pin numbers
44+
4845
// the MUX5 bit of ADCSRB selects whether we're reading from channels
4946
// 0 to 7 (MUX5 low) or 8 to 15 (MUX5 high).
5047
ADCSRB = (ADCSRB & ~(1 << MUX5)) | (((pin >> 3) & 0x01) << MUX5);
48+
#else
49+
if (pin >= 14) pin -= 14; // allow for channel or pin numbers
5150
#endif
51+
52+
// set the analog reference (high two bits of ADMUX) and select the
53+
// channel (low 4 bits). this also sets ADLAR (left-adjust result)
54+
// to 0 (the default).
55+
ADMUX = (analog_reference << 6) | (pin & 0x07);
5256

5357
// without a delay, we seem to read from the wrong channel
5458
//delay(1);
@@ -84,19 +88,19 @@ void analogWrite(uint8_t pin, int val)
8488
pinMode(pin, OUTPUT);
8589

8690
if (digitalPinToTimer(pin) == TIMER1A) {
87-
/* DuinOS uses the timer 1 for its kernel:
91+
/* Because DuinOS uses the timer 1 for its kernel, disable this part:
8892
// connect pwm to pin on timer 1, channel A
8993
sbi(TCCR1A, COM1A1);
9094
// set pwm duty
9195
OCR1A = val;
92-
*/
96+
*/
9397
} else if (digitalPinToTimer(pin) == TIMER1B) {
94-
/* DuinOS uses the timer 1 for its kernel:
98+
/* Because DuinOS uses the timer 1 for its kernel, disable this part:
9599
// connect pwm to pin on timer 1, channel B
96100
sbi(TCCR1A, COM1B1);
97101
// set pwm duty
98102
OCR1B = val;
99-
*/
103+
*/
100104
#if defined(__AVR_ATmega8__)
101105
} else if (digitalPinToTimer(pin) == TIMER2) {
102106
// connect pwm to pin on timer 2, channel B
@@ -133,7 +137,7 @@ void analogWrite(uint8_t pin, int val)
133137
// set pwm duty
134138
OCR2B = val;
135139
#endif
136-
#if defined(__AVR_ATmega1280__)
140+
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
137141
// XXX: need to handle other timers here
138142
} else if (digitalPinToTimer(pin) == TIMER3A) {
139143
// connect pwm to pin on timer 3, channel A

0 commit comments

Comments
 (0)