├── .gitignore ├── arduino.DuinOS ├── WConstants.h ├── main.cpp ├── WProgram.h ├── wiring_shift.c ├── WMath.cpp ├── wiring_private.h ├── Print.h ├── HardwareSerial.h ├── DuinOS.h ├── wiring_pulse.c ├── DuinOS │ ├── projdefs.h │ ├── portmacro.h │ ├── heap_3.c │ ├── heap_1.c │ ├── list.c │ ├── StackMacros.h │ ├── portable.h │ ├── heap_2.c │ ├── list.h │ └── FreeRTOS.h ├── pins_arduino.h ├── wiring_digital.c ├── wiring.h ├── Print.cpp ├── WInterrupts.c ├── wiring_analog.c ├── HardwareSerial.cpp ├── wiring.c ├── FreeRTOSConfig.h ├── binary.h └── pins_arduino.c ├── Leeme.txt ├── Readme.txt ├── Readme-rsanders.txt ├── ide ├── duinos_boards.txt ├── keywords.txt └── boards.txt ├── examples └── MoreComplexBlinking │ └── MoreComplexBlinking.pde └── hardware └── boards.txt /.gitignore: -------------------------------------------------------------------------------- 1 | tmp 2 | -------------------------------------------------------------------------------- /arduino.DuinOS/WConstants.h: -------------------------------------------------------------------------------- 1 | #include "wiring.h" 2 | -------------------------------------------------------------------------------- /Leeme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsanders/DuinOS/HEAD/Leeme.txt -------------------------------------------------------------------------------- /Readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsanders/DuinOS/HEAD/Readme.txt -------------------------------------------------------------------------------- /Readme-rsanders.txt: -------------------------------------------------------------------------------- 1 | This repo was based upon the v0.1alpha distribution of DuinOS, with some small patches 2 | to make the demo program compile and run under the Arduino 0018 environment. 3 | 4 | Robert Sanders 5 | robert@curioussquid.com 6 | 2010-02-01 7 | 8 | References: 9 | 10 | See http://github.com/rsanders/DuinOS for my Git repository. 11 | See http://www.multiplo.org/duinos/wiki/index.php for the original DuinOS distribution. 12 | See http://freertos.org/ for the RTOS upon which DuinOS is based. 13 | -------------------------------------------------------------------------------- /arduino.DuinOS/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "DuinOS.h" 4 | 5 | unsigned portBASE_TYPE mainLoopPriority; 6 | 7 | void main_Task(void *pvParameters) 8 | { 9 | for(;;) 10 | loop(); 11 | } 12 | 13 | 14 | int main(void) 15 | { 16 | //This is made prior to setup(), so this priority could be changed in setup(): 17 | mainLoopPriority = LOW_PRIORITY; 18 | 19 | init(); 20 | setup(); 21 | 22 | xTaskCreate(main_Task, (signed portCHAR *) "main", configMINIMAL_STACK_SIZE, NULL, mainLoopPriority, NULL); 23 | vTaskStartScheduler(); 24 | 25 | //Will not get here unless a task calls vTaskEndScheduler(): 26 | for (;;); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /arduino.DuinOS/WProgram.h: -------------------------------------------------------------------------------- 1 | #ifndef WProgram_h 2 | #define WProgram_h 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include "wiring.h" 11 | 12 | //##DiunOS is include here, because it's part of the core: 13 | #include "DuinOS.h" 14 | 15 | #ifdef __cplusplus 16 | #include "HardwareSerial.h" 17 | 18 | uint16_t makeWord(uint16_t w); 19 | uint16_t makeWord(byte h, byte l); 20 | 21 | #define word(...) makeWord(__VA_ARGS__) 22 | 23 | unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); 24 | 25 | void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0); 26 | void noTone(uint8_t _pin); 27 | 28 | // WMath prototypes 29 | long random(long); 30 | long random(long, long); 31 | void randomSeed(unsigned int); 32 | long map(long, long, long, long, long); 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /arduino.DuinOS/wiring_shift.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_shift.c - shiftOut() function 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ 23 | */ 24 | 25 | #include "wiring_private.h" 26 | 27 | void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val) 28 | { 29 | int i; 30 | 31 | for (i = 0; i < 8; i++) { 32 | if (bitOrder == LSBFIRST) 33 | digitalWrite(dataPin, !!(val & (1 << i))); 34 | else 35 | digitalWrite(dataPin, !!(val & (1 << (7 - i)))); 36 | 37 | digitalWrite(clockPin, HIGH); 38 | digitalWrite(clockPin, LOW); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /arduino.DuinOS/WMath.cpp: -------------------------------------------------------------------------------- 1 | /* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 | 3 | /* 4 | Part of the Wiring project - http://wiring.org.co 5 | Copyright (c) 2004-06 Hernando Barragan 6 | Modified 13 August 2006, David A. Mellis for Arduino - http://www.arduino.cc/ 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General 19 | Public License along with this library; if not, write to the 20 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 21 | Boston, MA 02111-1307 USA 22 | 23 | $Id$ 24 | */ 25 | 26 | extern "C" { 27 | #include "stdlib.h" 28 | } 29 | 30 | void randomSeed(unsigned int seed) 31 | { 32 | if (seed != 0) { 33 | srandom(seed); 34 | } 35 | } 36 | 37 | long random(long howbig) 38 | { 39 | if (howbig == 0) { 40 | return 0; 41 | } 42 | return random() % howbig; 43 | } 44 | 45 | long random(long howsmall, long howbig) 46 | { 47 | if (howsmall >= howbig) { 48 | return howsmall; 49 | } 50 | long diff = howbig - howsmall; 51 | return random(diff) + howsmall; 52 | } 53 | 54 | long map(long x, long in_min, long in_max, long out_min, long out_max) 55 | { 56 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; 57 | } 58 | 59 | unsigned int makeWord(unsigned int w) { return w; } 60 | unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8) | l; } -------------------------------------------------------------------------------- /arduino.DuinOS/wiring_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_private.h - Internal header file. 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.h 239 2007-01-12 17:58:39Z mellis $ 23 | */ 24 | 25 | #ifndef WiringPrivate_h 26 | #define WiringPrivate_h 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "wiring.h" 35 | 36 | #ifdef __cplusplus 37 | extern "C"{ 38 | #endif 39 | 40 | #ifndef cbi 41 | #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) 42 | #endif 43 | #ifndef sbi 44 | #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) 45 | #endif 46 | 47 | #define EXTERNAL_INT_0 0 48 | #define EXTERNAL_INT_1 1 49 | #define EXTERNAL_INT_2 2 50 | #define EXTERNAL_INT_3 3 51 | #define EXTERNAL_INT_4 4 52 | #define EXTERNAL_INT_5 5 53 | #define EXTERNAL_INT_6 6 54 | #define EXTERNAL_INT_7 7 55 | 56 | #if defined(__AVR_ATmega1280__) 57 | #define EXTERNAL_NUM_INTERRUPTS 8 58 | #else 59 | #define EXTERNAL_NUM_INTERRUPTS 2 60 | #endif 61 | 62 | typedef void (*voidFuncPtr)(void); 63 | 64 | #ifdef __cplusplus 65 | } // extern "C" 66 | #endif 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /arduino.DuinOS/Print.h: -------------------------------------------------------------------------------- 1 | /* 2 | Print.h - Base class that provides print() and println() 3 | Copyright (c) 2008 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Print_h 21 | #define Print_h 22 | 23 | #include 24 | #include // for size_t 25 | 26 | #define DEC 10 27 | #define HEX 16 28 | #define OCT 8 29 | #define BIN 2 30 | #define BYTE 0 31 | 32 | class Print 33 | { 34 | private: 35 | void printNumber(unsigned long, uint8_t); 36 | void printFloat(double, uint8_t); 37 | public: 38 | virtual void write(uint8_t) = 0; 39 | virtual void write(const char *str); 40 | virtual void write(const uint8_t *buffer, size_t size); 41 | void print(char); 42 | void print(const char[]); 43 | void print(uint8_t); 44 | void print(int); 45 | void print(unsigned int); 46 | void print(long); 47 | void print(unsigned long); 48 | void print(long, int); 49 | void print(double); 50 | void println(void); 51 | void println(char); 52 | void println(const char[]); 53 | void println(uint8_t); 54 | void println(int); 55 | void println(unsigned int); 56 | void println(long); 57 | void println(unsigned long); 58 | void println(long, int); 59 | void println(double); 60 | }; 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /ide/duinos_boards.txt: -------------------------------------------------------------------------------- 1 | ############################################################## 2 | 3 | atmega328_DuinOS.name=Arduino Duemilanove or Nano w/ ATmega328 + DuinOS 4 | 5 | atmega328_DuinOS.upload.protocol=stk500 6 | atmega328_DuinOS.upload.maximum_size=30720 7 | atmega328_DuinOS.upload.speed=57600 8 | 9 | atmega328_DuinOS.bootloader.low_fuses=0xFF 10 | atmega328_DuinOS.bootloader.high_fuses=0xDA 11 | atmega328_DuinOS.bootloader.extended_fuses=0x05 12 | atmega328_DuinOS.bootloader.path=atmega 13 | atmega328_DuinOS.bootloader.file=ATmegaBOOT_168_atmega328.hex 14 | atmega328_DuinOS.bootloader.unlock_bits=0x3F 15 | atmega328_DuinOS.bootloader.lock_bits=0x0F 16 | 17 | atmega328_DuinOS.build.mcu=atmega328p 18 | atmega328_DuinOS.build.f_cpu=16000000L 19 | atmega328_DuinOS.build.core=arduino.DuinOS 20 | 21 | ############################################################## 22 | 23 | diecimila_DuinOS.name=Arduino Diecimila, Duemilanove, or Nano w/ ATmega168 + DuinOS 24 | 25 | diecimila_DuinOS.upload.protocol=stk500 26 | diecimila_DuinOS.upload.maximum_size=14336 27 | diecimila_DuinOS.upload.speed=19200 28 | 29 | diecimila_DuinOS.bootloader.low_fuses=0xff 30 | diecimila_DuinOS.bootloader.high_fuses=0xdd 31 | diecimila_DuinOS.bootloader.extended_fuses=0x00 32 | diecimila_DuinOS.bootloader.path=atmega 33 | diecimila_DuinOS.bootloader.file=ATmegaBOOT_168_diecimila.hex 34 | diecimila_DuinOS.bootloader.unlock_bits=0x3F 35 | diecimila_DuinOS.bootloader.lock_bits=0x0F 36 | 37 | diecimila_DuinOS.build.mcu=atmega168 38 | diecimila_DuinOS.build.f_cpu=16000000L 39 | diecimila_DuinOS.build.core=arduino.DuinOS 40 | 41 | ############################################################## 42 | 43 | mega_DuinOS.name=Arduino Mega + DuinOS 44 | 45 | mega_DuinOS.upload.protocol=stk500 46 | mega_DuinOS.upload.maximum_size=126976 47 | mega_DuinOS.upload.speed=57600 48 | 49 | mega_DuinOS.bootloader.low_fuses=0xFF 50 | mega_DuinOS.bootloader.high_fuses=0xDA 51 | mega_DuinOS.bootloader.extended_fuses=0xF5 52 | mega_DuinOS.bootloader.path=atmega 53 | mega_DuinOS.bootloader.file=ATmegaBOOT_168_atmega1280.hex 54 | mega_DuinOS.bootloader.unlock_bits=0x3F 55 | mega_DuinOS.bootloader.lock_bits=0x0F 56 | 57 | mega_DuinOS.build.mcu=atmega1280 58 | mega_DuinOS.build.f_cpu=16000000L 59 | mega_DuinOS.build.core=arduino.DuinOS 60 | 61 | -------------------------------------------------------------------------------- /arduino.DuinOS/HardwareSerial.h: -------------------------------------------------------------------------------- 1 | /* 2 | HardwareSerial.h - Hardware serial library for Wiring 3 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef HardwareSerial_h 21 | #define HardwareSerial_h 22 | 23 | #include 24 | 25 | #include "Print.h" 26 | 27 | struct ring_buffer; 28 | 29 | class HardwareSerial : public Print 30 | { 31 | private: 32 | ring_buffer *_rx_buffer; 33 | volatile uint8_t *_ubrrh; 34 | volatile uint8_t *_ubrrl; 35 | volatile uint8_t *_ucsra; 36 | volatile uint8_t *_ucsrb; 37 | volatile uint8_t *_udr; 38 | uint8_t _rxen; 39 | uint8_t _txen; 40 | uint8_t _rxcie; 41 | uint8_t _udre; 42 | uint8_t _u2x; 43 | public: 44 | void (*recv_handler)(HardwareSerial *, int); 45 | 46 | HardwareSerial(ring_buffer *rx_buffer, 47 | volatile uint8_t *ubrrh, volatile uint8_t *ubrrl, 48 | volatile uint8_t *ucsra, volatile uint8_t *ucsrb, 49 | volatile uint8_t *udr, 50 | uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x); 51 | void begin(long); 52 | uint8_t available(void); 53 | int read(void); 54 | void flush(void); 55 | virtual void write(uint8_t); 56 | inline void store_char(unsigned char c); 57 | using Print::write; // pull in write(str) and write(buf, size) from Print 58 | }; 59 | 60 | extern HardwareSerial Serial; 61 | 62 | #if defined(__AVR_ATmega1280__) 63 | extern HardwareSerial Serial1; 64 | extern HardwareSerial Serial2; 65 | extern HardwareSerial Serial3; 66 | #endif 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /arduino.DuinOS/DuinOS.h: -------------------------------------------------------------------------------- 1 | #ifndef DuinOS__h 2 | #define DuinOS__h 3 | 4 | #ifdef __cplusplus 5 | extern "C" 6 | { 7 | #endif 8 | 9 | #include 10 | #include 11 | 12 | //#ifdef GCC_MEGA_AVR 13 | /* EEPROM routines used only with the WinAVR compiler. */ 14 | #include 15 | //#endif 16 | 17 | /* Scheduler include files. */ 18 | #include "DuinOS/FreeRTOS.h" 19 | #include "DuinOS/task.h" 20 | 21 | #ifdef __cplusplus 22 | } // extern "C" 23 | #endif 24 | 25 | extern unsigned portBASE_TYPE mainLoopPriority; 26 | 27 | //In small devices, we use only 3 priorities: 28 | #define LOW_PRIORITY (tskIDLE_PRIORITY) 29 | #define NORMAL_PRIORITY (tskIDLE_PRIORITY + 1) 30 | #define HIGH_PRIORITY (tskIDLE_PRIORITY + 2) 31 | 32 | #define taskLoop(name)\ 33 | void name##Function();\ 34 | xTaskHandle name;\ 35 | void name##_Task(void *pvParameters)\ 36 | {\ 37 | for(;;)\ 38 | name##Function();\ 39 | }\ 40 | void name##Function() 41 | 42 | //This macro enables the forward declaration of a task, to allow other tasks previous defined (with the 43 | //taskLoop()macro use and reference them: 44 | #define declareTaskLoop(name) extern xTaskHandle name 45 | 46 | #define createTaskLoop(name, priority)\ 47 | {\ 48 | xTaskCreate(name##_Task, (signed portCHAR *) #name, configMINIMAL_STACK_SIZE, NULL, priority, &name);\ 49 | } 50 | 51 | #define createTaskLoopWithStackSize(name, priority, ssize)\ 52 | {\ 53 | xTaskCreate(name##_Task, (signed portCHAR *) #name, ssize, NULL, priority, &name);\ 54 | } 55 | 56 | #define suspend() vTaskSuspend(NULL) 57 | 58 | #define suspendTask(name) vTaskSuspend(name) 59 | 60 | #define suspendAll() vTaskSuspendAll() 61 | 62 | #define resumeTask(name) vTaskResume(name) 63 | 64 | #define resumeAll() xTaskResumeAll() 65 | 66 | #define nextTask() taskYIELD() 67 | 68 | #define delay(ticks) vTaskDelay(ticks) 69 | /* 70 | inline void delay(const portTickType ticks) 71 | { 72 | portTickType xLastWakeTime = xTaskGetTickCount(); 73 | 74 | //Better than vTaskDelay: 75 | vTaskDelayUntil( &xLastWakeTime, ticks); 76 | } 77 | */ 78 | 79 | //This macro is quiet different from setPriority, because this works even in those CPUs wich does not support 80 | //the set/getPriority macros (due to their small RAM memories). And, this only has effect if called in setup(). 81 | #define initMainLoopPriority(priority) (mainLoopPriority = priority) 82 | 83 | //These only works if INCLUDE_vTaskPrioritySet / INCLUDE_vTaskPriorityGet are != 0 84 | //(disabled for CPUs with less than 2KB RAM): 85 | #if INCLUDE_vTaskPriorityGet //This #if is to improve the error readability. 86 | #define getPriority(name) uxTaskPriorityGet(name) 87 | #endif 88 | #if INCLUDE_vTaskPrioritySet 89 | #define setPriority(name, priority) uxTaskPrioritySet(name, priority) 90 | #endif 91 | 92 | //##In bigger CPUs, DuinOS may use cTaskDelete, and uxTaskPrioritySet/Get. 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /arduino.DuinOS/wiring_pulse.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_pulse.c - pulseIn() function 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ 23 | */ 24 | 25 | #include "wiring_private.h" 26 | #include "pins_arduino.h" 27 | 28 | /* Measures the length (in microseconds) of a pulse on the pin; state is HIGH 29 | * or LOW, the type of pulse to measure. Works on pulses from 2-3 microseconds 30 | * to 3 minutes in length, but must be called at least a few dozen microseconds 31 | * before the start of the pulse. */ 32 | unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout) 33 | { 34 | // cache the port and bit of the pin in order to speed up the 35 | // pulse width measuring loop and achieve finer resolution. calling 36 | // digitalRead() instead yields much coarser resolution. 37 | uint8_t bit = digitalPinToBitMask(pin); 38 | uint8_t port = digitalPinToPort(pin); 39 | uint8_t stateMask = (state ? bit : 0); 40 | unsigned long width = 0; // keep initialization out of time critical area 41 | 42 | // convert the timeout from microseconds to a number of times through 43 | // the initial loop; it takes 16 clock cycles per iteration. 44 | unsigned long numloops = 0; 45 | unsigned long maxloops = microsecondsToClockCycles(timeout) / 16; 46 | 47 | // wait for any previous pulse to end 48 | while ((*portInputRegister(port) & bit) == stateMask) 49 | if (numloops++ == maxloops) 50 | return 0; 51 | 52 | // wait for the pulse to start 53 | while ((*portInputRegister(port) & bit) != stateMask) 54 | if (numloops++ == maxloops) 55 | return 0; 56 | 57 | // wait for the pulse to stop 58 | while ((*portInputRegister(port) & bit) == stateMask) 59 | width++; 60 | 61 | // convert the reading to microseconds. The loop has been determined 62 | // to be 10 clock cycles long and have about 16 clocks between the edge 63 | // and the start of the loop. There will be some error introduced by 64 | // the interrupt handlers. 65 | return clockCyclesToMicroseconds(width * 10 + 16); 66 | } 67 | -------------------------------------------------------------------------------- /arduino.DuinOS/DuinOS/projdefs.h: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V5.4.2 - Copyright (C) 2009 Real Time Engineers Ltd. 3 | 4 | This file is part of the FreeRTOS distribution. 5 | 6 | FreeRTOS is free software; you can redistribute it and/or modify it under 7 | the terms of the GNU General Public License (version 2) as published by the 8 | Free Software Foundation and modified by the FreeRTOS exception. 9 | **NOTE** The exception to the GPL is included to allow you to distribute a 10 | combined work that includes FreeRTOS without being obliged to provide the 11 | source code for proprietary components outside of the FreeRTOS kernel. 12 | Alternative commercial license and support terms are also available upon 13 | request. See the licensing section of http://www.FreeRTOS.org for full 14 | license details. 15 | 16 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 19 | more details. 20 | 21 | You should have received a copy of the GNU General Public License along 22 | with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59 23 | Temple Place, Suite 330, Boston, MA 02111-1307 USA. 24 | 25 | 26 | *************************************************************************** 27 | * * 28 | * Looking for a quick start? Then check out the FreeRTOS eBook! * 29 | * See http://www.FreeRTOS.org/Documentation for details * 30 | * * 31 | *************************************************************************** 32 | 33 | 1 tab == 4 spaces! 34 | 35 | Please ensure to read the configuration and relevant port sections of the 36 | online documentation. 37 | 38 | http://www.FreeRTOS.org - Documentation, latest information, license and 39 | contact details. 40 | 41 | http://www.SafeRTOS.com - A version that is certified for use in safety 42 | critical systems. 43 | 44 | http://www.OpenRTOS.com - Commercial support, development, porting, 45 | licensing and training services. 46 | */ 47 | 48 | #ifndef PROJDEFS_H 49 | #define PROJDEFS_H 50 | 51 | /* Defines the prototype to which task functions must conform. */ 52 | typedef void (*pdTASK_CODE)( void * ); 53 | 54 | #define pdTRUE ( 1 ) 55 | #define pdFALSE ( 0 ) 56 | 57 | #define pdPASS ( 1 ) 58 | #define pdFAIL ( 0 ) 59 | #define errQUEUE_EMPTY ( 0 ) 60 | #define errQUEUE_FULL ( 0 ) 61 | 62 | /* Error definitions. */ 63 | #define errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY ( -1 ) 64 | #define errNO_TASK_TO_RUN ( -2 ) 65 | #define errQUEUE_BLOCKED ( -4 ) 66 | #define errQUEUE_YIELD ( -5 ) 67 | 68 | #endif /* PROJDEFS_H */ 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /arduino.DuinOS/pins_arduino.h: -------------------------------------------------------------------------------- 1 | /* 2 | pins_arduino.h - Pin definition functions for Arduino 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2007 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $ 23 | */ 24 | 25 | #ifndef Pins_Arduino_h 26 | #define Pins_Arduino_h 27 | 28 | #include 29 | 30 | #define NOT_A_PIN 0 31 | #define NOT_A_PORT 0 32 | 33 | #define NOT_ON_TIMER 0 34 | #define TIMER0A 1 35 | #define TIMER0B 2 36 | #define TIMER1A 3 37 | #define TIMER1B 4 38 | #define TIMER2 5 39 | #define TIMER2A 6 40 | #define TIMER2B 7 41 | 42 | #define TIMER3A 8 43 | #define TIMER3B 9 44 | #define TIMER3C 10 45 | #define TIMER4A 11 46 | #define TIMER4B 12 47 | #define TIMER4C 13 48 | #define TIMER5A 14 49 | #define TIMER5B 15 50 | #define TIMER5C 16 51 | 52 | // On the ATmega1280, the addresses of some of the port registers are 53 | // greater than 255, so we can't store them in uint8_t's. 54 | extern const uint16_t PROGMEM port_to_mode_PGM[]; 55 | extern const uint16_t PROGMEM port_to_input_PGM[]; 56 | extern const uint16_t PROGMEM port_to_output_PGM[]; 57 | 58 | extern const uint8_t PROGMEM digital_pin_to_port_PGM[]; 59 | // extern const uint8_t PROGMEM digital_pin_to_bit_PGM[]; 60 | extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[]; 61 | extern const uint8_t PROGMEM digital_pin_to_timer_PGM[]; 62 | 63 | // Get the bit location within the hardware port of the given virtual pin. 64 | // This comes from the pins_*.c file for the active board configuration. 65 | // 66 | // These perform slightly better as macros compared to inline functions 67 | // 68 | #define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) ) 69 | #define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) ) 70 | #define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) ) 71 | #define analogInPinToBit(P) (P) 72 | #define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) ) 73 | #define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) ) 74 | #define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) ) 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /examples/MoreComplexBlinking/MoreComplexBlinking.pde: -------------------------------------------------------------------------------- 1 | /* 2 | DuinOS MoreComplexBlinking 3 | 4 | Blinks two LEDs. One LED shows two combined waves. 5 | 6 | The circuit: ##Pins: 7 | * LED connected from digital pin 14 to Vcc. 8 | * LED connected from digital pin 15 to Vcc. 9 | 10 | ##Pins: 11 | * Note: On most Comm.ProgUSB boards, there are already two LEDs on the board 12 | connected to pins 14 and 15, so you don't need any extra components for this example. 13 | 14 | Created 2009.10.26 (yyyy.mm.dd) 15 | by Julián da Silva Gillig 16 | 17 | http://multiplo.org 18 | http://robotgroup.com.ar 19 | 20 | Based on the original Blink code by David Cuartielles 21 | 22 | */ 23 | 24 | #define INITIAL_GREEN_DELAY 200 25 | #define NEW_GREEN_DELAY 20 26 | 27 | int ledPinRed = 8; 28 | int ledPinGreen = 9; 29 | 30 | unsigned int greenDelay = INITIAL_GREEN_DELAY; 31 | boolean redLED_isOn = false; 32 | boolean greenLED_isOn = false; 33 | 34 | //Forward declaration, to let redLED call to resumeTask(greenLED). It's not necessary if we put the greenLED 35 | //itself here, but declareLoopTask may be usefull in more complex situations: 36 | declareTaskLoop(greenLED); 37 | 38 | taskLoop(redLED) 39 | { 40 | static unsigned char counter = 0; 41 | 42 | if (!greenLED_isOn) 43 | { 44 | if (counter >2) 45 | resumeTask(greenLED); 46 | counter++; 47 | } 48 | 49 | redLED_isOn = false; 50 | delay(1000); 51 | redLED_isOn = true; 52 | delay(1000); 53 | } 54 | 55 | 56 | taskLoop(greenLED) 57 | { 58 | static unsigned char counter = 1; 59 | 60 | digitalWrite(ledPinGreen, HIGH); // set the LED on 61 | delay(greenDelay); 62 | digitalWrite(ledPinGreen, LOW); // set the LED off 63 | delay(greenDelay); 64 | 65 | if ( (counter >= 9) && (greenDelay != NEW_GREEN_DELAY) ) 66 | greenDelay = NEW_GREEN_DELAY; //now, after 10 blinks, accelerates 67 | if (counter >= 99) 68 | { 69 | //Reset vars, so next time, if the task is resumed, it executes all again: 70 | counter = 0; 71 | greenDelay = INITIAL_GREEN_DELAY; 72 | greenLED_isOn = false; 73 | suspend(); //After a while, the tasks suspends itself (forever) 74 | } 75 | counter++; 76 | } 77 | 78 | 79 | // The setup() method runs once, when the sketch starts 80 | 81 | void setup() 82 | { 83 | // Initialize the digital pins as outputs: 84 | pinMode(ledPinRed, OUTPUT); 85 | pinMode(ledPinGreen, OUTPUT); 86 | 87 | createTaskLoop(redLED, NORMAL_PRIORITY); 88 | createTaskLoop(greenLED, LOW_PRIORITY); 89 | 90 | //This initializes the main loop's with a different priority (default is LOW_PRIORITY): 91 | //initMainLoopPriority(NORMAL_PRIORITY); 92 | 93 | //Try this and see what happends: 94 | //suspendTask(redLED); 95 | } 96 | 97 | 98 | // This is the main loop() method, wich runs over and over again, 99 | // as long as the Arduino has power. Is a LOW_PRIORITY taskLoop: 100 | 101 | void loop() 102 | { 103 | if (redLED_isOn) 104 | { 105 | digitalWrite(ledPinRed, LOW); // set the LED off 106 | delay(25); // The OS can be tested reducing these delays, and seeing how both LEDs work together... 107 | digitalWrite(ledPinRed, HIGH); // set the LED on 108 | delay(25); 109 | } 110 | else 111 | { 112 | digitalWrite(ledPinRed, LOW); // LED is off 113 | //If nextTask is not called, the application will not hang, because the OS is preemptive. BUT, the current task 114 | //will consume a lot of computational resources (due to it's lack of a delay() in this branch), the application will 115 | //turn slower, and the other tasks may be affected by this, loossing precision in their timing: 116 | nextTask(); 117 | } 118 | } 119 | 120 | -------------------------------------------------------------------------------- /arduino.DuinOS/wiring_digital.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_digital.c - digital input and output functions 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ 23 | */ 24 | 25 | #include "wiring_private.h" 26 | #include "pins_arduino.h" 27 | 28 | void pinMode(uint8_t pin, uint8_t mode) 29 | { 30 | uint8_t bit = digitalPinToBitMask(pin); 31 | uint8_t port = digitalPinToPort(pin); 32 | volatile uint8_t *reg; 33 | 34 | if (port == NOT_A_PIN) return; 35 | 36 | // JWS: can I let the optimizer do this? 37 | reg = portModeRegister(port); 38 | 39 | if (mode == INPUT) *reg &= ~bit; 40 | else *reg |= bit; 41 | } 42 | 43 | // Forcing this inline keeps the callers from having to push their own stuff 44 | // on the stack. It is a good performance win and only takes 1 more byte per 45 | // user than calling. (It will take more bytes on the 168.) 46 | // 47 | // But shouldn't this be moved into pinMode? Seems silly to check and do on 48 | // each digitalread or write. 49 | // 50 | static inline void turnOffPWM(uint8_t timer) __attribute__ ((always_inline)); 51 | static inline void turnOffPWM(uint8_t timer) 52 | { 53 | if (timer == TIMER1A) cbi(TCCR1A, COM1A1); 54 | if (timer == TIMER1B) cbi(TCCR1A, COM1B1); 55 | 56 | #if defined(__AVR_ATmega8__) 57 | if (timer == TIMER2) cbi(TCCR2, COM21); 58 | #else 59 | if (timer == TIMER0A) cbi(TCCR0A, COM0A1); 60 | if (timer == TIMER0B) cbi(TCCR0A, COM0B1); 61 | if (timer == TIMER2A) cbi(TCCR2A, COM2A1); 62 | if (timer == TIMER2B) cbi(TCCR2A, COM2B1); 63 | #endif 64 | 65 | #if defined(__AVR_ATmega1280__) 66 | if (timer == TIMER3A) cbi(TCCR3A, COM3A1); 67 | if (timer == TIMER3B) cbi(TCCR3A, COM3B1); 68 | if (timer == TIMER3C) cbi(TCCR3A, COM3C1); 69 | if (timer == TIMER4A) cbi(TCCR4A, COM4A1); 70 | if (timer == TIMER4B) cbi(TCCR4A, COM4B1); 71 | if (timer == TIMER4C) cbi(TCCR4A, COM4C1); 72 | if (timer == TIMER5A) cbi(TCCR5A, COM5A1); 73 | if (timer == TIMER5B) cbi(TCCR5A, COM5B1); 74 | if (timer == TIMER5C) cbi(TCCR5A, COM5C1); 75 | #endif 76 | } 77 | 78 | void digitalWrite(uint8_t pin, uint8_t val) 79 | { 80 | uint8_t timer = digitalPinToTimer(pin); 81 | uint8_t bit = digitalPinToBitMask(pin); 82 | uint8_t port = digitalPinToPort(pin); 83 | volatile uint8_t *out; 84 | 85 | if (port == NOT_A_PIN) return; 86 | 87 | // If the pin that support PWM output, we need to turn it off 88 | // before doing a digital write. 89 | if (timer != NOT_ON_TIMER) turnOffPWM(timer); 90 | 91 | out = portOutputRegister(port); 92 | 93 | if (val == LOW) *out &= ~bit; 94 | else *out |= bit; 95 | } 96 | 97 | int digitalRead(uint8_t pin) 98 | { 99 | uint8_t timer = digitalPinToTimer(pin); 100 | uint8_t bit = digitalPinToBitMask(pin); 101 | uint8_t port = digitalPinToPort(pin); 102 | 103 | if (port == NOT_A_PIN) return LOW; 104 | 105 | // If the pin that support PWM output, we need to turn it off 106 | // before getting a digital reading. 107 | if (timer != NOT_ON_TIMER) turnOffPWM(timer); 108 | 109 | if (*portInputRegister(port) & bit) return HIGH; 110 | return LOW; 111 | } 112 | -------------------------------------------------------------------------------- /arduino.DuinOS/wiring.h: -------------------------------------------------------------------------------- 1 | /* 2 | wiring.h - Partial implementation of the Wiring API for the ATmega8. 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.h 602 2009-06-01 08:32:11Z dmellis $ 23 | */ 24 | 25 | #ifndef Wiring_h 26 | #define Wiring_h 27 | 28 | #include 29 | #include "binary.h" 30 | 31 | #ifdef __cplusplus 32 | extern "C"{ 33 | #endif 34 | 35 | #ifndef ARDUINO 36 | #define ARDUINO 16 37 | #endif 38 | 39 | #define HIGH 0x1 40 | #define LOW 0x0 41 | 42 | #define INPUT 0x0 43 | #define OUTPUT 0x1 44 | 45 | #define true 0x1 46 | #define false 0x0 47 | 48 | #define PI 3.1415926535897932384626433832795 49 | #define HALF_PI 1.5707963267948966192313216916398 50 | #define TWO_PI 6.283185307179586476925286766559 51 | #define DEG_TO_RAD 0.017453292519943295769236907684886 52 | #define RAD_TO_DEG 57.295779513082320876798154814105 53 | 54 | #define SERIAL 0x0 55 | #define DISPLAY 0x1 56 | 57 | #define LSBFIRST 0 58 | #define MSBFIRST 1 59 | 60 | #define CHANGE 1 61 | #define FALLING 2 62 | #define RISING 3 63 | 64 | #define INTERNAL 3 65 | #define DEFAULT 1 66 | #define EXTERNAL 0 67 | 68 | // undefine stdlib's abs if encountered 69 | #ifdef abs 70 | #undef abs 71 | #endif 72 | 73 | #define min(a,b) ((a)<(b)?(a):(b)) 74 | #define max(a,b) ((a)>(b)?(a):(b)) 75 | #define abs(x) ((x)>0?(x):-(x)) 76 | #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) 77 | #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) 78 | #define radians(deg) ((deg)*DEG_TO_RAD) 79 | #define degrees(rad) ((rad)*RAD_TO_DEG) 80 | #define sq(x) ((x)*(x)) 81 | 82 | #define interrupts() sei() 83 | #define noInterrupts() cli() 84 | 85 | #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L ) 86 | #define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) 87 | #define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() ) 88 | 89 | #define lowByte(w) ((uint8_t) ((w) & 0xff)) 90 | #define highByte(w) ((uint8_t) ((w) >> 8)) 91 | 92 | #define bitRead(value, bit) (((value) >> (bit)) & 0x01) 93 | #define bitSet(value, bit) ((value) |= (1UL << (bit))) 94 | #define bitClear(value, bit) ((value) &= ~(1UL << (bit))) 95 | #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) 96 | 97 | typedef unsigned int word; 98 | 99 | #define bit(b) (1UL << (b)) 100 | 101 | typedef uint8_t boolean; 102 | typedef uint8_t byte; 103 | 104 | void init(void); 105 | 106 | void pinMode(uint8_t, uint8_t); 107 | void digitalWrite(uint8_t, uint8_t); 108 | int digitalRead(uint8_t); 109 | int analogRead(uint8_t); 110 | void analogReference(uint8_t mode); 111 | void analogWrite(uint8_t, int); 112 | 113 | void beginSerial(long); 114 | void serialWrite(unsigned char); 115 | int serialAvailable(void); 116 | int serialRead(void); 117 | void serialFlush(void); 118 | 119 | unsigned long millis(void); 120 | unsigned long micros(void); 121 | 122 | #ifndef DuinOS__h 123 | //##: DuinOS overrides this: 124 | void delay(unsigned long); 125 | #endif 126 | 127 | void delayMicroseconds(unsigned int us); 128 | unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout); 129 | 130 | void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val); 131 | 132 | void attachInterrupt(uint8_t, void (*)(void), int mode); 133 | void detachInterrupt(uint8_t); 134 | 135 | void setup(void); 136 | 137 | void loop(void); 138 | 139 | 140 | #ifdef __cplusplus 141 | } // extern "C" 142 | #endif 143 | 144 | #endif 145 | -------------------------------------------------------------------------------- /arduino.DuinOS/Print.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Print.cpp - Base class that provides print() and println() 3 | Copyright (c) 2008 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Modified 23 November 2006 by David A. Mellis 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include "wiring.h" 26 | 27 | #include "Print.h" 28 | 29 | // Public Methods ////////////////////////////////////////////////////////////// 30 | 31 | /* default implementation: may be overridden */ 32 | void Print::write(const char *str) 33 | { 34 | while (*str) 35 | write(*str++); 36 | } 37 | 38 | /* default implementation: may be overridden */ 39 | void Print::write(const uint8_t *buffer, size_t size) 40 | { 41 | while (size--) 42 | write(*buffer++); 43 | } 44 | 45 | void Print::print(uint8_t b) 46 | { 47 | this->write(b); 48 | } 49 | 50 | void Print::print(char c) 51 | { 52 | print((byte) c); 53 | } 54 | 55 | void Print::print(const char str[]) 56 | { 57 | write(str); 58 | } 59 | 60 | void Print::print(int n) 61 | { 62 | print((long) n); 63 | } 64 | 65 | void Print::print(unsigned int n) 66 | { 67 | print((unsigned long) n); 68 | } 69 | 70 | void Print::print(long n) 71 | { 72 | if (n < 0) { 73 | print('-'); 74 | n = -n; 75 | } 76 | printNumber(n, 10); 77 | } 78 | 79 | void Print::print(unsigned long n) 80 | { 81 | printNumber(n, 10); 82 | } 83 | 84 | void Print::print(long n, int base) 85 | { 86 | if (base == 0) 87 | print((char) n); 88 | else if (base == 10) 89 | print(n); 90 | else 91 | printNumber(n, base); 92 | } 93 | 94 | void Print::print(double n) 95 | { 96 | printFloat(n, 2); 97 | } 98 | 99 | void Print::println(void) 100 | { 101 | print('\r'); 102 | print('\n'); 103 | } 104 | 105 | void Print::println(char c) 106 | { 107 | print(c); 108 | println(); 109 | } 110 | 111 | void Print::println(const char c[]) 112 | { 113 | print(c); 114 | println(); 115 | } 116 | 117 | void Print::println(uint8_t b) 118 | { 119 | print(b); 120 | println(); 121 | } 122 | 123 | void Print::println(int n) 124 | { 125 | print(n); 126 | println(); 127 | } 128 | 129 | void Print::println(unsigned int n) 130 | { 131 | print(n); 132 | println(); 133 | } 134 | 135 | void Print::println(long n) 136 | { 137 | print(n); 138 | println(); 139 | } 140 | 141 | void Print::println(unsigned long n) 142 | { 143 | print(n); 144 | println(); 145 | } 146 | 147 | void Print::println(long n, int base) 148 | { 149 | print(n, base); 150 | println(); 151 | } 152 | 153 | void Print::println(double n) 154 | { 155 | print(n); 156 | println(); 157 | } 158 | 159 | // Private Methods ///////////////////////////////////////////////////////////// 160 | 161 | void Print::printNumber(unsigned long n, uint8_t base) 162 | { 163 | unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars. 164 | unsigned long i = 0; 165 | 166 | if (n == 0) { 167 | print('0'); 168 | return; 169 | } 170 | 171 | while (n > 0) { 172 | buf[i++] = n % base; 173 | n /= base; 174 | } 175 | 176 | for (; i > 0; i--) 177 | print((char) (buf[i - 1] < 10 ? 178 | '0' + buf[i - 1] : 179 | 'A' + buf[i - 1] - 10)); 180 | } 181 | 182 | void Print::printFloat(double number, uint8_t digits) 183 | { 184 | // Handle negative numbers 185 | if (number < 0.0) 186 | { 187 | print('-'); 188 | number = -number; 189 | } 190 | 191 | // Round correctly so that print(1.999, 2) prints as "2.00" 192 | double rounding = 0.5; 193 | for (uint8_t i=0; i 0) 205 | print("."); 206 | 207 | // Extract digits from the remainder one at a time 208 | while (digits-- > 0) 209 | { 210 | remainder *= 10.0; 211 | int toPrint = int(remainder); 212 | print(toPrint); 213 | remainder -= toPrint; 214 | } 215 | } 216 | -------------------------------------------------------------------------------- /arduino.DuinOS/DuinOS/portmacro.h: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V5.4.2 - Copyright (C) 2009 Real Time Engineers Ltd. 3 | 4 | This file is part of the FreeRTOS distribution. 5 | 6 | FreeRTOS is free software; you can redistribute it and/or modify it under 7 | the terms of the GNU General Public License (version 2) as published by the 8 | Free Software Foundation and modified by the FreeRTOS exception. 9 | **NOTE** The exception to the GPL is included to allow you to distribute a 10 | combined work that includes FreeRTOS without being obliged to provide the 11 | source code for proprietary components outside of the FreeRTOS kernel. 12 | Alternative commercial license and support terms are also available upon 13 | request. See the licensing section of http://www.FreeRTOS.org for full 14 | license details. 15 | 16 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 19 | more details. 20 | 21 | You should have received a copy of the GNU General Public License along 22 | with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59 23 | Temple Place, Suite 330, Boston, MA 02111-1307 USA. 24 | 25 | 26 | *************************************************************************** 27 | * * 28 | * Looking for a quick start? Then check out the FreeRTOS eBook! * 29 | * See http://www.FreeRTOS.org/Documentation for details * 30 | * * 31 | *************************************************************************** 32 | 33 | 1 tab == 4 spaces! 34 | 35 | Please ensure to read the configuration and relevant port sections of the 36 | online documentation. 37 | 38 | http://www.FreeRTOS.org - Documentation, latest information, license and 39 | contact details. 40 | 41 | http://www.SafeRTOS.com - A version that is certified for use in safety 42 | critical systems. 43 | 44 | http://www.OpenRTOS.com - Commercial support, development, porting, 45 | licensing and training services. 46 | */ 47 | 48 | /* 49 | Changes from V1.2.3 50 | 51 | + portCPU_CLOSK_HZ definition changed to 8MHz base 10, previously it 52 | base 16. 53 | */ 54 | 55 | #ifndef PORTMACRO_H 56 | #define PORTMACRO_H 57 | 58 | #ifdef __cplusplus 59 | extern "C" { 60 | #endif 61 | 62 | /*----------------------------------------------------------- 63 | * Port specific definitions. 64 | * 65 | * The settings in this file configure FreeRTOS correctly for the 66 | * given hardware and compiler. 67 | * 68 | * These settings should not be altered. 69 | *----------------------------------------------------------- 70 | */ 71 | 72 | /* Type definitions. */ 73 | #define portCHAR char 74 | #define portFLOAT float 75 | #define portDOUBLE double 76 | #define portLONG long 77 | #define portSHORT int 78 | #define portSTACK_TYPE unsigned portCHAR 79 | #define portBASE_TYPE char 80 | 81 | #if( configUSE_16_BIT_TICKS == 1 ) 82 | typedef unsigned portSHORT portTickType; 83 | #define portMAX_DELAY ( portTickType ) 0xffff 84 | #else 85 | typedef unsigned portLONG portTickType; 86 | #define portMAX_DELAY ( portTickType ) 0xffffffff 87 | #endif 88 | /*-----------------------------------------------------------*/ 89 | 90 | /* Critical section management. */ 91 | #define portENTER_CRITICAL() asm volatile ( "in __tmp_reg__, __SREG__" :: ); \ 92 | asm volatile ( "cli" :: ); \ 93 | asm volatile ( "push __tmp_reg__" :: ) 94 | 95 | #define portEXIT_CRITICAL() asm volatile ( "pop __tmp_reg__" :: ); \ 96 | asm volatile ( "out __SREG__, __tmp_reg__" :: ) 97 | 98 | #define portDISABLE_INTERRUPTS() asm volatile ( "cli" :: ); 99 | #define portENABLE_INTERRUPTS() asm volatile ( "sei" :: ); 100 | /*-----------------------------------------------------------*/ 101 | 102 | /* Architecture specifics. */ 103 | #define portSTACK_GROWTH ( -1 ) 104 | #define portTICK_RATE_MS ( ( portTickType ) 1000 / configTICK_RATE_HZ ) 105 | #define portBYTE_ALIGNMENT 1 106 | #define portNOP() asm volatile ( "nop" ); 107 | /*-----------------------------------------------------------*/ 108 | 109 | /* Kernel utilities. */ 110 | extern void vPortYield( void ) __attribute__ ( ( naked ) ); 111 | #define portYIELD() vPortYield() 112 | /*-----------------------------------------------------------*/ 113 | 114 | /* Task function macros as described on the FreeRTOS.org WEB site. */ 115 | #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) 116 | #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) 117 | 118 | #ifdef __cplusplus 119 | } 120 | #endif 121 | 122 | #endif /* PORTMACRO_H */ 123 | 124 | -------------------------------------------------------------------------------- /arduino.DuinOS/DuinOS/heap_3.c: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V6.0.2 - Copyright (C) 2010 Real Time Engineers Ltd. 3 | 4 | *************************************************************************** 5 | * * 6 | * If you are: * 7 | * * 8 | * + New to FreeRTOS, * 9 | * + Wanting to learn FreeRTOS or multitasking in general quickly * 10 | * + Looking for basic training, * 11 | * + Wanting to improve your FreeRTOS skills and productivity * 12 | * * 13 | * then take a look at the FreeRTOS eBook * 14 | * * 15 | * "Using the FreeRTOS Real Time Kernel - a Practical Guide" * 16 | * http://www.FreeRTOS.org/Documentation * 17 | * * 18 | * A pdf reference manual is also available. Both are usually delivered * 19 | * to your inbox within 20 minutes to two hours when purchased between 8am * 20 | * and 8pm GMT (although please allow up to 24 hours in case of * 21 | * exceptional circumstances). Thank you for your support! * 22 | * * 23 | *************************************************************************** 24 | 25 | This file is part of the FreeRTOS distribution. 26 | 27 | FreeRTOS is free software; you can redistribute it and/or modify it under 28 | the terms of the GNU General Public License (version 2) as published by the 29 | Free Software Foundation AND MODIFIED BY the FreeRTOS exception. 30 | ***NOTE*** The exception to the GPL is included to allow you to distribute 31 | a combined work that includes FreeRTOS without being obliged to provide the 32 | source code for proprietary components outside of the FreeRTOS kernel. 33 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT 34 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 35 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 36 | more details. You should have received a copy of the GNU General Public 37 | License and the FreeRTOS license exception along with FreeRTOS; if not it 38 | can be viewed here: http://www.freertos.org/a00114.html and also obtained 39 | by writing to Richard Barry, contact details for whom are available on the 40 | FreeRTOS WEB site. 41 | 42 | 1 tab == 4 spaces! 43 | 44 | http://www.FreeRTOS.org - Documentation, latest information, license and 45 | contact details. 46 | 47 | http://www.SafeRTOS.com - A version that is certified for use in safety 48 | critical systems. 49 | 50 | http://www.OpenRTOS.com - Commercial support, development, porting, 51 | licensing and training services. 52 | */ 53 | 54 | 55 | /* 56 | * Implementation of pvPortMalloc() and vPortFree() that relies on the 57 | * compilers own malloc() and free() implementations. 58 | * 59 | * This file can only be used if the linker is configured to to generate 60 | * a heap memory area. 61 | * 62 | * See heap_2.c and heap_1.c for alternative implementations, and the memory 63 | * management pages of http://www.FreeRTOS.org for more information. 64 | */ 65 | 66 | #include 67 | 68 | /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining 69 | all the API functions to use the MPU wrappers. That should only be done when 70 | task.h is included from an application file. */ 71 | #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE 72 | 73 | #include "FreeRTOS.h" 74 | #include "task.h" 75 | 76 | #ifdef DUINOS_USE_HEAP3 77 | #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE 78 | 79 | /*-----------------------------------------------------------*/ 80 | 81 | void *pvPortMalloc( size_t xWantedSize ) 82 | { 83 | void *pvReturn; 84 | 85 | vTaskSuspendAll(); 86 | { 87 | pvReturn = malloc( xWantedSize ); 88 | } 89 | xTaskResumeAll(); 90 | 91 | #if( configUSE_MALLOC_FAILED_HOOK == 1 ) 92 | { 93 | if( pvReturn == NULL ) 94 | { 95 | extern void vApplicationMallocFailedHook( void ); 96 | vApplicationMallocFailedHook(); 97 | } 98 | } 99 | #endif 100 | 101 | return pvReturn; 102 | } 103 | /*-----------------------------------------------------------*/ 104 | 105 | void vPortFree( void *pv ) 106 | { 107 | if( pv ) 108 | { 109 | vTaskSuspendAll(); 110 | { 111 | free( pv ); 112 | } 113 | xTaskResumeAll(); 114 | } 115 | } 116 | 117 | 118 | 119 | #endif 120 | 121 | -------------------------------------------------------------------------------- /ide/keywords.txt: -------------------------------------------------------------------------------- 1 | # LITERAL1 specifies constants 2 | 3 | HIGH LITERAL1 Constants 4 | LOW LITERAL1 Constants 5 | INPUT LITERAL1 Constants 6 | OUTPUT LITERAL1 Constants 7 | SERIAL LITERAL1 8 | DISPLAY LITERAL1 9 | DEC LITERAL1 Serial_Print 10 | BIN LITERAL1 Serial_Print 11 | HEX LITERAL1 Serial_Print 12 | OCT LITERAL1 Serial_Print 13 | BYTE LITERAL1 Serial_Print 14 | PI LITERAL1 15 | HALF_PI LITERAL1 16 | TWO_PI LITERAL1 17 | LSBFIRST LITERAL1 ShiftOut 18 | MSBFIRST LITERAL1 ShiftOut 19 | CHANGE LITERAL1 AttachInterrupt 20 | FALLING LITERAL1 AttachInterrupt 21 | RISING LITERAL1 AttachInterrupt 22 | DEFAULT LITERAL1 AnalogReference 23 | EXTERNAL LITERAL1 AnalogReference 24 | INTERAL LITERAL1 AnalogReference 25 | 26 | # KEYWORD1 specifies datatypes and C/C++ keywords 27 | 28 | boolean KEYWORD1 BooleanVariables 29 | break KEYWORD1 Break 30 | byte KEYWORD1 Byte 31 | case KEYWORD1 SwitchCase 32 | char KEYWORD1 Char 33 | class KEYWORD1 34 | continue KEYWORD1 Continue 35 | default KEYWORD1 SwitchCase 36 | do KEYWORD1 DoWhile 37 | double KEYWORD1 Double 38 | else KEYWORD1 Else 39 | false KEYWORD1 Constants 40 | float KEYWORD1 Float 41 | for KEYWORD1 For 42 | if KEYWORD1 If 43 | int KEYWORD1 Int 44 | long KEYWORD1 Long 45 | new KEYWORD1 46 | null KEYWORD1 47 | private KEYWORD1 48 | protected KEYWORD1 49 | public KEYWORD1 50 | return KEYWORD1 Return 51 | short KEYWORD1 52 | signed KEYWORD1 53 | static KEYWORD1 Static 54 | switch KEYWORD1 SwitchCase 55 | this KEYWORD1 56 | throw KEYWORD1 57 | try KEYWORD1 58 | true KEYWORD1 59 | unsigned KEYWORD1 60 | void KEYWORD1 Void 61 | while KEYWORD1 While 62 | word KEYWORD1 Word 63 | 64 | # operators aren't highlighted, but may have documentation 65 | 66 | += IncrementCompound 67 | + Arithmetic 68 | [] arrayaccess 69 | = assign 70 | & BitwiseAnd 71 | | BitwiseAnd 72 | , 73 | // Comments 74 | ?: 75 | {} Braces 76 | -- Increment 77 | / Arithmetic 78 | /* Comments 79 | . dot 80 | == 81 | < greaterthan 82 | <= greaterthanorequalto 83 | ++ Increment 84 | != inequality 85 | << Bitshift 86 | < lessthan 87 | <= lessthanorequalto 88 | && Boolean 89 | ! Boolean 90 | || Boolean 91 | - Arithmetic 92 | % Modulo 93 | * Arithmetic 94 | () parentheses 95 | >> Bitshift 96 | ; SemiColon 97 | -= IncrementCompound 98 | 99 | # these are datatypes, but we've also defined functions to cast to them 100 | 101 | boolean KEYWORD2 boolean_ 102 | byte KEYWORD2 byte_ 103 | char KEYWORD2 char_ 104 | float KEYWORD2 float_ 105 | int KEYWORD2 int_ 106 | long KEYWORD2 long_ 107 | word KEYWORD2 word_ 108 | 109 | # KEYWORD2 specifies methods and functions 110 | 111 | abs KEYWORD2 Abs 112 | acos KEYWORD2 ACos 113 | asin KEYWORD2 ASin 114 | atan KEYWORD2 ATan 115 | atan2 KEYWORD2 ATan2 116 | ceil KEYWORD2 Ceil 117 | constrain KEYWORD2 Constrain 118 | cos KEYWORD2 Cos 119 | degrees KEYWORD2 120 | exp KEYWORD2 Exp 121 | floor KEYWORD2 Floor 122 | log KEYWORD2 Log 123 | map KEYWORD2 Map 124 | max KEYWORD2 Max 125 | min KEYWORD2 Min 126 | radians KEYWORD2 127 | random KEYWORD2 Random 128 | randomSeed KEYWORD2 RandomSeed 129 | round KEYWORD2 130 | sin KEYWORD2 Sin 131 | sq KEYWORD2 Sq 132 | sqrt KEYWORD2 Sqrt 133 | tan KEYWORD2 Tan 134 | 135 | bitRead KEYWORD2 BitRead 136 | bitWrite KEYWORD2 BitWrite 137 | bitSet KEYWORD2 BitSet 138 | bitClear KEYWORD2 BitClear 139 | bit KEYWORD2 Bit 140 | highByte KEYWORD2 HighByte 141 | lowByte KEYWORD2 LowByte 142 | 143 | analogReference KEYWORD2 AnalogReference 144 | analogRead KEYWORD2 AnalogRead 145 | analogWrite KEYWORD2 AnalogWrite 146 | attachInterrupt KEYWORD2 AttachInterrupt 147 | detachInterrupt KEYWORD2 DetachInterrupt 148 | delay KEYWORD2 Delay 149 | delayMicroseconds KEYWORD2 DelayMicroseconds 150 | digitalWrite KEYWORD2 DigitalWrite 151 | digitalRead KEYWORD2 DigitalRead 152 | interrupts KEYWORD2 153 | millis KEYWORD2 Millis 154 | micros KEYWORD2 Micros 155 | noInterrupts KEYWORD2 NoInterrupts 156 | noTone KEYWORD2 NoTone 157 | pinMode KEYWORD2 PinMode 158 | pulseIn KEYWORD2 PulseIn 159 | shiftOut KEYWORD2 ShiftOut 160 | tone KEYWORD2 Tone 161 | 162 | Serial KEYWORD3 Serial 163 | Serial1 KEYWORD3 Serial 164 | Serial2 KEYWORD3 Serial 165 | Serial3 KEYWORD3 Serial 166 | begin KEYWORD2 Serial_Begin 167 | end KEYWORD2 Serial_End 168 | read KEYWORD2 Serial_Read 169 | print KEYWORD2 Serial_Print 170 | println KEYWORD2 Serial_Println 171 | available KEYWORD2 Serial_Available 172 | flush KEYWORD2 Serial_Flush 173 | 174 | setup KEYWORD3 Setup 175 | loop KEYWORD3 Loop 176 | 177 | ####################################### 178 | # Syntax Coloring Map DuinOS 179 | ####################################### 180 | 181 | ####################################### 182 | # Datatypes (KEYWORD1) 183 | ####################################### 184 | 185 | taskLoop KEYWORD1 186 | 187 | ####################################### 188 | # Methods and Functions (KEYWORD2) 189 | ####################################### 190 | declareTaskLoop KEYWORD2 191 | createTaskLoop KEYWORD2 192 | suspend KEYWORD2 193 | suspendTask KEYWORD2 194 | suspendAll KEYWORD2 195 | resumeTask KEYWORD2 196 | resumeAll KEYWORD2 197 | nextTask KEYWORD2 198 | initMainLoopPriority KEYWORD2 199 | 200 | 201 | ####################################### 202 | # Constants (LITERAL1) 203 | ####################################### 204 | LOW_PRIORITY LITERAL1 205 | NORMAL_PRIORITY LITERAL1 206 | HIGH_PRIORITY LITERAL1 207 | 208 | -------------------------------------------------------------------------------- /arduino.DuinOS/DuinOS/heap_1.c: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V5.4.2 - Copyright (C) 2009 Real Time Engineers Ltd. 3 | 4 | This file is part of the FreeRTOS distribution. 5 | 6 | FreeRTOS is free software; you can redistribute it and/or modify it under 7 | the terms of the GNU General Public License (version 2) as published by the 8 | Free Software Foundation and modified by the FreeRTOS exception. 9 | **NOTE** The exception to the GPL is included to allow you to distribute a 10 | combined work that includes FreeRTOS without being obliged to provide the 11 | source code for proprietary components outside of the FreeRTOS kernel. 12 | Alternative commercial license and support terms are also available upon 13 | request. See the licensing section of http://www.FreeRTOS.org for full 14 | license details. 15 | 16 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 19 | more details. 20 | 21 | You should have received a copy of the GNU General Public License along 22 | with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59 23 | Temple Place, Suite 330, Boston, MA 02111-1307 USA. 24 | 25 | 26 | *************************************************************************** 27 | * * 28 | * Looking for a quick start? Then check out the FreeRTOS eBook! * 29 | * See http://www.FreeRTOS.org/Documentation for details * 30 | * * 31 | *************************************************************************** 32 | 33 | 1 tab == 4 spaces! 34 | 35 | Please ensure to read the configuration and relevant port sections of the 36 | online documentation. 37 | 38 | http://www.FreeRTOS.org - Documentation, latest information, license and 39 | contact details. 40 | 41 | http://www.SafeRTOS.com - A version that is certified for use in safety 42 | critical systems. 43 | 44 | http://www.OpenRTOS.com - Commercial support, development, porting, 45 | licensing and training services. 46 | */ 47 | 48 | 49 | /* 50 | * The simplest possible implementation of pvPortMalloc(). Note that this 51 | * implementation does NOT allow allocated memory to be freed again. 52 | * 53 | * See heap_2.c and heap_3.c for alternative implementations, and the memory 54 | * management pages of http://www.FreeRTOS.org for more information. 55 | */ 56 | #include 57 | #include "FreeRTOS.h" 58 | #include "task.h" 59 | 60 | #ifdef DUINOS_USE_HEAP1 61 | /* Setup the correct byte alignment mask for the defined byte alignment. */ 62 | 63 | #if portBYTE_ALIGNMENT == 8 64 | #define heapBYTE_ALIGNMENT_MASK ( ( size_t ) 0x0007 ) 65 | #endif 66 | 67 | #if portBYTE_ALIGNMENT == 4 68 | #define heapBYTE_ALIGNMENT_MASK ( ( size_t ) 0x0003 ) 69 | #endif 70 | 71 | #if portBYTE_ALIGNMENT == 2 72 | #define heapBYTE_ALIGNMENT_MASK ( ( size_t ) 0x0001 ) 73 | #endif 74 | 75 | #if portBYTE_ALIGNMENT == 1 76 | #define heapBYTE_ALIGNMENT_MASK ( ( size_t ) 0x0000 ) 77 | #endif 78 | 79 | #ifndef heapBYTE_ALIGNMENT_MASK 80 | #error "Invalid portBYTE_ALIGNMENT definition" 81 | #endif 82 | 83 | /* Allocate the memory for the heap. The struct is used to force byte 84 | alignment without using any non-portable code. */ 85 | static union xRTOS_HEAP 86 | { 87 | #if portBYTE_ALIGNMENT == 8 88 | volatile portDOUBLE dDummy; 89 | #else 90 | volatile unsigned portLONG ulDummy; 91 | #endif 92 | unsigned portCHAR ucHeap[ configTOTAL_HEAP_SIZE ]; 93 | } xHeap; 94 | 95 | static size_t xNextFreeByte = ( size_t ) 0; 96 | /*-----------------------------------------------------------*/ 97 | 98 | void *pvPortMalloc( size_t xWantedSize ) 99 | { 100 | void *pvReturn = NULL; 101 | 102 | /* Ensure that blocks are always aligned to the required number of bytes. */ 103 | #if portBYTE_ALIGNMENT != 1 104 | if( xWantedSize & heapBYTE_ALIGNMENT_MASK ) 105 | { 106 | /* Byte alignment required. */ 107 | xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & heapBYTE_ALIGNMENT_MASK ) ); 108 | } 109 | #endif 110 | 111 | vTaskSuspendAll(); 112 | { 113 | /* Check there is enough room left for the allocation. */ 114 | if( ( ( xNextFreeByte + xWantedSize ) < configTOTAL_HEAP_SIZE ) && 115 | ( ( xNextFreeByte + xWantedSize ) > xNextFreeByte ) )/* Check for overflow. */ 116 | { 117 | /* Return the next free byte then increment the index past this 118 | block. */ 119 | pvReturn = &( xHeap.ucHeap[ xNextFreeByte ] ); 120 | xNextFreeByte += xWantedSize; 121 | } 122 | } 123 | xTaskResumeAll(); 124 | 125 | #if( configUSE_MALLOC_FAILED_HOOK == 1 ) 126 | { 127 | if( pvReturn == NULL ) 128 | { 129 | extern void vApplicationMallocFailedHook( void ); 130 | vApplicationMallocFailedHook(); 131 | } 132 | } 133 | #endif 134 | 135 | return pvReturn; 136 | } 137 | /*-----------------------------------------------------------*/ 138 | 139 | void vPortFree( void *pv ) 140 | { 141 | /* Memory cannot be freed using this scheme. See heap_2.c and heap_3.c 142 | for alternative implementations, and the memory management pages of 143 | http://www.FreeRTOS.org for more information. */ 144 | ( void ) pv; 145 | } 146 | /*-----------------------------------------------------------*/ 147 | 148 | void vPortInitialiseBlocks( void ) 149 | { 150 | /* Only required when static memory is not cleared. */ 151 | xNextFreeByte = ( size_t ) 0; 152 | } 153 | 154 | 155 | #endif 156 | 157 | -------------------------------------------------------------------------------- /arduino.DuinOS/WInterrupts.c: -------------------------------------------------------------------------------- 1 | /* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 | 3 | /* 4 | Part of the Wiring project - http://wiring.uniandes.edu.co 5 | 6 | Copyright (c) 2004-05 Hernando Barragan 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General 19 | Public License along with this library; if not, write to the 20 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 21 | Boston, MA 02111-1307 USA 22 | 23 | Modified 24 November 2006 by David A. Mellis 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "WConstants.h" 33 | #include "wiring_private.h" 34 | 35 | volatile static voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS]; 36 | // volatile static voidFuncPtr twiIntFunc; 37 | 38 | #if defined(__AVR_ATmega8__) 39 | #define EICRA MCUCR 40 | #define EIMSK GICR 41 | #endif 42 | 43 | void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) { 44 | if(interruptNum < EXTERNAL_NUM_INTERRUPTS) { 45 | intFunc[interruptNum] = userFunc; 46 | 47 | // Configure the interrupt mode (trigger on low input, any change, rising 48 | // edge, or falling edge). The mode constants were chosen to correspond 49 | // to the configuration bits in the hardware register, so we simply shift 50 | // the mode into place. 51 | 52 | // Enable the interrupt. 53 | 54 | switch (interruptNum) { 55 | #if defined(__AVR_ATmega1280__) 56 | case 2: 57 | EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00); 58 | EIMSK |= (1 << INT0); 59 | break; 60 | case 3: 61 | EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10); 62 | EIMSK |= (1 << INT1); 63 | break; 64 | case 4: 65 | EICRA = (EICRA & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20); 66 | EIMSK |= (1 << INT2); 67 | break; 68 | case 5: 69 | EICRA = (EICRA & ~((1 << ISC30) | (1 << ISC31))) | (mode << ISC30); 70 | EIMSK |= (1 << INT3); 71 | break; 72 | case 0: 73 | EICRB = (EICRB & ~((1 << ISC40) | (1 << ISC41))) | (mode << ISC40); 74 | EIMSK |= (1 << INT4); 75 | break; 76 | case 1: 77 | EICRB = (EICRB & ~((1 << ISC50) | (1 << ISC51))) | (mode << ISC50); 78 | EIMSK |= (1 << INT5); 79 | break; 80 | case 6: 81 | EICRB = (EICRB & ~((1 << ISC60) | (1 << ISC61))) | (mode << ISC60); 82 | EIMSK |= (1 << INT6); 83 | break; 84 | case 7: 85 | EICRB = (EICRB & ~((1 << ISC70) | (1 << ISC71))) | (mode << ISC70); 86 | EIMSK |= (1 << INT7); 87 | break; 88 | #else 89 | case 0: 90 | EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00); 91 | EIMSK |= (1 << INT0); 92 | break; 93 | case 1: 94 | EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10); 95 | EIMSK |= (1 << INT1); 96 | break; 97 | #endif 98 | } 99 | } 100 | } 101 | 102 | void detachInterrupt(uint8_t interruptNum) { 103 | if(interruptNum < EXTERNAL_NUM_INTERRUPTS) { 104 | // Disable the interrupt. (We can't assume that interruptNum is equal 105 | // to the number of the EIMSK bit to clear, as this isn't true on the 106 | // ATmega8. There, INT0 is 6 and INT1 is 7.) 107 | switch (interruptNum) { 108 | #if defined(__AVR_ATmega1280__) 109 | case 2: 110 | EIMSK &= ~(1 << INT0); 111 | break; 112 | case 3: 113 | EIMSK &= ~(1 << INT1); 114 | break; 115 | case 4: 116 | EIMSK &= ~(1 << INT2); 117 | break; 118 | case 5: 119 | EIMSK &= ~(1 << INT3); 120 | break; 121 | case 0: 122 | EIMSK &= ~(1 << INT4); 123 | break; 124 | case 1: 125 | EIMSK &= ~(1 << INT5); 126 | break; 127 | case 6: 128 | EIMSK &= ~(1 << INT6); 129 | break; 130 | case 7: 131 | EIMSK &= ~(1 << INT7); 132 | break; 133 | #else 134 | case 0: 135 | EIMSK &= ~(1 << INT0); 136 | break; 137 | case 1: 138 | EIMSK &= ~(1 << INT1); 139 | break; 140 | #endif 141 | } 142 | 143 | intFunc[interruptNum] = 0; 144 | } 145 | } 146 | 147 | /* 148 | void attachInterruptTwi(void (*userFunc)(void) ) { 149 | twiIntFunc = userFunc; 150 | } 151 | */ 152 | 153 | #if defined(__AVR_ATmega1280__) 154 | 155 | SIGNAL(INT0_vect) { 156 | if(intFunc[EXTERNAL_INT_2]) 157 | intFunc[EXTERNAL_INT_2](); 158 | } 159 | 160 | SIGNAL(INT1_vect) { 161 | if(intFunc[EXTERNAL_INT_3]) 162 | intFunc[EXTERNAL_INT_3](); 163 | } 164 | 165 | SIGNAL(INT2_vect) { 166 | if(intFunc[EXTERNAL_INT_4]) 167 | intFunc[EXTERNAL_INT_4](); 168 | } 169 | 170 | SIGNAL(INT3_vect) { 171 | if(intFunc[EXTERNAL_INT_5]) 172 | intFunc[EXTERNAL_INT_5](); 173 | } 174 | 175 | SIGNAL(INT4_vect) { 176 | if(intFunc[EXTERNAL_INT_0]) 177 | intFunc[EXTERNAL_INT_0](); 178 | } 179 | 180 | SIGNAL(INT5_vect) { 181 | if(intFunc[EXTERNAL_INT_1]) 182 | intFunc[EXTERNAL_INT_1](); 183 | } 184 | 185 | SIGNAL(INT6_vect) { 186 | if(intFunc[EXTERNAL_INT_6]) 187 | intFunc[EXTERNAL_INT_6](); 188 | } 189 | 190 | SIGNAL(INT7_vect) { 191 | if(intFunc[EXTERNAL_INT_7]) 192 | intFunc[EXTERNAL_INT_7](); 193 | } 194 | 195 | #else 196 | 197 | SIGNAL(INT0_vect) { 198 | if(intFunc[EXTERNAL_INT_0]) 199 | intFunc[EXTERNAL_INT_0](); 200 | } 201 | 202 | SIGNAL(INT1_vect) { 203 | if(intFunc[EXTERNAL_INT_1]) 204 | intFunc[EXTERNAL_INT_1](); 205 | } 206 | 207 | #endif 208 | 209 | /* 210 | SIGNAL(SIG_2WIRE_SERIAL) { 211 | if(twiIntFunc) 212 | twiIntFunc(); 213 | } 214 | */ 215 | 216 | -------------------------------------------------------------------------------- /arduino.DuinOS/wiring_analog.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_analog.c - analog input and output 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ 23 | */ 24 | 25 | #include "wiring_private.h" 26 | #include "pins_arduino.h" 27 | 28 | uint8_t analog_reference = DEFAULT; 29 | 30 | void analogReference(uint8_t mode) 31 | { 32 | // can't actually set the register here because the default setting 33 | // will connect AVCC and the AREF pin, which would cause a short if 34 | // there's something connected to AREF. 35 | analog_reference = mode; 36 | } 37 | 38 | int analogRead(uint8_t pin) 39 | { 40 | uint8_t low, high; 41 | 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 & 0x0f); 46 | 47 | #if defined(__AVR_ATmega1280__) 48 | // the MUX5 bit of ADCSRB selects whether we're reading from channels 49 | // 0 to 7 (MUX5 low) or 8 to 15 (MUX5 high). 50 | ADCSRB = (ADCSRB & ~(1 << MUX5)) | (((pin >> 3) & 0x01) << MUX5); 51 | #endif 52 | 53 | // without a delay, we seem to read from the wrong channel 54 | //delay(1); 55 | 56 | // start the conversion 57 | sbi(ADCSRA, ADSC); 58 | 59 | // ADSC is cleared when the conversion finishes 60 | while (bit_is_set(ADCSRA, ADSC)); 61 | 62 | // we have to read ADCL first; doing so locks both ADCL 63 | // and ADCH until ADCH is read. reading ADCL second would 64 | // cause the results of each conversion to be discarded, 65 | // as ADCL and ADCH would be locked when it completed. 66 | low = ADCL; 67 | high = ADCH; 68 | 69 | // combine the two bytes 70 | return (high << 8) | low; 71 | } 72 | 73 | // Right now, PWM output only works on the pins with 74 | // hardware support. These are defined in the appropriate 75 | // pins_*.c file. For the rest of the pins, we default 76 | // to digital output. 77 | void analogWrite(uint8_t pin, int val) 78 | { 79 | // We need to make sure the PWM output is enabled for those pins 80 | // that support it, as we turn it off when digitally reading or 81 | // writing with them. Also, make sure the pin is in output mode 82 | // for consistenty with Wiring, which doesn't require a pinMode 83 | // call for the analog output pins. 84 | pinMode(pin, OUTPUT); 85 | 86 | if (digitalPinToTimer(pin) == TIMER1A) { 87 | /*##DuinOS uses the timer 1 for its kernel: 88 | 89 | // connect pwm to pin on timer 1, channel A 90 | sbi(TCCR1A, COM1A1); 91 | // set pwm duty 92 | OCR1A = val; 93 | */ 94 | } else if (digitalPinToTimer(pin) == TIMER1B) { 95 | /*##DuinOS uses the timer 1 for its kernel: 96 | // connect pwm to pin on timer 1, channel B 97 | sbi(TCCR1A, COM1B1); 98 | // set pwm duty 99 | OCR1B = val; 100 | */ 101 | #if defined(__AVR_ATmega8__) 102 | } else if (digitalPinToTimer(pin) == TIMER2) { 103 | // connect pwm to pin on timer 2, channel B 104 | sbi(TCCR2, COM21); 105 | // set pwm duty 106 | OCR2 = val; 107 | #else 108 | } else if (digitalPinToTimer(pin) == TIMER0A) { 109 | if (val == 0) { 110 | digitalWrite(pin, LOW); 111 | } else { 112 | // connect pwm to pin on timer 0, channel A 113 | sbi(TCCR0A, COM0A1); 114 | // set pwm duty 115 | OCR0A = val; 116 | } 117 | } else if (digitalPinToTimer(pin) == TIMER0B) { 118 | if (val == 0) { 119 | digitalWrite(pin, LOW); 120 | } else { 121 | // connect pwm to pin on timer 0, channel B 122 | sbi(TCCR0A, COM0B1); 123 | // set pwm duty 124 | OCR0B = val; 125 | } 126 | } else if (digitalPinToTimer(pin) == TIMER2A) { 127 | // connect pwm to pin on timer 2, channel A 128 | sbi(TCCR2A, COM2A1); 129 | // set pwm duty 130 | OCR2A = val; 131 | } else if (digitalPinToTimer(pin) == TIMER2B) { 132 | // connect pwm to pin on timer 2, channel B 133 | sbi(TCCR2A, COM2B1); 134 | // set pwm duty 135 | OCR2B = val; 136 | #endif 137 | #if defined(__AVR_ATmega1280__) 138 | // XXX: need to handle other timers here 139 | } else if (digitalPinToTimer(pin) == TIMER3A) { 140 | // connect pwm to pin on timer 3, channel A 141 | sbi(TCCR3A, COM3A1); 142 | // set pwm duty 143 | OCR3A = val; 144 | } else if (digitalPinToTimer(pin) == TIMER3B) { 145 | // connect pwm to pin on timer 3, channel B 146 | sbi(TCCR3A, COM3B1); 147 | // set pwm duty 148 | OCR3B = val; 149 | } else if (digitalPinToTimer(pin) == TIMER3C) { 150 | // connect pwm to pin on timer 3, channel C 151 | sbi(TCCR3A, COM3C1); 152 | // set pwm duty 153 | OCR3C = val; 154 | } else if (digitalPinToTimer(pin) == TIMER4A) { 155 | // connect pwm to pin on timer 4, channel A 156 | sbi(TCCR4A, COM4A1); 157 | // set pwm duty 158 | OCR4A = val; 159 | } else if (digitalPinToTimer(pin) == TIMER4B) { 160 | // connect pwm to pin on timer 4, channel B 161 | sbi(TCCR4A, COM4B1); 162 | // set pwm duty 163 | OCR4B = val; 164 | } else if (digitalPinToTimer(pin) == TIMER4C) { 165 | // connect pwm to pin on timer 4, channel C 166 | sbi(TCCR4A, COM4C1); 167 | // set pwm duty 168 | OCR4C = val; 169 | } else if (digitalPinToTimer(pin) == TIMER5A) { 170 | // connect pwm to pin on timer 5, channel A 171 | sbi(TCCR5A, COM5A1); 172 | // set pwm duty 173 | OCR5A = val; 174 | } else if (digitalPinToTimer(pin) == TIMER5B) { 175 | // connect pwm to pin on timer 5, channel B 176 | sbi(TCCR5A, COM5B1); 177 | // set pwm duty 178 | OCR5B = val; 179 | #endif 180 | } else if (val < 128) 181 | digitalWrite(pin, LOW); 182 | else 183 | digitalWrite(pin, HIGH); 184 | } 185 | -------------------------------------------------------------------------------- /arduino.DuinOS/HardwareSerial.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | HardwareSerial.cpp - Hardware serial library for Wiring 3 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Modified 23 November 2006 by David A. Mellis 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include "wiring.h" 26 | #include "wiring_private.h" 27 | 28 | #include "HardwareSerial.h" 29 | 30 | // Define constants and variables for buffering incoming serial data. We're 31 | // using a ring buffer (I think), in which rx_buffer_head is the index of the 32 | // location to which to write the next incoming character and rx_buffer_tail 33 | // is the index of the location from which to read. 34 | #define RX_BUFFER_SIZE 128 35 | 36 | struct ring_buffer { 37 | unsigned char buffer[RX_BUFFER_SIZE]; 38 | int head; 39 | int tail; 40 | }; 41 | 42 | ring_buffer rx_buffer = { { 0 }, 0, 0 }; 43 | 44 | #if defined(__AVR_ATmega1280__) 45 | ring_buffer rx_buffer1 = { { 0 }, 0, 0 }; 46 | ring_buffer rx_buffer2 = { { 0 }, 0, 0 }; 47 | ring_buffer rx_buffer3 = { { 0 }, 0, 0 }; 48 | #endif 49 | 50 | inline void store_char(unsigned char c, ring_buffer *rx_buffer) 51 | { 52 | int i = (rx_buffer->head + 1) % RX_BUFFER_SIZE; 53 | 54 | // if we should be storing the received character into the location 55 | // just before the tail (meaning that the head would advance to the 56 | // current location of the tail), we're about to overflow the buffer 57 | // and so we don't write the character or advance the head. 58 | if (i != rx_buffer->tail) { 59 | rx_buffer->buffer[rx_buffer->head] = c; 60 | rx_buffer->head = i; 61 | } 62 | } 63 | 64 | inline void HardwareSerial::store_char(unsigned char c) 65 | { 66 | int i = (_rx_buffer->head + 1) % RX_BUFFER_SIZE; 67 | 68 | // if we should be storing the received character into the location 69 | // just before the tail (meaning that the head would advance to the 70 | // current location of the tail), we're about to overflow the buffer 71 | // and so we don't write the character or advance the head. 72 | if (i != _rx_buffer->tail) { 73 | _rx_buffer->buffer[_rx_buffer->head] = c; 74 | _rx_buffer->head = i; 75 | } 76 | if (recv_handler) { 77 | recv_handler(this, c); 78 | } 79 | } 80 | 81 | 82 | #if defined(__AVR_ATmega1280__) 83 | 84 | SIGNAL(SIG_USART0_RECV) 85 | { 86 | unsigned char c = UDR0; 87 | Serial.store_char(c); 88 | } 89 | 90 | SIGNAL(SIG_USART1_RECV) 91 | { 92 | unsigned char c = UDR1; 93 | Serial1.store_char(c); 94 | } 95 | 96 | SIGNAL(SIG_USART2_RECV) 97 | { 98 | unsigned char c = UDR2; 99 | Serial2.store_char(c); 100 | } 101 | 102 | SIGNAL(SIG_USART3_RECV) 103 | { 104 | unsigned char c = UDR3; 105 | Serial3.store_char(c); 106 | } 107 | 108 | #else 109 | 110 | #if defined(__AVR_ATmega8__) 111 | SIGNAL(SIG_UART_RECV) 112 | #else 113 | SIGNAL(USART_RX_vect) 114 | #endif 115 | { 116 | #if defined(__AVR_ATmega8__) 117 | unsigned char c = UDR; 118 | #else 119 | unsigned char c = UDR0; 120 | #endif 121 | Serial.store_char(c); 122 | } 123 | 124 | #endif 125 | 126 | // Constructors //////////////////////////////////////////////////////////////// 127 | 128 | HardwareSerial::HardwareSerial(ring_buffer *rx_buffer, 129 | volatile uint8_t *ubrrh, volatile uint8_t *ubrrl, 130 | volatile uint8_t *ucsra, volatile uint8_t *ucsrb, 131 | volatile uint8_t *udr, 132 | uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x) 133 | { 134 | _rx_buffer = rx_buffer; 135 | _ubrrh = ubrrh; 136 | _ubrrl = ubrrl; 137 | _ucsra = ucsra; 138 | _ucsrb = ucsrb; 139 | _udr = udr; 140 | _rxen = rxen; 141 | _txen = txen; 142 | _rxcie = rxcie; 143 | _udre = udre; 144 | _u2x = u2x; 145 | } 146 | 147 | // Public Methods ////////////////////////////////////////////////////////////// 148 | 149 | void HardwareSerial::begin(long baud) 150 | { 151 | uint16_t baud_setting; 152 | bool use_u2x; 153 | 154 | // U2X mode is needed for baud rates higher than (CPU Hz / 16) 155 | if (baud > F_CPU / 16) { 156 | use_u2x = true; 157 | } else { 158 | // figure out if U2X mode would allow for a better connection 159 | 160 | // calculate the percent difference between the baud-rate specified and 161 | // the real baud rate for both U2X and non-U2X mode (0-255 error percent) 162 | uint8_t nonu2x_baud_error = abs((int)(255-((F_CPU/(16*(((F_CPU/8/baud-1)/2)+1))*255)/baud))); 163 | uint8_t u2x_baud_error = abs((int)(255-((F_CPU/(8*(((F_CPU/4/baud-1)/2)+1))*255)/baud))); 164 | 165 | // prefer non-U2X mode because it handles clock skew better 166 | use_u2x = (nonu2x_baud_error > u2x_baud_error); 167 | } 168 | 169 | if (use_u2x) { 170 | *_ucsra = 1 << _u2x; 171 | baud_setting = (F_CPU / 4 / baud - 1) / 2; 172 | } else { 173 | *_ucsra = 0; 174 | baud_setting = (F_CPU / 8 / baud - 1) / 2; 175 | } 176 | 177 | // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register) 178 | *_ubrrh = baud_setting >> 8; 179 | *_ubrrl = baud_setting; 180 | 181 | sbi(*_ucsrb, _rxen); 182 | sbi(*_ucsrb, _txen); 183 | sbi(*_ucsrb, _rxcie); 184 | } 185 | 186 | uint8_t HardwareSerial::available(void) 187 | { 188 | return (RX_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % RX_BUFFER_SIZE; 189 | } 190 | 191 | int HardwareSerial::read(void) 192 | { 193 | // if the head isn't ahead of the tail, we don't have any characters 194 | if (_rx_buffer->head == _rx_buffer->tail) { 195 | return -1; 196 | } else { 197 | unsigned char c = _rx_buffer->buffer[_rx_buffer->tail]; 198 | _rx_buffer->tail = (_rx_buffer->tail + 1) % RX_BUFFER_SIZE; 199 | return c; 200 | } 201 | } 202 | 203 | void HardwareSerial::flush() 204 | { 205 | // don't reverse this or there may be problems if the RX interrupt 206 | // occurs after reading the value of rx_buffer_head but before writing 207 | // the value to rx_buffer_tail; the previous value of rx_buffer_head 208 | // may be written to rx_buffer_tail, making it appear as if the buffer 209 | // don't reverse this or there may be problems if the RX interrupt 210 | // occurs after reading the value of rx_buffer_head but before writing 211 | // the value to rx_buffer_tail; the previous value of rx_buffer_head 212 | // may be written to rx_buffer_tail, making it appear as if the buffer 213 | // were full, not empty. 214 | _rx_buffer->head = _rx_buffer->tail; 215 | } 216 | 217 | void HardwareSerial::write(uint8_t c) 218 | { 219 | while (!((*_ucsra) & (1 << _udre))) 220 | ; 221 | 222 | *_udr = c; 223 | } 224 | 225 | // Preinstantiate Objects ////////////////////////////////////////////////////// 226 | 227 | #if defined(__AVR_ATmega8__) 228 | HardwareSerial Serial(&rx_buffer, &UBRRH, &UBRRL, &UCSRA, &UCSRB, &UDR, RXEN, TXEN, RXCIE, UDRE, U2X); 229 | #else 230 | HardwareSerial Serial(&rx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRE0, U2X0); 231 | #endif 232 | 233 | #if defined(__AVR_ATmega1280__) 234 | HardwareSerial Serial1(&rx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UDR1, RXEN1, TXEN1, RXCIE1, UDRE1, U2X1); 235 | HardwareSerial Serial2(&rx_buffer2, &UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UDR2, RXEN2, TXEN2, RXCIE2, UDRE2, U2X2); 236 | HardwareSerial Serial3(&rx_buffer3, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UDR3, RXEN3, TXEN3, RXCIE3, UDRE3, U2X3); 237 | #endif 238 | -------------------------------------------------------------------------------- /arduino.DuinOS/wiring.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring.c - Partial implementation of the Wiring API for the ATmega8. 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.c 585 2009-05-12 10:55:26Z dmellis $ 23 | */ 24 | 25 | #include "wiring_private.h" 26 | 27 | // the prescaler is set so that timer0 ticks every 64 clock cycles, and the 28 | // the overflow handler is called every 256 ticks. 29 | #define MICROSECONDS_PER_TIMER0_OVERFLOW (clockCyclesToMicroseconds(64 * 256)) 30 | 31 | // the whole number of milliseconds per timer0 overflow 32 | #define MILLIS_INC (MICROSECONDS_PER_TIMER0_OVERFLOW / 1000) 33 | 34 | // the fractional number of milliseconds per timer0 overflow. we shift right 35 | // by three to fit these numbers into a byte. (for the clock speeds we care 36 | // about - 8 and 16 MHz - this doesn't lose precision.) 37 | #define FRACT_INC ((MICROSECONDS_PER_TIMER0_OVERFLOW % 1000) >> 3) 38 | #define FRACT_MAX (1000 >> 3) 39 | 40 | volatile unsigned long timer0_overflow_count = 0; 41 | volatile unsigned long timer0_millis = 0; 42 | static unsigned char timer0_fract = 0; 43 | 44 | SIGNAL(TIMER0_OVF_vect) 45 | { 46 | // copy these to local variables so they can be stored in registers 47 | // (volatile variables must be read from memory on every access) 48 | unsigned long m = timer0_millis; 49 | unsigned char f = timer0_fract; 50 | 51 | m += MILLIS_INC; 52 | f += FRACT_INC; 53 | if (f >= FRACT_MAX) { 54 | f -= FRACT_MAX; 55 | m += 1; 56 | } 57 | 58 | timer0_fract = f; 59 | timer0_millis = m; 60 | timer0_overflow_count++; 61 | } 62 | 63 | unsigned long millis() 64 | { 65 | unsigned long m; 66 | uint8_t oldSREG = SREG; 67 | 68 | // disable interrupts while we read timer0_millis or we might get an 69 | // inconsistent value (e.g. in the middle of a write to timer0_millis) 70 | cli(); 71 | m = timer0_millis; 72 | SREG = oldSREG; 73 | 74 | return m; 75 | } 76 | 77 | unsigned long micros() { 78 | unsigned long m, t; 79 | uint8_t oldSREG = SREG; 80 | 81 | cli(); 82 | t = TCNT0; 83 | 84 | #ifdef TIFR0 85 | if ((TIFR0 & _BV(TOV0)) && (t == 0)) 86 | t = 256; 87 | #else 88 | if ((TIFR & _BV(TOV0)) && (t == 0)) 89 | t = 256; 90 | #endif 91 | 92 | m = timer0_overflow_count; 93 | SREG = oldSREG; 94 | 95 | return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond()); 96 | } 97 | 98 | //##DuinOS overrides this function with a macro (DuinOS.h) 99 | //void delay(unsigned long ms) 100 | 101 | 102 | /* Delay for the given number of microseconds. Assumes a 8 or 16 MHz clock. 103 | * Disables interrupts, which will disrupt the millis() function if used 104 | * too frequently. */ 105 | void delayMicroseconds(unsigned int us) 106 | { 107 | uint8_t oldSREG; 108 | 109 | // calling avrlib's delay_us() function with low values (e.g. 1 or 110 | // 2 microseconds) gives delays longer than desired. 111 | //delay_us(us); 112 | 113 | #if F_CPU >= 16000000L 114 | // for the 16 MHz clock on most Arduino boards 115 | 116 | // for a one-microsecond delay, simply return. the overhead 117 | // of the function call yields a delay of approximately 1 1/8 us. 118 | if (--us == 0) 119 | return; 120 | 121 | // the following loop takes a quarter of a microsecond (4 cycles) 122 | // per iteration, so execute it four times for each microsecond of 123 | // delay requested. 124 | us <<= 2; 125 | 126 | // account for the time taken in the preceeding commands. 127 | us -= 2; 128 | #else 129 | // for the 8 MHz internal clock on the ATmega168 130 | 131 | // for a one- or two-microsecond delay, simply return. the overhead of 132 | // the function calls takes more than two microseconds. can't just 133 | // subtract two, since us is unsigned; we'd overflow. 134 | if (--us == 0) 135 | return; 136 | if (--us == 0) 137 | return; 138 | 139 | // the following loop takes half of a microsecond (4 cycles) 140 | // per iteration, so execute it twice for each microsecond of 141 | // delay requested. 142 | us <<= 1; 143 | 144 | // partially compensate for the time taken by the preceeding commands. 145 | // we can't subtract any more than this or we'd overflow w/ small delays. 146 | us--; 147 | #endif 148 | 149 | // disable interrupts, otherwise the timer 0 overflow interrupt that 150 | // tracks milliseconds will make us delay longer than we want. 151 | oldSREG = SREG; 152 | cli(); 153 | 154 | // busy wait 155 | __asm__ __volatile__ ( 156 | "1: sbiw %0,1" "\n\t" // 2 cycles 157 | "brne 1b" : "=w" (us) : "0" (us) // 2 cycles 158 | ); 159 | 160 | // reenable interrupts. 161 | SREG = oldSREG; 162 | } 163 | 164 | 165 | void init() 166 | { 167 | // this needs to be called before setup() or some functions won't 168 | // work there 169 | sei(); 170 | 171 | // on the ATmega168, timer 0 is also used for fast hardware pwm 172 | // (using phase-correct PWM would mean that timer 0 overflowed half as often 173 | // resulting in different millis() behavior on the ATmega8 and ATmega168) 174 | #if !defined(__AVR_ATmega8__) 175 | sbi(TCCR0A, WGM01); 176 | sbi(TCCR0A, WGM00); 177 | #endif 178 | // set timer 0 prescale factor to 64 179 | #if defined(__AVR_ATmega8__) 180 | sbi(TCCR0, CS01); 181 | sbi(TCCR0, CS00); 182 | #else 183 | sbi(TCCR0B, CS01); 184 | sbi(TCCR0B, CS00); 185 | #endif 186 | // enable timer 0 overflow interrupt 187 | #if defined(__AVR_ATmega8__) 188 | sbi(TIMSK, TOIE0); 189 | #else 190 | sbi(TIMSK0, TOIE0); 191 | #endif 192 | 193 | //##DuinOS: This commented code is the only difference with the standard init() function 194 | //(DuinOS uses the timer 1 for the preemptive kernel): 195 | /* 196 | // timers 1 and 2 are used for phase-correct hardware pwm 197 | // this is better for motors as it ensures an even waveform 198 | // note, however, that fast pwm mode can achieve a frequency of up 199 | // 8 MHz (with a 16 MHz clock) at 50% duty cycle 200 | sbi(TCCR1B, CS11);\ 201 | sbi(TCCR1B, CS10);\ 202 | sbi(TCCR1A, WGM10);\ 203 | */ 204 | 205 | // set timer 2 prescale factor to 64 206 | #if defined(__AVR_ATmega8__) 207 | sbi(TCCR2, CS22); 208 | #else 209 | sbi(TCCR2B, CS22); 210 | #endif 211 | // configure timer 2 for phase correct pwm (8-bit) 212 | #if defined(__AVR_ATmega8__) 213 | sbi(TCCR2, WGM20); 214 | #else 215 | sbi(TCCR2A, WGM20); 216 | #endif 217 | 218 | #if defined(__AVR_ATmega1280__) 219 | // set timer 3, 4, 5 prescale factor to 64 220 | sbi(TCCR3B, CS31); sbi(TCCR3B, CS30); 221 | sbi(TCCR4B, CS41); sbi(TCCR4B, CS40); 222 | sbi(TCCR5B, CS51); sbi(TCCR5B, CS50); 223 | // put timer 3, 4, 5 in 8-bit phase correct pwm mode 224 | sbi(TCCR3A, WGM30); 225 | sbi(TCCR4A, WGM40); 226 | sbi(TCCR5A, WGM50); 227 | #endif 228 | 229 | // set a2d prescale factor to 128 230 | // 16 MHz / 128 = 125 KHz, inside the desired 50-200 KHz range. 231 | // XXX: this will not work properly for other clock speeds, and 232 | // this code should use F_CPU to determine the prescale factor. 233 | sbi(ADCSRA, ADPS2); 234 | sbi(ADCSRA, ADPS1); 235 | sbi(ADCSRA, ADPS0); 236 | 237 | // enable a2d conversions 238 | sbi(ADCSRA, ADEN); 239 | 240 | // the bootloader connects pins 0 and 1 to the USART; disconnect them 241 | // here so they can be used as normal digital i/o; they will be 242 | // reconnected in Serial.begin() 243 | #if defined(__AVR_ATmega8__) 244 | UCSRB = 0; 245 | #else 246 | UCSR0B = 0; 247 | #endif 248 | } 249 | -------------------------------------------------------------------------------- /arduino.DuinOS/DuinOS/list.c: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V5.4.2 - Copyright (C) 2009 Real Time Engineers Ltd. 3 | 4 | This file is part of the FreeRTOS distribution. 5 | 6 | FreeRTOS is free software; you can redistribute it and/or modify it under 7 | the terms of the GNU General Public License (version 2) as published by the 8 | Free Software Foundation and modified by the FreeRTOS exception. 9 | **NOTE** The exception to the GPL is included to allow you to distribute a 10 | combined work that includes FreeRTOS without being obliged to provide the 11 | source code for proprietary components outside of the FreeRTOS kernel. 12 | Alternative commercial license and support terms are also available upon 13 | request. See the licensing section of http://www.FreeRTOS.org for full 14 | license details. 15 | 16 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 19 | more details. 20 | 21 | You should have received a copy of the GNU General Public License along 22 | with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59 23 | Temple Place, Suite 330, Boston, MA 02111-1307 USA. 24 | 25 | 26 | *************************************************************************** 27 | * * 28 | * Looking for a quick start? Then check out the FreeRTOS eBook! * 29 | * See http://www.FreeRTOS.org/Documentation for details * 30 | * * 31 | *************************************************************************** 32 | 33 | 1 tab == 4 spaces! 34 | 35 | Please ensure to read the configuration and relevant port sections of the 36 | online documentation. 37 | 38 | http://www.FreeRTOS.org - Documentation, latest information, license and 39 | contact details. 40 | 41 | http://www.SafeRTOS.com - A version that is certified for use in safety 42 | critical systems. 43 | 44 | http://www.OpenRTOS.com - Commercial support, development, porting, 45 | licensing and training services. 46 | */ 47 | 48 | 49 | #include 50 | #include "FreeRTOS.h" 51 | #include "list.h" 52 | 53 | /*----------------------------------------------------------- 54 | * PUBLIC LIST API documented in list.h 55 | *----------------------------------------------------------*/ 56 | 57 | void vListInitialise( xList *pxList ) 58 | { 59 | /* The list structure contains a list item which is used to mark the 60 | end of the list. To initialise the list the list end is inserted 61 | as the only list entry. */ 62 | pxList->pxIndex = ( xListItem * ) &( pxList->xListEnd ); 63 | 64 | /* The list end value is the highest possible value in the list to 65 | ensure it remains at the end of the list. */ 66 | pxList->xListEnd.xItemValue = portMAX_DELAY; 67 | 68 | /* The list end next and previous pointers point to itself so we know 69 | when the list is empty. */ 70 | pxList->xListEnd.pxNext = ( xListItem * ) &( pxList->xListEnd ); 71 | pxList->xListEnd.pxPrevious = ( xListItem * ) &( pxList->xListEnd ); 72 | 73 | pxList->uxNumberOfItems = 0; 74 | } 75 | /*-----------------------------------------------------------*/ 76 | 77 | void vListInitialiseItem( xListItem *pxItem ) 78 | { 79 | /* Make sure the list item is not recorded as being on a list. */ 80 | pxItem->pvContainer = NULL; 81 | } 82 | /*-----------------------------------------------------------*/ 83 | 84 | void vListInsertEnd( xList *pxList, xListItem *pxNewListItem ) 85 | { 86 | volatile xListItem * pxIndex; 87 | 88 | /* Insert a new list item into pxList, but rather than sort the list, 89 | makes the new list item the last item to be removed by a call to 90 | pvListGetOwnerOfNextEntry. This means it has to be the item pointed to by 91 | the pxIndex member. */ 92 | pxIndex = pxList->pxIndex; 93 | 94 | pxNewListItem->pxNext = pxIndex->pxNext; 95 | pxNewListItem->pxPrevious = pxList->pxIndex; 96 | pxIndex->pxNext->pxPrevious = ( volatile xListItem * ) pxNewListItem; 97 | pxIndex->pxNext = ( volatile xListItem * ) pxNewListItem; 98 | pxList->pxIndex = ( volatile xListItem * ) pxNewListItem; 99 | 100 | /* Remember which list the item is in. */ 101 | pxNewListItem->pvContainer = ( void * ) pxList; 102 | 103 | ( pxList->uxNumberOfItems )++; 104 | } 105 | /*-----------------------------------------------------------*/ 106 | 107 | void vListInsert( xList *pxList, xListItem *pxNewListItem ) 108 | { 109 | volatile xListItem *pxIterator; 110 | portTickType xValueOfInsertion; 111 | 112 | /* Insert the new list item into the list, sorted in ulListItem order. */ 113 | xValueOfInsertion = pxNewListItem->xItemValue; 114 | 115 | /* If the list already contains a list item with the same item value then 116 | the new list item should be placed after it. This ensures that TCB's which 117 | are stored in ready lists (all of which have the same ulListItem value) 118 | get an equal share of the CPU. However, if the xItemValue is the same as 119 | the back marker the iteration loop below will not end. This means we need 120 | to guard against this by checking the value first and modifying the 121 | algorithm slightly if necessary. */ 122 | if( xValueOfInsertion == portMAX_DELAY ) 123 | { 124 | pxIterator = pxList->xListEnd.pxPrevious; 125 | } 126 | else 127 | { 128 | /* *** NOTE *********************************************************** 129 | If you find your application is crashing here then likely causes are: 130 | 1) Stack overflow - 131 | see http://www.freertos.org/Stacks-and-stack-overflow-checking.html 132 | 2) Incorrect interrupt priority assignment, especially on Cortex M3 133 | parts where numerically high priority values denote low actual 134 | interrupt priories, which can seem counter intuitive. See 135 | configMAX_SYSCALL_INTERRUPT_PRIORITY on http://www.freertos.org/a00110.html 136 | 3) Calling an API function from within a critical section or when 137 | the scheduler is suspended. 138 | 4) Using a queue or semaphore before it has been initialised or 139 | before the scheduler has been started (are interrupts firing 140 | before vTaskStartScheduler() has been called?). 141 | See http://www.freertos.org/FAQHelp.html for more tips. 142 | **********************************************************************/ 143 | 144 | for( pxIterator = ( xListItem * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) 145 | { 146 | /* There is nothing to do here, we are just iterating to the 147 | wanted insertion position. */ 148 | } 149 | } 150 | 151 | pxNewListItem->pxNext = pxIterator->pxNext; 152 | pxNewListItem->pxNext->pxPrevious = ( volatile xListItem * ) pxNewListItem; 153 | pxNewListItem->pxPrevious = pxIterator; 154 | pxIterator->pxNext = ( volatile xListItem * ) pxNewListItem; 155 | 156 | /* Remember which list the item is in. This allows fast removal of the 157 | item later. */ 158 | pxNewListItem->pvContainer = ( void * ) pxList; 159 | 160 | ( pxList->uxNumberOfItems )++; 161 | } 162 | /*-----------------------------------------------------------*/ 163 | 164 | void vListRemove( xListItem *pxItemToRemove ) 165 | { 166 | xList * pxList; 167 | 168 | pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious; 169 | pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext; 170 | 171 | /* The list item knows which list it is in. Obtain the list from the list 172 | item. */ 173 | pxList = ( xList * ) pxItemToRemove->pvContainer; 174 | 175 | /* Make sure the index is left pointing to a valid item. */ 176 | if( pxList->pxIndex == pxItemToRemove ) 177 | { 178 | pxList->pxIndex = pxItemToRemove->pxPrevious; 179 | } 180 | 181 | pxItemToRemove->pvContainer = NULL; 182 | ( pxList->uxNumberOfItems )--; 183 | } 184 | /*-----------------------------------------------------------*/ 185 | 186 | -------------------------------------------------------------------------------- /arduino.DuinOS/DuinOS/StackMacros.h: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V5.4.2 - Copyright (C) 2009 Real Time Engineers Ltd. 3 | 4 | This file is part of the FreeRTOS distribution. 5 | 6 | FreeRTOS is free software; you can redistribute it and/or modify it under 7 | the terms of the GNU General Public License (version 2) as published by the 8 | Free Software Foundation and modified by the FreeRTOS exception. 9 | **NOTE** The exception to the GPL is included to allow you to distribute a 10 | combined work that includes FreeRTOS without being obliged to provide the 11 | source code for proprietary components outside of the FreeRTOS kernel. 12 | Alternative commercial license and support terms are also available upon 13 | request. See the licensing section of http://www.FreeRTOS.org for full 14 | license details. 15 | 16 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 19 | more details. 20 | 21 | You should have received a copy of the GNU General Public License along 22 | with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59 23 | Temple Place, Suite 330, Boston, MA 02111-1307 USA. 24 | 25 | 26 | *************************************************************************** 27 | * * 28 | * Looking for a quick start? Then check out the FreeRTOS eBook! * 29 | * See http://www.FreeRTOS.org/Documentation for details * 30 | * * 31 | *************************************************************************** 32 | 33 | 1 tab == 4 spaces! 34 | 35 | Please ensure to read the configuration and relevant port sections of the 36 | online documentation. 37 | 38 | http://www.FreeRTOS.org - Documentation, latest information, license and 39 | contact details. 40 | 41 | http://www.SafeRTOS.com - A version that is certified for use in safety 42 | critical systems. 43 | 44 | http://www.OpenRTOS.com - Commercial support, development, porting, 45 | licensing and training services. 46 | */ 47 | 48 | #ifndef STACK_MACROS_H 49 | #define STACK_MACROS_H 50 | 51 | /* 52 | * Call the stack overflow hook function if the stack of the task being swapped 53 | * out is currently overflowed, or looks like it might have overflowed in the 54 | * past. 55 | * 56 | * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check 57 | * the current stack state only - comparing the current top of stack value to 58 | * the stack limit. Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1 59 | * will also cause the last few stack bytes to be checked to ensure the value 60 | * to which the bytes were set when the task was created have not been 61 | * overwritten. Note this second test does not guarantee that an overflowed 62 | * stack will always be recognised. 63 | */ 64 | 65 | /*-----------------------------------------------------------*/ 66 | 67 | #if( configCHECK_FOR_STACK_OVERFLOW == 0 ) 68 | 69 | /* FreeRTOSConfig.h is not set to check for stack overflows. */ 70 | #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() 71 | #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() 72 | 73 | #endif /* configCHECK_FOR_STACK_OVERFLOW == 0 */ 74 | /*-----------------------------------------------------------*/ 75 | 76 | #if( configCHECK_FOR_STACK_OVERFLOW == 1 ) 77 | 78 | /* FreeRTOSConfig.h is only set to use the first method of 79 | overflow checking. */ 80 | #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() 81 | 82 | #endif 83 | /*-----------------------------------------------------------*/ 84 | 85 | #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH < 0 ) ) 86 | 87 | /* Only the current stack state is to be checked. */ 88 | #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() \ 89 | { \ 90 | extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName ); \ 91 | \ 92 | /* Is the currently saved stack pointer within the stack limit? */ \ 93 | if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack ) \ 94 | { \ 95 | vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 96 | } \ 97 | } 98 | 99 | #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ 100 | /*-----------------------------------------------------------*/ 101 | 102 | #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH > 0 ) ) 103 | 104 | /* Only the current stack state is to be checked. */ 105 | #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() \ 106 | { \ 107 | extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName ); \ 108 | \ 109 | /* Is the currently saved stack pointer within the stack limit? */ \ 110 | if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack ) \ 111 | { \ 112 | vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 113 | } \ 114 | } 115 | 116 | #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ 117 | /*-----------------------------------------------------------*/ 118 | 119 | #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) ) 120 | 121 | #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() \ 122 | { \ 123 | extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName ); \ 124 | static const unsigned portCHAR ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 125 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 126 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 127 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 128 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ 129 | \ 130 | \ 131 | /* Has the extremity of the task stack ever been written over? */ \ 132 | if( memcmp( ( void * ) pxCurrentTCB->pxStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \ 133 | { \ 134 | vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 135 | } \ 136 | } 137 | 138 | #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ 139 | /*-----------------------------------------------------------*/ 140 | 141 | #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) ) 142 | 143 | #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() \ 144 | { \ 145 | extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName ); \ 146 | portCHAR *pcEndOfStack = ( portCHAR * ) pxCurrentTCB->pxEndOfStack; \ 147 | static const unsigned portCHAR ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 148 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 149 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 150 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 151 | tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ 152 | \ 153 | \ 154 | pcEndOfStack -= sizeof( ucExpectedStackBytes ); \ 155 | \ 156 | /* Has the extremity of the task stack ever been written over? */ \ 157 | if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \ 158 | { \ 159 | vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ 160 | } \ 161 | } 162 | 163 | #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ 164 | /*-----------------------------------------------------------*/ 165 | 166 | #endif /* STACK_MACROS_H */ 167 | 168 | -------------------------------------------------------------------------------- /ide/boards.txt: -------------------------------------------------------------------------------- 1 | ############################################################## 2 | 3 | atmega328.name=Arduino Duemilanove or Nano w/ ATmega328 4 | 5 | atmega328.upload.protocol=stk500 6 | atmega328.upload.maximum_size=30720 7 | atmega328.upload.speed=57600 8 | 9 | atmega328.bootloader.low_fuses=0xFF 10 | atmega328.bootloader.high_fuses=0xDA 11 | atmega328.bootloader.extended_fuses=0x05 12 | atmega328.bootloader.path=atmega 13 | atmega328.bootloader.file=ATmegaBOOT_168_atmega328.hex 14 | atmega328.bootloader.unlock_bits=0x3F 15 | atmega328.bootloader.lock_bits=0x0F 16 | 17 | atmega328.build.mcu=atmega328p 18 | atmega328.build.f_cpu=16000000L 19 | atmega328.build.core=arduino 20 | 21 | ############################################################## 22 | 23 | atmega328_DuinOS.name=Arduino Duemilanove or Nano w/ ATmega328 + DuinOS 24 | 25 | atmega328_DuinOS.upload.protocol=stk500 26 | atmega328_DuinOS.upload.maximum_size=30720 27 | atmega328_DuinOS.upload.speed=57600 28 | 29 | atmega328_DuinOS.bootloader.low_fuses=0xFF 30 | atmega328_DuinOS.bootloader.high_fuses=0xDA 31 | atmega328_DuinOS.bootloader.extended_fuses=0x05 32 | atmega328_DuinOS.bootloader.path=atmega 33 | atmega328_DuinOS.bootloader.file=ATmegaBOOT_168_atmega328.hex 34 | atmega328_DuinOS.bootloader.unlock_bits=0x3F 35 | atmega328_DuinOS.bootloader.lock_bits=0x0F 36 | 37 | atmega328_DuinOS.build.mcu=atmega328p 38 | atmega328_DuinOS.build.f_cpu=16000000L 39 | atmega328_DuinOS.build.core=arduino.DuinOS 40 | 41 | ############################################################## 42 | 43 | diecimila.name=Arduino Diecimila, Duemilanove, or Nano w/ ATmega168 44 | 45 | diecimila.upload.protocol=stk500 46 | diecimila.upload.maximum_size=14336 47 | diecimila.upload.speed=19200 48 | 49 | diecimila.bootloader.low_fuses=0xff 50 | diecimila.bootloader.high_fuses=0xdd 51 | diecimila.bootloader.extended_fuses=0x00 52 | diecimila.bootloader.path=atmega 53 | diecimila.bootloader.file=ATmegaBOOT_168_diecimila.hex 54 | diecimila.bootloader.unlock_bits=0x3F 55 | diecimila.bootloader.lock_bits=0x0F 56 | 57 | diecimila.build.mcu=atmega168 58 | diecimila.build.f_cpu=16000000L 59 | diecimila.build.core=arduino 60 | 61 | ############################################################## 62 | 63 | diecimila_DuinOS.name=Arduino Diecimila, Duemilanove, or Nano w/ ATmega168 + DuinOS 64 | 65 | diecimila_DuinOS.upload.protocol=stk500 66 | diecimila_DuinOS.upload.maximum_size=14336 67 | diecimila_DuinOS.upload.speed=19200 68 | 69 | diecimila_DuinOS.bootloader.low_fuses=0xff 70 | diecimila_DuinOS.bootloader.high_fuses=0xdd 71 | diecimila_DuinOS.bootloader.extended_fuses=0x00 72 | diecimila_DuinOS.bootloader.path=atmega 73 | diecimila_DuinOS.bootloader.file=ATmegaBOOT_168_diecimila.hex 74 | diecimila_DuinOS.bootloader.unlock_bits=0x3F 75 | diecimila_DuinOS.bootloader.lock_bits=0x0F 76 | 77 | diecimila_DuinOS.build.mcu=atmega168 78 | diecimila_DuinOS.build.f_cpu=16000000L 79 | diecimila_DuinOS.build.core=arduino.DuinOS 80 | 81 | ############################################################## 82 | 83 | mega.name=Arduino Mega 84 | 85 | mega.upload.protocol=stk500 86 | mega.upload.maximum_size=126976 87 | mega.upload.speed=57600 88 | 89 | mega.bootloader.low_fuses=0xFF 90 | mega.bootloader.high_fuses=0xDA 91 | mega.bootloader.extended_fuses=0xF5 92 | mega.bootloader.path=atmega 93 | mega.bootloader.file=ATmegaBOOT_168_atmega1280.hex 94 | mega.bootloader.unlock_bits=0x3F 95 | mega.bootloader.lock_bits=0x0F 96 | 97 | mega.build.mcu=atmega1280 98 | mega.build.f_cpu=16000000L 99 | mega.build.core=arduino 100 | 101 | ############################################################## 102 | 103 | mega_DuinOS.name=Arduino Mega + DuinOS 104 | 105 | mega_DuinOS.upload.protocol=stk500 106 | mega_DuinOS.upload.maximum_size=126976 107 | mega_DuinOS.upload.speed=57600 108 | 109 | mega_DuinOS.bootloader.low_fuses=0xFF 110 | mega_DuinOS.bootloader.high_fuses=0xDA 111 | mega_DuinOS.bootloader.extended_fuses=0xF5 112 | mega_DuinOS.bootloader.path=atmega 113 | mega_DuinOS.bootloader.file=ATmegaBOOT_168_atmega1280.hex 114 | mega_DuinOS.bootloader.unlock_bits=0x3F 115 | mega_DuinOS.bootloader.lock_bits=0x0F 116 | 117 | mega_DuinOS.build.mcu=atmega1280 118 | mega_DuinOS.build.f_cpu=16000000L 119 | mega_DuinOS.build.core=arduino.DuinOS 120 | 121 | ############################################################## 122 | 123 | mini.name=Arduino Mini 124 | 125 | mini.upload.protocol=stk500 126 | mini.upload.maximum_size=14336 127 | mini.upload.speed=19200 128 | 129 | mini.bootloader.low_fuses=0xff 130 | mini.bootloader.high_fuses=0xdd 131 | mini.bootloader.extended_fuses=0x00 132 | mini.bootloader.path=atmega 133 | mini.bootloader.file=ATmegaBOOT_168_ng.hex 134 | mini.bootloader.unlock_bits=0x3F 135 | mini.bootloader.lock_bits=0x0F 136 | 137 | mini.build.mcu=atmega168 138 | mini.build.f_cpu=16000000L 139 | mini.build.core=arduino 140 | 141 | ############################################################## 142 | 143 | bt.name=Arduino BT 144 | 145 | bt.upload.protocol=stk500 146 | bt.upload.maximum_size=14336 147 | bt.upload.speed=19200 148 | bt.upload.disable_flushing=true 149 | 150 | bt.bootloader.low_fuses=0xff 151 | bt.bootloader.high_fuses=0xdd 152 | bt.bootloader.extended_fuses=0x00 153 | bt.bootloader.path=bt 154 | bt.bootloader.file=ATmegaBOOT_168.hex 155 | bt.bootloader.unlock_bits=0x3F 156 | bt.bootloader.lock_bits=0x0F 157 | 158 | bt.build.mcu=atmega168 159 | bt.build.f_cpu=16000000L 160 | bt.build.core=arduino 161 | 162 | ############################################################## 163 | 164 | lilypad328.name=LilyPad Arduino w/ ATmega328 165 | 166 | lilypad328.upload.protocol=stk500 167 | lilypad328.upload.maximum_size=30720 168 | lilypad328.upload.speed=57600 169 | 170 | lilypad328.bootloader.low_fuses=0xFF 171 | lilypad328.bootloader.high_fuses=0xDA 172 | lilypad328.bootloader.extended_fuses=0x05 173 | lilypad328.bootloader.path=atmega 174 | lilypad328.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex 175 | lilypad328.bootloader.unlock_bits=0x3F 176 | lilypad328.bootloader.lock_bits=0x0F 177 | 178 | lilypad328.build.mcu=atmega328p 179 | lilypad328.build.f_cpu=8000000L 180 | lilypad328.build.core=arduino 181 | 182 | ############################################################## 183 | 184 | lilypad.name=LilyPad Arduino w/ ATmega168 185 | 186 | lilypad.upload.protocol=stk500 187 | lilypad.upload.maximum_size=14336 188 | lilypad.upload.speed=19200 189 | 190 | lilypad.bootloader.low_fuses=0xe2 191 | lilypad.bootloader.high_fuses=0xdd 192 | lilypad.bootloader.extended_fuses=0x00 193 | lilypad.bootloader.path=lilypad 194 | lilypad.bootloader.file=LilyPadBOOT_168.hex 195 | lilypad.bootloader.unlock_bits=0x3F 196 | lilypad.bootloader.lock_bits=0x0F 197 | 198 | lilypad.build.mcu=atmega168 199 | lilypad.build.f_cpu=8000000L 200 | lilypad.build.core=arduino 201 | 202 | ############################################################## 203 | 204 | pro328.name=Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328 205 | 206 | pro328.upload.protocol=stk500 207 | pro328.upload.maximum_size=30720 208 | pro328.upload.speed=57600 209 | 210 | pro328.bootloader.low_fuses=0xFF 211 | pro328.bootloader.high_fuses=0xDA 212 | pro328.bootloader.extended_fuses=0x05 213 | pro328.bootloader.path=atmega 214 | pro328.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex 215 | pro328.bootloader.unlock_bits=0x3F 216 | pro328.bootloader.lock_bits=0x0F 217 | 218 | pro328.build.mcu=atmega328p 219 | pro328.build.f_cpu=8000000L 220 | pro328.build.core=arduino 221 | 222 | ############################################################## 223 | 224 | pro.name=Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega168 225 | 226 | pro.upload.protocol=stk500 227 | pro.upload.maximum_size=14336 228 | pro.upload.speed=19200 229 | 230 | pro.bootloader.low_fuses=0xc6 231 | pro.bootloader.high_fuses=0xdd 232 | pro.bootloader.extended_fuses=0x00 233 | pro.bootloader.path=atmega 234 | pro.bootloader.file=ATmegaBOOT_168_pro_8MHz.hex 235 | pro.bootloader.unlock_bits=0x3F 236 | pro.bootloader.lock_bits=0x0F 237 | 238 | pro.build.mcu=atmega168 239 | pro.build.f_cpu=8000000L 240 | pro.build.core=arduino 241 | 242 | ############################################################## 243 | 244 | atmega168.name=Arduino NG or older w/ ATmega168 245 | 246 | atmega168.upload.protocol=stk500 247 | atmega168.upload.maximum_size=14336 248 | atmega168.upload.speed=19200 249 | 250 | atmega168.bootloader.low_fuses=0xff 251 | atmega168.bootloader.high_fuses=0xdd 252 | atmega168.bootloader.extended_fuses=0x00 253 | atmega168.bootloader.path=atmega 254 | atmega168.bootloader.file=ATmegaBOOT_168_ng.hex 255 | atmega168.bootloader.unlock_bits=0x3F 256 | atmega168.bootloader.lock_bits=0x0F 257 | 258 | atmega168.build.mcu=atmega168 259 | atmega168.build.f_cpu=16000000L 260 | atmega168.build.core=arduino 261 | 262 | ############################################################## 263 | 264 | atmega8.name=Arduino NG or older w/ ATmega8 265 | 266 | atmega8.upload.protocol=stk500 267 | atmega8.upload.maximum_size=7168 268 | atmega8.upload.speed=19200 269 | 270 | atmega8.bootloader.low_fuses=0xdf 271 | atmega8.bootloader.high_fuses=0xca 272 | atmega8.bootloader.path=atmega8 273 | atmega8.bootloader.file=ATmegaBOOT.hex 274 | atmega8.bootloader.unlock_bits=0x3F 275 | atmega8.bootloader.lock_bits=0x0F 276 | 277 | atmega8.build.mcu=atmega8 278 | atmega8.build.f_cpu=16000000L 279 | atmega8.build.core=arduino 280 | 281 | -------------------------------------------------------------------------------- /hardware/boards.txt: -------------------------------------------------------------------------------- 1 | ############################################################## 2 | 3 | atmega328.name=Arduino Duemilanove or Nano w/ ATmega328 4 | 5 | atmega328.upload.protocol=stk500 6 | atmega328.upload.maximum_size=30720 7 | atmega328.upload.speed=57600 8 | 9 | atmega328.bootloader.low_fuses=0xFF 10 | atmega328.bootloader.high_fuses=0xDA 11 | atmega328.bootloader.extended_fuses=0x05 12 | atmega328.bootloader.path=atmega 13 | atmega328.bootloader.file=ATmegaBOOT_168_atmega328.hex 14 | atmega328.bootloader.unlock_bits=0x3F 15 | atmega328.bootloader.lock_bits=0x0F 16 | 17 | atmega328.build.mcu=atmega328p 18 | atmega328.build.f_cpu=16000000L 19 | atmega328.build.core=arduino 20 | 21 | ############################################################## 22 | 23 | atmega328_DuinOS.name=Arduino Duemilanove or Nano w/ ATmega328 + DuinOS 24 | 25 | atmega328_DuinOS.upload.protocol=stk500 26 | atmega328_DuinOS.upload.maximum_size=30720 27 | atmega328_DuinOS.upload.speed=57600 28 | 29 | atmega328_DuinOS.bootloader.low_fuses=0xFF 30 | atmega328_DuinOS.bootloader.high_fuses=0xDA 31 | atmega328_DuinOS.bootloader.extended_fuses=0x05 32 | atmega328_DuinOS.bootloader.path=atmega 33 | atmega328_DuinOS.bootloader.file=ATmegaBOOT_168_atmega328.hex 34 | atmega328_DuinOS.bootloader.unlock_bits=0x3F 35 | atmega328_DuinOS.bootloader.lock_bits=0x0F 36 | 37 | atmega328_DuinOS.build.mcu=atmega328p 38 | atmega328_DuinOS.build.f_cpu=16000000L 39 | atmega328_DuinOS.build.core=arduino.DuinOS 40 | 41 | ############################################################## 42 | 43 | diecimila.name=Arduino Diecimila, Duemilanove, or Nano w/ ATmega168 44 | 45 | diecimila.upload.protocol=stk500 46 | diecimila.upload.maximum_size=14336 47 | diecimila.upload.speed=19200 48 | 49 | diecimila.bootloader.low_fuses=0xff 50 | diecimila.bootloader.high_fuses=0xdd 51 | diecimila.bootloader.extended_fuses=0x00 52 | diecimila.bootloader.path=atmega 53 | diecimila.bootloader.file=ATmegaBOOT_168_diecimila.hex 54 | diecimila.bootloader.unlock_bits=0x3F 55 | diecimila.bootloader.lock_bits=0x0F 56 | 57 | diecimila.build.mcu=atmega168 58 | diecimila.build.f_cpu=16000000L 59 | diecimila.build.core=arduino 60 | 61 | ############################################################## 62 | 63 | diecimila_DuinOS.name=Arduino Diecimila, Duemilanove, or Nano w/ ATmega168 + DuinOS 64 | 65 | diecimila_DuinOS.upload.protocol=stk500 66 | diecimila_DuinOS.upload.maximum_size=14336 67 | diecimila_DuinOS.upload.speed=19200 68 | 69 | diecimila_DuinOS.bootloader.low_fuses=0xff 70 | diecimila_DuinOS.bootloader.high_fuses=0xdd 71 | diecimila_DuinOS.bootloader.extended_fuses=0x00 72 | diecimila_DuinOS.bootloader.path=atmega 73 | diecimila_DuinOS.bootloader.file=ATmegaBOOT_168_diecimila.hex 74 | diecimila_DuinOS.bootloader.unlock_bits=0x3F 75 | diecimila_DuinOS.bootloader.lock_bits=0x0F 76 | 77 | diecimila_DuinOS.build.mcu=atmega168 78 | diecimila_DuinOS.build.f_cpu=16000000L 79 | diecimila_DuinOS.build.core=arduino.DuinOS 80 | 81 | ############################################################## 82 | 83 | mega.name=Arduino Mega 84 | 85 | mega.upload.protocol=stk500 86 | mega.upload.maximum_size=126976 87 | mega.upload.speed=57600 88 | 89 | mega.bootloader.low_fuses=0xFF 90 | mega.bootloader.high_fuses=0xDA 91 | mega.bootloader.extended_fuses=0xF5 92 | mega.bootloader.path=atmega 93 | mega.bootloader.file=ATmegaBOOT_168_atmega1280.hex 94 | mega.bootloader.unlock_bits=0x3F 95 | mega.bootloader.lock_bits=0x0F 96 | 97 | mega.build.mcu=atmega1280 98 | mega.build.f_cpu=16000000L 99 | mega.build.core=arduino 100 | 101 | ############################################################## 102 | 103 | mega_DuinOS.name=Arduino Mega + DuinOS 104 | 105 | mega_DuinOS.upload.protocol=stk500 106 | mega_DuinOS.upload.maximum_size=126976 107 | mega_DuinOS.upload.speed=57600 108 | 109 | mega_DuinOS.bootloader.low_fuses=0xFF 110 | mega_DuinOS.bootloader.high_fuses=0xDA 111 | mega_DuinOS.bootloader.extended_fuses=0xF5 112 | mega_DuinOS.bootloader.path=atmega 113 | mega_DuinOS.bootloader.file=ATmegaBOOT_168_atmega1280.hex 114 | mega_DuinOS.bootloader.unlock_bits=0x3F 115 | mega_DuinOS.bootloader.lock_bits=0x0F 116 | 117 | mega_DuinOS.build.mcu=atmega1280 118 | mega_DuinOS.build.f_cpu=16000000L 119 | mega_DuinOS.build.core=arduino.DuinOS 120 | 121 | ############################################################## 122 | 123 | mini.name=Arduino Mini 124 | 125 | mini.upload.protocol=stk500 126 | mini.upload.maximum_size=14336 127 | mini.upload.speed=19200 128 | 129 | mini.bootloader.low_fuses=0xff 130 | mini.bootloader.high_fuses=0xdd 131 | mini.bootloader.extended_fuses=0x00 132 | mini.bootloader.path=atmega 133 | mini.bootloader.file=ATmegaBOOT_168_ng.hex 134 | mini.bootloader.unlock_bits=0x3F 135 | mini.bootloader.lock_bits=0x0F 136 | 137 | mini.build.mcu=atmega168 138 | mini.build.f_cpu=16000000L 139 | mini.build.core=arduino 140 | 141 | ############################################################## 142 | 143 | bt.name=Arduino BT 144 | 145 | bt.upload.protocol=stk500 146 | bt.upload.maximum_size=14336 147 | bt.upload.speed=19200 148 | bt.upload.disable_flushing=true 149 | 150 | bt.bootloader.low_fuses=0xff 151 | bt.bootloader.high_fuses=0xdd 152 | bt.bootloader.extended_fuses=0x00 153 | bt.bootloader.path=bt 154 | bt.bootloader.file=ATmegaBOOT_168.hex 155 | bt.bootloader.unlock_bits=0x3F 156 | bt.bootloader.lock_bits=0x0F 157 | 158 | bt.build.mcu=atmega168 159 | bt.build.f_cpu=16000000L 160 | bt.build.core=arduino 161 | 162 | ############################################################## 163 | 164 | lilypad328.name=LilyPad Arduino w/ ATmega328 165 | 166 | lilypad328.upload.protocol=stk500 167 | lilypad328.upload.maximum_size=30720 168 | lilypad328.upload.speed=57600 169 | 170 | lilypad328.bootloader.low_fuses=0xFF 171 | lilypad328.bootloader.high_fuses=0xDA 172 | lilypad328.bootloader.extended_fuses=0x05 173 | lilypad328.bootloader.path=atmega 174 | lilypad328.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex 175 | lilypad328.bootloader.unlock_bits=0x3F 176 | lilypad328.bootloader.lock_bits=0x0F 177 | 178 | lilypad328.build.mcu=atmega328p 179 | lilypad328.build.f_cpu=8000000L 180 | lilypad328.build.core=arduino 181 | 182 | ############################################################## 183 | 184 | lilypad.name=LilyPad Arduino w/ ATmega168 185 | 186 | lilypad.upload.protocol=stk500 187 | lilypad.upload.maximum_size=14336 188 | lilypad.upload.speed=19200 189 | 190 | lilypad.bootloader.low_fuses=0xe2 191 | lilypad.bootloader.high_fuses=0xdd 192 | lilypad.bootloader.extended_fuses=0x00 193 | lilypad.bootloader.path=lilypad 194 | lilypad.bootloader.file=LilyPadBOOT_168.hex 195 | lilypad.bootloader.unlock_bits=0x3F 196 | lilypad.bootloader.lock_bits=0x0F 197 | 198 | lilypad.build.mcu=atmega168 199 | lilypad.build.f_cpu=8000000L 200 | lilypad.build.core=arduino 201 | 202 | ############################################################## 203 | 204 | pro328.name=Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328 205 | 206 | pro328.upload.protocol=stk500 207 | pro328.upload.maximum_size=30720 208 | pro328.upload.speed=57600 209 | 210 | pro328.bootloader.low_fuses=0xFF 211 | pro328.bootloader.high_fuses=0xDA 212 | pro328.bootloader.extended_fuses=0x05 213 | pro328.bootloader.path=atmega 214 | pro328.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex 215 | pro328.bootloader.unlock_bits=0x3F 216 | pro328.bootloader.lock_bits=0x0F 217 | 218 | pro328.build.mcu=atmega328p 219 | pro328.build.f_cpu=8000000L 220 | pro328.build.core=arduino 221 | 222 | ############################################################## 223 | 224 | pro.name=Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega168 225 | 226 | pro.upload.protocol=stk500 227 | pro.upload.maximum_size=14336 228 | pro.upload.speed=19200 229 | 230 | pro.bootloader.low_fuses=0xc6 231 | pro.bootloader.high_fuses=0xdd 232 | pro.bootloader.extended_fuses=0x00 233 | pro.bootloader.path=atmega 234 | pro.bootloader.file=ATmegaBOOT_168_pro_8MHz.hex 235 | pro.bootloader.unlock_bits=0x3F 236 | pro.bootloader.lock_bits=0x0F 237 | 238 | pro.build.mcu=atmega168 239 | pro.build.f_cpu=8000000L 240 | pro.build.core=arduino 241 | 242 | ############################################################## 243 | 244 | atmega168.name=Arduino NG or older w/ ATmega168 245 | 246 | atmega168.upload.protocol=stk500 247 | atmega168.upload.maximum_size=14336 248 | atmega168.upload.speed=19200 249 | 250 | atmega168.bootloader.low_fuses=0xff 251 | atmega168.bootloader.high_fuses=0xdd 252 | atmega168.bootloader.extended_fuses=0x00 253 | atmega168.bootloader.path=atmega 254 | atmega168.bootloader.file=ATmegaBOOT_168_ng.hex 255 | atmega168.bootloader.unlock_bits=0x3F 256 | atmega168.bootloader.lock_bits=0x0F 257 | 258 | atmega168.build.mcu=atmega168 259 | atmega168.build.f_cpu=16000000L 260 | atmega168.build.core=arduino 261 | 262 | ############################################################## 263 | 264 | atmega8.name=Arduino NG or older w/ ATmega8 265 | 266 | atmega8.upload.protocol=stk500 267 | atmega8.upload.maximum_size=7168 268 | atmega8.upload.speed=19200 269 | 270 | atmega8.bootloader.low_fuses=0xdf 271 | atmega8.bootloader.high_fuses=0xca 272 | atmega8.bootloader.path=atmega8 273 | atmega8.bootloader.file=ATmegaBOOT.hex 274 | atmega8.bootloader.unlock_bits=0x3F 275 | atmega8.bootloader.lock_bits=0x0F 276 | 277 | atmega8.build.mcu=atmega8 278 | atmega8.build.f_cpu=16000000L 279 | atmega8.build.core=arduino 280 | 281 | -------------------------------------------------------------------------------- /arduino.DuinOS/DuinOS/portable.h: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V5.4.2 - Copyright (C) 2009 Real Time Engineers Ltd. 3 | 4 | This file is part of the FreeRTOS distribution. 5 | 6 | FreeRTOS is free software; you can redistribute it and/or modify it under 7 | the terms of the GNU General Public License (version 2) as published by the 8 | Free Software Foundation and modified by the FreeRTOS exception. 9 | **NOTE** The exception to the GPL is included to allow you to distribute a 10 | combined work that includes FreeRTOS without being obliged to provide the 11 | source code for proprietary components outside of the FreeRTOS kernel. 12 | Alternative commercial license and support terms are also available upon 13 | request. See the licensing section of http://www.FreeRTOS.org for full 14 | license details. 15 | 16 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 19 | more details. 20 | 21 | You should have received a copy of the GNU General Public License along 22 | with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59 23 | Temple Place, Suite 330, Boston, MA 02111-1307 USA. 24 | 25 | 26 | *************************************************************************** 27 | * * 28 | * Looking for a quick start? Then check out the FreeRTOS eBook! * 29 | * See http://www.FreeRTOS.org/Documentation for details * 30 | * * 31 | *************************************************************************** 32 | 33 | 1 tab == 4 spaces! 34 | 35 | Please ensure to read the configuration and relevant port sections of the 36 | online documentation. 37 | 38 | http://www.FreeRTOS.org - Documentation, latest information, license and 39 | contact details. 40 | 41 | http://www.SafeRTOS.com - A version that is certified for use in safety 42 | critical systems. 43 | 44 | http://www.OpenRTOS.com - Commercial support, development, porting, 45 | licensing and training services. 46 | */ 47 | 48 | /*----------------------------------------------------------- 49 | * Portable layer API. Each function must be defined for each port. 50 | *----------------------------------------------------------*/ 51 | 52 | #ifndef PORTABLE_H 53 | #define PORTABLE_H 54 | 55 | /* Include the macro file relevant to the port being used. */ 56 | 57 | #ifdef OPEN_WATCOM_INDUSTRIAL_PC_PORT 58 | #include "..\..\Source\portable\owatcom\16bitdos\pc\portmacro.h" 59 | typedef void ( __interrupt __far *pxISR )(); 60 | #endif 61 | 62 | #ifdef OPEN_WATCOM_FLASH_LITE_186_PORT 63 | #include "..\..\Source\portable\owatcom\16bitdos\flsh186\portmacro.h" 64 | typedef void ( __interrupt __far *pxISR )(); 65 | #endif 66 | 67 | #ifdef GCC_MEGA_AVR 68 | #include "../portable/GCC/ATMega323/portmacro.h" 69 | #endif 70 | 71 | #ifdef IAR_MEGA_AVR 72 | #include "../portable/IAR/ATMega323/portmacro.h" 73 | #endif 74 | 75 | #ifdef MPLAB_PIC24_PORT 76 | #include "..\..\Source\portable\MPLAB\PIC24_dsPIC\portmacro.h" 77 | #endif 78 | 79 | #ifdef MPLAB_DSPIC_PORT 80 | #include "..\..\Source\portable\MPLAB\PIC24_dsPIC\portmacro.h" 81 | #endif 82 | 83 | #ifdef MPLAB_PIC18F_PORT 84 | #include "..\..\Source\portable\MPLAB\PIC18F\portmacro.h" 85 | #endif 86 | 87 | #ifdef MPLAB_PIC32MX_PORT 88 | #include "..\..\Source\portable\MPLAB\PIC32MX\portmacro.h" 89 | #endif 90 | 91 | #ifdef _FEDPICC 92 | #include "libFreeRTOS/Include/portmacro.h" 93 | #endif 94 | 95 | #ifdef SDCC_CYGNAL 96 | #include "../../Source/portable/SDCC/Cygnal/portmacro.h" 97 | #endif 98 | 99 | #ifdef GCC_ARM7 100 | #include "../../Source/portable/GCC/ARM7_LPC2000/portmacro.h" 101 | #endif 102 | 103 | #ifdef GCC_ARM7_ECLIPSE 104 | #include "portmacro.h" 105 | #endif 106 | 107 | #ifdef ROWLEY_LPC23xx 108 | #include "../../Source/portable/GCC/ARM7_LPC23xx/portmacro.h" 109 | #endif 110 | 111 | #ifdef IAR_MSP430 112 | #include "..\..\Source\portable\IAR\MSP430\portmacro.h" 113 | #endif 114 | 115 | #ifdef GCC_MSP430 116 | #include "../../Source/portable/GCC/MSP430F449/portmacro.h" 117 | #endif 118 | 119 | #ifdef ROWLEY_MSP430 120 | #include "../../Source/portable/Rowley/MSP430F449/portmacro.h" 121 | #endif 122 | 123 | #ifdef ARM7_LPC21xx_KEIL_RVDS 124 | #include "..\..\Source\portable\RVDS\ARM7_LPC21xx\portmacro.h" 125 | #endif 126 | 127 | #ifdef SAM7_GCC 128 | #include "../../Source/portable/GCC/ARM7_AT91SAM7S/portmacro.h" 129 | #endif 130 | 131 | #ifdef SAM7_IAR 132 | #include "..\..\Source\portable\IAR\AtmelSAM7S64\portmacro.h" 133 | #endif 134 | 135 | #ifdef SAM9XE_IAR 136 | #include "..\..\Source\portable\IAR\AtmelSAM9XE\portmacro.h" 137 | #endif 138 | 139 | #ifdef LPC2000_IAR 140 | #include "..\..\Source\portable\IAR\LPC2000\portmacro.h" 141 | #endif 142 | 143 | #ifdef STR71X_IAR 144 | #include "..\..\Source\portable\IAR\STR71x\portmacro.h" 145 | #endif 146 | 147 | #ifdef STR75X_IAR 148 | #include "..\..\Source\portable\IAR\STR75x\portmacro.h" 149 | #endif 150 | 151 | #ifdef STR75X_GCC 152 | #include "..\..\Source\portable\GCC\STR75x\portmacro.h" 153 | #endif 154 | 155 | #ifdef STR91X_IAR 156 | #include "..\..\Source\portable\IAR\STR91x\portmacro.h" 157 | #endif 158 | 159 | #ifdef GCC_H8S 160 | #include "../../Source/portable/GCC/H8S2329/portmacro.h" 161 | #endif 162 | 163 | #ifdef GCC_AT91FR40008 164 | #include "../../Source/portable/GCC/ARM7_AT91FR40008/portmacro.h" 165 | #endif 166 | 167 | #ifdef RVDS_ARMCM3_LM3S102 168 | #include "../../Source/portable/RVDS/ARM_CM3/portmacro.h" 169 | #endif 170 | 171 | #ifdef GCC_ARMCM3_LM3S102 172 | #include "../../Source/portable/GCC/ARM_CM3/portmacro.h" 173 | #endif 174 | 175 | #ifdef GCC_ARMCM3 176 | #include "../../Source/portable/GCC/ARM_CM3/portmacro.h" 177 | #endif 178 | 179 | #ifdef IAR_ARM_CM3 180 | #include "../../Source/portable/IAR/ARM_CM3/portmacro.h" 181 | #endif 182 | 183 | #ifdef IAR_ARMCM3_LM 184 | #include "../../Source/portable/IAR/ARM_CM3/portmacro.h" 185 | #endif 186 | 187 | #ifdef HCS12_CODE_WARRIOR 188 | #include "../../Source/portable/CodeWarrior/HCS12/portmacro.h" 189 | #endif 190 | 191 | #ifdef MICROBLAZE_GCC 192 | #include "../../Source/portable/GCC/MicroBlaze/portmacro.h" 193 | #endif 194 | 195 | #ifdef TERN_EE 196 | #include "..\..\Source\portable\Paradigm\Tern_EE\small\portmacro.h" 197 | #endif 198 | 199 | #ifdef GCC_HCS12 200 | #include "../../Source/portable/GCC/HCS12/portmacro.h" 201 | #endif 202 | 203 | #ifdef GCC_MCF5235 204 | #include "../../Source/portable/GCC/MCF5235/portmacro.h" 205 | #endif 206 | 207 | #ifdef COLDFIRE_V2_GCC 208 | #include "../../../Source/portable/GCC/ColdFire_V2/portmacro.h" 209 | #endif 210 | 211 | #ifdef COLDFIRE_V2_CODEWARRIOR 212 | #include "../../Source/portable/CodeWarrior/ColdFire_V2/portmacro.h" 213 | #endif 214 | 215 | #ifdef GCC_PPC405 216 | #include "../../Source/portable/GCC/PPC405_Xilinx/portmacro.h" 217 | #endif 218 | 219 | #ifdef GCC_PPC440 220 | #include "../../Source/portable/GCC/PPC440_Xilinx/portmacro.h" 221 | #endif 222 | 223 | #ifdef _16FX_SOFTUNE 224 | #include "..\..\Source\portable\Softune\MB96340\portmacro.h" 225 | #endif 226 | 227 | #ifdef BCC_INDUSTRIAL_PC_PORT 228 | /* A short file name has to be used in place of the normal 229 | FreeRTOSConfig.h when using the Borland compiler. */ 230 | #include "frconfig.h" 231 | #include "..\portable\BCC\16BitDOS\PC\prtmacro.h" 232 | typedef void ( __interrupt __far *pxISR )(); 233 | #endif 234 | 235 | #ifdef BCC_FLASH_LITE_186_PORT 236 | /* A short file name has to be used in place of the normal 237 | FreeRTOSConfig.h when using the Borland compiler. */ 238 | #include "frconfig.h" 239 | #include "..\portable\BCC\16BitDOS\flsh186\prtmacro.h" 240 | typedef void ( __interrupt __far *pxISR )(); 241 | #endif 242 | 243 | #ifdef __GNUC__ 244 | #ifdef __AVR32_AVR32A__ 245 | #include "portmacro.h" 246 | #endif 247 | #endif 248 | 249 | #ifdef __ICCAVR32__ 250 | #ifdef __CORE__ 251 | #if __CORE__ == __AVR32A__ 252 | #include "portmacro.h" 253 | #endif 254 | #endif 255 | #endif 256 | 257 | #ifdef __91467D 258 | #include "portmacro.h" 259 | #endif 260 | 261 | #ifdef __96340 262 | #include "portmacro.h" 263 | #endif 264 | 265 | 266 | #ifdef __IAR_V850ES_Fx3__ 267 | #include "../../Source/portable/IAR/V850ES/portmacro.h" 268 | #endif 269 | 270 | #ifdef __IAR_V850ES_Jx3__ 271 | #include "../../Source/portable/IAR/V850ES/portmacro.h" 272 | #endif 273 | 274 | #ifdef __IAR_V850ES_Jx3_L__ 275 | #include "../../Source/portable/IAR/V850ES/portmacro.h" 276 | #endif 277 | 278 | #ifdef __IAR_V850ES_Jx2__ 279 | #include "../../Source/portable/IAR/V850ES/portmacro.h" 280 | #endif 281 | 282 | #ifdef __IAR_V850ES_Hx2__ 283 | #include "../../Source/portable/IAR/V850ES/portmacro.h" 284 | #endif 285 | 286 | #ifdef __IAR_78K0R_Kx3__ 287 | #include "../../Source/portable/IAR/78K0R/portmacro.h" 288 | #endif 289 | 290 | #ifdef __IAR_78K0R_Kx3L__ 291 | #include "../../Source/portable/IAR/78K0R/portmacro.h" 292 | #endif 293 | 294 | /* Catch all to ensure portmacro.h is included in the build. Newer demos 295 | have the path as part of the project options, rather than as relative from 296 | the project location. If portENTER_CRITICAL() has not been defined then 297 | portmacro.h has not yet been included - as every portmacro.h provides a 298 | portENTER_CRITICAL() definition. Check the demo application for your demo 299 | to find the path to the correct portmacro.h file. */ 300 | #ifndef portENTER_CRITICAL 301 | #include "portmacro.h" 302 | #endif 303 | 304 | #ifdef __cplusplus 305 | extern "C" { 306 | #endif 307 | 308 | /* 309 | * Setup the stack of a new task so it is ready to be placed under the 310 | * scheduler control. The registers have to be placed on the stack in 311 | * the order that the port expects to find them. 312 | * 313 | */ 314 | portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ); 315 | 316 | /* 317 | * Map to the memory management routines required for the port. 318 | */ 319 | void *pvPortMalloc( size_t xSize ); 320 | void vPortFree( void *pv ); 321 | void vPortInitialiseBlocks( void ); 322 | 323 | /* 324 | * Setup the hardware ready for the scheduler to take control. This generally 325 | * sets up a tick interrupt and sets timers for the correct tick frequency. 326 | */ 327 | portBASE_TYPE xPortStartScheduler( void ); 328 | 329 | /* 330 | * Undo any hardware/ISR setup that was performed by xPortStartScheduler() so 331 | * the hardware is left in its original condition after the scheduler stops 332 | * executing. 333 | */ 334 | void vPortEndScheduler( void ); 335 | 336 | #ifdef __cplusplus 337 | } 338 | #endif 339 | 340 | #endif /* PORTABLE_H */ 341 | 342 | -------------------------------------------------------------------------------- /arduino.DuinOS/FreeRTOSConfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS.org V5.3.0 - Copyright (C) 2003-2009 Richard Barry. 3 | 4 | This file is part of the FreeRTOS.org distribution. 5 | 6 | FreeRTOS.org is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License (version 2) as published 8 | by the Free Software Foundation and modified by the FreeRTOS exception. 9 | **NOTE** The exception to the GPL is included to allow you to distribute a 10 | combined work that includes FreeRTOS.org without being obliged to provide 11 | the source code for any proprietary components. Alternative commercial 12 | license and support terms are also available upon request. See the 13 | licensing section of http://www.FreeRTOS.org for full details. 14 | 15 | FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 18 | more details. 19 | 20 | You should have received a copy of the GNU General Public License along 21 | with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59 22 | Temple Place, Suite 330, Boston, MA 02111-1307 USA. 23 | 24 | 25 | *************************************************************************** 26 | * * 27 | * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation * 28 | * * 29 | * This is a concise, step by step, 'hands on' guide that describes both * 30 | * general multitasking concepts and FreeRTOS specifics. It presents and * 31 | * explains numerous examples that are written using the FreeRTOS API. * 32 | * Full source code for all the examples is provided in an accompanying * 33 | * .zip file. * 34 | * * 35 | *************************************************************************** 36 | 37 | 1 tab == 4 spaces! 38 | 39 | Please ensure to read the configuration and relevant port sections of the 40 | online documentation. 41 | 42 | http://www.FreeRTOS.org - Documentation, latest information, license and 43 | contact details. 44 | 45 | http://www.SafeRTOS.com - A version that is certified for use in safety 46 | critical systems. 47 | 48 | http://www.OpenRTOS.com - Commercial support, development, porting, 49 | licensing and training services. 50 | */ 51 | 52 | #ifndef FREERTOS_CONFIG_H 53 | #define FREERTOS_CONFIG_H 54 | 55 | #include 56 | 57 | /*----------------------------------------------------------- 58 | * Application specific definitions. 59 | * 60 | * These definitions should be adjusted for your particular hardware and 61 | * application requirements. 62 | * 63 | * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE 64 | * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. 65 | * 66 | * See http://www.freertos.org/a00110.html. 67 | *----------------------------------------------------------*/ 68 | 69 | // XXX: rsanders testing 70 | #define portBYTE_ALIGNMENT 1 71 | #define DUINOS_USE_HEAP2 1 72 | 73 | 74 | //##2009.10.29: These values may be improved: 75 | #if defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) 76 | 77 | //##Multiplo.Brain.M644: 78 | #define configUSE_PREEMPTION 1 79 | #define configUSE_IDLE_HOOK 0 80 | #define configUSE_TICK_HOOK 0 81 | 82 | //##20091029: Use compiler defined freq.: 83 | #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) 84 | //#define configCPU_CLOCK_HZ ( ( unsigned portLONG ) 18432000 ) 85 | 86 | #define configTICK_RATE_HZ ( ( portTickType ) 1000 ) 87 | //##For these big cpus, it's possible to define more priorities if necessary: 88 | #define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 3 ) 89 | #define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 85 ) 90 | //##Run experiments to test this value: 91 | #define configTOTAL_HEAP_SIZE ( (size_t ) ( 2048 ) ) 92 | //#define configMAX_TASK_NAME_LEN ( 8 ) 93 | #define configMAX_TASK_NAME_LEN ( 16 ) 94 | #define configUSE_TRACE_FACILITY 0 95 | #define configUSE_16_BIT_TICKS 1 96 | #define configIDLE_SHOULD_YIELD 0 97 | #define configQUEUE_REGISTRY_SIZE 0 98 | 99 | /* Co-routine definitions. */ 100 | //##2009.10.20: defined as "0": 101 | #define configUSE_CO_ROUTINES 0 102 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 103 | 104 | /* Set the following definitions to 1 to include the API function, or zero 105 | to exclude the API function. */ 106 | #define INCLUDE_vTaskPrioritySet 1 107 | #define INCLUDE_uxTaskPriorityGet 1 108 | //##If the following value is set to 1, change the memory managment scheme to heap_2.c: 109 | #define INCLUDE_vTaskDelete 0 110 | #define INCLUDE_vTaskCleanUpResources 0 111 | #define INCLUDE_vTaskSuspend 1 112 | #define INCLUDE_vTaskDelayUntil 1 113 | #define INCLUDE_vTaskDelay 1 114 | 115 | #elif defined(__AVR_ATmega1284P__) 116 | 117 | //##Multiplo.Brain.M1284 118 | #define configUSE_PREEMPTION 1 119 | #define configUSE_IDLE_HOOK 0 120 | #define configUSE_TICK_HOOK 0 121 | 122 | //##20091029: Use compiler defined freq.: 123 | #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) 124 | //#define configCPU_CLOCK_HZ ( ( unsigned portLONG ) 18432000 ) 125 | 126 | #define configTICK_RATE_HZ ( ( portTickType ) 1000 ) 127 | //##For these big cpus, it's possible to define more priorities if necessary: 128 | #define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 3 ) 129 | #define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 85 ) 130 | //##Run experiments to test this value: 131 | #define configTOTAL_HEAP_SIZE ( (size_t ) ( 4096 ) ) 132 | //#define configMAX_TASK_NAME_LEN ( 8 ) 133 | #define configMAX_TASK_NAME_LEN ( 16 ) 134 | #define configUSE_TRACE_FACILITY 0 135 | #define configUSE_16_BIT_TICKS 1 136 | #define configIDLE_SHOULD_YIELD 0 137 | #define configQUEUE_REGISTRY_SIZE 0 138 | 139 | /* Co-routine definitions. */ 140 | //##2009.10.20: defined as "0": 141 | #define configUSE_CO_ROUTINES 0 142 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 143 | 144 | /* Set the following definitions to 1 to include the API function, or zero 145 | to exclude the API function. */ 146 | #define INCLUDE_vTaskPrioritySet 1 147 | #define INCLUDE_uxTaskPriorityGet 1 148 | //##If the following value is set to 1, change the memory managment scheme to heap_2.c: 149 | #define INCLUDE_vTaskDelete 0 150 | #define INCLUDE_vTaskCleanUpResources 0 151 | #define INCLUDE_vTaskSuspend 1 152 | #define INCLUDE_vTaskDelayUntil 1 153 | #define INCLUDE_vTaskDelay 1 154 | 155 | #elif defined(__AVR_ATmega1280__) 156 | //##Arduino Mega? Not tested yet: 157 | 158 | #define configUSE_PREEMPTION 1 159 | #define configUSE_IDLE_HOOK 0 160 | #define configUSE_TICK_HOOK 0 161 | 162 | //##20091029: Use compiler defined freq.: 163 | #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) 164 | //#define configCPU_CLOCK_HZ ( ( unsigned portLONG ) 16000000 ) 165 | 166 | #define configTICK_RATE_HZ ( ( portTickType ) 1000 ) 167 | //##For these bigger cpus, it's possible to define more priorities if necessary: 168 | #define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 3 ) 169 | #define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 85 ) 170 | //##Run experiments to test this value: 171 | #define configTOTAL_HEAP_SIZE ( (size_t ) ( 4096 ) ) 172 | //#define configMAX_TASK_NAME_LEN ( 8 ) 173 | #define configMAX_TASK_NAME_LEN ( 16 ) 174 | #define configUSE_TRACE_FACILITY 0 175 | #define configUSE_16_BIT_TICKS 1 176 | #define configIDLE_SHOULD_YIELD 0 177 | #define configQUEUE_REGISTRY_SIZE 0 178 | 179 | /* Co-routine definitions. */ 180 | //##2009.10.20: defined as "0": 181 | #define configUSE_CO_ROUTINES 0 182 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 183 | 184 | /* Set the following definitions to 1 to include the API function, or zero 185 | to exclude the API function. */ 186 | #define INCLUDE_vTaskPrioritySet 1 187 | #define INCLUDE_uxTaskPriorityGet 1 188 | //##If the following value is set to 1, change the memory managment scheme to heap_2.c: 189 | #define INCLUDE_vTaskDelete 0 190 | #define INCLUDE_vTaskCleanUpResources 0 191 | #define INCLUDE_vTaskSuspend 1 192 | #define INCLUDE_vTaskDelayUntil 1 193 | #define INCLUDE_vTaskDelay 1 194 | 195 | #elif defined(__AVR_ATmega328P__) 196 | //##Mega328p: 197 | 198 | #define configUSE_PREEMPTION 1 199 | #define configUSE_IDLE_HOOK 0 200 | #define configUSE_TICK_HOOK 0 201 | 202 | //##20091029: Use compiler defined freq.: 203 | #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) 204 | //#define configCPU_CLOCK_HZ ( ( unsigned portLONG ) 12000000 ) 205 | 206 | #define configTICK_RATE_HZ ( ( portTickType ) 1000 ) 207 | //##For these bigger cpus, it's possible to define more priorities if necessary: 208 | #define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 3 ) 209 | #define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 85 ) 210 | #define configTOTAL_HEAP_SIZE ( (size_t ) ( 1200 ) ) 211 | //#define configMAX_TASK_NAME_LEN ( 8 ) 212 | #define configMAX_TASK_NAME_LEN ( 16 ) 213 | #define configUSE_TRACE_FACILITY 0 214 | #define configUSE_16_BIT_TICKS 1 215 | #define configIDLE_SHOULD_YIELD 0 216 | #define configQUEUE_REGISTRY_SIZE 0 217 | 218 | /* Co-routine definitions. */ 219 | //##2009.10.20: defined as "0": 220 | #define configUSE_CO_ROUTINES 0 221 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 222 | 223 | /* Set the following definitions to 1 to include the API function, or zero 224 | to exclude the API function. */ 225 | #define INCLUDE_vTaskPrioritySet 0 226 | #define INCLUDE_uxTaskPriorityGet 0 227 | #define INCLUDE_vTaskDelete 1 228 | #define INCLUDE_vTaskCleanUpResources 1 229 | #define INCLUDE_vTaskSuspend 1 230 | #define INCLUDE_vTaskDelayUntil 1 231 | #define INCLUDE_vTaskDelay 1 232 | 233 | #elif defined(__AVR_ATmega88__) || defined(__AVR_ATmega88P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) 234 | //##Mega88, Mega88p, Mega168, Mega168p: 235 | 236 | #define configUSE_PREEMPTION 1 237 | #define configUSE_IDLE_HOOK 0 238 | #define configUSE_TICK_HOOK 0 239 | 240 | //##20091029: Use compiler defined freq.: 241 | #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) 242 | //#define configCPU_CLOCK_HZ ( ( unsigned portLONG ) 12000000 ) 243 | 244 | #define configTICK_RATE_HZ ( ( portTickType ) 1000 ) 245 | //##For these bigger cpus, it's possible to define more priorities if necessary: 246 | #define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 3 ) 247 | #define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 85 ) 248 | #define configTOTAL_HEAP_SIZE ( (size_t ) ( 800 ) ) 249 | //#define configMAX_TASK_NAME_LEN ( 8 ) 250 | #define configMAX_TASK_NAME_LEN ( 16 ) 251 | #define configUSE_TRACE_FACILITY 0 252 | #define configUSE_16_BIT_TICKS 1 253 | #define configIDLE_SHOULD_YIELD 0 254 | #define configQUEUE_REGISTRY_SIZE 0 255 | 256 | /* Co-routine definitions. */ 257 | //##2009.10.20: defined as "0": 258 | #define configUSE_CO_ROUTINES 0 259 | #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) 260 | 261 | /* Set the following definitions to 1 to include the API function, or zero 262 | to exclude the API function. */ 263 | #define INCLUDE_vTaskPrioritySet 0 264 | #define INCLUDE_uxTaskPriorityGet 0 265 | #define INCLUDE_vTaskDelete 0 266 | #define INCLUDE_vTaskCleanUpResources 0 267 | #define INCLUDE_vTaskSuspend 1 268 | #define INCLUDE_vTaskDelayUntil 1 269 | #define INCLUDE_vTaskDelay 1 270 | 271 | #else 272 | #error "Device is not supported by DuinOS" 273 | 274 | #endif 275 | 276 | #if !defined(DUINOS_USE_HEAP1) && ! defined(DUINOS_USE_HEAP2) && !defined(DUINOS_USE_HEAP3) 277 | #define DUINOS_USE_HEAP1 1 278 | #endif 279 | 280 | 281 | #endif /* FREERTOS_CONFIG_H */ 282 | -------------------------------------------------------------------------------- /arduino.DuinOS/DuinOS/heap_2.c: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V6.0.2 - Copyright (C) 2010 Real Time Engineers Ltd. 3 | 4 | *************************************************************************** 5 | * * 6 | * If you are: * 7 | * * 8 | * + New to FreeRTOS, * 9 | * + Wanting to learn FreeRTOS or multitasking in general quickly * 10 | * + Looking for basic training, * 11 | * + Wanting to improve your FreeRTOS skills and productivity * 12 | * * 13 | * then take a look at the FreeRTOS eBook * 14 | * * 15 | * "Using the FreeRTOS Real Time Kernel - a Practical Guide" * 16 | * http://www.FreeRTOS.org/Documentation * 17 | * * 18 | * A pdf reference manual is also available. Both are usually delivered * 19 | * to your inbox within 20 minutes to two hours when purchased between 8am * 20 | * and 8pm GMT (although please allow up to 24 hours in case of * 21 | * exceptional circumstances). Thank you for your support! * 22 | * * 23 | *************************************************************************** 24 | 25 | This file is part of the FreeRTOS distribution. 26 | 27 | FreeRTOS is free software; you can redistribute it and/or modify it under 28 | the terms of the GNU General Public License (version 2) as published by the 29 | Free Software Foundation AND MODIFIED BY the FreeRTOS exception. 30 | ***NOTE*** The exception to the GPL is included to allow you to distribute 31 | a combined work that includes FreeRTOS without being obliged to provide the 32 | source code for proprietary components outside of the FreeRTOS kernel. 33 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT 34 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 35 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 36 | more details. You should have received a copy of the GNU General Public 37 | License and the FreeRTOS license exception along with FreeRTOS; if not it 38 | can be viewed here: http://www.freertos.org/a00114.html and also obtained 39 | by writing to Richard Barry, contact details for whom are available on the 40 | FreeRTOS WEB site. 41 | 42 | 1 tab == 4 spaces! 43 | 44 | http://www.FreeRTOS.org - Documentation, latest information, license and 45 | contact details. 46 | 47 | http://www.SafeRTOS.com - A version that is certified for use in safety 48 | critical systems. 49 | 50 | http://www.OpenRTOS.com - Commercial support, development, porting, 51 | licensing and training services. 52 | */ 53 | 54 | /* 55 | * A sample implementation of pvPortMalloc() and vPortFree() that permits 56 | * allocated blocks to be freed, but does not combine adjacent free blocks 57 | * into a single larger block. 58 | * 59 | * See heap_1.c and heap_3.c for alternative implementations, and the memory 60 | * management pages of http://www.FreeRTOS.org for more information. 61 | */ 62 | #include 63 | 64 | /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining 65 | all the API functions to use the MPU wrappers. That should only be done when 66 | task.h is included from an application file. */ 67 | #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE 68 | 69 | #include "FreeRTOS.h" 70 | #include "task.h" 71 | 72 | #ifdef DUINOS_USE_HEAP2 73 | #if portBYTE_ALIGNMENT == 8 74 | #define portBYTE_ALIGNMENT_MASK ( ( size_t ) 0x0007 ) 75 | #endif 76 | #if portBYTE_ALIGNMENT == 4 77 | #define portBYTE_ALIGNMENT_MASK ( ( size_t ) 0x0003 ) 78 | #endif 79 | 80 | #if portBYTE_ALIGNMENT == 2 81 | #define portBYTE_ALIGNMENT_MASK ( ( size_t ) 0x0001 ) 82 | #endif 83 | 84 | #if portBYTE_ALIGNMENT == 1 85 | #define portBYTE_ALIGNMENT_MASK ( ( size_t ) 0x0000 ) 86 | #endif 87 | 88 | #ifndef portBYTE_ALIGNMENT_MASK 89 | #error "Invalid portBYTE_ALIGNMENT definition" 90 | #endif 91 | 92 | #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE 93 | 94 | /* Allocate the memory for the heap. The struct is used to force byte 95 | alignment without using any non-portable code. */ 96 | static union xRTOS_HEAP 97 | { 98 | #if portBYTE_ALIGNMENT == 8 99 | volatile portDOUBLE dDummy; 100 | #else 101 | volatile unsigned long ulDummy; 102 | #endif 103 | unsigned char ucHeap[ configTOTAL_HEAP_SIZE ]; 104 | } xHeap; 105 | 106 | /* Define the linked list structure. This is used to link free blocks in order 107 | of their size. */ 108 | typedef struct A_BLOCK_LINK 109 | { 110 | struct A_BLOCK_LINK *pxNextFreeBlock; /*<< The next free block in the list. */ 111 | size_t xBlockSize; /*<< The size of the free block. */ 112 | } xBlockLink; 113 | 114 | 115 | static const unsigned short heapSTRUCT_SIZE = ( sizeof( xBlockLink ) + portBYTE_ALIGNMENT - ( sizeof( xBlockLink ) % portBYTE_ALIGNMENT ) ); 116 | #define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( heapSTRUCT_SIZE * 2 ) ) 117 | 118 | /* Create a couple of list links to mark the start and end of the list. */ 119 | static xBlockLink xStart, xEnd; 120 | 121 | /* Keeps track of the number of free bytes remaining, but says nothing about 122 | fragmentation. */ 123 | static size_t xFreeBytesRemaining; 124 | 125 | /* STATIC FUNCTIONS ARE DEFINED AS MACROS TO MINIMIZE THE FUNCTION CALL DEPTH. */ 126 | 127 | /* 128 | * Insert a block into the list of free blocks - which is ordered by size of 129 | * the block. Small blocks at the start of the list and large blocks at the end 130 | * of the list. 131 | */ 132 | #define prvInsertBlockIntoFreeList( pxBlockToInsert ) \ 133 | { \ 134 | xBlockLink *pxIterator; \ 135 | size_t xBlockSize; \ 136 | \ 137 | xBlockSize = pxBlockToInsert->xBlockSize; \ 138 | \ 139 | /* Iterate through the list until a block is found that has a larger size */ \ 140 | /* than the block we are inserting. */ \ 141 | for( pxIterator = &xStart; pxIterator->pxNextFreeBlock->xBlockSize < xBlockSize; pxIterator = pxIterator->pxNextFreeBlock ) \ 142 | { \ 143 | /* There is nothing to do here - just iterate to the correct position. */ \ 144 | } \ 145 | \ 146 | /* Update the list to include the block being inserted in the correct */ \ 147 | /* position. */ \ 148 | pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock; \ 149 | pxIterator->pxNextFreeBlock = pxBlockToInsert; \ 150 | } 151 | /*-----------------------------------------------------------*/ 152 | 153 | #define prvHeapInit() \ 154 | { \ 155 | xBlockLink *pxFirstFreeBlock; \ 156 | \ 157 | /* xStart is used to hold a pointer to the first item in the list of free */ \ 158 | /* blocks. The void cast is used to prevent compiler warnings. */ \ 159 | xStart.pxNextFreeBlock = ( void * ) xHeap.ucHeap; \ 160 | xStart.xBlockSize = ( size_t ) 0; \ 161 | \ 162 | /* xEnd is used to mark the end of the list of free blocks. */ \ 163 | xEnd.xBlockSize = configTOTAL_HEAP_SIZE; \ 164 | xEnd.pxNextFreeBlock = NULL; \ 165 | \ 166 | /* To start with there is a single free block that is sized to take up the \ 167 | entire heap space. */ \ 168 | pxFirstFreeBlock = ( void * ) xHeap.ucHeap; \ 169 | pxFirstFreeBlock->xBlockSize = configTOTAL_HEAP_SIZE; \ 170 | pxFirstFreeBlock->pxNextFreeBlock = &xEnd; \ 171 | \ 172 | xFreeBytesRemaining = configTOTAL_HEAP_SIZE; \ 173 | } 174 | /*-----------------------------------------------------------*/ 175 | 176 | void *pvPortMalloc( size_t xWantedSize ) 177 | { 178 | xBlockLink *pxBlock, *pxPreviousBlock, *pxNewBlockLink; 179 | static portBASE_TYPE xHeapHasBeenInitialised = pdFALSE; 180 | void *pvReturn = NULL; 181 | 182 | vTaskSuspendAll(); 183 | { 184 | /* If this is the first call to malloc then the heap will require 185 | initialisation to setup the list of free blocks. */ 186 | if( xHeapHasBeenInitialised == pdFALSE ) 187 | { 188 | prvHeapInit(); 189 | xHeapHasBeenInitialised = pdTRUE; 190 | } 191 | 192 | /* The wanted size is increased so it can contain a xBlockLink 193 | structure in addition to the requested amount of bytes. */ 194 | if( xWantedSize > 0 ) 195 | { 196 | xWantedSize += heapSTRUCT_SIZE; 197 | 198 | /* Ensure that blocks are always aligned to the required number of bytes. */ 199 | if( xWantedSize & portBYTE_ALIGNMENT_MASK ) 200 | { 201 | /* Byte alignment required. */ 202 | xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ); 203 | } 204 | } 205 | 206 | if( ( xWantedSize > 0 ) && ( xWantedSize < configTOTAL_HEAP_SIZE ) ) 207 | { 208 | /* Blocks are stored in byte order - traverse the list from the start 209 | (smallest) block until one of adequate size is found. */ 210 | pxPreviousBlock = &xStart; 211 | pxBlock = xStart.pxNextFreeBlock; 212 | while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock ) ) 213 | { 214 | pxPreviousBlock = pxBlock; 215 | pxBlock = pxBlock->pxNextFreeBlock; 216 | } 217 | 218 | /* If we found the end marker then a block of adequate size was not found. */ 219 | if( pxBlock != &xEnd ) 220 | { 221 | /* Return the memory space - jumping over the xBlockLink structure 222 | at its start. */ 223 | pvReturn = ( void * ) ( ( ( unsigned char * ) pxPreviousBlock->pxNextFreeBlock ) + heapSTRUCT_SIZE ); 224 | 225 | /* This block is being returned for use so must be taken our of the 226 | list of free blocks. */ 227 | pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock; 228 | 229 | /* If the block is larger than required it can be split into two. */ 230 | if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE ) 231 | { 232 | /* This block is to be split into two. Create a new block 233 | following the number of bytes requested. The void cast is 234 | used to prevent byte alignment warnings from the compiler. */ 235 | pxNewBlockLink = ( void * ) ( ( ( unsigned char * ) pxBlock ) + xWantedSize ); 236 | 237 | /* Calculate the sizes of two blocks split from the single 238 | block. */ 239 | pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize; 240 | pxBlock->xBlockSize = xWantedSize; 241 | 242 | /* Insert the new block into the list of free blocks. */ 243 | prvInsertBlockIntoFreeList( ( pxNewBlockLink ) ); 244 | } 245 | 246 | xFreeBytesRemaining -= xWantedSize; 247 | } 248 | } 249 | } 250 | xTaskResumeAll(); 251 | 252 | #if( configUSE_MALLOC_FAILED_HOOK == 1 ) 253 | { 254 | if( pvReturn == NULL ) 255 | { 256 | extern void vApplicationMallocFailedHook( void ); 257 | vApplicationMallocFailedHook(); 258 | } 259 | } 260 | #endif 261 | 262 | return pvReturn; 263 | } 264 | /*-----------------------------------------------------------*/ 265 | 266 | void vPortFree( void *pv ) 267 | { 268 | unsigned char *puc = ( unsigned char * ) pv; 269 | xBlockLink *pxLink; 270 | 271 | if( pv ) 272 | { 273 | /* The memory being freed will have an xBlockLink structure immediately 274 | before it. */ 275 | puc -= heapSTRUCT_SIZE; 276 | 277 | /* This casting is to keep the compiler from issuing warnings. */ 278 | pxLink = ( void * ) puc; 279 | 280 | vTaskSuspendAll(); 281 | { 282 | /* Add this block to the list of free blocks. */ 283 | prvInsertBlockIntoFreeList( ( ( xBlockLink * ) pxLink ) ); 284 | xFreeBytesRemaining += pxLink->xBlockSize; 285 | } 286 | xTaskResumeAll(); 287 | } 288 | } 289 | /*-----------------------------------------------------------*/ 290 | 291 | size_t xPortGetFreeHeapSize( void ) 292 | { 293 | return xFreeBytesRemaining; 294 | } 295 | /*-----------------------------------------------------------*/ 296 | 297 | void vPortInitialiseBlocks( void ) 298 | { 299 | /* This just exists to keep the linker quiet. */ 300 | } 301 | #endif 302 | -------------------------------------------------------------------------------- /arduino.DuinOS/binary.h: -------------------------------------------------------------------------------- 1 | #ifndef Binary_h 2 | #define Binary_h 3 | 4 | #define B0 0 5 | #define B00 0 6 | #define B000 0 7 | #define B0000 0 8 | #define B00000 0 9 | #define B000000 0 10 | #define B0000000 0 11 | #define B00000000 0 12 | #define B1 1 13 | #define B01 1 14 | #define B001 1 15 | #define B0001 1 16 | #define B00001 1 17 | #define B000001 1 18 | #define B0000001 1 19 | #define B00000001 1 20 | #define B10 2 21 | #define B010 2 22 | #define B0010 2 23 | #define B00010 2 24 | #define B000010 2 25 | #define B0000010 2 26 | #define B00000010 2 27 | #define B11 3 28 | #define B011 3 29 | #define B0011 3 30 | #define B00011 3 31 | #define B000011 3 32 | #define B0000011 3 33 | #define B00000011 3 34 | #define B100 4 35 | #define B0100 4 36 | #define B00100 4 37 | #define B000100 4 38 | #define B0000100 4 39 | #define B00000100 4 40 | #define B101 5 41 | #define B0101 5 42 | #define B00101 5 43 | #define B000101 5 44 | #define B0000101 5 45 | #define B00000101 5 46 | #define B110 6 47 | #define B0110 6 48 | #define B00110 6 49 | #define B000110 6 50 | #define B0000110 6 51 | #define B00000110 6 52 | #define B111 7 53 | #define B0111 7 54 | #define B00111 7 55 | #define B000111 7 56 | #define B0000111 7 57 | #define B00000111 7 58 | #define B1000 8 59 | #define B01000 8 60 | #define B001000 8 61 | #define B0001000 8 62 | #define B00001000 8 63 | #define B1001 9 64 | #define B01001 9 65 | #define B001001 9 66 | #define B0001001 9 67 | #define B00001001 9 68 | #define B1010 10 69 | #define B01010 10 70 | #define B001010 10 71 | #define B0001010 10 72 | #define B00001010 10 73 | #define B1011 11 74 | #define B01011 11 75 | #define B001011 11 76 | #define B0001011 11 77 | #define B00001011 11 78 | #define B1100 12 79 | #define B01100 12 80 | #define B001100 12 81 | #define B0001100 12 82 | #define B00001100 12 83 | #define B1101 13 84 | #define B01101 13 85 | #define B001101 13 86 | #define B0001101 13 87 | #define B00001101 13 88 | #define B1110 14 89 | #define B01110 14 90 | #define B001110 14 91 | #define B0001110 14 92 | #define B00001110 14 93 | #define B1111 15 94 | #define B01111 15 95 | #define B001111 15 96 | #define B0001111 15 97 | #define B00001111 15 98 | #define B10000 16 99 | #define B010000 16 100 | #define B0010000 16 101 | #define B00010000 16 102 | #define B10001 17 103 | #define B010001 17 104 | #define B0010001 17 105 | #define B00010001 17 106 | #define B10010 18 107 | #define B010010 18 108 | #define B0010010 18 109 | #define B00010010 18 110 | #define B10011 19 111 | #define B010011 19 112 | #define B0010011 19 113 | #define B00010011 19 114 | #define B10100 20 115 | #define B010100 20 116 | #define B0010100 20 117 | #define B00010100 20 118 | #define B10101 21 119 | #define B010101 21 120 | #define B0010101 21 121 | #define B00010101 21 122 | #define B10110 22 123 | #define B010110 22 124 | #define B0010110 22 125 | #define B00010110 22 126 | #define B10111 23 127 | #define B010111 23 128 | #define B0010111 23 129 | #define B00010111 23 130 | #define B11000 24 131 | #define B011000 24 132 | #define B0011000 24 133 | #define B00011000 24 134 | #define B11001 25 135 | #define B011001 25 136 | #define B0011001 25 137 | #define B00011001 25 138 | #define B11010 26 139 | #define B011010 26 140 | #define B0011010 26 141 | #define B00011010 26 142 | #define B11011 27 143 | #define B011011 27 144 | #define B0011011 27 145 | #define B00011011 27 146 | #define B11100 28 147 | #define B011100 28 148 | #define B0011100 28 149 | #define B00011100 28 150 | #define B11101 29 151 | #define B011101 29 152 | #define B0011101 29 153 | #define B00011101 29 154 | #define B11110 30 155 | #define B011110 30 156 | #define B0011110 30 157 | #define B00011110 30 158 | #define B11111 31 159 | #define B011111 31 160 | #define B0011111 31 161 | #define B00011111 31 162 | #define B100000 32 163 | #define B0100000 32 164 | #define B00100000 32 165 | #define B100001 33 166 | #define B0100001 33 167 | #define B00100001 33 168 | #define B100010 34 169 | #define B0100010 34 170 | #define B00100010 34 171 | #define B100011 35 172 | #define B0100011 35 173 | #define B00100011 35 174 | #define B100100 36 175 | #define B0100100 36 176 | #define B00100100 36 177 | #define B100101 37 178 | #define B0100101 37 179 | #define B00100101 37 180 | #define B100110 38 181 | #define B0100110 38 182 | #define B00100110 38 183 | #define B100111 39 184 | #define B0100111 39 185 | #define B00100111 39 186 | #define B101000 40 187 | #define B0101000 40 188 | #define B00101000 40 189 | #define B101001 41 190 | #define B0101001 41 191 | #define B00101001 41 192 | #define B101010 42 193 | #define B0101010 42 194 | #define B00101010 42 195 | #define B101011 43 196 | #define B0101011 43 197 | #define B00101011 43 198 | #define B101100 44 199 | #define B0101100 44 200 | #define B00101100 44 201 | #define B101101 45 202 | #define B0101101 45 203 | #define B00101101 45 204 | #define B101110 46 205 | #define B0101110 46 206 | #define B00101110 46 207 | #define B101111 47 208 | #define B0101111 47 209 | #define B00101111 47 210 | #define B110000 48 211 | #define B0110000 48 212 | #define B00110000 48 213 | #define B110001 49 214 | #define B0110001 49 215 | #define B00110001 49 216 | #define B110010 50 217 | #define B0110010 50 218 | #define B00110010 50 219 | #define B110011 51 220 | #define B0110011 51 221 | #define B00110011 51 222 | #define B110100 52 223 | #define B0110100 52 224 | #define B00110100 52 225 | #define B110101 53 226 | #define B0110101 53 227 | #define B00110101 53 228 | #define B110110 54 229 | #define B0110110 54 230 | #define B00110110 54 231 | #define B110111 55 232 | #define B0110111 55 233 | #define B00110111 55 234 | #define B111000 56 235 | #define B0111000 56 236 | #define B00111000 56 237 | #define B111001 57 238 | #define B0111001 57 239 | #define B00111001 57 240 | #define B111010 58 241 | #define B0111010 58 242 | #define B00111010 58 243 | #define B111011 59 244 | #define B0111011 59 245 | #define B00111011 59 246 | #define B111100 60 247 | #define B0111100 60 248 | #define B00111100 60 249 | #define B111101 61 250 | #define B0111101 61 251 | #define B00111101 61 252 | #define B111110 62 253 | #define B0111110 62 254 | #define B00111110 62 255 | #define B111111 63 256 | #define B0111111 63 257 | #define B00111111 63 258 | #define B1000000 64 259 | #define B01000000 64 260 | #define B1000001 65 261 | #define B01000001 65 262 | #define B1000010 66 263 | #define B01000010 66 264 | #define B1000011 67 265 | #define B01000011 67 266 | #define B1000100 68 267 | #define B01000100 68 268 | #define B1000101 69 269 | #define B01000101 69 270 | #define B1000110 70 271 | #define B01000110 70 272 | #define B1000111 71 273 | #define B01000111 71 274 | #define B1001000 72 275 | #define B01001000 72 276 | #define B1001001 73 277 | #define B01001001 73 278 | #define B1001010 74 279 | #define B01001010 74 280 | #define B1001011 75 281 | #define B01001011 75 282 | #define B1001100 76 283 | #define B01001100 76 284 | #define B1001101 77 285 | #define B01001101 77 286 | #define B1001110 78 287 | #define B01001110 78 288 | #define B1001111 79 289 | #define B01001111 79 290 | #define B1010000 80 291 | #define B01010000 80 292 | #define B1010001 81 293 | #define B01010001 81 294 | #define B1010010 82 295 | #define B01010010 82 296 | #define B1010011 83 297 | #define B01010011 83 298 | #define B1010100 84 299 | #define B01010100 84 300 | #define B1010101 85 301 | #define B01010101 85 302 | #define B1010110 86 303 | #define B01010110 86 304 | #define B1010111 87 305 | #define B01010111 87 306 | #define B1011000 88 307 | #define B01011000 88 308 | #define B1011001 89 309 | #define B01011001 89 310 | #define B1011010 90 311 | #define B01011010 90 312 | #define B1011011 91 313 | #define B01011011 91 314 | #define B1011100 92 315 | #define B01011100 92 316 | #define B1011101 93 317 | #define B01011101 93 318 | #define B1011110 94 319 | #define B01011110 94 320 | #define B1011111 95 321 | #define B01011111 95 322 | #define B1100000 96 323 | #define B01100000 96 324 | #define B1100001 97 325 | #define B01100001 97 326 | #define B1100010 98 327 | #define B01100010 98 328 | #define B1100011 99 329 | #define B01100011 99 330 | #define B1100100 100 331 | #define B01100100 100 332 | #define B1100101 101 333 | #define B01100101 101 334 | #define B1100110 102 335 | #define B01100110 102 336 | #define B1100111 103 337 | #define B01100111 103 338 | #define B1101000 104 339 | #define B01101000 104 340 | #define B1101001 105 341 | #define B01101001 105 342 | #define B1101010 106 343 | #define B01101010 106 344 | #define B1101011 107 345 | #define B01101011 107 346 | #define B1101100 108 347 | #define B01101100 108 348 | #define B1101101 109 349 | #define B01101101 109 350 | #define B1101110 110 351 | #define B01101110 110 352 | #define B1101111 111 353 | #define B01101111 111 354 | #define B1110000 112 355 | #define B01110000 112 356 | #define B1110001 113 357 | #define B01110001 113 358 | #define B1110010 114 359 | #define B01110010 114 360 | #define B1110011 115 361 | #define B01110011 115 362 | #define B1110100 116 363 | #define B01110100 116 364 | #define B1110101 117 365 | #define B01110101 117 366 | #define B1110110 118 367 | #define B01110110 118 368 | #define B1110111 119 369 | #define B01110111 119 370 | #define B1111000 120 371 | #define B01111000 120 372 | #define B1111001 121 373 | #define B01111001 121 374 | #define B1111010 122 375 | #define B01111010 122 376 | #define B1111011 123 377 | #define B01111011 123 378 | #define B1111100 124 379 | #define B01111100 124 380 | #define B1111101 125 381 | #define B01111101 125 382 | #define B1111110 126 383 | #define B01111110 126 384 | #define B1111111 127 385 | #define B01111111 127 386 | #define B10000000 128 387 | #define B10000001 129 388 | #define B10000010 130 389 | #define B10000011 131 390 | #define B10000100 132 391 | #define B10000101 133 392 | #define B10000110 134 393 | #define B10000111 135 394 | #define B10001000 136 395 | #define B10001001 137 396 | #define B10001010 138 397 | #define B10001011 139 398 | #define B10001100 140 399 | #define B10001101 141 400 | #define B10001110 142 401 | #define B10001111 143 402 | #define B10010000 144 403 | #define B10010001 145 404 | #define B10010010 146 405 | #define B10010011 147 406 | #define B10010100 148 407 | #define B10010101 149 408 | #define B10010110 150 409 | #define B10010111 151 410 | #define B10011000 152 411 | #define B10011001 153 412 | #define B10011010 154 413 | #define B10011011 155 414 | #define B10011100 156 415 | #define B10011101 157 416 | #define B10011110 158 417 | #define B10011111 159 418 | #define B10100000 160 419 | #define B10100001 161 420 | #define B10100010 162 421 | #define B10100011 163 422 | #define B10100100 164 423 | #define B10100101 165 424 | #define B10100110 166 425 | #define B10100111 167 426 | #define B10101000 168 427 | #define B10101001 169 428 | #define B10101010 170 429 | #define B10101011 171 430 | #define B10101100 172 431 | #define B10101101 173 432 | #define B10101110 174 433 | #define B10101111 175 434 | #define B10110000 176 435 | #define B10110001 177 436 | #define B10110010 178 437 | #define B10110011 179 438 | #define B10110100 180 439 | #define B10110101 181 440 | #define B10110110 182 441 | #define B10110111 183 442 | #define B10111000 184 443 | #define B10111001 185 444 | #define B10111010 186 445 | #define B10111011 187 446 | #define B10111100 188 447 | #define B10111101 189 448 | #define B10111110 190 449 | #define B10111111 191 450 | #define B11000000 192 451 | #define B11000001 193 452 | #define B11000010 194 453 | #define B11000011 195 454 | #define B11000100 196 455 | #define B11000101 197 456 | #define B11000110 198 457 | #define B11000111 199 458 | #define B11001000 200 459 | #define B11001001 201 460 | #define B11001010 202 461 | #define B11001011 203 462 | #define B11001100 204 463 | #define B11001101 205 464 | #define B11001110 206 465 | #define B11001111 207 466 | #define B11010000 208 467 | #define B11010001 209 468 | #define B11010010 210 469 | #define B11010011 211 470 | #define B11010100 212 471 | #define B11010101 213 472 | #define B11010110 214 473 | #define B11010111 215 474 | #define B11011000 216 475 | #define B11011001 217 476 | #define B11011010 218 477 | #define B11011011 219 478 | #define B11011100 220 479 | #define B11011101 221 480 | #define B11011110 222 481 | #define B11011111 223 482 | #define B11100000 224 483 | #define B11100001 225 484 | #define B11100010 226 485 | #define B11100011 227 486 | #define B11100100 228 487 | #define B11100101 229 488 | #define B11100110 230 489 | #define B11100111 231 490 | #define B11101000 232 491 | #define B11101001 233 492 | #define B11101010 234 493 | #define B11101011 235 494 | #define B11101100 236 495 | #define B11101101 237 496 | #define B11101110 238 497 | #define B11101111 239 498 | #define B11110000 240 499 | #define B11110001 241 500 | #define B11110010 242 501 | #define B11110011 243 502 | #define B11110100 244 503 | #define B11110101 245 504 | #define B11110110 246 505 | #define B11110111 247 506 | #define B11111000 248 507 | #define B11111001 249 508 | #define B11111010 250 509 | #define B11111011 251 510 | #define B11111100 252 511 | #define B11111101 253 512 | #define B11111110 254 513 | #define B11111111 255 514 | 515 | #endif 516 | -------------------------------------------------------------------------------- /arduino.DuinOS/DuinOS/list.h: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V5.4.2 - Copyright (C) 2009 Real Time Engineers Ltd. 3 | 4 | This file is part of the FreeRTOS distribution. 5 | 6 | FreeRTOS is free software; you can redistribute it and/or modify it under 7 | the terms of the GNU General Public License (version 2) as published by the 8 | Free Software Foundation and modified by the FreeRTOS exception. 9 | **NOTE** The exception to the GPL is included to allow you to distribute a 10 | combined work that includes FreeRTOS without being obliged to provide the 11 | source code for proprietary components outside of the FreeRTOS kernel. 12 | Alternative commercial license and support terms are also available upon 13 | request. See the licensing section of http://www.FreeRTOS.org for full 14 | license details. 15 | 16 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 19 | more details. 20 | 21 | You should have received a copy of the GNU General Public License along 22 | with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59 23 | Temple Place, Suite 330, Boston, MA 02111-1307 USA. 24 | 25 | 26 | *************************************************************************** 27 | * * 28 | * Looking for a quick start? Then check out the FreeRTOS eBook! * 29 | * See http://www.FreeRTOS.org/Documentation for details * 30 | * * 31 | *************************************************************************** 32 | 33 | 1 tab == 4 spaces! 34 | 35 | Please ensure to read the configuration and relevant port sections of the 36 | online documentation. 37 | 38 | http://www.FreeRTOS.org - Documentation, latest information, license and 39 | contact details. 40 | 41 | http://www.SafeRTOS.com - A version that is certified for use in safety 42 | critical systems. 43 | 44 | http://www.OpenRTOS.com - Commercial support, development, porting, 45 | licensing and training services. 46 | */ 47 | 48 | /* 49 | * This is the list implementation used by the scheduler. While it is tailored 50 | * heavily for the schedulers needs, it is also available for use by 51 | * application code. 52 | * 53 | * xLists can only store pointers to xListItems. Each xListItem contains a 54 | * numeric value (xItemValue). Most of the time the lists are sorted in 55 | * descending item value order. 56 | * 57 | * Lists are created already containing one list item. The value of this 58 | * item is the maximum possible that can be stored, it is therefore always at 59 | * the end of the list and acts as a marker. The list member pxHead always 60 | * points to this marker - even though it is at the tail of the list. This 61 | * is because the tail contains a wrap back pointer to the true head of 62 | * the list. 63 | * 64 | * In addition to it's value, each list item contains a pointer to the next 65 | * item in the list (pxNext), a pointer to the list it is in (pxContainer) 66 | * and a pointer to back to the object that contains it. These later two 67 | * pointers are included for efficiency of list manipulation. There is 68 | * effectively a two way link between the object containing the list item and 69 | * the list item itself. 70 | * 71 | * 72 | * \page ListIntroduction List Implementation 73 | * \ingroup FreeRTOSIntro 74 | */ 75 | 76 | /* 77 | Changes from V4.3.1 78 | 79 | + Included local const within listGET_OWNER_OF_NEXT_ENTRY() to assist 80 | compiler with optimisation. Thanks B.R. 81 | */ 82 | 83 | #ifndef LIST_H 84 | #define LIST_H 85 | 86 | #ifdef __cplusplus 87 | extern "C" { 88 | #endif 89 | /* 90 | * Definition of the only type of object that a list can contain. 91 | */ 92 | struct xLIST_ITEM 93 | { 94 | portTickType xItemValue; /*< The value being listed. In most cases this is used to sort the list in descending order. */ 95 | volatile struct xLIST_ITEM * pxNext; /*< Pointer to the next xListItem in the list. */ 96 | volatile struct xLIST_ITEM * pxPrevious;/*< Pointer to the previous xListItem in the list. */ 97 | void * pvOwner; /*< Pointer to the object (normally a TCB) that contains the list item. There is therefore a two way link between the object containing the list item and the list item itself. */ 98 | void * pvContainer; /*< Pointer to the list in which this list item is placed (if any). */ 99 | }; 100 | typedef struct xLIST_ITEM xListItem; /* For some reason lint wants this as two separate definitions. */ 101 | 102 | struct xMINI_LIST_ITEM 103 | { 104 | portTickType xItemValue; 105 | volatile struct xLIST_ITEM *pxNext; 106 | volatile struct xLIST_ITEM *pxPrevious; 107 | }; 108 | typedef struct xMINI_LIST_ITEM xMiniListItem; 109 | 110 | /* 111 | * Definition of the type of queue used by the scheduler. 112 | */ 113 | typedef struct xLIST 114 | { 115 | volatile unsigned portBASE_TYPE uxNumberOfItems; 116 | volatile xListItem * pxIndex; /*< Used to walk through the list. Points to the last item returned by a call to pvListGetOwnerOfNextEntry (). */ 117 | volatile xMiniListItem xListEnd; /*< List item that contains the maximum possible item value meaning it is always at the end of the list and is therefore used as a marker. */ 118 | } xList; 119 | 120 | /* 121 | * Access macro to set the owner of a list item. The owner of a list item 122 | * is the object (usually a TCB) that contains the list item. 123 | * 124 | * \page listSET_LIST_ITEM_OWNER listSET_LIST_ITEM_OWNER 125 | * \ingroup LinkedList 126 | */ 127 | #define listSET_LIST_ITEM_OWNER( pxListItem, pxOwner ) ( pxListItem )->pvOwner = ( void * ) pxOwner 128 | 129 | /* 130 | * Access macro to set the value of the list item. In most cases the value is 131 | * used to sort the list in descending order. 132 | * 133 | * \page listSET_LIST_ITEM_VALUE listSET_LIST_ITEM_VALUE 134 | * \ingroup LinkedList 135 | */ 136 | #define listSET_LIST_ITEM_VALUE( pxListItem, xValue ) ( pxListItem )->xItemValue = xValue 137 | 138 | /* 139 | * Access macro the retrieve the value of the list item. The value can 140 | * represent anything - for example a the priority of a task, or the time at 141 | * which a task should be unblocked. 142 | * 143 | * \page listGET_LIST_ITEM_VALUE listGET_LIST_ITEM_VALUE 144 | * \ingroup LinkedList 145 | */ 146 | #define listGET_LIST_ITEM_VALUE( pxListItem ) ( ( pxListItem )->xItemValue ) 147 | 148 | /* 149 | * Access macro to determine if a list contains any items. The macro will 150 | * only have the value true if the list is empty. 151 | * 152 | * \page listLIST_IS_EMPTY listLIST_IS_EMPTY 153 | * \ingroup LinkedList 154 | */ 155 | #define listLIST_IS_EMPTY( pxList ) ( ( pxList )->uxNumberOfItems == ( unsigned portBASE_TYPE ) 0 ) 156 | 157 | /* 158 | * Access macro to return the number of items in the list. 159 | */ 160 | #define listCURRENT_LIST_LENGTH( pxList ) ( ( pxList )->uxNumberOfItems ) 161 | 162 | /* 163 | * Access function to obtain the owner of the next entry in a list. 164 | * 165 | * The list member pxIndex is used to walk through a list. Calling 166 | * listGET_OWNER_OF_NEXT_ENTRY increments pxIndex to the next item in the list 167 | * and returns that entries pxOwner parameter. Using multiple calls to this 168 | * function it is therefore possible to move through every item contained in 169 | * a list. 170 | * 171 | * The pxOwner parameter of a list item is a pointer to the object that owns 172 | * the list item. In the scheduler this is normally a task control block. 173 | * The pxOwner parameter effectively creates a two way link between the list 174 | * item and its owner. 175 | * 176 | * @param pxList The list from which the next item owner is to be returned. 177 | * 178 | * \page listGET_OWNER_OF_NEXT_ENTRY listGET_OWNER_OF_NEXT_ENTRY 179 | * \ingroup LinkedList 180 | */ 181 | #define listGET_OWNER_OF_NEXT_ENTRY( pxTCB, pxList ) \ 182 | { \ 183 | xList * const pxConstList = pxList; \ 184 | /* Increment the index to the next item and return the item, ensuring */ \ 185 | /* we don't return the marker used at the end of the list. */ \ 186 | ( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext; \ 187 | if( ( pxConstList )->pxIndex == ( xListItem * ) &( ( pxConstList )->xListEnd ) ) \ 188 | { \ 189 | ( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext; \ 190 | } \ 191 | pxTCB = ( pxConstList )->pxIndex->pvOwner; \ 192 | } 193 | 194 | 195 | /* 196 | * Access function to obtain the owner of the first entry in a list. Lists 197 | * are normally sorted in ascending item value order. 198 | * 199 | * This function returns the pxOwner member of the first item in the list. 200 | * The pxOwner parameter of a list item is a pointer to the object that owns 201 | * the list item. In the scheduler this is normally a task control block. 202 | * The pxOwner parameter effectively creates a two way link between the list 203 | * item and its owner. 204 | * 205 | * @param pxList The list from which the owner of the head item is to be 206 | * returned. 207 | * 208 | * \page listGET_OWNER_OF_HEAD_ENTRY listGET_OWNER_OF_HEAD_ENTRY 209 | * \ingroup LinkedList 210 | */ 211 | #define listGET_OWNER_OF_HEAD_ENTRY( pxList ) ( ( pxList->uxNumberOfItems != ( unsigned portBASE_TYPE ) 0 ) ? ( (&( pxList->xListEnd ))->pxNext->pvOwner ) : ( NULL ) ) 212 | 213 | /* 214 | * Check to see if a list item is within a list. The list item maintains a 215 | * "container" pointer that points to the list it is in. All this macro does 216 | * is check to see if the container and the list match. 217 | * 218 | * @param pxList The list we want to know if the list item is within. 219 | * @param pxListItem The list item we want to know if is in the list. 220 | * @return pdTRUE is the list item is in the list, otherwise pdFALSE. 221 | * pointer against 222 | */ 223 | #define listIS_CONTAINED_WITHIN( pxList, pxListItem ) ( ( pxListItem )->pvContainer == ( void * ) pxList ) 224 | 225 | /* 226 | * Must be called before a list is used! This initialises all the members 227 | * of the list structure and inserts the xListEnd item into the list as a 228 | * marker to the back of the list. 229 | * 230 | * @param pxList Pointer to the list being initialised. 231 | * 232 | * \page vListInitialise vListInitialise 233 | * \ingroup LinkedList 234 | */ 235 | void vListInitialise( xList *pxList ); 236 | 237 | /* 238 | * Must be called before a list item is used. This sets the list container to 239 | * null so the item does not think that it is already contained in a list. 240 | * 241 | * @param pxItem Pointer to the list item being initialised. 242 | * 243 | * \page vListInitialiseItem vListInitialiseItem 244 | * \ingroup LinkedList 245 | */ 246 | void vListInitialiseItem( xListItem *pxItem ); 247 | 248 | /* 249 | * Insert a list item into a list. The item will be inserted into the list in 250 | * a position determined by its item value (descending item value order). 251 | * 252 | * @param pxList The list into which the item is to be inserted. 253 | * 254 | * @param pxNewListItem The item to that is to be placed in the list. 255 | * 256 | * \page vListInsert vListInsert 257 | * \ingroup LinkedList 258 | */ 259 | void vListInsert( xList *pxList, xListItem *pxNewListItem ); 260 | 261 | /* 262 | * Insert a list item into a list. The item will be inserted in a position 263 | * such that it will be the last item within the list returned by multiple 264 | * calls to listGET_OWNER_OF_NEXT_ENTRY. 265 | * 266 | * The list member pvIndex is used to walk through a list. Calling 267 | * listGET_OWNER_OF_NEXT_ENTRY increments pvIndex to the next item in the list. 268 | * Placing an item in a list using vListInsertEnd effectively places the item 269 | * in the list position pointed to by pvIndex. This means that every other 270 | * item within the list will be returned by listGET_OWNER_OF_NEXT_ENTRY before 271 | * the pvIndex parameter again points to the item being inserted. 272 | * 273 | * @param pxList The list into which the item is to be inserted. 274 | * 275 | * @param pxNewListItem The list item to be inserted into the list. 276 | * 277 | * \page vListInsertEnd vListInsertEnd 278 | * \ingroup LinkedList 279 | */ 280 | void vListInsertEnd( xList *pxList, xListItem *pxNewListItem ); 281 | 282 | /* 283 | * Remove an item from a list. The list item has a pointer to the list that 284 | * it is in, so only the list item need be passed into the function. 285 | * 286 | * @param vListRemove The item to be removed. The item will remove itself from 287 | * the list pointed to by it's pxContainer parameter. 288 | * 289 | * \page vListRemove vListRemove 290 | * \ingroup LinkedList 291 | */ 292 | void vListRemove( xListItem *pxItemToRemove ); 293 | 294 | #ifdef __cplusplus 295 | } 296 | #endif 297 | 298 | #endif 299 | 300 | -------------------------------------------------------------------------------- /arduino.DuinOS/DuinOS/FreeRTOS.h: -------------------------------------------------------------------------------- 1 | /* 2 | FreeRTOS V5.4.2 - Copyright (C) 2009 Real Time Engineers Ltd. 3 | 4 | This file is part of the FreeRTOS distribution. 5 | 6 | FreeRTOS is free software; you can redistribute it and/or modify it under 7 | the terms of the GNU General Public License (version 2) as published by the 8 | Free Software Foundation and modified by the FreeRTOS exception. 9 | **NOTE** The exception to the GPL is included to allow you to distribute a 10 | combined work that includes FreeRTOS without being obliged to provide the 11 | source code for proprietary components outside of the FreeRTOS kernel. 12 | Alternative commercial license and support terms are also available upon 13 | request. See the licensing section of http://www.FreeRTOS.org for full 14 | license details. 15 | 16 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 19 | more details. 20 | 21 | You should have received a copy of the GNU General Public License along 22 | with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59 23 | Temple Place, Suite 330, Boston, MA 02111-1307 USA. 24 | 25 | 26 | *************************************************************************** 27 | * * 28 | * Looking for a quick start? Then check out the FreeRTOS eBook! * 29 | * See http://www.FreeRTOS.org/Documentation for details * 30 | * * 31 | *************************************************************************** 32 | 33 | 1 tab == 4 spaces! 34 | 35 | Please ensure to read the configuration and relevant port sections of the 36 | online documentation. 37 | 38 | http://www.FreeRTOS.org - Documentation, latest information, license and 39 | contact details. 40 | 41 | http://www.SafeRTOS.com - A version that is certified for use in safety 42 | critical systems. 43 | 44 | http://www.OpenRTOS.com - Commercial support, development, porting, 45 | licensing and training services. 46 | */ 47 | 48 | #ifndef INC_FREERTOS_H 49 | #define INC_FREERTOS_H 50 | 51 | 52 | /* 53 | * Include the generic headers required for the FreeRTOS port being used. 54 | */ 55 | #include 56 | 57 | /* Basic FreeRTOS definitions. */ 58 | #include "projdefs.h" 59 | 60 | /* Application specific configuration options. */ 61 | #include "FreeRTOSConfig.h" 62 | 63 | /* Definitions specific to the port being used. */ 64 | #include "portable.h" 65 | 66 | 67 | 68 | 69 | /* Defines the prototype to which the application task hook function must 70 | conform. */ 71 | typedef portBASE_TYPE (*pdTASK_HOOK_CODE)( void * ); 72 | 73 | 74 | 75 | 76 | 77 | /* 78 | * Check all the required application specific macros have been defined. 79 | * These macros are application specific and (as downloaded) are defined 80 | * within FreeRTOSConfig.h. 81 | */ 82 | 83 | #ifndef configUSE_PREEMPTION 84 | #error Missing definition: configUSE_PREEMPTION should be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. 85 | #endif 86 | 87 | #ifndef configUSE_IDLE_HOOK 88 | #error Missing definition: configUSE_IDLE_HOOK should be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. 89 | #endif 90 | 91 | #ifndef configUSE_TICK_HOOK 92 | #error Missing definition: configUSE_TICK_HOOK should be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. 93 | #endif 94 | 95 | #ifndef configUSE_CO_ROUTINES 96 | #error Missing definition: configUSE_CO_ROUTINES should be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. 97 | #endif 98 | 99 | #ifndef INCLUDE_vTaskPrioritySet 100 | #error Missing definition: INCLUDE_vTaskPrioritySet should be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. 101 | #endif 102 | 103 | #ifndef INCLUDE_uxTaskPriorityGet 104 | #error Missing definition: INCLUDE_uxTaskPriorityGet should be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. 105 | #endif 106 | 107 | #ifndef INCLUDE_vTaskDelete 108 | #error Missing definition: INCLUDE_vTaskDelete should be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. 109 | #endif 110 | 111 | #ifndef INCLUDE_vTaskCleanUpResources 112 | #error Missing definition: INCLUDE_vTaskCleanUpResources should be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. 113 | #endif 114 | 115 | #ifndef INCLUDE_vTaskSuspend 116 | #error Missing definition: INCLUDE_vTaskSuspend should be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. 117 | #endif 118 | 119 | #ifndef INCLUDE_vTaskDelayUntil 120 | #error Missing definition: INCLUDE_vTaskDelayUntil should be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. 121 | #endif 122 | 123 | #ifndef INCLUDE_vTaskDelay 124 | #error Missing definition: INCLUDE_vTaskDelay should be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. 125 | #endif 126 | 127 | #ifndef configUSE_16_BIT_TICKS 128 | #error Missing definition: configUSE_16_BIT_TICKS should be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. 129 | #endif 130 | 131 | #ifndef configUSE_APPLICATION_TASK_TAG 132 | #define configUSE_APPLICATION_TASK_TAG 0 133 | #endif 134 | 135 | #ifndef INCLUDE_uxTaskGetStackHighWaterMark 136 | #define INCLUDE_uxTaskGetStackHighWaterMark 0 137 | #endif 138 | 139 | #ifndef configUSE_RECURSIVE_MUTEXES 140 | #define configUSE_RECURSIVE_MUTEXES 0 141 | #endif 142 | 143 | #ifndef configUSE_MUTEXES 144 | #define configUSE_MUTEXES 0 145 | #endif 146 | 147 | #ifndef configUSE_COUNTING_SEMAPHORES 148 | #define configUSE_COUNTING_SEMAPHORES 0 149 | #endif 150 | 151 | #ifndef configUSE_ALTERNATIVE_API 152 | #define configUSE_ALTERNATIVE_API 0 153 | #endif 154 | 155 | #ifndef portCRITICAL_NESTING_IN_TCB 156 | #define portCRITICAL_NESTING_IN_TCB 0 157 | #endif 158 | 159 | #ifndef configMAX_TASK_NAME_LEN 160 | #define configMAX_TASK_NAME_LEN 16 161 | #endif 162 | 163 | #ifndef configIDLE_SHOULD_YIELD 164 | #define configIDLE_SHOULD_YIELD 1 165 | #endif 166 | 167 | #if configMAX_TASK_NAME_LEN < 1 168 | #undef configMAX_TASK_NAME_LEN 169 | #define configMAX_TASK_NAME_LEN 1 170 | #endif 171 | 172 | #ifndef INCLUDE_xTaskResumeFromISR 173 | #define INCLUDE_xTaskResumeFromISR 1 174 | #endif 175 | 176 | #ifndef INCLUDE_xTaskGetSchedulerState 177 | #define INCLUDE_xTaskGetSchedulerState 0 178 | #endif 179 | 180 | #if ( configUSE_MUTEXES == 1 ) 181 | /* xTaskGetCurrentTaskHandle is used by the priority inheritance mechanism 182 | within the mutex implementation so must be available if mutexes are used. */ 183 | #undef INCLUDE_xTaskGetCurrentTaskHandle 184 | #define INCLUDE_xTaskGetCurrentTaskHandle 1 185 | #else 186 | #ifndef INCLUDE_xTaskGetCurrentTaskHandle 187 | #define INCLUDE_xTaskGetCurrentTaskHandle 0 188 | #endif 189 | #endif 190 | 191 | 192 | #ifndef portSET_INTERRUPT_MASK_FROM_ISR 193 | #define portSET_INTERRUPT_MASK_FROM_ISR() 0 194 | #endif 195 | 196 | #ifndef portCLEAR_INTERRUPT_MASK_FROM_ISR 197 | #define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusValue ) ( void ) uxSavedStatusValue 198 | #endif 199 | 200 | 201 | #ifndef configQUEUE_REGISTRY_SIZE 202 | #define configQUEUE_REGISTRY_SIZE 0 203 | #endif 204 | 205 | #if configQUEUE_REGISTRY_SIZE < 1 206 | #define configQUEUE_REGISTRY_SIZE 0 207 | #define vQueueAddToRegistry( xQueue, pcName ) 208 | #define vQueueUnregisterQueue( xQueue ) 209 | #endif 210 | 211 | 212 | /* Remove any unused trace macros. */ 213 | #ifndef traceSTART 214 | /* Used to perform any necessary initialisation - for example, open a file 215 | into which trace is to be written. */ 216 | #define traceSTART() 217 | #endif 218 | 219 | #ifndef traceEND 220 | /* Use to close a trace, for example close a file into which trace has been 221 | written. */ 222 | #define traceEND() 223 | #endif 224 | 225 | #ifndef traceTASK_SWITCHED_IN 226 | /* Called after a task has been selected to run. pxCurrentTCB holds a pointer 227 | to the task control block of the selected task. */ 228 | #define traceTASK_SWITCHED_IN() 229 | #endif 230 | 231 | #ifndef traceTASK_SWITCHED_OUT 232 | /* Called before a task has been selected to run. pxCurrentTCB holds a pointer 233 | to the task control block of the task being switched out. */ 234 | #define traceTASK_SWITCHED_OUT() 235 | #endif 236 | 237 | #ifndef traceBLOCKING_ON_QUEUE_RECEIVE 238 | /* Task is about to block because it cannot read from a 239 | queue/mutex/semaphore. pxQueue is a pointer to the queue/mutex/semaphore 240 | upon which the read was attempted. pxCurrentTCB points to the TCB of the 241 | task that attempted the read. */ 242 | #define traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue ) 243 | #endif 244 | 245 | #ifndef traceBLOCKING_ON_QUEUE_SEND 246 | /* Task is about to block because it cannot write to a 247 | queue/mutex/semaphore. pxQueue is a pointer to the queue/mutex/semaphore 248 | upon which the write was attempted. pxCurrentTCB points to the TCB of the 249 | task that attempted the write. */ 250 | #define traceBLOCKING_ON_QUEUE_SEND( pxQueue ) 251 | #endif 252 | 253 | #ifndef configCHECK_FOR_STACK_OVERFLOW 254 | #define configCHECK_FOR_STACK_OVERFLOW 0 255 | #endif 256 | 257 | /* The following event macros are embedded in the kernel API calls. */ 258 | 259 | #ifndef traceQUEUE_CREATE 260 | #define traceQUEUE_CREATE( pxNewQueue ) 261 | #endif 262 | 263 | #ifndef traceQUEUE_CREATE_FAILED 264 | #define traceQUEUE_CREATE_FAILED() 265 | #endif 266 | 267 | #ifndef traceCREATE_MUTEX 268 | #define traceCREATE_MUTEX( pxNewQueue ) 269 | #endif 270 | 271 | #ifndef traceCREATE_MUTEX_FAILED 272 | #define traceCREATE_MUTEX_FAILED() 273 | #endif 274 | 275 | #ifndef traceGIVE_MUTEX_RECURSIVE 276 | #define traceGIVE_MUTEX_RECURSIVE( pxMutex ) 277 | #endif 278 | 279 | #ifndef traceGIVE_MUTEX_RECURSIVE_FAILED 280 | #define traceGIVE_MUTEX_RECURSIVE_FAILED( pxMutex ) 281 | #endif 282 | 283 | #ifndef traceTAKE_MUTEX_RECURSIVE 284 | #define traceTAKE_MUTEX_RECURSIVE( pxMutex ) 285 | #endif 286 | 287 | #ifndef traceCREATE_COUNTING_SEMAPHORE 288 | #define traceCREATE_COUNTING_SEMAPHORE() 289 | #endif 290 | 291 | #ifndef traceCREATE_COUNTING_SEMAPHORE_FAILED 292 | #define traceCREATE_COUNTING_SEMAPHORE_FAILED() 293 | #endif 294 | 295 | #ifndef traceQUEUE_SEND 296 | #define traceQUEUE_SEND( pxQueue ) 297 | #endif 298 | 299 | #ifndef traceQUEUE_SEND_FAILED 300 | #define traceQUEUE_SEND_FAILED( pxQueue ) 301 | #endif 302 | 303 | #ifndef traceQUEUE_RECEIVE 304 | #define traceQUEUE_RECEIVE( pxQueue ) 305 | #endif 306 | 307 | #ifndef traceQUEUE_PEEK 308 | #define traceQUEUE_PEEK( pxQueue ) 309 | #endif 310 | 311 | #ifndef traceQUEUE_RECEIVE_FAILED 312 | #define traceQUEUE_RECEIVE_FAILED( pxQueue ) 313 | #endif 314 | 315 | #ifndef traceQUEUE_SEND_FROM_ISR 316 | #define traceQUEUE_SEND_FROM_ISR( pxQueue ) 317 | #endif 318 | 319 | #ifndef traceQUEUE_SEND_FROM_ISR_FAILED 320 | #define traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue ) 321 | #endif 322 | 323 | #ifndef traceQUEUE_RECEIVE_FROM_ISR 324 | #define traceQUEUE_RECEIVE_FROM_ISR( pxQueue ) 325 | #endif 326 | 327 | #ifndef traceQUEUE_RECEIVE_FROM_ISR_FAILED 328 | #define traceQUEUE_RECEIVE_FROM_ISR_FAILED( pxQueue ) 329 | #endif 330 | 331 | #ifndef traceQUEUE_DELETE 332 | #define traceQUEUE_DELETE( pxQueue ) 333 | #endif 334 | 335 | #ifndef traceTASK_CREATE 336 | #define traceTASK_CREATE( pxNewTCB ) 337 | #endif 338 | 339 | #ifndef traceTASK_CREATE_FAILED 340 | #define traceTASK_CREATE_FAILED( pxNewTCB ) 341 | #endif 342 | 343 | #ifndef traceTASK_DELETE 344 | #define traceTASK_DELETE( pxTaskToDelete ) 345 | #endif 346 | 347 | #ifndef traceTASK_DELAY_UNTIL 348 | #define traceTASK_DELAY_UNTIL() 349 | #endif 350 | 351 | #ifndef traceTASK_DELAY 352 | #define traceTASK_DELAY() 353 | #endif 354 | 355 | #ifndef traceTASK_PRIORITY_SET 356 | #define traceTASK_PRIORITY_SET( pxTask, uxNewPriority ) 357 | #endif 358 | 359 | #ifndef traceTASK_SUSPEND 360 | #define traceTASK_SUSPEND( pxTaskToSuspend ) 361 | #endif 362 | 363 | #ifndef traceTASK_RESUME 364 | #define traceTASK_RESUME( pxTaskToResume ) 365 | #endif 366 | 367 | #ifndef traceTASK_RESUME_FROM_ISR 368 | #define traceTASK_RESUME_FROM_ISR( pxTaskToResume ) 369 | #endif 370 | 371 | #ifndef traceTASK_INCREMENT_TICK 372 | #define traceTASK_INCREMENT_TICK( xTickCount ) 373 | #endif 374 | 375 | #ifndef configGENERATE_RUN_TIME_STATS 376 | #define configGENERATE_RUN_TIME_STATS 0 377 | #endif 378 | 379 | #if ( configGENERATE_RUN_TIME_STATS == 1 ) 380 | 381 | #ifndef portCONFIGURE_TIMER_FOR_RUN_TIME_STATS 382 | #error If configGENERATE_RUN_TIME_STATS is defined then portCONFIGURE_TIMER_FOR_RUN_TIME_STATS must also be defined. portCONFIGURE_TIMER_FOR_RUN_TIME_STATS should call a port layer function to setup a peripheral timer/counter that can then be used as the run time counter time base. 383 | #endif /* portCONFIGURE_TIMER_FOR_RUN_TIME_STATS */ 384 | 385 | #ifndef portGET_RUN_TIME_COUNTER_VALUE 386 | #error If configGENERATE_RUN_TIME_STATS is defined then portGET_RUN_TIME_COUNTER_VALUE must also be defined. portGET_RUN_TIME_COUNTER_VALUE should evaluate to the counter value of the timer/counter peripheral used as the run time counter time base. 387 | #endif /* portGET_RUN_TIME_COUNTER_VALUE */ 388 | 389 | #endif /* configGENERATE_RUN_TIME_STATS */ 390 | 391 | #ifndef portCONFIGURE_TIMER_FOR_RUN_TIME_STATS 392 | #define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() 393 | #endif 394 | 395 | #ifndef configUSE_MALLOC_FAILED_HOOK 396 | #define configUSE_MALLOC_FAILED_HOOK 0 397 | #endif 398 | 399 | #endif /* INC_FREERTOS_H */ 400 | 401 | -------------------------------------------------------------------------------- /arduino.DuinOS/pins_arduino.c: -------------------------------------------------------------------------------- 1 | /* 2 | pins_arduino.c - pin definitions for the Arduino board 3 | Part of Arduino / Wiring Lite 4 | 5 | Copyright (c) 2005 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: pins_arduino.c 565 2009-03-25 10:50:00Z dmellis $ 23 | */ 24 | 25 | #include 26 | #include "wiring_private.h" 27 | #include "pins_arduino.h" 28 | 29 | // On the Arduino board, digital pins are also used 30 | // for the analog output (software PWM). Analog input 31 | // pins are a separate set. 32 | 33 | // ATMEL ATMEGA8 & 168 / ARDUINO 34 | // 35 | // +-\/-+ 36 | // PC6 1| |28 PC5 (AI 5) 37 | // (D 0) PD0 2| |27 PC4 (AI 4) 38 | // (D 1) PD1 3| |26 PC3 (AI 3) 39 | // (D 2) PD2 4| |25 PC2 (AI 2) 40 | // PWM+ (D 3) PD3 5| |24 PC1 (AI 1) 41 | // (D 4) PD4 6| |23 PC0 (AI 0) 42 | // VCC 7| |22 GND 43 | // GND 8| |21 AREF 44 | // PB6 9| |20 AVCC 45 | // PB7 10| |19 PB5 (D 13) 46 | // PWM+ (D 5) PD5 11| |18 PB4 (D 12) 47 | // PWM+ (D 6) PD6 12| |17 PB3 (D 11) PWM 48 | // (D 7) PD7 13| |16 PB2 (D 10) PWM 49 | // (D 8) PB0 14| |15 PB1 (D 9) PWM 50 | // +----+ 51 | // 52 | // (PWM+ indicates the additional PWM pins on the ATmega168.) 53 | 54 | // ATMEL ATMEGA1280 / ARDUINO 55 | // 56 | // 0-7 PE0-PE7 works 57 | // 8-13 PB0-PB5 works 58 | // 14-21 PA0-PA7 works 59 | // 22-29 PH0-PH7 works 60 | // 30-35 PG5-PG0 works 61 | // 36-43 PC7-PC0 works 62 | // 44-51 PJ7-PJ0 works 63 | // 52-59 PL7-PL0 works 64 | // 60-67 PD7-PD0 works 65 | // A0-A7 PF0-PF7 66 | // A8-A15 PK0-PK7 67 | 68 | #define PA 1 69 | #define PB 2 70 | #define PC 3 71 | #define PD 4 72 | #define PE 5 73 | #define PF 6 74 | #define PG 7 75 | #define PH 8 76 | #define PJ 10 77 | #define PK 11 78 | #define PL 12 79 | 80 | #define REPEAT8(x) x, x, x, x, x, x, x, x 81 | #define BV0TO7 _BV(0), _BV(1), _BV(2), _BV(3), _BV(4), _BV(5), _BV(6), _BV(7) 82 | #define BV7TO0 _BV(7), _BV(6), _BV(5), _BV(4), _BV(3), _BV(2), _BV(1), _BV(0) 83 | 84 | 85 | #if defined(__AVR_ATmega1280__) 86 | const uint16_t PROGMEM port_to_mode_PGM[] = { 87 | NOT_A_PORT, 88 | &DDRA, 89 | &DDRB, 90 | &DDRC, 91 | &DDRD, 92 | &DDRE, 93 | &DDRF, 94 | &DDRG, 95 | &DDRH, 96 | NOT_A_PORT, 97 | &DDRJ, 98 | &DDRK, 99 | &DDRL, 100 | }; 101 | 102 | const uint16_t PROGMEM port_to_output_PGM[] = { 103 | NOT_A_PORT, 104 | &PORTA, 105 | &PORTB, 106 | &PORTC, 107 | &PORTD, 108 | &PORTE, 109 | &PORTF, 110 | &PORTG, 111 | &PORTH, 112 | NOT_A_PORT, 113 | &PORTJ, 114 | &PORTK, 115 | &PORTL, 116 | }; 117 | 118 | const uint16_t PROGMEM port_to_input_PGM[] = { 119 | NOT_A_PIN, 120 | &PINA, 121 | &PINB, 122 | &PINC, 123 | &PIND, 124 | &PINE, 125 | &PINF, 126 | &PING, 127 | &PINH, 128 | NOT_A_PIN, 129 | &PINJ, 130 | &PINK, 131 | &PINL, 132 | }; 133 | 134 | const uint8_t PROGMEM digital_pin_to_port_PGM[] = { 135 | // PORTLIST 136 | // ------------------------------------------- 137 | PE , // PE 0 ** 0 ** USART0_RX 138 | PE , // PE 1 ** 1 ** USART0_TX 139 | PE , // PE 4 ** 2 ** PWM2 140 | PE , // PE 5 ** 3 ** PWM3 141 | PG , // PG 5 ** 4 ** PWM4 142 | PE , // PE 3 ** 5 ** PWM5 143 | PH , // PH 3 ** 6 ** PWM6 144 | PH , // PH 4 ** 7 ** PWM7 145 | PH , // PH 5 ** 8 ** PWM8 146 | PH , // PH 6 ** 9 ** PWM9 147 | PB , // PB 4 ** 10 ** PWM10 148 | PB , // PB 5 ** 11 ** PWM11 149 | PB , // PB 6 ** 12 ** PWM12 150 | PB , // PB 7 ** 13 ** PWM13 151 | PJ , // PJ 1 ** 14 ** USART3_TX 152 | PJ , // PJ 0 ** 15 ** USART3_RX 153 | PH , // PH 1 ** 16 ** USART2_TX 154 | PH , // PH 0 ** 17 ** USART2_RX 155 | PD , // PD 3 ** 18 ** USART1_TX 156 | PD , // PD 2 ** 19 ** USART1_RX 157 | PD , // PD 1 ** 20 ** I2C_SDA 158 | PD , // PD 0 ** 21 ** I2C_SCL 159 | PA , // PA 0 ** 22 ** D22 160 | PA , // PA 1 ** 23 ** D23 161 | PA , // PA 2 ** 24 ** D24 162 | PA , // PA 3 ** 25 ** D25 163 | PA , // PA 4 ** 26 ** D26 164 | PA , // PA 5 ** 27 ** D27 165 | PA , // PA 6 ** 28 ** D28 166 | PA , // PA 7 ** 29 ** D29 167 | PC , // PC 7 ** 30 ** D30 168 | PC , // PC 6 ** 31 ** D31 169 | PC , // PC 5 ** 32 ** D32 170 | PC , // PC 4 ** 33 ** D33 171 | PC , // PC 3 ** 34 ** D34 172 | PC , // PC 2 ** 35 ** D35 173 | PC , // PC 1 ** 36 ** D36 174 | PC , // PC 0 ** 37 ** D37 175 | PD , // PD 7 ** 38 ** D38 176 | PG , // PG 2 ** 39 ** D39 177 | PG , // PG 1 ** 40 ** D40 178 | PG , // PG 0 ** 41 ** D41 179 | PL , // PL 7 ** 42 ** D42 180 | PL , // PL 6 ** 43 ** D43 181 | PL , // PL 5 ** 44 ** D44 182 | PL , // PL 4 ** 45 ** D45 183 | PL , // PL 3 ** 46 ** D46 184 | PL , // PL 2 ** 47 ** D47 185 | PL , // PL 1 ** 48 ** D48 186 | PL , // PL 0 ** 49 ** D49 187 | PB , // PB 3 ** 50 ** SPI_MISO 188 | PB , // PB 2 ** 51 ** SPI_MOSI 189 | PB , // PB 1 ** 52 ** SPI_SCK 190 | PB , // PB 0 ** 53 ** SPI_SS 191 | PF , // PF 0 ** 54 ** A0 192 | PF , // PF 1 ** 55 ** A1 193 | PF , // PF 2 ** 56 ** A2 194 | PF , // PF 3 ** 57 ** A3 195 | PF , // PF 4 ** 58 ** A4 196 | PF , // PF 5 ** 59 ** A5 197 | PF , // PF 6 ** 60 ** A6 198 | PF , // PF 7 ** 61 ** A7 199 | PK , // PK 0 ** 62 ** A8 200 | PK , // PK 1 ** 63 ** A9 201 | PK , // PK 2 ** 64 ** A10 202 | PK , // PK 3 ** 65 ** A11 203 | PK , // PK 4 ** 66 ** A12 204 | PK , // PK 5 ** 67 ** A13 205 | PK , // PK 6 ** 68 ** A14 206 | PK , // PK 7 ** 69 ** A15 207 | }; 208 | 209 | const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = { 210 | // PIN IN PORT 211 | // ------------------------------------------- 212 | _BV( 0 ) , // PE 0 ** 0 ** USART0_RX 213 | _BV( 1 ) , // PE 1 ** 1 ** USART0_TX 214 | _BV( 4 ) , // PE 4 ** 2 ** PWM2 215 | _BV( 5 ) , // PE 5 ** 3 ** PWM3 216 | _BV( 5 ) , // PG 5 ** 4 ** PWM4 217 | _BV( 3 ) , // PE 3 ** 5 ** PWM5 218 | _BV( 3 ) , // PH 3 ** 6 ** PWM6 219 | _BV( 4 ) , // PH 4 ** 7 ** PWM7 220 | _BV( 5 ) , // PH 5 ** 8 ** PWM8 221 | _BV( 6 ) , // PH 6 ** 9 ** PWM9 222 | _BV( 4 ) , // PB 4 ** 10 ** PWM10 223 | _BV( 5 ) , // PB 5 ** 11 ** PWM11 224 | _BV( 6 ) , // PB 6 ** 12 ** PWM12 225 | _BV( 7 ) , // PB 7 ** 13 ** PWM13 226 | _BV( 1 ) , // PJ 1 ** 14 ** USART3_TX 227 | _BV( 0 ) , // PJ 0 ** 15 ** USART3_RX 228 | _BV( 1 ) , // PH 1 ** 16 ** USART2_TX 229 | _BV( 0 ) , // PH 0 ** 17 ** USART2_RX 230 | _BV( 3 ) , // PD 3 ** 18 ** USART1_TX 231 | _BV( 2 ) , // PD 2 ** 19 ** USART1_RX 232 | _BV( 1 ) , // PD 1 ** 20 ** I2C_SDA 233 | _BV( 0 ) , // PD 0 ** 21 ** I2C_SCL 234 | _BV( 0 ) , // PA 0 ** 22 ** D22 235 | _BV( 1 ) , // PA 1 ** 23 ** D23 236 | _BV( 2 ) , // PA 2 ** 24 ** D24 237 | _BV( 3 ) , // PA 3 ** 25 ** D25 238 | _BV( 4 ) , // PA 4 ** 26 ** D26 239 | _BV( 5 ) , // PA 5 ** 27 ** D27 240 | _BV( 6 ) , // PA 6 ** 28 ** D28 241 | _BV( 7 ) , // PA 7 ** 29 ** D29 242 | _BV( 7 ) , // PC 7 ** 30 ** D30 243 | _BV( 6 ) , // PC 6 ** 31 ** D31 244 | _BV( 5 ) , // PC 5 ** 32 ** D32 245 | _BV( 4 ) , // PC 4 ** 33 ** D33 246 | _BV( 3 ) , // PC 3 ** 34 ** D34 247 | _BV( 2 ) , // PC 2 ** 35 ** D35 248 | _BV( 1 ) , // PC 1 ** 36 ** D36 249 | _BV( 0 ) , // PC 0 ** 37 ** D37 250 | _BV( 7 ) , // PD 7 ** 38 ** D38 251 | _BV( 2 ) , // PG 2 ** 39 ** D39 252 | _BV( 1 ) , // PG 1 ** 40 ** D40 253 | _BV( 0 ) , // PG 0 ** 41 ** D41 254 | _BV( 7 ) , // PL 7 ** 42 ** D42 255 | _BV( 6 ) , // PL 6 ** 43 ** D43 256 | _BV( 5 ) , // PL 5 ** 44 ** D44 257 | _BV( 4 ) , // PL 4 ** 45 ** D45 258 | _BV( 3 ) , // PL 3 ** 46 ** D46 259 | _BV( 2 ) , // PL 2 ** 47 ** D47 260 | _BV( 1 ) , // PL 1 ** 48 ** D48 261 | _BV( 0 ) , // PL 0 ** 49 ** D49 262 | _BV( 3 ) , // PB 3 ** 50 ** SPI_MISO 263 | _BV( 2 ) , // PB 2 ** 51 ** SPI_MOSI 264 | _BV( 1 ) , // PB 1 ** 52 ** SPI_SCK 265 | _BV( 0 ) , // PB 0 ** 53 ** SPI_SS 266 | _BV( 0 ) , // PF 0 ** 54 ** A0 267 | _BV( 1 ) , // PF 1 ** 55 ** A1 268 | _BV( 2 ) , // PF 2 ** 56 ** A2 269 | _BV( 3 ) , // PF 3 ** 57 ** A3 270 | _BV( 4 ) , // PF 4 ** 58 ** A4 271 | _BV( 5 ) , // PF 5 ** 59 ** A5 272 | _BV( 6 ) , // PF 6 ** 60 ** A6 273 | _BV( 7 ) , // PF 7 ** 61 ** A7 274 | _BV( 0 ) , // PK 0 ** 62 ** A8 275 | _BV( 1 ) , // PK 1 ** 63 ** A9 276 | _BV( 2 ) , // PK 2 ** 64 ** A10 277 | _BV( 3 ) , // PK 3 ** 65 ** A11 278 | _BV( 4 ) , // PK 4 ** 66 ** A12 279 | _BV( 5 ) , // PK 5 ** 67 ** A13 280 | _BV( 6 ) , // PK 6 ** 68 ** A14 281 | _BV( 7 ) , // PK 7 ** 69 ** A15 282 | }; 283 | 284 | const uint8_t PROGMEM digital_pin_to_timer_PGM[] = { 285 | // TIMERS 286 | // ------------------------------------------- 287 | NOT_ON_TIMER , // PE 0 ** 0 ** USART0_RX 288 | NOT_ON_TIMER , // PE 1 ** 1 ** USART0_TX 289 | TIMER3B , // PE 4 ** 2 ** PWM2 290 | TIMER3C , // PE 5 ** 3 ** PWM3 291 | TIMER0B , // PG 5 ** 4 ** PWM4 292 | TIMER3A , // PE 3 ** 5 ** PWM5 293 | TIMER4A , // PH 3 ** 6 ** PWM6 294 | TIMER4B , // PH 4 ** 7 ** PWM7 295 | TIMER4C , // PH 5 ** 8 ** PWM8 296 | TIMER2B , // PH 6 ** 9 ** PWM9 297 | TIMER2A , // PB 4 ** 10 ** PWM10 298 | TIMER1A , // PB 5 ** 11 ** PWM11 299 | TIMER1B , // PB 6 ** 12 ** PWM12 300 | TIMER0A , // PB 7 ** 13 ** PWM13 301 | NOT_ON_TIMER , // PJ 1 ** 14 ** USART3_TX 302 | NOT_ON_TIMER , // PJ 0 ** 15 ** USART3_RX 303 | NOT_ON_TIMER , // PH 1 ** 16 ** USART2_TX 304 | NOT_ON_TIMER , // PH 0 ** 17 ** USART2_RX 305 | NOT_ON_TIMER , // PD 3 ** 18 ** USART1_TX 306 | NOT_ON_TIMER , // PD 2 ** 19 ** USART1_RX 307 | NOT_ON_TIMER , // PD 1 ** 20 ** I2C_SDA 308 | NOT_ON_TIMER , // PD 0 ** 21 ** I2C_SCL 309 | NOT_ON_TIMER , // PA 0 ** 22 ** D22 310 | NOT_ON_TIMER , // PA 1 ** 23 ** D23 311 | NOT_ON_TIMER , // PA 2 ** 24 ** D24 312 | NOT_ON_TIMER , // PA 3 ** 25 ** D25 313 | NOT_ON_TIMER , // PA 4 ** 26 ** D26 314 | NOT_ON_TIMER , // PA 5 ** 27 ** D27 315 | NOT_ON_TIMER , // PA 6 ** 28 ** D28 316 | NOT_ON_TIMER , // PA 7 ** 29 ** D29 317 | NOT_ON_TIMER , // PC 7 ** 30 ** D30 318 | NOT_ON_TIMER , // PC 6 ** 31 ** D31 319 | NOT_ON_TIMER , // PC 5 ** 32 ** D32 320 | NOT_ON_TIMER , // PC 4 ** 33 ** D33 321 | NOT_ON_TIMER , // PC 3 ** 34 ** D34 322 | NOT_ON_TIMER , // PC 2 ** 35 ** D35 323 | NOT_ON_TIMER , // PC 1 ** 36 ** D36 324 | NOT_ON_TIMER , // PC 0 ** 37 ** D37 325 | NOT_ON_TIMER , // PD 7 ** 38 ** D38 326 | NOT_ON_TIMER , // PG 2 ** 39 ** D39 327 | NOT_ON_TIMER , // PG 1 ** 40 ** D40 328 | NOT_ON_TIMER , // PG 0 ** 41 ** D41 329 | NOT_ON_TIMER , // PL 7 ** 42 ** D42 330 | NOT_ON_TIMER , // PL 6 ** 43 ** D43 331 | TIMER5C , // PL 5 ** 44 ** D44 332 | TIMER5B , // PL 4 ** 45 ** D45 333 | TIMER5A , // PL 3 ** 46 ** D46 334 | NOT_ON_TIMER , // PL 2 ** 47 ** D47 335 | NOT_ON_TIMER , // PL 1 ** 48 ** D48 336 | NOT_ON_TIMER , // PL 0 ** 49 ** D49 337 | NOT_ON_TIMER , // PB 3 ** 50 ** SPI_MISO 338 | NOT_ON_TIMER , // PB 2 ** 51 ** SPI_MOSI 339 | NOT_ON_TIMER , // PB 1 ** 52 ** SPI_SCK 340 | NOT_ON_TIMER , // PB 0 ** 53 ** SPI_SS 341 | NOT_ON_TIMER , // PF 0 ** 54 ** A0 342 | NOT_ON_TIMER , // PF 1 ** 55 ** A1 343 | NOT_ON_TIMER , // PF 2 ** 56 ** A2 344 | NOT_ON_TIMER , // PF 3 ** 57 ** A3 345 | NOT_ON_TIMER , // PF 4 ** 58 ** A4 346 | NOT_ON_TIMER , // PF 5 ** 59 ** A5 347 | NOT_ON_TIMER , // PF 6 ** 60 ** A6 348 | NOT_ON_TIMER , // PF 7 ** 61 ** A7 349 | NOT_ON_TIMER , // PK 0 ** 62 ** A8 350 | NOT_ON_TIMER , // PK 1 ** 63 ** A9 351 | NOT_ON_TIMER , // PK 2 ** 64 ** A10 352 | NOT_ON_TIMER , // PK 3 ** 65 ** A11 353 | NOT_ON_TIMER , // PK 4 ** 66 ** A12 354 | NOT_ON_TIMER , // PK 5 ** 67 ** A13 355 | NOT_ON_TIMER , // PK 6 ** 68 ** A14 356 | NOT_ON_TIMER , // PK 7 ** 69 ** A15 357 | }; 358 | #else 359 | // these arrays map port names (e.g. port B) to the 360 | // appropriate addresses for various functions (e.g. reading 361 | // and writing) 362 | const uint16_t PROGMEM port_to_mode_PGM[] = { 363 | NOT_A_PORT, 364 | NOT_A_PORT, 365 | &DDRB, 366 | &DDRC, 367 | &DDRD, 368 | }; 369 | 370 | const uint16_t PROGMEM port_to_output_PGM[] = { 371 | NOT_A_PORT, 372 | NOT_A_PORT, 373 | &PORTB, 374 | &PORTC, 375 | &PORTD, 376 | }; 377 | 378 | const uint16_t PROGMEM port_to_input_PGM[] = { 379 | NOT_A_PORT, 380 | NOT_A_PORT, 381 | &PINB, 382 | &PINC, 383 | &PIND, 384 | }; 385 | 386 | const uint8_t PROGMEM digital_pin_to_port_PGM[] = { 387 | PD, /* 0 */ 388 | PD, 389 | PD, 390 | PD, 391 | PD, 392 | PD, 393 | PD, 394 | PD, 395 | PB, /* 8 */ 396 | PB, 397 | PB, 398 | PB, 399 | PB, 400 | PB, 401 | PC, /* 14 */ 402 | PC, 403 | PC, 404 | PC, 405 | PC, 406 | PC, 407 | }; 408 | 409 | const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = { 410 | _BV(0), /* 0, port D */ 411 | _BV(1), 412 | _BV(2), 413 | _BV(3), 414 | _BV(4), 415 | _BV(5), 416 | _BV(6), 417 | _BV(7), 418 | _BV(0), /* 8, port B */ 419 | _BV(1), 420 | _BV(2), 421 | _BV(3), 422 | _BV(4), 423 | _BV(5), 424 | _BV(0), /* 14, port C */ 425 | _BV(1), 426 | _BV(2), 427 | _BV(3), 428 | _BV(4), 429 | _BV(5), 430 | }; 431 | 432 | const uint8_t PROGMEM digital_pin_to_timer_PGM[] = { 433 | NOT_ON_TIMER, /* 0 - port D */ 434 | NOT_ON_TIMER, 435 | NOT_ON_TIMER, 436 | // on the ATmega168, digital pin 3 has hardware pwm 437 | #if defined(__AVR_ATmega8__) 438 | NOT_ON_TIMER, 439 | #else 440 | TIMER2B, 441 | #endif 442 | NOT_ON_TIMER, 443 | // on the ATmega168, digital pins 5 and 6 have hardware pwm 444 | #if defined(__AVR_ATmega8__) 445 | NOT_ON_TIMER, 446 | NOT_ON_TIMER, 447 | #else 448 | TIMER0B, 449 | TIMER0A, 450 | #endif 451 | NOT_ON_TIMER, 452 | NOT_ON_TIMER, /* 8 - port B */ 453 | TIMER1A, 454 | TIMER1B, 455 | #if defined(__AVR_ATmega8__) 456 | TIMER2, 457 | #else 458 | TIMER2A, 459 | #endif 460 | NOT_ON_TIMER, 461 | NOT_ON_TIMER, 462 | NOT_ON_TIMER, 463 | NOT_ON_TIMER, /* 14 - port C */ 464 | NOT_ON_TIMER, 465 | NOT_ON_TIMER, 466 | NOT_ON_TIMER, 467 | NOT_ON_TIMER, 468 | }; 469 | #endif 470 | --------------------------------------------------------------------------------