forked from DuinOS/DuinOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
howto-new-duinos-release.txt
677 lines (578 loc) · 22.7 KB
/
howto-new-duinos-release.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
How to create a new DuinOS release by updating FreeRTOS and Arduino IDE parts.
Tested by upgrading DuinOS 0.2 to DuinOS 0.3 with
* upgrade Arduino IDE from 0018 to 0021
* upgrade FreeRTOS 6.0.5 to 6.1.0
1) Create the DuinOS_v0.X folder where is a number that is one step upper than the latest DuinOS release available.
2) Create the DuinOS_v0.X/arduino.DuinOS/DuinOS folder where there are all the files from FreeRTOS.
Now, you need to copy the following files in the folder that you have created :
a) from FreeRTOSVx.x.x/Source/
croutine.c
list.c
queue.c
tasks.c
b) from FreeRTOSVx.x.x/Source/include/
croutine.h
FreeRTOS.h
list.h
mpu_wrappers.h
portable.h
projdefs.h
queue.h
semphr.h
StackMacros.h
task.h
c) from FreeRTOSVx.x.x/Source/portable/MemMang/
heap_1.c
heap_2.c
heap_3.c
c) from FreeRTOSVx.x.x/Source/portable/GCC/ATMega323/
port.c
portmacro.h
port.c (file updated to add support for Atmel AtMega chips
3) Now you need to patch DuinOS_v0.X/arduino.DuinOS/DuinOS/port.c with the following patch :
--- port.c.ORI 2010-09-23 16:44:44.000000000 +0200
+++ port.c 2010-12-18 17:01:34.000000000 +0100
@@ -53,6 +53,19 @@
/*
+Changes from FreeRTOS 5.4.2
+
+ + AVR port - Adapted ATmega323 port to the AT90USB USB AVRs
+
+FreeRTOS developper team rename variables from portCHAR to char, portLONG to long, portSHORT to short.
+But (I think) we need to keep port* variables because there are used in the file FreeRTOSConfig.h that add support for
+Atmel AVR ATmega644, ATmega644P, ATmega1284P, AVR_ATmega1280, AVR_ATmega328P, ATmega88, ATmega88P, ATmega168, ATmega168P
+You can find information about adding support for Atmel AVR chips in Arduino Card in FreeRTOS here :
+http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=574737&sid=0d73d27555a0fd91faca37b6beee924e#574737
+
+
+/*
+
Changes from V2.6.0
+ AVR port - Replaced the inb() and outb() functions with direct memory
@@ -74,10 +87,15 @@
#define portFLAGS_INT_ENABLED ( ( portSTACK_TYPE ) 0x80 )
/* Hardware constants for timer 1. */
+/* Disable hardware constants for Atmel AVR ATmega323
#define portCLEAR_COUNTER_ON_MATCH ( ( unsigned char ) 0x08 )
#define portPRESCALE_64 ( ( unsigned char ) 0x03 )
#define portCLOCK_PRESCALER ( ( unsigned long ) 64 )
#define portCOMPARE_MATCH_A_INTERRUPT_ENABLE ( ( unsigned char ) 0x10 )
+/*
+/* Enable hardware constants for Atmel AVR ATmega644, ATmega644P, ATmega1284P, AVR_ATmega1280, AVR_ATmega328P, ATmega88, ATmega88P, ATmega168, ATmega168P */
+#define portCLEAR_COUNTER_ON_MATCH ( (unsigned portCHAR)(1 << WGM12) ) /* remove portCLEAR_COUNTER_ON_MATCH because it is not used in timer ? */
+#define portCLOCK_PRESCALER ( (unsigned portLONG) 64 )
/*-----------------------------------------------------------*/
@@ -210,7 +228,9 @@
*/
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
{
-unsigned short usAddress;
+/* Disable for Atmel AVR ATmega323
+ unsigned short usAddress; */
+ unsigned portSHORT usAddress;
/* Place a few bytes of known values on the bottom of the stack.
This is just useful for debugging. */
@@ -229,12 +249,17 @@
/* The start of the task code will be popped off the stack last, so place
it on first. */
+ /* Disable for Atmel AVR ATmega323
usAddress = ( unsigned short ) pxCode;
- *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned short ) 0x00ff );
+ *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned short ) 0x00ff ); */
+ usAddress = ( unsigned portSHORT ) pxCode;
+ *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff );
pxTopOfStack--;
usAddress >>= 8;
- *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned short ) 0x00ff );
+ /* Disable for Atmel AVR ATmega323
+ *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned short ) 0x00ff ); */
+ *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff );
pxTopOfStack--;
/* Next simulate the stack as if after a call to portSAVE_CONTEXT().
@@ -296,12 +321,17 @@
pxTopOfStack--;
/* Place the parameter on the stack in the expected location. */
+ /* Disable for Atmel AVR ATmega323
usAddress = ( unsigned short ) pvParameters;
- *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned short ) 0x00ff );
+ *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned short ) 0x00ff ); */
+ usAddress = ( unsigned portSHORT ) pvParameters;
+ *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff );
pxTopOfStack--;
usAddress >>= 8;
- *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned short ) 0x00ff );
+ /* Disable for Atmel AVR ATmega323
+ *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned short ) 0x00ff ); */
+ *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff );
pxTopOfStack--;
*pxTopOfStack = ( portSTACK_TYPE ) 0x26; /* R26 X */
@@ -385,8 +415,11 @@
*/
static void prvSetupTimerInterrupt( void )
{
+/* Disable for Atmel AVR ATmega323
unsigned long ulCompareMatch;
-unsigned char ucHighByte, ucLowByte;
+unsigned char ucHighByte, ucLowByte; */
+unsigned portLONG ulCompareMatch;
+
/* Using 16bit timer 1 to generate the tick. Correct fuses must be
selected for the configCPU_CLOCK_HZ clock. */
@@ -397,25 +430,35 @@
ulCompareMatch /= portCLOCK_PRESCALER;
/* Adjust for correct value. */
- ulCompareMatch -= ( unsigned long ) 1;
+ /* Disable for Atmel AVR ATmega323
+ ulCompareMatch -= ( unsigned long ) 1; */
+ ulCompareMatch -= ( unsigned portLONG ) 1;
/* Setup compare match value for compare match A. Interrupts are disabled
before this is called so we need not worry here. */
+ /* Disable for Atmel AVR ATmega323
ucLowByte = ( unsigned char ) ( ulCompareMatch & ( unsigned long ) 0xff );
ulCompareMatch >>= 8;
ucHighByte = ( unsigned char ) ( ulCompareMatch & ( unsigned long ) 0xff );
OCR1AH = ucHighByte;
- OCR1AL = ucLowByte;
+ OCR1AL = ucLowByte; */
+ OCR1A = ulCompareMatch;
/* Setup clock source and compare match behaviour. */
+ /* Disable for Atmel AVR ATmega323
ucLowByte = portCLEAR_COUNTER_ON_MATCH | portPRESCALE_64;
- TCCR1B = ucLowByte;
+ TCCR1B = ucLowByte; */
+ TCCR1A = 0;
+ // CS10 and CS11 will set a prescale value of 64
+ TCCR1B = ((1 << CS10) | (1 << CS11) | (1 << WGM12));
/* Enable the interrupt - this is okay as interrupt are currently globally
disabled. */
+ /* Disable for Atmel AVR ATmega323
ucLowByte = TIMSK;
ucLowByte |= portCOMPARE_MATCH_A_INTERRUPT_ENABLE;
- TIMSK = ucLowByte;
+ TIMSK = ucLowByte; */
+ TIMSK1 = (1 << OCIE1A);
}
/*-----------------------------------------------------------*/
@@ -426,8 +469,11 @@
* the context is saved at the start of vPortYieldFromTick(). The tick
* count is incremented after the context is saved.
*/
+ /* Disable for Atmel AVR ATmega323
void SIG_OUTPUT_COMPARE1A( void ) __attribute__ ( ( signal, naked ) );
- void SIG_OUTPUT_COMPARE1A( void )
+ void SIG_OUTPUT_COMPARE1A( void ) */
+ void TIMER1_COMPA_vect( void ) __attribute__ ( ( signal, naked ) );
+ void TIMER1_COMPA_vect( void )
{
vPortYieldFromTick();
asm volatile ( "reti" );
@@ -439,8 +485,11 @@
* tick count. We don't need to switch context, this can only be done by
* manual calls to taskYIELD();
*/
+ /* Disable for Atmel AVR ATmega323
void SIG_OUTPUT_COMPARE1A( void ) __attribute__ ( ( signal ) );
- void SIG_OUTPUT_COMPARE1A( void )
+ void SIG_OUTPUT_COMPARE1A( void ) */
+ void TIMER1_COMPA_vect( void ) __attribute__ ( ( signal ) );
+ void TIMER1_COMPA_vect( void )
{
vTaskIncrementTick();
}
4) In the DuinOS_v0.X/arduino.DuinOS folder, you need to copy the following files :
a) from arduino-00xx/hardware/arduino/cores/arduino/ (with no changes)
binary.h
HardwareSerial.cpp
HardwareSerial.h
pins_arduino.c
pins_arduino.h
Print.cpp
Print.h
Stream.h
Tone.cpp
WConstants.h
wiring_digital.c
wiring_private.h
wiring_pulse.c
wiring_shift.c
WInterrupts.c
WMath.cpp
WString.cpp
WString.h
5) Patch the following files from arduino-00xx/hardware/arduino/cores/arduino/ and copy them in DuinOS_v0.X/arduino.DuinOS folder
* wiring.c / disable delay function because DuinOS overrides this function with a macro (DuinOS.h) /
disable timer1 configuration because DuinOS overrides this function with a macro (DuinOS.h)
* wiring_analog.c / Because DuinOS uses the timer 1 for its kernel, disable TIMER1A and TIMER1B
* main.cpp / add loading DuinOS.h and several functions
* wiring.h / add conditional load for delay function
* WProgram.h / add loading DuinOS.h
Patchs :
--- wiring_analog.c.ORI 2010-10-02 22:17:42.000000000 +0200
+++ wiring_analog.c 2010-12-18 18:05:06.000000000 +0100
@@ -88,15 +88,19 @@
pinMode(pin, OUTPUT);
if (digitalPinToTimer(pin) == TIMER1A) {
+ /* Because DuinOS uses the timer 1 for its kernel, disable this part:
// connect pwm to pin on timer 1, channel A
sbi(TCCR1A, COM1A1);
// set pwm duty
OCR1A = val;
+ */
} else if (digitalPinToTimer(pin) == TIMER1B) {
+ /* Because DuinOS uses the timer 1 for its kernel, disable this part:
// connect pwm to pin on timer 1, channel B
sbi(TCCR1A, COM1B1);
// set pwm duty
OCR1B = val;
+ */
#if defined(__AVR_ATmega8__)
} else if (digitalPinToTimer(pin) == TIMER2) {
// connect pwm to pin on timer 2, channel B
--- wiring.c.ORI 2010-10-02 22:17:42.000000000 +0200
+++ wiring.c 2010-12-18 18:21:13.000000000 +0100
@@ -95,7 +95,8 @@
return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond());
}
-void delay(unsigned long ms)
+// DuinOS overrides this function with a macro (DuinOS.h)
+/* void delay(unsigned long ms)
{
uint16_t start = (uint16_t)micros();
@@ -106,6 +107,7 @@
}
}
}
+*/
/* Delay for the given number of microseconds. Assumes a 8 or 16 MHz clock. */
void delayMicroseconds(unsigned int us)
@@ -190,13 +192,16 @@
// note, however, that fast pwm mode can achieve a frequency of up
// 8 MHz (with a 16 MHz clock) at 50% duty cycle
- TCCR1B = 0;
+ // DuinOS: This commented code is the only difference with the standard init() function
+ // (DuinOS uses the timer 1 for the preemptive kernel):
+ /* TCCR1B = 0;
// set timer 1 prescale factor to 64
sbi(TCCR1B, CS11);
sbi(TCCR1B, CS10);
// put timer 1 in 8-bit phase correct pwm mode
- sbi(TCCR1A, WGM10);
+ sbi(TCCR1A, WGM10); */
+
// set timer 2 prescale factor to 64
#if defined(__AVR_ATmega8__)
--- wiring.h.ORI 2010-10-02 22:17:42.000000000 +0200
+++ wiring.h 2010-12-18 18:40:18.000000000 +0100
@@ -114,7 +114,12 @@
unsigned long millis(void);
unsigned long micros(void);
+
+#ifndef DuinOS__h
+// DuinOS overrides this:
void delay(unsigned long);
+#endif
+
void delayMicroseconds(unsigned int us);
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
--- WProgram.h.ORI 2010-10-02 22:17:42.000000000 +0200
+++ WProgram.h 2010-12-18 18:46:07.000000000 +0100
@@ -9,6 +9,9 @@
#include "wiring.h"
+// DuinOS is include here, because it's part of the core:
+#include "DuinOS.h"
+
#ifdef __cplusplus
#include "WString.h"
#include "HardwareSerial.h"
--- main.cpp.ORI 2010-10-02 22:17:42.000000000 +0200
+++ main.cpp 2010-12-18 18:53:06.000000000 +0100
@@ -1,14 +1,29 @@
-#include <WProgram.h>
-
-int main(void)
-{
- init();
-
- setup();
-
- for (;;)
- loop();
-
- return 0;
-}
-
+#include <WProgram.h>
+// add DuinOS support
+#include "DuinOS.h"
+
+unsigned portBASE_TYPE mainLoopPriority;
+
+void main_Task(void *pvParameters)
+{
+ for(;;)
+ loop();
+}
+
+
+int main(void)
+{
+ //This is made prior to setup(), so this priority could be changed in setup():
+ mainLoopPriority = LOW_PRIORITY;
+
+ init();
+ setup();
+
+ xTaskCreate(main_Task, (signed portCHAR *) "main", configMINIMAL_STACK_SIZE, NULL, mainLoopPriority, NULL);
+ vTaskStartScheduler();
+
+ //Will not get here unless a task calls vTaskEndScheduler():
+ for (;;);
+
+ return 0;
+}
6) Get the following files in a previous DuinOS release :
DuinOS.h
FreeRTOSConfig.h
and copy them in DuinOS_v0.X/arduino.DuinOS folder.
7) Copy the folder DuinOS_v0.x/examples/ from a previous release to the new DuinOS release in DuinOS_v0.x/examples/
8) Copy arduino-00xx/hardware/arduino/board.txt in DuinOS_v0.x/hardware folder and patch it with the following patch :
--- boards.txt.ORI 2010-10-02 22:17:42.000000000 +0200
+++ boards.txt 2010-12-18 19:23:23.000000000 +0100
@@ -37,6 +37,26 @@
##############################################################
+atmega328_DuinOS.name=Arduino Duemilanove or Nano w/ ATmega328 + DuinOS
+
+atmega328_DuinOS.upload.protocol=stk500
+atmega328_DuinOS.upload.maximum_size=30720
+atmega328_DuinOS.upload.speed=57600
+
+atmega328_DuinOS.bootloader.low_fuses=0xFF
+atmega328_DuinOS.bootloader.high_fuses=0xDA
+atmega328_DuinOS.bootloader.extended_fuses=0x05
+atmega328_DuinOS.bootloader.path=atmega
+atmega328_DuinOS.bootloader.file=ATmegaBOOT_168_atmega328.hex
+atmega328_DuinOS.bootloader.unlock_bits=0x3F
+atmega328_DuinOS.bootloader.lock_bits=0x0F
+
+atmega328_DuinOS.build.mcu=atmega328p
+atmega328_DuinOS.build.f_cpu=16000000L
+atmega328_DuinOS.build.core=arduino.DuinOS
+
+##############################################################
+
diecimila.name=Arduino Diecimila, Duemilanove, or Nano w/ ATmega168
diecimila.upload.protocol=stk500
@@ -57,6 +77,26 @@
##############################################################
+diecimila_DuinOS.name=Arduino Diecimila, Duemilanove, or Nano w/ ATmega168 + DuinOS
+
+diecimila_DuinOS.upload.protocol=stk500
+diecimila_DuinOS.upload.maximum_size=14336
+diecimila_DuinOS.upload.speed=19200
+
+diecimila_DuinOS.bootloader.low_fuses=0xff
+diecimila_DuinOS.bootloader.high_fuses=0xdd
+diecimila_DuinOS.bootloader.extended_fuses=0x00
+diecimila_DuinOS.bootloader.path=atmega
+diecimila_DuinOS.bootloader.file=ATmegaBOOT_168_diecimila.hex
+diecimila_DuinOS.bootloader.unlock_bits=0x3F
+diecimila_DuinOS.bootloader.lock_bits=0x0F
+
+diecimila_DuinOS.build.mcu=atmega168
+diecimila_DuinOS.build.f_cpu=16000000L
+diecimila_DuinOS.build.core=arduino.DuinOS
+
+##############################################################
+
mega2560.name=Arduino Mega 2560
mega2560.upload.protocol=stk500v2
@@ -97,6 +137,26 @@
##############################################################
+mega_DuinOS.name=Arduino Mega (ATmega1280) + DuinOS
+
+mega_DuinOS.upload.protocol=stk500
+mega_DuinOS.upload.maximum_size=126976
+mega_DuinOS.upload.speed=57600
+
+mega_DuinOS.bootloader.low_fuses=0xFF
+mega_DuinOS.bootloader.high_fuses=0xDA
+mega_DuinOS.bootloader.extended_fuses=0xF5
+mega_DuinOS.bootloader.path=atmega
+mega_DuinOS.bootloader.file=ATmegaBOOT_168_atmega1280.hex
+mega_DuinOS.bootloader.unlock_bits=0x3F
+mega_DuinOS.bootloader.lock_bits=0x0F
+
+mega_DuinOS.build.mcu=atmega1280
+mega_DuinOS.build.f_cpu=16000000L
+mega_DuinOS.build.core=arduino.DuinOS
+
+##############################################################
+
mini.name=Arduino Mini
mini.upload.protocol=stk500
9) Copy arduino-00xx/lib/keywords.txt in DuinOS_v0.x/lib folder and patch it with the following patch :
--- keywords.txt.ORI 2010-10-02 22:17:42.000000000 +0200
+++ keywords.txt 2010-12-18 19:35:55.000000000 +0100
@@ -4,6 +4,8 @@
LOW LITERAL1 Constants
INPUT LITERAL1 Constants
OUTPUT LITERAL1 Constants
+SERIAL LITERAL1
+DISPLAY LITERAL1
DEC LITERAL1 Serial_Print
BIN LITERAL1 Serial_Print
HEX LITERAL1 Serial_Print
@@ -176,3 +178,34 @@
setup KEYWORD3 Setup
loop KEYWORD3 Loop
+
+#######################################
+# Syntax Coloring Map DuinOS
+#######################################
+
+#######################################
+# Datatypes (KEYWORD1)
+#######################################
+
+taskLoop KEYWORD1
+
+#######################################
+# Methods and Functions (KEYWORD2)
+#######################################
+declareTaskLoop KEYWORD2
+createTaskLoop KEYWORD2
+suspend KEYWORD2
+suspendTask KEYWORD2
+suspendAll KEYWORD2
+resumeTask KEYWORD2
+resumeAll KEYWORD2
+nextTask KEYWORD2
+initMainLoopPriority KEYWORD2
+
+
+#######################################
+# Constants (LITERAL1)
+#######################################
+LOW_PRIORITY LITERAL1
+NORMAL_PRIORITY LITERAL1
+HIGH_PRIORITY LITERAL1
9) Copy arduino-00xx/libraries/Servo/Servo.h in DuinOS_v0.x/libraries/Servo folder and patch it with the following patch :
Disable Timer1 because DuinOS uses the timer 1 for its kernel in this file
--- Servo.h.ORI 2010-10-02 22:17:42.000000000 +0200
+++ Servo.h 2010-12-20 22:52:10.000000000 +0100
@@ -59,29 +59,38 @@
// Say which 16 bit timers can be used and in what order
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define _useTimer5
-#define _useTimer1
+/* Disable Timer1 because DuinOS uses the timer 1 for its kernel
+#define _useTimer1 */
#define _useTimer3
-#define _useTimer4
-typedef enum { _timer5, _timer1, _timer3, _timer4, _Nbr_16timers } timer16_Sequence_t ;
+#define _useTimer4
+/* Disable Timer1 because DuinOS uses the timer 1 for its kernel
+typedef enum { _timer5, _timer1, _timer3, _timer4, _Nbr_16timers } timer16_Sequence_t ; */
+typedef enum { _timer5, _timer3, _timer4, _Nbr_16timers } timer16_Sequence_t ;
#elif defined(__AVR_ATmega32U4__)
#define _useTimer3
+/* Disable Timer1 because DuinOS uses the timer 1 for its kernel
#define _useTimer1
-typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ;
+typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ; */
+typedef enum { _timer3, _Nbr_16timers } timer16_Sequence_t ;
#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
#define _useTimer3
-#define _useTimer1
-typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ;
+/* Disable Timer1 because DuinOS uses the timer 1 for its kernel
+#define _useTimer1
+typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ; */
+typedef enum { _timer3, _Nbr_16timers } timer16_Sequence_t ;
#elif defined(__AVR_ATmega128__) ||defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__)
#define _useTimer3
+/* Disable Timer1 because DuinOS uses the timer 1 for its kernel
#define _useTimer1
+typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ; */
typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ;
#else // everything else
-#define _useTimer1
-typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;
+/* Disable Timer1 because DuinOS uses the timer 1 for its kernel
+typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ; */
#endif
#define Servo_VERSION 2 // software version of this library
10) Copy arduino-00xx/libraries/Servo/Servo.cpp in DuinOS_v0.x/libraries/Servo folder and patch it with the following patch :
Disable Timer1 because DuinOS uses the timer 1 for its kernel in this file
--- Servo.cpp.ORI 2010-10-02 22:17:42.000000000 +0200
+++ Servo.cpp 2010-12-20 22:57:04.000000000 +0100
@@ -99,12 +99,13 @@
#ifndef WIRING // Wiring pre-defines signal handlers so don't define any if compiling for the Wiring platform
// Interrupt handlers for Arduino
+/* Disable Timer1 because DuinOS uses the timer 1 for its kernel
#if defined(_useTimer1)
SIGNAL (TIMER1_COMPA_vect)
{
handle_interrupts(_timer1, &TCNT1, &OCR1A);
}
-#endif
+#endif */
#if defined(_useTimer3)
SIGNAL (TIMER3_COMPA_vect)
@@ -128,13 +129,15 @@
#endif
#elif defined WIRING
-// Interrupt handlers for Wiring
+// Interrupt handlers for Wiring
+/* Disable Timer1 because DuinOS uses the timer 1 for its kernel
#if defined(_useTimer1)
void Timer1Service()
{
handle_interrupts(_timer1, &TCNT1, &OCR1A);
}
#endif
+*/
#if defined(_useTimer3)
void Timer3Service()
{
@@ -145,7 +148,8 @@
static void initISR(timer16_Sequence_t timer)
-{
+{
+/* Disable Timer1 because DuinOS uses the timer 1 for its kernel
#if defined (_useTimer1)
if(timer == _timer1) {
TCCR1A = 0; // normal counting mode
@@ -163,7 +167,7 @@
timerAttach(TIMER1OUTCOMPAREA_INT, Timer1Service);
#endif
}
-#endif
+#endif */
#if defined (_useTimer3)
if(timer == _timer3) {
@@ -208,6 +212,7 @@
{
//disable use of the given timer
#if defined WIRING // Wiring
+ /* Disable Timer1 because DuinOS uses the timer 1 for its kernel
if(timer == _timer1) {
#if defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__)
TIMSK1 &= ~_BV(OCIE1A) ; // disable timer 1 output compare interrupt
@@ -216,7 +221,8 @@
#endif
timerDetach(TIMER1OUTCOMPAREA_INT);
}
- else if(timer == _timer3) {
+ else if(timer == _timer3) { */
+ if(timer == _timer3) {
#if defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__)
TIMSK3 &= ~_BV(OCIE3A); // disable the timer3 output compare A interrupt
#else
11) Because with some chips as AtMega 168 and 328, Timer1 is disabled because DuinOS uses the timer 1 for its kernel.
and we don't have now a 16 bit timer to use Servo lib that need it.
Then we add ServoTimer2 lib (http://code.google.com/p/tricopter/source/browse/trunk/arduino/#arduino%2Flibraries%2FServoTimer2 )
that use the 8 bits timer 2 for Servo.
Copy the following files from this website
ServoTimer2.cpp, ServoTimer2.h, keywords.txt
in DuinOS_v0.x/libraries/ServoTimer2 folder