From 93598e3a7a4fdcf21b5e7e12b94f2b3f11ddcea7 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Thu, 1 Nov 2012 22:05:40 -0200 Subject: [PATCH 01/56] Premeiro commit, sucesso no teste do exemplo MoreComplexBlinking DuinOS, freeRTOS 7.3.0 e IDE Arduino 1.5.0 AVR. --- .../Arduino.h | 7 +- .../CDC.cpp | 112 ++- .../Client.h | 0 .../DuinOS.h | 0 .../DuinOS/FreeRTOS.h | 69 +- .../DuinOS/StackMacros.h | 33 +- .../DuinOS/croutine.c | 45 +- .../DuinOS/croutine.h | 33 +- .../DuinOS/heap_1.c | 58 +- .../DuinOS/heap_2.c | 48 +- .../DuinOS/heap_3.c | 39 +- arduino.DuinOS.AVR/DuinOS/heap_4.c | 359 ++++++++ .../DuinOS/list.c | 41 +- .../DuinOS/list.h | 68 +- .../DuinOS/mpu_wrappers.h | 38 +- .../DuinOS/port.c | 861 +++++++++--------- .../DuinOS/portable.h | 33 +- arduino.DuinOS.AVR/DuinOS/portmacro.h | 144 +++ .../DuinOS/projdefs.h | 33 +- .../DuinOS/queue.c | 156 +++- .../DuinOS/queue.h | 58 +- .../DuinOS/semphr.h | 86 +- .../DuinOS/task.h | 102 ++- .../DuinOS/tasks.c | 578 +++++++++--- arduino.DuinOS.AVR/DuinOS/timers.c | 688 ++++++++++++++ .../DuinOS/timers.h | 33 +- .../FreeRTOSConfig.h | 0 .../HID.cpp | 144 ++- .../HardwareSerial.cpp | 118 ++- .../HardwareSerial.h | 53 +- .../IPAddress.cpp | 0 .../IPAddress.h | 0 .../Platform.h | 0 .../Print.cpp | 7 +- .../Print.h | 5 +- .../Printable.h | 0 .../Server.h | 0 .../Stream.cpp | 44 +- .../Stream.h | 2 + .../Tone.cpp | 31 +- .../USBAPI.h | 82 +- .../USBCore.cpp | 32 +- .../USBCore.h | 0 .../USBDesc.h | 4 - {arduino.DuinOS => arduino.DuinOS.AVR}/Udp.h | 0 .../WCharacter.h | 0 .../WInterrupts.c | 84 +- .../WMath.cpp | 0 .../WString.cpp | 4 +- .../WString.h | 2 +- .../binary.h | 0 .../main.cpp | 20 +- .../new.cpp | 0 {arduino.DuinOS => arduino.DuinOS.AVR}/new.h | 0 .../wiring.c | 95 +- .../wiring_analog.c | 31 +- .../wiring_digital.c | 18 +- .../wiring_private.h | 4 + .../wiring_pulse.c | 0 .../wiring_shift.c | 0 arduino.DuinOS/DuinOS/portmacro.h | 129 --- arduino.DuinOS/WConstants.h | 1 - arduino.DuinOS/WProgram.h | 65 -- arduino.DuinOS/pins_arduino.c | 465 ---------- arduino.DuinOS/pins_arduino.h | 88 -- arduino.DuinOS/wiring.h | 139 --- .../MoreComplexBlinking.pde | 0 .../MoreComplexBlinkingAndSound.pde | 0 hardware/boards.txt | 20 +- 69 files changed, 3520 insertions(+), 1889 deletions(-) rename {arduino.DuinOS => arduino.DuinOS.AVR}/Arduino.h (94%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/CDC.cpp (56%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/Client.h (100%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/DuinOS.h (100%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/DuinOS/FreeRTOS.h (84%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/DuinOS/StackMacros.h (82%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/DuinOS/croutine.c (86%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/DuinOS/croutine.h (92%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/DuinOS/heap_1.c (69%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/DuinOS/heap_2.c (81%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/DuinOS/heap_3.c (67%) create mode 100644 arduino.DuinOS.AVR/DuinOS/heap_4.c rename {arduino.DuinOS => arduino.DuinOS.AVR}/DuinOS/list.c (81%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/DuinOS/list.h (79%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/DuinOS/mpu_wrappers.h (76%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/DuinOS/port.c (75%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/DuinOS/portable.h (85%) create mode 100644 arduino.DuinOS.AVR/DuinOS/portmacro.h rename {arduino.DuinOS => arduino.DuinOS.AVR}/DuinOS/projdefs.h (66%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/DuinOS/queue.c (88%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/DuinOS/queue.h (92%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/DuinOS/semphr.h (85%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/DuinOS/task.h (91%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/DuinOS/tasks.c (78%) create mode 100644 arduino.DuinOS.AVR/DuinOS/timers.c rename {arduino.DuinOS => arduino.DuinOS.AVR}/DuinOS/timers.h (94%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/FreeRTOSConfig.h (100%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/HID.cpp (79%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/HardwareSerial.cpp (79%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/HardwareSerial.h (60%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/IPAddress.cpp (100%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/IPAddress.h (100%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/Platform.h (100%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/Print.cpp (94%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/Print.h (94%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/Printable.h (100%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/Server.h (100%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/Stream.cpp (89%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/Stream.h (98%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/Tone.cpp (96%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/USBAPI.h (72%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/USBCore.cpp (95%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/USBCore.h (100%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/USBDesc.h (92%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/Udp.h (100%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/WCharacter.h (100%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/WInterrupts.c (73%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/WMath.cpp (100%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/WString.cpp (99%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/WString.h (98%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/binary.h (100%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/main.cpp (86%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/new.cpp (100%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/new.h (100%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/wiring.c (71%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/wiring_analog.c (92%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/wiring_digital.c (93%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/wiring_private.h (90%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/wiring_pulse.c (100%) rename {arduino.DuinOS => arduino.DuinOS.AVR}/wiring_shift.c (100%) delete mode 100644 arduino.DuinOS/DuinOS/portmacro.h delete mode 100644 arduino.DuinOS/WConstants.h delete mode 100644 arduino.DuinOS/WProgram.h delete mode 100644 arduino.DuinOS/pins_arduino.c delete mode 100644 arduino.DuinOS/pins_arduino.h delete mode 100644 arduino.DuinOS/wiring.h rename examples/{ => DuinOS}/MoreComplexBlinking/MoreComplexBlinking.pde (100%) rename examples/{ => DuinOS}/MoreComplexBlinkingAndSound/MoreComplexBlinkingAndSound.pde (100%) diff --git a/arduino.DuinOS/Arduino.h b/arduino.DuinOS.AVR/Arduino.h similarity index 94% rename from arduino.DuinOS/Arduino.h rename to arduino.DuinOS.AVR/Arduino.h index 692b6c0..fda08f0 100644 --- a/arduino.DuinOS/Arduino.h +++ b/arduino.DuinOS.AVR/Arduino.h @@ -20,6 +20,7 @@ extern "C"{ #define INPUT 0x0 #define OUTPUT 0x1 +#define INPUT_PULLUP 0x2 #define true 0x1 #define false 0x0 @@ -45,7 +46,7 @@ extern "C"{ #define EXTERNAL 1 #define INTERNAL 2 #else -#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) +#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644P__) #define INTERNAL1V1 2 #define INTERNAL2V56 3 #else @@ -73,8 +74,8 @@ extern "C"{ #define noInterrupts() cli() #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L ) -#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (F_CPU / 1000L) ) -#define microsecondsToClockCycles(a) ( ((a) * (F_CPU / 1000L)) / 1000L ) +#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) +#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() ) #define lowByte(w) ((uint8_t) ((w) & 0xff)) #define highByte(w) ((uint8_t) ((w) >> 8)) diff --git a/arduino.DuinOS/CDC.cpp b/arduino.DuinOS.AVR/CDC.cpp similarity index 56% rename from arduino.DuinOS/CDC.cpp rename to arduino.DuinOS.AVR/CDC.cpp index 14a0eae..701e483 100644 --- a/arduino.DuinOS/CDC.cpp +++ b/arduino.DuinOS.AVR/CDC.cpp @@ -23,12 +23,20 @@ #if defined(USBCON) #ifdef CDC_ENABLED -void Reboot() +#if (RAMEND < 1000) +#define SERIAL_BUFFER_SIZE 16 +#else +#define SERIAL_BUFFER_SIZE 64 +#endif + +struct ring_buffer { - USB.detach(); - cli(); - asm volatile("jmp 0x7800"); // jump to bootloader - DiskLoader takes up last 2 kB -} + unsigned char buffer[SERIAL_BUFFER_SIZE]; + volatile int head; + volatile int tail; +}; + +ring_buffer cdc_rx_buffer = { { 0 }, 0, 0}; typedef struct { @@ -92,9 +100,28 @@ bool WEAK CDC_Setup(Setup& setup) if (CDC_SET_CONTROL_LINE_STATE == r) { - if (0 != _usbLineInfo.lineState && 1200 == _usbLineInfo.dwDTERate) // auto-reset is triggered when the port, already open at 1200 bps, is closed - Reboot(); _usbLineInfo.lineState = setup.wValueL; + + // auto-reset into the bootloader is triggered when the port, already + // open at 1200 bps, is closed. this is the signal to start the watchdog + // with a relatively long period so it can finish housekeeping tasks + // like servicing endpoints before the sketch ends + if (1200 == _usbLineInfo.dwDTERate) { + // We check DTR state to determine if host port is open (bit 0 of lineState). + if ((_usbLineInfo.lineState & 0x01) == 0) { + *(uint16_t *)0x0800 = 0x7777; + wdt_enable(WDTO_120MS); + } else { + // Most OSs do some intermediate steps when configuring ports and DTR can + // twiggle more than once before stabilizing. + // To avoid spurious resets we set the watchdog to 250ms and eventually + // cancel if DTR goes back high. + + wdt_disable(); + wdt_reset(); + *(uint16_t *)0x0800 = 0x0; + } + } return true; } } @@ -111,33 +138,55 @@ void Serial_::end(void) { } +void Serial_::accept(void) +{ + ring_buffer *buffer = &cdc_rx_buffer; + int i = (unsigned int)(buffer->head+1) % SERIAL_BUFFER_SIZE; + + // if we should be storing the received character into the location + // just before the tail (meaning that the head would advance to the + // current location of the tail), we're about to overflow the buffer + // and so we don't write the character or advance the head. + + // while we have room to store a byte + while (i != buffer->tail) { + int c = USB_Recv(CDC_RX); + if (c == -1) + break; // no more data + buffer->buffer[buffer->head] = c; + buffer->head = i; + + i = (unsigned int)(buffer->head+1) % SERIAL_BUFFER_SIZE; + } +} + int Serial_::available(void) { - u8 avail = USB_Available(CDC_RX); - if (_serialPeek != -1) - avail++; - return avail; + ring_buffer *buffer = &cdc_rx_buffer; + return (unsigned int)(SERIAL_BUFFER_SIZE + buffer->head - buffer->tail) % SERIAL_BUFFER_SIZE; } -// peek is nasty int Serial_::peek(void) { - if (_serialPeek == -1) - _serialPeek = read(); - return _serialPeek; + ring_buffer *buffer = &cdc_rx_buffer; + if (buffer->head == buffer->tail) { + return -1; + } else { + return buffer->buffer[buffer->tail]; + } } int Serial_::read(void) { - int c; - if (_serialPeek != -1) - { - c = _serialPeek; - _serialPeek = -1; + ring_buffer *buffer = &cdc_rx_buffer; + // if the head isn't ahead of the tail, we don't have any characters + if (buffer->head == buffer->tail) { + return -1; } else { - c = USB_Recv(CDC_RX); - } - return c; + unsigned char c = buffer->buffer[buffer->tail]; + buffer->tail = (unsigned int)(buffer->tail + 1) % SERIAL_BUFFER_SIZE; + return c; + } } void Serial_::flush(void) @@ -169,7 +218,22 @@ size_t Serial_::write(uint8_t c) return 0; } +// This operator is a convenient way for a sketch to check whether the +// port has actually been configured and opened by the host (as opposed +// to just being connected to the host). It can be used, for example, in +// setup() before printing to ensure that an application on the host is +// actually ready to receive and display the data. +// We add a short delay before returning to fix a bug observed by Federico +// where the port is configured (lineState != 0) but not quite opened. +Serial_::operator bool() { + bool result = false; + if (_usbLineInfo.lineState > 0) + result = true; + delay(10); + return result; +} + Serial_ Serial; #endif -#endif /* if defined(USBCON) */ \ No newline at end of file +#endif /* if defined(USBCON) */ diff --git a/arduino.DuinOS/Client.h b/arduino.DuinOS.AVR/Client.h similarity index 100% rename from arduino.DuinOS/Client.h rename to arduino.DuinOS.AVR/Client.h diff --git a/arduino.DuinOS/DuinOS.h b/arduino.DuinOS.AVR/DuinOS.h similarity index 100% rename from arduino.DuinOS/DuinOS.h rename to arduino.DuinOS.AVR/DuinOS.h diff --git a/arduino.DuinOS/DuinOS/FreeRTOS.h b/arduino.DuinOS.AVR/DuinOS/FreeRTOS.h similarity index 84% rename from arduino.DuinOS/DuinOS/FreeRTOS.h rename to arduino.DuinOS.AVR/DuinOS/FreeRTOS.h index 9aa736a..2c0c28d 100644 --- a/arduino.DuinOS/DuinOS/FreeRTOS.h +++ b/arduino.DuinOS.AVR/DuinOS/FreeRTOS.h @@ -1,6 +1,8 @@ /* - FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd. - + FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** * * @@ -40,15 +42,28 @@ FreeRTOS WEB site. 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** - http://www.FreeRTOS.org - Documentation, latest information, license and - contact details. - - http://www.SafeRTOS.com - A version that is certified for use in safety - critical systems. - - http://www.OpenRTOS.com - Commercial support, development, porting, - licensing and training services. + + http://www.FreeRTOS.org - Documentation, training, latest versions, license + and contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool. + + Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell + the code with commercial support, indemnification, and middleware, under + the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also + provide a safety engineered and independently SIL3 certified version under + the SafeRTOS brand: http://www.SafeRTOS.com. */ #ifndef INC_FREERTOS_H @@ -66,6 +81,12 @@ /* Application specific configuration options. */ #include "FreeRTOSConfig.h" +/* configUSE_PORT_OPTIMISED_TASK_SELECTION must be defined before portable.h +is included as it is used by the port layer. */ +#ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION + #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 +#endif + /* Definitions specific to the port being used. */ #include "portable.h" @@ -136,6 +157,10 @@ typedef portBASE_TYPE (*pdTASK_HOOK_CODE)( void * ); #define INCLUDE_xTimerGetTimerDaemonTaskHandle 0 #endif +#ifndef INCLUDE_xQueueGetMutexHolder + #define INCLUDE_xQueueGetMutexHolder 0 +#endif + #ifndef INCLUDE_pcTaskGetTaskName #define INCLUDE_pcTaskGetTaskName 0 #endif @@ -148,6 +173,10 @@ typedef portBASE_TYPE (*pdTASK_HOOK_CODE)( void * ); #define INCLUDE_uxTaskGetStackHighWaterMark 0 #endif +#ifndef INCLUDE_eTaskStateGet + #define INCLUDE_eTaskStateGet 0 +#endif + #ifndef configUSE_RECURSIVE_MUTEXES #define configUSE_RECURSIVE_MUTEXES 0 #endif @@ -234,6 +263,10 @@ typedef portBASE_TYPE (*pdTASK_HOOK_CODE)( void * ); #define portCLEAN_UP_TCB( pxTCB ) ( void ) pxTCB #endif +#ifndef portSETUP_TCB + #define portSETUP_TCB( pxTCB ) ( void ) pxTCB +#endif + #ifndef configQUEUE_REGISTRY_SIZE #define configQUEUE_REGISTRY_SIZE 0U #endif @@ -311,6 +344,10 @@ typedef portBASE_TYPE (*pdTASK_HOOK_CODE)( void * ); /* The following event macros are embedded in the kernel API calls. */ +#ifndef traceMOVED_TASK_TO_READY_STATE + #define traceMOVED_TASK_TO_READY_STATE( pxTCB ) +#endif + #ifndef traceQUEUE_CREATE #define traceQUEUE_CREATE( pxNewQueue ) #endif @@ -493,5 +530,17 @@ typedef portBASE_TYPE (*pdTASK_HOOK_CODE)( void * ); #define vPortFreeAligned( pvBlockToFree ) vPortFree( pvBlockToFree ) #endif +#ifndef portSUPPRESS_TICKS_AND_SLEEP + #define portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime ) +#endif + +#ifndef configPRE_SLEEP_PROCESSING + #define configPRE_SLEEP_PROCESSING( x ) +#endif + +#ifndef configPOST_SLEEP_PROCESSING + #define configPOST_SLEEP_PROCESSING( x ) +#endif + #endif /* INC_FREERTOS_H */ diff --git a/arduino.DuinOS/DuinOS/StackMacros.h b/arduino.DuinOS.AVR/DuinOS/StackMacros.h similarity index 82% rename from arduino.DuinOS/DuinOS/StackMacros.h rename to arduino.DuinOS.AVR/DuinOS/StackMacros.h index 7fb5c24..7f2af14 100644 --- a/arduino.DuinOS/DuinOS/StackMacros.h +++ b/arduino.DuinOS.AVR/DuinOS/StackMacros.h @@ -1,6 +1,8 @@ /* - FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd. + FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** * * @@ -40,15 +42,28 @@ FreeRTOS WEB site. 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** - http://www.FreeRTOS.org - Documentation, latest information, license and - contact details. - - http://www.SafeRTOS.com - A version that is certified for use in safety - critical systems. - - http://www.OpenRTOS.com - Commercial support, development, porting, - licensing and training services. + + http://www.FreeRTOS.org - Documentation, training, latest versions, license + and contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool. + + Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell + the code with commercial support, indemnification, and middleware, under + the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also + provide a safety engineered and independently SIL3 certified version under + the SafeRTOS brand: http://www.SafeRTOS.com. */ #ifndef STACK_MACROS_H diff --git a/arduino.DuinOS/DuinOS/croutine.c b/arduino.DuinOS.AVR/DuinOS/croutine.c similarity index 86% rename from arduino.DuinOS/DuinOS/croutine.c rename to arduino.DuinOS.AVR/DuinOS/croutine.c index 168974e..d428dcc 100644 --- a/arduino.DuinOS/DuinOS/croutine.c +++ b/arduino.DuinOS.AVR/DuinOS/croutine.c @@ -1,6 +1,8 @@ /* - FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd. + FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** * * @@ -40,15 +42,28 @@ FreeRTOS WEB site. 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** - http://www.FreeRTOS.org - Documentation, latest information, license and - contact details. - - http://www.SafeRTOS.com - A version that is certified for use in safety - critical systems. - - http://www.OpenRTOS.com - Commercial support, development, porting, - licensing and training services. + + http://www.FreeRTOS.org - Documentation, training, latest versions, license + and contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool. + + Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell + the code with commercial support, indemnification, and middleware, under + the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also + provide a safety engineered and independently SIL3 certified version under + the SafeRTOS brand: http://www.SafeRTOS.com. */ #include "FreeRTOS.h" @@ -190,7 +205,7 @@ portTickType xTimeToWake; /* We must remove ourselves from the ready list before adding ourselves to the blocked list as the same list item is used for both lists. */ - vListRemove( ( xListItem * ) &( pxCurrentCoRoutine->xGenericListItem ) ); + uxListRemove( ( xListItem * ) &( pxCurrentCoRoutine->xGenericListItem ) ); /* The list item will be inserted in wake time order. */ listSET_LIST_ITEM_VALUE( &( pxCurrentCoRoutine->xGenericListItem ), xTimeToWake ); @@ -230,11 +245,11 @@ static void prvCheckPendingReadyList( void ) portDISABLE_INTERRUPTS(); { pxUnblockedCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( (&xPendingReadyCoRoutineList) ); - vListRemove( &( pxUnblockedCRCB->xEventListItem ) ); + uxListRemove( &( pxUnblockedCRCB->xEventListItem ) ); } portENABLE_INTERRUPTS(); - vListRemove( &( pxUnblockedCRCB->xGenericListItem ) ); + uxListRemove( &( pxUnblockedCRCB->xGenericListItem ) ); prvAddCoRoutineToReadyQueue( pxUnblockedCRCB ); } } @@ -280,12 +295,12 @@ corCRCB *pxCRCB; have been moved to the pending ready list and the following line is still valid. Also the pvContainer parameter will have been set to NULL so the following lines are also valid. */ - vListRemove( &( pxCRCB->xGenericListItem ) ); + uxListRemove( &( pxCRCB->xGenericListItem ) ); /* Is the co-routine waiting on an event also? */ if( pxCRCB->xEventListItem.pvContainer ) { - vListRemove( &( pxCRCB->xEventListItem ) ); + uxListRemove( &( pxCRCB->xEventListItem ) ); } } portENABLE_INTERRUPTS(); @@ -357,7 +372,7 @@ signed portBASE_TYPE xReturn; event lists and the pending ready list. This function assumes that a check has already been made to ensure pxEventList is not empty. */ pxUnblockedCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList ); - vListRemove( &( pxUnblockedCRCB->xEventListItem ) ); + uxListRemove( &( pxUnblockedCRCB->xEventListItem ) ); vListInsertEnd( ( xList * ) &( xPendingReadyCoRoutineList ), &( pxUnblockedCRCB->xEventListItem ) ); if( pxUnblockedCRCB->uxPriority >= pxCurrentCoRoutine->uxPriority ) diff --git a/arduino.DuinOS/DuinOS/croutine.h b/arduino.DuinOS.AVR/DuinOS/croutine.h similarity index 92% rename from arduino.DuinOS/DuinOS/croutine.h rename to arduino.DuinOS.AVR/DuinOS/croutine.h index d2339ee..f4f1931 100644 --- a/arduino.DuinOS/DuinOS/croutine.h +++ b/arduino.DuinOS.AVR/DuinOS/croutine.h @@ -1,6 +1,8 @@ /* - FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd. + FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** * * @@ -40,15 +42,28 @@ FreeRTOS WEB site. 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** - http://www.FreeRTOS.org - Documentation, latest information, license and - contact details. - - http://www.SafeRTOS.com - A version that is certified for use in safety - critical systems. - - http://www.OpenRTOS.com - Commercial support, development, porting, - licensing and training services. + + http://www.FreeRTOS.org - Documentation, training, latest versions, license + and contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool. + + Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell + the code with commercial support, indemnification, and middleware, under + the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also + provide a safety engineered and independently SIL3 certified version under + the SafeRTOS brand: http://www.SafeRTOS.com. */ #ifndef CO_ROUTINE_H diff --git a/arduino.DuinOS/DuinOS/heap_1.c b/arduino.DuinOS.AVR/DuinOS/heap_1.c similarity index 69% rename from arduino.DuinOS/DuinOS/heap_1.c rename to arduino.DuinOS.AVR/DuinOS/heap_1.c index 7359340..65e2cd7 100644 --- a/arduino.DuinOS/DuinOS/heap_1.c +++ b/arduino.DuinOS.AVR/DuinOS/heap_1.c @@ -1,6 +1,8 @@ /* - FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd. - + FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** * * @@ -40,15 +42,28 @@ FreeRTOS WEB site. 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** - http://www.FreeRTOS.org - Documentation, latest information, license and - contact details. - - http://www.SafeRTOS.com - A version that is certified for use in safety - critical systems. - - http://www.OpenRTOS.com - Commercial support, development, porting, - licensing and training services. + + http://www.FreeRTOS.org - Documentation, training, latest versions, license + and contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool. + + Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell + the code with commercial support, indemnification, and middleware, under + the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also + provide a safety engineered and independently SIL3 certified version under + the SafeRTOS brand: http://www.SafeRTOS.com. */ @@ -56,8 +71,8 @@ * The simplest possible implementation of pvPortMalloc(). Note that this * implementation does NOT allow allocated memory to be freed again. * - * See heap_2.c and heap_3.c for alternative implementations, and the memory - * management pages of http://www.FreeRTOS.org for more information. + * See heap_2.c, heap_3.c and heap_4.c for alternative implementations, and the + * memory management pages of http://www.FreeRTOS.org for more information. */ #include @@ -79,7 +94,7 @@ static union xRTOS_HEAP volatile portDOUBLE dDummy; #else volatile unsigned long ulDummy; - #endif + #endif unsigned char ucHeap[ configTOTAL_HEAP_SIZE ]; } xHeap; @@ -88,7 +103,7 @@ static size_t xNextFreeByte = ( size_t ) 0; void *pvPortMalloc( size_t xWantedSize ) { -void *pvReturn = NULL; +void *pvReturn = NULL; /* Ensure that blocks are always aligned to the required number of bytes. */ #if portBYTE_ALIGNMENT != 1 @@ -108,11 +123,11 @@ void *pvReturn = NULL; /* Return the next free byte then increment the index past this block. */ pvReturn = &( xHeap.ucHeap[ xNextFreeByte ] ); - xNextFreeByte += xWantedSize; - } + xNextFreeByte += xWantedSize; + } } xTaskResumeAll(); - + #if( configUSE_MALLOC_FAILED_HOOK == 1 ) { if( pvReturn == NULL ) @@ -121,7 +136,7 @@ void *pvReturn = NULL; vApplicationMallocFailedHook(); } } - #endif + #endif return pvReturn; } @@ -129,10 +144,13 @@ void *pvReturn = NULL; void vPortFree( void *pv ) { - /* Memory cannot be freed using this scheme. See heap_2.c and heap_3.c - for alternative implementations, and the memory management pages of + /* Memory cannot be freed using this scheme. See heap_2.c, heap_3.c and + heap_4.c for alternative implementations, and the memory management pages of http://www.FreeRTOS.org for more information. */ ( void ) pv; + + /* Force an assert as it is invalid to call this function. */ + configASSERT( pv == NULL ); } /*-----------------------------------------------------------*/ diff --git a/arduino.DuinOS/DuinOS/heap_2.c b/arduino.DuinOS.AVR/DuinOS/heap_2.c similarity index 81% rename from arduino.DuinOS/DuinOS/heap_2.c rename to arduino.DuinOS.AVR/DuinOS/heap_2.c index 0f4e6a3..bd827a9 100644 --- a/arduino.DuinOS/DuinOS/heap_2.c +++ b/arduino.DuinOS.AVR/DuinOS/heap_2.c @@ -1,6 +1,8 @@ /* - FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd. - + FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** * * @@ -40,24 +42,38 @@ FreeRTOS WEB site. 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** - http://www.FreeRTOS.org - Documentation, latest information, license and - contact details. - - http://www.SafeRTOS.com - A version that is certified for use in safety - critical systems. - - http://www.OpenRTOS.com - Commercial support, development, porting, - licensing and training services. + + http://www.FreeRTOS.org - Documentation, training, latest versions, license + and contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool. + + Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell + the code with commercial support, indemnification, and middleware, under + the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also + provide a safety engineered and independently SIL3 certified version under + the SafeRTOS brand: http://www.SafeRTOS.com. */ /* * A sample implementation of pvPortMalloc() and vPortFree() that permits * allocated blocks to be freed, but does not combine adjacent free blocks - * into a single larger block. + * into a single larger block (and so will fragment memory). See heap_4.c for + * an aquivalent that does combine adjacent blocks into single larger blocks. * - * See heap_1.c and heap_3.c for alternative implementations, and the memory - * management pages of http://www.FreeRTOS.org for more information. + * See heap_1.c, heap_3.c and heap_4.c for alternative implementations, and the + * memory management pages of http://www.FreeRTOS.org for more information. */ #include @@ -187,7 +203,7 @@ void *pvReturn = NULL; (smallest) block until one of adequate size is found. */ pxPreviousBlock = &xStart; pxBlock = xStart.pxNextFreeBlock; - while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock ) ) + while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock != NULL ) ) { pxPreviousBlock = pxBlock; pxBlock = pxBlock->pxNextFreeBlock; @@ -200,7 +216,7 @@ void *pvReturn = NULL; at its start. */ pvReturn = ( void * ) ( ( ( unsigned char * ) pxPreviousBlock->pxNextFreeBlock ) + heapSTRUCT_SIZE ); - /* This block is being returned for use so must be taken our of the + /* This block is being returned for use so must be taken out of the list of free blocks. */ pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock; @@ -246,7 +262,7 @@ void vPortFree( void *pv ) unsigned char *puc = ( unsigned char * ) pv; xBlockLink *pxLink; - if( pv ) + if( pv != NULL ) { /* The memory being freed will have an xBlockLink structure immediately before it. */ diff --git a/arduino.DuinOS/DuinOS/heap_3.c b/arduino.DuinOS.AVR/DuinOS/heap_3.c similarity index 67% rename from arduino.DuinOS/DuinOS/heap_3.c rename to arduino.DuinOS.AVR/DuinOS/heap_3.c index e1f0719..074835e 100644 --- a/arduino.DuinOS/DuinOS/heap_3.c +++ b/arduino.DuinOS.AVR/DuinOS/heap_3.c @@ -1,6 +1,8 @@ /* - FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd. - + FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** * * @@ -40,15 +42,28 @@ FreeRTOS WEB site. 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** - http://www.FreeRTOS.org - Documentation, latest information, license and - contact details. - - http://www.SafeRTOS.com - A version that is certified for use in safety - critical systems. - - http://www.OpenRTOS.com - Commercial support, development, porting, - licensing and training services. + + http://www.FreeRTOS.org - Documentation, training, latest versions, license + and contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool. + + Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell + the code with commercial support, indemnification, and middleware, under + the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also + provide a safety engineered and independently SIL3 certified version under + the SafeRTOS brand: http://www.SafeRTOS.com. */ @@ -59,8 +74,8 @@ * This file can only be used if the linker is configured to to generate * a heap memory area. * - * See heap_2.c and heap_1.c for alternative implementations, and the memory - * management pages of http://www.FreeRTOS.org for more information. + * See heap_1.c, heap_2.c and heap_4.c for alternative implementations, and the + * memory management pages of http://www.FreeRTOS.org for more information. */ #include diff --git a/arduino.DuinOS.AVR/DuinOS/heap_4.c b/arduino.DuinOS.AVR/DuinOS/heap_4.c new file mode 100644 index 0000000..d40fea1 --- /dev/null +++ b/arduino.DuinOS.AVR/DuinOS/heap_4.c @@ -0,0 +1,359 @@ +/* + FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. + + *************************************************************************** + * * + * FreeRTOS tutorial books are available in pdf and paperback. * + * Complete, revised, and edited pdf reference manuals are also * + * available. * + * * + * Purchasing FreeRTOS documentation will not only help you, by * + * ensuring you get running as quickly as possible and with an * + * in-depth knowledge of how to use FreeRTOS, it will also help * + * the FreeRTOS project to continue with its mission of providing * + * professional grade, cross platform, de facto standard solutions * + * for microcontrollers - completely free of charge! * + * * + * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * + * * + * Thank you for using FreeRTOS, and thank you for your support! * + * * + *************************************************************************** + + + This file is part of the FreeRTOS distribution. + + FreeRTOS is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License (version 2) as published by the + Free Software Foundation AND MODIFIED BY the FreeRTOS exception. + >>>NOTE<<< The modification to the GPL is included to allow you to + distribute a combined work that includes FreeRTOS without being obliged to + provide the source code for proprietary components outside of the FreeRTOS + kernel. FreeRTOS is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. You should have received a copy of the GNU General Public + License and the FreeRTOS license exception along with FreeRTOS; if not it + can be viewed here: http://www.freertos.org/a00114.html and also obtained + by writing to Richard Barry, contact details for whom are available on the + FreeRTOS WEB site. + + 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** + + + http://www.FreeRTOS.org - Documentation, training, latest versions, license + and contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool. + + Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell + the code with commercial support, indemnification, and middleware, under + the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also + provide a safety engineered and independently SIL3 certified version under + the SafeRTOS brand: http://www.SafeRTOS.com. +*/ + +/* + * A sample implementation of pvPortMalloc() and vPortFree() that combines + * (coalescences) adjacent memory blocks as they are freed, and in so doing + * limits memory fragmentation. + * + * See heap_1.c, heap_2.c and heap_3.c for alternative implementations, and the + * memory management pages of http://www.FreeRTOS.org for more information. + */ +#include + +/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining +all the API functions to use the MPU wrappers. That should only be done when +task.h is included from an application file. */ +#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +#include "FreeRTOS.h" +#include "task.h" + +#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +/* Block sizes must not get too small. */ +#define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( heapSTRUCT_SIZE * 2 ) ) + +/* Allocate the memory for the heap. The struct is used to force byte +alignment without using any non-portable code. */ +static union xRTOS_HEAP +{ + #if portBYTE_ALIGNMENT == 8 + volatile portDOUBLE dDummy; + #else + volatile unsigned long ulDummy; + #endif + unsigned char ucHeap[ configTOTAL_HEAP_SIZE ]; +} xHeap; + +/* Define the linked list structure. This is used to link free blocks in order +of their memory address. */ +typedef struct A_BLOCK_LINK +{ + struct A_BLOCK_LINK *pxNextFreeBlock; /*<< The next free block in the list. */ + size_t xBlockSize; /*<< The size of the free block. */ +} xBlockLink; + +/*-----------------------------------------------------------*/ + +/* + * Inserts a block of memory that is being freed into the correct position in + * the list of free memory blocks. The block being freed will be merged with + * the block in front it and/or the block behind it if the memory blocks are + * adjacent to each other. + */ +static void prvInsertBlockIntoFreeList( xBlockLink *pxBlockToInsert ); + +/* + * Called automatically to setup the required heap structures the first time + * pvPortMalloc() is called. + */ +static void prvHeapInit( void ); + +/*-----------------------------------------------------------*/ + +/* The size of the structure placed at the beginning of each allocated memory +block must by correctly byte aligned. */ +static const unsigned short heapSTRUCT_SIZE = ( sizeof( xBlockLink ) + portBYTE_ALIGNMENT - ( sizeof( xBlockLink ) % portBYTE_ALIGNMENT ) ); + +/* Ensure the pxEnd pointer will end up on the correct byte alignment. */ +static const size_t xTotalHeapSize = ( ( size_t ) configTOTAL_HEAP_SIZE ) & ( ( size_t ) ~portBYTE_ALIGNMENT_MASK ); + +/* Create a couple of list links to mark the start and end of the list. */ +static xBlockLink xStart, *pxEnd = NULL; + +/* Keeps track of the number of free bytes remaining, but says nothing about +fragmentation. */ +static size_t xFreeBytesRemaining = ( ( size_t ) configTOTAL_HEAP_SIZE ) & ( ( size_t ) ~portBYTE_ALIGNMENT_MASK ); + +/* STATIC FUNCTIONS ARE DEFINED AS MACROS TO MINIMIZE THE FUNCTION CALL DEPTH. */ + +/*-----------------------------------------------------------*/ + +void *pvPortMalloc( size_t xWantedSize ) +{ +xBlockLink *pxBlock, *pxPreviousBlock, *pxNewBlockLink; +void *pvReturn = NULL; + + vTaskSuspendAll(); + { + /* If this is the first call to malloc then the heap will require + initialisation to setup the list of free blocks. */ + if( pxEnd == NULL ) + { + prvHeapInit(); + } + + /* The wanted size is increased so it can contain a xBlockLink + structure in addition to the requested amount of bytes. */ + if( xWantedSize > 0 ) + { + xWantedSize += heapSTRUCT_SIZE; + + /* Ensure that blocks are always aligned to the required number of + bytes. */ + if( xWantedSize & portBYTE_ALIGNMENT_MASK ) + { + /* Byte alignment required. */ + xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ); + } + } + + if( ( xWantedSize > 0 ) && ( xWantedSize < xTotalHeapSize ) ) + { + /* Traverse the list from the start (lowest address) block until one + of adequate size is found. */ + pxPreviousBlock = &xStart; + pxBlock = xStart.pxNextFreeBlock; + while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock != NULL ) ) + { + pxPreviousBlock = pxBlock; + pxBlock = pxBlock->pxNextFreeBlock; + } + + /* If the end marker was reached then a block of adequate size was + not found. */ + if( pxBlock != pxEnd ) + { + /* Return the memory space - jumping over the xBlockLink structure + at its start. */ + pvReturn = ( void * ) ( ( ( unsigned char * ) pxPreviousBlock->pxNextFreeBlock ) + heapSTRUCT_SIZE ); + + /* This block is being returned for use so must be taken out of + the list of free blocks. */ + pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock; + + /* If the block is larger than required it can be split into two. */ + if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE ) + { + /* This block is to be split into two. Create a new block + following the number of bytes requested. The void cast is + used to prevent byte alignment warnings from the compiler. */ + pxNewBlockLink = ( void * ) ( ( ( unsigned char * ) pxBlock ) + xWantedSize ); + + /* Calculate the sizes of two blocks split from the single + block. */ + pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize; + pxBlock->xBlockSize = xWantedSize; + + /* Insert the new block into the list of free blocks. */ + prvInsertBlockIntoFreeList( ( pxNewBlockLink ) ); + } + + xFreeBytesRemaining -= pxBlock->xBlockSize; + } + } + } + xTaskResumeAll(); + + #if( configUSE_MALLOC_FAILED_HOOK == 1 ) + { + if( pvReturn == NULL ) + { + extern void vApplicationMallocFailedHook( void ); + vApplicationMallocFailedHook(); + } + } + #endif + + return pvReturn; +} +/*-----------------------------------------------------------*/ + +void vPortFree( void *pv ) +{ +unsigned char *puc = ( unsigned char * ) pv; +xBlockLink *pxLink; + + if( pv != NULL ) + { + /* The memory being freed will have an xBlockLink structure immediately + before it. */ + puc -= heapSTRUCT_SIZE; + + /* This casting is to keep the compiler from issuing warnings. */ + pxLink = ( void * ) puc; + + vTaskSuspendAll(); + { + /* Add this block to the list of free blocks. */ + xFreeBytesRemaining += pxLink->xBlockSize; + prvInsertBlockIntoFreeList( ( ( xBlockLink * ) pxLink ) ); + } + xTaskResumeAll(); + } +} +/*-----------------------------------------------------------*/ + +size_t xPortGetFreeHeapSize( void ) +{ + return xFreeBytesRemaining; +} +/*-----------------------------------------------------------*/ + +void vPortInitialiseBlocks( void ) +{ + /* This just exists to keep the linker quiet. */ +} +/*-----------------------------------------------------------*/ + +static void prvHeapInit( void ) +{ +xBlockLink *pxFirstFreeBlock; +unsigned char *pucHeapEnd; + + /* Ensure the start of the heap is aligned. */ + configASSERT( ( ( ( unsigned long ) xHeap.ucHeap ) & ( ( unsigned long ) portBYTE_ALIGNMENT_MASK ) ) == 0UL ); + + /* xStart is used to hold a pointer to the first item in the list of free + blocks. The void cast is used to prevent compiler warnings. */ + xStart.pxNextFreeBlock = ( void * ) xHeap.ucHeap; + xStart.xBlockSize = ( size_t ) 0; + + /* pxEnd is used to mark the end of the list of free blocks and is inserted + at the end of the heap space. */ + pucHeapEnd = xHeap.ucHeap + xTotalHeapSize; + pucHeapEnd -= heapSTRUCT_SIZE; + pxEnd = ( void * ) pucHeapEnd; + configASSERT( ( ( ( unsigned long ) pxEnd ) & ( ( unsigned long ) portBYTE_ALIGNMENT_MASK ) ) == 0UL ); + pxEnd->xBlockSize = 0; + pxEnd->pxNextFreeBlock = NULL; + + /* To start with there is a single free block that is sized to take up the + entire heap space, minus the space taken by pxEnd. */ + pxFirstFreeBlock = ( void * ) xHeap.ucHeap; + pxFirstFreeBlock->xBlockSize = xTotalHeapSize - heapSTRUCT_SIZE; + pxFirstFreeBlock->pxNextFreeBlock = pxEnd; + + /* The heap now contains pxEnd. */ + xFreeBytesRemaining -= heapSTRUCT_SIZE; +} +/*-----------------------------------------------------------*/ + +static void prvInsertBlockIntoFreeList( xBlockLink *pxBlockToInsert ) +{ +xBlockLink *pxIterator; +unsigned char *puc; + + /* Iterate through the list until a block is found that has a higher address + than the block being inserted. */ + for( pxIterator = &xStart; pxIterator->pxNextFreeBlock < pxBlockToInsert; pxIterator = pxIterator->pxNextFreeBlock ) + { + /* Nothing to do here, just iterate to the right position. */ + } + + /* Do the block being inserted, and the block it is being inserted after + make a contiguous block of memory? */ + puc = ( unsigned char * ) pxIterator; + if( ( puc + pxIterator->xBlockSize ) == ( unsigned char * ) pxBlockToInsert ) + { + pxIterator->xBlockSize += pxBlockToInsert->xBlockSize; + pxBlockToInsert = pxIterator; + } + + /* Do the block being inserted, and the block it is being inserted before + make a contiguous block of memory? */ + puc = ( unsigned char * ) pxBlockToInsert; + if( ( puc + pxBlockToInsert->xBlockSize ) == ( unsigned char * ) pxIterator->pxNextFreeBlock ) + { + if( pxIterator->pxNextFreeBlock != pxEnd ) + { + /* Form one big block from the two blocks. */ + pxBlockToInsert->xBlockSize += pxIterator->pxNextFreeBlock->xBlockSize; + pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock->pxNextFreeBlock; + } + else + { + pxBlockToInsert->pxNextFreeBlock = pxEnd; + } + } + else + { + pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock; + } + + /* If the block being inserted plugged a gab, so was merged with the block + before and the block after, then it's pxNextFreeBlock pointer will have + already been set, and should not be set here as that would make it point + to itself. */ + if( pxIterator != pxBlockToInsert ) + { + pxIterator->pxNextFreeBlock = pxBlockToInsert; + } +} + diff --git a/arduino.DuinOS/DuinOS/list.c b/arduino.DuinOS.AVR/DuinOS/list.c similarity index 81% rename from arduino.DuinOS/DuinOS/list.c rename to arduino.DuinOS.AVR/DuinOS/list.c index 923ec5c..f3749f0 100644 --- a/arduino.DuinOS/DuinOS/list.c +++ b/arduino.DuinOS.AVR/DuinOS/list.c @@ -1,6 +1,8 @@ /* - FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd. + FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** * * @@ -40,15 +42,28 @@ FreeRTOS WEB site. 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** - http://www.FreeRTOS.org - Documentation, latest information, license and - contact details. - - http://www.SafeRTOS.com - A version that is certified for use in safety - critical systems. - - http://www.OpenRTOS.com - Commercial support, development, porting, - licensing and training services. + + http://www.FreeRTOS.org - Documentation, training, latest versions, license + and contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool. + + Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell + the code with commercial support, indemnification, and middleware, under + the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also + provide a safety engineered and independently SIL3 certified version under + the SafeRTOS brand: http://www.SafeRTOS.com. */ @@ -146,7 +161,7 @@ portTickType xValueOfInsertion; before vTaskStartScheduler() has been called?). See http://www.freertos.org/FAQHelp.html for more tips. **********************************************************************/ - + for( pxIterator = ( xListItem * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) { /* There is nothing to do here, we are just iterating to the @@ -167,13 +182,13 @@ portTickType xValueOfInsertion; } /*-----------------------------------------------------------*/ -void vListRemove( xListItem *pxItemToRemove ) +unsigned portBASE_TYPE uxListRemove( xListItem *pxItemToRemove ) { xList * pxList; pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious; pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext; - + /* The list item knows which list it is in. Obtain the list from the list item. */ pxList = ( xList * ) pxItemToRemove->pvContainer; @@ -186,6 +201,8 @@ xList * pxList; pxItemToRemove->pvContainer = NULL; ( pxList->uxNumberOfItems )--; + + return pxList->uxNumberOfItems; } /*-----------------------------------------------------------*/ diff --git a/arduino.DuinOS/DuinOS/list.h b/arduino.DuinOS.AVR/DuinOS/list.h similarity index 79% rename from arduino.DuinOS/DuinOS/list.h rename to arduino.DuinOS.AVR/DuinOS/list.h index ead6707..efaff25 100644 --- a/arduino.DuinOS/DuinOS/list.h +++ b/arduino.DuinOS.AVR/DuinOS/list.h @@ -1,6 +1,8 @@ /* - FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd. + FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** * * @@ -40,15 +42,28 @@ FreeRTOS WEB site. 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** - http://www.FreeRTOS.org - Documentation, latest information, license and - contact details. - - http://www.SafeRTOS.com - A version that is certified for use in safety - critical systems. - - http://www.OpenRTOS.com - Commercial support, development, porting, - licensing and training services. + + http://www.FreeRTOS.org - Documentation, training, latest versions, license + and contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool. + + Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell + the code with commercial support, indemnification, and middleware, under + the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also + provide a safety engineered and independently SIL3 certified version under + the SafeRTOS brand: http://www.SafeRTOS.com. */ /* @@ -126,6 +141,15 @@ typedef struct xLIST */ #define listSET_LIST_ITEM_OWNER( pxListItem, pxOwner ) ( pxListItem )->pvOwner = ( void * ) ( pxOwner ) +/* + * Access macro to get the owner of a list item. The owner of a list item + * is the object (usually a TCB) that contains the list item. + * + * \page listSET_LIST_ITEM_OWNER listSET_LIST_ITEM_OWNER + * \ingroup LinkedList + */ +#define listGET_LIST_ITEM_OWNER( pxListItem ) ( pxListItem )->pvOwner + /* * Access macro to set the value of the list item. In most cases the value is * used to sort the list in descending order. @@ -136,7 +160,7 @@ typedef struct xLIST #define listSET_LIST_ITEM_VALUE( pxListItem, xValue ) ( pxListItem )->xItemValue = ( xValue ) /* - * Access macro the retrieve the value of the list item. The value can + * Access macro to retrieve the value of the list item. The value can * represent anything - for example a the priority of a task, or the time at * which a task should be unblocked. * @@ -231,6 +255,21 @@ xList * const pxConstList = ( pxList ); \ */ #define listIS_CONTAINED_WITHIN( pxList, pxListItem ) ( ( pxListItem )->pvContainer == ( void * ) ( pxList ) ) +/* + * Return the list a list item is contained within (referenced from). + * + * @param pxListItem The list item being queried. + * @return A pointer to the xList object that references the pxListItem + */ +#define listLIST_ITEM_CONTAINER( pxListItem ) ( ( pxListItem )->pvContainer ) + +/* + * This provides a crude means of knowing if a list has been initialised, as + * pxList->xListEnd.xItemValue is set to portMAX_DELAY by the vListInitialise() + * function. + */ +#define listLIST_IS_INITIALISED( pxList ) ( ( pxList )->xListEnd.xItemValue == portMAX_DELAY ) + /* * Must be called before a list is used! This initialises all the members * of the list structure and inserts the xListEnd item into the list as a @@ -292,13 +331,16 @@ void vListInsertEnd( xList *pxList, xListItem *pxNewListItem ); * Remove an item from a list. The list item has a pointer to the list that * it is in, so only the list item need be passed into the function. * - * @param vListRemove The item to be removed. The item will remove itself from + * @param uxListRemove The item to be removed. The item will remove itself from * the list pointed to by it's pxContainer parameter. + * + * @return The number of items that remain in the list after the list item has + * been removed. * - * \page vListRemove vListRemove + * \page uxListRemove uxListRemove * \ingroup LinkedList */ -void vListRemove( xListItem *pxItemToRemove ); +unsigned portBASE_TYPE uxListRemove( xListItem *pxItemToRemove ); #ifdef __cplusplus } diff --git a/arduino.DuinOS/DuinOS/mpu_wrappers.h b/arduino.DuinOS.AVR/DuinOS/mpu_wrappers.h similarity index 76% rename from arduino.DuinOS/DuinOS/mpu_wrappers.h rename to arduino.DuinOS.AVR/DuinOS/mpu_wrappers.h index 767a3e6..299e8d0 100644 --- a/arduino.DuinOS/DuinOS/mpu_wrappers.h +++ b/arduino.DuinOS.AVR/DuinOS/mpu_wrappers.h @@ -1,6 +1,8 @@ /* - FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd. + FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** * * @@ -40,15 +42,28 @@ FreeRTOS WEB site. 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** - http://www.FreeRTOS.org - Documentation, latest information, license and - contact details. - - http://www.SafeRTOS.com - A version that is certified for use in safety - critical systems. - - http://www.OpenRTOS.com - Commercial support, development, porting, - licensing and training services. + + http://www.FreeRTOS.org - Documentation, training, latest versions, license + and contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool. + + Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell + the code with commercial support, indemnification, and middleware, under + the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also + provide a safety engineered and independently SIL3 certified version under + the SafeRTOS brand: http://www.SafeRTOS.com. */ #ifndef MPU_WRAPPERS_H @@ -70,6 +85,7 @@ only for ports that are using the MPU. */ #define vTaskDelay MPU_vTaskDelay #define uxTaskPriorityGet MPU_uxTaskPriorityGet #define vTaskPrioritySet MPU_vTaskPrioritySet + #define eTaskStateGet MPU_eTaskStateGet #define vTaskSuspend MPU_vTaskSuspend #define xTaskIsTaskSuspended MPU_xTaskIsTaskSuspended #define vTaskResume MPU_vTaskResume @@ -79,8 +95,6 @@ only for ports that are using the MPU. */ #define uxTaskGetNumberOfTasks MPU_uxTaskGetNumberOfTasks #define vTaskList MPU_vTaskList #define vTaskGetRunTimeStats MPU_vTaskGetRunTimeStats - #define vTaskStartTrace MPU_vTaskStartTrace - #define ulTaskEndTrace MPU_ulTaskEndTrace #define vTaskSetApplicationTaskTag MPU_vTaskSetApplicationTaskTag #define xTaskGetApplicationTaskTag MPU_xTaskGetApplicationTaskTag #define xTaskCallApplicationTaskHook MPU_xTaskCallApplicationTaskHook @@ -88,7 +102,7 @@ only for ports that are using the MPU. */ #define xTaskGetCurrentTaskHandle MPU_xTaskGetCurrentTaskHandle #define xTaskGetSchedulerState MPU_xTaskGetSchedulerState - #define xQueueCreate MPU_xQueueCreate + #define xQueueGenericCreate MPU_xQueueGenericCreate #define xQueueCreateMutex MPU_xQueueCreateMutex #define xQueueGiveMutexRecursive MPU_xQueueGiveMutexRecursive #define xQueueTakeMutexRecursive MPU_xQueueTakeMutexRecursive diff --git a/arduino.DuinOS/DuinOS/port.c b/arduino.DuinOS.AVR/DuinOS/port.c similarity index 75% rename from arduino.DuinOS/DuinOS/port.c rename to arduino.DuinOS.AVR/DuinOS/port.c index a2b2c55..4afbbb0 100644 --- a/arduino.DuinOS/DuinOS/port.c +++ b/arduino.DuinOS.AVR/DuinOS/port.c @@ -1,390 +1,406 @@ -/* - FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd. - - *************************************************************************** - * * - * If you are: * - * * - * + New to FreeRTOS, * - * + Wanting to learn FreeRTOS or multitasking in general quickly * - * + Looking for basic training, * - * + Wanting to improve your FreeRTOS skills and productivity * - * * - * then take a look at the FreeRTOS books - available as PDF or paperback * - * * - * "Using the FreeRTOS Real Time Kernel - a Practical Guide" * - * http://www.FreeRTOS.org/Documentation * - * * - * A pdf reference manual is also available. Both are usually delivered * - * to your inbox within 20 minutes to two hours when purchased between 8am * - * and 8pm GMT (although please allow up to 24 hours in case of * - * exceptional circumstances). Thank you for your support! * - * * - *************************************************************************** - - This file is part of the FreeRTOS distribution. - - FreeRTOS is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License (version 2) as published by the - Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - ***NOTE*** The exception to the GPL is included to allow you to distribute - a combined work that includes FreeRTOS without being obliged to provide the - source code for proprietary components outside of the FreeRTOS kernel. - FreeRTOS is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. You should have received a copy of the GNU General Public - License and the FreeRTOS license exception along with FreeRTOS; if not it - can be viewed here: http://www.freertos.org/a00114.html and also obtained - by writing to Richard Barry, contact details for whom are available on the - FreeRTOS WEB site. - - 1 tab == 4 spaces! - - http://www.FreeRTOS.org - Documentation, latest information, license and - contact details. - - http://www.SafeRTOS.com - A version that is certified for use in safety - critical systems. - - http://www.OpenRTOS.com - Commercial support, development, porting, - licensing and training services. -*/ - -/* - -Changes from V2.6.0 - - + AVR port - Replaced the inb() and outb() functions with direct memory - access. This allows the port to be built with the 20050414 build of - WinAVR. -*/ - -#include -#include - -#include "FreeRTOS.h" -#include "task.h" +/* + FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. + + *************************************************************************** + * * + * FreeRTOS tutorial books are available in pdf and paperback. * + * Complete, revised, and edited pdf reference manuals are also * + * available. * + * * + * Purchasing FreeRTOS documentation will not only help you, by * + * ensuring you get running as quickly as possible and with an * + * in-depth knowledge of how to use FreeRTOS, it will also help * + * the FreeRTOS project to continue with its mission of providing * + * professional grade, cross platform, de facto standard solutions * + * for microcontrollers - completely free of charge! * + * * + * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * + * * + * Thank you for using FreeRTOS, and thank you for your support! * + * * + *************************************************************************** + + + This file is part of the FreeRTOS distribution. + + FreeRTOS is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License (version 2) as published by the + Free Software Foundation AND MODIFIED BY the FreeRTOS exception. + >>>NOTE<<< The modification to the GPL is included to allow you to + distribute a combined work that includes FreeRTOS without being obliged to + provide the source code for proprietary components outside of the FreeRTOS + kernel. FreeRTOS is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. You should have received a copy of the GNU General Public + License and the FreeRTOS license exception along with FreeRTOS; if not it + can be viewed here: http://www.freertos.org/a00114.html and also obtained + by writing to Richard Barry, contact details for whom are available on the + FreeRTOS WEB site. + + 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** + + + http://www.FreeRTOS.org - Documentation, training, latest versions, license + and contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool. + + Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell + the code with commercial support, indemnification, and middleware, under + the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also + provide a safety engineered and independently SIL3 certified version under + the SafeRTOS brand: http://www.SafeRTOS.com. +*/ + +/* + +Changes from V2.6.0 + + + AVR port - Replaced the inb() and outb() functions with direct memory + access. This allows the port to be built with the 20050414 build of + WinAVR. +*/ + +#include +#include + +#include "FreeRTOS.h" +#include "task.h" #include "wiring_private.h" - -/*----------------------------------------------------------- - * Implementation of functions defined in portable.h for the AVR port. - *----------------------------------------------------------*/ - -/* Start tasks with interrupts enables. */ -#define portFLAGS_INT_ENABLED ( ( portSTACK_TYPE ) 0x80 ) - -/* Hardware constants for timer 1. */ -/* Enable hardware constants for Atmel AVR ATmega644, ATmega644P, ATmega1284P, AVR_ATmega1280, AVR_ATmega328P, ATmega88, ATmega88P, ATmega168, ATmega168P */ -#define portCLEAR_COUNTER_ON_MATCH ( (unsigned portCHAR)(1 << WGM12) ) /* remove portCLEAR_COUNTER_ON_MATCH because it is not used in timer ? */ -#define portCLOCK_PRESCALER ( (unsigned portLONG) 64 ) - -/*-----------------------------------------------------------*/ - -/* We require the address of the pxCurrentTCB variable, but don't want to know -any details of its type. */ -typedef void tskTCB; -extern volatile tskTCB * volatile pxCurrentTCB; - -/*-----------------------------------------------------------*/ - -/* - * Macro to save all the general purpose registers, the save the stack pointer - * into the TCB. - * - * The first thing we do is save the flags then disable interrupts. This is to - * guard our stack against having a context switch interrupt after we have already - * pushed the registers onto the stack - causing the 32 registers to be on the - * stack twice. - * - * r1 is set to zero as the compiler expects it to be thus, however some - * of the math routines make use of R1. - * - * The interrupts will have been disabled during the call to portSAVE_CONTEXT() - * so we need not worry about reading/writing to the stack pointer. - */ - -#define portSAVE_CONTEXT() \ - asm volatile ( "push r0 \n\t" \ - "in r0, __SREG__ \n\t" \ - "cli \n\t" \ - "push r0 \n\t" \ - "push r1 \n\t" \ - "clr r1 \n\t" \ - "push r2 \n\t" \ - "push r3 \n\t" \ - "push r4 \n\t" \ - "push r5 \n\t" \ - "push r6 \n\t" \ - "push r7 \n\t" \ - "push r8 \n\t" \ - "push r9 \n\t" \ - "push r10 \n\t" \ - "push r11 \n\t" \ - "push r12 \n\t" \ - "push r13 \n\t" \ - "push r14 \n\t" \ - "push r15 \n\t" \ - "push r16 \n\t" \ - "push r17 \n\t" \ - "push r18 \n\t" \ - "push r19 \n\t" \ - "push r20 \n\t" \ - "push r21 \n\t" \ - "push r22 \n\t" \ - "push r23 \n\t" \ - "push r24 \n\t" \ - "push r25 \n\t" \ - "push r26 \n\t" \ - "push r27 \n\t" \ - "push r28 \n\t" \ - "push r29 \n\t" \ - "push r30 \n\t" \ - "push r31 \n\t" \ - "lds r26, pxCurrentTCB \n\t" \ - "lds r27, pxCurrentTCB + 1 \n\t" \ - "in r0, 0x3d \n\t" \ - "st x+, r0 \n\t" \ - "in r0, 0x3e \n\t" \ - "st x+, r0 \n\t" \ - ); - -/* - * Opposite to portSAVE_CONTEXT(). Interrupts will have been disabled during - * the context save so we can write to the stack pointer. - */ - -#define portRESTORE_CONTEXT() \ - asm volatile ( "lds r26, pxCurrentTCB \n\t" \ - "lds r27, pxCurrentTCB + 1 \n\t" \ - "ld r28, x+ \n\t" \ - "out __SP_L__, r28 \n\t" \ - "ld r29, x+ \n\t" \ - "out __SP_H__, r29 \n\t" \ - "pop r31 \n\t" \ - "pop r30 \n\t" \ - "pop r29 \n\t" \ - "pop r28 \n\t" \ - "pop r27 \n\t" \ - "pop r26 \n\t" \ - "pop r25 \n\t" \ - "pop r24 \n\t" \ - "pop r23 \n\t" \ - "pop r22 \n\t" \ - "pop r21 \n\t" \ - "pop r20 \n\t" \ - "pop r19 \n\t" \ - "pop r18 \n\t" \ - "pop r17 \n\t" \ - "pop r16 \n\t" \ - "pop r15 \n\t" \ - "pop r14 \n\t" \ - "pop r13 \n\t" \ - "pop r12 \n\t" \ - "pop r11 \n\t" \ - "pop r10 \n\t" \ - "pop r9 \n\t" \ - "pop r8 \n\t" \ - "pop r7 \n\t" \ - "pop r6 \n\t" \ - "pop r5 \n\t" \ - "pop r4 \n\t" \ - "pop r3 \n\t" \ - "pop r2 \n\t" \ - "pop r1 \n\t" \ - "pop r0 \n\t" \ - "out __SREG__, r0 \n\t" \ - "pop r0 \n\t" \ - ); - -/*-----------------------------------------------------------*/ - -/* - * Perform hardware setup to enable ticks from timer 1, compare match A. - */ -static void prvSetupTimerInterrupt( void ); -/*-----------------------------------------------------------*/ - -/* - * See header file for description. - */ -portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ) -{ + +/*----------------------------------------------------------- + * Implementation of functions defined in portable.h for the AVR port. + *----------------------------------------------------------*/ + +/* Start tasks with interrupts enables. */ +#define portFLAGS_INT_ENABLED ( ( portSTACK_TYPE ) 0x80 ) + +/* Hardware constants for timer 1. */ +#define portCLEAR_COUNTER_ON_MATCH ( ( unsigned char ) 0x08 ) +#define portPRESCALE_64 ( ( unsigned char ) 0x03 ) +#define portCLOCK_PRESCALER ( ( unsigned long ) 64 ) +#define portCOMPARE_MATCH_A_INTERRUPT_ENABLE ( ( unsigned char ) 0x10 ) + +/*-----------------------------------------------------------*/ + +/* We require the address of the pxCurrentTCB variable, but don't want to know +any details of its type. */ +typedef void tskTCB; +extern volatile tskTCB * volatile pxCurrentTCB; + +/*-----------------------------------------------------------*/ + +/* + * Macro to save all the general purpose registers, the save the stack pointer + * into the TCB. + * + * The first thing we do is save the flags then disable interrupts. This is to + * guard our stack against having a context switch interrupt after we have already + * pushed the registers onto the stack - causing the 32 registers to be on the + * stack twice. + * + * r1 is set to zero as the compiler expects it to be thus, however some + * of the math routines make use of R1. + * + * The interrupts will have been disabled during the call to portSAVE_CONTEXT() + * so we need not worry about reading/writing to the stack pointer. + */ + +#define portSAVE_CONTEXT() \ + asm volatile ( "push r0 \n\t" \ + "in r0, __SREG__ \n\t" \ + "cli \n\t" \ + "push r0 \n\t" \ + "push r1 \n\t" \ + "clr r1 \n\t" \ + "push r2 \n\t" \ + "push r3 \n\t" \ + "push r4 \n\t" \ + "push r5 \n\t" \ + "push r6 \n\t" \ + "push r7 \n\t" \ + "push r8 \n\t" \ + "push r9 \n\t" \ + "push r10 \n\t" \ + "push r11 \n\t" \ + "push r12 \n\t" \ + "push r13 \n\t" \ + "push r14 \n\t" \ + "push r15 \n\t" \ + "push r16 \n\t" \ + "push r17 \n\t" \ + "push r18 \n\t" \ + "push r19 \n\t" \ + "push r20 \n\t" \ + "push r21 \n\t" \ + "push r22 \n\t" \ + "push r23 \n\t" \ + "push r24 \n\t" \ + "push r25 \n\t" \ + "push r26 \n\t" \ + "push r27 \n\t" \ + "push r28 \n\t" \ + "push r29 \n\t" \ + "push r30 \n\t" \ + "push r31 \n\t" \ + "lds r26, pxCurrentTCB \n\t" \ + "lds r27, pxCurrentTCB + 1 \n\t" \ + "in r0, 0x3d \n\t" \ + "st x+, r0 \n\t" \ + "in r0, 0x3e \n\t" \ + "st x+, r0 \n\t" \ + ); + +/* + * Opposite to portSAVE_CONTEXT(). Interrupts will have been disabled during + * the context save so we can write to the stack pointer. + */ + +#define portRESTORE_CONTEXT() \ + asm volatile ( "lds r26, pxCurrentTCB \n\t" \ + "lds r27, pxCurrentTCB + 1 \n\t" \ + "ld r28, x+ \n\t" \ + "out __SP_L__, r28 \n\t" \ + "ld r29, x+ \n\t" \ + "out __SP_H__, r29 \n\t" \ + "pop r31 \n\t" \ + "pop r30 \n\t" \ + "pop r29 \n\t" \ + "pop r28 \n\t" \ + "pop r27 \n\t" \ + "pop r26 \n\t" \ + "pop r25 \n\t" \ + "pop r24 \n\t" \ + "pop r23 \n\t" \ + "pop r22 \n\t" \ + "pop r21 \n\t" \ + "pop r20 \n\t" \ + "pop r19 \n\t" \ + "pop r18 \n\t" \ + "pop r17 \n\t" \ + "pop r16 \n\t" \ + "pop r15 \n\t" \ + "pop r14 \n\t" \ + "pop r13 \n\t" \ + "pop r12 \n\t" \ + "pop r11 \n\t" \ + "pop r10 \n\t" \ + "pop r9 \n\t" \ + "pop r8 \n\t" \ + "pop r7 \n\t" \ + "pop r6 \n\t" \ + "pop r5 \n\t" \ + "pop r4 \n\t" \ + "pop r3 \n\t" \ + "pop r2 \n\t" \ + "pop r1 \n\t" \ + "pop r0 \n\t" \ + "out __SREG__, r0 \n\t" \ + "pop r0 \n\t" \ + ); + +/*-----------------------------------------------------------*/ + +/* + * Perform hardware setup to enable ticks from timer 1, compare match A. + */ +static void prvSetupTimerInterrupt( void ); +/*-----------------------------------------------------------*/ + +/* + * See header file for description. + */ +portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ) +{ unsigned portSHORT usAddress; - - /* Place a few bytes of known values on the bottom of the stack. - This is just useful for debugging. */ - - *pxTopOfStack = 0x11; - pxTopOfStack--; - *pxTopOfStack = 0x22; - pxTopOfStack--; - *pxTopOfStack = 0x33; - pxTopOfStack--; - - /* Simulate how the stack would look after a call to vPortYield() generated by - the compiler. */ - - /*lint -e950 -e611 -e923 Lint doesn't like this much - but nothing I can do about it. */ - - /* The start of the task code will be popped off the stack last, so place - it on first. */ + + /* Place a few bytes of known values on the bottom of the stack. + This is just useful for debugging. */ + + *pxTopOfStack = 0x11; + pxTopOfStack--; + *pxTopOfStack = 0x22; + pxTopOfStack--; + *pxTopOfStack = 0x33; + pxTopOfStack--; + + /* Simulate how the stack would look after a call to vPortYield() generated by + the compiler. */ + + /*lint -e950 -e611 -e923 Lint doesn't like this much - but nothing I can do about it. */ + + /* The start of the task code will be popped off the stack last, so place + it on first. */ usAddress = ( unsigned portSHORT ) pxCode; *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff ); - pxTopOfStack--; - - usAddress >>= 8; + pxTopOfStack--; + + usAddress >>= 8; *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff ); - pxTopOfStack--; - - /* Next simulate the stack as if after a call to portSAVE_CONTEXT(). - portSAVE_CONTEXT places the flags on the stack immediately after r0 - to ensure the interrupts get disabled as soon as possible, and so ensuring - the stack use is minimal should a context switch interrupt occur. */ - *pxTopOfStack = ( portSTACK_TYPE ) 0x00; /* R0 */ - pxTopOfStack--; - *pxTopOfStack = portFLAGS_INT_ENABLED; - pxTopOfStack--; - - - /* Now the remaining registers. The compiler expects R1 to be 0. */ - *pxTopOfStack = ( portSTACK_TYPE ) 0x00; /* R1 */ - pxTopOfStack--; - *pxTopOfStack = ( portSTACK_TYPE ) 0x02; /* R2 */ - pxTopOfStack--; - *pxTopOfStack = ( portSTACK_TYPE ) 0x03; /* R3 */ - pxTopOfStack--; - *pxTopOfStack = ( portSTACK_TYPE ) 0x04; /* R4 */ - pxTopOfStack--; - *pxTopOfStack = ( portSTACK_TYPE ) 0x05; /* R5 */ - pxTopOfStack--; - *pxTopOfStack = ( portSTACK_TYPE ) 0x06; /* R6 */ - pxTopOfStack--; - *pxTopOfStack = ( portSTACK_TYPE ) 0x07; /* R7 */ - pxTopOfStack--; - *pxTopOfStack = ( portSTACK_TYPE ) 0x08; /* R8 */ - pxTopOfStack--; - *pxTopOfStack = ( portSTACK_TYPE ) 0x09; /* R9 */ - pxTopOfStack--; - *pxTopOfStack = ( portSTACK_TYPE ) 0x10; /* R10 */ - pxTopOfStack--; - *pxTopOfStack = ( portSTACK_TYPE ) 0x11; /* R11 */ - pxTopOfStack--; - *pxTopOfStack = ( portSTACK_TYPE ) 0x12; /* R12 */ - pxTopOfStack--; - *pxTopOfStack = ( portSTACK_TYPE ) 0x13; /* R13 */ - pxTopOfStack--; - *pxTopOfStack = ( portSTACK_TYPE ) 0x14; /* R14 */ - pxTopOfStack--; - *pxTopOfStack = ( portSTACK_TYPE ) 0x15; /* R15 */ - pxTopOfStack--; - *pxTopOfStack = ( portSTACK_TYPE ) 0x16; /* R16 */ - pxTopOfStack--; - *pxTopOfStack = ( portSTACK_TYPE ) 0x17; /* R17 */ - pxTopOfStack--; - *pxTopOfStack = ( portSTACK_TYPE ) 0x18; /* R18 */ - pxTopOfStack--; - *pxTopOfStack = ( portSTACK_TYPE ) 0x19; /* R19 */ - pxTopOfStack--; - *pxTopOfStack = ( portSTACK_TYPE ) 0x20; /* R20 */ - pxTopOfStack--; - *pxTopOfStack = ( portSTACK_TYPE ) 0x21; /* R21 */ - pxTopOfStack--; - *pxTopOfStack = ( portSTACK_TYPE ) 0x22; /* R22 */ - pxTopOfStack--; - *pxTopOfStack = ( portSTACK_TYPE ) 0x23; /* R23 */ - pxTopOfStack--; - - /* Place the parameter on the stack in the expected location. */ + pxTopOfStack--; + + /* Next simulate the stack as if after a call to portSAVE_CONTEXT(). + portSAVE_CONTEXT places the flags on the stack immediately after r0 + to ensure the interrupts get disabled as soon as possible, and so ensuring + the stack use is minimal should a context switch interrupt occur. */ + *pxTopOfStack = ( portSTACK_TYPE ) 0x00; /* R0 */ + pxTopOfStack--; + *pxTopOfStack = portFLAGS_INT_ENABLED; + pxTopOfStack--; + + + /* Now the remaining registers. The compiler expects R1 to be 0. */ + *pxTopOfStack = ( portSTACK_TYPE ) 0x00; /* R1 */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x02; /* R2 */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x03; /* R3 */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x04; /* R4 */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x05; /* R5 */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x06; /* R6 */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x07; /* R7 */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x08; /* R8 */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x09; /* R9 */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x10; /* R10 */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x11; /* R11 */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x12; /* R12 */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x13; /* R13 */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x14; /* R14 */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x15; /* R15 */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x16; /* R16 */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x17; /* R17 */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x18; /* R18 */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x19; /* R19 */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x20; /* R20 */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x21; /* R21 */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x22; /* R22 */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x23; /* R23 */ + pxTopOfStack--; + + /* Place the parameter on the stack in the expected location. */ usAddress = ( unsigned portSHORT ) pvParameters; *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff ); - pxTopOfStack--; - - usAddress >>= 8; + pxTopOfStack--; + + usAddress >>= 8; *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff ); - pxTopOfStack--; - - *pxTopOfStack = ( portSTACK_TYPE ) 0x26; /* R26 X */ - pxTopOfStack--; - *pxTopOfStack = ( portSTACK_TYPE ) 0x27; /* R27 */ - pxTopOfStack--; - *pxTopOfStack = ( portSTACK_TYPE ) 0x28; /* R28 Y */ - pxTopOfStack--; - *pxTopOfStack = ( portSTACK_TYPE ) 0x29; /* R29 */ - pxTopOfStack--; - *pxTopOfStack = ( portSTACK_TYPE ) 0x30; /* R30 Z */ - pxTopOfStack--; - *pxTopOfStack = ( portSTACK_TYPE ) 0x031; /* R31 */ - pxTopOfStack--; - - /*lint +e950 +e611 +e923 */ - - return pxTopOfStack; -} -/*-----------------------------------------------------------*/ - -portBASE_TYPE xPortStartScheduler( void ) -{ - /* Setup the hardware to generate the tick. */ - prvSetupTimerInterrupt(); - - /* Restore the context of the first task that is going to run. */ - portRESTORE_CONTEXT(); - - /* Simulate a function call end as generated by the compiler. We will now - jump to the start of the task the context of which we have just restored. */ - asm volatile ( "ret" ); - - /* Should not get here. */ - return pdTRUE; -} -/*-----------------------------------------------------------*/ - -void vPortEndScheduler( void ) -{ - /* It is unlikely that the AVR port will get stopped. If required simply - disable the tick interrupt here. */ -} -/*-----------------------------------------------------------*/ - -/* - * Manual context switch. The first thing we do is save the registers so we - * can use a naked attribute. - */ -void vPortYield( void ) __attribute__ ( ( naked ) ); -void vPortYield( void ) -{ - portSAVE_CONTEXT(); - vTaskSwitchContext(); - portRESTORE_CONTEXT(); - - asm volatile ( "ret" ); -} -/*-----------------------------------------------------------*/ - -/* - * Context switch function used by the tick. This must be identical to - * vPortYield() from the call to vTaskSwitchContext() onwards. The only - * difference from vPortYield() is the tick count is incremented as the - * call comes from the tick ISR. - */ -void vPortYieldFromTick( void ) __attribute__ ( ( naked ) ); -void vPortYieldFromTick( void ) -{ - portSAVE_CONTEXT(); - vTaskIncrementTick(); - vTaskSwitchContext(); - portRESTORE_CONTEXT(); - - asm volatile ( "ret" ); -} -/*-----------------------------------------------------------*/ - -/* - * Setup timer 1 compare match A to generate a tick interrupt. - */ -static void prvSetupTimerInterrupt( void ) -{ + pxTopOfStack--; + + *pxTopOfStack = ( portSTACK_TYPE ) 0x26; /* R26 X */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x27; /* R27 */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x28; /* R28 Y */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x29; /* R29 */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x30; /* R30 Z */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x031; /* R31 */ + pxTopOfStack--; + + /*lint +e950 +e611 +e923 */ + + return pxTopOfStack; +} +/*-----------------------------------------------------------*/ + +portBASE_TYPE xPortStartScheduler( void ) +{ + /* Setup the hardware to generate the tick. */ + prvSetupTimerInterrupt(); + + /* Restore the context of the first task that is going to run. */ + portRESTORE_CONTEXT(); + + /* Simulate a function call end as generated by the compiler. We will now + jump to the start of the task the context of which we have just restored. */ + asm volatile ( "ret" ); + + /* Should not get here. */ + return pdTRUE; +} +/*-----------------------------------------------------------*/ + +void vPortEndScheduler( void ) +{ + /* It is unlikely that the AVR port will get stopped. If required simply + disable the tick interrupt here. */ +} +/*-----------------------------------------------------------*/ + +/* + * Manual context switch. The first thing we do is save the registers so we + * can use a naked attribute. + */ +void vPortYield( void ) __attribute__ ( ( naked ) ); +void vPortYield( void ) +{ + portSAVE_CONTEXT(); + vTaskSwitchContext(); + portRESTORE_CONTEXT(); + + asm volatile ( "ret" ); +} +/*-----------------------------------------------------------*/ + +/* + * Context switch function used by the tick. This must be identical to + * vPortYield() from the call to vTaskSwitchContext() onwards. The only + * difference from vPortYield() is the tick count is incremented as the + * call comes from the tick ISR. + */ +void vPortYieldFromTick( void ) __attribute__ ( ( naked ) ); +void vPortYieldFromTick( void ) +{ + portSAVE_CONTEXT(); + vTaskIncrementTick(); + vTaskSwitchContext(); + portRESTORE_CONTEXT(); + + asm volatile ( "ret" ); +} +/*-----------------------------------------------------------*/ + +/* + * Setup timer 1 compare match A to generate a tick interrupt. + */ +static void prvSetupTimerInterrupt( void ) +{ // on the ATmega168, timer 0 is also used for fast hardware pwm // (using phase-correct PWM would mean that timer 0 overflowed half as often // resulting in different millis() behavior on the ATmega8 and ATmega168) @@ -392,7 +408,7 @@ static void prvSetupTimerInterrupt( void ) sbi(TCCR0A, WGM01); sbi(TCCR0A, WGM00); #endif - + // set timer 0 prescale factor to 64 #if defined(__AVR_ATmega128__) // CPU specific: different values for the ATmega128 @@ -412,7 +428,7 @@ static void prvSetupTimerInterrupt( void ) #else #error Timer 0 prescale factor 64 not set correctly #endif - + // enable timer 0 overflow interrupt #if defined(TIMSK) && defined(TOIE0) sbi(TIMSK, TOIE0); @@ -421,40 +437,49 @@ static void prvSetupTimerInterrupt( void ) #else #error Timer 0 overflow interrupt not set correctly #endif -} -/*-----------------------------------------------------------*/ - -#if configUSE_PREEMPTION == 1 - - /* - * Tick ISR for preemptive scheduler. We can use a naked attribute as - * the context is saved at the start of vPortYieldFromTick(). The tick - * count is incremented after the context is saved. - */ - #if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) - ISR(TIM0_OVF_vect) - #else - ISR(TIMER0_OVF_vect) - #endif - { - vPortYieldFromTick(); - } -#else - - /* - * Tick ISR for the cooperative scheduler. All this does is increment the - * tick count. We don't need to switch context, this can only be done by - * manual calls to taskYIELD(); - */ - #if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) - SIGNAL(TIM0_OVF_vect) - #else - SIGNAL(TIMER0_OVF_vect) - #endif - { - vTaskIncrementTick(); - } -#endif - - - +} +/*-----------------------------------------------------------*/ + +#if configUSE_PREEMPTION == 1 + + /* + * Tick ISR for preemptive scheduler. We can use a naked attribute as + * the context is saved at the start of vPortYieldFromTick(). The tick + * count is incremented after the context is saved. + */ + /* + void SIG_OUTPUT_COMPARE1A( void ) __attribute__ ( ( signal, naked ) ); + void SIG_OUTPUT_COMPARE1A( void ) + */ + #if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) + ISR(TIM0_OVF_vect) + #else + ISR(TIMER0_OVF_vect) + #endif + { + vPortYieldFromTick(); + //asm volatile ( "reti" ); + } +#else + + /* + * Tick ISR for the cooperative scheduler. All this does is increment the + * tick count. We don't need to switch context, this can only be done by + * manual calls to taskYIELD(); + */ + /* + void SIG_OUTPUT_COMPARE1A( void ) __attribute__ ( ( signal ) ); + void SIG_OUTPUT_COMPARE1A( void ) + */ + #if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) + SIGNAL(TIM0_OVF_vect) + #else + SIGNAL(TIMER0_OVF_vect) + #endif + { + vTaskIncrementTick(); + } +#endif + + + diff --git a/arduino.DuinOS/DuinOS/portable.h b/arduino.DuinOS.AVR/DuinOS/portable.h similarity index 85% rename from arduino.DuinOS/DuinOS/portable.h rename to arduino.DuinOS.AVR/DuinOS/portable.h index f99a880..bdf1e8f 100644 --- a/arduino.DuinOS/DuinOS/portable.h +++ b/arduino.DuinOS.AVR/DuinOS/portable.h @@ -1,6 +1,8 @@ /* - FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd. + FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** * * @@ -40,15 +42,28 @@ FreeRTOS WEB site. 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** - http://www.FreeRTOS.org - Documentation, latest information, license and - contact details. - - http://www.SafeRTOS.com - A version that is certified for use in safety - critical systems. - - http://www.OpenRTOS.com - Commercial support, development, porting, - licensing and training services. + + http://www.FreeRTOS.org - Documentation, training, latest versions, license + and contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool. + + Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell + the code with commercial support, indemnification, and middleware, under + the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also + provide a safety engineered and independently SIL3 certified version under + the SafeRTOS brand: http://www.SafeRTOS.com. */ /*----------------------------------------------------------- diff --git a/arduino.DuinOS.AVR/DuinOS/portmacro.h b/arduino.DuinOS.AVR/DuinOS/portmacro.h new file mode 100644 index 0000000..bef20ad --- /dev/null +++ b/arduino.DuinOS.AVR/DuinOS/portmacro.h @@ -0,0 +1,144 @@ +/* + FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. + + *************************************************************************** + * * + * FreeRTOS tutorial books are available in pdf and paperback. * + * Complete, revised, and edited pdf reference manuals are also * + * available. * + * * + * Purchasing FreeRTOS documentation will not only help you, by * + * ensuring you get running as quickly as possible and with an * + * in-depth knowledge of how to use FreeRTOS, it will also help * + * the FreeRTOS project to continue with its mission of providing * + * professional grade, cross platform, de facto standard solutions * + * for microcontrollers - completely free of charge! * + * * + * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * + * * + * Thank you for using FreeRTOS, and thank you for your support! * + * * + *************************************************************************** + + + This file is part of the FreeRTOS distribution. + + FreeRTOS is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License (version 2) as published by the + Free Software Foundation AND MODIFIED BY the FreeRTOS exception. + >>>NOTE<<< The modification to the GPL is included to allow you to + distribute a combined work that includes FreeRTOS without being obliged to + provide the source code for proprietary components outside of the FreeRTOS + kernel. FreeRTOS is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. You should have received a copy of the GNU General Public + License and the FreeRTOS license exception along with FreeRTOS; if not it + can be viewed here: http://www.freertos.org/a00114.html and also obtained + by writing to Richard Barry, contact details for whom are available on the + FreeRTOS WEB site. + + 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** + + + http://www.FreeRTOS.org - Documentation, training, latest versions, license + and contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool. + + Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell + the code with commercial support, indemnification, and middleware, under + the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also + provide a safety engineered and independently SIL3 certified version under + the SafeRTOS brand: http://www.SafeRTOS.com. +*/ + +/* +Changes from V1.2.3 + + + portCPU_CLOSK_HZ definition changed to 8MHz base 10, previously it + base 16. +*/ + +#ifndef PORTMACRO_H +#define PORTMACRO_H + +#ifdef __cplusplus +extern "C" { +#endif + +/*----------------------------------------------------------- + * Port specific definitions. + * + * The settings in this file configure FreeRTOS correctly for the + * given hardware and compiler. + * + * These settings should not be altered. + *----------------------------------------------------------- + */ + +/* Type definitions. */ +#define portCHAR char +#define portFLOAT float +#define portDOUBLE double +#define portLONG long +#define portSHORT int +#define portSTACK_TYPE unsigned portCHAR +#define portBASE_TYPE char + +#if( configUSE_16_BIT_TICKS == 1 ) + typedef unsigned portSHORT portTickType; + #define portMAX_DELAY ( portTickType ) 0xffff +#else + typedef unsigned portLONG portTickType; + #define portMAX_DELAY ( portTickType ) 0xffffffff +#endif +/*-----------------------------------------------------------*/ + +/* Critical section management. */ +#define portENTER_CRITICAL() asm volatile ( "in __tmp_reg__, __SREG__" :: ); \ + asm volatile ( "cli" :: ); \ + asm volatile ( "push __tmp_reg__" :: ) + +#define portEXIT_CRITICAL() asm volatile ( "pop __tmp_reg__" :: ); \ + asm volatile ( "out __SREG__, __tmp_reg__" :: ) + +#define portDISABLE_INTERRUPTS() asm volatile ( "cli" :: ); +#define portENABLE_INTERRUPTS() asm volatile ( "sei" :: ); +/*-----------------------------------------------------------*/ + +/* Architecture specifics. */ +#define portSTACK_GROWTH ( -1 ) +#define portTICK_RATE_MS ( ( portTickType ) 1000 / configTICK_RATE_HZ ) +#define portBYTE_ALIGNMENT 1 +#define portNOP() asm volatile ( "nop" ); +/*-----------------------------------------------------------*/ + +/* Kernel utilities. */ +extern void vPortYield( void ) __attribute__ ( ( naked ) ); +#define portYIELD() vPortYield() +/*-----------------------------------------------------------*/ + +/* Task function macros as described on the FreeRTOS.org WEB site. */ +#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) +#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) + +#ifdef __cplusplus +} +#endif + +#endif /* PORTMACRO_H */ + diff --git a/arduino.DuinOS/DuinOS/projdefs.h b/arduino.DuinOS.AVR/DuinOS/projdefs.h similarity index 66% rename from arduino.DuinOS/DuinOS/projdefs.h rename to arduino.DuinOS.AVR/DuinOS/projdefs.h index a5210c7..9001cb5 100644 --- a/arduino.DuinOS/DuinOS/projdefs.h +++ b/arduino.DuinOS.AVR/DuinOS/projdefs.h @@ -1,6 +1,8 @@ /* - FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd. + FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** * * @@ -40,15 +42,28 @@ FreeRTOS WEB site. 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** - http://www.FreeRTOS.org - Documentation, latest information, license and - contact details. - - http://www.SafeRTOS.com - A version that is certified for use in safety - critical systems. - - http://www.OpenRTOS.com - Commercial support, development, porting, - licensing and training services. + + http://www.FreeRTOS.org - Documentation, training, latest versions, license + and contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool. + + Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell + the code with commercial support, indemnification, and middleware, under + the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also + provide a safety engineered and independently SIL3 certified version under + the SafeRTOS brand: http://www.SafeRTOS.com. */ #ifndef PROJDEFS_H diff --git a/arduino.DuinOS/DuinOS/queue.c b/arduino.DuinOS.AVR/DuinOS/queue.c similarity index 88% rename from arduino.DuinOS/DuinOS/queue.c rename to arduino.DuinOS.AVR/DuinOS/queue.c index 9dfc679..c4e3712 100644 --- a/arduino.DuinOS/DuinOS/queue.c +++ b/arduino.DuinOS.AVR/DuinOS/queue.c @@ -1,6 +1,8 @@ /* - FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd. + FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** * * @@ -40,15 +42,28 @@ FreeRTOS WEB site. 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** - http://www.FreeRTOS.org - Documentation, latest information, license and - contact details. - - http://www.SafeRTOS.com - A version that is certified for use in safety - critical systems. - - http://www.OpenRTOS.com - Commercial support, development, porting, - licensing and training services. + + http://www.FreeRTOS.org - Documentation, training, latest versions, license + and contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool. + + Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell + the code with commercial support, indemnification, and middleware, under + the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also + provide a safety engineered and independently SIL3 certified version under + the SafeRTOS brand: http://www.SafeRTOS.com. */ #include @@ -72,7 +87,7 @@ task.h is included from an application file. */ * PUBLIC LIST API documented in list.h *----------------------------------------------------------*/ -/* Constants used with the cRxLock and cTxLock structure members. */ +/* Constants used with the cRxLock and xTxLock structure members. */ #define queueUNLOCKED ( ( signed portBASE_TYPE ) -1 ) #define queueLOCKED_UNMODIFIED ( ( signed portBASE_TYPE ) 0 ) @@ -120,9 +135,9 @@ typedef struct QueueDefinition unsigned portBASE_TYPE uxLength; /*< The length of the queue defined as the number of items it will hold, not the number of bytes. */ unsigned portBASE_TYPE uxItemSize; /*< The size of each items that the queue will hold. */ - signed portBASE_TYPE xRxLock; /*< Stores the number of items received from the queue (removed from the queue) while the queue was locked. Set to queueUNLOCKED when the queue is not locked. */ - signed portBASE_TYPE xTxLock; /*< Stores the number of items transmitted to the queue (added to the queue) while the queue was locked. Set to queueUNLOCKED when the queue is not locked. */ - + volatile signed portBASE_TYPE xRxLock; /*< Stores the number of items received from the queue (removed from the queue) while the queue was locked. Set to queueUNLOCKED when the queue is not locked. */ + volatile signed portBASE_TYPE xTxLock; /*< Stores the number of items transmitted to the queue (added to the queue) while the queue was locked. Set to queueUNLOCKED when the queue is not locked. */ + #if ( configUSE_TRACE_FACILITY == 1 ) unsigned char ucQueueNumber; unsigned char ucQueueType; @@ -144,12 +159,12 @@ typedef xQUEUE * xQueueHandle; * functions are documented in the API header file. */ xQueueHandle xQueueGenericCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize, unsigned char ucQueueType ) PRIVILEGED_FUNCTION; -signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION; +signed portBASE_TYPE xQueueGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION; unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION; void vQueueDelete( xQueueHandle xQueue ) PRIVILEGED_FUNCTION; signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION; signed portBASE_TYPE xQueueGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking ) PRIVILEGED_FUNCTION; -signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken ) PRIVILEGED_FUNCTION; +signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; xQueueHandle xQueueCreateMutex( unsigned char ucQueueType ) PRIVILEGED_FUNCTION; xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount ) PRIVILEGED_FUNCTION; portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime ) PRIVILEGED_FUNCTION; @@ -163,6 +178,8 @@ void vQueueWaitForMessageRestricted( xQueueHandle pxQueue, portTickType xTicksTo unsigned char ucQueueGetQueueNumber( xQueueHandle pxQueue ) PRIVILEGED_FUNCTION; void vQueueSetQueueNumber( xQueueHandle pxQueue, unsigned char ucQueueNumber ) PRIVILEGED_FUNCTION; unsigned char ucQueueGetQueueType( xQueueHandle pxQueue ) PRIVILEGED_FUNCTION; +portBASE_TYPE xQueueGenericReset( xQueueHandle pxQueue, portBASE_TYPE xNewQueue ) PRIVILEGED_FUNCTION; +xTaskHandle xQueueGetMutexHolder( xQueueHandle xSemaphore ) PRIVILEGED_FUNCTION; /* * Co-routine queue functions differ from task queue functions. Co-routines are @@ -261,13 +278,56 @@ static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void *pvBuffer ) * PUBLIC QUEUE MANAGEMENT API documented in queue.h *----------------------------------------------------------*/ +portBASE_TYPE xQueueGenericReset( xQueueHandle pxQueue, portBASE_TYPE xNewQueue ) +{ + configASSERT( pxQueue ); + + taskENTER_CRITICAL(); + { + pxQueue->pcTail = pxQueue->pcHead + ( pxQueue->uxLength * pxQueue->uxItemSize ); + pxQueue->uxMessagesWaiting = ( unsigned portBASE_TYPE ) 0U; + pxQueue->pcWriteTo = pxQueue->pcHead; + pxQueue->pcReadFrom = pxQueue->pcHead + ( ( pxQueue->uxLength - ( unsigned portBASE_TYPE ) 1U ) * pxQueue->uxItemSize ); + pxQueue->xRxLock = queueUNLOCKED; + pxQueue->xTxLock = queueUNLOCKED; + + if( xNewQueue == pdFALSE ) + { + /* If there are tasks blocked waiting to read from the queue, then + the tasks will remain blocked as after this function exits the queue + will still be empty. If there are tasks blocked waiting to write to + the queue, then one should be unblocked as after this function exits + it will be possible to write to it. */ + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) == pdTRUE ) + { + portYIELD_WITHIN_API(); + } + } + } + else + { + /* Ensure the event queues start in the correct state. */ + vListInitialise( &( pxQueue->xTasksWaitingToSend ) ); + vListInitialise( &( pxQueue->xTasksWaitingToReceive ) ); + } + } + taskEXIT_CRITICAL(); + + /* A value is returned for calling semantic consistency with previous + versions. */ + return pdPASS; +} +/*-----------------------------------------------------------*/ + xQueueHandle xQueueGenericCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize, unsigned char ucQueueType ) { xQUEUE *pxNewQueue; size_t xQueueSizeInBytes; xQueueHandle xReturn = NULL; - /* Remove compiler warnings about unused parameters should + /* Remove compiler warnings about unused parameters should configUSE_TRACE_FACILITY not be set to 1. */ ( void ) ucQueueType; @@ -286,24 +346,15 @@ xQueueHandle xReturn = NULL; { /* Initialise the queue members as described above where the queue type is defined. */ - pxNewQueue->pcTail = pxNewQueue->pcHead + ( uxQueueLength * uxItemSize ); - pxNewQueue->uxMessagesWaiting = ( unsigned portBASE_TYPE ) 0U; - pxNewQueue->pcWriteTo = pxNewQueue->pcHead; - pxNewQueue->pcReadFrom = pxNewQueue->pcHead + ( ( uxQueueLength - ( unsigned portBASE_TYPE ) 1U ) * uxItemSize ); pxNewQueue->uxLength = uxQueueLength; pxNewQueue->uxItemSize = uxItemSize; - pxNewQueue->xRxLock = queueUNLOCKED; - pxNewQueue->xTxLock = queueUNLOCKED; + xQueueGenericReset( pxNewQueue, pdTRUE ); #if ( configUSE_TRACE_FACILITY == 1 ) { pxNewQueue->ucQueueType = ucQueueType; } #endif /* configUSE_TRACE_FACILITY */ - /* Likewise ensure the event queues start with the correct state. */ - vListInitialise( &( pxNewQueue->xTasksWaitingToSend ) ); - vListInitialise( &( pxNewQueue->xTasksWaitingToReceive ) ); - traceQUEUE_CREATE( pxNewQueue ); xReturn = pxNewQueue; } @@ -330,7 +381,7 @@ xQueueHandle xReturn = NULL; /* Prevent compiler warnings about unused parameters if configUSE_TRACE_FACILITY does not equal 1. */ ( void ) ucQueueType; - + /* Allocate the new queue structure. */ pxNewQueue = ( xQUEUE * ) pvPortMalloc( sizeof( xQUEUE ) ); if( pxNewQueue != NULL ) @@ -352,7 +403,7 @@ xQueueHandle xReturn = NULL; pxNewQueue->uxItemSize = ( unsigned portBASE_TYPE ) 0U; pxNewQueue->xRxLock = queueUNLOCKED; pxNewQueue->xTxLock = queueUNLOCKED; - + #if ( configUSE_TRACE_FACILITY == 1 ) { pxNewQueue->ucQueueType = ucQueueType; @@ -380,7 +431,37 @@ xQueueHandle xReturn = NULL; #endif /* configUSE_MUTEXES */ /*-----------------------------------------------------------*/ -#if configUSE_RECURSIVE_MUTEXES == 1 +#if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xQueueGetMutexHolder == 1 ) ) + + void* xQueueGetMutexHolder( xQueueHandle xSemaphore ) + { + void *pxReturn; + + /* This function is called by xSemaphoreGetMutexHolder(), and should not + be called directly. Note: This is is a good way of determining if the + calling task is the mutex holder, but not a good way of determining the + identity of the mutex holder, as the holder may change between the + following critical section exiting and the function returning. */ + taskENTER_CRITICAL(); + { + if( xSemaphore->uxQueueType == queueQUEUE_IS_MUTEX ) + { + pxReturn = ( void * ) xSemaphore->pxMutexHolder; + } + else + { + pxReturn = NULL; + } + } + taskEXIT_CRITICAL(); + + return pxReturn; + } + +#endif +/*-----------------------------------------------------------*/ + +#if ( configUSE_RECURSIVE_MUTEXES == 1 ) portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle pxMutex ) { @@ -795,7 +876,9 @@ xTimeOutType xTimeOut; if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX ) { portENTER_CRITICAL(); + { vTaskPriorityInherit( ( void * ) pxQueue->pxMutexHolder ); + } portEXIT_CRITICAL(); } } @@ -826,7 +909,6 @@ signed portBASE_TYPE xReturn; unsigned portBASE_TYPE uxSavedInterruptStatus; configASSERT( pxQueue ); - configASSERT( pxHigherPriorityTaskWoken ); configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) ); /* Similar to xQueueGenericSend, except we don't block if there is no room @@ -852,7 +934,10 @@ unsigned portBASE_TYPE uxSavedInterruptStatus; { /* The task waiting has a higher priority so record that a context switch is required. */ - *pxHigherPriorityTaskWoken = pdTRUE; + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } } } } @@ -949,7 +1034,6 @@ signed char *pcOriginalReadPosition; portYIELD_WITHIN_API(); } } - } taskEXIT_CRITICAL(); @@ -1027,13 +1111,12 @@ signed char *pcOriginalReadPosition; } /*-----------------------------------------------------------*/ -signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken ) +signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken ) { signed portBASE_TYPE xReturn; unsigned portBASE_TYPE uxSavedInterruptStatus; configASSERT( pxQueue ); - configASSERT( pxTaskWoken ); configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) ); uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); @@ -1057,7 +1140,10 @@ unsigned portBASE_TYPE uxSavedInterruptStatus; { /* The task waiting has a higher priority than us so force a context switch. */ - *pxTaskWoken = pdTRUE; + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } } } } diff --git a/arduino.DuinOS/DuinOS/queue.h b/arduino.DuinOS.AVR/DuinOS/queue.h similarity index 92% rename from arduino.DuinOS/DuinOS/queue.h rename to arduino.DuinOS.AVR/DuinOS/queue.h index 80ee4f1..40562cf 100644 --- a/arduino.DuinOS/DuinOS/queue.h +++ b/arduino.DuinOS.AVR/DuinOS/queue.h @@ -1,6 +1,8 @@ /* - FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd. + FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** * * @@ -40,15 +42,28 @@ FreeRTOS WEB site. 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** - http://www.FreeRTOS.org - Documentation, latest information, license and - contact details. - - http://www.SafeRTOS.com - A version that is certified for use in safety - critical systems. - - http://www.OpenRTOS.com - Commercial support, development, porting, - licensing and training services. + + http://www.FreeRTOS.org - Documentation, training, latest versions, license + and contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool. + + Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell + the code with commercial support, indemnification, and middleware, under + the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also + provide a safety engineered and independently SIL3 certified version under + the SafeRTOS brand: http://www.SafeRTOS.com. */ @@ -56,7 +71,7 @@ #define QUEUE_H #ifndef INC_FREERTOS_H - #error "#include FreeRTOS.h" must appear in source files before "#include queue.h" + #error "include FreeRTOS.h" must appear in source files before "include queue.h" #endif #ifdef __cplusplus @@ -1174,10 +1189,10 @@ signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR * \ingroup QueueManagement */ -signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken ); +signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken ); /* - * Utilities to query queue that are safe to use from an ISR. These utilities + * Utilities to query queues that are safe to use from an ISR. These utilities * should be used only from witin an ISR, or within a critical section. */ signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue ); @@ -1221,11 +1236,13 @@ signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQue signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait ); /* - * For internal use only. Use xSemaphoreCreateMutex() or - * xSemaphoreCreateCounting() instead of calling these functions directly. + * For internal use only. Use xSemaphoreCreateMutex(), + * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling + * these functions directly. */ xQueueHandle xQueueCreateMutex( unsigned char ucQueueType ); xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount ); +void* xQueueGetMutexHolder( xQueueHandle xSemaphore ); /* * For internal use only. Use xSemaphoreTakeMutexRecursive() or @@ -1234,6 +1251,14 @@ xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle pxMutex, portTickType xBlockTime ); portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle pxMutex ); +/* + * Reset a queue back to its original empty state. pdPASS is returned if the + * queue is successfully reset. pdFAIL is returned if the queue could not be + * reset because there are tasks blocked on the queue waiting to either + * receive from the queue or send to the queue. + */ +#define xQueueReset( pxQueue ) xQueueGenericReset( pxQueue, pdFALSE ) + /* * The registry is provided as a means for kernel aware debuggers to * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add @@ -1264,10 +1289,9 @@ portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle pxMutex ); */ xQueueHandle xQueueGenericCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize, unsigned char ucQueueType ); -/* - * Not a public API function, hence the 'Restricted' in the name. - */ +/* Not public API functions. */ void vQueueWaitForMessageRestricted( xQueueHandle pxQueue, portTickType xTicksToWait ); +portBASE_TYPE xQueueGenericReset( xQueueHandle pxQueue, portBASE_TYPE xNewQueue ); #ifdef __cplusplus diff --git a/arduino.DuinOS/DuinOS/semphr.h b/arduino.DuinOS.AVR/DuinOS/semphr.h similarity index 85% rename from arduino.DuinOS/DuinOS/semphr.h rename to arduino.DuinOS.AVR/DuinOS/semphr.h index 251e738..ef2dac2 100644 --- a/arduino.DuinOS/DuinOS/semphr.h +++ b/arduino.DuinOS.AVR/DuinOS/semphr.h @@ -1,6 +1,8 @@ /* - FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd. + FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** * * @@ -40,22 +42,35 @@ FreeRTOS WEB site. 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** - http://www.FreeRTOS.org - Documentation, latest information, license and - contact details. - - http://www.SafeRTOS.com - A version that is certified for use in safety - critical systems. - - http://www.OpenRTOS.com - Commercial support, development, porting, - licensing and training services. + + http://www.FreeRTOS.org - Documentation, training, latest versions, license + and contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool. + + Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell + the code with commercial support, indemnification, and middleware, under + the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also + provide a safety engineered and independently SIL3 certified version under + the SafeRTOS brand: http://www.SafeRTOS.com. */ #ifndef SEMAPHORE_H #define SEMAPHORE_H #ifndef INC_FREERTOS_H - #error "#include FreeRTOS.h" must appear in source files before "#include semphr.h" + #error "include FreeRTOS.h" must appear in source files before "include semphr.h" #endif #include "queue.h" @@ -541,6 +556,40 @@ typedef xQueueHandle xSemaphoreHandle; */ #define xSemaphoreGiveFromISR( xSemaphore, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueueHandle ) ( xSemaphore ), NULL, ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK ) +/** + * semphr. h + *
+ xSemaphoreTakeFromISR( 
+                          xSemaphoreHandle xSemaphore, 
+                          signed portBASE_TYPE *pxHigherPriorityTaskWoken
+                      )
+ * + * Macro to take a semaphore from an ISR. The semaphore must have + * previously been created with a call to vSemaphoreCreateBinary() or + * xSemaphoreCreateCounting(). + * + * Mutex type semaphores (those created using a call to xSemaphoreCreateMutex()) + * must not be used with this macro. + * + * This macro can be used from an ISR, however taking a semaphore from an ISR + * is not a common operation. It is likely to only be useful when taking a + * counting semaphore when an interrupt is obtaining an object from a resource + * pool (when the semaphore count indicates the number of resources available). + * + * @param xSemaphore A handle to the semaphore being taken. This is the + * handle returned when the semaphore was created. + * + * @param pxHigherPriorityTaskWoken xSemaphoreTakeFromISR() will set + * *pxHigherPriorityTaskWoken to pdTRUE if taking the semaphore caused a task + * to unblock, and the unblocked task has a priority higher than the currently + * running task. If xSemaphoreTakeFromISR() sets this value to pdTRUE then + * a context switch should be requested before the interrupt is exited. + * + * @return pdTRUE if the semaphore was successfully taken, otherwise + * pdFALSE + */ +#define xSemaphoreTakeFromISR( xSemaphore, pxHigherPriorityTaskWoken ) xQueueReceiveFromISR( ( xQueueHandle ) ( xSemaphore ), NULL, ( pxHigherPriorityTaskWoken ) ) + /** * semphr. h *
xSemaphoreHandle xSemaphoreCreateMutex( void )
@@ -718,7 +767,22 @@ typedef xQueueHandle xSemaphoreHandle; * \page vSemaphoreDelete vSemaphoreDelete * \ingroup Semaphores */ -#define vSemaphoreDelete( xSemaphore ) vQueueDelete( ( xQueueHandle ) xSemaphore ) +#define vSemaphoreDelete( xSemaphore ) vQueueDelete( ( xQueueHandle ) ( xSemaphore ) ) + +/** + * semphr.h + *
xTaskHandle xSemaphoreGetMutexHolder( xSemaphoreHandle xMutex );
+ * + * If xMutex is indeed a mutex type semaphore, return the current mutex holder. + * If xMutex is not a mutex type semaphore, or the mutex is available (not held + * by a task), return NULL. + * + * Note: This Is is a good way of determining if the calling task is the mutex + * holder, but not a good way of determining the identity of the mutex holder as + * the holder may change between the function exiting and the returned value + * being tested. + */ +#define xSemaphoreGetMutexHolder( xSemaphore ) xQueueGetMutexHolder( ( xSemaphore ) ) #endif /* SEMAPHORE_H */ diff --git a/arduino.DuinOS/DuinOS/task.h b/arduino.DuinOS.AVR/DuinOS/task.h similarity index 91% rename from arduino.DuinOS/DuinOS/task.h rename to arduino.DuinOS.AVR/DuinOS/task.h index 38e9d55..b6a7818 100644 --- a/arduino.DuinOS/DuinOS/task.h +++ b/arduino.DuinOS.AVR/DuinOS/task.h @@ -1,5 +1,5 @@ /* - FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd. + FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. *************************************************************************** @@ -41,14 +41,28 @@ 1 tab == 4 spaces! - http://www.FreeRTOS.org - Documentation, latest information, license and - contact details. - - http://www.SafeRTOS.com - A version that is certified for use in safety - critical systems. + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong? * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** - http://www.OpenRTOS.com - Commercial support, development, porting, - licensing and training services. + + http://www.FreeRTOS.org - Documentation, training, latest information, + license and contact details. + + http://www.FreeRTOS.org/plus - Selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool. + + Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell + the code with commercial support, indemnification, and middleware, under + the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also + provide a safety engineered and independently SIL3 certified version under + the SafeRTOS brand: http://www.SafeRTOS.com. */ @@ -70,7 +84,7 @@ extern "C" { * MACROS AND DEFINITIONS *----------------------------------------------------------*/ -#define tskKERNEL_VERSION_NUMBER "V7.1.0" +#define tskKERNEL_VERSION_NUMBER "V7.3.0" /** * task. h @@ -117,6 +131,16 @@ typedef struct xTASK_PARAMTERS xMemoryRegion xRegions[ portNUM_CONFIGURABLE_REGIONS ]; } xTaskParameters; +/* Task states returned by eTaskStateGet. */ +typedef enum +{ + eRunning = 0, /* A task is querying the state of itself, so must be running. */ + eReady, /* The task being queried is in a read or pending ready list. */ + eBlocked, /* The task being queried is in the Blocked state. */ + eSuspended, /* The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */ + eDeleted /* The task being queried has been deleted, but its TCB has not yet been freed. */ +} eTaskState; + /* * Defines the priority used by the idle task. This must not be modified. * @@ -587,6 +611,24 @@ void vTaskDelayUntil( portTickType * const pxPreviousWakeTime, portTickType xTim */ unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask ) PRIVILEGED_FUNCTION; +/** + * task. h + *
eTaskState eTaskStateGet( xTaskHandle pxTask );
+ * + * INCLUDE_eTaskStateGet must be defined as 1 for this function to be available. + * See the configuration section for more information. + * + * Obtain the state of any task. States are encoded by the eTaskState + * enumerated type. + * + * @param pxTask Handle of the task to be queried. + * + * @return The state of pxTask at the time the function was called. Note the + * state of the task might change between the function being called, and the + * functions return value being tested by the calling task. + */ +eTaskState eTaskStateGet( xTaskHandle pxTask ) PRIVILEGED_FUNCTION; + /** * task. h *
void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority );
@@ -1071,40 +1113,6 @@ void vTaskList( signed char *pcWriteBuffer ) PRIVILEGED_FUNCTION; */ void vTaskGetRunTimeStats( signed char *pcWriteBuffer ) PRIVILEGED_FUNCTION; -/** - * task. h - *
void vTaskStartTrace( char * pcBuffer, unsigned portBASE_TYPE uxBufferSize );
- * - * Starts a real time kernel activity trace. The trace logs the identity of - * which task is running when. - * - * The trace file is stored in binary format. A separate DOS utility called - * convtrce.exe is used to convert this into a tab delimited text file which - * can be viewed and plotted in a spread sheet. - * - * @param pcBuffer The buffer into which the trace will be written. - * - * @param ulBufferSize The size of pcBuffer in bytes. The trace will continue - * until either the buffer in full, or ulTaskEndTrace () is called. - * - * \page vTaskStartTrace vTaskStartTrace - * \ingroup TaskUtils - */ -void vTaskStartTrace( signed char * pcBuffer, unsigned long ulBufferSize ) PRIVILEGED_FUNCTION; - -/** - * task. h - *
unsigned long ulTaskEndTrace( void );
- * - * Stops a kernel activity trace. See vTaskStartTrace (). - * - * @return The number of bytes that have been written into the trace buffer. - * - * \page usTaskEndTrace usTaskEndTrace - * \ingroup TaskUtils - */ -unsigned long ulTaskEndTrace( void ) PRIVILEGED_FUNCTION; - /** * task.h *
unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask );
@@ -1312,6 +1320,14 @@ unsigned portBASE_TYPE uxTaskGetTaskNumber( xTaskHandle xTask ); */ void vTaskSetTaskNumber( xTaskHandle xTask, unsigned portBASE_TYPE uxHandle ); +/* + * If tickless mode is being used, or a low power mode is implemented, then + * the tick interrupt will not execute during idle periods. When this is the + * case, the tick count value maintained by the scheduler needs to be kept up + * to date with the actual execution time by being skipped forward by the by + * a time equal to the idle period. + */ +void vTaskStepTick( portTickType xTicksToJump ); #ifdef __cplusplus } diff --git a/arduino.DuinOS/DuinOS/tasks.c b/arduino.DuinOS.AVR/DuinOS/tasks.c similarity index 78% rename from arduino.DuinOS/DuinOS/tasks.c rename to arduino.DuinOS.AVR/DuinOS/tasks.c index bec79c2..a7800fc 100644 --- a/arduino.DuinOS/DuinOS/tasks.c +++ b/arduino.DuinOS.AVR/DuinOS/tasks.c @@ -1,6 +1,8 @@ /* - FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd. - + FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** * * @@ -41,17 +43,30 @@ 1 tab == 4 spaces! - http://www.FreeRTOS.org - Documentation, latest information, license and - contact details. + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** + - http://www.SafeRTOS.com - A version that is certified for use in safety - critical systems. + http://www.FreeRTOS.org - Documentation, training, latest versions, license + and contact details. - http://www.OpenRTOS.com - Commercial support, development, porting, - licensing and training services. -*/ + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool. + Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell + the code with commercial support, indemnification, and middleware, under + the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also + provide a safety engineered and independently SIL3 certified version under + the SafeRTOS brand: http://www.SafeRTOS.com. +*/ +/* Standard includes. */ #include #include #include @@ -61,6 +76,7 @@ all the API functions to use the MPU wrappers. That should only be done when task.h is included from an application file. */ #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE +/* FreeRTOS includes. */ #include "FreeRTOS.h" #include "task.h" #include "timers.h" @@ -69,42 +85,40 @@ task.h is included from an application file. */ #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /* - * Macro to define the amount of stack available to the idle task. + * Defines the size, in words, of the stack allocated to the idle task. */ #define tskIDLE_STACK_SIZE configMINIMAL_STACK_SIZE - -void arduinoTickHook(void); - /* - * Task control block. A task control block (TCB) is allocated to each task, - * and stores the context of the task. + * Task control block. A task control block (TCB) is allocated for each task, + * and stores task state information, including a pointer to the task's context + * (the task's run time environment, including register values) */ typedef struct tskTaskControlBlock { - volatile portSTACK_TYPE *pxTopOfStack; /*< Points to the location of the last item placed on the tasks stack. THIS MUST BE THE FIRST MEMBER OF THE STRUCT. */ + volatile portSTACK_TYPE *pxTopOfStack; /*< Points to the location of the last item placed on the tasks stack. THIS MUST BE THE FIRST MEMBER OF THE TCB STRUCT. */ #if ( portUSING_MPU_WRAPPERS == 1 ) - xMPU_SETTINGS xMPUSettings; /*< The MPU settings are defined as part of the port layer. THIS MUST BE THE SECOND MEMBER OF THE STRUCT. */ - #endif - - xListItem xGenericListItem; /*< List item used to place the TCB in ready and blocked queues. */ - xListItem xEventListItem; /*< List item used to place the TCB in event lists. */ - unsigned portBASE_TYPE uxPriority; /*< The priority of the task where 0 is the lowest priority. */ + xMPU_SETTINGS xMPUSettings; /*< The MPU settings are defined as part of the port layer. THIS MUST BE THE SECOND MEMBER OF THE TCB STRUCT. */ + #endif + + xListItem xGenericListItem; /*< The list that the state list item of a task is reference from denotes the state of that task (Ready, Blocked, Suspended ). */ + xListItem xEventListItem; /*< Used to reference a task from an event list. */ + unsigned portBASE_TYPE uxPriority; /*< The priority of the task. 0 is the lowest priority. */ portSTACK_TYPE *pxStack; /*< Points to the start of the stack. */ signed char pcTaskName[ configMAX_TASK_NAME_LEN ];/*< Descriptive name given to the task when created. Facilitates debugging only. */ #if ( portSTACK_GROWTH > 0 ) - portSTACK_TYPE *pxEndOfStack; /*< Used for stack overflow checking on architectures where the stack grows up from low memory. */ + portSTACK_TYPE *pxEndOfStack; /*< Points to the end of the stack on architectures where the stack grows up from low memory. */ #endif #if ( portCRITICAL_NESTING_IN_TCB == 1 ) - unsigned portBASE_TYPE uxCriticalNesting; + unsigned portBASE_TYPE uxCriticalNesting; /*< Holds the critical section nesting depth for ports that do not maintain their own count in the port layer. */ #endif #if ( configUSE_TRACE_FACILITY == 1 ) - unsigned portBASE_TYPE uxTCBNumber; /*< This stores a number that increments each time a TCB is created. It allows debuggers to determine when a task has been deleted and then recreated. */ - unsigned portBASE_TYPE uxTaskNumber; /*< This stores a number specifically for use by third party trace code. */ + unsigned portBASE_TYPE uxTCBNumber; /*< Stores a number that increments each time a TCB is created. It allows debuggers to determine when a task has been deleted and then recreated. */ + unsigned portBASE_TYPE uxTaskNumber; /*< Stores a number specifically for use by third party trace code. */ #endif #if ( configUSE_MUTEXES == 1 ) @@ -116,15 +130,15 @@ typedef struct tskTaskControlBlock #endif #if ( configGENERATE_RUN_TIME_STATS == 1 ) - unsigned long ulRunTimeCounter; /*< Used for calculating how much CPU time each task is utilising. */ + unsigned long ulRunTimeCounter; /*< Stores the amount of time the task has spent in the Running state. */ #endif } tskTCB; /* - * Some kernel aware debuggers require data to be viewed to be global, rather - * than file scope. + * Some kernel aware debuggers require the data the debugger needs access to to + * be global, rather than file scope. */ #ifdef portREMOVE_STATIC_QUALIFIER #define static @@ -134,7 +148,6 @@ typedef struct tskTaskControlBlock PRIVILEGED_DATA tskTCB * volatile pxCurrentTCB = NULL; /* Lists for ready and blocked tasks. --------------------*/ - PRIVILEGED_DATA static xList pxReadyTasksLists[ configMAX_PRIORITIES ]; /*< Prioritised ready tasks. */ PRIVILEGED_DATA static xList xDelayedTaskList1; /*< Delayed tasks. */ PRIVILEGED_DATA static xList xDelayedTaskList2; /*< Delayed tasks (two lists are used - one for delays that have overflowed the current tick count. */ @@ -156,9 +169,9 @@ PRIVILEGED_DATA static xList xPendingReadyList; /*< Tasks that have been r #endif #if ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) - - PRIVILEGED_DATA static xTaskHandle xIdleTaskHandle = NULL; - + + PRIVILEGED_DATA static xTaskHandle xIdleTaskHandle = NULL; /*< Holds the handle of the idle task. The idle task is created automatically when the scheduler is started. */ + #endif /* File private variables. --------------------------------*/ @@ -171,8 +184,8 @@ PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxSchedulerSuspended = PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxMissedTicks = ( unsigned portBASE_TYPE ) 0U; PRIVILEGED_DATA static volatile portBASE_TYPE xMissedYield = ( portBASE_TYPE ) pdFALSE; PRIVILEGED_DATA static volatile portBASE_TYPE xNumOfOverflows = ( portBASE_TYPE ) 0; -PRIVILEGED_DATA static unsigned portBASE_TYPE uxTCBNumber = ( unsigned portBASE_TYPE ) 0U; -PRIVILEGED_DATA static portTickType xNextTaskUnblockTime = ( portTickType ) portMAX_DELAY; +PRIVILEGED_DATA static unsigned portBASE_TYPE uxTaskNumber = ( unsigned portBASE_TYPE ) 0U; +PRIVILEGED_DATA static volatile portTickType xNextTaskUnblockTime = ( portTickType ) portMAX_DELAY; #if ( configGENERATE_RUN_TIME_STATS == 1 ) @@ -200,6 +213,82 @@ PRIVILEGED_DATA static portTickType xNextTaskUnblockTime = ( portTickType ) /*-----------------------------------------------------------*/ +#if configUSE_PORT_OPTIMISED_TASK_SELECTION == 0 + + /* If configUSE_PORT_OPTIMISED_TASK_SELECTION is 0 then task selection is + performed in a generic way that is not optimised to any particular + microcontroller architecture. */ + + /* uxTopReadyPriority holds the priority of the highest priority ready + state task. */ + #define taskRECORD_READY_PRIORITY( uxPriority ) \ + { \ + if( ( uxPriority ) > uxTopReadyPriority ) \ + { \ + uxTopReadyPriority = ( uxPriority ); \ + } \ + } /* taskRECORD_READY_PRIORITY */ + + /*-----------------------------------------------------------*/ + + #define taskSELECT_HIGHEST_PRIORITY_TASK() \ + { \ + /* Find the highest priority queue that contains ready tasks. */ \ + while( listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxTopReadyPriority ] ) ) ) \ + { \ + configASSERT( uxTopReadyPriority ); \ + --uxTopReadyPriority; \ + } \ + \ + /* listGET_OWNER_OF_NEXT_ENTRY indexes through the list, so the tasks of \ + the same priority get an equal share of the processor time. */ \ + listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopReadyPriority ] ) ); \ + } /* taskSELECT_HIGHEST_PRIORITY_TASK */ + + /*-----------------------------------------------------------*/ + + /* Define away taskRESET_READY_PRIORITY() and portRESET_READY_PRIORITY() as + they are only required when a port optimised method of task selection is + being used. */ + #define taskRESET_READY_PRIORITY( uxPriority ) + #define portRESET_READY_PRIORITY( uxPriority, uxTopReadyPriority ) + +#else /* configUSE_PORT_OPTIMISED_TASK_SELECTION */ + + /* If configUSE_PORT_OPTIMISED_TASK_SELECTION is 1 then task selection is + performed in a way that is tailored to the particular microcontroller + architecture being used. */ + + /* A port optimised version is provided. Call the port defined macros. */ + #define taskRECORD_READY_PRIORITY( uxPriority ) portRECORD_READY_PRIORITY( uxPriority, uxTopReadyPriority ) + + /*-----------------------------------------------------------*/ + + #define taskSELECT_HIGHEST_PRIORITY_TASK() \ + { \ + unsigned portBASE_TYPE uxTopPriority; \ + \ + /* Find the highest priority queue that contains ready tasks. */ \ + portGET_HIGHEST_PRIORITY( uxTopPriority, uxTopReadyPriority ); \ + configASSERT( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ uxTopPriority ] ) ) > 0 ); \ + listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopPriority ] ) ); \ + } /* taskSELECT_HIGHEST_PRIORITY_TASK() */ + + /*-----------------------------------------------------------*/ + + /* A port optimised version is provided, call it only if the TCB being reset + is being referenced from a ready list. If it is referenced from a delayed + or suspended list then it won't be in a ready list. */ + #define taskRESET_READY_PRIORITY( uxPriority ) \ + { \ + if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ ( uxPriority ) ] ) ) == 0 ) \ + { \ + portRESET_READY_PRIORITY( ( uxPriority ), ( uxTopReadyPriority ) ); \ + } \ + } + +#endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */ + /* * Place the task represented by pxTCB into the appropriate ready queue for * the task. It is inserted at the end of the list. One quirk of this is @@ -207,11 +296,9 @@ PRIVILEGED_DATA static portTickType xNextTaskUnblockTime = ( portTickType ) * executing task, then it will only be rescheduled after the currently * executing task has been rescheduled. */ -#define prvAddTaskToReadyQueue( pxTCB ) \ - if( ( pxTCB )->uxPriority > uxTopReadyPriority ) \ - { \ - uxTopReadyPriority = ( pxTCB )->uxPriority; \ - } \ +#define prvAddTaskToReadyQueue( pxTCB ) \ + traceMOVED_TASK_TO_READY_STATE( pxTCB ) \ + taskRECORD_READY_PRIORITY( ( pxTCB )->uxPriority ); \ vListInsertEnd( ( xList * ) &( pxReadyTasksLists[ ( pxTCB )->uxPriority ] ), &( ( pxTCB )->xGenericListItem ) ) /*-----------------------------------------------------------*/ @@ -262,12 +349,12 @@ portTickType xItemValue; \ } \ \ /* It is time to remove the item from the Blocked state. */ \ - vListRemove( &( pxTCB->xGenericListItem ) ); \ + uxListRemove( &( pxTCB->xGenericListItem ) ); \ \ /* Is the task waiting on an event also? */ \ if( pxTCB->xEventListItem.pvContainer != NULL ) \ { \ - vListRemove( &( pxTCB->xEventListItem ) ); \ + uxListRemove( &( pxTCB->xEventListItem ) ); \ } \ prvAddTaskToReadyQueue( pxTCB ); \ } \ @@ -285,9 +372,9 @@ portTickType xItemValue; \ #define prvGetTCBFromHandle( pxHandle ) ( ( ( pxHandle ) == NULL ) ? ( tskTCB * ) pxCurrentTCB : ( tskTCB * ) ( pxHandle ) ) /* Callback function prototypes. --------------------------*/ -extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName ); +extern void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName ); extern void vApplicationTickHook( void ); - + /* File private functions. --------------------------------*/ /* @@ -373,6 +460,20 @@ static tskTCB *prvAllocateTCBAndStack( unsigned short usStackDepth, portSTACK_TY #endif +/* + * Return the amount of time, in ticks, that will pass before the kernel will + * next move a task from the Blocked state to the Running state. + * + * This conditional compilation should use inequality to 0, not equality to 1. + * This is to ensure portSUPPRESS_TICKS_AND_SLEEP() can be called when user + * defined low power mode implementations require configUSE_TICKLESS_IDLE to be + * set to a value other than 1. + */ +#if ( configUSE_TICKLESS_IDLE != 0 ) + + static portTickType prvGetExpectedIdleTime( void ) PRIVILEGED_FUNCTION; + +#endif /*lint +e956 */ @@ -388,7 +489,7 @@ signed portBASE_TYPE xReturn; tskTCB * pxNewTCB; configASSERT( pxTaskCode ); - configASSERT( ( uxPriority < configMAX_PRIORITIES ) ); + configASSERT( ( ( uxPriority & ( ~portPRIVILEGE_BIT ) ) < configMAX_PRIORITIES ) ); /* Allocate the memory required by the TCB and stack for the new task, checking that the allocation was successful. */ @@ -427,7 +528,7 @@ tskTCB * pxNewTCB; #else { pxTopOfStack = pxNewTCB->pxStack; - + /* Check the alignment of the stack buffer is correct. */ configASSERT( ( ( ( unsigned long ) pxNewTCB->pxStack & ( unsigned long ) portBYTE_ALIGNMENT_MASK ) == 0UL ) ); @@ -465,7 +566,7 @@ tskTCB * pxNewTCB; required.*/ *pxCreatedTask = ( xTaskHandle ) pxNewTCB; } - + /* We are going to manipulate the task queues to add this task to a ready list, so must make sure no interrupts occur. */ taskENTER_CRITICAL(); @@ -509,14 +610,15 @@ tskTCB * pxNewTCB; #if ( configUSE_TRACE_FACILITY == 1 ) { /* Add a counter into the TCB for tracing only. */ - pxNewTCB->uxTCBNumber = uxTCBNumber; + pxNewTCB->uxTCBNumber = uxTaskNumber; } #endif - uxTCBNumber++; + uxTaskNumber++; prvAddTaskToReadyQueue( pxNewTCB ); xReturn = pdPASS; + portSETUP_TCB( pxNewTCB ); traceTASK_CREATE( pxNewTCB ); } taskEXIT_CRITICAL(); @@ -566,12 +668,15 @@ tskTCB * pxNewTCB; This will stop the task from be scheduled. The idle task will check the termination list and free up any memory allocated by the scheduler for the TCB and stack. */ - vListRemove( &( pxTCB->xGenericListItem ) ); + if( uxListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) ) == 0 ) + { + taskRESET_READY_PRIORITY( pxTCB->uxPriority ); + } /* Is the task waiting on an event also? */ if( pxTCB->xEventListItem.pvContainer != NULL ) { - vListRemove( &( pxTCB->xEventListItem ) ); + uxListRemove( &( pxTCB->xEventListItem ) ); } vListInsertEnd( ( xList * ) &xTasksWaitingTermination, &( pxTCB->xGenericListItem ) ); @@ -583,7 +688,7 @@ tskTCB * pxNewTCB; /* Increment the uxTaskNumberVariable also so kernel aware debuggers can detect that the task lists need re-generating. */ - uxTCBNumber++; + uxTaskNumber++; traceTASK_DELETE( pxTCB ); } @@ -658,7 +763,14 @@ tskTCB * pxNewTCB; /* We must remove ourselves from the ready list before adding ourselves to the blocked list as the same list item is used for both lists. */ - vListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ); + if( uxListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ) == 0 ) + { + /* The current task must be in a ready list, so there is + no need to check, and the port reset macro can be called + directly. */ + portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority ); + } + prvAddCurrentTaskToDelayedList( xTimeToWake ); } } @@ -704,7 +816,13 @@ tskTCB * pxNewTCB; /* We must remove ourselves from the ready list before adding ourselves to the blocked list as the same list item is used for both lists. */ - vListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ); + if( uxListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ) == 0 ) + { + /* The current task must be in a ready list, so there is + no need to check, and the port reset macro can be called + directly. */ + portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority ); + } prvAddCurrentTaskToDelayedList( xTimeToWake ); } xAlreadyYielded = xTaskResumeAll(); @@ -721,6 +839,68 @@ tskTCB * pxNewTCB; #endif /*-----------------------------------------------------------*/ +#if ( INCLUDE_eTaskStateGet == 1 ) + + eTaskState eTaskStateGet( xTaskHandle pxTask ) + { + eTaskState eReturn; + xList *pxStateList; + tskTCB *pxTCB; + + pxTCB = ( tskTCB * ) pxTask; + + if( pxTCB == pxCurrentTCB ) + { + /* The task calling this function is querying its own state. */ + eReturn = eRunning; + } + else + { + taskENTER_CRITICAL(); + { + pxStateList = ( xList * ) listLIST_ITEM_CONTAINER( &( pxTCB->xGenericListItem ) ); + } + taskEXIT_CRITICAL(); + + if( ( pxStateList == pxDelayedTaskList ) || ( pxStateList == pxOverflowDelayedTaskList ) ) + { + /* The task being queried is referenced from one of the Blocked + lists. */ + eReturn = eBlocked; + } + + #if ( INCLUDE_vTaskSuspend == 1 ) + else if( pxStateList == &xSuspendedTaskList ) + { + /* The task being queried is referenced from the suspended + list. */ + eReturn = eSuspended; + } + #endif + + #if ( INCLUDE_vTaskDelete == 1 ) + else if( pxStateList == &xTasksWaitingTermination ) + { + /* The task being queried is referenced from the deleted + tasks list. */ + eReturn = eDeleted; + } + #endif + + else + { + /* If the task is not in any other state, it must be in the + Ready (including pending ready) state. */ + eReturn = eReady; + } + } + + return eReturn; + } + +#endif +/*-----------------------------------------------------------*/ + #if ( INCLUDE_uxTaskPriorityGet == 1 ) unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask ) @@ -748,7 +928,7 @@ tskTCB * pxNewTCB; void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority ) { tskTCB *pxTCB; - unsigned portBASE_TYPE uxCurrentPriority; + unsigned portBASE_TYPE uxCurrentPriority, uxPriorityUsedOnEntry; portBASE_TYPE xYieldRequired = pdFALSE; configASSERT( ( uxNewPriority < configMAX_PRIORITIES ) ); @@ -804,7 +984,10 @@ tskTCB * pxNewTCB; xYieldRequired = pdTRUE; } - + /* Remember the ready list the task might be referenced from + before its uxPriority member is changed so the + taskRESET_READY_PRIORITY() macro can function correctly. */ + uxPriorityUsedOnEntry = pxTCB->uxPriority; #if ( configUSE_MUTEXES == 1 ) { @@ -835,7 +1018,10 @@ tskTCB * pxNewTCB; /* The task is currently in its ready list - remove before adding it to it's new ready list. As we are in a critical section we can do this even if the scheduler is suspended. */ - vListRemove( &( pxTCB->xGenericListItem ) ); + if( uxListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) ) == 0 ) + { + taskRESET_READY_PRIORITY( uxPriorityUsedOnEntry ); + } prvAddTaskToReadyQueue( pxTCB ); } @@ -846,6 +1032,10 @@ tskTCB * pxNewTCB; } } taskEXIT_CRITICAL(); + + /* Remove compiler warning about unused parameter when the port + optimised task selection is not being used. */ + ( void ) uxPriorityUsedOnEntry; } #endif @@ -872,12 +1062,15 @@ tskTCB * pxNewTCB; traceTASK_SUSPEND( pxTCB ); /* Remove task from the ready/delayed list and place in the suspended list. */ - vListRemove( &( pxTCB->xGenericListItem ) ); + if( uxListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) ) == 0 ) + { + taskRESET_READY_PRIORITY( pxTCB->uxPriority ); + } /* Is the task waiting on an event also? */ if( pxTCB->xEventListItem.pvContainer != NULL ) { - vListRemove( &( pxTCB->xEventListItem ) ); + uxListRemove( &( pxTCB->xEventListItem ) ); } vListInsertEnd( ( xList * ) &xSuspendedTaskList, &( pxTCB->xGenericListItem ) ); @@ -974,7 +1167,7 @@ tskTCB * pxNewTCB; /* As we are in a critical section we can access the ready lists even if the scheduler is suspended. */ - vListRemove( &( pxTCB->xGenericListItem ) ); + uxListRemove( &( pxTCB->xGenericListItem ) ); prvAddTaskToReadyQueue( pxTCB ); /* We may have just resumed a higher priority task. */ @@ -1015,7 +1208,7 @@ tskTCB * pxNewTCB; if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE ) { xYieldRequired = ( pxTCB->uxPriority >= pxCurrentTCB->uxPriority ); - vListRemove( &( pxTCB->xGenericListItem ) ); + uxListRemove( &( pxTCB->xGenericListItem ) ); prvAddTaskToReadyQueue( pxTCB ); } else @@ -1088,7 +1281,7 @@ portBASE_TYPE xReturn; macro must be defined to configure the timer/counter used to generate the run time counter time base. */ portCONFIGURE_TIMER_FOR_RUN_TIME_STATS(); - + /* Setting up the timer tick is hardware specific and thus in the portable interface. */ if( xPortStartScheduler() != pdFALSE ) @@ -1126,6 +1319,34 @@ void vTaskSuspendAll( void ) } /*----------------------------------------------------------*/ +#if ( configUSE_TICKLESS_IDLE != 0 ) + + portTickType prvGetExpectedIdleTime( void ) + { + portTickType xReturn; + + if( pxCurrentTCB->uxPriority > tskIDLE_PRIORITY ) + { + xReturn = 0; + } + else if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ tskIDLE_PRIORITY ] ) ) > 1 ) + { + /* There are other idle priority tasks in the ready state. If + time slicing is used then the very next tick interrupt must be + processed. */ + xReturn = 0; + } + else + { + xReturn = xNextTaskUnblockTime - xTickCount; + } + + return xReturn; + } + +#endif /* configUSE_TICKLESS_IDLE != 0 */ +/*----------------------------------------------------------*/ + signed portBASE_TYPE xTaskResumeAll( void ) { register tskTCB *pxTCB; @@ -1155,8 +1376,8 @@ signed portBASE_TYPE xAlreadyYielded = pdFALSE; while( listLIST_IS_EMPTY( ( xList * ) &xPendingReadyList ) == pdFALSE ) { pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( ( ( xList * ) &xPendingReadyList ) ); - vListRemove( &( pxTCB->xEventListItem ) ); - vListRemove( &( pxTCB->xGenericListItem ) ); + uxListRemove( &( pxTCB->xEventListItem ) ); + uxListRemove( &( pxTCB->xGenericListItem ) ); prvAddTaskToReadyQueue( pxTCB ); /* If we have moved a task that has a priority higher than @@ -1348,7 +1569,7 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void ) /* Divide ulTotalRunTime by 100 to make the percentage caluclations simpler in the prvGenerateRunTimeStatsForTasksInList() function. */ ulTotalRunTime /= 100UL; - + /* Run through all the lists that could potentially contain a TCB, generating a table of run timer percentages in the provided buffer. */ @@ -1411,7 +1632,22 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void ) configASSERT( ( xIdleTaskHandle != NULL ) ); return xIdleTaskHandle; } - + +#endif +/*----------------------------------------------------------*/ + +/* This conditional compilation should use inequality to 0, not equality to 1. +This is to ensure vTaskStepTick() is available when user defined low power mode +implementations require configUSE_TICKLESS_IDLE to be set to a value other than +1. */ +#if ( configUSE_TICKLESS_IDLE != 0 ) + + void vTaskStepTick( portTickType xTicksToJump ) + { + configASSERT( xTicksToJump <= xNextTaskUnblockTime ); + xTickCount += xTicksToJump; + } + #endif /*----------------------------------------------------------- @@ -1426,6 +1662,7 @@ tskTCB * pxTCB; /* Called by the portable layer each time a tick interrupt occurs. Increments the tick then checks to see if the new tick value will cause any tasks to be unblocked. */ + traceTASK_INCREMENT_TICK( xTickCount ); if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE ) { ++xTickCount; @@ -1437,17 +1674,17 @@ tskTCB * pxTCB; If there are any items in pxDelayedTaskList here then there is an error! */ configASSERT( ( listLIST_IS_EMPTY( pxDelayedTaskList ) ) ); - + pxTemp = pxDelayedTaskList; pxDelayedTaskList = pxOverflowDelayedTaskList; pxOverflowDelayedTaskList = pxTemp; xNumOfOverflows++; - + if( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE ) { /* The new current delayed list is empty. Set xNextTaskUnblockTime to the maximum possible value so it is - extremely unlikely that the + extremely unlikely that the if( xTickCount >= xNextTaskUnblockTime ) test will pass until there is an item in the delayed list. */ xNextTaskUnblockTime = portMAX_DELAY; @@ -1469,7 +1706,6 @@ tskTCB * pxTCB; else { ++uxMissedTicks; - arduinoTickHook(); /* The tick hook gets called at regular intervals, even if the scheduler is locked. */ @@ -1480,17 +1716,16 @@ tskTCB * pxTCB; #endif } - /* Guard against the tick hook being called when the missed tick - count is being unwound (when the scheduler is being unlocked. */ - if( uxMissedTicks == ( unsigned portBASE_TYPE ) 0U ) - { - arduinoTickHook(); #if ( configUSE_TICK_HOOK == 1 ) - vApplicationTickHook(); - #endif + { + /* Guard against the tick hook being called when the missed tick + count is being unwound (when the scheduler is being unlocked. */ + if( uxMissedTicks == ( unsigned portBASE_TYPE ) 0U ) + { + vApplicationTickHook(); + } } - - traceTASK_INCREMENT_TICK( xTickCount ); + #endif } /*-----------------------------------------------------------*/ @@ -1592,17 +1827,17 @@ void vTaskSwitchContext( void ) else { traceTASK_SWITCHED_OUT(); - + #if ( configGENERATE_RUN_TIME_STATS == 1 ) { unsigned long ulTempCounter; - + #ifdef portALT_GET_RUN_TIME_COUNTER_VALUE portALT_GET_RUN_TIME_COUNTER_VALUE( ulTempCounter ); #else ulTempCounter = portGET_RUN_TIME_COUNTER_VALUE(); #endif - + /* Add the amount of time the task has been running to the accumulated time so far. The time the task started running was stored in ulTaskSwitchedInTime. Note that there is no overflow protection here @@ -1612,21 +1847,12 @@ void vTaskSwitchContext( void ) ulTaskSwitchedInTime = ulTempCounter; } #endif - + taskFIRST_CHECK_FOR_STACK_OVERFLOW(); taskSECOND_CHECK_FOR_STACK_OVERFLOW(); - - /* Find the highest priority queue that contains ready tasks. */ - while( listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxTopReadyPriority ] ) ) ) - { - configASSERT( uxTopReadyPriority ); - --uxTopReadyPriority; - } - - /* listGET_OWNER_OF_NEXT_ENTRY walks through the list, so the tasks of the - same priority get an equal share of the processor time. */ - listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopReadyPriority ] ) ); - + + taskSELECT_HIGHEST_PRIORITY_TASK(); + traceTASK_SWITCHED_IN(); } } @@ -1649,8 +1875,12 @@ portTickType xTimeToWake; /* We must remove ourselves from the ready list before adding ourselves to the blocked list as the same list item is used for both lists. We have exclusive access to the ready lists as the scheduler is locked. */ - vListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ); - + if( uxListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ) == 0 ) + { + /* The current task must be in a ready list, so there is no need to + check, and the port reset macro can be called directly. */ + portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority ); + } #if ( INCLUDE_vTaskSuspend == 1 ) { @@ -1693,7 +1923,7 @@ portTickType xTimeToWake; designed for use by kernel code, and has special calling requirements - it should be called from a critical section. */ - + /* Place the event list item of the TCB in the appropriate event list. In this case it is assume that this is the only task that is going to be waiting on this event list, so the faster vListInsertEnd() function @@ -1703,14 +1933,21 @@ portTickType xTimeToWake; /* We must remove this task from the ready list before adding it to the blocked list as the same list item is used for both lists. This function is called form a critical section. */ - vListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ); + if( uxListRemove( ( xListItem * ) &( pxCurrentTCB->xGenericListItem ) ) == 0 ) + { + /* The current task must be in a ready list, so there is no need to + check, and the port reset macro can be called directly. */ + portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority ); + } /* Calculate the time at which the task should be woken if the event does not occur. This may overflow but this doesn't matter. */ xTimeToWake = xTickCount + xTicksToWait; + + traceTASK_DELAY_UNTIL(); prvAddCurrentTaskToDelayedList( xTimeToWake ); } - + #endif /* configUSE_TIMERS */ /*-----------------------------------------------------------*/ @@ -1729,16 +1966,16 @@ portBASE_TYPE xReturn; If an event is for a queue that is locked then this function will never get called - the lock count on the queue will get modified instead. This means we can always expect exclusive access to the event list here. - + This function assumes that a check has already been made to ensure that pxEventList is not empty. */ pxUnblockedTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList ); configASSERT( pxUnblockedTCB ); - vListRemove( &( pxUnblockedTCB->xEventListItem ) ); + uxListRemove( &( pxUnblockedTCB->xEventListItem ) ); if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE ) { - vListRemove( &( pxUnblockedTCB->xGenericListItem ) ); + uxListRemove( &( pxUnblockedTCB->xGenericListItem ) ); prvAddTaskToReadyQueue( pxUnblockedTCB ); } else @@ -1830,7 +2067,7 @@ void vTaskMissedYield( void ) { unsigned portBASE_TYPE uxReturn; tskTCB *pxTCB; - + if( xTask != NULL ) { pxTCB = ( tskTCB * ) xTask; @@ -1840,7 +2077,7 @@ void vTaskMissedYield( void ) { uxReturn = 0U; } - + return uxReturn; } #endif @@ -1850,7 +2087,7 @@ void vTaskMissedYield( void ) void vTaskSetTaskNumber( xTaskHandle xTask, unsigned portBASE_TYPE uxHandle ) { tskTCB *pxTCB; - + if( xTask != NULL ) { pxTCB = ( tskTCB * ) xTask; @@ -1921,6 +2158,47 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters ) vApplicationIdleHook(); } #endif + + /* This conditional compilation should use inequality to 0, not equality + to 1. This is to ensure portSUPPRESS_TICKS_AND_SLEEP() is called when + user defined low power mode implementations require + configUSE_TICKLESS_IDLE to be set to a value other than 1. */ + #if ( configUSE_TICKLESS_IDLE != 0 ) + { + portTickType xExpectedIdleTime; + /* If the expected idle time is 1 then the idle time would end at + the end of the current time slice. The idle time must be at least + 2 to ensure any pended ticks between this point and the tick being + stopped can be legitimately stepped over when the tick suppression + routines returns. */ + const portTickType xMinimumExpectedIdleTime = ( portTickType ) 2; + + /* It is not desirable to suspend then resume the scheduler on + each iteration of the idle task. Therefore, a preliminary + test of the expected idle time is performed without the + scheduler suspended. The result here is not necessarily + valid. */ + xExpectedIdleTime = prvGetExpectedIdleTime(); + + if( xExpectedIdleTime >= xMinimumExpectedIdleTime ) + { + vTaskSuspendAll(); + { + /* Now the scheduler is suspended, the expected idle + time can be sampled again, and this time its value can + be used. */ + configASSERT( xNextTaskUnblockTime >= xTickCount ); + xExpectedIdleTime = prvGetExpectedIdleTime(); + + if( xExpectedIdleTime >= xMinimumExpectedIdleTime ) + { + portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime ); + } + } + xTaskResumeAll(); + } + } + #endif } } /*lint !e715 pvParameters is not accessed but all task functions require the same prototype. */ @@ -2008,7 +2286,7 @@ static void prvInitialiseTCBVariables( tskTCB *pxTCB, const signed char * const void vTaskAllocateMPURegions( xTaskHandle xTaskToModify, const xMemoryRegion * const xRegions ) { tskTCB *pxTCB; - + if( xTaskToModify == pxCurrentTCB ) { xTaskToModify = NULL; @@ -2062,7 +2340,7 @@ static void prvCheckTasksWaitingTermination( void ) /* ucTasksDeleted is used to prevent vTaskSuspendAll() being called too often in the idle task. */ - if( uxTasksDeleted > ( unsigned portBASE_TYPE ) 0U ) + while( uxTasksDeleted > ( unsigned portBASE_TYPE ) 0U ) { vTaskSuspendAll(); xListIsEmpty = listLIST_IS_EMPTY( &xTasksWaitingTermination ); @@ -2075,7 +2353,7 @@ static void prvCheckTasksWaitingTermination( void ) taskENTER_CRITICAL(); { pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( ( ( xList * ) &xTasksWaitingTermination ) ); - vListRemove( &( pxTCB->xGenericListItem ) ); + uxListRemove( &( pxTCB->xGenericListItem ) ); --uxCurrentNumberOfTasks; --uxTasksDeleted; } @@ -2153,7 +2431,7 @@ tskTCB *pxNewTCB; { volatile tskTCB *pxNextTCB, *pxFirstTCB; unsigned short usStackRemaining; - PRIVILEGED_DATA static char pcStatusString[ 50 ]; + PRIVILEGED_DATA static char pcStatusString[ configMAX_TASK_NAME_LEN + 30 ]; /* Write the details of all the TCB's in pxList into the buffer. */ listGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, pxList ); @@ -2168,8 +2446,8 @@ tskTCB *pxNewTCB; { usStackRemaining = usTaskCheckFreeStackSpace( ( unsigned char * ) pxNextTCB->pxStack ); } - #endif - + #endif + sprintf( pcStatusString, ( char * ) "%s\t\t%c\t%u\t%u\t%u\r\n", pxNextTCB->pcTaskName, cStatus, ( unsigned int ) pxNextTCB->uxPriority, usStackRemaining, ( unsigned int ) pxNextTCB->uxTCBNumber ); strcat( ( char * ) pcWriteBuffer, ( char * ) pcStatusString ); @@ -2213,7 +2491,7 @@ tskTCB *pxNewTCB; { #ifdef portLU_PRINTF_SPECIFIER_REQUIRED { - sprintf( pcStatsString, ( char * ) "%s\t\t%lu\t\t%lu%%\r\n", pxNextTCB->pcTaskName, pxNextTCB->ulRunTimeCounter, ulStatsAsPercentage ); + sprintf( pcStatsString, ( char * ) "%s\t\t%lu\t\t%lu%%\r\n", pxNextTCB->pcTaskName, pxNextTCB->ulRunTimeCounter, ulStatsAsPercentage ); } #else { @@ -2229,7 +2507,7 @@ tskTCB *pxNewTCB; consumed less than 1% of the total run time. */ #ifdef portLU_PRINTF_SPECIFIER_REQUIRED { - sprintf( pcStatsString, ( char * ) "%s\t\t%lu\t\t<1%%\r\n", pxNextTCB->pcTaskName, pxNextTCB->ulRunTimeCounter ); + sprintf( pcStatsString, ( char * ) "%s\t\t%lu\t\t<1%%\r\n", pxNextTCB->pcTaskName, pxNextTCB->ulRunTimeCounter ); } #else { @@ -2303,7 +2581,8 @@ tskTCB *pxNewTCB; static void prvDeleteTCB( tskTCB *pxTCB ) { /* This call is required specifically for the TriCore port. It must be - above the vPortFree() calls. */ + above the vPortFree() calls. The call is also used by ports/demos that + want to allocate and clean RAM statically. */ portCLEAN_UP_TCB( pxTCB ); /* Free up the memory allocated by the scheduler for the task. It is up to @@ -2369,30 +2648,36 @@ tskTCB *pxNewTCB; { tskTCB * const pxTCB = ( tskTCB * ) pxMutexHolder; - configASSERT( pxMutexHolder ); - - if( pxTCB->uxPriority < pxCurrentTCB->uxPriority ) + /* If the mutex was given back by an interrupt while the queue was + locked then the mutex holder might now be NULL. */ + if( pxMutexHolder != NULL ) { - /* Adjust the mutex holder state to account for its new priority. */ - listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), configMAX_PRIORITIES - ( portTickType ) pxCurrentTCB->uxPriority ); - - /* If the task being modified is in the ready state it will need to - be moved in to a new list. */ - if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ pxTCB->uxPriority ] ), &( pxTCB->xGenericListItem ) ) != pdFALSE ) + if( pxTCB->uxPriority < pxCurrentTCB->uxPriority ) { - vListRemove( &( pxTCB->xGenericListItem ) ); + /* Adjust the mutex holder state to account for its new priority. */ + listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), configMAX_PRIORITIES - ( portTickType ) pxCurrentTCB->uxPriority ); - /* Inherit the priority before being moved into the new list. */ - pxTCB->uxPriority = pxCurrentTCB->uxPriority; - prvAddTaskToReadyQueue( pxTCB ); - } - else - { - /* Just inherit the priority. */ - pxTCB->uxPriority = pxCurrentTCB->uxPriority; - } + /* If the task being modified is in the ready state it will need to + be moved into a new list. */ + if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ pxTCB->uxPriority ] ), &( pxTCB->xGenericListItem ) ) != pdFALSE ) + { + if( uxListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) ) == 0 ) + { + taskRESET_READY_PRIORITY( pxTCB->uxPriority ); + } - traceTASK_PRIORITY_INHERIT( pxTCB, pxCurrentTCB->uxPriority ); + /* Inherit the priority before being moved into the new list. */ + pxTCB->uxPriority = pxCurrentTCB->uxPriority; + prvAddTaskToReadyQueue( pxTCB ); + } + else + { + /* Just inherit the priority. */ + pxTCB->uxPriority = pxCurrentTCB->uxPriority; + } + + traceTASK_PRIORITY_INHERIT( pxTCB, pxCurrentTCB->uxPriority ); + } } } @@ -2411,7 +2696,10 @@ tskTCB *pxNewTCB; { /* We must be the running task to be able to give the mutex back. Remove ourselves from the ready list we currently appear in. */ - vListRemove( &( pxTCB->xGenericListItem ) ); + if( uxListRemove( ( xListItem * ) &( pxTCB->xGenericListItem ) ) == 0 ) + { + taskRESET_READY_PRIORITY( pxTCB->uxPriority ); + } /* Disinherit the priority before adding the task into the new ready list. */ @@ -2443,21 +2731,21 @@ tskTCB *pxNewTCB; #if ( portCRITICAL_NESTING_IN_TCB == 1 ) -void vTaskExitCritical( void ) -{ - if( xSchedulerRunning != pdFALSE ) + void vTaskExitCritical( void ) { - if( pxCurrentTCB->uxCriticalNesting > 0U ) + if( xSchedulerRunning != pdFALSE ) { - ( pxCurrentTCB->uxCriticalNesting )--; - - if( pxCurrentTCB->uxCriticalNesting == 0U ) + if( pxCurrentTCB->uxCriticalNesting > 0U ) { - portENABLE_INTERRUPTS(); + ( pxCurrentTCB->uxCriticalNesting )--; + + if( pxCurrentTCB->uxCriticalNesting == 0U ) + { + portENABLE_INTERRUPTS(); + } } } } -} #endif /*-----------------------------------------------------------*/ diff --git a/arduino.DuinOS.AVR/DuinOS/timers.c b/arduino.DuinOS.AVR/DuinOS/timers.c new file mode 100644 index 0000000..d910505 --- /dev/null +++ b/arduino.DuinOS.AVR/DuinOS/timers.c @@ -0,0 +1,688 @@ +/* + FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. + + *************************************************************************** + * * + * FreeRTOS tutorial books are available in pdf and paperback. * + * Complete, revised, and edited pdf reference manuals are also * + * available. * + * * + * Purchasing FreeRTOS documentation will not only help you, by * + * ensuring you get running as quickly as possible and with an * + * in-depth knowledge of how to use FreeRTOS, it will also help * + * the FreeRTOS project to continue with its mission of providing * + * professional grade, cross platform, de facto standard solutions * + * for microcontrollers - completely free of charge! * + * * + * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * + * * + * Thank you for using FreeRTOS, and thank you for your support! * + * * + *************************************************************************** + + + This file is part of the FreeRTOS distribution. + + FreeRTOS is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License (version 2) as published by the + Free Software Foundation AND MODIFIED BY the FreeRTOS exception. + >>>NOTE<<< The modification to the GPL is included to allow you to + distribute a combined work that includes FreeRTOS without being obliged to + provide the source code for proprietary components outside of the FreeRTOS + kernel. FreeRTOS is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. You should have received a copy of the GNU General Public + License and the FreeRTOS license exception along with FreeRTOS; if not it + can be viewed here: http://www.freertos.org/a00114.html and also obtained + by writing to Richard Barry, contact details for whom are available on the + FreeRTOS WEB site. + + 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** + + + http://www.FreeRTOS.org - Documentation, training, latest versions, license + and contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool. + + Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell + the code with commercial support, indemnification, and middleware, under + the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also + provide a safety engineered and independently SIL3 certified version under + the SafeRTOS brand: http://www.SafeRTOS.com. +*/ + +/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining +all the API functions to use the MPU wrappers. That should only be done when +task.h is included from an application file. */ +#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +#include "FreeRTOS.h" +#include "task.h" +#include "queue.h" +#include "timers.h" + +#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +/* This entire source file will be skipped if the application is not configured +to include software timer functionality. This #if is closed at the very bottom +of this file. If you want to include software timer functionality then ensure +configUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */ +#if ( configUSE_TIMERS == 1 ) + +/* Misc definitions. */ +#define tmrNO_DELAY ( portTickType ) 0U + +/* The definition of the timers themselves. */ +typedef struct tmrTimerControl +{ + const signed char *pcTimerName; /*<< Text name. This is not used by the kernel, it is included simply to make debugging easier. */ + xListItem xTimerListItem; /*<< Standard linked list item as used by all kernel features for event management. */ + portTickType xTimerPeriodInTicks;/*<< How quickly and often the timer expires. */ + unsigned portBASE_TYPE uxAutoReload; /*<< Set to pdTRUE if the timer should be automatically restarted once expired. Set to pdFALSE if the timer is, in effect, a one shot timer. */ + void *pvTimerID; /*<< An ID to identify the timer. This allows the timer to be identified when the same callback is used for multiple timers. */ + tmrTIMER_CALLBACK pxCallbackFunction; /*<< The function that will be called when the timer expires. */ +} xTIMER; + +/* The definition of messages that can be sent and received on the timer +queue. */ +typedef struct tmrTimerQueueMessage +{ + portBASE_TYPE xMessageID; /*<< The command being sent to the timer service task. */ + portTickType xMessageValue; /*<< An optional value used by a subset of commands, for example, when changing the period of a timer. */ + xTIMER * pxTimer; /*<< The timer to which the command will be applied. */ +} xTIMER_MESSAGE; + + +/* The list in which active timers are stored. Timers are referenced in expire +time order, with the nearest expiry time at the front of the list. Only the +timer service task is allowed to access xActiveTimerList. */ +PRIVILEGED_DATA static xList xActiveTimerList1; +PRIVILEGED_DATA static xList xActiveTimerList2; +PRIVILEGED_DATA static xList *pxCurrentTimerList; +PRIVILEGED_DATA static xList *pxOverflowTimerList; + +/* A queue that is used to send commands to the timer service task. */ +PRIVILEGED_DATA static xQueueHandle xTimerQueue = NULL; + +#if ( INCLUDE_xTimerGetTimerDaemonTaskHandle == 1 ) + + PRIVILEGED_DATA static xTaskHandle xTimerTaskHandle = NULL; + +#endif + +/*-----------------------------------------------------------*/ + +/* + * Initialise the infrastructure used by the timer service task if it has not + * been initialised already. + */ +static void prvCheckForValidListAndQueue( void ) PRIVILEGED_FUNCTION; + +/* + * The timer service task (daemon). Timer functionality is controlled by this + * task. Other tasks communicate with the timer service task using the + * xTimerQueue queue. + */ +static void prvTimerTask( void *pvParameters ) PRIVILEGED_FUNCTION; + +/* + * Called by the timer service task to interpret and process a command it + * received on the timer queue. + */ +static void prvProcessReceivedCommands( void ) PRIVILEGED_FUNCTION; + +/* + * Insert the timer into either xActiveTimerList1, or xActiveTimerList2, + * depending on if the expire time causes a timer counter overflow. + */ +static portBASE_TYPE prvInsertTimerInActiveList( xTIMER *pxTimer, portTickType xNextExpiryTime, portTickType xTimeNow, portTickType xCommandTime ) PRIVILEGED_FUNCTION; + +/* + * An active timer has reached its expire time. Reload the timer if it is an + * auto reload timer, then call its callback. + */ +static void prvProcessExpiredTimer( portTickType xNextExpireTime, portTickType xTimeNow ) PRIVILEGED_FUNCTION; + +/* + * The tick count has overflowed. Switch the timer lists after ensuring the + * current timer list does not still reference some timers. + */ +static void prvSwitchTimerLists( portTickType xLastTime ) PRIVILEGED_FUNCTION; + +/* + * Obtain the current tick count, setting *pxTimerListsWereSwitched to pdTRUE + * if a tick count overflow occurred since prvSampleTimeNow() was last called. + */ +static portTickType prvSampleTimeNow( portBASE_TYPE *pxTimerListsWereSwitched ) PRIVILEGED_FUNCTION; + +/* + * If the timer list contains any active timers then return the expire time of + * the timer that will expire first and set *pxListWasEmpty to false. If the + * timer list does not contain any timers then return 0 and set *pxListWasEmpty + * to pdTRUE. + */ +static portTickType prvGetNextExpireTime( portBASE_TYPE *pxListWasEmpty ) PRIVILEGED_FUNCTION; + +/* + * If a timer has expired, process it. Otherwise, block the timer service task + * until either a timer does expire or a command is received. + */ +static void prvProcessTimerOrBlockTask( portTickType xNextExpireTime, portBASE_TYPE xListWasEmpty ) PRIVILEGED_FUNCTION; + +/*-----------------------------------------------------------*/ + +portBASE_TYPE xTimerCreateTimerTask( void ) +{ +portBASE_TYPE xReturn = pdFAIL; + + /* This function is called when the scheduler is started if + configUSE_TIMERS is set to 1. Check that the infrastructure used by the + timer service task has been created/initialised. If timers have already + been created then the initialisation will already have been performed. */ + prvCheckForValidListAndQueue(); + + if( xTimerQueue != NULL ) + { + #if ( INCLUDE_xTimerGetTimerDaemonTaskHandle == 1 ) + { + /* Create the timer task, storing its handle in xTimerTaskHandle so + it can be returned by the xTimerGetTimerDaemonTaskHandle() function. */ + xReturn = xTaskCreate( prvTimerTask, ( const signed char * ) "Tmr Svc", ( unsigned short ) configTIMER_TASK_STACK_DEPTH, NULL, ( ( unsigned portBASE_TYPE ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT, &xTimerTaskHandle ); + } + #else + { + /* Create the timer task without storing its handle. */ + xReturn = xTaskCreate( prvTimerTask, ( const signed char * ) "Tmr Svc", ( unsigned short ) configTIMER_TASK_STACK_DEPTH, NULL, ( ( unsigned portBASE_TYPE ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT, NULL); + } + #endif + } + + configASSERT( xReturn ); + return xReturn; +} +/*-----------------------------------------------------------*/ + +xTimerHandle xTimerCreate( const signed char *pcTimerName, portTickType xTimerPeriodInTicks, unsigned portBASE_TYPE uxAutoReload, void *pvTimerID, tmrTIMER_CALLBACK pxCallbackFunction ) +{ +xTIMER *pxNewTimer; + + /* Allocate the timer structure. */ + if( xTimerPeriodInTicks == ( portTickType ) 0U ) + { + pxNewTimer = NULL; + configASSERT( ( xTimerPeriodInTicks > 0 ) ); + } + else + { + pxNewTimer = ( xTIMER * ) pvPortMalloc( sizeof( xTIMER ) ); + if( pxNewTimer != NULL ) + { + /* Ensure the infrastructure used by the timer service task has been + created/initialised. */ + prvCheckForValidListAndQueue(); + + /* Initialise the timer structure members using the function parameters. */ + pxNewTimer->pcTimerName = pcTimerName; + pxNewTimer->xTimerPeriodInTicks = xTimerPeriodInTicks; + pxNewTimer->uxAutoReload = uxAutoReload; + pxNewTimer->pvTimerID = pvTimerID; + pxNewTimer->pxCallbackFunction = pxCallbackFunction; + vListInitialiseItem( &( pxNewTimer->xTimerListItem ) ); + + traceTIMER_CREATE( pxNewTimer ); + } + else + { + traceTIMER_CREATE_FAILED(); + } + } + + return ( xTimerHandle ) pxNewTimer; +} +/*-----------------------------------------------------------*/ + +portBASE_TYPE xTimerGenericCommand( xTimerHandle xTimer, portBASE_TYPE xCommandID, portTickType xOptionalValue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portTickType xBlockTime ) +{ +portBASE_TYPE xReturn = pdFAIL; +xTIMER_MESSAGE xMessage; + + /* Send a message to the timer service task to perform a particular action + on a particular timer definition. */ + if( xTimerQueue != NULL ) + { + /* Send a command to the timer service task to start the xTimer timer. */ + xMessage.xMessageID = xCommandID; + xMessage.xMessageValue = xOptionalValue; + xMessage.pxTimer = ( xTIMER * ) xTimer; + + if( pxHigherPriorityTaskWoken == NULL ) + { + if( xTaskGetSchedulerState() == taskSCHEDULER_RUNNING ) + { + xReturn = xQueueSendToBack( xTimerQueue, &xMessage, xBlockTime ); + } + else + { + xReturn = xQueueSendToBack( xTimerQueue, &xMessage, tmrNO_DELAY ); + } + } + else + { + xReturn = xQueueSendToBackFromISR( xTimerQueue, &xMessage, pxHigherPriorityTaskWoken ); + } + + traceTIMER_COMMAND_SEND( xTimer, xCommandID, xOptionalValue, xReturn ); + } + + return xReturn; +} +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_xTimerGetTimerDaemonTaskHandle == 1 ) + + xTaskHandle xTimerGetTimerDaemonTaskHandle( void ) + { + /* If xTimerGetTimerDaemonTaskHandle() is called before the scheduler has been + started, then xTimerTaskHandle will be NULL. */ + configASSERT( ( xTimerTaskHandle != NULL ) ); + return xTimerTaskHandle; + } + +#endif +/*-----------------------------------------------------------*/ + +static void prvProcessExpiredTimer( portTickType xNextExpireTime, portTickType xTimeNow ) +{ +xTIMER *pxTimer; +portBASE_TYPE xResult; + + /* Remove the timer from the list of active timers. A check has already + been performed to ensure the list is not empty. */ + pxTimer = ( xTIMER * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList ); + uxListRemove( &( pxTimer->xTimerListItem ) ); + traceTIMER_EXPIRED( pxTimer ); + + /* If the timer is an auto reload timer then calculate the next + expiry time and re-insert the timer in the list of active timers. */ + if( pxTimer->uxAutoReload == ( unsigned portBASE_TYPE ) pdTRUE ) + { + /* This is the only time a timer is inserted into a list using + a time relative to anything other than the current time. It + will therefore be inserted into the correct list relative to + the time this task thinks it is now, even if a command to + switch lists due to a tick count overflow is already waiting in + the timer queue. */ + if( prvInsertTimerInActiveList( pxTimer, ( xNextExpireTime + pxTimer->xTimerPeriodInTicks ), xTimeNow, xNextExpireTime ) == pdTRUE ) + { + /* The timer expired before it was added to the active timer + list. Reload it now. */ + xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START, xNextExpireTime, NULL, tmrNO_DELAY ); + configASSERT( xResult ); + ( void ) xResult; + } + } + + /* Call the timer callback. */ + pxTimer->pxCallbackFunction( ( xTimerHandle ) pxTimer ); +} +/*-----------------------------------------------------------*/ + +static void prvTimerTask( void *pvParameters ) +{ +portTickType xNextExpireTime; +portBASE_TYPE xListWasEmpty; + + /* Just to avoid compiler warnings. */ + ( void ) pvParameters; + + for( ;; ) + { + /* Query the timers list to see if it contains any timers, and if so, + obtain the time at which the next timer will expire. */ + xNextExpireTime = prvGetNextExpireTime( &xListWasEmpty ); + + /* If a timer has expired, process it. Otherwise, block this task + until either a timer does expire, or a command is received. */ + prvProcessTimerOrBlockTask( xNextExpireTime, xListWasEmpty ); + + /* Empty the command queue. */ + prvProcessReceivedCommands(); + } +} +/*-----------------------------------------------------------*/ + +static void prvProcessTimerOrBlockTask( portTickType xNextExpireTime, portBASE_TYPE xListWasEmpty ) +{ +portTickType xTimeNow; +portBASE_TYPE xTimerListsWereSwitched; + + vTaskSuspendAll(); + { + /* Obtain the time now to make an assessment as to whether the timer + has expired or not. If obtaining the time causes the lists to switch + then don't process this timer as any timers that remained in the list + when the lists were switched will have been processed within the + prvSampelTimeNow() function. */ + xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched ); + if( xTimerListsWereSwitched == pdFALSE ) + { + /* The tick count has not overflowed, has the timer expired? */ + if( ( xListWasEmpty == pdFALSE ) && ( xNextExpireTime <= xTimeNow ) ) + { + xTaskResumeAll(); + prvProcessExpiredTimer( xNextExpireTime, xTimeNow ); + } + else + { + /* The tick count has not overflowed, and the next expire + time has not been reached yet. This task should therefore + block to wait for the next expire time or a command to be + received - whichever comes first. The following line cannot + be reached unless xNextExpireTime > xTimeNow, except in the + case when the current timer list is empty. */ + vQueueWaitForMessageRestricted( xTimerQueue, ( xNextExpireTime - xTimeNow ) ); + + if( xTaskResumeAll() == pdFALSE ) + { + /* Yield to wait for either a command to arrive, or the block time + to expire. If a command arrived between the critical section being + exited and this yield then the yield will not cause the task + to block. */ + portYIELD_WITHIN_API(); + } + } + } + else + { + xTaskResumeAll(); + } + } +} +/*-----------------------------------------------------------*/ + +static portTickType prvGetNextExpireTime( portBASE_TYPE *pxListWasEmpty ) +{ +portTickType xNextExpireTime; + + /* Timers are listed in expiry time order, with the head of the list + referencing the task that will expire first. Obtain the time at which + the timer with the nearest expiry time will expire. If there are no + active timers then just set the next expire time to 0. That will cause + this task to unblock when the tick count overflows, at which point the + timer lists will be switched and the next expiry time can be + re-assessed. */ + *pxListWasEmpty = listLIST_IS_EMPTY( pxCurrentTimerList ); + if( *pxListWasEmpty == pdFALSE ) + { + xNextExpireTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxCurrentTimerList ); + } + else + { + /* Ensure the task unblocks when the tick count rolls over. */ + xNextExpireTime = ( portTickType ) 0U; + } + + return xNextExpireTime; +} +/*-----------------------------------------------------------*/ + +static portTickType prvSampleTimeNow( portBASE_TYPE *pxTimerListsWereSwitched ) +{ +portTickType xTimeNow; +PRIVILEGED_DATA static portTickType xLastTime = ( portTickType ) 0U; + + xTimeNow = xTaskGetTickCount(); + + if( xTimeNow < xLastTime ) + { + prvSwitchTimerLists( xLastTime ); + *pxTimerListsWereSwitched = pdTRUE; + } + else + { + *pxTimerListsWereSwitched = pdFALSE; + } + + xLastTime = xTimeNow; + + return xTimeNow; +} +/*-----------------------------------------------------------*/ + +static portBASE_TYPE prvInsertTimerInActiveList( xTIMER *pxTimer, portTickType xNextExpiryTime, portTickType xTimeNow, portTickType xCommandTime ) +{ +portBASE_TYPE xProcessTimerNow = pdFALSE; + + listSET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ), xNextExpiryTime ); + listSET_LIST_ITEM_OWNER( &( pxTimer->xTimerListItem ), pxTimer ); + + if( xNextExpiryTime <= xTimeNow ) + { + /* Has the expiry time elapsed between the command to start/reset a + timer was issued, and the time the command was processed? */ + if( ( ( portTickType ) ( xTimeNow - xCommandTime ) ) >= pxTimer->xTimerPeriodInTicks ) + { + /* The time between a command being issued and the command being + processed actually exceeds the timers period. */ + xProcessTimerNow = pdTRUE; + } + else + { + vListInsert( pxOverflowTimerList, &( pxTimer->xTimerListItem ) ); + } + } + else + { + if( ( xTimeNow < xCommandTime ) && ( xNextExpiryTime >= xCommandTime ) ) + { + /* If, since the command was issued, the tick count has overflowed + but the expiry time has not, then the timer must have already passed + its expiry time and should be processed immediately. */ + xProcessTimerNow = pdTRUE; + } + else + { + vListInsert( pxCurrentTimerList, &( pxTimer->xTimerListItem ) ); + } + } + + return xProcessTimerNow; +} +/*-----------------------------------------------------------*/ + +static void prvProcessReceivedCommands( void ) +{ +xTIMER_MESSAGE xMessage; +xTIMER *pxTimer; +portBASE_TYPE xTimerListsWereSwitched, xResult; +portTickType xTimeNow; + + /* In this case the xTimerListsWereSwitched parameter is not used, but it + must be present in the function call. */ + xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched ); + + while( xQueueReceive( xTimerQueue, &xMessage, tmrNO_DELAY ) != pdFAIL ) + { + pxTimer = xMessage.pxTimer; + + /* Is the timer already in a list of active timers? When the command + is trmCOMMAND_PROCESS_TIMER_OVERFLOW, the timer will be NULL as the + command is to the task rather than to an individual timer. */ + if( pxTimer != NULL ) + { + if( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) == pdFALSE ) + { + /* The timer is in a list, remove it. */ + uxListRemove( &( pxTimer->xTimerListItem ) ); + } + } + + traceTIMER_COMMAND_RECEIVED( pxTimer, xMessage.xMessageID, xMessage.xMessageValue ); + + switch( xMessage.xMessageID ) + { + case tmrCOMMAND_START : + /* Start or restart a timer. */ + if( prvInsertTimerInActiveList( pxTimer, xMessage.xMessageValue + pxTimer->xTimerPeriodInTicks, xTimeNow, xMessage.xMessageValue ) == pdTRUE ) + { + /* The timer expired before it was added to the active timer + list. Process it now. */ + pxTimer->pxCallbackFunction( ( xTimerHandle ) pxTimer ); + + if( pxTimer->uxAutoReload == ( unsigned portBASE_TYPE ) pdTRUE ) + { + xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START, xMessage.xMessageValue + pxTimer->xTimerPeriodInTicks, NULL, tmrNO_DELAY ); + configASSERT( xResult ); + ( void ) xResult; + } + } + break; + + case tmrCOMMAND_STOP : + /* The timer has already been removed from the active list. + There is nothing to do here. */ + break; + + case tmrCOMMAND_CHANGE_PERIOD : + pxTimer->xTimerPeriodInTicks = xMessage.xMessageValue; + configASSERT( ( pxTimer->xTimerPeriodInTicks > 0 ) ); + prvInsertTimerInActiveList( pxTimer, ( xTimeNow + pxTimer->xTimerPeriodInTicks ), xTimeNow, xTimeNow ); + break; + + case tmrCOMMAND_DELETE : + /* The timer has already been removed from the active list, + just free up the memory. */ + vPortFree( pxTimer ); + break; + + default : + /* Don't expect to get here. */ + break; + } + } +} +/*-----------------------------------------------------------*/ + +static void prvSwitchTimerLists( portTickType xLastTime ) +{ +portTickType xNextExpireTime, xReloadTime; +xList *pxTemp; +xTIMER *pxTimer; +portBASE_TYPE xResult; + + /* Remove compiler warnings if configASSERT() is not defined. */ + ( void ) xLastTime; + + /* The tick count has overflowed. The timer lists must be switched. + If there are any timers still referenced from the current timer list + then they must have expired and should be processed before the lists + are switched. */ + while( listLIST_IS_EMPTY( pxCurrentTimerList ) == pdFALSE ) + { + xNextExpireTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxCurrentTimerList ); + + /* Remove the timer from the list. */ + pxTimer = ( xTIMER * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList ); + uxListRemove( &( pxTimer->xTimerListItem ) ); + + /* Execute its callback, then send a command to restart the timer if + it is an auto-reload timer. It cannot be restarted here as the lists + have not yet been switched. */ + pxTimer->pxCallbackFunction( ( xTimerHandle ) pxTimer ); + + if( pxTimer->uxAutoReload == ( unsigned portBASE_TYPE ) pdTRUE ) + { + /* Calculate the reload value, and if the reload value results in + the timer going into the same timer list then it has already expired + and the timer should be re-inserted into the current list so it is + processed again within this loop. Otherwise a command should be sent + to restart the timer to ensure it is only inserted into a list after + the lists have been swapped. */ + xReloadTime = ( xNextExpireTime + pxTimer->xTimerPeriodInTicks ); + if( xReloadTime > xNextExpireTime ) + { + listSET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ), xReloadTime ); + listSET_LIST_ITEM_OWNER( &( pxTimer->xTimerListItem ), pxTimer ); + vListInsert( pxCurrentTimerList, &( pxTimer->xTimerListItem ) ); + } + else + { + xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START, xNextExpireTime, NULL, tmrNO_DELAY ); + configASSERT( xResult ); + ( void ) xResult; + } + } + } + + pxTemp = pxCurrentTimerList; + pxCurrentTimerList = pxOverflowTimerList; + pxOverflowTimerList = pxTemp; +} +/*-----------------------------------------------------------*/ + +static void prvCheckForValidListAndQueue( void ) +{ + /* Check that the list from which active timers are referenced, and the + queue used to communicate with the timer service, have been + initialised. */ + taskENTER_CRITICAL(); + { + if( xTimerQueue == NULL ) + { + vListInitialise( &xActiveTimerList1 ); + vListInitialise( &xActiveTimerList2 ); + pxCurrentTimerList = &xActiveTimerList1; + pxOverflowTimerList = &xActiveTimerList2; + xTimerQueue = xQueueCreate( ( unsigned portBASE_TYPE ) configTIMER_QUEUE_LENGTH, sizeof( xTIMER_MESSAGE ) ); + } + } + taskEXIT_CRITICAL(); +} +/*-----------------------------------------------------------*/ + +portBASE_TYPE xTimerIsTimerActive( xTimerHandle xTimer ) +{ +portBASE_TYPE xTimerIsInActiveList; +xTIMER *pxTimer = ( xTIMER * ) xTimer; + + /* Is the timer in the list of active timers? */ + taskENTER_CRITICAL(); + { + /* Checking to see if it is in the NULL list in effect checks to see if + it is referenced from either the current or the overflow timer lists in + one go, but the logic has to be reversed, hence the '!'. */ + xTimerIsInActiveList = !( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) ); + } + taskEXIT_CRITICAL(); + + return xTimerIsInActiveList; +} +/*-----------------------------------------------------------*/ + +void *pvTimerGetTimerID( xTimerHandle xTimer ) +{ +xTIMER *pxTimer = ( xTIMER * ) xTimer; + + return pxTimer->pvTimerID; +} +/*-----------------------------------------------------------*/ + +/* This entire source file will be skipped if the application is not configured +to include software timer functionality. If you want to include software timer +functionality then ensure configUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */ +#endif /* configUSE_TIMERS == 1 */ diff --git a/arduino.DuinOS/DuinOS/timers.h b/arduino.DuinOS.AVR/DuinOS/timers.h similarity index 94% rename from arduino.DuinOS/DuinOS/timers.h rename to arduino.DuinOS.AVR/DuinOS/timers.h index 972aad0..1ee5b9c 100644 --- a/arduino.DuinOS/DuinOS/timers.h +++ b/arduino.DuinOS.AVR/DuinOS/timers.h @@ -1,6 +1,8 @@ /* - FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd. + FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** * * @@ -40,15 +42,28 @@ FreeRTOS WEB site. 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** - http://www.FreeRTOS.org - Documentation, latest information, license and - contact details. - - http://www.SafeRTOS.com - A version that is certified for use in safety - critical systems. - - http://www.OpenRTOS.com - Commercial support, development, porting, - licensing and training services. + + http://www.FreeRTOS.org - Documentation, training, latest versions, license + and contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool. + + Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell + the code with commercial support, indemnification, and middleware, under + the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also + provide a safety engineered and independently SIL3 certified version under + the SafeRTOS brand: http://www.SafeRTOS.com. */ diff --git a/arduino.DuinOS/FreeRTOSConfig.h b/arduino.DuinOS.AVR/FreeRTOSConfig.h similarity index 100% rename from arduino.DuinOS/FreeRTOSConfig.h rename to arduino.DuinOS.AVR/FreeRTOSConfig.h diff --git a/arduino.DuinOS/HID.cpp b/arduino.DuinOS.AVR/HID.cpp similarity index 79% rename from arduino.DuinOS/HID.cpp rename to arduino.DuinOS.AVR/HID.cpp index 8ed1566..ac63608 100644 --- a/arduino.DuinOS/HID.cpp +++ b/arduino.DuinOS.AVR/HID.cpp @@ -144,7 +144,6 @@ u8 _hid_protocol = 1; u8 _hid_idle = 1; #define WEAK __attribute__ ((weak)) -#define WEAK int WEAK HID_GetInterface(u8* interfaceNum) { @@ -202,7 +201,15 @@ bool WEAK HID_Setup(Setup& setup) //================================================================================ // Mouse -Mouse_::Mouse_() : _buttons(0) +Mouse_::Mouse_(void) : _buttons(0) +{ +} + +void Mouse_::begin(void) +{ +} + +void Mouse_::end(void) { } @@ -245,7 +252,7 @@ void Mouse_::release(uint8_t b) bool Mouse_::isPressed(uint8_t b) { - if (b & _buttons > 0) + if ((b & _buttons) > 0) return true; return false; } @@ -254,18 +261,21 @@ bool Mouse_::isPressed(uint8_t b) //================================================================================ // Keyboard -Keyboard_::Keyboard_() : _keyMap(0) +Keyboard_::Keyboard_(void) { } -void Keyboard_::sendReport(KeyReport* keys) +void Keyboard_::begin(void) +{ +} + +void Keyboard_::end(void) { - HID_SendReport(2,keys,sizeof(KeyReport)); } -void Keyboard_::setKeyMap(KeyMap* keyMap) +void Keyboard_::sendReport(KeyReport* keys) { - _keyMap = keyMap; + HID_SendReport(2,keys,sizeof(KeyReport)); } extern @@ -406,41 +416,105 @@ const uint8_t _asciimap[128] = }; uint8_t USBPutChar(uint8_t c); -size_t Keyboard_::write(uint8_t c) + +// press() adds the specified key (printing, non-printing, or modifier) +// to the persistent key report and sends the report. Because of the way +// USB HID works, the host acts like the key remains pressed until we +// call release(), releaseAll(), or otherwise clear the report and resend. +size_t Keyboard_::press(uint8_t k) { - // Keydown - { - KeyReport keys = {0}; - if (_keyMap) - _keyMap->charToKey(c,&keys); - else - { - if (c >= 128) { - setWriteError(); - return 0; - } - c = pgm_read_byte(_asciimap + c); - if (!c) { - setWriteError(); - return 0; - } - if (c & 0x80) - { - keys.modifiers |= KEY_MODIFIER_LEFT_SHIFT; - c &= 0x7F; + uint8_t i; + if (k >= 136) { // it's a non-printing key (not a modifier) + k = k - 136; + } else if (k >= 128) { // it's a modifier key + _keyReport.modifiers |= (1<<(k-128)); + k = 0; + } else { // it's a printing key + k = pgm_read_byte(_asciimap + k); + if (!k) { + setWriteError(); + return 0; + } + if (k & 0x80) { // it's a capital letter or other character reached with shift + _keyReport.modifiers |= 0x02; // the left shift modifier + k &= 0x7F; + } + } + + // Add k to the key report only if it's not already present + // and if there is an empty slot. + if (_keyReport.keys[0] != k && _keyReport.keys[1] != k && + _keyReport.keys[2] != k && _keyReport.keys[3] != k && + _keyReport.keys[4] != k && _keyReport.keys[5] != k) { + + for (i=0; i<6; i++) { + if (_keyReport.keys[i] == 0x00) { + _keyReport.keys[i] = k; + break; } - keys.keys[0] = c; } - sendReport(&keys); + if (i == 6) { + setWriteError(); + return 0; + } } - // Keyup - { - KeyReport keys = {0}; - sendReport(&keys); + sendReport(&_keyReport); + return 1; +} + +// release() takes the specified key out of the persistent key report and +// sends the report. This tells the OS the key is no longer pressed and that +// it shouldn't be repeated any more. +size_t Keyboard_::release(uint8_t k) +{ + uint8_t i; + if (k >= 136) { // it's a non-printing key (not a modifier) + k = k - 136; + } else if (k >= 128) { // it's a modifier key + _keyReport.modifiers &= ~(1<<(k-128)); + k = 0; + } else { // it's a printing key + k = pgm_read_byte(_asciimap + k); + if (!k) { + return 0; + } + if (k & 0x80) { // it's a capital letter or other character reached with shift + _keyReport.modifiers &= ~(0x02); // the left shift modifier + k &= 0x7F; + } } + + // Test the key report to see if k is present. Clear it if it exists. + // Check all positions in case the key is present more than once (which it shouldn't be) + for (i=0; i<6; i++) { + if (0 != k && _keyReport.keys[i] == k) { + _keyReport.keys[i] = 0x00; + } + } + + sendReport(&_keyReport); return 1; } +void Keyboard_::releaseAll(void) +{ + _keyReport.keys[0] = 0; + _keyReport.keys[1] = 0; + _keyReport.keys[2] = 0; + _keyReport.keys[3] = 0; + _keyReport.keys[4] = 0; + _keyReport.keys[5] = 0; + _keyReport.modifiers = 0; + sendReport(&_keyReport); +} + +size_t Keyboard_::write(uint8_t c) +{ + uint8_t p = press(c); // Keydown + uint8_t r = release(c); // Keyup + return (p); // just return the result of press() since release() almost always returns 1 +} + #endif #endif /* if defined(USBCON) */ \ No newline at end of file diff --git a/arduino.DuinOS/HardwareSerial.cpp b/arduino.DuinOS.AVR/HardwareSerial.cpp similarity index 79% rename from arduino.DuinOS/HardwareSerial.cpp rename to arduino.DuinOS.AVR/HardwareSerial.cpp index 1b1fa71..2e64acb 100644 --- a/arduino.DuinOS/HardwareSerial.cpp +++ b/arduino.DuinOS.AVR/HardwareSerial.cpp @@ -18,6 +18,7 @@ Modified 23 November 2006 by David A. Mellis Modified 28 September 2010 by Mark Sproul + Modified 14 August 2012 by Alarus */ #include @@ -46,8 +47,8 @@ struct ring_buffer { unsigned char buffer[SERIAL_BUFFER_SIZE]; - volatile int head; - volatile int tail; + volatile unsigned int head; + volatile unsigned int tail; }; #if defined(USBCON) @@ -109,13 +110,22 @@ inline void store_char(unsigned char c, ring_buffer *buffer) #endif { #if defined(UDR0) - unsigned char c = UDR0; + if (bit_is_clear(UCSR0A, UPE0)) { + unsigned char c = UDR0; + store_char(c, &rx_buffer); + } else { + unsigned char c = UDR0; + }; #elif defined(UDR) - unsigned char c = UDR; + if (bit_is_clear(UCSRA, PE)) { + unsigned char c = UDR; + store_char(c, &rx_buffer); + } else { + unsigned char c = UDR; + }; #else #error UDR not defined #endif - store_char(c, &rx_buffer); } #endif #endif @@ -126,8 +136,12 @@ inline void store_char(unsigned char c, ring_buffer *buffer) #define serialEvent1_implemented SIGNAL(USART1_RX_vect) { - unsigned char c = UDR1; - store_char(c, &rx_buffer1); + if (bit_is_clear(UCSR1A, UPE1)) { + unsigned char c = UDR1; + store_char(c, &rx_buffer1); + } else { + unsigned char c = UDR1; + }; } #elif defined(SIG_USART1_RECV) #error SIG_USART1_RECV @@ -139,8 +153,12 @@ inline void store_char(unsigned char c, ring_buffer *buffer) #define serialEvent2_implemented SIGNAL(USART2_RX_vect) { - unsigned char c = UDR2; - store_char(c, &rx_buffer2); + if (bit_is_clear(UCSR2A, UPE2)) { + unsigned char c = UDR2; + store_char(c, &rx_buffer2); + } else { + unsigned char c = UDR2; + }; } #elif defined(SIG_USART2_RECV) #error SIG_USART2_RECV @@ -152,8 +170,12 @@ inline void store_char(unsigned char c, ring_buffer *buffer) #define serialEvent3_implemented SIGNAL(USART3_RX_vect) { - unsigned char c = UDR3; - store_char(c, &rx_buffer3); + if (bit_is_clear(UCSR3A, UPE3)) { + unsigned char c = UDR3; + store_char(c, &rx_buffer3); + } else { + unsigned char c = UDR3; + }; } #elif defined(SIG_USART3_RECV) #error SIG_USART3_RECV @@ -274,7 +296,7 @@ ISR(USART3_UDRE_vect) HardwareSerial::HardwareSerial(ring_buffer *rx_buffer, ring_buffer *tx_buffer, volatile uint8_t *ubrrh, volatile uint8_t *ubrrl, volatile uint8_t *ucsra, volatile uint8_t *ucsrb, - volatile uint8_t *udr, + volatile uint8_t *ucsrc, volatile uint8_t *udr, uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udrie, uint8_t u2x) { _rx_buffer = rx_buffer; @@ -283,6 +305,7 @@ HardwareSerial::HardwareSerial(ring_buffer *rx_buffer, ring_buffer *tx_buffer, _ubrrl = ubrrl; _ucsra = ucsra; _ucsrb = ucsrb; + _ucsrc = ucsrc; _udr = udr; _rxen = rxen; _txen = txen; @@ -327,6 +350,55 @@ void HardwareSerial::begin(unsigned long baud) *_ubrrh = baud_setting >> 8; *_ubrrl = baud_setting; + transmitting = false; + + sbi(*_ucsrb, _rxen); + sbi(*_ucsrb, _txen); + sbi(*_ucsrb, _rxcie); + cbi(*_ucsrb, _udrie); +} + +void HardwareSerial::begin(unsigned long baud, byte config) +{ + uint16_t baud_setting; + uint8_t current_config; + bool use_u2x = true; + +#if F_CPU == 16000000UL + // hardcoded exception for compatibility with the bootloader shipped + // with the Duemilanove and previous boards and the firmware on the 8U2 + // on the Uno and Mega 2560. + if (baud == 57600) { + use_u2x = false; + } +#endif + +try_again: + + if (use_u2x) { + *_ucsra = 1 << _u2x; + baud_setting = (F_CPU / 4 / baud - 1) / 2; + } else { + *_ucsra = 0; + baud_setting = (F_CPU / 8 / baud - 1) / 2; + } + + if ((baud_setting > 4095) && use_u2x) + { + use_u2x = false; + goto try_again; + } + + // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register) + *_ubrrh = baud_setting >> 8; + *_ubrrl = baud_setting; + + //set the data bits, parity, and stop bits +#if defined(__AVR_ATmega8__) + config |= 0x80; // select UCSRC register (shared with UBRRH) +#endif + *_ucsrc = config; + sbi(*_ucsrb, _rxen); sbi(*_ucsrb, _txen); sbi(*_ucsrb, _rxcie); @@ -376,8 +448,9 @@ int HardwareSerial::read(void) void HardwareSerial::flush() { - while (_tx_buffer->head != _tx_buffer->tail) - ; + // UDR is kept full while the buffer is not empty, so TXC triggers when EMPTY && SENT + while (transmitting && ! (*_ucsra & _BV(TXC0))); + transmitting = false; } size_t HardwareSerial::write(uint8_t c) @@ -394,16 +467,23 @@ size_t HardwareSerial::write(uint8_t c) _tx_buffer->head = i; sbi(*_ucsrb, _udrie); + // clear the TXC bit -- "can be cleared by writing a one to its bit location" + transmitting = true; + sbi(*_ucsra, TXC0); return 1; } +HardwareSerial::operator bool() { + return true; +} + // Preinstantiate Objects ////////////////////////////////////////////////////// #if defined(UBRRH) && defined(UBRRL) - HardwareSerial Serial(&rx_buffer, &tx_buffer, &UBRRH, &UBRRL, &UCSRA, &UCSRB, &UDR, RXEN, TXEN, RXCIE, UDRIE, U2X); + HardwareSerial Serial(&rx_buffer, &tx_buffer, &UBRRH, &UBRRL, &UCSRA, &UCSRB, &UCSRC, &UDR, RXEN, TXEN, RXCIE, UDRIE, U2X); #elif defined(UBRR0H) && defined(UBRR0L) - HardwareSerial Serial(&rx_buffer, &tx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRIE0, U2X0); + HardwareSerial Serial(&rx_buffer, &tx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UCSR0C, &UDR0, RXEN0, TXEN0, RXCIE0, UDRIE0, U2X0); #elif defined(USBCON) // do nothing - Serial object and buffers are initialized in CDC code #else @@ -411,13 +491,13 @@ size_t HardwareSerial::write(uint8_t c) #endif #if defined(UBRR1H) - HardwareSerial Serial1(&rx_buffer1, &tx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UDR1, RXEN1, TXEN1, RXCIE1, UDRIE1, U2X1); + HardwareSerial Serial1(&rx_buffer1, &tx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UCSR1C, &UDR1, RXEN1, TXEN1, RXCIE1, UDRIE1, U2X1); #endif #if defined(UBRR2H) - HardwareSerial Serial2(&rx_buffer2, &tx_buffer2, &UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UDR2, RXEN2, TXEN2, RXCIE2, UDRIE2, U2X2); + HardwareSerial Serial2(&rx_buffer2, &tx_buffer2, &UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UCSR2C, &UDR2, RXEN2, TXEN2, RXCIE2, UDRIE2, U2X2); #endif #if defined(UBRR3H) - HardwareSerial Serial3(&rx_buffer3, &tx_buffer3, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UDR3, RXEN3, TXEN3, RXCIE3, UDRIE3, U2X3); + HardwareSerial Serial3(&rx_buffer3, &tx_buffer3, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UCSR3C, &UDR3, RXEN3, TXEN3, RXCIE3, UDRIE3, U2X3); #endif #endif // whole file diff --git a/arduino.DuinOS/HardwareSerial.h b/arduino.DuinOS.AVR/HardwareSerial.h similarity index 60% rename from arduino.DuinOS/HardwareSerial.h rename to arduino.DuinOS.AVR/HardwareSerial.h index 176abe1..c2d0ce9 100644 --- a/arduino.DuinOS/HardwareSerial.h +++ b/arduino.DuinOS.AVR/HardwareSerial.h @@ -17,6 +17,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Modified 28 September 2010 by Mark Sproul + Modified 14 August 2012 by Alarus */ #ifndef HardwareSerial_h @@ -37,28 +38,62 @@ class HardwareSerial : public Stream volatile uint8_t *_ubrrl; volatile uint8_t *_ucsra; volatile uint8_t *_ucsrb; + volatile uint8_t *_ucsrc; volatile uint8_t *_udr; uint8_t _rxen; uint8_t _txen; uint8_t _rxcie; uint8_t _udrie; uint8_t _u2x; + bool transmitting; public: HardwareSerial(ring_buffer *rx_buffer, ring_buffer *tx_buffer, volatile uint8_t *ubrrh, volatile uint8_t *ubrrl, volatile uint8_t *ucsra, volatile uint8_t *ucsrb, - volatile uint8_t *udr, + volatile uint8_t *ucsrc, volatile uint8_t *udr, uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udrie, uint8_t u2x); void begin(unsigned long); + void begin(unsigned long, byte); void end(); virtual int available(void); virtual int peek(void); virtual int read(void); virtual void flush(void); virtual size_t write(uint8_t); + inline size_t write(unsigned long n) { return write((uint8_t)n); } + inline size_t write(long n) { return write((uint8_t)n); } + inline size_t write(unsigned int n) { return write((uint8_t)n); } + inline size_t write(int n) { return write((uint8_t)n); } using Print::write; // pull in write(str) and write(buf, size) from Print + operator bool(); }; +// Define config for Serial.begin(baud, config); +#define SERIAL_5N1 0x00 +#define SERIAL_6N1 0x02 +#define SERIAL_7N1 0x04 +#define SERIAL_8N1 0x06 +#define SERIAL_5N2 0x08 +#define SERIAL_6N2 0x0A +#define SERIAL_7N2 0x0C +#define SERIAL_8N2 0x0E +#define SERIAL_5E1 0x20 +#define SERIAL_6E1 0x22 +#define SERIAL_7E1 0x24 +#define SERIAL_8E1 0x26 +#define SERIAL_5E2 0x28 +#define SERIAL_6E2 0x2A +#define SERIAL_7E2 0x2C +#define SERIAL_8E2 0x2E +#define SERIAL_5O1 0x30 +#define SERIAL_6O1 0x32 +#define SERIAL_7O1 0x34 +#define SERIAL_8O1 0x36 +#define SERIAL_5O2 0x38 +#define SERIAL_6O2 0x3A +#define SERIAL_7O2 0x3C +#define SERIAL_8O2 0x3E + #if defined(UBRRH) || defined(UBRR0H) extern HardwareSerial Serial; #elif defined(USBCON) @@ -75,6 +110,22 @@ class HardwareSerial : public Stream extern HardwareSerial Serial3; #endif +/* + * on ATmega8, the uart and its bits are not numbered, so there is no "TXC0" + * definition. It is slightly cleaner to define this here instead of having + * conditional code in the cpp module. + */ +#if !defined(TXC0) +#if defined(TXC) +#define TXC0 TXC +#elif defined(TXC1) +// Some devices have uart1 but no uart0 +#define TXC0 TXC1 +#else +#error TXC0 not definable in HardwareSerial.h +#endif +#endif + extern void serialEventRun(void) __attribute__((weak)); #endif diff --git a/arduino.DuinOS/IPAddress.cpp b/arduino.DuinOS.AVR/IPAddress.cpp similarity index 100% rename from arduino.DuinOS/IPAddress.cpp rename to arduino.DuinOS.AVR/IPAddress.cpp diff --git a/arduino.DuinOS/IPAddress.h b/arduino.DuinOS.AVR/IPAddress.h similarity index 100% rename from arduino.DuinOS/IPAddress.h rename to arduino.DuinOS.AVR/IPAddress.h diff --git a/arduino.DuinOS/Platform.h b/arduino.DuinOS.AVR/Platform.h similarity index 100% rename from arduino.DuinOS/Platform.h rename to arduino.DuinOS.AVR/Platform.h diff --git a/arduino.DuinOS/Print.cpp b/arduino.DuinOS.AVR/Print.cpp similarity index 94% rename from arduino.DuinOS/Print.cpp rename to arduino.DuinOS.AVR/Print.cpp index ff9b154..53961ec 100644 --- a/arduino.DuinOS/Print.cpp +++ b/arduino.DuinOS.AVR/Print.cpp @@ -41,7 +41,7 @@ size_t Print::write(const uint8_t *buffer, size_t size) size_t Print::print(const __FlashStringHelper *ifsh) { - const prog_char *p = (const prog_char *)ifsh; + const char PROGMEM *p = (const char PROGMEM *)ifsh; size_t n = 0; while (1) { unsigned char c = pgm_read_byte(p++); @@ -226,6 +226,11 @@ size_t Print::printFloat(double number, uint8_t digits) { size_t n = 0; + if (isnan(number)) return print("nan"); + if (isinf(number)) return print("inf"); + if (number > 4294967040.0) return print ("ovf"); // constant determined empirically + if (number <-4294967040.0) return print ("ovf"); // constant determined empirically + // Handle negative numbers if (number < 0.0) { diff --git a/arduino.DuinOS/Print.h b/arduino.DuinOS.AVR/Print.h similarity index 94% rename from arduino.DuinOS/Print.h rename to arduino.DuinOS.AVR/Print.h index 1af6b72..dc76150 100644 --- a/arduino.DuinOS/Print.h +++ b/arduino.DuinOS.AVR/Print.h @@ -46,7 +46,10 @@ class Print void clearWriteError() { setWriteError(0); } virtual size_t write(uint8_t) = 0; - size_t write(const char *str) { return write((const uint8_t *)str, strlen(str)); } + size_t write(const char *str) { + if (str == NULL) return 0; + return write((const uint8_t *)str, strlen(str)); + } virtual size_t write(const uint8_t *buffer, size_t size); size_t print(const __FlashStringHelper *); diff --git a/arduino.DuinOS/Printable.h b/arduino.DuinOS.AVR/Printable.h similarity index 100% rename from arduino.DuinOS/Printable.h rename to arduino.DuinOS.AVR/Printable.h diff --git a/arduino.DuinOS/Server.h b/arduino.DuinOS.AVR/Server.h similarity index 100% rename from arduino.DuinOS/Server.h rename to arduino.DuinOS.AVR/Server.h diff --git a/arduino.DuinOS/Stream.cpp b/arduino.DuinOS.AVR/Stream.cpp similarity index 89% rename from arduino.DuinOS/Stream.cpp rename to arduino.DuinOS.AVR/Stream.cpp index 5fad8dd..aafb7fc 100644 --- a/arduino.DuinOS/Stream.cpp +++ b/arduino.DuinOS.AVR/Stream.cpp @@ -99,25 +99,27 @@ bool Stream::findUntil(char *target, size_t targetLen, char *terminator, size_t size_t index = 0; // maximum target string length is 64k bytes! size_t termIndex = 0; int c; - + if( *target == 0) - return true; // return true if target is a null string + return true; // return true if target is a null string while( (c = timedRead()) > 0){ + + if(c != target[index]) + index = 0; // reset index if any char does not match + if( c == target[index]){ - //////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1); + //////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1); if(++index >= targetLen){ // return true if all chars in the target match return true; } } - else{ - index = 0; // reset index if any char does not match - } + if(termLen > 0 && c == terminator[termIndex]){ - if(++termIndex >= termLen) - return false; // return false if terminate string found before target string + if(++termIndex >= termLen) + return false; // return false if terminate string found before target string } else - termIndex = 0; + termIndex = 0; } return false; } @@ -242,3 +244,27 @@ size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length) return index; // return number of characters, not including null terminator } +String Stream::readString() +{ + String ret; + int c = timedRead(); + while (c >= 0) + { + ret += (char)c; + c = timedRead(); + } + return ret; +} + +String Stream::readStringUntil(char terminator) +{ + String ret; + int c = timedRead(); + while (c >= 0 && c != terminator) + { + ret += (char)c; + c = timedRead(); + } + return ret; +} + diff --git a/arduino.DuinOS/Stream.h b/arduino.DuinOS.AVR/Stream.h similarity index 98% rename from arduino.DuinOS/Stream.h rename to arduino.DuinOS.AVR/Stream.h index 13f11be..58bbf75 100644 --- a/arduino.DuinOS/Stream.h +++ b/arduino.DuinOS.AVR/Stream.h @@ -82,6 +82,8 @@ class Stream : public Print // returns the number of characters placed in the buffer (0 means no valid data found) // Arduino String functions to be added here + String readString(); + String readStringUntil(char terminator); protected: long parseInt(char skipChar); // as above but the given skipChar is ignored diff --git a/arduino.DuinOS/Tone.cpp b/arduino.DuinOS.AVR/Tone.cpp similarity index 96% rename from arduino.DuinOS/Tone.cpp rename to arduino.DuinOS.AVR/Tone.cpp index 20eed3f..9bb6fe7 100644 --- a/arduino.DuinOS/Tone.cpp +++ b/arduino.DuinOS.AVR/Tone.cpp @@ -29,6 +29,7 @@ Version Modified By Date Comments 09/11/25 Fixed timer0 from being excluded 0006 D Mellis 09/12/29 Replaced objects with functions 0007 M Sproul 10/08/29 Changed #ifdefs from cpu to register +0008 S Kanemoto 12/06/22 Fixed for Leonardo by @maris_HY *************************************************/ #include @@ -85,10 +86,10 @@ volatile uint8_t timer5_pin_mask; #endif -// MLS: This does not make sense, the 3 options are the same #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) #define AVAILABLE_TONE_PINS 1 +#define USE_TIMER2 const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 3, 4, 5, 1, 0 */ }; static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255, 255, 255, 255, 255 */ }; @@ -96,13 +97,23 @@ static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255, 255, 255, 255, 25 #elif defined(__AVR_ATmega8__) #define AVAILABLE_TONE_PINS 1 +#define USE_TIMER2 const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 1 */ }; static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255 */ }; +#elif defined(__AVR_ATmega32U4__) + +#define AVAILABLE_TONE_PINS 1 +#define USE_TIMER3 + +const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 3 /*, 1 */ }; +static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255 */ }; + #else #define AVAILABLE_TONE_PINS 1 +#define USE_TIMER2 // Leave timer 0 to last. const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 1, 0 */ }; @@ -480,8 +491,7 @@ void noTone(uint8_t _pin) digitalWrite(_pin, 0); } -#if 0 -#if !defined(__AVR_ATmega8__) +#ifdef USE_TIMER0 ISR(TIMER0_COMPA_vect) { if (timer0_toggle_count != 0) @@ -501,6 +511,7 @@ ISR(TIMER0_COMPA_vect) #endif +#ifdef USE_TIMER1 ISR(TIMER1_COMPA_vect) { if (timer1_toggle_count != 0) @@ -520,6 +531,7 @@ ISR(TIMER1_COMPA_vect) #endif +#ifdef USE_TIMER2 ISR(TIMER2_COMPA_vect) { @@ -541,12 +553,10 @@ ISR(TIMER2_COMPA_vect) // *timer2_pin_port &= ~(timer2_pin_mask); // keep pin low after stop } } +#endif - -//#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) -#if 0 - +#ifdef USE_TIMER3 ISR(TIMER3_COMPA_vect) { if (timer3_toggle_count != 0) @@ -563,7 +573,10 @@ ISR(TIMER3_COMPA_vect) *timer3_pin_port &= ~(timer3_pin_mask); // keep pin low after stop } } +#endif + +#ifdef USE_TIMER4 ISR(TIMER4_COMPA_vect) { if (timer4_toggle_count != 0) @@ -580,7 +593,10 @@ ISR(TIMER4_COMPA_vect) *timer4_pin_port &= ~(timer4_pin_mask); // keep pin low after stop } } +#endif + +#ifdef USE_TIMER5 ISR(TIMER5_COMPA_vect) { if (timer5_toggle_count != 0) @@ -597,5 +613,4 @@ ISR(TIMER5_COMPA_vect) *timer5_pin_port &= ~(timer5_pin_mask); // keep pin low after stop } } - #endif diff --git a/arduino.DuinOS/USBAPI.h b/arduino.DuinOS.AVR/USBAPI.h similarity index 72% rename from arduino.DuinOS/USBAPI.h rename to arduino.DuinOS.AVR/USBAPI.h index 26a2032..eb2e593 100644 --- a/arduino.DuinOS/USBAPI.h +++ b/arduino.DuinOS.AVR/USBAPI.h @@ -9,17 +9,17 @@ //================================================================================ // USB -class USB_ +class USBDevice_ { public: - USB_(); + USBDevice_(); bool configured(); void attach(); void detach(); // Serial port goes down too... void poll(); }; -extern USB_ USB; +extern USBDevice_ USBDevice; //================================================================================ //================================================================================ @@ -27,15 +27,20 @@ extern USB_ USB; class Serial_ : public Stream { +private: + ring_buffer *_cdc_rx_buffer; public: void begin(uint16_t baud_count); void end(void); virtual int available(void); + virtual void accept(void); virtual int peek(void); virtual int read(void); virtual void flush(void); virtual size_t write(uint8_t); + using Print::write; // pull in write(str) and write(buf, size) from Print + operator bool(); }; extern Serial_ Serial; @@ -54,12 +59,14 @@ class Mouse_ uint8_t _buttons; void buttons(uint8_t b); public: - Mouse_(); + Mouse_(void); + void begin(void); + void end(void); void click(uint8_t b = MOUSE_LEFT); void move(signed char x, signed char y, signed char wheel = 0); void press(uint8_t b = MOUSE_LEFT); // press LEFT by default void release(uint8_t b = MOUSE_LEFT); // release LEFT by default - bool isPressed(uint8_t b = MOUSE_ALL); // check all buttons by default + bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default }; extern Mouse_ Mouse; @@ -67,14 +74,42 @@ extern Mouse_ Mouse; //================================================================================ // Keyboard -#define KEY_MODIFIER_LEFT_CTRL 0x01 -#define KEY_MODIFIER_LEFT_SHIFT 0x02 -#define KEY_MODIFIER_LEFT_ALT 0x04 -#define KEY_MODIFIER_LEFT_GUI 0x08 -#define KEY_MODIFIER_RIGHT_CTRL 0x010 -#define KEY_MODIFIER_RIGHT_SHIFT 0x020 -#define KEY_MODIFIER_RIGHT_ALT 0x040 -#define KEY_MODIFIER_RIGHT_GUI 0x080 +#define KEY_LEFT_CTRL 0x80 +#define KEY_LEFT_SHIFT 0x81 +#define KEY_LEFT_ALT 0x82 +#define KEY_LEFT_GUI 0x83 +#define KEY_RIGHT_CTRL 0x84 +#define KEY_RIGHT_SHIFT 0x85 +#define KEY_RIGHT_ALT 0x86 +#define KEY_RIGHT_GUI 0x87 + +#define KEY_UP_ARROW 0xDA +#define KEY_DOWN_ARROW 0xD9 +#define KEY_LEFT_ARROW 0xD8 +#define KEY_RIGHT_ARROW 0xD7 +#define KEY_BACKSPACE 0xB2 +#define KEY_TAB 0xB3 +#define KEY_RETURN 0xB0 +#define KEY_ESC 0xB1 +#define KEY_INSERT 0xD1 +#define KEY_DELETE 0xD4 +#define KEY_PAGE_UP 0xD3 +#define KEY_PAGE_DOWN 0xD6 +#define KEY_HOME 0xD2 +#define KEY_END 0xD5 +#define KEY_CAPS_LOCK 0xC1 +#define KEY_F1 0xC2 +#define KEY_F2 0xC3 +#define KEY_F3 0xC4 +#define KEY_F4 0xC5 +#define KEY_F5 0xC6 +#define KEY_F6 0xC7 +#define KEY_F7 0xC8 +#define KEY_F8 0xC9 +#define KEY_F9 0xCA +#define KEY_F10 0xCB +#define KEY_F11 0xCC +#define KEY_F12 0xCD // Low level key report: up to 6 keys and shift, ctrl etc at once typedef struct @@ -84,24 +119,19 @@ typedef struct uint8_t keys[6]; } KeyReport; -// Map a character into a key report -// Called from Print to map text to keycodes -class KeyMap -{ -public: - virtual void charToKey(int c, KeyReport* keyReport) = 0; -}; - -// class Keyboard_ : public Print { private: - KeyMap* _keyMap; + KeyReport _keyReport; void sendReport(KeyReport* keys); - void setKeyMap(KeyMap* keyMap); public: - Keyboard_(); - virtual size_t write(uint8_t); + Keyboard_(void); + void begin(void); + void end(void); + virtual size_t write(uint8_t k); + virtual size_t press(uint8_t k); + virtual size_t release(uint8_t k); + virtual void releaseAll(void); }; extern Keyboard_ Keyboard; diff --git a/arduino.DuinOS/USBCore.cpp b/arduino.DuinOS.AVR/USBCore.cpp similarity index 95% rename from arduino.DuinOS/USBCore.cpp rename to arduino.DuinOS.AVR/USBCore.cpp index 398bc73..8bcf66c 100644 --- a/arduino.DuinOS/USBCore.cpp +++ b/arduino.DuinOS.AVR/USBCore.cpp @@ -51,16 +51,20 @@ const u16 STRING_LANGUAGE[2] = { const u16 STRING_IPRODUCT[17] = { (3<<8) | (2+2*16), -#if USB_PID == USB_PID_LEONARDO +#if USB_PID == 0x8036 'A','r','d','u','i','n','o',' ','L','e','o','n','a','r','d','o' -#elif USB_PID == USB_PID_MICRO - 'A','r','d','u','i','n','o',' ','M','i','c','r','o',' ',' ',' ' +#else + 'U','S','B',' ','I','O',' ','B','o','a','r','d',' ',' ',' ',' ' #endif }; const u16 STRING_IMANUFACTURER[12] = { (3<<8) | (2+2*11), +#if USB_VID == 0x2341 'A','r','d','u','i','n','o',' ','L','L','C' +#else + 'U','n','k','n','o','w','n',' ',' ',' ',' ' +#endif }; #ifdef CDC_ENABLED @@ -599,6 +603,8 @@ ISR(USB_GEN_vect) { #ifdef CDC_ENABLED USB_Flush(CDC_TX); // Send a tx frame if found + if (USB_Available(CDC_RX)) // Handle received bytes (if any) + Serial.accept(); #endif // check whether the one-shot period has elapsed. if so, turn off the LED @@ -621,13 +627,13 @@ u8 USBConnected() //======================================================================= //======================================================================= -USB_ USB; +USBDevice_ USBDevice; -USB_::USB_() +USBDevice_::USBDevice_() { } -void USB_::attach() +void USBDevice_::attach() { _usbConfiguration = 0; UHWCON = 0x01; // power internal reg @@ -635,6 +641,12 @@ void USB_::attach() PLLCSR = 0x12; // Need 16 MHz xtal while (!(PLLCSR & (1<= len || fromIndex < 0) return -1; + if (fromIndex >= len) return -1; char tempchar = buffer[fromIndex + 1]; buffer[fromIndex + 1] = '\0'; char* temp = strrchr( buffer, ch ); @@ -516,7 +516,7 @@ int String::lastIndexOf(const String &s2) const int String::lastIndexOf(const String &s2, unsigned int fromIndex) const { - if (s2.len == 0 || len == 0 || s2.len > len || fromIndex < 0) return -1; + if (s2.len == 0 || len == 0 || s2.len > len) return -1; if (fromIndex >= len) fromIndex = len - 1; int found = -1; for (char *p = buffer; p <= buffer + fromIndex; p++) { diff --git a/arduino.DuinOS/WString.h b/arduino.DuinOS.AVR/WString.h similarity index 98% rename from arduino.DuinOS/WString.h rename to arduino.DuinOS.AVR/WString.h index d76d2a3..947325e 100644 --- a/arduino.DuinOS/WString.h +++ b/arduino.DuinOS.AVR/WString.h @@ -35,7 +35,7 @@ // -std=c++0x class __FlashStringHelper; -#define F(string_literal) (reinterpret_cast<__FlashStringHelper *>(PSTR(string_literal))) +#define F(string_literal) (reinterpret_cast(PSTR(string_literal))) // An inherited class for holding the result of a concatenation. These // result objects are assumed to be writable by subsequent concatenations. diff --git a/arduino.DuinOS/binary.h b/arduino.DuinOS.AVR/binary.h similarity index 100% rename from arduino.DuinOS/binary.h rename to arduino.DuinOS.AVR/binary.h diff --git a/arduino.DuinOS/main.cpp b/arduino.DuinOS.AVR/main.cpp similarity index 86% rename from arduino.DuinOS/main.cpp rename to arduino.DuinOS.AVR/main.cpp index b9361f8..efa2b7f 100644 --- a/arduino.DuinOS/main.cpp +++ b/arduino.DuinOS.AVR/main.cpp @@ -8,23 +8,25 @@ void main_Task(void *pvParameters) loop(); if (serialEventRun) serialEventRun(); } - -} + +} -int main(void) +int main(void) { mainLoopPriority = LOW_PRIORITY; - init(); + #if defined(USBCON) - USB.attach(); + USBDevice.attach(); #endif + setup(); - + xTaskCreate(main_Task, (signed portCHAR *) "main", configMINIMAL_STACK_SIZE, NULL, mainLoopPriority, NULL); vTaskStartScheduler(); - - for(;;); - + + for (;;); + return 0; } + diff --git a/arduino.DuinOS/new.cpp b/arduino.DuinOS.AVR/new.cpp similarity index 100% rename from arduino.DuinOS/new.cpp rename to arduino.DuinOS.AVR/new.cpp diff --git a/arduino.DuinOS/new.h b/arduino.DuinOS.AVR/new.h similarity index 100% rename from arduino.DuinOS/new.h rename to arduino.DuinOS.AVR/new.h diff --git a/arduino.DuinOS/wiring.c b/arduino.DuinOS.AVR/wiring.c similarity index 71% rename from arduino.DuinOS/wiring.c rename to arduino.DuinOS.AVR/wiring.c index 9ad13bb..5b9167d 100644 --- a/arduino.DuinOS/wiring.c +++ b/arduino.DuinOS.AVR/wiring.c @@ -41,7 +41,14 @@ volatile unsigned long timer0_overflow_count = 0; volatile unsigned long timer0_millis = 0; static unsigned char timer0_fract = 0; -void arduinoTickHook(void) +/* +#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) +SIGNAL(TIM0_OVF_vect) +#else +SIGNAL(TIMER0_OVF_vect) +#endif +*/ +void vApplicationTickHook(void) { // copy these to local variables so they can be stored in registers // (volatile variables must be read from memory on every access) @@ -102,14 +109,46 @@ unsigned long micros() { return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond()); } +/* +void delay(unsigned long ms) +{ + uint16_t start = (uint16_t)micros(); + + while (ms > 0) { + if (((uint16_t)micros() - start) >= 1000) { + ms--; + start += 1000; + } + } +} +*/ + /* Delay for the given number of microseconds. Assumes a 8 or 16 MHz clock. */ void delayMicroseconds(unsigned int us) { // calling avrlib's delay_us() function with low values (e.g. 1 or // 2 microseconds) gives delays longer than desired. //delay_us(us); +#if F_CPU >= 20000000L + // for the 20 MHz clock on rare Arduino boards + + // for a one-microsecond delay, simply wait 2 cycle and return. The overhead + // of the function call yields a delay of exactly a one microsecond. + __asm__ __volatile__ ( + "nop" "\n\t" + "nop"); //just waiting 2 cycle + if (--us == 0) + return; + + // the following loop takes a 1/5 of a microsecond (4 cycles) + // per iteration, so execute it five times for each microsecond of + // delay requested. + us = (us<<2) + us; // x5 us + + // account for the time taken in the preceeding commands. + us -= 2; -#if F_CPU >= 16000000L +#elif F_CPU >= 16000000L // for the 16 MHz clock on most Arduino boards // for a one-microsecond delay, simply return. the overhead @@ -158,10 +197,50 @@ void init() // work there sei(); +/* + // on the ATmega168, timer 0 is also used for fast hardware pwm + // (using phase-correct PWM would mean that timer 0 overflowed half as often + // resulting in different millis() behavior on the ATmega8 and ATmega168) +#if defined(TCCR0A) && defined(WGM01) + sbi(TCCR0A, WGM01); + sbi(TCCR0A, WGM00); +#endif + + // set timer 0 prescale factor to 64 +#if defined(__AVR_ATmega128__) + // CPU specific: different values for the ATmega128 + sbi(TCCR0, CS02); +#elif defined(TCCR0) && defined(CS01) && defined(CS00) + // this combination is for the standard atmega8 + sbi(TCCR0, CS01); + sbi(TCCR0, CS00); +#elif defined(TCCR0B) && defined(CS01) && defined(CS00) + // this combination is for the standard 168/328/1280/2560 + sbi(TCCR0B, CS01); + sbi(TCCR0B, CS00); +#elif defined(TCCR0A) && defined(CS01) && defined(CS00) + // this combination is for the __AVR_ATmega645__ series + sbi(TCCR0A, CS01); + sbi(TCCR0A, CS00); +#else + #error Timer 0 prescale factor 64 not set correctly +#endif + + // enable timer 0 overflow interrupt +#if defined(TIMSK) && defined(TOIE0) + sbi(TIMSK, TOIE0); +#elif defined(TIMSK0) && defined(TOIE0) + sbi(TIMSK0, TOIE0); +#else + #error Timer 0 overflow interrupt not set correctly +#endif +*/ + // timers 1 and 2 are used for phase-correct hardware pwm // this is better for motors as it ensures an even waveform // note, however, that fast pwm mode can achieve a frequency of up // 8 MHz (with a 16 MHz clock) at 50% duty cycle + #if defined(TCCR1B) && defined(CS11) && defined(CS10) TCCR1B = 0; @@ -182,6 +261,7 @@ void init() #elif defined(TCCR1) #warning this needs to be finished #endif + // set timer 2 prescale factor to 64 #if defined(TCCR2) && defined(CS22) sbi(TCCR2, CS22); @@ -205,12 +285,21 @@ void init() sbi(TCCR3B, CS30); sbi(TCCR3A, WGM30); // put timer 3 in 8-bit phase correct pwm mode #endif - + +#if defined(TCCR4A) && defined(TCCR4B) && defined(TCCR4D) /* beginning of timer4 block for 32U4 and similar */ + sbi(TCCR4B, CS42); // set timer4 prescale factor to 64 + sbi(TCCR4B, CS41); + sbi(TCCR4B, CS40); + sbi(TCCR4D, WGM40); // put timer 4 in phase- and frequency-correct PWM mode + sbi(TCCR4A, PWM4A); // enable PWM mode for comparator OCR4A + sbi(TCCR4C, PWM4D); // enable PWM mode for comparator OCR4D +#else /* beginning of timer4 block for ATMEGA1280 and ATMEGA2560 */ #if defined(TCCR4B) && defined(CS41) && defined(WGM40) sbi(TCCR4B, CS41); // set timer 4 prescale factor to 64 sbi(TCCR4B, CS40); sbi(TCCR4A, WGM40); // put timer 4 in 8-bit phase correct pwm mode #endif +#endif /* end timer4 block for ATMEGA1280/2560 and similar */ #if defined(TCCR5B) && defined(CS51) && defined(WGM50) sbi(TCCR5B, CS51); // set timer 5 prescale factor to 64 diff --git a/arduino.DuinOS/wiring_analog.c b/arduino.DuinOS.AVR/wiring_analog.c similarity index 92% rename from arduino.DuinOS/wiring_analog.c rename to arduino.DuinOS.AVR/wiring_analog.c index b53cb9a..23b01c6 100644 --- a/arduino.DuinOS/wiring_analog.c +++ b/arduino.DuinOS.AVR/wiring_analog.c @@ -45,6 +45,8 @@ int analogRead(uint8_t pin) if (pin >= 54) pin -= 54; // allow for channel or pin numbers #elif defined(__AVR_ATmega32U4__) if (pin >= 18) pin -= 18; // allow for channel or pin numbers +#elif defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644P__) + if (pin >= 24) pin -= 24; // allow for channel or pin numbers #else if (pin >= 14) pin -= 14; // allow for channel or pin numbers #endif @@ -140,10 +142,6 @@ void analogWrite(uint8_t pin, int val) break; #endif -#ifdef DISABLED_BY_DUINOS - -// disabled because DuinOS uses timer 1 for its kernel - #if defined(TCCR1A) && defined(COM1A1) case TIMER1A: // connect pwm to pin on timer 1, channel A @@ -159,7 +157,6 @@ void analogWrite(uint8_t pin, int val) OCR1B = val; // set pwm duty break; #endif -#endif #if defined(TCCR2) && defined(COM21) case TIMER2: @@ -209,14 +206,17 @@ void analogWrite(uint8_t pin, int val) break; #endif - #if defined(TCCR4A) && defined(COM4A1) + #if defined(TCCR4A) case TIMER4A: - // connect pwm to pin on timer 4, channel A + //connect pwm to pin on timer 4, channel A sbi(TCCR4A, COM4A1); - OCR4A = val; // set pwm duty + #if defined(COM4A0) // only used on 32U4 + cbi(TCCR4A, COM4A0); + #endif + OCR4A = val; // set pwm duty break; #endif - + #if defined(TCCR4A) && defined(COM4B1) case TIMER4B: // connect pwm to pin on timer 4, channel B @@ -233,14 +233,18 @@ void analogWrite(uint8_t pin, int val) break; #endif - #if defined(TCCR4A) && defined(COM4D1) - case TIMER4D: + #if defined(TCCR4C) && defined(COM4D1) + case TIMER4D: // connect pwm to pin on timer 4, channel D - sbi(TCCR4A, COM4D1); - OCR4D = val; // set pwm duty + sbi(TCCR4C, COM4D1); + #if defined(COM4D0) // only used on 32U4 + cbi(TCCR4C, COM4D0); + #endif + OCR4D = val; // set pwm duty break; #endif + #if defined(TCCR5A) && defined(COM5A1) case TIMER5A: // connect pwm to pin on timer 5, channel A @@ -275,3 +279,4 @@ void analogWrite(uint8_t pin, int val) } } } + diff --git a/arduino.DuinOS/wiring_digital.c b/arduino.DuinOS.AVR/wiring_digital.c similarity index 93% rename from arduino.DuinOS/wiring_digital.c rename to arduino.DuinOS.AVR/wiring_digital.c index 97ef134..be323b1 100644 --- a/arduino.DuinOS/wiring_digital.c +++ b/arduino.DuinOS.AVR/wiring_digital.c @@ -32,17 +32,25 @@ void pinMode(uint8_t pin, uint8_t mode) { uint8_t bit = digitalPinToBitMask(pin); uint8_t port = digitalPinToPort(pin); - volatile uint8_t *reg; + volatile uint8_t *reg, *out; if (port == NOT_A_PIN) return; // JWS: can I let the optimizer do this? reg = portModeRegister(port); + out = portOutputRegister(port); if (mode == INPUT) { uint8_t oldSREG = SREG; cli(); *reg &= ~bit; + *out &= ~bit; + SREG = oldSREG; + } else if (mode == INPUT_PULLUP) { + uint8_t oldSREG = SREG; + cli(); + *reg &= ~bit; + *out |= bit; SREG = oldSREG; } else { uint8_t oldSREG = SREG; @@ -107,13 +115,17 @@ static void turnOffPWM(uint8_t timer) #if defined(TCCR4A) && defined(COM4A1) case TIMER4A: cbi(TCCR4A, COM4A1); break; - #endif + #endif #if defined(TCCR4A) && defined(COM4B1) case TIMER4B: cbi(TCCR4A, COM4B1); break; #endif #if defined(TCCR4A) && defined(COM4C1) case TIMER4C: cbi(TCCR4A, COM4C1); break; - #endif + #endif + #if defined(TCCR4C) && defined(COM4D1) + case TIMER4D: cbi(TCCR4C, COM4D1); break; + #endif + #if defined(TCCR5A) case TIMER5A: cbi(TCCR5A, COM5A1); break; case TIMER5B: cbi(TCCR5A, COM5B1); break; diff --git a/arduino.DuinOS/wiring_private.h b/arduino.DuinOS.AVR/wiring_private.h similarity index 90% rename from arduino.DuinOS/wiring_private.h rename to arduino.DuinOS.AVR/wiring_private.h index 41d1d40..f678265 100644 --- a/arduino.DuinOS/wiring_private.h +++ b/arduino.DuinOS.AVR/wiring_private.h @@ -54,6 +54,10 @@ extern "C"{ #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) #define EXTERNAL_NUM_INTERRUPTS 8 +#elif defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644P__) +#define EXTERNAL_NUM_INTERRUPTS 3 +#elif defined(__AVR_ATmega32U4__) +#define EXTERNAL_NUM_INTERRUPTS 4 #else #define EXTERNAL_NUM_INTERRUPTS 2 #endif diff --git a/arduino.DuinOS/wiring_pulse.c b/arduino.DuinOS.AVR/wiring_pulse.c similarity index 100% rename from arduino.DuinOS/wiring_pulse.c rename to arduino.DuinOS.AVR/wiring_pulse.c diff --git a/arduino.DuinOS/wiring_shift.c b/arduino.DuinOS.AVR/wiring_shift.c similarity index 100% rename from arduino.DuinOS/wiring_shift.c rename to arduino.DuinOS.AVR/wiring_shift.c diff --git a/arduino.DuinOS/DuinOS/portmacro.h b/arduino.DuinOS/DuinOS/portmacro.h deleted file mode 100644 index 62e3870..0000000 --- a/arduino.DuinOS/DuinOS/portmacro.h +++ /dev/null @@ -1,129 +0,0 @@ -/* - FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd. - - *************************************************************************** - * * - * If you are: * - * * - * + New to FreeRTOS, * - * + Wanting to learn FreeRTOS or multitasking in general quickly * - * + Looking for basic training, * - * + Wanting to improve your FreeRTOS skills and productivity * - * * - * then take a look at the FreeRTOS books - available as PDF or paperback * - * * - * "Using the FreeRTOS Real Time Kernel - a Practical Guide" * - * http://www.FreeRTOS.org/Documentation * - * * - * A pdf reference manual is also available. Both are usually delivered * - * to your inbox within 20 minutes to two hours when purchased between 8am * - * and 8pm GMT (although please allow up to 24 hours in case of * - * exceptional circumstances). Thank you for your support! * - * * - *************************************************************************** - - This file is part of the FreeRTOS distribution. - - FreeRTOS is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License (version 2) as published by the - Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - ***NOTE*** The exception to the GPL is included to allow you to distribute - a combined work that includes FreeRTOS without being obliged to provide the - source code for proprietary components outside of the FreeRTOS kernel. - FreeRTOS is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. You should have received a copy of the GNU General Public - License and the FreeRTOS license exception along with FreeRTOS; if not it - can be viewed here: http://www.freertos.org/a00114.html and also obtained - by writing to Richard Barry, contact details for whom are available on the - FreeRTOS WEB site. - - 1 tab == 4 spaces! - - http://www.FreeRTOS.org - Documentation, latest information, license and - contact details. - - http://www.SafeRTOS.com - A version that is certified for use in safety - critical systems. - - http://www.OpenRTOS.com - Commercial support, development, porting, - licensing and training services. -*/ - -/* -Changes from V1.2.3 - - + portCPU_CLOSK_HZ definition changed to 8MHz base 10, previously it - base 16. -*/ - -#ifndef PORTMACRO_H -#define PORTMACRO_H - -#ifdef __cplusplus -extern "C" { -#endif - -/*----------------------------------------------------------- - * Port specific definitions. - * - * The settings in this file configure FreeRTOS correctly for the - * given hardware and compiler. - * - * These settings should not be altered. - *----------------------------------------------------------- - */ - -/* Type definitions. */ -#define portCHAR char -#define portFLOAT float -#define portDOUBLE double -#define portLONG long -#define portSHORT int -#define portSTACK_TYPE unsigned portCHAR -#define portBASE_TYPE char - -#if( configUSE_16_BIT_TICKS == 1 ) - typedef unsigned portSHORT portTickType; - #define portMAX_DELAY ( portTickType ) 0xffff -#else - typedef unsigned portLONG portTickType; - #define portMAX_DELAY ( portTickType ) 0xffffffff -#endif -/*-----------------------------------------------------------*/ - -/* Critical section management. */ -#define portENTER_CRITICAL() asm volatile ( "in __tmp_reg__, __SREG__" :: ); \ - asm volatile ( "cli" :: ); \ - asm volatile ( "push __tmp_reg__" :: ) - -#define portEXIT_CRITICAL() asm volatile ( "pop __tmp_reg__" :: ); \ - asm volatile ( "out __SREG__, __tmp_reg__" :: ) - -#define portDISABLE_INTERRUPTS() asm volatile ( "cli" :: ); -#define portENABLE_INTERRUPTS() asm volatile ( "sei" :: ); -/*-----------------------------------------------------------*/ - -/* Architecture specifics. */ -#define portSTACK_GROWTH ( -1 ) -#define portTICK_RATE_MS ( ( portTickType ) 1000 / configTICK_RATE_HZ ) -#define portBYTE_ALIGNMENT 1 -#define portNOP() asm volatile ( "nop" ); -/*-----------------------------------------------------------*/ - -/* Kernel utilities. */ -extern void vPortYield( void ) __attribute__ ( ( naked ) ); -#define portYIELD() vPortYield() -/*-----------------------------------------------------------*/ - -/* Task function macros as described on the FreeRTOS.org WEB site. */ -#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) -#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) - -#ifdef __cplusplus -} -#endif - -#endif /* PORTMACRO_H */ - diff --git a/arduino.DuinOS/WConstants.h b/arduino.DuinOS/WConstants.h deleted file mode 100644 index 3e19ac4..0000000 --- a/arduino.DuinOS/WConstants.h +++ /dev/null @@ -1 +0,0 @@ -#include "wiring.h" diff --git a/arduino.DuinOS/WProgram.h b/arduino.DuinOS/WProgram.h deleted file mode 100644 index d5cd9c4..0000000 --- a/arduino.DuinOS/WProgram.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef WProgram_h -#define WProgram_h - -#include -#include -#include - -#include - -#include "wiring.h" - -// DuinOS is include here, because it's part of the core: -#include "DuinOS.h" - -#ifdef __cplusplus -#include "WString.h" -#include "HardwareSerial.h" - -uint16_t makeWord(uint16_t w); -uint16_t makeWord(byte h, byte l); - -#define word(...) makeWord(__VA_ARGS__) - -unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); - -void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0); -void noTone(uint8_t _pin); - -// WMath prototypes -long random(long); -long random(long, long); -void randomSeed(unsigned int); -long map(long, long, long, long, long); - -#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) -const static uint8_t A0 = 54; -const static uint8_t A1 = 55; -const static uint8_t A2 = 56; -const static uint8_t A3 = 57; -const static uint8_t A4 = 58; -const static uint8_t A5 = 59; -const static uint8_t A6 = 60; -const static uint8_t A7 = 61; -const static uint8_t A8 = 62; -const static uint8_t A9 = 63; -const static uint8_t A10 = 64; -const static uint8_t A11 = 65; -const static uint8_t A12 = 66; -const static uint8_t A13 = 67; -const static uint8_t A14 = 68; -const static uint8_t A15 = 69; -#else -const static uint8_t A0 = 14; -const static uint8_t A1 = 15; -const static uint8_t A2 = 16; -const static uint8_t A3 = 17; -const static uint8_t A4 = 18; -const static uint8_t A5 = 19; -const static uint8_t A6 = 20; -const static uint8_t A7 = 21; -#endif - -#endif - -#endif \ No newline at end of file diff --git a/arduino.DuinOS/pins_arduino.c b/arduino.DuinOS/pins_arduino.c deleted file mode 100644 index 0c816e9..0000000 --- a/arduino.DuinOS/pins_arduino.c +++ /dev/null @@ -1,465 +0,0 @@ -/* - pins_arduino.c - pin definitions for the Arduino board - Part of Arduino / Wiring Lite - - Copyright (c) 2005 David A. Mellis - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General - Public License along with this library; if not, write to the - Free Software Foundation, Inc., 59 Temple Place, Suite 330, - Boston, MA 02111-1307 USA - - $Id$ -*/ - -#include -#include "wiring_private.h" -#include "pins_arduino.h" - -// On the Arduino board, digital pins are also used -// for the analog output (software PWM). Analog input -// pins are a separate set. - -// ATMEL ATMEGA8 & 168 / ARDUINO -// -// +-\/-+ -// PC6 1| |28 PC5 (AI 5) -// (D 0) PD0 2| |27 PC4 (AI 4) -// (D 1) PD1 3| |26 PC3 (AI 3) -// (D 2) PD2 4| |25 PC2 (AI 2) -// PWM+ (D 3) PD3 5| |24 PC1 (AI 1) -// (D 4) PD4 6| |23 PC0 (AI 0) -// VCC 7| |22 GND -// GND 8| |21 AREF -// PB6 9| |20 AVCC -// PB7 10| |19 PB5 (D 13) -// PWM+ (D 5) PD5 11| |18 PB4 (D 12) -// PWM+ (D 6) PD6 12| |17 PB3 (D 11) PWM -// (D 7) PD7 13| |16 PB2 (D 10) PWM -// (D 8) PB0 14| |15 PB1 (D 9) PWM -// +----+ -// -// (PWM+ indicates the additional PWM pins on the ATmega168.) - -// ATMEL ATMEGA1280 / ARDUINO -// -// 0-7 PE0-PE7 works -// 8-13 PB0-PB5 works -// 14-21 PA0-PA7 works -// 22-29 PH0-PH7 works -// 30-35 PG5-PG0 works -// 36-43 PC7-PC0 works -// 44-51 PJ7-PJ0 works -// 52-59 PL7-PL0 works -// 60-67 PD7-PD0 works -// A0-A7 PF0-PF7 -// A8-A15 PK0-PK7 - -#define PA 1 -#define PB 2 -#define PC 3 -#define PD 4 -#define PE 5 -#define PF 6 -#define PG 7 -#define PH 8 -#define PJ 10 -#define PK 11 -#define PL 12 - - -#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) -const uint16_t PROGMEM port_to_mode_PGM[] = { - NOT_A_PORT, - &DDRA, - &DDRB, - &DDRC, - &DDRD, - &DDRE, - &DDRF, - &DDRG, - &DDRH, - NOT_A_PORT, - &DDRJ, - &DDRK, - &DDRL, -}; - -const uint16_t PROGMEM port_to_output_PGM[] = { - NOT_A_PORT, - &PORTA, - &PORTB, - &PORTC, - &PORTD, - &PORTE, - &PORTF, - &PORTG, - &PORTH, - NOT_A_PORT, - &PORTJ, - &PORTK, - &PORTL, -}; - -const uint16_t PROGMEM port_to_input_PGM[] = { - NOT_A_PIN, - &PINA, - &PINB, - &PINC, - &PIND, - &PINE, - &PINF, - &PING, - &PINH, - NOT_A_PIN, - &PINJ, - &PINK, - &PINL, -}; - -const uint8_t PROGMEM digital_pin_to_port_PGM[] = { - // PORTLIST - // ------------------------------------------- - PE , // PE 0 ** 0 ** USART0_RX - PE , // PE 1 ** 1 ** USART0_TX - PE , // PE 4 ** 2 ** PWM2 - PE , // PE 5 ** 3 ** PWM3 - PG , // PG 5 ** 4 ** PWM4 - PE , // PE 3 ** 5 ** PWM5 - PH , // PH 3 ** 6 ** PWM6 - PH , // PH 4 ** 7 ** PWM7 - PH , // PH 5 ** 8 ** PWM8 - PH , // PH 6 ** 9 ** PWM9 - PB , // PB 4 ** 10 ** PWM10 - PB , // PB 5 ** 11 ** PWM11 - PB , // PB 6 ** 12 ** PWM12 - PB , // PB 7 ** 13 ** PWM13 - PJ , // PJ 1 ** 14 ** USART3_TX - PJ , // PJ 0 ** 15 ** USART3_RX - PH , // PH 1 ** 16 ** USART2_TX - PH , // PH 0 ** 17 ** USART2_RX - PD , // PD 3 ** 18 ** USART1_TX - PD , // PD 2 ** 19 ** USART1_RX - PD , // PD 1 ** 20 ** I2C_SDA - PD , // PD 0 ** 21 ** I2C_SCL - PA , // PA 0 ** 22 ** D22 - PA , // PA 1 ** 23 ** D23 - PA , // PA 2 ** 24 ** D24 - PA , // PA 3 ** 25 ** D25 - PA , // PA 4 ** 26 ** D26 - PA , // PA 5 ** 27 ** D27 - PA , // PA 6 ** 28 ** D28 - PA , // PA 7 ** 29 ** D29 - PC , // PC 7 ** 30 ** D30 - PC , // PC 6 ** 31 ** D31 - PC , // PC 5 ** 32 ** D32 - PC , // PC 4 ** 33 ** D33 - PC , // PC 3 ** 34 ** D34 - PC , // PC 2 ** 35 ** D35 - PC , // PC 1 ** 36 ** D36 - PC , // PC 0 ** 37 ** D37 - PD , // PD 7 ** 38 ** D38 - PG , // PG 2 ** 39 ** D39 - PG , // PG 1 ** 40 ** D40 - PG , // PG 0 ** 41 ** D41 - PL , // PL 7 ** 42 ** D42 - PL , // PL 6 ** 43 ** D43 - PL , // PL 5 ** 44 ** D44 - PL , // PL 4 ** 45 ** D45 - PL , // PL 3 ** 46 ** D46 - PL , // PL 2 ** 47 ** D47 - PL , // PL 1 ** 48 ** D48 - PL , // PL 0 ** 49 ** D49 - PB , // PB 3 ** 50 ** SPI_MISO - PB , // PB 2 ** 51 ** SPI_MOSI - PB , // PB 1 ** 52 ** SPI_SCK - PB , // PB 0 ** 53 ** SPI_SS - PF , // PF 0 ** 54 ** A0 - PF , // PF 1 ** 55 ** A1 - PF , // PF 2 ** 56 ** A2 - PF , // PF 3 ** 57 ** A3 - PF , // PF 4 ** 58 ** A4 - PF , // PF 5 ** 59 ** A5 - PF , // PF 6 ** 60 ** A6 - PF , // PF 7 ** 61 ** A7 - PK , // PK 0 ** 62 ** A8 - PK , // PK 1 ** 63 ** A9 - PK , // PK 2 ** 64 ** A10 - PK , // PK 3 ** 65 ** A11 - PK , // PK 4 ** 66 ** A12 - PK , // PK 5 ** 67 ** A13 - PK , // PK 6 ** 68 ** A14 - PK , // PK 7 ** 69 ** A15 -}; - -const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = { - // PIN IN PORT - // ------------------------------------------- - _BV( 0 ) , // PE 0 ** 0 ** USART0_RX - _BV( 1 ) , // PE 1 ** 1 ** USART0_TX - _BV( 4 ) , // PE 4 ** 2 ** PWM2 - _BV( 5 ) , // PE 5 ** 3 ** PWM3 - _BV( 5 ) , // PG 5 ** 4 ** PWM4 - _BV( 3 ) , // PE 3 ** 5 ** PWM5 - _BV( 3 ) , // PH 3 ** 6 ** PWM6 - _BV( 4 ) , // PH 4 ** 7 ** PWM7 - _BV( 5 ) , // PH 5 ** 8 ** PWM8 - _BV( 6 ) , // PH 6 ** 9 ** PWM9 - _BV( 4 ) , // PB 4 ** 10 ** PWM10 - _BV( 5 ) , // PB 5 ** 11 ** PWM11 - _BV( 6 ) , // PB 6 ** 12 ** PWM12 - _BV( 7 ) , // PB 7 ** 13 ** PWM13 - _BV( 1 ) , // PJ 1 ** 14 ** USART3_TX - _BV( 0 ) , // PJ 0 ** 15 ** USART3_RX - _BV( 1 ) , // PH 1 ** 16 ** USART2_TX - _BV( 0 ) , // PH 0 ** 17 ** USART2_RX - _BV( 3 ) , // PD 3 ** 18 ** USART1_TX - _BV( 2 ) , // PD 2 ** 19 ** USART1_RX - _BV( 1 ) , // PD 1 ** 20 ** I2C_SDA - _BV( 0 ) , // PD 0 ** 21 ** I2C_SCL - _BV( 0 ) , // PA 0 ** 22 ** D22 - _BV( 1 ) , // PA 1 ** 23 ** D23 - _BV( 2 ) , // PA 2 ** 24 ** D24 - _BV( 3 ) , // PA 3 ** 25 ** D25 - _BV( 4 ) , // PA 4 ** 26 ** D26 - _BV( 5 ) , // PA 5 ** 27 ** D27 - _BV( 6 ) , // PA 6 ** 28 ** D28 - _BV( 7 ) , // PA 7 ** 29 ** D29 - _BV( 7 ) , // PC 7 ** 30 ** D30 - _BV( 6 ) , // PC 6 ** 31 ** D31 - _BV( 5 ) , // PC 5 ** 32 ** D32 - _BV( 4 ) , // PC 4 ** 33 ** D33 - _BV( 3 ) , // PC 3 ** 34 ** D34 - _BV( 2 ) , // PC 2 ** 35 ** D35 - _BV( 1 ) , // PC 1 ** 36 ** D36 - _BV( 0 ) , // PC 0 ** 37 ** D37 - _BV( 7 ) , // PD 7 ** 38 ** D38 - _BV( 2 ) , // PG 2 ** 39 ** D39 - _BV( 1 ) , // PG 1 ** 40 ** D40 - _BV( 0 ) , // PG 0 ** 41 ** D41 - _BV( 7 ) , // PL 7 ** 42 ** D42 - _BV( 6 ) , // PL 6 ** 43 ** D43 - _BV( 5 ) , // PL 5 ** 44 ** D44 - _BV( 4 ) , // PL 4 ** 45 ** D45 - _BV( 3 ) , // PL 3 ** 46 ** D46 - _BV( 2 ) , // PL 2 ** 47 ** D47 - _BV( 1 ) , // PL 1 ** 48 ** D48 - _BV( 0 ) , // PL 0 ** 49 ** D49 - _BV( 3 ) , // PB 3 ** 50 ** SPI_MISO - _BV( 2 ) , // PB 2 ** 51 ** SPI_MOSI - _BV( 1 ) , // PB 1 ** 52 ** SPI_SCK - _BV( 0 ) , // PB 0 ** 53 ** SPI_SS - _BV( 0 ) , // PF 0 ** 54 ** A0 - _BV( 1 ) , // PF 1 ** 55 ** A1 - _BV( 2 ) , // PF 2 ** 56 ** A2 - _BV( 3 ) , // PF 3 ** 57 ** A3 - _BV( 4 ) , // PF 4 ** 58 ** A4 - _BV( 5 ) , // PF 5 ** 59 ** A5 - _BV( 6 ) , // PF 6 ** 60 ** A6 - _BV( 7 ) , // PF 7 ** 61 ** A7 - _BV( 0 ) , // PK 0 ** 62 ** A8 - _BV( 1 ) , // PK 1 ** 63 ** A9 - _BV( 2 ) , // PK 2 ** 64 ** A10 - _BV( 3 ) , // PK 3 ** 65 ** A11 - _BV( 4 ) , // PK 4 ** 66 ** A12 - _BV( 5 ) , // PK 5 ** 67 ** A13 - _BV( 6 ) , // PK 6 ** 68 ** A14 - _BV( 7 ) , // PK 7 ** 69 ** A15 -}; - -const uint8_t PROGMEM digital_pin_to_timer_PGM[] = { - // TIMERS - // ------------------------------------------- - NOT_ON_TIMER , // PE 0 ** 0 ** USART0_RX - NOT_ON_TIMER , // PE 1 ** 1 ** USART0_TX - TIMER3B , // PE 4 ** 2 ** PWM2 - TIMER3C , // PE 5 ** 3 ** PWM3 - TIMER0B , // PG 5 ** 4 ** PWM4 - TIMER3A , // PE 3 ** 5 ** PWM5 - TIMER4A , // PH 3 ** 6 ** PWM6 - TIMER4B , // PH 4 ** 7 ** PWM7 - TIMER4C , // PH 5 ** 8 ** PWM8 - TIMER2B , // PH 6 ** 9 ** PWM9 - TIMER2A , // PB 4 ** 10 ** PWM10 - TIMER1A , // PB 5 ** 11 ** PWM11 - TIMER1B , // PB 6 ** 12 ** PWM12 - TIMER0A , // PB 7 ** 13 ** PWM13 - NOT_ON_TIMER , // PJ 1 ** 14 ** USART3_TX - NOT_ON_TIMER , // PJ 0 ** 15 ** USART3_RX - NOT_ON_TIMER , // PH 1 ** 16 ** USART2_TX - NOT_ON_TIMER , // PH 0 ** 17 ** USART2_RX - NOT_ON_TIMER , // PD 3 ** 18 ** USART1_TX - NOT_ON_TIMER , // PD 2 ** 19 ** USART1_RX - NOT_ON_TIMER , // PD 1 ** 20 ** I2C_SDA - NOT_ON_TIMER , // PD 0 ** 21 ** I2C_SCL - NOT_ON_TIMER , // PA 0 ** 22 ** D22 - NOT_ON_TIMER , // PA 1 ** 23 ** D23 - NOT_ON_TIMER , // PA 2 ** 24 ** D24 - NOT_ON_TIMER , // PA 3 ** 25 ** D25 - NOT_ON_TIMER , // PA 4 ** 26 ** D26 - NOT_ON_TIMER , // PA 5 ** 27 ** D27 - NOT_ON_TIMER , // PA 6 ** 28 ** D28 - NOT_ON_TIMER , // PA 7 ** 29 ** D29 - NOT_ON_TIMER , // PC 7 ** 30 ** D30 - NOT_ON_TIMER , // PC 6 ** 31 ** D31 - NOT_ON_TIMER , // PC 5 ** 32 ** D32 - NOT_ON_TIMER , // PC 4 ** 33 ** D33 - NOT_ON_TIMER , // PC 3 ** 34 ** D34 - NOT_ON_TIMER , // PC 2 ** 35 ** D35 - NOT_ON_TIMER , // PC 1 ** 36 ** D36 - NOT_ON_TIMER , // PC 0 ** 37 ** D37 - NOT_ON_TIMER , // PD 7 ** 38 ** D38 - NOT_ON_TIMER , // PG 2 ** 39 ** D39 - NOT_ON_TIMER , // PG 1 ** 40 ** D40 - NOT_ON_TIMER , // PG 0 ** 41 ** D41 - NOT_ON_TIMER , // PL 7 ** 42 ** D42 - NOT_ON_TIMER , // PL 6 ** 43 ** D43 - TIMER5C , // PL 5 ** 44 ** D44 - TIMER5B , // PL 4 ** 45 ** D45 - TIMER5A , // PL 3 ** 46 ** D46 - NOT_ON_TIMER , // PL 2 ** 47 ** D47 - NOT_ON_TIMER , // PL 1 ** 48 ** D48 - NOT_ON_TIMER , // PL 0 ** 49 ** D49 - NOT_ON_TIMER , // PB 3 ** 50 ** SPI_MISO - NOT_ON_TIMER , // PB 2 ** 51 ** SPI_MOSI - NOT_ON_TIMER , // PB 1 ** 52 ** SPI_SCK - NOT_ON_TIMER , // PB 0 ** 53 ** SPI_SS - NOT_ON_TIMER , // PF 0 ** 54 ** A0 - NOT_ON_TIMER , // PF 1 ** 55 ** A1 - NOT_ON_TIMER , // PF 2 ** 56 ** A2 - NOT_ON_TIMER , // PF 3 ** 57 ** A3 - NOT_ON_TIMER , // PF 4 ** 58 ** A4 - NOT_ON_TIMER , // PF 5 ** 59 ** A5 - NOT_ON_TIMER , // PF 6 ** 60 ** A6 - NOT_ON_TIMER , // PF 7 ** 61 ** A7 - NOT_ON_TIMER , // PK 0 ** 62 ** A8 - NOT_ON_TIMER , // PK 1 ** 63 ** A9 - NOT_ON_TIMER , // PK 2 ** 64 ** A10 - NOT_ON_TIMER , // PK 3 ** 65 ** A11 - NOT_ON_TIMER , // PK 4 ** 66 ** A12 - NOT_ON_TIMER , // PK 5 ** 67 ** A13 - NOT_ON_TIMER , // PK 6 ** 68 ** A14 - NOT_ON_TIMER , // PK 7 ** 69 ** A15 -}; -#else -// these arrays map port names (e.g. port B) to the -// appropriate addresses for various functions (e.g. reading -// and writing) -const uint16_t PROGMEM port_to_mode_PGM[] = { - NOT_A_PORT, - NOT_A_PORT, - &DDRB, - &DDRC, - &DDRD, -}; - -const uint16_t PROGMEM port_to_output_PGM[] = { - NOT_A_PORT, - NOT_A_PORT, - &PORTB, - &PORTC, - &PORTD, -}; - -const uint16_t PROGMEM port_to_input_PGM[] = { - NOT_A_PORT, - NOT_A_PORT, - &PINB, - &PINC, - &PIND, -}; - -const uint8_t PROGMEM digital_pin_to_port_PGM[] = { - PD, /* 0 */ - PD, - PD, - PD, - PD, - PD, - PD, - PD, - PB, /* 8 */ - PB, - PB, - PB, - PB, - PB, - PC, /* 14 */ - PC, - PC, - PC, - PC, - PC, -}; - -const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = { - _BV(0), /* 0, port D */ - _BV(1), - _BV(2), - _BV(3), - _BV(4), - _BV(5), - _BV(6), - _BV(7), - _BV(0), /* 8, port B */ - _BV(1), - _BV(2), - _BV(3), - _BV(4), - _BV(5), - _BV(0), /* 14, port C */ - _BV(1), - _BV(2), - _BV(3), - _BV(4), - _BV(5), -}; - -const uint8_t PROGMEM digital_pin_to_timer_PGM[] = { - NOT_ON_TIMER, /* 0 - port D */ - NOT_ON_TIMER, - NOT_ON_TIMER, - // on the ATmega168, digital pin 3 has hardware pwm -#if defined(__AVR_ATmega8__) - NOT_ON_TIMER, -#else - TIMER2B, -#endif - NOT_ON_TIMER, - // on the ATmega168, digital pins 5 and 6 have hardware pwm -#if defined(__AVR_ATmega8__) - NOT_ON_TIMER, - NOT_ON_TIMER, -#else - TIMER0B, - TIMER0A, -#endif - NOT_ON_TIMER, - NOT_ON_TIMER, /* 8 - port B */ - TIMER1A, - TIMER1B, -#if defined(__AVR_ATmega8__) - TIMER2, -#else - TIMER2A, -#endif - NOT_ON_TIMER, - NOT_ON_TIMER, - NOT_ON_TIMER, - NOT_ON_TIMER, /* 14 - port C */ - NOT_ON_TIMER, - NOT_ON_TIMER, - NOT_ON_TIMER, - NOT_ON_TIMER, -}; -#endif diff --git a/arduino.DuinOS/pins_arduino.h b/arduino.DuinOS/pins_arduino.h deleted file mode 100644 index bc931c5..0000000 --- a/arduino.DuinOS/pins_arduino.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - pins_arduino.h - Pin definition functions for Arduino - Part of Arduino - http://www.arduino.cc/ - - Copyright (c) 2007 David A. Mellis - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General - Public License along with this library; if not, write to the - Free Software Foundation, Inc., 59 Temple Place, Suite 330, - Boston, MA 02111-1307 USA - - $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $ -*/ - -#ifndef Pins_Arduino_h -#define Pins_Arduino_h - -#include - -#define NOT_A_PIN 0 -#define NOT_A_PORT 0 - -#define NOT_ON_TIMER 0 -#define TIMER0A 1 -#define TIMER0B 2 -#define TIMER1A 3 -#define TIMER1B 4 -#define TIMER2 5 -#define TIMER2A 6 -#define TIMER2B 7 - -#define TIMER3A 8 -#define TIMER3B 9 -#define TIMER3C 10 -#define TIMER4A 11 -#define TIMER4B 12 -#define TIMER4C 13 -#define TIMER5A 14 -#define TIMER5B 15 -#define TIMER5C 16 - -#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) -const static uint8_t SS = 53; -const static uint8_t MOSI = 51; -const static uint8_t MISO = 50; -const static uint8_t SCK = 52; -#else -const static uint8_t SS = 10; -const static uint8_t MOSI = 11; -const static uint8_t MISO = 12; -const static uint8_t SCK = 13; -#endif - -// On the ATmega1280, the addresses of some of the port registers are -// greater than 255, so we can't store them in uint8_t's. -extern const uint16_t PROGMEM port_to_mode_PGM[]; -extern const uint16_t PROGMEM port_to_input_PGM[]; -extern const uint16_t PROGMEM port_to_output_PGM[]; - -extern const uint8_t PROGMEM digital_pin_to_port_PGM[]; -// extern const uint8_t PROGMEM digital_pin_to_bit_PGM[]; -extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[]; -extern const uint8_t PROGMEM digital_pin_to_timer_PGM[]; - -// Get the bit location within the hardware port of the given virtual pin. -// This comes from the pins_*.c file for the active board configuration. -// -// These perform slightly better as macros compared to inline functions -// -#define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) ) -#define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) ) -#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) ) -#define analogInPinToBit(P) (P) -#define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) ) -#define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) ) -#define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) ) - -#endif diff --git a/arduino.DuinOS/wiring.h b/arduino.DuinOS/wiring.h deleted file mode 100644 index 9ddc91e..0000000 --- a/arduino.DuinOS/wiring.h +++ /dev/null @@ -1,139 +0,0 @@ -/* - wiring.h - Partial implementation of the Wiring API for the ATmega8. - Part of Arduino - http://www.arduino.cc/ - - Copyright (c) 2005-2006 David A. Mellis - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General - Public License along with this library; if not, write to the - Free Software Foundation, Inc., 59 Temple Place, Suite 330, - Boston, MA 02111-1307 USA - - $Id$ -*/ - -#ifndef Wiring_h -#define Wiring_h - -#include -#include -#include "binary.h" - -#ifdef __cplusplus -extern "C"{ -#endif - -#define HIGH 0x1 -#define LOW 0x0 - -#define INPUT 0x0 -#define OUTPUT 0x1 - -#define true 0x1 -#define false 0x0 - -#define PI 3.1415926535897932384626433832795 -#define HALF_PI 1.5707963267948966192313216916398 -#define TWO_PI 6.283185307179586476925286766559 -#define DEG_TO_RAD 0.017453292519943295769236907684886 -#define RAD_TO_DEG 57.295779513082320876798154814105 - -#define SERIAL 0x0 -#define DISPLAY 0x1 - -#define LSBFIRST 0 -#define MSBFIRST 1 - -#define CHANGE 1 -#define FALLING 2 -#define RISING 3 - -#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) -#define INTERNAL1V1 2 -#define INTERNAL2V56 3 -#else -#define INTERNAL 3 -#endif -#define DEFAULT 1 -#define EXTERNAL 0 - -// undefine stdlib's abs if encountered -#ifdef abs -#undef abs -#endif - -#define min(a,b) ((a)<(b)?(a):(b)) -#define max(a,b) ((a)>(b)?(a):(b)) -#define abs(x) ((x)>0?(x):-(x)) -#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) -#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) -#define radians(deg) ((deg)*DEG_TO_RAD) -#define degrees(rad) ((rad)*RAD_TO_DEG) -#define sq(x) ((x)*(x)) - -#define interrupts() sei() -#define noInterrupts() cli() - -#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L ) -#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) -#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() ) - -#define lowByte(w) ((uint8_t) ((w) & 0xff)) -#define highByte(w) ((uint8_t) ((w) >> 8)) - -#define bitRead(value, bit) (((value) >> (bit)) & 0x01) -#define bitSet(value, bit) ((value) |= (1UL << (bit))) -#define bitClear(value, bit) ((value) &= ~(1UL << (bit))) -#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) - -typedef unsigned int word; - -#define bit(b) (1UL << (b)) - -typedef uint8_t boolean; -typedef uint8_t byte; - -void init(void); - -void pinMode(uint8_t, uint8_t); -void digitalWrite(uint8_t, uint8_t); -int digitalRead(uint8_t); -int analogRead(uint8_t); -void analogReference(uint8_t mode); -void analogWrite(uint8_t, int); - -unsigned long millis(void); -unsigned long micros(void); - -#ifndef DuinOS__h -// DuinOS overrides this: -void delay(unsigned long); -#endif - -void delayMicroseconds(unsigned int us); -unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout); - -void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val); -uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder); - -void attachInterrupt(uint8_t, void (*)(void), int mode); -void detachInterrupt(uint8_t); - -void setup(void); -void loop(void); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif diff --git a/examples/MoreComplexBlinking/MoreComplexBlinking.pde b/examples/DuinOS/MoreComplexBlinking/MoreComplexBlinking.pde similarity index 100% rename from examples/MoreComplexBlinking/MoreComplexBlinking.pde rename to examples/DuinOS/MoreComplexBlinking/MoreComplexBlinking.pde diff --git a/examples/MoreComplexBlinkingAndSound/MoreComplexBlinkingAndSound.pde b/examples/DuinOS/MoreComplexBlinkingAndSound/MoreComplexBlinkingAndSound.pde similarity index 100% rename from examples/MoreComplexBlinkingAndSound/MoreComplexBlinkingAndSound.pde rename to examples/DuinOS/MoreComplexBlinkingAndSound/MoreComplexBlinkingAndSound.pde diff --git a/hardware/boards.txt b/hardware/boards.txt index 846bf52..7351d65 100644 --- a/hardware/boards.txt +++ b/hardware/boards.txt @@ -31,7 +31,7 @@ uno_Duinos.bootloader.unlock_bits=0x3F uno_Duinos.bootloader.lock_bits=0x0F uno_Duinos.build.mcu=atmega328p uno_Duinos.build.f_cpu=16000000L -uno_Duinos.build.core=arduino.DuinOS +uno_Duinos.build.core=arduino.DuinOS.avr uno_Duinos.build.variant=standard ############################################################## @@ -129,6 +129,24 @@ mega2560.build.variant=mega ############################################################## +mega2560.name=Arduino Mega 2560 or Mega ADK +mega2560.upload.protocol=stk500v2 +mega2560.upload.maximum_size=258048 +mega2560.upload.speed=115200 +mega2560.bootloader.low_fuses=0xFF +mega2560.bootloader.high_fuses=0xD8 +mega2560.bootloader.extended_fuses=0xFD +mega2560.bootloader.path=stk500v2 +mega2560.bootloader.file=stk500boot_v2_mega2560.hex +mega2560.bootloader.unlock_bits=0x3F +mega2560.bootloader.lock_bits=0x0F +mega2560.build.mcu=atmega2560 +mega2560.build.f_cpu=16000000L +mega2560.build.core=arduino.DuinOS.avr +mega2560.build.variant=mega + +############################################################## + mega.name=Arduino Mega (ATmega1280) mega.upload.protocol=arduino mega.upload.maximum_size=126976 From 6817552be32d9781f6f29baf0d523f6803a904dc Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Thu, 1 Nov 2012 22:34:04 -0200 Subject: [PATCH 02/56] Adicionado suporte para Arduino Mega 2560 --- arduino.DuinOS.AVR/DuinOS/port.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/arduino.DuinOS.AVR/DuinOS/port.c b/arduino.DuinOS.AVR/DuinOS/port.c index 4afbbb0..f0faee6 100644 --- a/arduino.DuinOS.AVR/DuinOS/port.c +++ b/arduino.DuinOS.AVR/DuinOS/port.c @@ -226,7 +226,13 @@ static void prvSetupTimerInterrupt( void ); */ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ) { -unsigned portSHORT usAddress; + /* ATmega2560 DuinOS port by SkyWodd */ +#if defined(__AVR_ATmega2560__) + unsigned portLONG usAddress; // ATMega2560 have 22bit Program Counter register +#else + unsigned portSHORT usAddress; // over ATmega have 16bit Program Counter register +#endif + /* Place a few bytes of known values on the bottom of the stack. This is just useful for debugging. */ @@ -243,6 +249,23 @@ unsigned portSHORT usAddress; /*lint -e950 -e611 -e923 Lint doesn't like this much - but nothing I can do about it. */ +#if defined(__AVR_ATmega2560__) + // Implement normal stack initialisation but with portLONG instead of portSHORT + usAddress = ( unsigned portLONG ) pxCode; + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); + pxTopOfStack--; + + usAddress >>= 8; + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); + pxTopOfStack--; + + // Implemented the 3byte addressing + usAddress >>= 8; + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); + pxTopOfStack--; + +// Normal initialisation for over ATmega +#else /* The start of the task code will be popped off the stack last, so place it on first. */ usAddress = ( unsigned portSHORT ) pxCode; @@ -252,6 +275,7 @@ unsigned portSHORT usAddress; usAddress >>= 8; *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff ); pxTopOfStack--; +#endif /* Next simulate the stack as if after a call to portSAVE_CONTEXT(). portSAVE_CONTEXT places the flags on the stack immediately after r0 From c22b7421672d4c8320547c60e716046e6d4b3510 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Fri, 2 Nov 2012 19:18:58 -0200 Subject: [PATCH 03/56] =?UTF-8?q?Corre=C3=A7=C3=A3o=20do=20Arquivo=20board?= =?UTF-8?q?s.txt,=20para=20a=20vers=C3=A3o=20correta=20em=20uso=20no=20mom?= =?UTF-8?q?ento.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hardware/boards.txt | 319 +++++++++++++++++++++++++++++--------------- 1 file changed, 212 insertions(+), 107 deletions(-) diff --git a/hardware/boards.txt b/hardware/boards.txt index 7351d65..efafc4f 100644 --- a/hardware/boards.txt +++ b/hardware/boards.txt @@ -1,16 +1,21 @@ +# See: http://code.google.com/p/arduino/wiki/Platforms + ############################################################## -uno.name=Arduino Uno +uno.name=Arduino Uno +uno.upload.tool=avrdude uno.upload.protocol=arduino uno.upload.maximum_size=32256 uno.upload.speed=115200 -uno.bootloader.low_fuses=0xff -uno.bootloader.high_fuses=0xde + +uno.bootloader.tool=avrdude +uno.bootloader.low_fuses=0xFF +uno.bootloader.high_fuses=0xDE uno.bootloader.extended_fuses=0x05 -uno.bootloader.path=optiboot -uno.bootloader.file=optiboot_atmega328.hex uno.bootloader.unlock_bits=0x3F uno.bootloader.lock_bits=0x0F +uno.bootloader.file=optiboot/optiboot_atmega328.hex + uno.build.mcu=atmega328p uno.build.f_cpu=16000000L uno.build.core=arduino @@ -18,35 +23,42 @@ uno.build.variant=standard ############################################################## -uno_Duinos.name=Arduino Uno + Duinos -uno_Duinos.upload.protocol=arduino -uno_Duinos.upload.maximum_size=30720 -uno_Duinos.upload.speed=115200 -uno_Duinos.bootloader.low_fuses=0xff -uno_Duinos.bootloader.high_fuses=0xde -uno_Duinos.bootloader.extended_fuses=0x05 -uno_Duinos.bootloader.path=optiboot -uno_Duinos.bootloader.file=optiboot_atmega328.hex -uno_Duinos.bootloader.unlock_bits=0x3F -uno_Duinos.bootloader.lock_bits=0x0F -uno_Duinos.build.mcu=atmega328p -uno_Duinos.build.f_cpu=16000000L -uno_Duinos.build.core=arduino.DuinOS.avr -uno_Duinos.build.variant=standard +uno_DuinOS.name=Arduino Uno + DuinOS +uno_DuinOS.upload.tool=avrdude +uno_DuinOS.upload.protocol=arduino +uno_DuinOS.upload.maximum_size=32256 +uno_DuinOS.upload.speed=115200 + +uno_DuinOS.bootloader.tool=avrdude +uno_DuinOS.bootloader.low_fuses=0xFF +uno_DuinOS.bootloader.high_fuses=0xDE +uno_DuinOS.bootloader.extended_fuses=0x05 +uno_DuinOS.bootloader.unlock_bits=0x3F +uno_DuinOS.bootloader.lock_bits=0x0F +uno_DuinOS.bootloader.file=optiboot/optiboot_atmega328.hex + +uno_DuinOS.build.mcu=atmega328p +uno_DuinOS.build.f_cpu=16000000L +uno_DuinOS.build.core=arduino.DuinOS.AVR +uno_DuinOS.build.variant=standard ############################################################## atmega328.name=Arduino Duemilanove w/ ATmega328 + +atmega328.upload.tool=avrdude atmega328.upload.protocol=arduino atmega328.upload.maximum_size=30720 atmega328.upload.speed=57600 + +atmega328.bootloader.tool=avrdude atmega328.bootloader.low_fuses=0xFF atmega328.bootloader.high_fuses=0xDA atmega328.bootloader.extended_fuses=0x05 -atmega328.bootloader.path=atmega -atmega328.bootloader.file=ATmegaBOOT_168_atmega328.hex +atmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex atmega328.bootloader.unlock_bits=0x3F atmega328.bootloader.lock_bits=0x0F + atmega328.build.mcu=atmega328p atmega328.build.f_cpu=16000000L atmega328.build.core=arduino @@ -56,15 +68,16 @@ atmega328.build.variant=standard diecimila.name=Arduino Diecimila or Duemilanove w/ ATmega168 +diecimila.upload.tool=avrdude diecimila.upload.protocol=arduino diecimila.upload.maximum_size=14336 diecimila.upload.speed=19200 +diecimila.bootloader.tool=avrdude diecimila.bootloader.low_fuses=0xff diecimila.bootloader.high_fuses=0xdd diecimila.bootloader.extended_fuses=0x00 -diecimila.bootloader.path=atmega -diecimila.bootloader.file=ATmegaBOOT_168_diecimila.hex +diecimila.bootloader.file=atmega/ATmegaBOOT_168_diecimila.hex diecimila.bootloader.unlock_bits=0x3F diecimila.bootloader.lock_bits=0x0F @@ -76,16 +89,22 @@ diecimila.build.variant=standard ############################################################## nano328.name=Arduino Nano w/ ATmega328 +nano328.cpu=ATmega328 +nano328.container=Arduino Nano + +nano328.upload.tool=avrdude nano328.upload.protocol=arduino nano328.upload.maximum_size=30720 nano328.upload.speed=57600 + +nano328.bootloader.tool=avrdude nano328.bootloader.low_fuses=0xFF nano328.bootloader.high_fuses=0xDA nano328.bootloader.extended_fuses=0x05 -nano328.bootloader.path=atmega -nano328.bootloader.file=ATmegaBOOT_168_atmega328.hex +nano328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex nano328.bootloader.unlock_bits=0x3F nano328.bootloader.lock_bits=0x0F + nano328.build.mcu=atmega328p nano328.build.f_cpu=16000000L nano328.build.core=arduino @@ -94,16 +113,22 @@ nano328.build.variant=eightanaloginputs ############################################################## nano.name=Arduino Nano w/ ATmega168 +nano.cpu=ATmega168 +nano.container=Arduino Nano + +nano.upload.tool=avrdude nano.upload.protocol=arduino nano.upload.maximum_size=14336 nano.upload.speed=19200 + +nano.bootloader.tool=avrdude nano.bootloader.low_fuses=0xff nano.bootloader.high_fuses=0xdd nano.bootloader.extended_fuses=0x00 -nano.bootloader.path=atmega -nano.bootloader.file=ATmegaBOOT_168_diecimila.hex +nano.bootloader.file=atmega/ATmegaBOOT_168_diecimila.hex nano.bootloader.unlock_bits=0x3F nano.bootloader.lock_bits=0x0F + nano.build.mcu=atmega168 nano.build.f_cpu=16000000L nano.build.core=arduino @@ -112,16 +137,22 @@ nano.build.variant=eightanaloginputs ############################################################## mega2560.name=Arduino Mega 2560 or Mega ADK -mega2560.upload.protocol=stk500v2 +mega2560.cpu=2560 or ADK +mega2560.container=Arduino Mega 2560 + +mega2560.upload.tool=avrdude +mega2560.upload.protocol=wiring mega2560.upload.maximum_size=258048 mega2560.upload.speed=115200 + +mega2560.bootloader.tool=avrdude mega2560.bootloader.low_fuses=0xFF mega2560.bootloader.high_fuses=0xD8 mega2560.bootloader.extended_fuses=0xFD -mega2560.bootloader.path=stk500v2 -mega2560.bootloader.file=stk500boot_v2_mega2560.hex +mega2560.bootloader.file=stk500v2/stk500boot_v2_mega2560.hex mega2560.bootloader.unlock_bits=0x3F mega2560.bootloader.lock_bits=0x0F + mega2560.build.mcu=atmega2560 mega2560.build.f_cpu=16000000L mega2560.build.core=arduino @@ -129,35 +160,47 @@ mega2560.build.variant=mega ############################################################## -mega2560.name=Arduino Mega 2560 or Mega ADK -mega2560.upload.protocol=stk500v2 -mega2560.upload.maximum_size=258048 -mega2560.upload.speed=115200 -mega2560.bootloader.low_fuses=0xFF -mega2560.bootloader.high_fuses=0xD8 -mega2560.bootloader.extended_fuses=0xFD -mega2560.bootloader.path=stk500v2 -mega2560.bootloader.file=stk500boot_v2_mega2560.hex -mega2560.bootloader.unlock_bits=0x3F -mega2560.bootloader.lock_bits=0x0F -mega2560.build.mcu=atmega2560 -mega2560.build.f_cpu=16000000L -mega2560.build.core=arduino.DuinOS.avr -mega2560.build.variant=mega +mega2560_DuinOS.name=Arduino Mega 2560 or Mega ADK + DuinOS +mega2560_DuinOS.cpu=2560 or ADK +mega2560_DuinOS.container=Arduino Mega 2560 + DuinOS + +mega2560_DuinOS.upload.tool=avrdude +mega2560_DuinOS.upload.protocol=wiring +mega2560_DuinOS.upload.maximum_size=258048 +mega2560_DuinOS.upload.speed=115200 + +mega2560_DuinOS.bootloader.tool=avrdude +mega2560_DuinOS.bootloader.low_fuses=0xFF +mega2560_DuinOS.bootloader.high_fuses=0xD8 +mega2560_DuinOS.bootloader.extended_fuses=0xFD +mega2560_DuinOS.bootloader.file=stk500v2/stk500boot_v2_mega2560.hex +mega2560_DuinOS.bootloader.unlock_bits=0x3F +mega2560_DuinOS.bootloader.lock_bits=0x0F + +mega2560_DuinOS.build.mcu=atmega2560 +mega2560_DuinOS.build.f_cpu=16000000L +mega2560_DuinOS.build.core=arduino.DuinOS.AVR +mega2560_DuinOS.build.variant=mega ############################################################## mega.name=Arduino Mega (ATmega1280) +mega.cpu=ATmega1280 +mega.container=Arduino Mega 1280 + +mega.upload.tool=avrdude mega.upload.protocol=arduino mega.upload.maximum_size=126976 mega.upload.speed=57600 + +mega.bootloader.tool=avrdude mega.bootloader.low_fuses=0xFF mega.bootloader.high_fuses=0xDA mega.bootloader.extended_fuses=0xF5 -mega.bootloader.path=atmega -mega.bootloader.file=ATmegaBOOT_168_atmega1280.hex +mega.bootloader.file=atmega/ATmegaBOOT_168_atmega1280.hex mega.bootloader.unlock_bits=0x3F mega.bootloader.lock_bits=0x0F + mega.build.mcu=atmega1280 mega.build.f_cpu=16000000L mega.build.core=arduino @@ -165,53 +208,74 @@ mega.build.variant=mega ############################################################## -#leonardo.name=Arduino Leonardo -#leonardo.upload.protocol=arduino -#leonardo.upload.maximum_size=28672 -#leonardo.upload.speed=1200 -#leonardo.bootloader.low_fuses=0xde -#leonardo.bootloader.high_fuses=0xd8 -#leonardo.bootloader.extended_fuses=0xcb -#leonardo.bootloader.path=diskloader -#leonardo.bootloader.file=DiskLoader-Leonardo.hex -#leonardo.bootloader.unlock_bits=0x3F -#leonardo.bootloader.lock_bits=0x2F -#leonardo.build.mcu=atmega32u4 -#leonardo.build.f_cpu=16000000L -#leonardo.build.core=arduino -#leonardo.build.variant=leonardo +mega_DuinOS.name=Arduino Mega (ATmega1280) + DuinOS +mega_DuinOS.cpu=ATmega1280 +mega_DuinOS.container=Arduino Mega 1280 + DuinOS + +mega_DuinOS.upload.tool=avrdude +mega_DuinOS.upload.protocol=arduino +mega_DuinOS.upload.maximum_size=126976 +mega_DuinOS.upload.speed=57600 + +mega_DuinOS.bootloader.tool=avrdude +mega_DuinOS.bootloader.low_fuses=0xFF +mega_DuinOS.bootloader.high_fuses=0xDA +mega_DuinOS.bootloader.extended_fuses=0xF5 +mega_DuinOS.bootloader.file=atmega/ATmegaBOOT_168_atmega1280.hex +mega_DuinOS.bootloader.unlock_bits=0x3F +mega_DuinOS.bootloader.lock_bits=0x0F + +mega_DuinOS.build.mcu=atmega1280 +mega_DuinOS.build.f_cpu=16000000L +mega_DuinOS.build.core=arduino.DuinOS.AVR +mega_DuinOS.build.variant=mega ############################################################## -#micro.name=Arduino Micro -#micro.upload.protocol=arduino -#micro.upload.maximum_size=30720 -#micro.upload.speed=1200 -#micro.bootloader.low_fuses=0xde -#micro.bootloader.high_fuses=0xda -#micro.bootloader.extended_fuses=0xcb -#micro.bootloader.path=diskloader -#micro.bootloader.file=DiskLoader-Micro.hex -#micro.bootloader.unlock_bits=0x3F -#micro.bootloader.lock_bits=0x2F -#micro.build.mcu=atmega32u4 -#micro.build.f_cpu=16000000L -#micro.build.core=arduino -#micro.build.variant=micro +leonardo.name=Arduino Leonardo +leonardo.upload.tool=avrdude +leonardo.upload.protocol=avr109 +leonardo.upload.maximum_size=28672 +leonardo.upload.speed=57600 +leonardo.upload.disable_flushing=true +leonardo.upload.use_1200bps_touch=true +leonardo.upload.wait_for_upload_port=true + +leonardo.bootloader.tool=avrdude +leonardo.bootloader.low_fuses=0xff +leonardo.bootloader.high_fuses=0xd8 +leonardo.bootloader.extended_fuses=0xcb +leonardo.bootloader.file=caterina/Caterina-Leonardo.hex +leonardo.bootloader.unlock_bits=0x3F +leonardo.bootloader.lock_bits=0x2F + +leonardo.build.mcu=atmega32u4 +leonardo.build.f_cpu=16000000L +leonardo.build.vid=0x2341 +leonardo.build.pid=0x8036 +leonardo.build.core=arduino +leonardo.build.variant=leonardo +leonardo.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} ############################################################## mini328.name=Arduino Mini w/ ATmega328 -mini328.upload.protocol=stk500 +mini328.cpu=ATmega328 +mini328.container=Arduino Mini + +mini328.upload.tool=avrdude +mini328.upload.protocol=arduino mini328.upload.maximum_size=28672 mini328.upload.speed=115200 + +mini328.bootloader.tool=avrdude mini328.bootloader.low_fuses=0xff mini328.bootloader.high_fuses=0xd8 mini328.bootloader.extended_fuses=0x05 -mini328.bootloader.path=optiboot -mini328.bootloader.file=optiboot_atmega328-Mini.hex +mini328.bootloader.file=optiboot/optiboot_atmega328-Mini.hex mini328.bootloader.unlock_bits=0x3F mini328.bootloader.lock_bits=0x0F + mini328.build.mcu=atmega328p mini328.build.f_cpu=16000000L mini328.build.core=arduino @@ -220,16 +284,22 @@ mini328.build.variant=eightanaloginputs ############################################################## mini.name=Arduino Mini w/ ATmega168 +mini.cpu=ATmega168 +mini.container=Arduino Mini + +mini.upload.tool=avrdude mini.upload.protocol=arduino mini.upload.maximum_size=14336 mini.upload.speed=19200 + +mini.bootloader.tool=avrdude mini.bootloader.low_fuses=0xff mini.bootloader.high_fuses=0xdd mini.bootloader.extended_fuses=0x00 -mini.bootloader.path=atmega -mini.bootloader.file=ATmegaBOOT_168_ng.hex +mini.bootloader.file=atmega/ATmegaBOOT_168_ng.hex mini.bootloader.unlock_bits=0x3F mini.bootloader.lock_bits=0x0F + mini.build.mcu=atmega168 mini.build.f_cpu=16000000L mini.build.core=arduino @@ -238,16 +308,20 @@ mini.build.variant=eightanaloginputs ############################################################## ethernet.name=Arduino Ethernet + +ethernet.upload.tool=avrdude ethernet.upload.protocol=arduino ethernet.upload.maximum_size=32256 ethernet.upload.speed=115200 + +ethernet.bootloader.tool=avrdude ethernet.bootloader.low_fuses=0xff ethernet.bootloader.high_fuses=0xde ethernet.bootloader.extended_fuses=0x05 -ethernet.bootloader.path=optiboot -ethernet.bootloader.file=optiboot_atmega328.hex +ethernet.bootloader.file=optiboot/optiboot_atmega328.hex ethernet.bootloader.unlock_bits=0x3F ethernet.bootloader.lock_bits=0x0F + ethernet.build.variant=standard ethernet.build.mcu=atmega328p ethernet.build.f_cpu=16000000L @@ -257,15 +331,16 @@ ethernet.build.core=arduino fio.name=Arduino Fio +fio.upload.tool=avrdude fio.upload.protocol=arduino fio.upload.maximum_size=30720 fio.upload.speed=57600 +fio.bootloader.tool=avrdude fio.bootloader.low_fuses=0xFF fio.bootloader.high_fuses=0xDA fio.bootloader.extended_fuses=0x05 -fio.bootloader.path=arduino:atmega -fio.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex +fio.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex fio.bootloader.unlock_bits=0x3F fio.bootloader.lock_bits=0x0F @@ -277,17 +352,20 @@ fio.build.variant=eightanaloginputs ############################################################## bt328.name=Arduino BT w/ ATmega328 +bt328.cpu=ATmega328 +bt328.container=Arduino BT +bt328.upload.tool=avrdude bt328.upload.protocol=arduino bt328.upload.maximum_size=28672 bt328.upload.speed=19200 bt328.upload.disable_flushing=true +bt328.bootloader.tool=avrdude bt328.bootloader.low_fuses=0xff bt328.bootloader.high_fuses=0xd8 bt328.bootloader.extended_fuses=0x05 -bt328.bootloader.path=bt -bt328.bootloader.file=ATmegaBOOT_168_atmega328_bt.hex +bt328.bootloader.file=bt/ATmegaBOOT_168_atmega328_bt.hex bt328.bootloader.unlock_bits=0x3F bt328.bootloader.lock_bits=0x0F @@ -299,17 +377,20 @@ bt328.build.variant=eightanaloginputs ############################################################## bt.name=Arduino BT w/ ATmega168 +bt.cpu=ATmega168 +bt.container=Arduino BT +bt.upload.tool=avrdude bt.upload.protocol=arduino bt.upload.maximum_size=14336 bt.upload.speed=19200 bt.upload.disable_flushing=true +bt.bootloader.tool=avrdude bt.bootloader.low_fuses=0xff bt.bootloader.high_fuses=0xdd bt.bootloader.extended_fuses=0x00 -bt.bootloader.path=bt -bt.bootloader.file=ATmegaBOOT_168.hex +bt.bootloader.file=bt/ATmegaBOOT_168.hex bt.bootloader.unlock_bits=0x3F bt.bootloader.lock_bits=0x0F @@ -321,16 +402,19 @@ bt.build.variant=eightanaloginputs ############################################################## lilypad328.name=LilyPad Arduino w/ ATmega328 +lilypad328.cpu=ATmega328 +lilypad328.container=LilyPad Arduino +lilypad328.upload.tool=avrdude lilypad328.upload.protocol=arduino lilypad328.upload.maximum_size=30720 lilypad328.upload.speed=57600 +lilypad328.bootloader.tool=avrdude lilypad328.bootloader.low_fuses=0xFF lilypad328.bootloader.high_fuses=0xDA lilypad328.bootloader.extended_fuses=0x05 -lilypad328.bootloader.path=atmega -lilypad328.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex +lilypad328.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex lilypad328.bootloader.unlock_bits=0x3F lilypad328.bootloader.lock_bits=0x0F @@ -342,16 +426,19 @@ lilypad328.build.variant=standard ############################################################## lilypad.name=LilyPad Arduino w/ ATmega168 +lilypad.cpu=ATmega168 +lilypad.container=LilyPad Arduino +lilypad.upload.tool=avrdude lilypad.upload.protocol=arduino lilypad.upload.maximum_size=14336 lilypad.upload.speed=19200 +lilypad.bootloader.tool=avrdude lilypad.bootloader.low_fuses=0xe2 lilypad.bootloader.high_fuses=0xdd lilypad.bootloader.extended_fuses=0x00 -lilypad.bootloader.path=lilypad -lilypad.bootloader.file=LilyPadBOOT_168.hex +lilypad.bootloader.file=lilypad/LilyPadBOOT_168.hex lilypad.bootloader.unlock_bits=0x3F lilypad.bootloader.lock_bits=0x0F @@ -363,16 +450,19 @@ lilypad.build.variant=standard ############################################################## pro5v328.name=Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328 +pro5v328.cpu=ATmega328 (5V, 16 MHz) +pro5v328.container=Arduino Pro or Pro Mini +pro5v328.upload.tool=avrdude pro5v328.upload.protocol=arduino pro5v328.upload.maximum_size=30720 pro5v328.upload.speed=57600 +pro5v328.bootloader.tool=avrdude pro5v328.bootloader.low_fuses=0xFF pro5v328.bootloader.high_fuses=0xDA pro5v328.bootloader.extended_fuses=0x05 -pro5v328.bootloader.path=atmega -pro5v328.bootloader.file=ATmegaBOOT_168_atmega328.hex +pro5v328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex pro5v328.bootloader.unlock_bits=0x3F pro5v328.bootloader.lock_bits=0x0F @@ -384,16 +474,19 @@ pro5v328.build.variant=standard ############################################################## pro5v.name=Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega168 +pro5v.cpu=ATmega168 (5V, 16 MHz) +pro5v.container=Arduino Pro or Pro Mini +pro5v.upload.tool=avrdude pro5v.upload.protocol=arduino pro5v.upload.maximum_size=14336 pro5v.upload.speed=19200 +pro5v.bootloader.tool=avrdude pro5v.bootloader.low_fuses=0xff pro5v.bootloader.high_fuses=0xdd pro5v.bootloader.extended_fuses=0x00 -pro5v.bootloader.path=atmega -pro5v.bootloader.file=ATmegaBOOT_168_diecimila.hex +pro5v.bootloader.file=atmega/ATmegaBOOT_168_diecimila.hex pro5v.bootloader.unlock_bits=0x3F pro5v.bootloader.lock_bits=0x0F @@ -405,16 +498,19 @@ pro5v.build.variant=standard ############################################################## pro328.name=Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328 +pro328.cpu=ATmega328 (3.3V, 8 MHz) +pro328.container=Arduino Pro or Pro Mini +pro328.upload.tool=avrdude pro328.upload.protocol=arduino pro328.upload.maximum_size=30720 pro328.upload.speed=57600 +pro328.bootloader.tool=avrdude pro328.bootloader.low_fuses=0xFF pro328.bootloader.high_fuses=0xDA pro328.bootloader.extended_fuses=0x05 -pro328.bootloader.path=atmega -pro328.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex +pro328.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex pro328.bootloader.unlock_bits=0x3F pro328.bootloader.lock_bits=0x0F @@ -426,16 +522,19 @@ pro328.build.variant=standard ############################################################## pro.name=Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega168 +pro.cpu=ATmega168 (3.3V, 8 MHz) +pro.container=Arduino Pro or Pro Mini +pro.upload.tool=avrdude pro.upload.protocol=arduino pro.upload.maximum_size=14336 pro.upload.speed=19200 +pro.bootloader.tool=avrdude pro.bootloader.low_fuses=0xc6 pro.bootloader.high_fuses=0xdd pro.bootloader.extended_fuses=0x00 -pro.bootloader.path=atmega -pro.bootloader.file=ATmegaBOOT_168_pro_8MHz.hex +pro.bootloader.file=atmega/ATmegaBOOT_168_pro_8MHz.hex pro.bootloader.unlock_bits=0x3F pro.bootloader.lock_bits=0x0F @@ -447,16 +546,19 @@ pro.build.variant=standard ############################################################## atmega168.name=Arduino NG or older w/ ATmega168 +atmega168.cpu=ATmega168 +atmega168.container=Arduino NG or older +atmega168.upload.tool=avrdude atmega168.upload.protocol=arduino atmega168.upload.maximum_size=14336 atmega168.upload.speed=19200 +atmega168.bootloader.tool=avrdude atmega168.bootloader.low_fuses=0xff atmega168.bootloader.high_fuses=0xdd atmega168.bootloader.extended_fuses=0x00 -atmega168.bootloader.path=atmega -atmega168.bootloader.file=ATmegaBOOT_168_ng.hex +atmega168.bootloader.file=atmega/ATmegaBOOT_168_ng.hex atmega168.bootloader.unlock_bits=0x3F atmega168.bootloader.lock_bits=0x0F @@ -468,15 +570,18 @@ atmega168.build.variant=standard ############################################################## atmega8.name=Arduino NG or older w/ ATmega8 +atmega8.cpu=ATmega8 +atmega8.container=Arduino NG or older +atmega8.upload.tool=avrdude atmega8.upload.protocol=arduino atmega8.upload.maximum_size=7168 atmega8.upload.speed=19200 +atmega8.bootloader.tool=avrdude atmega8.bootloader.low_fuses=0xdf atmega8.bootloader.high_fuses=0xca -atmega8.bootloader.path=atmega8 -atmega8.bootloader.file=ATmegaBOOT.hex +atmega8.bootloader.file=atmega8/ATmegaBOOT.hex atmega8.bootloader.unlock_bits=0x3F atmega8.bootloader.lock_bits=0x0F From 4662b726284ce15cfd862ed092f19a1ea7af97ec Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Sat, 3 Nov 2012 10:38:56 -0200 Subject: [PATCH 04/56] =?UTF-8?q?instru=C3=A7=C3=B5es=20do=20Readme.txt=20?= =?UTF-8?q?atualizado.=20Arquivo=20boards.txt=20copiado=20para=20a=20pasta?= =?UTF-8?q?=20avr=20para=20manter=20separado=20informa=C3=A7=C3=B2es=20de?= =?UTF-8?q?=20cada=20tipo=20de=20MCU.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Readme.txt | 31 ++++++++++++++++++++----------- hardware/{ => avr}/boards.txt | 0 2 files changed, 20 insertions(+), 11 deletions(-) rename hardware/{ => avr}/boards.txt (100%) diff --git a/Readme.txt b/Readme.txt index 263e214..dd7cbf8 100644 --- a/Readme.txt +++ b/Readme.txt @@ -1,21 +1,24 @@ ******************************** - DuinOS v0.4 Alpha + DuinOS v0.6.1 Beta ******************************** Copyright (C) 2009 Multiplo http://multiplo.org http://robotgroup.com.ar Created by Julián U. da Silva Gillig. +Ported by Carlos Delfino {consultoria@carlosdelfino.eti.br} +Copyleft (C) 2012 Carlos Delfino e Amigos +http://www.carlosdelfino.eti.br -Based on the FreeRTOS v6.1.0 kernel (www.freertos.org). Please see the License section below. +Based on the FreeRTOS v7.3.0 kernel (www.freertos.org). Please see the License section below. This is our only distribution of DuinOS, which includes the complete source code. The last version is always available -from http://robotgroup.com.ar +from https://github.com/CarlosDelfino/DuinOS/downloads ******************************** License ******************************** -The DuinOS kernel (cores\arduino.DuinOS) is under the same license as the FreeRTOS operating system (www.freertos.org) +The DuinOS kernel (cores\arduino.DuinOS.*) is under the same license as the FreeRTOS operating system (www.freertos.org) Please see the included FreeRTOS.license.txt file. We have used too, some files belonging to the AVR port of the FreeRTOS operating system, made by Micropendous @@ -29,7 +32,7 @@ By Opendous Inc. www.Micropendous.org October 04, 2009 -Please visit www.micropendous.org if there is any doubt. +Please visit www.micropendous.org or contact consultoria@carlosdelfino.eti if there is any doubt NOTE: We strongly believe in peace, so we would not like to see our work in any non-civil or military project. But, due to the FreeRTOS's modified GPL license which we do have to maintain, this is only a recommendation and an expression of @@ -41,14 +44,14 @@ our wishes. ******************************** 0. Close the Arduino IDE (all instances). -1. Copy the arduino.DuinOS folder to the \hardware\cores folder. -2. Rename your current \hardware\boards.txt file. -3. Copy the boards.txt deployed with DuinOS to the \hardware folder. +1. Copy the arduino.DuinOS.* folder to the \hardware\arduino\*\cores folder. +2. Rename your current \hardware\arduino\*\boards.txt file. +3. Copy the *\boards.txt deployed with DuinOS to the \hardware\arduino\* folder, remember eatch borads.*.txt for respective hardware folder. 4. Rename your current \lib\keywords.txt file. 5. Copy the keywords.txt deployed with DuinOS to the \lib folder. 6. Start the Arduino IDE. 7. Please select any DuinOS board from the Tools->Board menu, like the "Arduino Duemilanove or Nano w/ ATmega328 + DuinOS". -8. Now, you can compile any standard project, but we suggest the \examples\MoreComplexBlinking deployed with DuinOS. +8. Now, you can compile any standard project, but we suggest the \examples\DuinOS\MoreComplexBlinking deployed with DuinOS. ******************************** Uninstall @@ -57,7 +60,7 @@ our wishes. 0. Close the Arduino IDE (all instances). 1. If you have renamed the original boards.txt file, delete the current boards.txt file and rename the previous one (so it will be now your new boards.txt). 2. If you have renamed the original keywords.txt file, delete the current keywords.txt file and rename the previous one (so it will be now your new keywords.txt). -3. Delete the arduino.DuinOS folder from the \cores folder. +3. Delete the arduino.DuinOS folder from the \cores\arduino\* folder. 4. Now you can restart the Arduino IDE and keep working without DuinOS. ******************************** @@ -112,4 +115,10 @@ MATERIALS ON THIS WEBSITE. - Use Timer0 for FreeRTOS - Remove Servo library (standard one should work) * 0. - +* 0. +* 0.6.1 Beta / 2012.01.01 (Carlos Delfino ) +- Arduino IDE updated to version 1.5.0 +- FreeRTOS updated to 7.3.0 +- Tested with MoreComplexBlinking example on Arduino UNO e Arduino Mega +- created a folder for eatch mcu (AVR and ARM) +- created a folder boards for eatch mcu \ No newline at end of file diff --git a/hardware/boards.txt b/hardware/avr/boards.txt similarity index 100% rename from hardware/boards.txt rename to hardware/avr/boards.txt From 1db6c11d2c8de6a1407ee6f17d1911d3fdafe4cc Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Sat, 3 Nov 2012 14:59:56 -0200 Subject: [PATCH 05/56] =?UTF-8?q?Inserido=20as=20macros=20que=20delimitam?= =?UTF-8?q?=20a=20area=20critica=20quando=20usando=20lcd.write(const=20cha?= =?UTF-8?q?r*).=20Ainda=20estou=20fazendo=20testes,=20continuo=20tendo=20p?= =?UTF-8?q?roblemas=20de=20travamento=20quando=20uso=20lcd.write(uint8=5Ft?= =?UTF-8?q?,mode),=20J=C3=A1=20tentei=20de=20diversas=20formas=20delimitan?= =?UTF-8?q?do=20a=20area=20critica,=20usando=20delays()=20mas=20n=C3=A3o?= =?UTF-8?q?=20obtive=20sucesso=20ainda.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/DuinOS/LCDMultiTask/LCDMultiTask.ino | 49 +++ libraries/LiquidCrystal2/LiquidCrystal2.cpp | 312 ++++++++++++++++++ libraries/LiquidCrystal2/LiquidCrystal2.h | 106 ++++++ .../examples/Autoscroll/Autoscroll.ino | 74 +++++ .../LiquidCrystal2/examples/Blink/Blink.ino | 61 ++++ .../LiquidCrystal2/examples/Cursor/Cursor.ino | 61 ++++ .../CustomCharacter/CustomCharacter.ino | 138 ++++++++ .../examples/Display/Display.ino | 61 ++++ .../examples/HelloWorld/HelloWorld.ino | 58 ++++ .../LiquidCrystal2/examples/Scroll/Scroll.ino | 86 +++++ .../examples/SerialDisplay/SerialDisplay.ino | 65 ++++ .../examples/TextDirection/TextDirection.ino | 86 +++++ .../examples/setCursor/setCursor.ino | 72 ++++ libraries/LiquidCrystal2/keywords.txt | 37 +++ 14 files changed, 1266 insertions(+) create mode 100644 examples/DuinOS/LCDMultiTask/LCDMultiTask.ino create mode 100644 libraries/LiquidCrystal2/LiquidCrystal2.cpp create mode 100755 libraries/LiquidCrystal2/LiquidCrystal2.h create mode 100644 libraries/LiquidCrystal2/examples/Autoscroll/Autoscroll.ino create mode 100644 libraries/LiquidCrystal2/examples/Blink/Blink.ino create mode 100644 libraries/LiquidCrystal2/examples/Cursor/Cursor.ino create mode 100644 libraries/LiquidCrystal2/examples/CustomCharacter/CustomCharacter.ino create mode 100644 libraries/LiquidCrystal2/examples/Display/Display.ino create mode 100644 libraries/LiquidCrystal2/examples/HelloWorld/HelloWorld.ino create mode 100644 libraries/LiquidCrystal2/examples/Scroll/Scroll.ino create mode 100644 libraries/LiquidCrystal2/examples/SerialDisplay/SerialDisplay.ino create mode 100644 libraries/LiquidCrystal2/examples/TextDirection/TextDirection.ino create mode 100644 libraries/LiquidCrystal2/examples/setCursor/setCursor.ino create mode 100755 libraries/LiquidCrystal2/keywords.txt diff --git a/examples/DuinOS/LCDMultiTask/LCDMultiTask.ino b/examples/DuinOS/LCDMultiTask/LCDMultiTask.ino new file mode 100644 index 0000000..e356825 --- /dev/null +++ b/examples/DuinOS/LCDMultiTask/LCDMultiTask.ino @@ -0,0 +1,49 @@ + +#include + + + +//LiquidCrystal lcd(10,11,2,3,4,5); +LiquidCrystal2 lcd(10,11,22,24,26,28); + +void setup(){ + lcd.begin(16,2); + + pinMode(8,OUTPUT); + pinMode(9,OUTPUT); + + analogWrite(8,200); // contraste + analogWrite(9,128); // brilho de fundo + lcd.write("1234567890123456"); +} + +volatile int x = 0; +void loop(){ + //lcd.write("1234567890123456"); + //lcd.write("1234567890123456"); + + +delay(3); + lcd.setCursor(0,1); +delay(3); + +//taskENTER_CRITICAL(); +lcd.write(x++); +//taskEXIT_CRITICAL(); + +lcd.print("teste "); + + for(int i=100;i<=200;i++) { + analogWrite(8,i); + delay(15); + } + for(int i=200;i>=100;i--) { + analogWrite(8,i); + delay(15); + } + + + +} + + diff --git a/libraries/LiquidCrystal2/LiquidCrystal2.cpp b/libraries/LiquidCrystal2/LiquidCrystal2.cpp new file mode 100644 index 0000000..674ad07 --- /dev/null +++ b/libraries/LiquidCrystal2/LiquidCrystal2.cpp @@ -0,0 +1,312 @@ +#include "LiquidCrystal2.h" + +#include +#include +#include +#include "Arduino.h" + +// When the display powers up, it is configured as follows: +// +// 1. Display clear +// 2. Function set: +// DL = 1; 8-bit interface data +// N = 0; 1-line display +// F = 0; 5x8 dot character font +// 3. Display on/off control: +// D = 0; Display off +// C = 0; Cursor off +// B = 0; Blinking off +// 4. Entry mode set: +// I/D = 1; Increment by 1 +// S = 0; No shift +// +// Note, however, that resetting the Arduino doesn't reset the LCD, so we +// can't assume that its in that state when a sketch starts (and the +// LiquidCrystal2 constructor is called). + +LiquidCrystal2::LiquidCrystal2(uint8_t rs, uint8_t rw, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, + uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) +{ + init(0, rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7); +} + +LiquidCrystal2::LiquidCrystal2(uint8_t rs, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, + uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) +{ + init(0, rs, 255, enable, d0, d1, d2, d3, d4, d5, d6, d7); +} + +LiquidCrystal2::LiquidCrystal2(uint8_t rs, uint8_t rw, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3) +{ + init(1, rs, rw, enable, d0, d1, d2, d3, 0, 0, 0, 0); +} + +LiquidCrystal2::LiquidCrystal2(uint8_t rs, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3) +{ + init(1, rs, 255, enable, d0, d1, d2, d3, 0, 0, 0, 0); +} + +void LiquidCrystal2::init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, + uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) +{ + _rs_pin = rs; + _rw_pin = rw; + _enable_pin = enable; + + _data_pins[0] = d0; + _data_pins[1] = d1; + _data_pins[2] = d2; + _data_pins[3] = d3; + _data_pins[4] = d4; + _data_pins[5] = d5; + _data_pins[6] = d6; + _data_pins[7] = d7; + + pinMode(_rs_pin, OUTPUT); + // we can save 1 pin by not using RW. Indicate by passing 255 instead of pin# + if (_rw_pin != 255) { + pinMode(_rw_pin, OUTPUT); + } + pinMode(_enable_pin, OUTPUT); + + if (fourbitmode) + _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS; + else + _displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS; + + begin(16, 1); +} + +void LiquidCrystal2::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) { + if (lines > 1) { + _displayfunction |= LCD_2LINE; + } + _numlines = lines; + _currline = 0; + + // for some 1 line displays you can select a 10 pixel high font + if ((dotsize != 0) && (lines == 1)) { + _displayfunction |= LCD_5x10DOTS; + } + + // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! + // according to datasheet, we need at least 40ms after power rises above 2.7V + // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50 + delayMicroseconds(50000); + // Now we pull both RS and R/W low to begin commands + digitalWrite(_rs_pin, LOW); + digitalWrite(_enable_pin, LOW); + if (_rw_pin != 255) { + digitalWrite(_rw_pin, LOW); + } + + //put the LCD into 4 bit or 8 bit mode + if (! (_displayfunction & LCD_8BITMODE)) { + // this is according to the hitachi HD44780 datasheet + // figure 24, pg 46 + + // we start in 8bit mode, try to set 4 bit mode + write4bits(0x03); + delayMicroseconds(4500); // wait min 4.1ms + + // second try + write4bits(0x03); + delayMicroseconds(4500); // wait min 4.1ms + + // third go! + write4bits(0x03); + delayMicroseconds(150); + + // finally, set to 4-bit interface + write4bits(0x02); + } else { + // this is according to the hitachi HD44780 datasheet + // page 45 figure 23 + + // Send function set command sequence + command(LCD_FUNCTIONSET | _displayfunction); + delayMicroseconds(4500); // wait more than 4.1ms + + // second try + command(LCD_FUNCTIONSET | _displayfunction); + delayMicroseconds(150); + + // third go + command(LCD_FUNCTIONSET | _displayfunction); + } + + // finally, set # lines, font size, etc. + command(LCD_FUNCTIONSET | _displayfunction); + + // turn the display on with no cursor or blinking default + _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; + display(); + + // clear it off + clear(); + + // Initialize to default text direction (for romance languages) + _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; + // set the entry mode + command(LCD_ENTRYMODESET | _displaymode); + +} + +/********** high level commands, for the user! */ +void LiquidCrystal2::clear() +{ + command(LCD_CLEARDISPLAY); // clear display, set cursor position to zero + delayMicroseconds(2000); // this command takes a long time! +} + +void LiquidCrystal2::home() +{ + command(LCD_RETURNHOME); // set cursor position to zero + delayMicroseconds(2000); // this command takes a long time! +} + +void LiquidCrystal2::setCursor(uint8_t col, uint8_t row) +{ + int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 }; + if ( row >= _numlines ) { + row = _numlines-1; // we count rows starting w/0 + } + + command(LCD_SETDDRAMADDR | (col + row_offsets[row])); +} + +// Turn the display on/off (quickly) +void LiquidCrystal2::noDisplay() { + _displaycontrol &= ~LCD_DISPLAYON; + command(LCD_DISPLAYCONTROL | _displaycontrol); +} +void LiquidCrystal2::display() { + _displaycontrol |= LCD_DISPLAYON; + command(LCD_DISPLAYCONTROL | _displaycontrol); +} + +// Turns the underline cursor on/off +void LiquidCrystal2::noCursor() { + _displaycontrol &= ~LCD_CURSORON; + command(LCD_DISPLAYCONTROL | _displaycontrol); +} +void LiquidCrystal2::cursor() { + _displaycontrol |= LCD_CURSORON; + command(LCD_DISPLAYCONTROL | _displaycontrol); +} + +// Turn on and off the blinking cursor +void LiquidCrystal2::noBlink() { + _displaycontrol &= ~LCD_BLINKON; + command(LCD_DISPLAYCONTROL | _displaycontrol); +} +void LiquidCrystal2::blink() { + _displaycontrol |= LCD_BLINKON; + command(LCD_DISPLAYCONTROL | _displaycontrol); +} + +// These commands scroll the display without changing the RAM +void LiquidCrystal2::scrollDisplayLeft(void) { + command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT); +} +void LiquidCrystal2::scrollDisplayRight(void) { + command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT); +} + +// This is for text that flows Left to Right +void LiquidCrystal2::leftToRight(void) { + _displaymode |= LCD_ENTRYLEFT; + command(LCD_ENTRYMODESET | _displaymode); +} + +// This is for text that flows Right to Left +void LiquidCrystal2::rightToLeft(void) { + _displaymode &= ~LCD_ENTRYLEFT; + command(LCD_ENTRYMODESET | _displaymode); +} + +// This will 'right justify' text from the cursor +void LiquidCrystal2::autoscroll(void) { + _displaymode |= LCD_ENTRYSHIFTINCREMENT; + command(LCD_ENTRYMODESET | _displaymode); +} + +// This will 'left justify' text from the cursor +void LiquidCrystal2::noAutoscroll(void) { + _displaymode &= ~LCD_ENTRYSHIFTINCREMENT; + command(LCD_ENTRYMODESET | _displaymode); +} + +// Allows us to fill the first 8 CGRAM locations +// with custom characters +void LiquidCrystal2::createChar(uint8_t location, uint8_t charmap[]) { + location &= 0x7; // we only have 8 locations 0-7 + command(LCD_SETCGRAMADDR | (location << 3)); + for (int i=0; i<8; i++) { + write(charmap[i]); + } +} + +/*********** mid level commands, for sending data/cmds */ + +inline void LiquidCrystal2::command(uint8_t value) { + send(value, LOW); +} + +inline size_t LiquidCrystal2::write(uint8_t value) { + send(value, HIGH); + return 1; // assume sucess +} + +/************ low level data pushing commands **********/ + +// write either command or data, with automatic 4/8-bit selection +void LiquidCrystal2::send(uint8_t value, uint8_t mode) { + taskENTER_CRITICAL(); + digitalWrite(_rs_pin, mode); + + // if there is a RW pin indicated, set it low to Write + if (_rw_pin != 255) { + digitalWrite(_rw_pin, LOW); + } + + if (_displayfunction & LCD_8BITMODE) { + write8bits(value); + } else { + write4bits(value>>4); + write4bits(value); + } + taskEXIT_CRITICAL(); +} + +void LiquidCrystal2::pulseEnable(void) { + digitalWrite(_enable_pin, LOW); + delayMicroseconds(1); + digitalWrite(_enable_pin, HIGH); + delayMicroseconds(1); // enable pulse must be >450ns + digitalWrite(_enable_pin, LOW); + delayMicroseconds(100); // commands need > 37us to settle +} + +void LiquidCrystal2::write4bits(uint8_t value) { + for (int i = 0; i < 4; i++) { + pinMode(_data_pins[i], OUTPUT); + digitalWrite(_data_pins[i], (value >> i) & 0x01); + } + + pulseEnable(); +} + +void LiquidCrystal2::write8bits(uint8_t value) { + for (int i = 0; i < 8; i++) { + pinMode(_data_pins[i], OUTPUT); + digitalWrite(_data_pins[i], (value >> i) & 0x01); + } + + pulseEnable(); +} diff --git a/libraries/LiquidCrystal2/LiquidCrystal2.h b/libraries/LiquidCrystal2/LiquidCrystal2.h new file mode 100755 index 0000000..e693f9d --- /dev/null +++ b/libraries/LiquidCrystal2/LiquidCrystal2.h @@ -0,0 +1,106 @@ +#ifndef LiquidCrystal2_h +#define LiquidCrystal2_h + +#include +#include "Print.h" + +// commands +#define LCD_CLEARDISPLAY 0x01 +#define LCD_RETURNHOME 0x02 +#define LCD_ENTRYMODESET 0x04 +#define LCD_DISPLAYCONTROL 0x08 +#define LCD_CURSORSHIFT 0x10 +#define LCD_FUNCTIONSET 0x20 +#define LCD_SETCGRAMADDR 0x40 +#define LCD_SETDDRAMADDR 0x80 + +// flags for display entry mode +#define LCD_ENTRYRIGHT 0x00 +#define LCD_ENTRYLEFT 0x02 +#define LCD_ENTRYSHIFTINCREMENT 0x01 +#define LCD_ENTRYSHIFTDECREMENT 0x00 + +// flags for display on/off control +#define LCD_DISPLAYON 0x04 +#define LCD_DISPLAYOFF 0x00 +#define LCD_CURSORON 0x02 +#define LCD_CURSOROFF 0x00 +#define LCD_BLINKON 0x01 +#define LCD_BLINKOFF 0x00 + +// flags for display/cursor shift +#define LCD_DISPLAYMOVE 0x08 +#define LCD_CURSORMOVE 0x00 +#define LCD_MOVERIGHT 0x04 +#define LCD_MOVELEFT 0x00 + +// flags for function set +#define LCD_8BITMODE 0x10 +#define LCD_4BITMODE 0x00 +#define LCD_2LINE 0x08 +#define LCD_1LINE 0x00 +#define LCD_5x10DOTS 0x04 +#define LCD_5x8DOTS 0x00 + +class LiquidCrystal2 : public Print { +public: + LiquidCrystal2(uint8_t rs, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, + uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); + LiquidCrystal2(uint8_t rs, uint8_t rw, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, + uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); + LiquidCrystal2(uint8_t rs, uint8_t rw, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); + LiquidCrystal2(uint8_t rs, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); + + void init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, + uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); + + void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS); + + void clear(); + void home(); + + void noDisplay(); + void display(); + void noBlink(); + void blink(); + void noCursor(); + void cursor(); + void scrollDisplayLeft(); + void scrollDisplayRight(); + void leftToRight(); + void rightToLeft(); + void autoscroll(); + void noAutoscroll(); + + void createChar(uint8_t, uint8_t[]); + void setCursor(uint8_t, uint8_t); + virtual size_t write(uint8_t); + void command(uint8_t); + + using Print::write; +private: + void send(uint8_t, uint8_t); + void write4bits(uint8_t); + void write8bits(uint8_t); + void pulseEnable(); + + uint8_t _rs_pin; // LOW: command. HIGH: character. + uint8_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD. + uint8_t _enable_pin; // activated by a HIGH pulse. + uint8_t _data_pins[8]; + + uint8_t _displayfunction; + uint8_t _displaycontrol; + uint8_t _displaymode; + + uint8_t _initialized; + + uint8_t _numlines,_currline; +}; + +#endif diff --git a/libraries/LiquidCrystal2/examples/Autoscroll/Autoscroll.ino b/libraries/LiquidCrystal2/examples/Autoscroll/Autoscroll.ino new file mode 100644 index 0000000..c77167f --- /dev/null +++ b/libraries/LiquidCrystal2/examples/Autoscroll/Autoscroll.ino @@ -0,0 +1,74 @@ +/* + LiquidCrystal2 Library - Autoscroll + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal2 + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch demonstrates the use of the autoscroll() + and noAutoscroll() functions to make new text scroll or not. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + + This example code is in the public domain. + + http://arduino.cc/en/Tutorial/LiquidCrystal2Autoscroll + + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal2 lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16,2); +} + +void loop() { + // set the cursor to (0,0): + lcd.setCursor(0, 0); + // print from 0 to 9: + for (int thisChar = 0; thisChar < 10; thisChar++) { + lcd.print(thisChar); + delay(500); + } + + // set the cursor to (16,1): + lcd.setCursor(16,1); + // set the display to automatically scroll: + lcd.autoscroll(); + // print from 0 to 9: + for (int thisChar = 0; thisChar < 10; thisChar++) { + lcd.print(thisChar); + delay(500); + } + // turn off automatic scrolling + lcd.noAutoscroll(); + + // clear screen for the next loop: + lcd.clear(); +} + diff --git a/libraries/LiquidCrystal2/examples/Blink/Blink.ino b/libraries/LiquidCrystal2/examples/Blink/Blink.ino new file mode 100644 index 0000000..b70210d --- /dev/null +++ b/libraries/LiquidCrystal2/examples/Blink/Blink.ino @@ -0,0 +1,61 @@ +/* + LiquidCrystal2 Library - Blink + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal2 + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "Hello World!" to the LCD and makes the + cursor block blink. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + + This example code is in the public domain. + + http://arduino.cc/en/Tutorial/LiquidCrystal2Blink + + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal2 lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); +} + +void loop() { + // Turn off the blinking cursor: + lcd.noBlink(); + delay(3000); + // Turn on the blinking cursor: + lcd.blink(); + delay(3000); +} + + diff --git a/libraries/LiquidCrystal2/examples/Cursor/Cursor.ino b/libraries/LiquidCrystal2/examples/Cursor/Cursor.ino new file mode 100644 index 0000000..d10a0b8 --- /dev/null +++ b/libraries/LiquidCrystal2/examples/Cursor/Cursor.ino @@ -0,0 +1,61 @@ +/* + LiquidCrystal2 Library - Cursor + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal2 + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "Hello World!" to the LCD and + uses the cursor() and noCursor() methods to turn + on and off the cursor. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + + This example code is in the public domain. + + http://arduino.cc/en/Tutorial/LiquidCrystal2Cursor + + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal2 lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); +} + +void loop() { + // Turn off the cursor: + lcd.noCursor(); + delay(500); + // Turn on the cursor: + lcd.cursor(); + delay(500); +} + diff --git a/libraries/LiquidCrystal2/examples/CustomCharacter/CustomCharacter.ino b/libraries/LiquidCrystal2/examples/CustomCharacter/CustomCharacter.ino new file mode 100644 index 0000000..4c9d1a3 --- /dev/null +++ b/libraries/LiquidCrystal2/examples/CustomCharacter/CustomCharacter.ino @@ -0,0 +1,138 @@ +/* + LiquidCrystal2 Library - Custom Characters + + Demonstrates how to add custom characters on an LCD display. + The LiquidCrystal2 library works with all LCD displays that are + compatible with the Hitachi HD44780 driver. There are many of + them out there, and you can usually tell them by the 16-pin interface. + + This sketch prints "I Arduino!" and a little dancing man + to the LCD. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K potentiometer: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + * 10K poterntiometer on pin A0 + + created21 Mar 2011 + by Tom Igoe + Based on Adafruit's example at + https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde + + This example code is in the public domain. + http://www.arduino.cc/en/Tutorial/LiquidCrystal2 + + Also useful: + http://icontexto.com/charactercreator/ + + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal2 lcd(12, 11, 5, 4, 3, 2); + +// make some custom characters: +byte heart[8] = { + 0b00000, + 0b01010, + 0b11111, + 0b11111, + 0b11111, + 0b01110, + 0b00100, + 0b00000 +}; + +byte smiley[8] = { + 0b00000, + 0b00000, + 0b01010, + 0b00000, + 0b00000, + 0b10001, + 0b01110, + 0b00000 +}; + +byte frownie[8] = { + 0b00000, + 0b00000, + 0b01010, + 0b00000, + 0b00000, + 0b00000, + 0b01110, + 0b10001 +}; + +byte armsDown[8] = { + 0b00100, + 0b01010, + 0b00100, + 0b00100, + 0b01110, + 0b10101, + 0b00100, + 0b01010 +}; + +byte armsUp[8] = { + 0b00100, + 0b01010, + 0b00100, + 0b10101, + 0b01110, + 0b00100, + 0b00100, + 0b01010 +}; +void setup() { + // create a new character + lcd.createChar(0, heart); + // create a new character + lcd.createChar(1, smiley); + // create a new character + lcd.createChar(2, frownie); + // create a new character + lcd.createChar(3, armsDown); + // create a new character + lcd.createChar(4, armsUp); + + // set up the lcd's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the lcd. + lcd.print("I "); + lcd.write(0); + lcd.print(" Arduino! "); + lcd.write(1); + +} + +void loop() { + // read the potentiometer on A0: + int sensorReading = analogRead(A0); + // map the result to 200 - 1000: + int delayTime = map(sensorReading, 0, 1023, 200, 1000); + // set the cursor to the bottom row, 5th position: + lcd.setCursor(4, 1); + // draw the little man, arms down: + lcd.write(3); + delay(delayTime); + lcd.setCursor(4, 1); + // draw him arms up: + lcd.write(4); + delay(delayTime); +} + + + diff --git a/libraries/LiquidCrystal2/examples/Display/Display.ino b/libraries/LiquidCrystal2/examples/Display/Display.ino new file mode 100644 index 0000000..7bd38e1 --- /dev/null +++ b/libraries/LiquidCrystal2/examples/Display/Display.ino @@ -0,0 +1,61 @@ +/* + LiquidCrystal2 Library - display() and noDisplay() + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal2 + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "Hello World!" to the LCD and uses the + display() and noDisplay() functions to turn on and off + the display. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + + This example code is in the public domain. + + http://arduino.cc/en/Tutorial/LiquidCrystal2Display + + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal2 lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); +} + +void loop() { + // Turn off the display: + lcd.noDisplay(); + delay(500); + // Turn on the display: + lcd.display(); + delay(500); +} + diff --git a/libraries/LiquidCrystal2/examples/HelloWorld/HelloWorld.ino b/libraries/LiquidCrystal2/examples/HelloWorld/HelloWorld.ino new file mode 100644 index 0000000..65b6de8 --- /dev/null +++ b/libraries/LiquidCrystal2/examples/HelloWorld/HelloWorld.ino @@ -0,0 +1,58 @@ +/* + LiquidCrystal2 Library - Hello World + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal2 + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "Hello World!" to the LCD + and shows the time. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + + This example code is in the public domain. + + http://www.arduino.cc/en/Tutorial/LiquidCrystal2 + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal2 lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); +} + +void loop() { + // set the cursor to column 0, line 1 + // (note: line 1 is the second row, since counting begins with 0): + lcd.setCursor(0, 1); + // print the number of seconds since reset: + lcd.print(millis()/1000); +} + diff --git a/libraries/LiquidCrystal2/examples/Scroll/Scroll.ino b/libraries/LiquidCrystal2/examples/Scroll/Scroll.ino new file mode 100644 index 0000000..2af978e --- /dev/null +++ b/libraries/LiquidCrystal2/examples/Scroll/Scroll.ino @@ -0,0 +1,86 @@ +/* + LiquidCrystal2 Library - scrollDisplayLeft() and scrollDisplayRight() + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal2 + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "Hello World!" to the LCD and uses the + scrollDisplayLeft() and scrollDisplayRight() methods to scroll + the text. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + + This example code is in the public domain. + + http://arduino.cc/en/Tutorial/LiquidCrystal2Scroll + + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal2 lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); + delay(1000); +} + +void loop() { + // scroll 13 positions (string length) to the left + // to move it offscreen left: + for (int positionCounter = 0; positionCounter < 13; positionCounter++) { + // scroll one position left: + lcd.scrollDisplayLeft(); + // wait a bit: + delay(150); + } + + // scroll 29 positions (string length + display length) to the right + // to move it offscreen right: + for (int positionCounter = 0; positionCounter < 29; positionCounter++) { + // scroll one position right: + lcd.scrollDisplayRight(); + // wait a bit: + delay(150); + } + + // scroll 16 positions (display length + string length) to the left + // to move it back to center: + for (int positionCounter = 0; positionCounter < 16; positionCounter++) { + // scroll one position left: + lcd.scrollDisplayLeft(); + // wait a bit: + delay(150); + } + + // delay at the end of the full loop: + delay(1000); + +} + diff --git a/libraries/LiquidCrystal2/examples/SerialDisplay/SerialDisplay.ino b/libraries/LiquidCrystal2/examples/SerialDisplay/SerialDisplay.ino new file mode 100644 index 0000000..191e9de --- /dev/null +++ b/libraries/LiquidCrystal2/examples/SerialDisplay/SerialDisplay.ino @@ -0,0 +1,65 @@ +/* + LiquidCrystal2 Library - Serial Input + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal2 + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch displays text sent over the serial port + (e.g. from the Serial Monitor) on an attached LCD. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + + This example code is in the public domain. + + http://arduino.cc/en/Tutorial/LiquidCrystal2Serial + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal2 lcd(12, 11, 5, 4, 3, 2); + +void setup(){ + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // initialize the serial communications: + Serial.begin(9600); +} + +void loop() +{ + // when characters arrive over the serial port... + if (Serial.available()) { + // wait a bit for the entire message to arrive + delay(100); + // clear the screen + lcd.clear(); + // read all the available characters + while (Serial.available() > 0) { + // display each character to the LCD + lcd.write(Serial.read()); + } + } +} diff --git a/libraries/LiquidCrystal2/examples/TextDirection/TextDirection.ino b/libraries/LiquidCrystal2/examples/TextDirection/TextDirection.ino new file mode 100644 index 0000000..7d3b939 --- /dev/null +++ b/libraries/LiquidCrystal2/examples/TextDirection/TextDirection.ino @@ -0,0 +1,86 @@ + /* + LiquidCrystal22 Library - TextDirection + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal2 + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch demonstrates how to use leftToRight() and rightToLeft() + to move the cursor. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + + This example code is in the public domain. + + http://arduino.cc/en/Tutorial/LiquidCrystal2TextDirection + + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal22 lcd(12, 11, 5, 4, 3, 2); + +int thisChar = 'a'; + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // turn on the cursor: + lcd.cursor(); +} + +void loop() { + // reverse directions at 'm': + if (thisChar == 'm') { + // go right for the next letter + lcd.rightToLeft(); + } + // reverse again at 's': + if (thisChar == 's') { + // go left for the next letter + lcd.leftToRight(); + } + // reset at 'z': + if (thisChar > 'z') { + // go to (0,0): + lcd.home(); + // start again at 0 + thisChar = 'a'; + } + // print the character + lcd.write(thisChar); + // wait a second: + delay(1000); + // increment the letter: + thisChar++; +} + + + + + + + + diff --git a/libraries/LiquidCrystal2/examples/setCursor/setCursor.ino b/libraries/LiquidCrystal2/examples/setCursor/setCursor.ino new file mode 100644 index 0000000..f3bc593 --- /dev/null +++ b/libraries/LiquidCrystal2/examples/setCursor/setCursor.ino @@ -0,0 +1,72 @@ +/* + LiquidCrystal2 Library - setCursor + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal2 + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints to all the positions of the LCD using the + setCursor(0 method: + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + + This example code is in the public domain. + + http://arduino.cc/en/Tutorial/LiquidCrystal2SetCursor + + */ + +// include the library code: +#include + +// these constants won't change. But you can change the size of +// your LCD using them: +const int numRows = 2; +const int numCols = 16; + +// initialize the library with the numbers of the interface pins +LiquidCrystal2 lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(numCols,numRows); +} + +void loop() { + // loop from ASCII 'a' to ASCII 'z': + for (int thisLetter = 'a'; thisLetter <= 'z'; thisLetter++) { + // loop over the columns: + for (int thisCol = 0; thisCol < numRows; thisCol++) { + // loop over the rows: + for (int thisRow = 0; thisRow < numCols; thisRow++) { + // set the cursor position: + lcd.setCursor(thisRow,thisCol); + // print the letter: + lcd.write(thisLetter); + delay(200); + } + } + } +} + + diff --git a/libraries/LiquidCrystal2/keywords.txt b/libraries/LiquidCrystal2/keywords.txt new file mode 100755 index 0000000..faeaf95 --- /dev/null +++ b/libraries/LiquidCrystal2/keywords.txt @@ -0,0 +1,37 @@ +####################################### +# Syntax Coloring Map For LiquidCrystal2 +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +LiquidCrystal2 KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +begin KEYWORD2 +clear KEYWORD2 +home KEYWORD2 +print KEYWORD2 +setCursor KEYWORD2 +cursor KEYWORD2 +noCursor KEYWORD2 +blink KEYWORD2 +noBlink KEYWORD2 +display KEYWORD2 +noDisplay KEYWORD2 +autoscroll KEYWORD2 +noAutoscroll KEYWORD2 +leftToRight KEYWORD2 +rightToLeft KEYWORD2 +scrollDisplayLeft KEYWORD2 +scrollDisplayRight KEYWORD2 +createChar KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### + From 3c922a42cfe5ebe0c565ab01ef5d60dc609a8c46 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Sat, 3 Nov 2012 15:05:55 -0200 Subject: [PATCH 06/56] =?UTF-8?q?FreeRTOSConfig=20alterado=20para=20ativar?= =?UTF-8?q?=20o=20vApplicationTickHook=20que=20substitui=20a=20fun=C3=A7?= =?UTF-8?q?=C3=A3o=20arduinoTickHook.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arduino.DuinOS.AVR/FreeRTOSConfig.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arduino.DuinOS.AVR/FreeRTOSConfig.h b/arduino.DuinOS.AVR/FreeRTOSConfig.h index 32106e5..fc3aeab 100644 --- a/arduino.DuinOS.AVR/FreeRTOSConfig.h +++ b/arduino.DuinOS.AVR/FreeRTOSConfig.h @@ -81,7 +81,7 @@ //##Multiplo.Brain.M644: #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 0 - #define configUSE_TICK_HOOK 0 + #define configUSE_TICK_HOOK 1 //##20091029: Use compiler defined freq.: #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) @@ -121,7 +121,7 @@ //##Multiplo.Brain.M1284 #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 0 - #define configUSE_TICK_HOOK 0 + #define configUSE_TICK_HOOK 1 //##20091029: Use compiler defined freq.: #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) @@ -161,7 +161,7 @@ #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 0 - #define configUSE_TICK_HOOK 0 + #define configUSE_TICK_HOOK 1 //##20091029: Use compiler defined freq.: #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) @@ -202,7 +202,7 @@ #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 0 - #define configUSE_TICK_HOOK 0 + #define configUSE_TICK_HOOK 1 //##20091029: Use compiler defined freq.: #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) @@ -242,7 +242,7 @@ #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 0 - #define configUSE_TICK_HOOK 0 + #define configUSE_TICK_HOOK 1 //##20091029: Use compiler defined freq.: #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) @@ -281,7 +281,7 @@ #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 0 - #define configUSE_TICK_HOOK 0 + #define configUSE_TICK_HOOK 1 //##20091029: Use compiler defined freq.: #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) From 9814d55346da8567f43002d7ea1b33101f2d23f3 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Sat, 3 Nov 2012 19:49:51 -0200 Subject: [PATCH 07/56] =?UTF-8?q?corrigido=20o=20problema=20que=20impedia?= =?UTF-8?q?=20a=20execu=C3=A7=C3=A3o=20da=20fun=C3=A7=C3=A3o=20delay()=20d?= =?UTF-8?q?entro=20do=20setup().=20Criei=20uma=20nova=20estrutura=20em=20m?= =?UTF-8?q?ain.c=20onde=20a=20fun=C3=A7=C3=A3o=20setup()=20passa=20a=20ser?= =?UTF-8?q?=20uma=20tarefa=20executada=20uma=20unica=20vez=20antes=20de=20?= =?UTF-8?q?loop()=20que=20est=C3=A1=20em=20estado=20suspenso=20at=C3=A9=20?= =?UTF-8?q?que=20setup()=20setup=20termine=20e=20seja=20posta=20em=20modo?= =?UTF-8?q?=20suspenso.=20Para=20o=20arduino=20mega=20setup=20ser=C3=A1=20?= =?UTF-8?q?removido=20quando=20loop()=20for=20iniciado.=20Estarei=20verifi?= =?UTF-8?q?cando=20se=20=C3=A9=20interessante=20ativar=20vTaskDelete()=20p?= =?UTF-8?q?ara=20outros=20ATMega=20por=20quest=C3=B5es=20de=20memoria.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arduino.DuinOS.AVR/DuinOS.h | 3 +++ arduino.DuinOS.AVR/FreeRTOSConfig.h | 2 +- arduino.DuinOS.AVR/main.cpp | 30 ++++++++++++++++++++++++----- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/arduino.DuinOS.AVR/DuinOS.h b/arduino.DuinOS.AVR/DuinOS.h index e835765..59869bc 100644 --- a/arduino.DuinOS.AVR/DuinOS.h +++ b/arduino.DuinOS.AVR/DuinOS.h @@ -79,6 +79,9 @@ inline void delay(const portTickType ticks) vTaskDelayUntil( &xLastWakeTime, ticks); } */ +#if INCLUDE_vTaskDelete + #define deleteTask(name) vTaskDelete(name); +#endif //This macro is quiet different from setPriority, because this works even in those CPUs wich does not support //the set/getPriority macros (due to their small RAM memories). And, this only has effect if called in setup(). diff --git a/arduino.DuinOS.AVR/FreeRTOSConfig.h b/arduino.DuinOS.AVR/FreeRTOSConfig.h index fc3aeab..b0b1ce3 100644 --- a/arduino.DuinOS.AVR/FreeRTOSConfig.h +++ b/arduino.DuinOS.AVR/FreeRTOSConfig.h @@ -231,7 +231,7 @@ #define INCLUDE_vTaskPrioritySet 1 #define INCLUDE_uxTaskPriorityGet 1 //##If the following value is set to 1, change the memory managment scheme to heap_2.c: - #define INCLUDE_vTaskDelete 0 + #define INCLUDE_vTaskDelete 1 #define INCLUDE_vTaskCleanUpResources 0 #define INCLUDE_vTaskSuspend 1 #define INCLUDE_vTaskDelayUntil 1 diff --git a/arduino.DuinOS.AVR/main.cpp b/arduino.DuinOS.AVR/main.cpp index efa2b7f..a81d078 100644 --- a/arduino.DuinOS.AVR/main.cpp +++ b/arduino.DuinOS.AVR/main.cpp @@ -1,9 +1,16 @@ #include + unsigned portBASE_TYPE mainLoopPriority; +xTaskHandle xHandleLoop; +xTaskHandle xHandleSetup; + void main_Task(void *pvParameters) { +#if INCLUDE_vTaskDelete + vTaskDelete(xHandleSetup); +#endif for (;;) { loop(); if (serialEventRun) serialEventRun(); @@ -11,6 +18,15 @@ void main_Task(void *pvParameters) } +void setup_Task(void *pvParameters) +{ + + setup(); + vTaskResume(xHandleLoop); + vTaskSuspend(NULL); + +} + int main(void) { mainLoopPriority = LOW_PRIORITY; @@ -19,12 +35,16 @@ int main(void) #if defined(USBCON) USBDevice.attach(); #endif - - setup(); - - xTaskCreate(main_Task, (signed portCHAR *) "main", configMINIMAL_STACK_SIZE, NULL, mainLoopPriority, NULL); + +// setup(); + + xTaskCreate(setup_Task, (signed portCHAR *) "setup", configMINIMAL_STACK_SIZE, NULL, HIGH_PRIORITY, &xHandleSetup); + + xTaskCreate(main_Task, (signed portCHAR *) "main", configMINIMAL_STACK_SIZE, NULL, mainLoopPriority, &xHandleLoop); + vTaskSuspend(xHandleLoop); + vTaskStartScheduler(); - + for (;;); return 0; From 54a312b97fe038942abfc1abbe1053e27ad4d681 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Mon, 12 Nov 2012 14:52:47 -0200 Subject: [PATCH 08/56] =?UTF-8?q?Arquivo=20removido,=20n=C3=A3o=20=C3=A9?= =?UTF-8?q?=20necess=C3=A1rio.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hardware/boards-test.txt | 675 --------------------------------------- 1 file changed, 675 deletions(-) delete mode 100644 hardware/boards-test.txt diff --git a/hardware/boards-test.txt b/hardware/boards-test.txt deleted file mode 100644 index 4aa3a23..0000000 --- a/hardware/boards-test.txt +++ /dev/null @@ -1,675 +0,0 @@ -############################################################## - -uno.name=Arduino Uno -uno.upload.protocol=stk500 -uno.upload.maximum_size=32256 -uno.upload.speed=115200 -uno.bootloader.low_fuses=0xff -uno.bootloader.high_fuses=0xde -uno.bootloader.extended_fuses=0x05 -uno.bootloader.path=optiboot -uno.bootloader.file=optiboot_atmega328.hex -uno.bootloader.unlock_bits=0x3F -uno.bootloader.lock_bits=0x0F -uno.build.mcu=atmega328p -uno.build.f_cpu=16000000L -uno.build.core=arduino - -############################################################## - -uno_DuinOS.name=Arduino Uno + DuinOS -uno_DuinOS.upload.protocol=stk500 -uno_DuinOS.upload.maximum_size=32256 -uno_DuinOS.upload.speed=115200 -uno_DuinOS.bootloader.low_fuses=0xff -uno_DuinOS.bootloader.high_fuses=0xde -uno_DuinOS.bootloader.extended_fuses=0x05 -uno_DuinOS.bootloader.path=optiboot -uno_DuinOS.bootloader.file=optiboot_atmega328.hex -uno_DuinOS.bootloader.unlock_bits=0x3F -uno_DuinOS.bootloader.lock_bits=0x0F -uno_DuinOS.build.mcu=atmega328p -uno_DuinOS.build.f_cpu=16000000L -uno_DuinOS.build.core=arduino.DuinOS - -############################################################## - -atmega328.name=Arduino Duemilanove or Nano w/ ATmega328 - -atmega328.upload.protocol=stk500 -atmega328.upload.maximum_size=30720 -atmega328.upload.speed=57600 - -atmega328.bootloader.low_fuses=0xFF -atmega328.bootloader.high_fuses=0xDA -atmega328.bootloader.extended_fuses=0x05 -atmega328.bootloader.path=atmega -atmega328.bootloader.file=ATmegaBOOT_168_atmega328.hex -atmega328.bootloader.unlock_bits=0x3F -atmega328.bootloader.lock_bits=0x0F - -atmega328.build.mcu=atmega328p -atmega328.build.f_cpu=16000000L -atmega328.build.core=arduino - -############################################################## - -atmega328_DuinOS.name=Arduino Duemilanove or Nano w/ ATmega328 + DuinOS - -atmega328_DuinOS.upload.protocol=stk500 -atmega328_DuinOS.upload.maximum_size=30720 -atmega328_DuinOS.upload.speed=57600 - -atmega328_DuinOS.bootloader.low_fuses=0xFF -atmega328_DuinOS.bootloader.high_fuses=0xDA -atmega328_DuinOS.bootloader.extended_fuses=0x05 -atmega328_DuinOS.bootloader.path=atmega -atmega328_DuinOS.bootloader.file=ATmegaBOOT_168_atmega328.hex -atmega328_DuinOS.bootloader.unlock_bits=0x3F -atmega328_DuinOS.bootloader.lock_bits=0x0F - -atmega328_DuinOS.build.mcu=atmega328p -atmega328_DuinOS.build.f_cpu=16000000L -atmega328_DuinOS.build.core=arduino.DuinOS - -############################################################## - -diecimila.name=Arduino Diecimila, Duemilanove, or Nano w/ ATmega168 - -diecimila.upload.protocol=stk500 -diecimila.upload.maximum_size=14336 -diecimila.upload.speed=19200 - -diecimila.bootloader.low_fuses=0xff -diecimila.bootloader.high_fuses=0xdd -diecimila.bootloader.extended_fuses=0x00 -diecimila.bootloader.path=atmega -diecimila.bootloader.file=ATmegaBOOT_168_diecimila.hex -diecimila.bootloader.unlock_bits=0x3F -diecimila.bootloader.lock_bits=0x0F - -diecimila.build.mcu=atmega168 -diecimila.build.f_cpu=16000000L -diecimila.build.core=arduino - -############################################################## - -diecimila_DuinOS.name=Arduino Diecimila, Duemilanove, or Nano w/ ATmega168 + DuinOS - -diecimila_DuinOS.upload.protocol=stk500 -diecimila_DuinOS.upload.maximum_size=14336 -diecimila_DuinOS.upload.speed=19200 - -diecimila_DuinOS.bootloader.low_fuses=0xff -diecimila_DuinOS.bootloader.high_fuses=0xdd -diecimila_DuinOS.bootloader.extended_fuses=0x00 -diecimila_DuinOS.bootloader.path=atmega -diecimila_DuinOS.bootloader.file=ATmegaBOOT_168_diecimila.hex -diecimila_DuinOS.bootloader.unlock_bits=0x3F -diecimila_DuinOS.bootloader.lock_bits=0x0F - -diecimila_DuinOS.build.mcu=atmega168 -diecimila_DuinOS.build.f_cpu=16000000L -diecimila_DuinOS.build.core=arduino.DuinOS - -############################################################## - -mega2560.name=Arduino Mega 2560 - -mega2560.upload.protocol=stk500v2 -mega2560.upload.maximum_size=258048 -mega2560.upload.speed=115200 - -mega2560.bootloader.low_fuses=0xFF -mega2560.bootloader.high_fuses=0xD8 -mega2560.bootloader.extended_fuses=0xFD -mega2560.bootloader.path=stk500v2 -mega2560.bootloader.file=stk500boot_v2_mega2560.hex -mega2560.bootloader.unlock_bits=0x3F -mega2560.bootloader.lock_bits=0x0F - -mega2560.build.mcu=atmega2560 -mega2560.build.f_cpu=16000000L -mega2560.build.core=arduino - -############################################################## - -mega2560_DuinOS.name=Arduino Mega 2560 + DuinOS - -mega2560_DuinOS.upload.protocol=stk500v2 -mega2560_DuinOS.upload.maximum_size=258048 -mega2560_DuinOS.upload.speed=115200 - -mega2560_DuinOS.bootloader.low_fuses=0xFF -mega2560_DuinOS.bootloader.high_fuses=0xD8 -mega2560_DuinOS.bootloader.extended_fuses=0xFD -mega2560_DuinOS.bootloader.path=stk500v2 -mega2560_DuinOS.bootloader.file=stk500boot_v2_mega2560.hex -mega2560_DuinOS.bootloader.unlock_bits=0x3F -mega2560_DuinOS.bootloader.lock_bits=0x0F - -mega2560_DuinOS.build.mcu=atmega2560 -mega2560_DuinOS.build.f_cpu=16000000L -mega2560_DuinOS.build.core=arduino.DuinOS - -############################################################## - -mega.name=Arduino Mega (ATmega1280) - -mega.upload.protocol=stk500 -mega.upload.maximum_size=126976 -mega.upload.speed=57600 - -mega.bootloader.low_fuses=0xFF -mega.bootloader.high_fuses=0xDA -mega.bootloader.extended_fuses=0xF5 -mega.bootloader.path=atmega -mega.bootloader.file=ATmegaBOOT_168_atmega1280.hex -mega.bootloader.unlock_bits=0x3F -mega.bootloader.lock_bits=0x0F - -mega.build.mcu=atmega1280 -mega.build.f_cpu=16000000L -mega.build.core=arduino - -############################################################## - -mega_DuinOS.name=Arduino Mega (ATmega1280) + DuinOS - -mega_DuinOS.upload.protocol=stk500 -mega_DuinOS.upload.maximum_size=126976 -mega_DuinOS.upload.speed=57600 - -mega_DuinOS.bootloader.low_fuses=0xFF -mega_DuinOS.bootloader.high_fuses=0xDA -mega_DuinOS.bootloader.extended_fuses=0xF5 -mega_DuinOS.bootloader.path=atmega -mega_DuinOS.bootloader.file=ATmegaBOOT_168_atmega1280.hex -mega_DuinOS.bootloader.unlock_bits=0x3F -mega_DuinOS.bootloader.lock_bits=0x0F - -mega_DuinOS.build.mcu=atmega1280 -mega_DuinOS.build.f_cpu=16000000L -mega_DuinOS.build.core=arduino.DuinOS - -############################################################## - -mini.name=Arduino Mini - -mini.upload.protocol=stk500 -mini.upload.maximum_size=14336 -mini.upload.speed=19200 - -mini.bootloader.low_fuses=0xff -mini.bootloader.high_fuses=0xdd -mini.bootloader.extended_fuses=0x00 -mini.bootloader.path=atmega -mini.bootloader.file=ATmegaBOOT_168_ng.hex -mini.bootloader.unlock_bits=0x3F -mini.bootloader.lock_bits=0x0F - -mini.build.mcu=atmega168 -mini.build.f_cpu=16000000L -mini.build.core=arduino - -############################################################## - -mini_DuinOS.name=Arduino Mini + DuinOS - -mini_DuinOS.upload.protocol=stk500 -mini_DuinOS.upload.maximum_size=14336 -mini_DuinOS.upload.speed=19200 - -mini_DuinOS.bootloader.low_fuses=0xff -mini_DuinOS.bootloader.high_fuses=0xdd -mini_DuinOS.bootloader.extended_fuses=0x00 -mini_DuinOS.bootloader.path=atmega -mini_DuinOS.bootloader.file=ATmegaBOOT_168_ng.hex -mini_DuinOS.bootloader.unlock_bits=0x3F -mini_DuinOS.bootloader.lock_bits=0x0F - -mini_DuinOS.build.mcu=atmega168 -mini_DuinOS.build.f_cpu=16000000L -mini_DuinOS.build.core=arduino.DuinOS - -############################################################## - -fio.name=Arduino Fio - -fio.upload.protocol=stk500 -fio.upload.maximum_size=30720 -fio.upload.speed=57600 - -fio.bootloader.low_fuses=0xFF -fio.bootloader.high_fuses=0xDA -fio.bootloader.extended_fuses=0x05 -fio.bootloader.path=arduino:atmega -fio.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex -fio.bootloader.unlock_bits=0x3F -fio.bootloader.lock_bits=0x0F - -fio.build.mcu=atmega328p -fio.build.f_cpu=8000000L -fio.build.core=arduino:arduino - -############################################################## - -fio_DuinOS.name=Arduino Fio + DuinOS - -fio_DuinOS.upload.protocol=stk500 -fio_DuinOS.upload.maximum_size=30720 -fio_DuinOS.upload.speed=57600 - -fio_DuinOS.bootloader.low_fuses=0xFF -fio_DuinOS.bootloader.high_fuses=0xDA -fio_DuinOS.bootloader.extended_fuses=0x05 -fio_DuinOS.bootloader.path=arduino:atmega -fio_DuinOS.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex -fio_DuinOS.bootloader.unlock_bits=0x3F -fio_DuinOS.bootloader.lock_bits=0x0F - -fio_DuinOS.build.mcu=atmega328p -fio_DuinOS.build.f_cpu=8000000L -fio_DuinOS.build.core=arduino.DuinOS - -############################################################## - -bt328.name=Arduino BT w/ ATmega328 - -bt328.upload.protocol=stk500 -bt328.upload.maximum_size=28672 -bt328.upload.speed=19200 -bt328.upload.disable_flushing=true - -bt328.bootloader.low_fuses=0xff -bt328.bootloader.high_fuses=0xd8 -bt328.bootloader.extended_fuses=0x05 -bt328.bootloader.path=bt -bt328.bootloader.file=ATmegaBOOT_168_atmega328_bt.hex -bt328.bootloader.unlock_bits=0x3F -bt328.bootloader.lock_bits=0x0F - -bt328.build.mcu=atmega328p -bt328.build.f_cpu=16000000L -bt328.build.core=arduino - -############################################################## - -bt328_DuinOS.name=Arduino BT w/ ATmega328 + DuinOS - -bt328_DuinOS.upload.protocol=stk500 -bt328_DuinOS.upload.maximum_size=28672 -bt328_DuinOS.upload.speed=19200 -bt328_DuinOS.upload.disable_flushing=true - -bt328_DuinOS.bootloader.low_fuses=0xff -bt328_DuinOS.bootloader.high_fuses=0xd8 -bt328_DuinOS.bootloader.extended_fuses=0x05 -bt328_DuinOS.bootloader.path=bt -bt328_DuinOS.bootloader.file=ATmegaBOOT_168_atmega328_bt.hex -bt328_DuinOS.bootloader.unlock_bits=0x3F -bt328_DuinOS.bootloader.lock_bits=0x0F - -bt328_DuinOS.build.mcu=atmega328p -bt328_DuinOS.build.f_cpu=16000000L -bt328_DuinOS.build.core=arduino.DuinOS - -############################################################## - -bt.name=Arduino BT w/ ATmega168 - -bt.upload.protocol=stk500 -bt.upload.maximum_size=14336 -bt.upload.speed=19200 -bt.upload.disable_flushing=true - -bt.bootloader.low_fuses=0xff -bt.bootloader.high_fuses=0xdd -bt.bootloader.extended_fuses=0x00 -bt.bootloader.path=bt -bt.bootloader.file=ATmegaBOOT_168.hex -bt.bootloader.unlock_bits=0x3F -bt.bootloader.lock_bits=0x0F - -bt.build.mcu=atmega168 -bt.build.f_cpu=16000000L -bt.build.core=arduino - -############################################################## - -bt_DuinOS.name=Arduino BT w/ ATmega168 + DuinOS - -bt_DuinOS.upload.protocol=stk500 -bt_DuinOS.upload.maximum_size=14336 -bt_DuinOS.upload.speed=19200 -bt_DuinOS.upload.disable_flushing=true - -bt_DuinOS.bootloader.low_fuses=0xff -bt_DuinOS.bootloader.high_fuses=0xdd -bt_DuinOS.bootloader.extended_fuses=0x00 -bt_DuinOS.bootloader.path=bt -bt_DuinOS.bootloader.file=ATmegaBOOT_168.hex -bt_DuinOS.bootloader.unlock_bits=0x3F -bt_DuinOS.bootloader.lock_bits=0x0F - -bt_DuinOS.build.mcu=atmega168 -bt_DuinOS.build.f_cpu=16000000L -bt_DuinOS.build.core=arduino.DuinOS - -############################################################## - -lilypad328.name=LilyPad Arduino w/ ATmega328 - -lilypad328.upload.protocol=stk500 -lilypad328.upload.maximum_size=30720 -lilypad328.upload.speed=57600 - -lilypad328.bootloader.low_fuses=0xFF -lilypad328.bootloader.high_fuses=0xDA -lilypad328.bootloader.extended_fuses=0x05 -lilypad328.bootloader.path=atmega -lilypad328.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex -lilypad328.bootloader.unlock_bits=0x3F -lilypad328.bootloader.lock_bits=0x0F - -lilypad328.build.mcu=atmega328p -lilypad328.build.f_cpu=8000000L -lilypad328.build.core=arduino - -############################################################## - -lilypad328_DuinOS.name=LilyPad Arduino w/ ATmega328 + DuinOS - -lilypad328_DuinOS.upload.protocol=stk500 -lilypad328_DuinOS.upload.maximum_size=30720 -lilypad328_DuinOS.upload.speed=57600 - -lilypad328_DuinOS.bootloader.low_fuses=0xFF -lilypad328_DuinOS.bootloader.high_fuses=0xDA -lilypad328_DuinOS.bootloader.extended_fuses=0x05 -lilypad328_DuinOS.bootloader.path=atmega -lilypad328_DuinOS.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex -lilypad328_DuinOS.bootloader.unlock_bits=0x3F -lilypad328_DuinOS.bootloader.lock_bits=0x0F - -lilypad328_DuinOS.build.mcu=atmega328p -lilypad328_DuinOS.build.f_cpu=8000000L -lilypad328_DuinOS.build.core=arduino.DuinOS - -############################################################## - -lilypad.name=LilyPad Arduino w/ ATmega168 - -lilypad.upload.protocol=stk500 -lilypad.upload.maximum_size=14336 -lilypad.upload.speed=19200 - -lilypad.bootloader.low_fuses=0xe2 -lilypad.bootloader.high_fuses=0xdd -lilypad.bootloader.extended_fuses=0x00 -lilypad.bootloader.path=lilypad -lilypad.bootloader.file=LilyPadBOOT_168.hex -lilypad.bootloader.unlock_bits=0x3F -lilypad.bootloader.lock_bits=0x0F - -lilypad.build.mcu=atmega168 -lilypad.build.f_cpu=8000000L -lilypad.build.core=arduino - -############################################################## - -lilypad_DuinOS.name=LilyPad Arduino w/ ATmega168 + DuinOS - -lilypad_DuinOS.upload.protocol=stk500 -lilypad_DuinOS.upload.maximum_size=14336 -lilypad_DuinOS.upload.speed=19200 - -lilypad_DuinOS.bootloader.low_fuses=0xe2 -lilypad_DuinOS.bootloader.high_fuses=0xdd -lilypad_DuinOS.bootloader.extended_fuses=0x00 -lilypad_DuinOS.bootloader.path=lilypad -lilypad_DuinOS.bootloader.file=LilyPadBOOT_168.hex -lilypad_DuinOS.bootloader.unlock_bits=0x3F -lilypad_DuinOS.bootloader.lock_bits=0x0F - -lilypad_DuinOS.build.mcu=atmega168 -lilypad_DuinOS.build.f_cpu=8000000L -lilypad_DuinOS.build.core=arduino.DuinOS - -############################################################## - -pro5v328.name=Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328 - -pro5v328.upload.protocol=stk500 -pro5v328.upload.maximum_size=30720 -pro5v328.upload.speed=57600 - -pro5v328.bootloader.low_fuses=0xFF -pro5v328.bootloader.high_fuses=0xDA -pro5v328.bootloader.extended_fuses=0x05 -pro5v328.bootloader.path=atmega -pro5v328.bootloader.file=ATmegaBOOT_168_atmega328.hex -pro5v328.bootloader.unlock_bits=0x3F -pro5v328.bootloader.lock_bits=0x0F - -pro5v328.build.mcu=atmega328p -pro5v328.build.f_cpu=16000000L -pro5v328.build.core=arduino - -############################################################## - -pro5v328_DuinOS.name=Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328 + DuinOS - -pro5v328_DuinOS.upload.protocol=stk500 -pro5v328_DuinOS.upload.maximum_size=30720 -pro5v328_DuinOS.upload.speed=57600 - -pro5v328_DuinOS.bootloader.low_fuses=0xFF -pro5v328_DuinOS.bootloader.high_fuses=0xDA -pro5v328_DuinOS.bootloader.extended_fuses=0x05 -pro5v328_DuinOS.bootloader.path=atmega -pro5v328_DuinOS.bootloader.file=ATmegaBOOT_168_atmega328.hex -pro5v328_DuinOS.bootloader.unlock_bits=0x3F -pro5v328_DuinOS.bootloader.lock_bits=0x0F - -pro5v328_DuinOS.build.mcu=atmega328p -pro5v328_DuinOS.build.f_cpu=16000000L -pro5v328_DuinOS.build.core=arduino.DuinOS - -############################################################## - -pro5v.name=Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega168 - -pro5v.upload.protocol=stk500 -pro5v.upload.maximum_size=14336 -pro5v.upload.speed=19200 - -pro5v.bootloader.low_fuses=0xff -pro5v.bootloader.high_fuses=0xdd -pro5v.bootloader.extended_fuses=0x00 -pro5v.bootloader.path=atmega -pro5v.bootloader.file=ATmegaBOOT_168_diecimila.hex -pro5v.bootloader.unlock_bits=0x3F -pro5v.bootloader.lock_bits=0x0F - -pro5v.build.mcu=atmega168 -pro5v.build.f_cpu=16000000L -pro5v.build.core=arduino - -############################################################## - -pro5v_DuinOS.name=Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega168 + DuinOS - -pro5v_DuinOS.upload.protocol=stk500 -pro5v_DuinOS.upload.maximum_size=14336 -pro5v_DuinOS.upload.speed=19200 - -pro5v_DuinOS.bootloader.low_fuses=0xff -pro5v_DuinOS.bootloader.high_fuses=0xdd -pro5v_DuinOS.bootloader.extended_fuses=0x00 -pro5v_DuinOS.bootloader.path=atmega -pro5v_DuinOS.bootloader.file=ATmegaBOOT_168_diecimila.hex -pro5v_DuinOS.bootloader.unlock_bits=0x3F -pro5v_DuinOS.bootloader.lock_bits=0x0F - -pro5v_DuinOS.build.mcu=atmega168 -pro5v_DuinOS.build.f_cpu=16000000L -pro5v_DuinOS.build.core=arduino.DuinOS - -############################################################## - -pro328.name=Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328 - -pro328.upload.protocol=stk500 -pro328.upload.maximum_size=30720 -pro328.upload.speed=57600 - -pro328.bootloader.low_fuses=0xFF -pro328.bootloader.high_fuses=0xDA -pro328.bootloader.extended_fuses=0x05 -pro328.bootloader.path=atmega -pro328.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex -pro328.bootloader.unlock_bits=0x3F -pro328.bootloader.lock_bits=0x0F - -pro328.build.mcu=atmega328p -pro328.build.f_cpu=8000000L -pro328.build.core=arduino - -############################################################## - -pro328_DuinOS.name=Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328 + DuinOS - -pro328_DuinOS.upload.protocol=stk500 -pro328_DuinOS.upload.maximum_size=30720 -pro328_DuinOS.upload.speed=57600 - -pro328_DuinOS.bootloader.low_fuses=0xFF -pro328_DuinOS.bootloader.high_fuses=0xDA -pro328_DuinOS.bootloader.extended_fuses=0x05 -pro328_DuinOS.bootloader.path=atmega -pro328_DuinOS.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex -pro328_DuinOS.bootloader.unlock_bits=0x3F -pro328_DuinOS.bootloader.lock_bits=0x0F - -pro328_DuinOS.build.mcu=atmega328p -pro328_DuinOS.build.f_cpu=8000000L -pro328_DuinOS.build.core=arduino - -############################################################## - -pro.name=Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega168 - -pro.upload.protocol=stk500 -pro.upload.maximum_size=14336 -pro.upload.speed=19200 - -pro.bootloader.low_fuses=0xc6 -pro.bootloader.high_fuses=0xdd -pro.bootloader.extended_fuses=0x00 -pro.bootloader.path=atmega -pro.bootloader.file=ATmegaBOOT_168_pro_8MHz.hex -pro.bootloader.unlock_bits=0x3F -pro.bootloader.lock_bits=0x0F - -pro.build.mcu=atmega168 -pro.build.f_cpu=8000000L -pro.build.core=arduino - -############################################################## - -pro_DuinOS.name=Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega168 + DuinOS - -pro_DuinOS.upload.protocol=stk500 -pro_DuinOS.upload.maximum_size=14336 -pro_DuinOS.upload.speed=19200 - -pro_DuinOS.bootloader.low_fuses=0xc6 -pro_DuinOS.bootloader.high_fuses=0xdd -pro_DuinOS.bootloader.extended_fuses=0x00 -pro_DuinOS.bootloader.path=atmega -pro_DuinOS.bootloader.file=ATmegaBOOT_168_pro_8MHz.hex -pro_DuinOS.bootloader.unlock_bits=0x3F -pro_DuinOS.bootloader.lock_bits=0x0F - -pro_DuinOS.build.mcu=atmega168 -pro_DuinOS.build.f_cpu=8000000L -pro_DuinOS.build.core=arduino.DuinOS - -############################################################## - -atmega168.name=Arduino NG or older w/ ATmega168 - -atmega168.upload.protocol=stk500 -atmega168.upload.maximum_size=14336 -atmega168.upload.speed=19200 - -atmega168.bootloader.low_fuses=0xff -atmega168.bootloader.high_fuses=0xdd -atmega168.bootloader.extended_fuses=0x00 -atmega168.bootloader.path=atmega -atmega168.bootloader.file=ATmegaBOOT_168_ng.hex -atmega168.bootloader.unlock_bits=0x3F -atmega168.bootloader.lock_bits=0x0F - -atmega168.build.mcu=atmega168 -atmega168.build.f_cpu=16000000L -atmega168.build.core=arduino - -############################################################## - -atmega168_DuinOS.name=Arduino NG or older w/ ATmega168 + DuinOS - -atmega168_DuinOS.upload.protocol=stk500 -atmega168_DuinOS.upload.maximum_size=14336 -atmega168_DuinOS.upload.speed=19200 - -atmega168_DuinOS.bootloader.low_fuses=0xff -atmega168_DuinOS.bootloader.high_fuses=0xdd -atmega168_DuinOS.bootloader.extended_fuses=0x00 -atmega168_DuinOS.bootloader.path=atmega -atmega168_DuinOS.bootloader.file=ATmegaBOOT_168_ng.hex -atmega168_DuinOS.bootloader.unlock_bits=0x3F -atmega168_DuinOS.bootloader.lock_bits=0x0F - -atmega168_DuinOS.build.mcu=atmega168 -atmega168_DuinOS.build.f_cpu=16000000L -atmega168_DuinOS.build.core=arduino.DuinOS - -############################################################## - -atmega8.name=Arduino NG or older w/ ATmega8 - -atmega8.upload.protocol=stk500 -atmega8.upload.maximum_size=7168 -atmega8.upload.speed=19200 - -atmega8.bootloader.low_fuses=0xdf -atmega8.bootloader.high_fuses=0xca -atmega8.bootloader.path=atmega8 -atmega8.bootloader.file=ATmegaBOOT.hex -atmega8.bootloader.unlock_bits=0x3F -atmega8.bootloader.lock_bits=0x0F - -atmega8.build.mcu=atmega8 -atmega8.build.f_cpu=16000000L -atmega8.build.core=arduino - -############################################################## - -atmega8_DuinOS.name=Arduino NG or older w/ ATmega8 + DuinOS - -atmega8_DuinOS.upload.protocol=stk500 -atmega8_DuinOS.upload.maximum_size=7168 -atmega8_DuinOS.upload.speed=19200 - -atmega8_DuinOS.bootloader.low_fuses=0xdf -atmega8_DuinOS.bootloader.high_fuses=0xca -atmega8_DuinOS.bootloader.path=atmega8 -atmega8_DuinOS.bootloader.file=ATmegaBOOT.hex -atmega8_DuinOS.bootloader.unlock_bits=0x3F -atmega8_DuinOS.bootloader.lock_bits=0x0F - -atmega8_DuinOS.build.mcu=atmega8 -atmega8_DuinOS.build.f_cpu=16000000L -atmega8_DuinOS.build.core=arduino.DuinOS From 420a6ddbf0f94189674c24ae64e859228e00deeb Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Mon, 12 Nov 2012 14:56:32 -0200 Subject: [PATCH 09/56] =?UTF-8?q?pequenas=20corre=C3=A7=C3=B5es=20no=20cod?= =?UTF-8?q?igo,=20sincronizando=20com=20o=20ultimo=20commit=20da=20vers?= =?UTF-8?q?=C3=A3o=207.3.0=20do=20FreeRTOS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arduino.DuinOS.AVR/DuinOS/tasks.c | 2 +- arduino.DuinOS.AVR/DuinOS/timers.c | 2 +- arduino.DuinOS.AVR/DuinOS/timers.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arduino.DuinOS.AVR/DuinOS/tasks.c b/arduino.DuinOS.AVR/DuinOS/tasks.c index a7800fc..ec8a052 100644 --- a/arduino.DuinOS.AVR/DuinOS/tasks.c +++ b/arduino.DuinOS.AVR/DuinOS/tasks.c @@ -2448,7 +2448,7 @@ tskTCB *pxNewTCB; } #endif - sprintf( pcStatusString, ( char * ) "%s\t\t%c\t%u\t%u\t%u\r\n", pxNextTCB->pcTaskName, cStatus, ( unsigned int ) pxNextTCB->uxPriority, usStackRemaining, ( unsigned int ) pxNextTCB->uxTCBNumber ); + sprintf( pcStatusString, ( char * ) "%s\t\t%c\t%u\t%u\t%u\r\n", pxNextTCB->pcTaskName, cStatus, ( unsigned int ) pxNextTCB->uxPriority, ( unsigned int ) usStackRemaining, ( unsigned int ) pxNextTCB->uxTCBNumber ); strcat( ( char * ) pcWriteBuffer, ( char * ) pcStatusString ); } while( pxNextTCB != pxFirstTCB ); diff --git a/arduino.DuinOS.AVR/DuinOS/timers.c b/arduino.DuinOS.AVR/DuinOS/timers.c index d910505..f8cb7f8 100644 --- a/arduino.DuinOS.AVR/DuinOS/timers.c +++ b/arduino.DuinOS.AVR/DuinOS/timers.c @@ -217,7 +217,7 @@ portBASE_TYPE xReturn = pdFAIL; } /*-----------------------------------------------------------*/ -xTimerHandle xTimerCreate( const signed char *pcTimerName, portTickType xTimerPeriodInTicks, unsigned portBASE_TYPE uxAutoReload, void *pvTimerID, tmrTIMER_CALLBACK pxCallbackFunction ) +xTimerHandle xTimerCreate( const signed char * const pcTimerName, portTickType xTimerPeriodInTicks, unsigned portBASE_TYPE uxAutoReload, void *pvTimerID, tmrTIMER_CALLBACK pxCallbackFunction ) { xTIMER *pxNewTimer; diff --git a/arduino.DuinOS.AVR/DuinOS/timers.h b/arduino.DuinOS.AVR/DuinOS/timers.h index 1ee5b9c..0d998a5 100644 --- a/arduino.DuinOS.AVR/DuinOS/timers.h +++ b/arduino.DuinOS.AVR/DuinOS/timers.h @@ -232,7 +232,7 @@ typedef void (*tmrTIMER_CALLBACK)( xTimerHandle xTimer ); * for( ;; ); * } */ -xTimerHandle xTimerCreate( const signed char *pcTimerName, portTickType xTimerPeriodInTicks, unsigned portBASE_TYPE uxAutoReload, void * pvTimerID, tmrTIMER_CALLBACK pxCallbackFunction ) PRIVILEGED_FUNCTION; +xTimerHandle xTimerCreate( const signed char * const pcTimerName, portTickType xTimerPeriodInTicks, unsigned portBASE_TYPE uxAutoReload, void * pvTimerID, tmrTIMER_CALLBACK pxCallbackFunction ) PRIVILEGED_FUNCTION; /** * void *pvTimerGetTimerID( xTimerHandle xTimer ); From 473ef03172d07d144b7f6eb48dd2eb2186e98b06 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Mon, 12 Nov 2012 14:57:15 -0200 Subject: [PATCH 10/56] Novos arquivos a serem ignorados. --- .gitignore | 2 ++ arduino.DuinOS.AVR/DuinOS/.gitignore | 1 + 2 files changed, 3 insertions(+) create mode 100644 .gitignore create mode 100644 arduino.DuinOS.AVR/DuinOS/.gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3462d9f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/.settings +/Debug diff --git a/arduino.DuinOS.AVR/DuinOS/.gitignore b/arduino.DuinOS.AVR/DuinOS/.gitignore new file mode 100644 index 0000000..61045a0 --- /dev/null +++ b/arduino.DuinOS.AVR/DuinOS/.gitignore @@ -0,0 +1 @@ +/port.c.corr From 5734363c0df41f06722738413c8d7cd96ebb2ae6 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Mon, 12 Nov 2012 14:59:40 -0200 Subject: [PATCH 11/56] adicionado compatiblidade ao ATMega 2560 para uso com Arduino Mega 2560 --- arduino.DuinOS.AVR/DuinOS/port.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/arduino.DuinOS.AVR/DuinOS/port.c b/arduino.DuinOS.AVR/DuinOS/port.c index 4afbbb0..f0faee6 100644 --- a/arduino.DuinOS.AVR/DuinOS/port.c +++ b/arduino.DuinOS.AVR/DuinOS/port.c @@ -226,7 +226,13 @@ static void prvSetupTimerInterrupt( void ); */ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ) { -unsigned portSHORT usAddress; + /* ATmega2560 DuinOS port by SkyWodd */ +#if defined(__AVR_ATmega2560__) + unsigned portLONG usAddress; // ATMega2560 have 22bit Program Counter register +#else + unsigned portSHORT usAddress; // over ATmega have 16bit Program Counter register +#endif + /* Place a few bytes of known values on the bottom of the stack. This is just useful for debugging. */ @@ -243,6 +249,23 @@ unsigned portSHORT usAddress; /*lint -e950 -e611 -e923 Lint doesn't like this much - but nothing I can do about it. */ +#if defined(__AVR_ATmega2560__) + // Implement normal stack initialisation but with portLONG instead of portSHORT + usAddress = ( unsigned portLONG ) pxCode; + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); + pxTopOfStack--; + + usAddress >>= 8; + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); + pxTopOfStack--; + + // Implemented the 3byte addressing + usAddress >>= 8; + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); + pxTopOfStack--; + +// Normal initialisation for over ATmega +#else /* The start of the task code will be popped off the stack last, so place it on first. */ usAddress = ( unsigned portSHORT ) pxCode; @@ -252,6 +275,7 @@ unsigned portSHORT usAddress; usAddress >>= 8; *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff ); pxTopOfStack--; +#endif /* Next simulate the stack as if after a call to portSAVE_CONTEXT(). portSAVE_CONTEXT places the flags on the stack immediately after r0 From 281c9e17ea0751ced6ff3f7a04723f9b096e6baa Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Mon, 12 Nov 2012 15:00:43 -0200 Subject: [PATCH 12/56] =?UTF-8?q?corre=C3=A7=C3=A3o=20do=20Arquivo=20board?= =?UTF-8?q?s.txt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hardware/boards.txt | 340 ++++++++++++++++++++++++++++++-------------- 1 file changed, 233 insertions(+), 107 deletions(-) diff --git a/hardware/boards.txt b/hardware/boards.txt index 7351d65..f0c0172 100644 --- a/hardware/boards.txt +++ b/hardware/boards.txt @@ -1,16 +1,21 @@ +# See: http://code.google.com/p/arduino/wiki/Platforms + ############################################################## -uno.name=Arduino Uno +uno.name=Arduino Uno +uno.upload.tool=avrdude uno.upload.protocol=arduino uno.upload.maximum_size=32256 uno.upload.speed=115200 -uno.bootloader.low_fuses=0xff -uno.bootloader.high_fuses=0xde + +uno.bootloader.tool=avrdude +uno.bootloader.low_fuses=0xFF +uno.bootloader.high_fuses=0xDE uno.bootloader.extended_fuses=0x05 -uno.bootloader.path=optiboot -uno.bootloader.file=optiboot_atmega328.hex uno.bootloader.unlock_bits=0x3F uno.bootloader.lock_bits=0x0F +uno.bootloader.file=optiboot/optiboot_atmega328.hex + uno.build.mcu=atmega328p uno.build.f_cpu=16000000L uno.build.core=arduino @@ -18,35 +23,63 @@ uno.build.variant=standard ############################################################## -uno_Duinos.name=Arduino Uno + Duinos -uno_Duinos.upload.protocol=arduino -uno_Duinos.upload.maximum_size=30720 -uno_Duinos.upload.speed=115200 -uno_Duinos.bootloader.low_fuses=0xff -uno_Duinos.bootloader.high_fuses=0xde -uno_Duinos.bootloader.extended_fuses=0x05 -uno_Duinos.bootloader.path=optiboot -uno_Duinos.bootloader.file=optiboot_atmega328.hex -uno_Duinos.bootloader.unlock_bits=0x3F -uno_Duinos.bootloader.lock_bits=0x0F -uno_Duinos.build.mcu=atmega328p -uno_Duinos.build.f_cpu=16000000L -uno_Duinos.build.core=arduino.DuinOS.avr -uno_Duinos.build.variant=standard +uno_DuinOS.name=Arduino Uno + DuinOS +uno_DuinOS.upload.tool=avrdude +uno_DuinOS.upload.protocol=arduino +uno_DuinOS.upload.maximum_size=32256 +uno_DuinOS.upload.speed=115200 + +uno_DuinOS.bootloader.tool=avrdude +uno_DuinOS.bootloader.low_fuses=0xFF +uno_DuinOS.bootloader.high_fuses=0xDE +uno_DuinOS.bootloader.extended_fuses=0x05 +uno_DuinOS.bootloader.unlock_bits=0x3F +uno_DuinOS.bootloader.lock_bits=0x0F +uno_DuinOS.bootloader.file=optiboot/optiboot_atmega328.hex + +uno_DuinOS.build.mcu=atmega328p +uno_DuinOS.build.f_cpu=16000000L +uno_DuinOS.build.core=arduino.DuinOS.AVR +uno_DuinOS.build.variant=standard + +############################################################## + +uno328.name=Arduino Uno w/ ATmega328 (non-P) +uno328.upload.tool=avrdude +uno328.upload.protocol=arduino +uno328.upload.maximum_size=32256 +uno328.upload.speed=115200 + +uno328.bootloader.tool=avrdude +uno328.bootloader.low_fuses=0xff +uno328.bootloader.high_fuses=0xde +uno328.bootloader.extended_fuses=0x05 +uno328.bootloader.unlock_bits=0x3F +uno328.bootloader.lock_bits=0x0F +uno328.bootloader.file=optiboot/optiboot_atmega328.hex + +uno328.build.mcu=atmega328 +uno328.build.f_cpu=16000000L +uno328.build.core=arduino +uno328.build.variant=standard ############################################################## atmega328.name=Arduino Duemilanove w/ ATmega328 + +atmega328.upload.tool=avrdude atmega328.upload.protocol=arduino atmega328.upload.maximum_size=30720 atmega328.upload.speed=57600 + +atmega328.bootloader.tool=avrdude atmega328.bootloader.low_fuses=0xFF atmega328.bootloader.high_fuses=0xDA atmega328.bootloader.extended_fuses=0x05 -atmega328.bootloader.path=atmega -atmega328.bootloader.file=ATmegaBOOT_168_atmega328.hex +atmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex atmega328.bootloader.unlock_bits=0x3F atmega328.bootloader.lock_bits=0x0F + atmega328.build.mcu=atmega328p atmega328.build.f_cpu=16000000L atmega328.build.core=arduino @@ -56,15 +89,16 @@ atmega328.build.variant=standard diecimila.name=Arduino Diecimila or Duemilanove w/ ATmega168 +diecimila.upload.tool=avrdude diecimila.upload.protocol=arduino diecimila.upload.maximum_size=14336 diecimila.upload.speed=19200 +diecimila.bootloader.tool=avrdude diecimila.bootloader.low_fuses=0xff diecimila.bootloader.high_fuses=0xdd diecimila.bootloader.extended_fuses=0x00 -diecimila.bootloader.path=atmega -diecimila.bootloader.file=ATmegaBOOT_168_diecimila.hex +diecimila.bootloader.file=atmega/ATmegaBOOT_168_diecimila.hex diecimila.bootloader.unlock_bits=0x3F diecimila.bootloader.lock_bits=0x0F @@ -76,16 +110,22 @@ diecimila.build.variant=standard ############################################################## nano328.name=Arduino Nano w/ ATmega328 +nano328.cpu=ATmega328 +nano328.container=Arduino Nano + +nano328.upload.tool=avrdude nano328.upload.protocol=arduino nano328.upload.maximum_size=30720 nano328.upload.speed=57600 + +nano328.bootloader.tool=avrdude nano328.bootloader.low_fuses=0xFF nano328.bootloader.high_fuses=0xDA nano328.bootloader.extended_fuses=0x05 -nano328.bootloader.path=atmega -nano328.bootloader.file=ATmegaBOOT_168_atmega328.hex +nano328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex nano328.bootloader.unlock_bits=0x3F nano328.bootloader.lock_bits=0x0F + nano328.build.mcu=atmega328p nano328.build.f_cpu=16000000L nano328.build.core=arduino @@ -94,16 +134,22 @@ nano328.build.variant=eightanaloginputs ############################################################## nano.name=Arduino Nano w/ ATmega168 +nano.cpu=ATmega168 +nano.container=Arduino Nano + +nano.upload.tool=avrdude nano.upload.protocol=arduino nano.upload.maximum_size=14336 nano.upload.speed=19200 + +nano.bootloader.tool=avrdude nano.bootloader.low_fuses=0xff nano.bootloader.high_fuses=0xdd nano.bootloader.extended_fuses=0x00 -nano.bootloader.path=atmega -nano.bootloader.file=ATmegaBOOT_168_diecimila.hex +nano.bootloader.file=atmega/ATmegaBOOT_168_diecimila.hex nano.bootloader.unlock_bits=0x3F nano.bootloader.lock_bits=0x0F + nano.build.mcu=atmega168 nano.build.f_cpu=16000000L nano.build.core=arduino @@ -112,16 +158,22 @@ nano.build.variant=eightanaloginputs ############################################################## mega2560.name=Arduino Mega 2560 or Mega ADK -mega2560.upload.protocol=stk500v2 +mega2560.cpu=2560 or ADK +mega2560.container=Arduino Mega 2560 + +mega2560.upload.tool=avrdude +mega2560.upload.protocol=wiring mega2560.upload.maximum_size=258048 mega2560.upload.speed=115200 + +mega2560.bootloader.tool=avrdude mega2560.bootloader.low_fuses=0xFF mega2560.bootloader.high_fuses=0xD8 mega2560.bootloader.extended_fuses=0xFD -mega2560.bootloader.path=stk500v2 -mega2560.bootloader.file=stk500boot_v2_mega2560.hex +mega2560.bootloader.file=stk500v2/stk500boot_v2_mega2560.hex mega2560.bootloader.unlock_bits=0x3F mega2560.bootloader.lock_bits=0x0F + mega2560.build.mcu=atmega2560 mega2560.build.f_cpu=16000000L mega2560.build.core=arduino @@ -129,35 +181,47 @@ mega2560.build.variant=mega ############################################################## -mega2560.name=Arduino Mega 2560 or Mega ADK -mega2560.upload.protocol=stk500v2 -mega2560.upload.maximum_size=258048 -mega2560.upload.speed=115200 -mega2560.bootloader.low_fuses=0xFF -mega2560.bootloader.high_fuses=0xD8 -mega2560.bootloader.extended_fuses=0xFD -mega2560.bootloader.path=stk500v2 -mega2560.bootloader.file=stk500boot_v2_mega2560.hex -mega2560.bootloader.unlock_bits=0x3F -mega2560.bootloader.lock_bits=0x0F -mega2560.build.mcu=atmega2560 -mega2560.build.f_cpu=16000000L -mega2560.build.core=arduino.DuinOS.avr -mega2560.build.variant=mega +mega2560_DuinOS.name=Arduino Mega 2560 or Mega ADK + DuinOS +mega2560_DuinOS.cpu=2560 or ADK +mega2560_DuinOS.container=Arduino Mega 2560 + DuinOS + +mega2560_DuinOS.upload.tool=avrdude +mega2560_DuinOS.upload.protocol=wiring +mega2560_DuinOS.upload.maximum_size=258048 +mega2560_DuinOS.upload.speed=115200 + +mega2560_DuinOS.bootloader.tool=avrdude +mega2560_DuinOS.bootloader.low_fuses=0xFF +mega2560_DuinOS.bootloader.high_fuses=0xD8 +mega2560_DuinOS.bootloader.extended_fuses=0xFD +mega2560_DuinOS.bootloader.file=stk500v2/stk500boot_v2_mega2560.hex +mega2560_DuinOS.bootloader.unlock_bits=0x3F +mega2560_DuinOS.bootloader.lock_bits=0x0F + +mega2560_DuinOS.build.mcu=atmega2560 +mega2560_DuinOS.build.f_cpu=16000000L +mega2560_DuinOS.build.core=arduino.DuinOS.AVR +mega2560_DuinOS.build.variant=mega ############################################################## mega.name=Arduino Mega (ATmega1280) +mega.cpu=ATmega1280 +mega.container=Arduino Mega 1280 + +mega.upload.tool=avrdude mega.upload.protocol=arduino mega.upload.maximum_size=126976 mega.upload.speed=57600 + +mega.bootloader.tool=avrdude mega.bootloader.low_fuses=0xFF mega.bootloader.high_fuses=0xDA mega.bootloader.extended_fuses=0xF5 -mega.bootloader.path=atmega -mega.bootloader.file=ATmegaBOOT_168_atmega1280.hex +mega.bootloader.file=atmega/ATmegaBOOT_168_atmega1280.hex mega.bootloader.unlock_bits=0x3F mega.bootloader.lock_bits=0x0F + mega.build.mcu=atmega1280 mega.build.f_cpu=16000000L mega.build.core=arduino @@ -165,53 +229,74 @@ mega.build.variant=mega ############################################################## -#leonardo.name=Arduino Leonardo -#leonardo.upload.protocol=arduino -#leonardo.upload.maximum_size=28672 -#leonardo.upload.speed=1200 -#leonardo.bootloader.low_fuses=0xde -#leonardo.bootloader.high_fuses=0xd8 -#leonardo.bootloader.extended_fuses=0xcb -#leonardo.bootloader.path=diskloader -#leonardo.bootloader.file=DiskLoader-Leonardo.hex -#leonardo.bootloader.unlock_bits=0x3F -#leonardo.bootloader.lock_bits=0x2F -#leonardo.build.mcu=atmega32u4 -#leonardo.build.f_cpu=16000000L -#leonardo.build.core=arduino -#leonardo.build.variant=leonardo +mega_DuinOS.name=Arduino Mega (ATmega1280) + DuinOS +mega_DuinOS.cpu=ATmega1280 +mega_DuinOS.container=Arduino Mega 1280 + DuinOS + +mega_DuinOS.upload.tool=avrdude +mega_DuinOS.upload.protocol=arduino +mega_DuinOS.upload.maximum_size=126976 +mega_DuinOS.upload.speed=57600 + +mega_DuinOS.bootloader.tool=avrdude +mega_DuinOS.bootloader.low_fuses=0xFF +mega_DuinOS.bootloader.high_fuses=0xDA +mega_DuinOS.bootloader.extended_fuses=0xF5 +mega_DuinOS.bootloader.file=atmega/ATmegaBOOT_168_atmega1280.hex +mega_DuinOS.bootloader.unlock_bits=0x3F +mega_DuinOS.bootloader.lock_bits=0x0F + +mega_DuinOS.build.mcu=atmega1280 +mega_DuinOS.build.f_cpu=16000000L +mega_DuinOS.build.core=arduino.DuinOS.AVR +mega_DuinOS.build.variant=mega ############################################################## -#micro.name=Arduino Micro -#micro.upload.protocol=arduino -#micro.upload.maximum_size=30720 -#micro.upload.speed=1200 -#micro.bootloader.low_fuses=0xde -#micro.bootloader.high_fuses=0xda -#micro.bootloader.extended_fuses=0xcb -#micro.bootloader.path=diskloader -#micro.bootloader.file=DiskLoader-Micro.hex -#micro.bootloader.unlock_bits=0x3F -#micro.bootloader.lock_bits=0x2F -#micro.build.mcu=atmega32u4 -#micro.build.f_cpu=16000000L -#micro.build.core=arduino -#micro.build.variant=micro +leonardo.name=Arduino Leonardo +leonardo.upload.tool=avrdude +leonardo.upload.protocol=avr109 +leonardo.upload.maximum_size=28672 +leonardo.upload.speed=57600 +leonardo.upload.disable_flushing=true +leonardo.upload.use_1200bps_touch=true +leonardo.upload.wait_for_upload_port=true + +leonardo.bootloader.tool=avrdude +leonardo.bootloader.low_fuses=0xff +leonardo.bootloader.high_fuses=0xd8 +leonardo.bootloader.extended_fuses=0xcb +leonardo.bootloader.file=caterina/Caterina-Leonardo.hex +leonardo.bootloader.unlock_bits=0x3F +leonardo.bootloader.lock_bits=0x2F + +leonardo.build.mcu=atmega32u4 +leonardo.build.f_cpu=16000000L +leonardo.build.vid=0x2341 +leonardo.build.pid=0x8036 +leonardo.build.core=arduino +leonardo.build.variant=leonardo +leonardo.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} ############################################################## mini328.name=Arduino Mini w/ ATmega328 -mini328.upload.protocol=stk500 +mini328.cpu=ATmega328 +mini328.container=Arduino Mini + +mini328.upload.tool=avrdude +mini328.upload.protocol=arduino mini328.upload.maximum_size=28672 mini328.upload.speed=115200 + +mini328.bootloader.tool=avrdude mini328.bootloader.low_fuses=0xff mini328.bootloader.high_fuses=0xd8 mini328.bootloader.extended_fuses=0x05 -mini328.bootloader.path=optiboot -mini328.bootloader.file=optiboot_atmega328-Mini.hex +mini328.bootloader.file=optiboot/optiboot_atmega328-Mini.hex mini328.bootloader.unlock_bits=0x3F mini328.bootloader.lock_bits=0x0F + mini328.build.mcu=atmega328p mini328.build.f_cpu=16000000L mini328.build.core=arduino @@ -220,16 +305,22 @@ mini328.build.variant=eightanaloginputs ############################################################## mini.name=Arduino Mini w/ ATmega168 +mini.cpu=ATmega168 +mini.container=Arduino Mini + +mini.upload.tool=avrdude mini.upload.protocol=arduino mini.upload.maximum_size=14336 mini.upload.speed=19200 + +mini.bootloader.tool=avrdude mini.bootloader.low_fuses=0xff mini.bootloader.high_fuses=0xdd mini.bootloader.extended_fuses=0x00 -mini.bootloader.path=atmega -mini.bootloader.file=ATmegaBOOT_168_ng.hex +mini.bootloader.file=atmega/ATmegaBOOT_168_ng.hex mini.bootloader.unlock_bits=0x3F mini.bootloader.lock_bits=0x0F + mini.build.mcu=atmega168 mini.build.f_cpu=16000000L mini.build.core=arduino @@ -238,16 +329,20 @@ mini.build.variant=eightanaloginputs ############################################################## ethernet.name=Arduino Ethernet + +ethernet.upload.tool=avrdude ethernet.upload.protocol=arduino ethernet.upload.maximum_size=32256 ethernet.upload.speed=115200 + +ethernet.bootloader.tool=avrdude ethernet.bootloader.low_fuses=0xff ethernet.bootloader.high_fuses=0xde ethernet.bootloader.extended_fuses=0x05 -ethernet.bootloader.path=optiboot -ethernet.bootloader.file=optiboot_atmega328.hex +ethernet.bootloader.file=optiboot/optiboot_atmega328.hex ethernet.bootloader.unlock_bits=0x3F ethernet.bootloader.lock_bits=0x0F + ethernet.build.variant=standard ethernet.build.mcu=atmega328p ethernet.build.f_cpu=16000000L @@ -257,15 +352,16 @@ ethernet.build.core=arduino fio.name=Arduino Fio +fio.upload.tool=avrdude fio.upload.protocol=arduino fio.upload.maximum_size=30720 fio.upload.speed=57600 +fio.bootloader.tool=avrdude fio.bootloader.low_fuses=0xFF fio.bootloader.high_fuses=0xDA fio.bootloader.extended_fuses=0x05 -fio.bootloader.path=arduino:atmega -fio.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex +fio.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex fio.bootloader.unlock_bits=0x3F fio.bootloader.lock_bits=0x0F @@ -277,17 +373,20 @@ fio.build.variant=eightanaloginputs ############################################################## bt328.name=Arduino BT w/ ATmega328 +bt328.cpu=ATmega328 +bt328.container=Arduino BT +bt328.upload.tool=avrdude bt328.upload.protocol=arduino bt328.upload.maximum_size=28672 bt328.upload.speed=19200 bt328.upload.disable_flushing=true +bt328.bootloader.tool=avrdude bt328.bootloader.low_fuses=0xff bt328.bootloader.high_fuses=0xd8 bt328.bootloader.extended_fuses=0x05 -bt328.bootloader.path=bt -bt328.bootloader.file=ATmegaBOOT_168_atmega328_bt.hex +bt328.bootloader.file=bt/ATmegaBOOT_168_atmega328_bt.hex bt328.bootloader.unlock_bits=0x3F bt328.bootloader.lock_bits=0x0F @@ -299,17 +398,20 @@ bt328.build.variant=eightanaloginputs ############################################################## bt.name=Arduino BT w/ ATmega168 +bt.cpu=ATmega168 +bt.container=Arduino BT +bt.upload.tool=avrdude bt.upload.protocol=arduino bt.upload.maximum_size=14336 bt.upload.speed=19200 bt.upload.disable_flushing=true +bt.bootloader.tool=avrdude bt.bootloader.low_fuses=0xff bt.bootloader.high_fuses=0xdd bt.bootloader.extended_fuses=0x00 -bt.bootloader.path=bt -bt.bootloader.file=ATmegaBOOT_168.hex +bt.bootloader.file=bt/ATmegaBOOT_168.hex bt.bootloader.unlock_bits=0x3F bt.bootloader.lock_bits=0x0F @@ -321,16 +423,19 @@ bt.build.variant=eightanaloginputs ############################################################## lilypad328.name=LilyPad Arduino w/ ATmega328 +lilypad328.cpu=ATmega328 +lilypad328.container=LilyPad Arduino +lilypad328.upload.tool=avrdude lilypad328.upload.protocol=arduino lilypad328.upload.maximum_size=30720 lilypad328.upload.speed=57600 +lilypad328.bootloader.tool=avrdude lilypad328.bootloader.low_fuses=0xFF lilypad328.bootloader.high_fuses=0xDA lilypad328.bootloader.extended_fuses=0x05 -lilypad328.bootloader.path=atmega -lilypad328.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex +lilypad328.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex lilypad328.bootloader.unlock_bits=0x3F lilypad328.bootloader.lock_bits=0x0F @@ -342,16 +447,19 @@ lilypad328.build.variant=standard ############################################################## lilypad.name=LilyPad Arduino w/ ATmega168 +lilypad.cpu=ATmega168 +lilypad.container=LilyPad Arduino +lilypad.upload.tool=avrdude lilypad.upload.protocol=arduino lilypad.upload.maximum_size=14336 lilypad.upload.speed=19200 +lilypad.bootloader.tool=avrdude lilypad.bootloader.low_fuses=0xe2 lilypad.bootloader.high_fuses=0xdd lilypad.bootloader.extended_fuses=0x00 -lilypad.bootloader.path=lilypad -lilypad.bootloader.file=LilyPadBOOT_168.hex +lilypad.bootloader.file=lilypad/LilyPadBOOT_168.hex lilypad.bootloader.unlock_bits=0x3F lilypad.bootloader.lock_bits=0x0F @@ -363,16 +471,19 @@ lilypad.build.variant=standard ############################################################## pro5v328.name=Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328 +pro5v328.cpu=ATmega328 (5V, 16 MHz) +pro5v328.container=Arduino Pro or Pro Mini +pro5v328.upload.tool=avrdude pro5v328.upload.protocol=arduino pro5v328.upload.maximum_size=30720 pro5v328.upload.speed=57600 +pro5v328.bootloader.tool=avrdude pro5v328.bootloader.low_fuses=0xFF pro5v328.bootloader.high_fuses=0xDA pro5v328.bootloader.extended_fuses=0x05 -pro5v328.bootloader.path=atmega -pro5v328.bootloader.file=ATmegaBOOT_168_atmega328.hex +pro5v328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex pro5v328.bootloader.unlock_bits=0x3F pro5v328.bootloader.lock_bits=0x0F @@ -384,16 +495,19 @@ pro5v328.build.variant=standard ############################################################## pro5v.name=Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega168 +pro5v.cpu=ATmega168 (5V, 16 MHz) +pro5v.container=Arduino Pro or Pro Mini +pro5v.upload.tool=avrdude pro5v.upload.protocol=arduino pro5v.upload.maximum_size=14336 pro5v.upload.speed=19200 +pro5v.bootloader.tool=avrdude pro5v.bootloader.low_fuses=0xff pro5v.bootloader.high_fuses=0xdd pro5v.bootloader.extended_fuses=0x00 -pro5v.bootloader.path=atmega -pro5v.bootloader.file=ATmegaBOOT_168_diecimila.hex +pro5v.bootloader.file=atmega/ATmegaBOOT_168_diecimila.hex pro5v.bootloader.unlock_bits=0x3F pro5v.bootloader.lock_bits=0x0F @@ -405,16 +519,19 @@ pro5v.build.variant=standard ############################################################## pro328.name=Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328 +pro328.cpu=ATmega328 (3.3V, 8 MHz) +pro328.container=Arduino Pro or Pro Mini +pro328.upload.tool=avrdude pro328.upload.protocol=arduino pro328.upload.maximum_size=30720 pro328.upload.speed=57600 +pro328.bootloader.tool=avrdude pro328.bootloader.low_fuses=0xFF pro328.bootloader.high_fuses=0xDA pro328.bootloader.extended_fuses=0x05 -pro328.bootloader.path=atmega -pro328.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex +pro328.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex pro328.bootloader.unlock_bits=0x3F pro328.bootloader.lock_bits=0x0F @@ -426,16 +543,19 @@ pro328.build.variant=standard ############################################################## pro.name=Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega168 +pro.cpu=ATmega168 (3.3V, 8 MHz) +pro.container=Arduino Pro or Pro Mini +pro.upload.tool=avrdude pro.upload.protocol=arduino pro.upload.maximum_size=14336 pro.upload.speed=19200 +pro.bootloader.tool=avrdude pro.bootloader.low_fuses=0xc6 pro.bootloader.high_fuses=0xdd pro.bootloader.extended_fuses=0x00 -pro.bootloader.path=atmega -pro.bootloader.file=ATmegaBOOT_168_pro_8MHz.hex +pro.bootloader.file=atmega/ATmegaBOOT_168_pro_8MHz.hex pro.bootloader.unlock_bits=0x3F pro.bootloader.lock_bits=0x0F @@ -447,16 +567,19 @@ pro.build.variant=standard ############################################################## atmega168.name=Arduino NG or older w/ ATmega168 +atmega168.cpu=ATmega168 +atmega168.container=Arduino NG or older +atmega168.upload.tool=avrdude atmega168.upload.protocol=arduino atmega168.upload.maximum_size=14336 atmega168.upload.speed=19200 +atmega168.bootloader.tool=avrdude atmega168.bootloader.low_fuses=0xff atmega168.bootloader.high_fuses=0xdd atmega168.bootloader.extended_fuses=0x00 -atmega168.bootloader.path=atmega -atmega168.bootloader.file=ATmegaBOOT_168_ng.hex +atmega168.bootloader.file=atmega/ATmegaBOOT_168_ng.hex atmega168.bootloader.unlock_bits=0x3F atmega168.bootloader.lock_bits=0x0F @@ -468,15 +591,18 @@ atmega168.build.variant=standard ############################################################## atmega8.name=Arduino NG or older w/ ATmega8 +atmega8.cpu=ATmega8 +atmega8.container=Arduino NG or older +atmega8.upload.tool=avrdude atmega8.upload.protocol=arduino atmega8.upload.maximum_size=7168 atmega8.upload.speed=19200 +atmega8.bootloader.tool=avrdude atmega8.bootloader.low_fuses=0xdf atmega8.bootloader.high_fuses=0xca -atmega8.bootloader.path=atmega8 -atmega8.bootloader.file=ATmegaBOOT.hex +atmega8.bootloader.file=atmega8/ATmegaBOOT.hex atmega8.bootloader.unlock_bits=0x3F atmega8.bootloader.lock_bits=0x0F From 1142b6243bd119bb952cad5daa614a45f615ac0c Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Mon, 12 Nov 2012 15:01:55 -0200 Subject: [PATCH 13/56] =?UTF-8?q?Atualiza=C3=A7=C3=A3o=20do=20Arquivo=20Re?= =?UTF-8?q?adme.txt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Readme.txt | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/Readme.txt b/Readme.txt index 263e214..dd7cbf8 100644 --- a/Readme.txt +++ b/Readme.txt @@ -1,21 +1,24 @@ ******************************** - DuinOS v0.4 Alpha + DuinOS v0.6.1 Beta ******************************** Copyright (C) 2009 Multiplo http://multiplo.org http://robotgroup.com.ar Created by Julián U. da Silva Gillig. +Ported by Carlos Delfino {consultoria@carlosdelfino.eti.br} +Copyleft (C) 2012 Carlos Delfino e Amigos +http://www.carlosdelfino.eti.br -Based on the FreeRTOS v6.1.0 kernel (www.freertos.org). Please see the License section below. +Based on the FreeRTOS v7.3.0 kernel (www.freertos.org). Please see the License section below. This is our only distribution of DuinOS, which includes the complete source code. The last version is always available -from http://robotgroup.com.ar +from https://github.com/CarlosDelfino/DuinOS/downloads ******************************** License ******************************** -The DuinOS kernel (cores\arduino.DuinOS) is under the same license as the FreeRTOS operating system (www.freertos.org) +The DuinOS kernel (cores\arduino.DuinOS.*) is under the same license as the FreeRTOS operating system (www.freertos.org) Please see the included FreeRTOS.license.txt file. We have used too, some files belonging to the AVR port of the FreeRTOS operating system, made by Micropendous @@ -29,7 +32,7 @@ By Opendous Inc. www.Micropendous.org October 04, 2009 -Please visit www.micropendous.org if there is any doubt. +Please visit www.micropendous.org or contact consultoria@carlosdelfino.eti if there is any doubt NOTE: We strongly believe in peace, so we would not like to see our work in any non-civil or military project. But, due to the FreeRTOS's modified GPL license which we do have to maintain, this is only a recommendation and an expression of @@ -41,14 +44,14 @@ our wishes. ******************************** 0. Close the Arduino IDE (all instances). -1. Copy the arduino.DuinOS folder to the \hardware\cores folder. -2. Rename your current \hardware\boards.txt file. -3. Copy the boards.txt deployed with DuinOS to the \hardware folder. +1. Copy the arduino.DuinOS.* folder to the \hardware\arduino\*\cores folder. +2. Rename your current \hardware\arduino\*\boards.txt file. +3. Copy the *\boards.txt deployed with DuinOS to the \hardware\arduino\* folder, remember eatch borads.*.txt for respective hardware folder. 4. Rename your current \lib\keywords.txt file. 5. Copy the keywords.txt deployed with DuinOS to the \lib folder. 6. Start the Arduino IDE. 7. Please select any DuinOS board from the Tools->Board menu, like the "Arduino Duemilanove or Nano w/ ATmega328 + DuinOS". -8. Now, you can compile any standard project, but we suggest the \examples\MoreComplexBlinking deployed with DuinOS. +8. Now, you can compile any standard project, but we suggest the \examples\DuinOS\MoreComplexBlinking deployed with DuinOS. ******************************** Uninstall @@ -57,7 +60,7 @@ our wishes. 0. Close the Arduino IDE (all instances). 1. If you have renamed the original boards.txt file, delete the current boards.txt file and rename the previous one (so it will be now your new boards.txt). 2. If you have renamed the original keywords.txt file, delete the current keywords.txt file and rename the previous one (so it will be now your new keywords.txt). -3. Delete the arduino.DuinOS folder from the \cores folder. +3. Delete the arduino.DuinOS folder from the \cores\arduino\* folder. 4. Now you can restart the Arduino IDE and keep working without DuinOS. ******************************** @@ -112,4 +115,10 @@ MATERIALS ON THIS WEBSITE. - Use Timer0 for FreeRTOS - Remove Servo library (standard one should work) * 0. - +* 0. +* 0.6.1 Beta / 2012.01.01 (Carlos Delfino ) +- Arduino IDE updated to version 1.5.0 +- FreeRTOS updated to 7.3.0 +- Tested with MoreComplexBlinking example on Arduino UNO e Arduino Mega +- created a folder for eatch mcu (AVR and ARM) +- created a folder boards for eatch mcu \ No newline at end of file From 7d8c3e59b8403a3081b7d5ed1977602c8839be9f Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Mon, 12 Nov 2012 15:03:30 -0200 Subject: [PATCH 14/56] =?UTF-8?q?nova=20abordagem=20do=20esqueleto=20do=20?= =?UTF-8?q?Arduino=20para=20fun=C3=A7=C3=B5es=20setup=20e=20loop=20Agora?= =?UTF-8?q?=20tanto=20setup=20como=20loop=20s=C3=A3o=20tasks,=20facilitand?= =?UTF-8?q?o=20o=20uso=20de=20delay()=20e=20outras=20fun=C3=A7=C3=B5es=20r?= =?UTF-8?q?elativas=20a=20tarefas=20dentro=20de=20setup();?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arduino.DuinOS.AVR/main.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/arduino.DuinOS.AVR/main.cpp b/arduino.DuinOS.AVR/main.cpp index efa2b7f..a81d078 100644 --- a/arduino.DuinOS.AVR/main.cpp +++ b/arduino.DuinOS.AVR/main.cpp @@ -1,9 +1,16 @@ #include + unsigned portBASE_TYPE mainLoopPriority; +xTaskHandle xHandleLoop; +xTaskHandle xHandleSetup; + void main_Task(void *pvParameters) { +#if INCLUDE_vTaskDelete + vTaskDelete(xHandleSetup); +#endif for (;;) { loop(); if (serialEventRun) serialEventRun(); @@ -11,6 +18,15 @@ void main_Task(void *pvParameters) } +void setup_Task(void *pvParameters) +{ + + setup(); + vTaskResume(xHandleLoop); + vTaskSuspend(NULL); + +} + int main(void) { mainLoopPriority = LOW_PRIORITY; @@ -19,12 +35,16 @@ int main(void) #if defined(USBCON) USBDevice.attach(); #endif - - setup(); - - xTaskCreate(main_Task, (signed portCHAR *) "main", configMINIMAL_STACK_SIZE, NULL, mainLoopPriority, NULL); + +// setup(); + + xTaskCreate(setup_Task, (signed portCHAR *) "setup", configMINIMAL_STACK_SIZE, NULL, HIGH_PRIORITY, &xHandleSetup); + + xTaskCreate(main_Task, (signed portCHAR *) "main", configMINIMAL_STACK_SIZE, NULL, mainLoopPriority, &xHandleLoop); + vTaskSuspend(xHandleLoop); + vTaskStartScheduler(); - + for (;;); return 0; From 25606e540a7634d78349d80ad4ea3109428da779 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Mon, 12 Nov 2012 15:04:19 -0200 Subject: [PATCH 15/56] =?UTF-8?q?Assionado=20Tick=20Hook=20para=20substitu?= =?UTF-8?q?i=C3=A7=C3=A3o=20da=20fun=C3=A7=C3=A3o=20que=20ajusta=20os=20mi?= =?UTF-8?q?llis=20segundos=20do=20Arduino.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arduino.DuinOS.AVR/FreeRTOSConfig.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/arduino.DuinOS.AVR/FreeRTOSConfig.h b/arduino.DuinOS.AVR/FreeRTOSConfig.h index 32106e5..b0b1ce3 100644 --- a/arduino.DuinOS.AVR/FreeRTOSConfig.h +++ b/arduino.DuinOS.AVR/FreeRTOSConfig.h @@ -81,7 +81,7 @@ //##Multiplo.Brain.M644: #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 0 - #define configUSE_TICK_HOOK 0 + #define configUSE_TICK_HOOK 1 //##20091029: Use compiler defined freq.: #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) @@ -121,7 +121,7 @@ //##Multiplo.Brain.M1284 #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 0 - #define configUSE_TICK_HOOK 0 + #define configUSE_TICK_HOOK 1 //##20091029: Use compiler defined freq.: #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) @@ -161,7 +161,7 @@ #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 0 - #define configUSE_TICK_HOOK 0 + #define configUSE_TICK_HOOK 1 //##20091029: Use compiler defined freq.: #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) @@ -202,7 +202,7 @@ #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 0 - #define configUSE_TICK_HOOK 0 + #define configUSE_TICK_HOOK 1 //##20091029: Use compiler defined freq.: #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) @@ -231,7 +231,7 @@ #define INCLUDE_vTaskPrioritySet 1 #define INCLUDE_uxTaskPriorityGet 1 //##If the following value is set to 1, change the memory managment scheme to heap_2.c: - #define INCLUDE_vTaskDelete 0 + #define INCLUDE_vTaskDelete 1 #define INCLUDE_vTaskCleanUpResources 0 #define INCLUDE_vTaskSuspend 1 #define INCLUDE_vTaskDelayUntil 1 @@ -242,7 +242,7 @@ #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 0 - #define configUSE_TICK_HOOK 0 + #define configUSE_TICK_HOOK 1 //##20091029: Use compiler defined freq.: #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) @@ -281,7 +281,7 @@ #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 0 - #define configUSE_TICK_HOOK 0 + #define configUSE_TICK_HOOK 1 //##20091029: Use compiler defined freq.: #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) From ef6395964cea901d66c02b82b14e24f3ab3e9ab6 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Mon, 12 Nov 2012 15:05:45 -0200 Subject: [PATCH 16/56] =?UTF-8?q?Agora=20=C3=A9=20possivel=20se=20ter=20a?= =?UTF-8?q?=20fun=C3=A7=C3=A3o=20deleteTask(),=20isto=20foi=20necess=C3=A1?= =?UTF-8?q?rio=20para=20uso=20na=20nova=20abordagem=20do=20main.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arduino.DuinOS.AVR/DuinOS.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arduino.DuinOS.AVR/DuinOS.h b/arduino.DuinOS.AVR/DuinOS.h index e835765..59869bc 100644 --- a/arduino.DuinOS.AVR/DuinOS.h +++ b/arduino.DuinOS.AVR/DuinOS.h @@ -79,6 +79,9 @@ inline void delay(const portTickType ticks) vTaskDelayUntil( &xLastWakeTime, ticks); } */ +#if INCLUDE_vTaskDelete + #define deleteTask(name) vTaskDelete(name); +#endif //This macro is quiet different from setPriority, because this works even in those CPUs wich does not support //the set/getPriority macros (due to their small RAM memories). And, this only has effect if called in setup(). From e2d1450f64b9ae321c6f7f123abae20a215e442e Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Mon, 12 Nov 2012 15:21:17 -0200 Subject: [PATCH 17/56] =?UTF-8?q?Adicionado=20deleteTask()=20para=20uso=20?= =?UTF-8?q?na=20nova=20abordagem=20do=20main.cpp,=20onde=20agora=20setup?= =?UTF-8?q?=20tamb=C3=A9m=20=C3=A9=20uma=20task.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arduino.DuinOS.AVR/DuinOS.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arduino.DuinOS.AVR/DuinOS.h b/arduino.DuinOS.AVR/DuinOS.h index e835765..59869bc 100644 --- a/arduino.DuinOS.AVR/DuinOS.h +++ b/arduino.DuinOS.AVR/DuinOS.h @@ -79,6 +79,9 @@ inline void delay(const portTickType ticks) vTaskDelayUntil( &xLastWakeTime, ticks); } */ +#if INCLUDE_vTaskDelete + #define deleteTask(name) vTaskDelete(name); +#endif //This macro is quiet different from setPriority, because this works even in those CPUs wich does not support //the set/getPriority macros (due to their small RAM memories). And, this only has effect if called in setup(). From 2378ba646633b1e0b76b6f5805abc1d0e95b4095 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Mon, 12 Nov 2012 15:22:54 -0200 Subject: [PATCH 18/56] =?UTF-8?q?ativado=20taskDelete=20no=20ATMega=202560?= =?UTF-8?q?=20para=20uso=20na=20nova=20abordagem=20do=20setup.cpp=20e=20ta?= =?UTF-8?q?mb=C3=A9m=20ativado=20Tick=20Hook=20para=20uso=20da=20fun=C3=A7?= =?UTF-8?q?=C3=A3o=20que=20atualiza=20milesegundos.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arduino.DuinOS.AVR/FreeRTOSConfig.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/arduino.DuinOS.AVR/FreeRTOSConfig.h b/arduino.DuinOS.AVR/FreeRTOSConfig.h index 32106e5..b0b1ce3 100644 --- a/arduino.DuinOS.AVR/FreeRTOSConfig.h +++ b/arduino.DuinOS.AVR/FreeRTOSConfig.h @@ -81,7 +81,7 @@ //##Multiplo.Brain.M644: #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 0 - #define configUSE_TICK_HOOK 0 + #define configUSE_TICK_HOOK 1 //##20091029: Use compiler defined freq.: #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) @@ -121,7 +121,7 @@ //##Multiplo.Brain.M1284 #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 0 - #define configUSE_TICK_HOOK 0 + #define configUSE_TICK_HOOK 1 //##20091029: Use compiler defined freq.: #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) @@ -161,7 +161,7 @@ #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 0 - #define configUSE_TICK_HOOK 0 + #define configUSE_TICK_HOOK 1 //##20091029: Use compiler defined freq.: #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) @@ -202,7 +202,7 @@ #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 0 - #define configUSE_TICK_HOOK 0 + #define configUSE_TICK_HOOK 1 //##20091029: Use compiler defined freq.: #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) @@ -231,7 +231,7 @@ #define INCLUDE_vTaskPrioritySet 1 #define INCLUDE_uxTaskPriorityGet 1 //##If the following value is set to 1, change the memory managment scheme to heap_2.c: - #define INCLUDE_vTaskDelete 0 + #define INCLUDE_vTaskDelete 1 #define INCLUDE_vTaskCleanUpResources 0 #define INCLUDE_vTaskSuspend 1 #define INCLUDE_vTaskDelayUntil 1 @@ -242,7 +242,7 @@ #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 0 - #define configUSE_TICK_HOOK 0 + #define configUSE_TICK_HOOK 1 //##20091029: Use compiler defined freq.: #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) @@ -281,7 +281,7 @@ #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 0 - #define configUSE_TICK_HOOK 0 + #define configUSE_TICK_HOOK 1 //##20091029: Use compiler defined freq.: #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) From 5fdb606357e5107c02f9cf55886ad2031cb6744e Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Mon, 12 Nov 2012 15:24:08 -0200 Subject: [PATCH 19/56] Nova abordagem do skeleto do Arduino que torna setup() uma task, permitindo assim o uso correto do novo delay(). --- arduino.DuinOS.AVR/main.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/arduino.DuinOS.AVR/main.cpp b/arduino.DuinOS.AVR/main.cpp index efa2b7f..a81d078 100644 --- a/arduino.DuinOS.AVR/main.cpp +++ b/arduino.DuinOS.AVR/main.cpp @@ -1,9 +1,16 @@ #include + unsigned portBASE_TYPE mainLoopPriority; +xTaskHandle xHandleLoop; +xTaskHandle xHandleSetup; + void main_Task(void *pvParameters) { +#if INCLUDE_vTaskDelete + vTaskDelete(xHandleSetup); +#endif for (;;) { loop(); if (serialEventRun) serialEventRun(); @@ -11,6 +18,15 @@ void main_Task(void *pvParameters) } +void setup_Task(void *pvParameters) +{ + + setup(); + vTaskResume(xHandleLoop); + vTaskSuspend(NULL); + +} + int main(void) { mainLoopPriority = LOW_PRIORITY; @@ -19,12 +35,16 @@ int main(void) #if defined(USBCON) USBDevice.attach(); #endif - - setup(); - - xTaskCreate(main_Task, (signed portCHAR *) "main", configMINIMAL_STACK_SIZE, NULL, mainLoopPriority, NULL); + +// setup(); + + xTaskCreate(setup_Task, (signed portCHAR *) "setup", configMINIMAL_STACK_SIZE, NULL, HIGH_PRIORITY, &xHandleSetup); + + xTaskCreate(main_Task, (signed portCHAR *) "main", configMINIMAL_STACK_SIZE, NULL, mainLoopPriority, &xHandleLoop); + vTaskSuspend(xHandleLoop); + vTaskStartScheduler(); - + for (;;); return 0; From c8baf3709b37e6865e14b71b1a55a04d6aabd2ae Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Mon, 12 Nov 2012 15:25:06 -0200 Subject: [PATCH 20/56] =?UTF-8?q?Corre=C3=A7=C3=B5es=20para=20uso=20no=20A?= =?UTF-8?q?TMega=202560.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arduino.DuinOS.AVR/DuinOS/port.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/arduino.DuinOS.AVR/DuinOS/port.c b/arduino.DuinOS.AVR/DuinOS/port.c index 4afbbb0..f0faee6 100644 --- a/arduino.DuinOS.AVR/DuinOS/port.c +++ b/arduino.DuinOS.AVR/DuinOS/port.c @@ -226,7 +226,13 @@ static void prvSetupTimerInterrupt( void ); */ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ) { -unsigned portSHORT usAddress; + /* ATmega2560 DuinOS port by SkyWodd */ +#if defined(__AVR_ATmega2560__) + unsigned portLONG usAddress; // ATMega2560 have 22bit Program Counter register +#else + unsigned portSHORT usAddress; // over ATmega have 16bit Program Counter register +#endif + /* Place a few bytes of known values on the bottom of the stack. This is just useful for debugging. */ @@ -243,6 +249,23 @@ unsigned portSHORT usAddress; /*lint -e950 -e611 -e923 Lint doesn't like this much - but nothing I can do about it. */ +#if defined(__AVR_ATmega2560__) + // Implement normal stack initialisation but with portLONG instead of portSHORT + usAddress = ( unsigned portLONG ) pxCode; + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); + pxTopOfStack--; + + usAddress >>= 8; + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); + pxTopOfStack--; + + // Implemented the 3byte addressing + usAddress >>= 8; + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); + pxTopOfStack--; + +// Normal initialisation for over ATmega +#else /* The start of the task code will be popped off the stack last, so place it on first. */ usAddress = ( unsigned portSHORT ) pxCode; @@ -252,6 +275,7 @@ unsigned portSHORT usAddress; usAddress >>= 8; *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff ); pxTopOfStack--; +#endif /* Next simulate the stack as if after a call to portSAVE_CONTEXT(). portSAVE_CONTEXT places the flags on the stack immediately after r0 From df3409994e76bffe6bb02cc80a0b5d67495ec77b Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Mon, 12 Nov 2012 15:25:42 -0200 Subject: [PATCH 21/56] =?UTF-8?q?Corre=C3=A7=C3=B5es=20do=20arquivo=20boar?= =?UTF-8?q?ds.txt,=20que=20foi=20perdido=20por=20motivo=20desconhecido.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hardware/boards.txt | 340 ++++++++++++++++++++++++++++++-------------- 1 file changed, 233 insertions(+), 107 deletions(-) diff --git a/hardware/boards.txt b/hardware/boards.txt index 7351d65..f0c0172 100644 --- a/hardware/boards.txt +++ b/hardware/boards.txt @@ -1,16 +1,21 @@ +# See: http://code.google.com/p/arduino/wiki/Platforms + ############################################################## -uno.name=Arduino Uno +uno.name=Arduino Uno +uno.upload.tool=avrdude uno.upload.protocol=arduino uno.upload.maximum_size=32256 uno.upload.speed=115200 -uno.bootloader.low_fuses=0xff -uno.bootloader.high_fuses=0xde + +uno.bootloader.tool=avrdude +uno.bootloader.low_fuses=0xFF +uno.bootloader.high_fuses=0xDE uno.bootloader.extended_fuses=0x05 -uno.bootloader.path=optiboot -uno.bootloader.file=optiboot_atmega328.hex uno.bootloader.unlock_bits=0x3F uno.bootloader.lock_bits=0x0F +uno.bootloader.file=optiboot/optiboot_atmega328.hex + uno.build.mcu=atmega328p uno.build.f_cpu=16000000L uno.build.core=arduino @@ -18,35 +23,63 @@ uno.build.variant=standard ############################################################## -uno_Duinos.name=Arduino Uno + Duinos -uno_Duinos.upload.protocol=arduino -uno_Duinos.upload.maximum_size=30720 -uno_Duinos.upload.speed=115200 -uno_Duinos.bootloader.low_fuses=0xff -uno_Duinos.bootloader.high_fuses=0xde -uno_Duinos.bootloader.extended_fuses=0x05 -uno_Duinos.bootloader.path=optiboot -uno_Duinos.bootloader.file=optiboot_atmega328.hex -uno_Duinos.bootloader.unlock_bits=0x3F -uno_Duinos.bootloader.lock_bits=0x0F -uno_Duinos.build.mcu=atmega328p -uno_Duinos.build.f_cpu=16000000L -uno_Duinos.build.core=arduino.DuinOS.avr -uno_Duinos.build.variant=standard +uno_DuinOS.name=Arduino Uno + DuinOS +uno_DuinOS.upload.tool=avrdude +uno_DuinOS.upload.protocol=arduino +uno_DuinOS.upload.maximum_size=32256 +uno_DuinOS.upload.speed=115200 + +uno_DuinOS.bootloader.tool=avrdude +uno_DuinOS.bootloader.low_fuses=0xFF +uno_DuinOS.bootloader.high_fuses=0xDE +uno_DuinOS.bootloader.extended_fuses=0x05 +uno_DuinOS.bootloader.unlock_bits=0x3F +uno_DuinOS.bootloader.lock_bits=0x0F +uno_DuinOS.bootloader.file=optiboot/optiboot_atmega328.hex + +uno_DuinOS.build.mcu=atmega328p +uno_DuinOS.build.f_cpu=16000000L +uno_DuinOS.build.core=arduino.DuinOS.AVR +uno_DuinOS.build.variant=standard + +############################################################## + +uno328.name=Arduino Uno w/ ATmega328 (non-P) +uno328.upload.tool=avrdude +uno328.upload.protocol=arduino +uno328.upload.maximum_size=32256 +uno328.upload.speed=115200 + +uno328.bootloader.tool=avrdude +uno328.bootloader.low_fuses=0xff +uno328.bootloader.high_fuses=0xde +uno328.bootloader.extended_fuses=0x05 +uno328.bootloader.unlock_bits=0x3F +uno328.bootloader.lock_bits=0x0F +uno328.bootloader.file=optiboot/optiboot_atmega328.hex + +uno328.build.mcu=atmega328 +uno328.build.f_cpu=16000000L +uno328.build.core=arduino +uno328.build.variant=standard ############################################################## atmega328.name=Arduino Duemilanove w/ ATmega328 + +atmega328.upload.tool=avrdude atmega328.upload.protocol=arduino atmega328.upload.maximum_size=30720 atmega328.upload.speed=57600 + +atmega328.bootloader.tool=avrdude atmega328.bootloader.low_fuses=0xFF atmega328.bootloader.high_fuses=0xDA atmega328.bootloader.extended_fuses=0x05 -atmega328.bootloader.path=atmega -atmega328.bootloader.file=ATmegaBOOT_168_atmega328.hex +atmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex atmega328.bootloader.unlock_bits=0x3F atmega328.bootloader.lock_bits=0x0F + atmega328.build.mcu=atmega328p atmega328.build.f_cpu=16000000L atmega328.build.core=arduino @@ -56,15 +89,16 @@ atmega328.build.variant=standard diecimila.name=Arduino Diecimila or Duemilanove w/ ATmega168 +diecimila.upload.tool=avrdude diecimila.upload.protocol=arduino diecimila.upload.maximum_size=14336 diecimila.upload.speed=19200 +diecimila.bootloader.tool=avrdude diecimila.bootloader.low_fuses=0xff diecimila.bootloader.high_fuses=0xdd diecimila.bootloader.extended_fuses=0x00 -diecimila.bootloader.path=atmega -diecimila.bootloader.file=ATmegaBOOT_168_diecimila.hex +diecimila.bootloader.file=atmega/ATmegaBOOT_168_diecimila.hex diecimila.bootloader.unlock_bits=0x3F diecimila.bootloader.lock_bits=0x0F @@ -76,16 +110,22 @@ diecimila.build.variant=standard ############################################################## nano328.name=Arduino Nano w/ ATmega328 +nano328.cpu=ATmega328 +nano328.container=Arduino Nano + +nano328.upload.tool=avrdude nano328.upload.protocol=arduino nano328.upload.maximum_size=30720 nano328.upload.speed=57600 + +nano328.bootloader.tool=avrdude nano328.bootloader.low_fuses=0xFF nano328.bootloader.high_fuses=0xDA nano328.bootloader.extended_fuses=0x05 -nano328.bootloader.path=atmega -nano328.bootloader.file=ATmegaBOOT_168_atmega328.hex +nano328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex nano328.bootloader.unlock_bits=0x3F nano328.bootloader.lock_bits=0x0F + nano328.build.mcu=atmega328p nano328.build.f_cpu=16000000L nano328.build.core=arduino @@ -94,16 +134,22 @@ nano328.build.variant=eightanaloginputs ############################################################## nano.name=Arduino Nano w/ ATmega168 +nano.cpu=ATmega168 +nano.container=Arduino Nano + +nano.upload.tool=avrdude nano.upload.protocol=arduino nano.upload.maximum_size=14336 nano.upload.speed=19200 + +nano.bootloader.tool=avrdude nano.bootloader.low_fuses=0xff nano.bootloader.high_fuses=0xdd nano.bootloader.extended_fuses=0x00 -nano.bootloader.path=atmega -nano.bootloader.file=ATmegaBOOT_168_diecimila.hex +nano.bootloader.file=atmega/ATmegaBOOT_168_diecimila.hex nano.bootloader.unlock_bits=0x3F nano.bootloader.lock_bits=0x0F + nano.build.mcu=atmega168 nano.build.f_cpu=16000000L nano.build.core=arduino @@ -112,16 +158,22 @@ nano.build.variant=eightanaloginputs ############################################################## mega2560.name=Arduino Mega 2560 or Mega ADK -mega2560.upload.protocol=stk500v2 +mega2560.cpu=2560 or ADK +mega2560.container=Arduino Mega 2560 + +mega2560.upload.tool=avrdude +mega2560.upload.protocol=wiring mega2560.upload.maximum_size=258048 mega2560.upload.speed=115200 + +mega2560.bootloader.tool=avrdude mega2560.bootloader.low_fuses=0xFF mega2560.bootloader.high_fuses=0xD8 mega2560.bootloader.extended_fuses=0xFD -mega2560.bootloader.path=stk500v2 -mega2560.bootloader.file=stk500boot_v2_mega2560.hex +mega2560.bootloader.file=stk500v2/stk500boot_v2_mega2560.hex mega2560.bootloader.unlock_bits=0x3F mega2560.bootloader.lock_bits=0x0F + mega2560.build.mcu=atmega2560 mega2560.build.f_cpu=16000000L mega2560.build.core=arduino @@ -129,35 +181,47 @@ mega2560.build.variant=mega ############################################################## -mega2560.name=Arduino Mega 2560 or Mega ADK -mega2560.upload.protocol=stk500v2 -mega2560.upload.maximum_size=258048 -mega2560.upload.speed=115200 -mega2560.bootloader.low_fuses=0xFF -mega2560.bootloader.high_fuses=0xD8 -mega2560.bootloader.extended_fuses=0xFD -mega2560.bootloader.path=stk500v2 -mega2560.bootloader.file=stk500boot_v2_mega2560.hex -mega2560.bootloader.unlock_bits=0x3F -mega2560.bootloader.lock_bits=0x0F -mega2560.build.mcu=atmega2560 -mega2560.build.f_cpu=16000000L -mega2560.build.core=arduino.DuinOS.avr -mega2560.build.variant=mega +mega2560_DuinOS.name=Arduino Mega 2560 or Mega ADK + DuinOS +mega2560_DuinOS.cpu=2560 or ADK +mega2560_DuinOS.container=Arduino Mega 2560 + DuinOS + +mega2560_DuinOS.upload.tool=avrdude +mega2560_DuinOS.upload.protocol=wiring +mega2560_DuinOS.upload.maximum_size=258048 +mega2560_DuinOS.upload.speed=115200 + +mega2560_DuinOS.bootloader.tool=avrdude +mega2560_DuinOS.bootloader.low_fuses=0xFF +mega2560_DuinOS.bootloader.high_fuses=0xD8 +mega2560_DuinOS.bootloader.extended_fuses=0xFD +mega2560_DuinOS.bootloader.file=stk500v2/stk500boot_v2_mega2560.hex +mega2560_DuinOS.bootloader.unlock_bits=0x3F +mega2560_DuinOS.bootloader.lock_bits=0x0F + +mega2560_DuinOS.build.mcu=atmega2560 +mega2560_DuinOS.build.f_cpu=16000000L +mega2560_DuinOS.build.core=arduino.DuinOS.AVR +mega2560_DuinOS.build.variant=mega ############################################################## mega.name=Arduino Mega (ATmega1280) +mega.cpu=ATmega1280 +mega.container=Arduino Mega 1280 + +mega.upload.tool=avrdude mega.upload.protocol=arduino mega.upload.maximum_size=126976 mega.upload.speed=57600 + +mega.bootloader.tool=avrdude mega.bootloader.low_fuses=0xFF mega.bootloader.high_fuses=0xDA mega.bootloader.extended_fuses=0xF5 -mega.bootloader.path=atmega -mega.bootloader.file=ATmegaBOOT_168_atmega1280.hex +mega.bootloader.file=atmega/ATmegaBOOT_168_atmega1280.hex mega.bootloader.unlock_bits=0x3F mega.bootloader.lock_bits=0x0F + mega.build.mcu=atmega1280 mega.build.f_cpu=16000000L mega.build.core=arduino @@ -165,53 +229,74 @@ mega.build.variant=mega ############################################################## -#leonardo.name=Arduino Leonardo -#leonardo.upload.protocol=arduino -#leonardo.upload.maximum_size=28672 -#leonardo.upload.speed=1200 -#leonardo.bootloader.low_fuses=0xde -#leonardo.bootloader.high_fuses=0xd8 -#leonardo.bootloader.extended_fuses=0xcb -#leonardo.bootloader.path=diskloader -#leonardo.bootloader.file=DiskLoader-Leonardo.hex -#leonardo.bootloader.unlock_bits=0x3F -#leonardo.bootloader.lock_bits=0x2F -#leonardo.build.mcu=atmega32u4 -#leonardo.build.f_cpu=16000000L -#leonardo.build.core=arduino -#leonardo.build.variant=leonardo +mega_DuinOS.name=Arduino Mega (ATmega1280) + DuinOS +mega_DuinOS.cpu=ATmega1280 +mega_DuinOS.container=Arduino Mega 1280 + DuinOS + +mega_DuinOS.upload.tool=avrdude +mega_DuinOS.upload.protocol=arduino +mega_DuinOS.upload.maximum_size=126976 +mega_DuinOS.upload.speed=57600 + +mega_DuinOS.bootloader.tool=avrdude +mega_DuinOS.bootloader.low_fuses=0xFF +mega_DuinOS.bootloader.high_fuses=0xDA +mega_DuinOS.bootloader.extended_fuses=0xF5 +mega_DuinOS.bootloader.file=atmega/ATmegaBOOT_168_atmega1280.hex +mega_DuinOS.bootloader.unlock_bits=0x3F +mega_DuinOS.bootloader.lock_bits=0x0F + +mega_DuinOS.build.mcu=atmega1280 +mega_DuinOS.build.f_cpu=16000000L +mega_DuinOS.build.core=arduino.DuinOS.AVR +mega_DuinOS.build.variant=mega ############################################################## -#micro.name=Arduino Micro -#micro.upload.protocol=arduino -#micro.upload.maximum_size=30720 -#micro.upload.speed=1200 -#micro.bootloader.low_fuses=0xde -#micro.bootloader.high_fuses=0xda -#micro.bootloader.extended_fuses=0xcb -#micro.bootloader.path=diskloader -#micro.bootloader.file=DiskLoader-Micro.hex -#micro.bootloader.unlock_bits=0x3F -#micro.bootloader.lock_bits=0x2F -#micro.build.mcu=atmega32u4 -#micro.build.f_cpu=16000000L -#micro.build.core=arduino -#micro.build.variant=micro +leonardo.name=Arduino Leonardo +leonardo.upload.tool=avrdude +leonardo.upload.protocol=avr109 +leonardo.upload.maximum_size=28672 +leonardo.upload.speed=57600 +leonardo.upload.disable_flushing=true +leonardo.upload.use_1200bps_touch=true +leonardo.upload.wait_for_upload_port=true + +leonardo.bootloader.tool=avrdude +leonardo.bootloader.low_fuses=0xff +leonardo.bootloader.high_fuses=0xd8 +leonardo.bootloader.extended_fuses=0xcb +leonardo.bootloader.file=caterina/Caterina-Leonardo.hex +leonardo.bootloader.unlock_bits=0x3F +leonardo.bootloader.lock_bits=0x2F + +leonardo.build.mcu=atmega32u4 +leonardo.build.f_cpu=16000000L +leonardo.build.vid=0x2341 +leonardo.build.pid=0x8036 +leonardo.build.core=arduino +leonardo.build.variant=leonardo +leonardo.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} ############################################################## mini328.name=Arduino Mini w/ ATmega328 -mini328.upload.protocol=stk500 +mini328.cpu=ATmega328 +mini328.container=Arduino Mini + +mini328.upload.tool=avrdude +mini328.upload.protocol=arduino mini328.upload.maximum_size=28672 mini328.upload.speed=115200 + +mini328.bootloader.tool=avrdude mini328.bootloader.low_fuses=0xff mini328.bootloader.high_fuses=0xd8 mini328.bootloader.extended_fuses=0x05 -mini328.bootloader.path=optiboot -mini328.bootloader.file=optiboot_atmega328-Mini.hex +mini328.bootloader.file=optiboot/optiboot_atmega328-Mini.hex mini328.bootloader.unlock_bits=0x3F mini328.bootloader.lock_bits=0x0F + mini328.build.mcu=atmega328p mini328.build.f_cpu=16000000L mini328.build.core=arduino @@ -220,16 +305,22 @@ mini328.build.variant=eightanaloginputs ############################################################## mini.name=Arduino Mini w/ ATmega168 +mini.cpu=ATmega168 +mini.container=Arduino Mini + +mini.upload.tool=avrdude mini.upload.protocol=arduino mini.upload.maximum_size=14336 mini.upload.speed=19200 + +mini.bootloader.tool=avrdude mini.bootloader.low_fuses=0xff mini.bootloader.high_fuses=0xdd mini.bootloader.extended_fuses=0x00 -mini.bootloader.path=atmega -mini.bootloader.file=ATmegaBOOT_168_ng.hex +mini.bootloader.file=atmega/ATmegaBOOT_168_ng.hex mini.bootloader.unlock_bits=0x3F mini.bootloader.lock_bits=0x0F + mini.build.mcu=atmega168 mini.build.f_cpu=16000000L mini.build.core=arduino @@ -238,16 +329,20 @@ mini.build.variant=eightanaloginputs ############################################################## ethernet.name=Arduino Ethernet + +ethernet.upload.tool=avrdude ethernet.upload.protocol=arduino ethernet.upload.maximum_size=32256 ethernet.upload.speed=115200 + +ethernet.bootloader.tool=avrdude ethernet.bootloader.low_fuses=0xff ethernet.bootloader.high_fuses=0xde ethernet.bootloader.extended_fuses=0x05 -ethernet.bootloader.path=optiboot -ethernet.bootloader.file=optiboot_atmega328.hex +ethernet.bootloader.file=optiboot/optiboot_atmega328.hex ethernet.bootloader.unlock_bits=0x3F ethernet.bootloader.lock_bits=0x0F + ethernet.build.variant=standard ethernet.build.mcu=atmega328p ethernet.build.f_cpu=16000000L @@ -257,15 +352,16 @@ ethernet.build.core=arduino fio.name=Arduino Fio +fio.upload.tool=avrdude fio.upload.protocol=arduino fio.upload.maximum_size=30720 fio.upload.speed=57600 +fio.bootloader.tool=avrdude fio.bootloader.low_fuses=0xFF fio.bootloader.high_fuses=0xDA fio.bootloader.extended_fuses=0x05 -fio.bootloader.path=arduino:atmega -fio.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex +fio.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex fio.bootloader.unlock_bits=0x3F fio.bootloader.lock_bits=0x0F @@ -277,17 +373,20 @@ fio.build.variant=eightanaloginputs ############################################################## bt328.name=Arduino BT w/ ATmega328 +bt328.cpu=ATmega328 +bt328.container=Arduino BT +bt328.upload.tool=avrdude bt328.upload.protocol=arduino bt328.upload.maximum_size=28672 bt328.upload.speed=19200 bt328.upload.disable_flushing=true +bt328.bootloader.tool=avrdude bt328.bootloader.low_fuses=0xff bt328.bootloader.high_fuses=0xd8 bt328.bootloader.extended_fuses=0x05 -bt328.bootloader.path=bt -bt328.bootloader.file=ATmegaBOOT_168_atmega328_bt.hex +bt328.bootloader.file=bt/ATmegaBOOT_168_atmega328_bt.hex bt328.bootloader.unlock_bits=0x3F bt328.bootloader.lock_bits=0x0F @@ -299,17 +398,20 @@ bt328.build.variant=eightanaloginputs ############################################################## bt.name=Arduino BT w/ ATmega168 +bt.cpu=ATmega168 +bt.container=Arduino BT +bt.upload.tool=avrdude bt.upload.protocol=arduino bt.upload.maximum_size=14336 bt.upload.speed=19200 bt.upload.disable_flushing=true +bt.bootloader.tool=avrdude bt.bootloader.low_fuses=0xff bt.bootloader.high_fuses=0xdd bt.bootloader.extended_fuses=0x00 -bt.bootloader.path=bt -bt.bootloader.file=ATmegaBOOT_168.hex +bt.bootloader.file=bt/ATmegaBOOT_168.hex bt.bootloader.unlock_bits=0x3F bt.bootloader.lock_bits=0x0F @@ -321,16 +423,19 @@ bt.build.variant=eightanaloginputs ############################################################## lilypad328.name=LilyPad Arduino w/ ATmega328 +lilypad328.cpu=ATmega328 +lilypad328.container=LilyPad Arduino +lilypad328.upload.tool=avrdude lilypad328.upload.protocol=arduino lilypad328.upload.maximum_size=30720 lilypad328.upload.speed=57600 +lilypad328.bootloader.tool=avrdude lilypad328.bootloader.low_fuses=0xFF lilypad328.bootloader.high_fuses=0xDA lilypad328.bootloader.extended_fuses=0x05 -lilypad328.bootloader.path=atmega -lilypad328.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex +lilypad328.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex lilypad328.bootloader.unlock_bits=0x3F lilypad328.bootloader.lock_bits=0x0F @@ -342,16 +447,19 @@ lilypad328.build.variant=standard ############################################################## lilypad.name=LilyPad Arduino w/ ATmega168 +lilypad.cpu=ATmega168 +lilypad.container=LilyPad Arduino +lilypad.upload.tool=avrdude lilypad.upload.protocol=arduino lilypad.upload.maximum_size=14336 lilypad.upload.speed=19200 +lilypad.bootloader.tool=avrdude lilypad.bootloader.low_fuses=0xe2 lilypad.bootloader.high_fuses=0xdd lilypad.bootloader.extended_fuses=0x00 -lilypad.bootloader.path=lilypad -lilypad.bootloader.file=LilyPadBOOT_168.hex +lilypad.bootloader.file=lilypad/LilyPadBOOT_168.hex lilypad.bootloader.unlock_bits=0x3F lilypad.bootloader.lock_bits=0x0F @@ -363,16 +471,19 @@ lilypad.build.variant=standard ############################################################## pro5v328.name=Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328 +pro5v328.cpu=ATmega328 (5V, 16 MHz) +pro5v328.container=Arduino Pro or Pro Mini +pro5v328.upload.tool=avrdude pro5v328.upload.protocol=arduino pro5v328.upload.maximum_size=30720 pro5v328.upload.speed=57600 +pro5v328.bootloader.tool=avrdude pro5v328.bootloader.low_fuses=0xFF pro5v328.bootloader.high_fuses=0xDA pro5v328.bootloader.extended_fuses=0x05 -pro5v328.bootloader.path=atmega -pro5v328.bootloader.file=ATmegaBOOT_168_atmega328.hex +pro5v328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex pro5v328.bootloader.unlock_bits=0x3F pro5v328.bootloader.lock_bits=0x0F @@ -384,16 +495,19 @@ pro5v328.build.variant=standard ############################################################## pro5v.name=Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega168 +pro5v.cpu=ATmega168 (5V, 16 MHz) +pro5v.container=Arduino Pro or Pro Mini +pro5v.upload.tool=avrdude pro5v.upload.protocol=arduino pro5v.upload.maximum_size=14336 pro5v.upload.speed=19200 +pro5v.bootloader.tool=avrdude pro5v.bootloader.low_fuses=0xff pro5v.bootloader.high_fuses=0xdd pro5v.bootloader.extended_fuses=0x00 -pro5v.bootloader.path=atmega -pro5v.bootloader.file=ATmegaBOOT_168_diecimila.hex +pro5v.bootloader.file=atmega/ATmegaBOOT_168_diecimila.hex pro5v.bootloader.unlock_bits=0x3F pro5v.bootloader.lock_bits=0x0F @@ -405,16 +519,19 @@ pro5v.build.variant=standard ############################################################## pro328.name=Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328 +pro328.cpu=ATmega328 (3.3V, 8 MHz) +pro328.container=Arduino Pro or Pro Mini +pro328.upload.tool=avrdude pro328.upload.protocol=arduino pro328.upload.maximum_size=30720 pro328.upload.speed=57600 +pro328.bootloader.tool=avrdude pro328.bootloader.low_fuses=0xFF pro328.bootloader.high_fuses=0xDA pro328.bootloader.extended_fuses=0x05 -pro328.bootloader.path=atmega -pro328.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex +pro328.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex pro328.bootloader.unlock_bits=0x3F pro328.bootloader.lock_bits=0x0F @@ -426,16 +543,19 @@ pro328.build.variant=standard ############################################################## pro.name=Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega168 +pro.cpu=ATmega168 (3.3V, 8 MHz) +pro.container=Arduino Pro or Pro Mini +pro.upload.tool=avrdude pro.upload.protocol=arduino pro.upload.maximum_size=14336 pro.upload.speed=19200 +pro.bootloader.tool=avrdude pro.bootloader.low_fuses=0xc6 pro.bootloader.high_fuses=0xdd pro.bootloader.extended_fuses=0x00 -pro.bootloader.path=atmega -pro.bootloader.file=ATmegaBOOT_168_pro_8MHz.hex +pro.bootloader.file=atmega/ATmegaBOOT_168_pro_8MHz.hex pro.bootloader.unlock_bits=0x3F pro.bootloader.lock_bits=0x0F @@ -447,16 +567,19 @@ pro.build.variant=standard ############################################################## atmega168.name=Arduino NG or older w/ ATmega168 +atmega168.cpu=ATmega168 +atmega168.container=Arduino NG or older +atmega168.upload.tool=avrdude atmega168.upload.protocol=arduino atmega168.upload.maximum_size=14336 atmega168.upload.speed=19200 +atmega168.bootloader.tool=avrdude atmega168.bootloader.low_fuses=0xff atmega168.bootloader.high_fuses=0xdd atmega168.bootloader.extended_fuses=0x00 -atmega168.bootloader.path=atmega -atmega168.bootloader.file=ATmegaBOOT_168_ng.hex +atmega168.bootloader.file=atmega/ATmegaBOOT_168_ng.hex atmega168.bootloader.unlock_bits=0x3F atmega168.bootloader.lock_bits=0x0F @@ -468,15 +591,18 @@ atmega168.build.variant=standard ############################################################## atmega8.name=Arduino NG or older w/ ATmega8 +atmega8.cpu=ATmega8 +atmega8.container=Arduino NG or older +atmega8.upload.tool=avrdude atmega8.upload.protocol=arduino atmega8.upload.maximum_size=7168 atmega8.upload.speed=19200 +atmega8.bootloader.tool=avrdude atmega8.bootloader.low_fuses=0xdf atmega8.bootloader.high_fuses=0xca -atmega8.bootloader.path=atmega8 -atmega8.bootloader.file=ATmegaBOOT.hex +atmega8.bootloader.file=atmega8/ATmegaBOOT.hex atmega8.bootloader.unlock_bits=0x3F atmega8.bootloader.lock_bits=0x0F From 4c455a4b44530796c4a36388720e771bd00cb867 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Mon, 12 Nov 2012 15:26:23 -0200 Subject: [PATCH 22/56] =?UTF-8?q?Atualiza=C3=A7=C3=A3o=20do=20arquivo=20Re?= =?UTF-8?q?adme.txt=20para=20a=20nova=20vers=C3=A3o.=20Adicionado=20novos?= =?UTF-8?q?=20arquivos=20para=20lista=20de=20ignorados.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + Readme.txt | 31 ++++++++++++++++++++----------- 2 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..98bbc31 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/Debug diff --git a/Readme.txt b/Readme.txt index 263e214..dd7cbf8 100644 --- a/Readme.txt +++ b/Readme.txt @@ -1,21 +1,24 @@ ******************************** - DuinOS v0.4 Alpha + DuinOS v0.6.1 Beta ******************************** Copyright (C) 2009 Multiplo http://multiplo.org http://robotgroup.com.ar Created by Julián U. da Silva Gillig. +Ported by Carlos Delfino {consultoria@carlosdelfino.eti.br} +Copyleft (C) 2012 Carlos Delfino e Amigos +http://www.carlosdelfino.eti.br -Based on the FreeRTOS v6.1.0 kernel (www.freertos.org). Please see the License section below. +Based on the FreeRTOS v7.3.0 kernel (www.freertos.org). Please see the License section below. This is our only distribution of DuinOS, which includes the complete source code. The last version is always available -from http://robotgroup.com.ar +from https://github.com/CarlosDelfino/DuinOS/downloads ******************************** License ******************************** -The DuinOS kernel (cores\arduino.DuinOS) is under the same license as the FreeRTOS operating system (www.freertos.org) +The DuinOS kernel (cores\arduino.DuinOS.*) is under the same license as the FreeRTOS operating system (www.freertos.org) Please see the included FreeRTOS.license.txt file. We have used too, some files belonging to the AVR port of the FreeRTOS operating system, made by Micropendous @@ -29,7 +32,7 @@ By Opendous Inc. www.Micropendous.org October 04, 2009 -Please visit www.micropendous.org if there is any doubt. +Please visit www.micropendous.org or contact consultoria@carlosdelfino.eti if there is any doubt NOTE: We strongly believe in peace, so we would not like to see our work in any non-civil or military project. But, due to the FreeRTOS's modified GPL license which we do have to maintain, this is only a recommendation and an expression of @@ -41,14 +44,14 @@ our wishes. ******************************** 0. Close the Arduino IDE (all instances). -1. Copy the arduino.DuinOS folder to the \hardware\cores folder. -2. Rename your current \hardware\boards.txt file. -3. Copy the boards.txt deployed with DuinOS to the \hardware folder. +1. Copy the arduino.DuinOS.* folder to the \hardware\arduino\*\cores folder. +2. Rename your current \hardware\arduino\*\boards.txt file. +3. Copy the *\boards.txt deployed with DuinOS to the \hardware\arduino\* folder, remember eatch borads.*.txt for respective hardware folder. 4. Rename your current \lib\keywords.txt file. 5. Copy the keywords.txt deployed with DuinOS to the \lib folder. 6. Start the Arduino IDE. 7. Please select any DuinOS board from the Tools->Board menu, like the "Arduino Duemilanove or Nano w/ ATmega328 + DuinOS". -8. Now, you can compile any standard project, but we suggest the \examples\MoreComplexBlinking deployed with DuinOS. +8. Now, you can compile any standard project, but we suggest the \examples\DuinOS\MoreComplexBlinking deployed with DuinOS. ******************************** Uninstall @@ -57,7 +60,7 @@ our wishes. 0. Close the Arduino IDE (all instances). 1. If you have renamed the original boards.txt file, delete the current boards.txt file and rename the previous one (so it will be now your new boards.txt). 2. If you have renamed the original keywords.txt file, delete the current keywords.txt file and rename the previous one (so it will be now your new keywords.txt). -3. Delete the arduino.DuinOS folder from the \cores folder. +3. Delete the arduino.DuinOS folder from the \cores\arduino\* folder. 4. Now you can restart the Arduino IDE and keep working without DuinOS. ******************************** @@ -112,4 +115,10 @@ MATERIALS ON THIS WEBSITE. - Use Timer0 for FreeRTOS - Remove Servo library (standard one should work) * 0. - +* 0. +* 0.6.1 Beta / 2012.01.01 (Carlos Delfino ) +- Arduino IDE updated to version 1.5.0 +- FreeRTOS updated to 7.3.0 +- Tested with MoreComplexBlinking example on Arduino UNO e Arduino Mega +- created a folder for eatch mcu (AVR and ARM) +- created a folder boards for eatch mcu \ No newline at end of file From 5774776b8aac50086f8e2c414d8d8a77d16e9957 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Date: Mon, 12 Nov 2012 15:51:25 -0200 Subject: [PATCH 23/56] Adicionado nova variavel e macro de controle do StackSize para o Loop, podendo ser ajustado com a macro de nome initMainLoopStackSize(ssize). Aumentado o StackSize da tarefa que gerencia o setup. Feito isto para uso com bibliotecas mais pesadas. --- .gitignore | 3 +++ arduino.DuinOS.AVR/DuinOS.h | 11 ++++++++++- arduino.DuinOS.AVR/main.cpp | 10 ++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 3462d9f..2125e36 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ /.settings /Debug +/.autotools +/.cproject +/.project diff --git a/arduino.DuinOS.AVR/DuinOS.h b/arduino.DuinOS.AVR/DuinOS.h index 59869bc..0bd5c12 100644 --- a/arduino.DuinOS.AVR/DuinOS.h +++ b/arduino.DuinOS.AVR/DuinOS.h @@ -27,6 +27,7 @@ extern "C" #endif extern unsigned portBASE_TYPE mainLoopPriority; +extern unsigned portBASE_TYPE mainLoopStackSize; //In small devices, we use only 3 priorities: #define LOW_PRIORITY (tskIDLE_PRIORITY) @@ -45,7 +46,10 @@ void name##Function() //This macro enables the forward declaration of a task, to allow other tasks previous defined (with the //taskLoop()macro use and reference them: -#define declareTaskLoop(name) extern xTaskHandle name +#define declareTaskLoop(name)\ + extern xTaskHandle name;\ + void name##_Task(void*) + #define createTaskLoop(name, priority)\ {\ @@ -87,6 +91,11 @@ inline void delay(const portTickType ticks) //the set/getPriority macros (due to their small RAM memories). And, this only has effect if called in setup(). #define initMainLoopPriority(priority) (mainLoopPriority = priority) +//This macro set the StackSize for use in Main Loop. +//Use with care for not drain all memory +//And, this only has effect if called in setup(). +#define initMainLoopStackSize(ssize) (mainLoopStackSize = ssize) + //These only works if INCLUDE_vTaskPrioritySet / INCLUDE_vTaskPriorityGet are != 0 //(disabled for CPUs with less than 2KB RAM): #if INCLUDE_vTaskPriorityGet //This #if is to improve the error readability. diff --git a/arduino.DuinOS.AVR/main.cpp b/arduino.DuinOS.AVR/main.cpp index a81d078..2dd89fe 100644 --- a/arduino.DuinOS.AVR/main.cpp +++ b/arduino.DuinOS.AVR/main.cpp @@ -1,7 +1,10 @@ #include +unsigned portBASE_TYPE mainSetupPriority; +unsigned portBASE_TYPE mainSetupStackSize; unsigned portBASE_TYPE mainLoopPriority; +unsigned portBASE_TYPE mainLoopStackSize; xTaskHandle xHandleLoop; xTaskHandle xHandleSetup; @@ -29,7 +32,10 @@ void setup_Task(void *pvParameters) int main(void) { + mainSetupPriority = HIGH_PRIORITY; + mainSetupStackSize = configMINIMAL_STACK_SIZE * 2; mainLoopPriority = LOW_PRIORITY; + mainLoopStackSize = configMINIMAL_STACK_SIZE; init(); #if defined(USBCON) @@ -38,9 +44,9 @@ int main(void) // setup(); - xTaskCreate(setup_Task, (signed portCHAR *) "setup", configMINIMAL_STACK_SIZE, NULL, HIGH_PRIORITY, &xHandleSetup); + xTaskCreate(setup_Task, (signed portCHAR *) "setup", mainSetupStackSize, NULL, mainSetupStackSize, &xHandleSetup); - xTaskCreate(main_Task, (signed portCHAR *) "main", configMINIMAL_STACK_SIZE, NULL, mainLoopPriority, &xHandleLoop); + xTaskCreate(main_Task, (signed portCHAR *) "main", mainLoopStackSize, NULL, mainLoopPriority, &xHandleLoop); vTaskSuspend(xHandleLoop); vTaskStartScheduler(); From d5e1b040b33f853ca331b24b38e9a1807e2f62de Mon Sep 17 00:00:00 2001 From: Carlos Delfino Date: Mon, 12 Nov 2012 17:49:45 -0200 Subject: [PATCH 24/56] =?UTF-8?q?Continua=C3=A7=C3=A3o=20dos=20ajustes=20n?= =?UTF-8?q?o=20exemplo=20de=20uso=20de=20LCD=20com=20DuinOS.=20J=C3=A1=20d?= =?UTF-8?q?escobri=20que=20da=20mesma=20forma=20com=20a=20Serial,=20o=20ta?= =?UTF-8?q?manho=20do=20Stack=20influ=C3=AAncia=20em=20seu=20funcionamento?= =?UTF-8?q?.=20Outro=20problema=20que=20encontrei=20est=C3=A1=20na=20fun?= =?UTF-8?q?=C3=A7=C3=A3o=20lcd.print(int)=20que=20usada=20com=20inteiros?= =?UTF-8?q?=20so=20funciona=20na=20primeira=20chamada,=20travando=20na=20s?= =?UTF-8?q?eguna=20em=20diante.=20Outro=20problema,=20caso=20se=20tente=20?= =?UTF-8?q?mudar=20a=20posi=C3=A7=C3=A3o=20do=20cursor=20em=20task=20difer?= =?UTF-8?q?entes=20isto=20pode=20se=20tornar=20um=20conflito,=20portanto?= =?UTF-8?q?=20=C3=A9=20fundamental=20o=20uso=20de=20mutex=20para=20sincron?= =?UTF-8?q?izar=20sequencias=20de=20chamadas=20as=20fun=C3=A7=C3=B5es=20de?= =?UTF-8?q?=20LCD,=20portanto=20se=20posicionar=20o=20cursor=20somente=20o?= =?UTF-8?q?utra=20thread=20pode=20posicionar=20e/ou=20imprimir,=20quando?= =?UTF-8?q?=20a=20primeira=20terminar=20seu=20trabalho=20no=20LCD.=20Este?= =?UTF-8?q?=20tipo=20de=20problema=20=C3=A9=20b=C3=A1sico=20em=20qualquer?= =?UTF-8?q?=20utiliza=C3=A7=C3=A3o=20de=20recursos,=20portanto=20o=20uso?= =?UTF-8?q?=20de=20mutex=20ser=C3=A1=20necess=C3=A1rio=20em=20todos=20os?= =?UTF-8?q?=20recursos=20como=20por=20exemplo=20Seriais,=20SD=20Cards,=20W?= =?UTF-8?q?iFI,=20Ethernet,=20LCDs=20e=20por=20ai=20vai.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/DuinOS/LCDMultiTask/LCDMultiTask.ino | 205 +++++++++++++++--- 1 file changed, 170 insertions(+), 35 deletions(-) diff --git a/examples/DuinOS/LCDMultiTask/LCDMultiTask.ino b/examples/DuinOS/LCDMultiTask/LCDMultiTask.ino index 67b8d42..cb10a59 100644 --- a/examples/DuinOS/LCDMultiTask/LCDMultiTask.ino +++ b/examples/DuinOS/LCDMultiTask/LCDMultiTask.ino @@ -1,50 +1,185 @@ +/** + * Exemplo de Uso de LCD com DuinOS + * O exemplo demonstra as melhores práticas para uso do LCD. + * Este exemplo está sendo construindo e no momento seu código foi ajustado para + * LCD de 16x2 e 20x4 + * O Exemplo também demonstra o uso de Mutex para evitar concorrencia no posicionamento + * do cursor, o que pode causar impressões misturadas, em locais errados. + * + * Autor: Carlos Delfino + * E-mail Autor: consultoria@carlosdelfino.eti.br + */ +#define configUSE_MUTEX 1; -#include +#include +#define LCD_C16_R2 1 +#define LCD_C20_R4 2 +#define LCD_TYPE LCD_C20_R4 +#if (LCD_TYPE == LCD_C16_R2) +#define COL 16 +#define ROW 2 +#define LCD_BACKGROUND_LIMIT_MAX 180 +#define LCD_BACKGROUND_LIMIT_MIN 50 +#elif (LCD_TYPE == LCD_C20_R4) +#define COL 20 +#define ROW 4 +#define LCD_BACKGROUND_LIMIT_MAX 180 +#define LCD_BACKGROUND_LIMIT_MIN 50 +#else +#define COL 16 +#define ROW 2 +#define LCD_BACKGROUND_LIMIT_MAX 180 +#define LCD_BACKGROUND_LIMIT_MIN 50 +#endif -LiquidCrystal2 lcd(10,11,2,3,4,5); + + +#define constrast_pin 6 +#define background_pin 9 + +#define sensor1_pin A0 +#define sensor2_pin A1 + +#define sensor1_col 10 +#define sensor2_col 10 +#define sensor1_row 2 +#define sensor2_row 3 + +LiquidCrystal lcd(7,8,2,3,4,5); //LiquidCrystal2 lcd(10,11,22,24,26,28); + +#include +xSemaphoreHandle xMutexLCD = NULL; + +declareTaskLoop(changeLCD); +declareTaskLoop(readSensor1); +declareTaskLoop(readSensor2); +declareTaskLoop(changeLCDSensor1); +declareTaskLoop(changeLCDSensor2); + +int sensor1; +int sensor2; + void setup(){ - lcd.begin(16,2); - - pinMode(8,OUTPUT); - pinMode(9,OUTPUT); - - analogWrite(8,200); // contraste - analogWrite(9,128); // brilho de fundo - lcd.write("1234567890123456"); + + initMainLoopStackSize(configMINIMAL_STACK_SIZE*3); + + pinMode(constrast_pin,OUTPUT); + pinMode(background_pin,OUTPUT); + + pinMode(13,OUTPUT); + digitalWrite(13,HIGH); + + analogWrite(constrast_pin, 50); // contraste + analogWrite(background_pin, LCD_BACKGROUND_LIMIT_MAX); // brilho de fundo + + vSemaphoreCreateBinary(xMutexLCD); + + lcd.begin(COL,ROW); + + digitalWrite(13,LOW); + + lcd.home(); + for(char i = 0; i< COL;i++) lcd.write("*"); + lcd.setCursor(0,1); + + int fator = (COL - 15)/2; + for(char i = 0; i=100;i--) { - analogWrite(8,i); - delay(15); +void loop(){ + digitalWrite(13,!digitalRead(13)); + delay(800); + + unsigned char i; + for(i=LCD_BACKGROUND_LIMIT_MAX;i>=LCD_BACKGROUND_LIMIT_MIN;i--) { + analogWrite(background_pin,i); + delay(15); + } + for(i=LCD_BACKGROUND_LIMIT_MIN;i<=LCD_BACKGROUND_LIMIT_MAX;i++) { + analogWrite(background_pin,i); + delay(15); + } + +} + +taskLoop(changeLCD){ + //taskENTER_CRITICAL(); + + + char x=0; + for(char i=40;i<128;i++){ + if(xSemaphoreTake(xMutexLCD, ( portTickType ) 10 ) == pdTRUE){ + lcd.setCursor(x++,1); + lcd.write(i); + xSemaphoreGive(xMutexLCD); } - - - + if(x>=COL)x=0; + delay(30); + } + //taskEXIT_CRITICAL(); +} + +taskLoop(readSensor1){ + sensor1 = analogRead(sensor1_pin); + resumeTask(changeLCDSensor1); +} +taskLoop(readSensor2){ + sensor2 = analogRead(sensor1_pin); + resumeTask(changeLCDSensor2); } +taskLoop(changeLCDSensor1){ + if(xSemaphoreTake(xMutexLCD, ( portTickType ) 10 ) == pdTRUE){ + lcd.setCursor(sensor1_col,sensor1_row); + lcd.print("Sen1"); // aqui deve ser espaço em branco, para limpar valores maiores do que o que será exibido. + lcd.print(sensor1); + xSemaphoreGive(xMutexLCD); + } + suspend(); +} + +taskLoop(changeLCDSensor2){ + + if(xSemaphoreTake(xMutexLCD, ( portTickType ) 10 ) == pdTRUE){ + lcd.setCursor(sensor2_col,sensor2_row); + lcd.print("Sen2"); // aqui deve ser espaço em branco, para limpar valores maiores do que o que será exibido. + //lcd.print(sensor2); + xSemaphoreGive(xMutexLCD); + } + + suspend(); +} + From 47c0eb450f274030d013ff634f3abbb82d9dd0fc Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Thu, 15 Nov 2012 16:03:17 -0200 Subject: [PATCH 25/56] =?UTF-8?q?Como=20o=20Arduino=20UNO,=20Mega=202560?= =?UTF-8?q?=20e=201280=20n=C3=A3o=20variam=20a=20CPU=20n=C3=A3o=20precisa?= =?UTF-8?q?=20deste=20parametro,=20por=C3=A9m=20na=20vers=C3=A3o=20disponi?= =?UTF-8?q?vel=20para=20download=20o=20arquivo=20Boards.txt=20precisa=20se?= =?UTF-8?q?r=20substituido=20para=20este=20novo,=20ou=20n=C3=A3o=20se=20es?= =?UTF-8?q?quecer=20de=20selecionar=20a=20CPU=20depois=20de=20selecionar?= =?UTF-8?q?=20a=20Placa=20"Board"=20Em=20um=20momento=20oportuno=20estarei?= =?UTF-8?q?=20unindo=20o=20Arduino=20Mega=20em=20um=20unico=20container,?= =?UTF-8?q?=20mantendo=20as=20CPUs=20diferentes,=20sendo:=20ATmega=202560?= =?UTF-8?q?=20ATmega=201280=20ATmega=20ADK?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hardware/avr/boards.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hardware/avr/boards.txt b/hardware/avr/boards.txt index 28db4eb..71d60ad 100644 --- a/hardware/avr/boards.txt +++ b/hardware/avr/boards.txt @@ -161,8 +161,8 @@ mega2560.build.variant=mega ############################################################## mega2560_DuinOS.name=Arduino Mega 2560 or Mega ADK + DuinOS -mega2560_DuinOS.cpu=2560 or ADK -mega2560_DuinOS.container=Arduino Mega 2560 + DuinOS +#mega2560_DuinOS.cpu=2560 or ADK +#mega2560_DuinOS.container=Arduino Mega 2560 + DuinOS mega2560_DuinOS.upload.tool=avrdude mega2560_DuinOS.upload.protocol=wiring @@ -185,8 +185,8 @@ mega2560_DuinOS.build.variant=mega ############################################################## mega.name=Arduino Mega (ATmega1280) -mega.cpu=ATmega1280 -mega.container=Arduino Mega 1280 +#mega.cpu=ATmega1280 +#mega.container=Arduino Mega 1280 mega.upload.tool=avrdude mega.upload.protocol=arduino @@ -209,8 +209,8 @@ mega.build.variant=mega ############################################################## mega_DuinOS.name=Arduino Mega (ATmega1280) + DuinOS -mega_DuinOS.cpu=ATmega1280 -mega_DuinOS.container=Arduino Mega 1280 + DuinOS +#mega_DuinOS.cpu=ATmega1280 +#mega_DuinOS.container=Arduino Mega 1280 + DuinOS mega_DuinOS.upload.tool=avrdude mega_DuinOS.upload.protocol=arduino From 59e843d308d71b5df75cefbaf8274b55e8d70c60 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Date: Sun, 18 Nov 2012 03:08:36 -0200 Subject: [PATCH 26/56] =?UTF-8?q?Novas=20Macros=20que=20auxiliam=20na=20de?= =?UTF-8?q?limita=C3=A7=C3=A3o=20de=20fun=C3=A7=C3=B5es=20e=20blocks=20cri?= =?UTF-8?q?ticos.=20Fun=C3=A7=C3=B5es=20ou=20Blocos=20Criticos=20s=C3=A3o?= =?UTF-8?q?=20blocos=20de=20codigos=20que=20n=C3=A3o=20podem=20sofrer=20in?= =?UTF-8?q?terrup=C3=A7=C3=B5es=20durante=20sua=20execu=C3=A7=C3=A3o.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arduino.DuinOS.AVR/DuinOS.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arduino.DuinOS.AVR/DuinOS.h b/arduino.DuinOS.AVR/DuinOS.h index 0bd5c12..fc6a161 100644 --- a/arduino.DuinOS.AVR/DuinOS.h +++ b/arduino.DuinOS.AVR/DuinOS.h @@ -74,6 +74,17 @@ void name##Function() #define nextTask() taskYIELD() #define delay(ticks) vTaskDelay(ticks) + +#define criticalFunction(region) void region##_CriticalFunction(void);\ + {\ + enterCritical();\ + region##_CriticalFunction();\ + exitCritical();\ + }\ + void region##_CriticalFunction(void) + +#define enterCritical() portENTER_CRITICAL() +#define exitCritical() portEXIT_CRITICAL() /* inline void delay(const portTickType ticks) { From e912f6bcfa6d7f2ba3f560cff21d7c3a6dc4778c Mon Sep 17 00:00:00 2001 From: Carlos Delfino Date: Sun, 18 Nov 2012 03:15:17 -0200 Subject: [PATCH 27/56] =?UTF-8?q?corrigido=20as=20fun=C3=A7=C3=B5es=20de?= =?UTF-8?q?=20interrup=C3=A7=C3=B5es,=20j=C3=A1=20que=20quando=20usado=20p?= =?UTF-8?q?reemp=C3=A7=C3=A3o=20n=C3=A3o=20=C3=A9=20indicado=20a=20grava?= =?UTF-8?q?=C3=A7=C3=A3o=20do=20contexto=20utilizado=20pelo=20gcc,=20ent?= =?UTF-8?q?=C3=A3o=20=C3=A9=20usado=20o=20atributo=20"naked",=20para=20pat?= =?UTF-8?q?ronizar=20tanto=20com=20preemp=C3=A7=C3=A3o=20quando=20sem,=20a?= =?UTF-8?q?s=20assintaturas=20das=20fun=C3=A7=C3=B5es=20de=20interrup?= =?UTF-8?q?=C3=A7=C3=B5es=20foram=20reescritas.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arduino.DuinOS.AVR/DuinOS/port.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/arduino.DuinOS.AVR/DuinOS/port.c b/arduino.DuinOS.AVR/DuinOS/port.c index f0faee6..1ac53ec 100644 --- a/arduino.DuinOS.AVR/DuinOS/port.c +++ b/arduino.DuinOS.AVR/DuinOS/port.c @@ -475,14 +475,16 @@ static void prvSetupTimerInterrupt( void ) void SIG_OUTPUT_COMPARE1A( void ) __attribute__ ( ( signal, naked ) ); void SIG_OUTPUT_COMPARE1A( void ) */ - #if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) - ISR(TIM0_OVF_vect) +#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) + void TIM0_OVF_vect(void) __attribute__ ((signal,__INTR_ATTRS,naked)); + void TIM0_OVF_vect(void) #else - ISR(TIMER0_OVF_vect) + void TIMER0_OVF_vect(void) __attribute__ ((signal,__INTR_ATTRS,naked)); + void TIMER0_OVF_vect(void) #endif { vPortYieldFromTick(); - //asm volatile ( "reti" ); + asm volatile ( "reti" ); } #else @@ -496,9 +498,11 @@ static void prvSetupTimerInterrupt( void ) void SIG_OUTPUT_COMPARE1A( void ) */ #if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) - SIGNAL(TIM0_OVF_vect) + void TIM0_OVF_vect(void) __attribute__ ((signal,__INTR_ATTRS)); + void TIM0_OVF_vect(void) #else - SIGNAL(TIMER0_OVF_vect) + void TIMER0_OVF_vect(void) __attribute__ ((signal,__INTR_ATTRS)); + void TIMER0_OVF_vect(void) #endif { vTaskIncrementTick(); From 1cdc6a3623aaf2677e3df9a1ff6db58f0687e297 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Date: Sun, 18 Nov 2012 13:52:51 -0200 Subject: [PATCH 28/56] Novos Exemplos usando LCD. Adotado o conceito de submodulo do GIT. --- .gitignore | 1 + .gitmodules | 3 + examples/DuinOS | 1 + examples/DuinOS/LCDMultiTask/LCDMultiTask.ino | 185 ------------------ .../MoreComplexBlinking.pde | 119 ----------- .../MoreComplexBlinkingAndSound.pde | 108 ---------- 6 files changed, 5 insertions(+), 412 deletions(-) create mode 100644 .gitmodules create mode 160000 examples/DuinOS delete mode 100644 examples/DuinOS/LCDMultiTask/LCDMultiTask.ino delete mode 100644 examples/DuinOS/MoreComplexBlinking/MoreComplexBlinking.pde delete mode 100644 examples/DuinOS/MoreComplexBlinkingAndSound/MoreComplexBlinkingAndSound.pde diff --git a/.gitignore b/.gitignore index 2125e36..3c289e7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /.autotools /.cproject /.project +/examples.original diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..507bbfb --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "examples/DuinOS"] + path = examples/DuinOS + url = ssh://git@github.com/carlosdelfino/DuinOS-Examples.git diff --git a/examples/DuinOS b/examples/DuinOS new file mode 160000 index 0000000..237fc1c --- /dev/null +++ b/examples/DuinOS @@ -0,0 +1 @@ +Subproject commit 237fc1ce4441952b64fface22a46f35b1f596866 diff --git a/examples/DuinOS/LCDMultiTask/LCDMultiTask.ino b/examples/DuinOS/LCDMultiTask/LCDMultiTask.ino deleted file mode 100644 index cb10a59..0000000 --- a/examples/DuinOS/LCDMultiTask/LCDMultiTask.ino +++ /dev/null @@ -1,185 +0,0 @@ -/** - * Exemplo de Uso de LCD com DuinOS - * O exemplo demonstra as melhores práticas para uso do LCD. - * Este exemplo está sendo construindo e no momento seu código foi ajustado para - * LCD de 16x2 e 20x4 - * O Exemplo também demonstra o uso de Mutex para evitar concorrencia no posicionamento - * do cursor, o que pode causar impressões misturadas, em locais errados. - * - * Autor: Carlos Delfino - * E-mail Autor: consultoria@carlosdelfino.eti.br - */ -#define configUSE_MUTEX 1; - -#include - -#define LCD_C16_R2 1 -#define LCD_C20_R4 2 -#define LCD_TYPE LCD_C20_R4 - -#if (LCD_TYPE == LCD_C16_R2) -#define COL 16 -#define ROW 2 -#define LCD_BACKGROUND_LIMIT_MAX 180 -#define LCD_BACKGROUND_LIMIT_MIN 50 -#elif (LCD_TYPE == LCD_C20_R4) -#define COL 20 -#define ROW 4 -#define LCD_BACKGROUND_LIMIT_MAX 180 -#define LCD_BACKGROUND_LIMIT_MIN 50 -#else -#define COL 16 -#define ROW 2 -#define LCD_BACKGROUND_LIMIT_MAX 180 -#define LCD_BACKGROUND_LIMIT_MIN 50 -#endif - - - -#define constrast_pin 6 -#define background_pin 9 - -#define sensor1_pin A0 -#define sensor2_pin A1 - -#define sensor1_col 10 -#define sensor2_col 10 -#define sensor1_row 2 -#define sensor2_row 3 - -LiquidCrystal lcd(7,8,2,3,4,5); -//LiquidCrystal2 lcd(10,11,22,24,26,28); - - -#include -xSemaphoreHandle xMutexLCD = NULL; - -declareTaskLoop(changeLCD); -declareTaskLoop(readSensor1); -declareTaskLoop(readSensor2); -declareTaskLoop(changeLCDSensor1); -declareTaskLoop(changeLCDSensor2); - -int sensor1; -int sensor2; - -void setup(){ - - initMainLoopStackSize(configMINIMAL_STACK_SIZE*3); - - pinMode(constrast_pin,OUTPUT); - pinMode(background_pin,OUTPUT); - - pinMode(13,OUTPUT); - digitalWrite(13,HIGH); - - analogWrite(constrast_pin, 50); // contraste - analogWrite(background_pin, LCD_BACKGROUND_LIMIT_MAX); // brilho de fundo - - vSemaphoreCreateBinary(xMutexLCD); - - lcd.begin(COL,ROW); - - digitalWrite(13,LOW); - - lcd.home(); - for(char i = 0; i< COL;i++) lcd.write("*"); - lcd.setCursor(0,1); - - int fator = (COL - 15)/2; - for(char i = 0; i=LCD_BACKGROUND_LIMIT_MIN;i--) { - analogWrite(background_pin,i); - delay(15); - } - for(i=LCD_BACKGROUND_LIMIT_MIN;i<=LCD_BACKGROUND_LIMIT_MAX;i++) { - analogWrite(background_pin,i); - delay(15); - } - -} - -taskLoop(changeLCD){ - //taskENTER_CRITICAL(); - - - char x=0; - for(char i=40;i<128;i++){ - if(xSemaphoreTake(xMutexLCD, ( portTickType ) 10 ) == pdTRUE){ - lcd.setCursor(x++,1); - lcd.write(i); - xSemaphoreGive(xMutexLCD); - } - if(x>=COL)x=0; - delay(30); - } - //taskEXIT_CRITICAL(); -} - -taskLoop(readSensor1){ - sensor1 = analogRead(sensor1_pin); - resumeTask(changeLCDSensor1); -} -taskLoop(readSensor2){ - sensor2 = analogRead(sensor1_pin); - resumeTask(changeLCDSensor2); -} - -taskLoop(changeLCDSensor1){ - if(xSemaphoreTake(xMutexLCD, ( portTickType ) 10 ) == pdTRUE){ - lcd.setCursor(sensor1_col,sensor1_row); - lcd.print("Sen1"); // aqui deve ser espaço em branco, para limpar valores maiores do que o que será exibido. - lcd.print(sensor1); - xSemaphoreGive(xMutexLCD); - } - suspend(); -} - -taskLoop(changeLCDSensor2){ - - if(xSemaphoreTake(xMutexLCD, ( portTickType ) 10 ) == pdTRUE){ - lcd.setCursor(sensor2_col,sensor2_row); - lcd.print("Sen2"); // aqui deve ser espaço em branco, para limpar valores maiores do que o que será exibido. - //lcd.print(sensor2); - xSemaphoreGive(xMutexLCD); - } - - suspend(); -} - - - diff --git a/examples/DuinOS/MoreComplexBlinking/MoreComplexBlinking.pde b/examples/DuinOS/MoreComplexBlinking/MoreComplexBlinking.pde deleted file mode 100644 index e708f54..0000000 --- a/examples/DuinOS/MoreComplexBlinking/MoreComplexBlinking.pde +++ /dev/null @@ -1,119 +0,0 @@ -/* - DuinOS MoreComplexBlinking - - Blinks two LEDs. One LED shows two combined waves. - - The circuit: ##Pins: - * LED connected from digital pin 14 to Vcc. - * LED connected from digital pin 15 to Vcc. - - ##Pins: - * Note: On most Comm.ProgUSB boards, there are already two LEDs on the board - connected to pins 14 and 15, so you don't need any extra components for this example. - - Created 2009.10.26 (yyyy.mm.dd) - by Julián da Silva Gillig - - http://multiplo.org - http://robotgroup.com.ar - - Based on the original Blink code by David Cuartielles - - */ - -#define INITIAL_GREEN_DELAY 200 -#define NEW_GREEN_DELAY 20 - -int ledPinRed = 8; -int ledPinGreen = 9; - -unsigned int greenDelay = INITIAL_GREEN_DELAY; -boolean redLED_isOn = false; -boolean greenLED_isOn = false; - -//Forward declaration, to let redLED call to resumeTask(greenLED). It's not necessary if we put the greenLED -//itself here, but declareLoopTask may be usefull in more complex situations: -declareTaskLoop(greenLED); - -taskLoop(redLED) -{ - static unsigned char counter = 0; - - if (!greenLED_isOn) - { - if (counter >2) - resumeTask(greenLED); - counter++; - } - - redLED_isOn = false; - delay(1000); - redLED_isOn = true; - delay(1000); -} - - -taskLoop(greenLED) -{ - static unsigned char counter = 1; - - digitalWrite(ledPinGreen, HIGH); // set the LED on - delay(greenDelay); - digitalWrite(ledPinGreen, LOW); // set the LED off - delay(greenDelay); - - if ( (counter >= 9) && (greenDelay != NEW_GREEN_DELAY) ) - greenDelay = NEW_GREEN_DELAY; //now, after 10 blinks, accelerates - if (counter >= 99) - { - //Reset vars, so next time, if the task is resumed, it executes all again: - counter = 0; - greenDelay = INITIAL_GREEN_DELAY; - greenLED_isOn = false; - suspend(); //After a while, the tasks suspends itself (forever) - } - counter++; -} - - -// The setup() method runs once, when the sketch starts - -void setup() -{ - // Initialize the digital pins as outputs: - pinMode(ledPinRed, OUTPUT); - pinMode(ledPinGreen, OUTPUT); - - createTaskLoop(redLED, NORMAL_PRIORITY); - createTaskLoop(greenLED, LOW_PRIORITY); - - //This initializes the main loop's with a different priority (default is LOW_PRIORITY): - //initMainLoopPriority(NORMAL_PRIORITY); - - //Try this and see what happends: - //suspendTask(redLED); -} - - -// This is the main loop() method, wich runs over and over again, -// as long as the Arduino has power. Is a LOW_PRIORITY taskLoop: - -void loop() -{ - if (redLED_isOn) - { - digitalWrite(ledPinRed, LOW); // set the LED off - delay(25); // The OS can be tested reducing these delays, and seeing how both LEDs work together... - digitalWrite(ledPinRed, HIGH); // set the LED on - delay(25); - } - else - { - digitalWrite(ledPinRed, LOW); // LED is off - //If nextTask is not called, the application will not hang, because the OS is preemptive. BUT, the current task - //will consume a lot of computational resources (due to it's lack of a delay() in this branch), the application will - //turn slower, and the other tasks may be affected by this, loossing precision in their timing: - nextTask(); - } -} - diff --git a/examples/DuinOS/MoreComplexBlinkingAndSound/MoreComplexBlinkingAndSound.pde b/examples/DuinOS/MoreComplexBlinkingAndSound/MoreComplexBlinkingAndSound.pde deleted file mode 100644 index 9aad132..0000000 --- a/examples/DuinOS/MoreComplexBlinkingAndSound/MoreComplexBlinkingAndSound.pde +++ /dev/null @@ -1,108 +0,0 @@ -/* - DuinOS MoreComplexBlinkingAndSound - - Blinks two LEDs and play sound. - - The circuit: - * 1 LED connected from digital pin 14 (8) - * 2 LED connected from digital pin 15 (9) - * Speaker connected from digital pin 16 (10) - - Created 2010.06.30 (yyyy.mm.dd) - by Michael Grigorev aka CHERTS - - */ - -int ledPinRed = 8; -int ledPinGreen = 9; -int SoundPin = 10; - -unsigned int greenDelay = 200; -unsigned int redDelay = 400; - -declareTaskLoop(redLED); -declareTaskLoop(greenLED); -declareTaskLoop(PlaySound); - -taskLoop(redLED) -{ - digitalWrite(ledPinRed, HIGH); - delay(redDelay); - digitalWrite(ledPinRed, LOW); - delay(redDelay); -} - - -taskLoop(greenLED) -{ - digitalWrite(ledPinGreen, HIGH); - delay(greenDelay); - digitalWrite(ledPinGreen, LOW); - delay(greenDelay); -} - -taskLoop(PlaySound) -{ - tone(SoundPin, 1245, 480); - delay(480); - tone(SoundPin, 932, 240); - delay(240); - tone(SoundPin, 1245, 960); - delay(120); - tone(SoundPin, 831, 240); - delay(240); - tone(SoundPin, 932, 480); - delay(480); - tone(SoundPin, 622, 720); - delay(240); - tone(SoundPin, 784, 120); - delay(120); - tone(SoundPin, 932, 120); - delay(120); - tone(SoundPin, 1245, 240); - delay(240); - tone(SoundPin, 932, 240); - delay(240); - tone(SoundPin, 1397, 240); - delay(240); - tone(SoundPin, 1245, 960); - delay(120); - tone(SoundPin, 1109, 360); - delay(360); - tone(SoundPin, 1047, 120); - delay(120); - tone(SoundPin, 932, 120); - delay(120); - tone(SoundPin, 831, 360); - delay(360); - tone(SoundPin, 932, 960); - suspend(); -} - -// The setup() method runs once, when the sketch starts -void setup() -{ - // Initialize the digital pins as outputs: - pinMode(ledPinRed, OUTPUT); - pinMode(ledPinGreen, OUTPUT); - - createTaskLoop(redLED, NORMAL_PRIORITY); - createTaskLoop(greenLED, NORMAL_PRIORITY); - createTaskLoop(PlaySound, NORMAL_PRIORITY); - - //This initializes the main loop's with a different priority (default is LOW_PRIORITY): - //initMainLoopPriority(NORMAL_PRIORITY); -} - - -// This is the main loop() method, wich runs over and over again, -// as long as the Arduino has power. Is a LOW_PRIORITY taskLoop: -void loop() -{ - // Stop the task of redLED in 10 seconds - delay(10000); - suspendTask(redLED); - // Start the task of redLED in 10 seconds - delay(10000); - resumeTask(redLED); -} From 1dac8ff06d2eaeb0a2b33822024243672532fa6b Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Thu, 10 Jan 2013 17:46:45 -0200 Subject: [PATCH 29/56] Move the call that sets xTimeNow inside the loop that drains the timer queue to ensure higher priority tasks that pre-empt the timer daemon cannot post messages that appear to be in the future to the daemon task. Default configUSE_TICKLESS_IDLE to 0 when it is not defined. Move location of traceTASK_CREATE() macro call. Remove obsolete handling of trmCOMMAND_PROCESS_TIMER_OVERFLOW as the command was never used in release versions. --- arduino.DuinOS.AVR/DuinOS/timers.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/arduino.DuinOS.AVR/DuinOS/timers.c b/arduino.DuinOS.AVR/DuinOS/timers.c index f8cb7f8..bc4ef06 100644 --- a/arduino.DuinOS.AVR/DuinOS/timers.c +++ b/arduino.DuinOS.AVR/DuinOS/timers.c @@ -512,28 +512,26 @@ xTIMER *pxTimer; portBASE_TYPE xTimerListsWereSwitched, xResult; portTickType xTimeNow; - /* In this case the xTimerListsWereSwitched parameter is not used, but it - must be present in the function call. */ - xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched ); - while( xQueueReceive( xTimerQueue, &xMessage, tmrNO_DELAY ) != pdFAIL ) { pxTimer = xMessage.pxTimer; - /* Is the timer already in a list of active timers? When the command - is trmCOMMAND_PROCESS_TIMER_OVERFLOW, the timer will be NULL as the - command is to the task rather than to an individual timer. */ - if( pxTimer != NULL ) + if( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) == pdFALSE ) { - if( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) == pdFALSE ) - { - /* The timer is in a list, remove it. */ - uxListRemove( &( pxTimer->xTimerListItem ) ); - } + /* The timer is in a list, remove it. */ + uxListRemove( &( pxTimer->xTimerListItem ) ); } traceTIMER_COMMAND_RECEIVED( pxTimer, xMessage.xMessageID, xMessage.xMessageValue ); + /* In this case the xTimerListsWereSwitched parameter is not used, but + it must be present in the function call. prvSampleTimeNow() must be + called after the message is received from xTimerQueue so there is no + possibility of a higher priority task adding a message to the message + queue with a time that is ahead of the timer daemon task (because it + pre-empted the timer daemon task after the xTimeNow value was set). */ + xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched ); + switch( xMessage.xMessageID ) { case tmrCOMMAND_START : @@ -686,3 +684,6 @@ xTIMER *pxTimer = ( xTIMER * ) xTimer; to include software timer functionality. If you want to include software timer functionality then ensure configUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */ #endif /* configUSE_TIMERS == 1 */ + + + From c4a05206e6d31345c3855aa6e3e79831b6170d58 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Thu, 10 Jan 2013 17:54:22 -0200 Subject: [PATCH 30/56] on ATmega8, the uart and its bits are not numbered, so there is no "TXC0" definition. It is slightly cleaner to define this here instead of having conditional code in the cpp module. --- arduino.DuinOS.AVR/HardwareSerial.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/arduino.DuinOS.AVR/HardwareSerial.cpp b/arduino.DuinOS.AVR/HardwareSerial.cpp index 2e64acb..719f3f6 100644 --- a/arduino.DuinOS.AVR/HardwareSerial.cpp +++ b/arduino.DuinOS.AVR/HardwareSerial.cpp @@ -34,6 +34,22 @@ #include "HardwareSerial.h" +/* + * on ATmega8, the uart and its bits are not numbered, so there is no "TXC0" + * definition. It is slightly cleaner to define this here instead of having + * conditional code in the cpp module. + */ +#if !defined(TXC0) +#if defined(TXC) +#define TXC0 TXC +#elif defined(TXC1) +// Some devices have uart1 but no uart0 +#define TXC0 TXC1 +#else +#error TXC0 not definable in HardwareSerial.h +#endif +#endif + // Define constants and variables for buffering incoming serial data. We're // using a ring buffer (I think), in which head is the index of the location // to which to write the next incoming character and tail is the index of the From fe5a4c4637c3bf924a815cdca1c9a16dad301a74 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Thu, 10 Jan 2013 17:56:59 -0200 Subject: [PATCH 31/56] =?UTF-8?q?mantendo=20os=20nomes=20de=20handlers=20d?= =?UTF-8?q?e=20fun=C3=A7=C3=B5es=20padronizado.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arduino.DuinOS.AVR/DuinOS/port.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arduino.DuinOS.AVR/DuinOS/port.c b/arduino.DuinOS.AVR/DuinOS/port.c index 1ac53ec..965902c 100644 --- a/arduino.DuinOS.AVR/DuinOS/port.c +++ b/arduino.DuinOS.AVR/DuinOS/port.c @@ -475,7 +475,7 @@ static void prvSetupTimerInterrupt( void ) void SIG_OUTPUT_COMPARE1A( void ) __attribute__ ( ( signal, naked ) ); void SIG_OUTPUT_COMPARE1A( void ) */ -#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) + #if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) void TIM0_OVF_vect(void) __attribute__ ((signal,__INTR_ATTRS,naked)); void TIM0_OVF_vect(void) #else From 4d3292b2c950dceedd66a6ca6559429816e17886 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Thu, 10 Jan 2013 17:58:20 -0200 Subject: [PATCH 32/56] =?UTF-8?q?retornando=20o=20uso=20de=20naked=20para?= =?UTF-8?q?=20handler=20de=20interrup=C3=A7=C3=A3o,=20=C3=A9=20o=20correto?= =?UTF-8?q?=20para=20o=20DuinOS.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arduino.DuinOS.AVR/DuinOS/port.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arduino.DuinOS.AVR/DuinOS/port.c b/arduino.DuinOS.AVR/DuinOS/port.c index 965902c..1ac53ec 100644 --- a/arduino.DuinOS.AVR/DuinOS/port.c +++ b/arduino.DuinOS.AVR/DuinOS/port.c @@ -475,7 +475,7 @@ static void prvSetupTimerInterrupt( void ) void SIG_OUTPUT_COMPARE1A( void ) __attribute__ ( ( signal, naked ) ); void SIG_OUTPUT_COMPARE1A( void ) */ - #if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) +#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) void TIM0_OVF_vect(void) __attribute__ ((signal,__INTR_ATTRS,naked)); void TIM0_OVF_vect(void) #else From d9bcf12157dbb7fe47826431ef30864cebbb0ec1 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Thu, 10 Jan 2013 18:01:10 -0200 Subject: [PATCH 33/56] =?UTF-8?q?Revert=20"retornando=20o=20uso=20de=20nak?= =?UTF-8?q?ed=20para=20handler=20de=20interrup=C3=A7=C3=A3o,=20=C3=A9=20o?= =?UTF-8?q?=20correto=20para=20o=20DuinOS."?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 4d3292b2c950dceedd66a6ca6559429816e17886. --- arduino.DuinOS.AVR/DuinOS/port.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arduino.DuinOS.AVR/DuinOS/port.c b/arduino.DuinOS.AVR/DuinOS/port.c index 1ac53ec..965902c 100644 --- a/arduino.DuinOS.AVR/DuinOS/port.c +++ b/arduino.DuinOS.AVR/DuinOS/port.c @@ -475,7 +475,7 @@ static void prvSetupTimerInterrupt( void ) void SIG_OUTPUT_COMPARE1A( void ) __attribute__ ( ( signal, naked ) ); void SIG_OUTPUT_COMPARE1A( void ) */ -#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) + #if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) void TIM0_OVF_vect(void) __attribute__ ((signal,__INTR_ATTRS,naked)); void TIM0_OVF_vect(void) #else From 3fcb9f41895003598bfa13da717ebc3808b9d57c Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Thu, 10 Jan 2013 18:02:18 -0200 Subject: [PATCH 34/56] Revert "Move the call that sets xTimeNow inside the loop that drains the timer queue to ensure higher priority tasks that pre-empt the timer daemon cannot post messages that appear to be in the future to the daemon task." This reverts commit 1dac8ff06d2eaeb0a2b33822024243672532fa6b. --- arduino.DuinOS.AVR/DuinOS/timers.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/arduino.DuinOS.AVR/DuinOS/timers.c b/arduino.DuinOS.AVR/DuinOS/timers.c index bc4ef06..f8cb7f8 100644 --- a/arduino.DuinOS.AVR/DuinOS/timers.c +++ b/arduino.DuinOS.AVR/DuinOS/timers.c @@ -512,26 +512,28 @@ xTIMER *pxTimer; portBASE_TYPE xTimerListsWereSwitched, xResult; portTickType xTimeNow; + /* In this case the xTimerListsWereSwitched parameter is not used, but it + must be present in the function call. */ + xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched ); + while( xQueueReceive( xTimerQueue, &xMessage, tmrNO_DELAY ) != pdFAIL ) { pxTimer = xMessage.pxTimer; - if( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) == pdFALSE ) + /* Is the timer already in a list of active timers? When the command + is trmCOMMAND_PROCESS_TIMER_OVERFLOW, the timer will be NULL as the + command is to the task rather than to an individual timer. */ + if( pxTimer != NULL ) { - /* The timer is in a list, remove it. */ - uxListRemove( &( pxTimer->xTimerListItem ) ); + if( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) == pdFALSE ) + { + /* The timer is in a list, remove it. */ + uxListRemove( &( pxTimer->xTimerListItem ) ); + } } traceTIMER_COMMAND_RECEIVED( pxTimer, xMessage.xMessageID, xMessage.xMessageValue ); - /* In this case the xTimerListsWereSwitched parameter is not used, but - it must be present in the function call. prvSampleTimeNow() must be - called after the message is received from xTimerQueue so there is no - possibility of a higher priority task adding a message to the message - queue with a time that is ahead of the timer daemon task (because it - pre-empted the timer daemon task after the xTimeNow value was set). */ - xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched ); - switch( xMessage.xMessageID ) { case tmrCOMMAND_START : @@ -684,6 +686,3 @@ xTIMER *pxTimer = ( xTIMER * ) xTimer; to include software timer functionality. If you want to include software timer functionality then ensure configUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */ #endif /* configUSE_TIMERS == 1 */ - - - From 09ecc5e26a3e7201753c805048121147982d55e5 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Thu, 10 Jan 2013 18:41:26 -0200 Subject: [PATCH 35/56] ajustes finais para manter atualizado com o FreeRTOS Make changes necessary to allow the latest StateViewer Eclipse plug-in obtain the run time stats information. Default configUSE_TICKLESS_IDLE to 0 when it is not defined. Move location of traceTASK_CREATE() macro call. Remove obsolete handling of trmCOMMAND_PROCESS_TIMER_OVERFLOW as the command was never used in release versions. Move the call that sets xTimeNow inside the loop that drains the timer queue to ensure higher priority tasks that pre-empt the timer daemon cannot post messages that appear to be in the future to the daemon task. --- arduino.DuinOS.AVR/DuinOS/FreeRTOS.h | 4 +++ arduino.DuinOS.AVR/DuinOS/port.c | 2 +- arduino.DuinOS.AVR/DuinOS/tasks.c | 39 ++++++++++++++-------------- arduino.DuinOS.AVR/DuinOS/timers.c | 27 +++++++++---------- 4 files changed, 38 insertions(+), 34 deletions(-) diff --git a/arduino.DuinOS.AVR/DuinOS/FreeRTOS.h b/arduino.DuinOS.AVR/DuinOS/FreeRTOS.h index 2c0c28d..99df4ac 100644 --- a/arduino.DuinOS.AVR/DuinOS/FreeRTOS.h +++ b/arduino.DuinOS.AVR/DuinOS/FreeRTOS.h @@ -534,6 +534,10 @@ typedef portBASE_TYPE (*pdTASK_HOOK_CODE)( void * ); #define portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime ) #endif +#ifndef configUSE_TICKLESS_IDLE + #define configUSE_TICKLESS_IDLE 0 +#endif + #ifndef configPRE_SLEEP_PROCESSING #define configPRE_SLEEP_PROCESSING( x ) #endif diff --git a/arduino.DuinOS.AVR/DuinOS/port.c b/arduino.DuinOS.AVR/DuinOS/port.c index 965902c..faf9ff1 100644 --- a/arduino.DuinOS.AVR/DuinOS/port.c +++ b/arduino.DuinOS.AVR/DuinOS/port.c @@ -421,7 +421,7 @@ void vPortYieldFromTick( void ) /*-----------------------------------------------------------*/ /* - * Setup timer 1 compare match A to generate a tick interrupt. + * Setup timer 0 compare match A to generate a tick interrupt. */ static void prvSetupTimerInterrupt( void ) { diff --git a/arduino.DuinOS.AVR/DuinOS/tasks.c b/arduino.DuinOS.AVR/DuinOS/tasks.c index ec8a052..56fc505 100644 --- a/arduino.DuinOS.AVR/DuinOS/tasks.c +++ b/arduino.DuinOS.AVR/DuinOS/tasks.c @@ -191,7 +191,8 @@ PRIVILEGED_DATA static volatile portTickType xNextTaskUnblockTime = ( portTic PRIVILEGED_DATA static char pcStatsString[ 50 ] ; PRIVILEGED_DATA static unsigned long ulTaskSwitchedInTime = 0UL; /*< Holds the value of a timer/counter the last time a task was switched in. */ - static void prvGenerateRunTimeStatsForTasksInList( const signed char *pcWriteBuffer, xList *pxList, unsigned long ulTotalRunTime ) PRIVILEGED_FUNCTION; + PRIVILEGED_DATA static unsigned long ulTotalRunTime; /*< Holds the total amount of execution time as defined by the run time counter clock. */ + static void prvGenerateRunTimeStatsForTasksInList( const signed char *pcWriteBuffer, xList *pxList, unsigned long ulTotalRunTimeDiv100 ) PRIVILEGED_FUNCTION; #endif @@ -614,12 +615,12 @@ tskTCB * pxNewTCB; } #endif uxTaskNumber++; + traceTASK_CREATE( pxNewTCB ); prvAddTaskToReadyQueue( pxNewTCB ); xReturn = pdPASS; - portSETUP_TCB( pxNewTCB ); - traceTASK_CREATE( pxNewTCB ); + portSETUP_TCB( pxNewTCB ); } taskEXIT_CRITICAL(); } @@ -1553,7 +1554,7 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void ) void vTaskGetRunTimeStats( signed char *pcWriteBuffer ) { unsigned portBASE_TYPE uxQueue; - unsigned long ulTotalRunTime; + unsigned long ulTotalRunTimeDiv100; /* This is a VERY costly function that should be used for debug only. It leaves interrupts disabled for a LONG time. */ @@ -1568,7 +1569,7 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void ) /* Divide ulTotalRunTime by 100 to make the percentage caluclations simpler in the prvGenerateRunTimeStatsForTasksInList() function. */ - ulTotalRunTime /= 100UL; + ulTotalRunTimeDiv100 = ulTotalRunTime / 100UL; /* Run through all the lists that could potentially contain a TCB, generating a table of run timer percentages in the provided @@ -1585,25 +1586,25 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void ) if( listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxQueue ] ) ) == pdFALSE ) { - prvGenerateRunTimeStatsForTasksInList( pcWriteBuffer, ( xList * ) &( pxReadyTasksLists[ uxQueue ] ), ulTotalRunTime ); + prvGenerateRunTimeStatsForTasksInList( pcWriteBuffer, ( xList * ) &( pxReadyTasksLists[ uxQueue ] ), ulTotalRunTimeDiv100 ); } }while( uxQueue > ( unsigned short ) tskIDLE_PRIORITY ); if( listLIST_IS_EMPTY( pxDelayedTaskList ) == pdFALSE ) { - prvGenerateRunTimeStatsForTasksInList( pcWriteBuffer, ( xList * ) pxDelayedTaskList, ulTotalRunTime ); + prvGenerateRunTimeStatsForTasksInList( pcWriteBuffer, ( xList * ) pxDelayedTaskList, ulTotalRunTimeDiv100 ); } if( listLIST_IS_EMPTY( pxOverflowDelayedTaskList ) == pdFALSE ) { - prvGenerateRunTimeStatsForTasksInList( pcWriteBuffer, ( xList * ) pxOverflowDelayedTaskList, ulTotalRunTime ); + prvGenerateRunTimeStatsForTasksInList( pcWriteBuffer, ( xList * ) pxOverflowDelayedTaskList, ulTotalRunTimeDiv100 ); } #if ( INCLUDE_vTaskDelete == 1 ) { if( listLIST_IS_EMPTY( &xTasksWaitingTermination ) == pdFALSE ) { - prvGenerateRunTimeStatsForTasksInList( pcWriteBuffer, &xTasksWaitingTermination, ulTotalRunTime ); + prvGenerateRunTimeStatsForTasksInList( pcWriteBuffer, &xTasksWaitingTermination, ulTotalRunTimeDiv100 ); } } #endif @@ -1612,7 +1613,7 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void ) { if( listLIST_IS_EMPTY( &xSuspendedTaskList ) == pdFALSE ) { - prvGenerateRunTimeStatsForTasksInList( pcWriteBuffer, &xSuspendedTaskList, ulTotalRunTime ); + prvGenerateRunTimeStatsForTasksInList( pcWriteBuffer, &xSuspendedTaskList, ulTotalRunTimeDiv100 ); } } #endif @@ -1830,12 +1831,10 @@ void vTaskSwitchContext( void ) #if ( configGENERATE_RUN_TIME_STATS == 1 ) { - unsigned long ulTempCounter; - #ifdef portALT_GET_RUN_TIME_COUNTER_VALUE - portALT_GET_RUN_TIME_COUNTER_VALUE( ulTempCounter ); + portALT_GET_RUN_TIME_COUNTER_VALUE( ulTotalRunTime ); #else - ulTempCounter = portGET_RUN_TIME_COUNTER_VALUE(); + ulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE(); #endif /* Add the amount of time the task has been running to the accumulated @@ -1843,8 +1842,8 @@ void vTaskSwitchContext( void ) ulTaskSwitchedInTime. Note that there is no overflow protection here so count values are only valid until the timer overflows. Generally this will be about 1 hour assuming a 1uS timer increment. */ - pxCurrentTCB->ulRunTimeCounter += ( ulTempCounter - ulTaskSwitchedInTime ); - ulTaskSwitchedInTime = ulTempCounter; + pxCurrentTCB->ulRunTimeCounter += ( ulTotalRunTime - ulTaskSwitchedInTime ); + ulTaskSwitchedInTime = ulTotalRunTime; } #endif @@ -2459,7 +2458,7 @@ tskTCB *pxNewTCB; #if ( configGENERATE_RUN_TIME_STATS == 1 ) - static void prvGenerateRunTimeStatsForTasksInList( const signed char *pcWriteBuffer, xList *pxList, unsigned long ulTotalRunTime ) + static void prvGenerateRunTimeStatsForTasksInList( const signed char *pcWriteBuffer, xList *pxList, unsigned long ulTotalRunTimeDiv100 ) { volatile tskTCB *pxNextTCB, *pxFirstTCB; unsigned long ulStatsAsPercentage; @@ -2472,7 +2471,7 @@ tskTCB *pxNewTCB; listGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, pxList ); /* Divide by zero check. */ - if( ulTotalRunTime > 0UL ) + if( ulTotalRunTimeDiv100 > 0UL ) { /* Has the task run at all? */ if( pxNextTCB->ulRunTimeCounter == 0UL ) @@ -2484,8 +2483,8 @@ tskTCB *pxNewTCB; { /* What percentage of the total run time has the task used? This will always be rounded down to the nearest integer. - ulTotalRunTime has already been divided by 100. */ - ulStatsAsPercentage = pxNextTCB->ulRunTimeCounter / ulTotalRunTime; + ulTotalRunTimeDiv100 has already been divided by 100. */ + ulStatsAsPercentage = pxNextTCB->ulRunTimeCounter / ulTotalRunTimeDiv100; if( ulStatsAsPercentage > 0UL ) { diff --git a/arduino.DuinOS.AVR/DuinOS/timers.c b/arduino.DuinOS.AVR/DuinOS/timers.c index f8cb7f8..bc4ef06 100644 --- a/arduino.DuinOS.AVR/DuinOS/timers.c +++ b/arduino.DuinOS.AVR/DuinOS/timers.c @@ -512,28 +512,26 @@ xTIMER *pxTimer; portBASE_TYPE xTimerListsWereSwitched, xResult; portTickType xTimeNow; - /* In this case the xTimerListsWereSwitched parameter is not used, but it - must be present in the function call. */ - xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched ); - while( xQueueReceive( xTimerQueue, &xMessage, tmrNO_DELAY ) != pdFAIL ) { pxTimer = xMessage.pxTimer; - /* Is the timer already in a list of active timers? When the command - is trmCOMMAND_PROCESS_TIMER_OVERFLOW, the timer will be NULL as the - command is to the task rather than to an individual timer. */ - if( pxTimer != NULL ) + if( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) == pdFALSE ) { - if( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) == pdFALSE ) - { - /* The timer is in a list, remove it. */ - uxListRemove( &( pxTimer->xTimerListItem ) ); - } + /* The timer is in a list, remove it. */ + uxListRemove( &( pxTimer->xTimerListItem ) ); } traceTIMER_COMMAND_RECEIVED( pxTimer, xMessage.xMessageID, xMessage.xMessageValue ); + /* In this case the xTimerListsWereSwitched parameter is not used, but + it must be present in the function call. prvSampleTimeNow() must be + called after the message is received from xTimerQueue so there is no + possibility of a higher priority task adding a message to the message + queue with a time that is ahead of the timer daemon task (because it + pre-empted the timer daemon task after the xTimeNow value was set). */ + xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched ); + switch( xMessage.xMessageID ) { case tmrCOMMAND_START : @@ -686,3 +684,6 @@ xTIMER *pxTimer = ( xTIMER * ) xTimer; to include software timer functionality. If you want to include software timer functionality then ensure configUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */ #endif /* configUSE_TIMERS == 1 */ + + + From 2ef1eb72cbbf84bcd65a7c2bc1f3c44acfaaffed Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Tue, 15 Jan 2013 12:44:13 -0200 Subject: [PATCH 36/56] =?UTF-8?q?Atualiza=C3=A7=C3=A3o=20dos=20arquivos=20?= =?UTF-8?q?conforme=20o=20Arduino=20Original.=20maior=20impacto=20no=20cod?= =?UTF-8?q?igo=20=C3=A9=20a=20adi=C3=A7=C3=A3o=20do=20malloc.c=20e=20mudan?= =?UTF-8?q?=C3=A7as=20no=20new.h?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- arduino.DuinOS.AVR/DuinOS/port.c | 20 +- arduino.DuinOS.AVR/HardwareSerial.h | 2 +- arduino.DuinOS.AVR/USBCore.cpp | 12 + arduino.DuinOS.AVR/malloc.c | 380 ++++++++++++++++++++++++++++ arduino.DuinOS.AVR/new.cpp | 12 +- arduino.DuinOS.AVR/new.h | 4 +- 7 files changed, 418 insertions(+), 14 deletions(-) create mode 100644 arduino.DuinOS.AVR/malloc.c diff --git a/.gitignore b/.gitignore index 3c289e7..9f3bcf5 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ /.autotools /.cproject /.project -/examples.original +/examples.original \ No newline at end of file diff --git a/arduino.DuinOS.AVR/DuinOS/port.c b/arduino.DuinOS.AVR/DuinOS/port.c index faf9ff1..4c2d6ba 100644 --- a/arduino.DuinOS.AVR/DuinOS/port.c +++ b/arduino.DuinOS.AVR/DuinOS/port.c @@ -251,18 +251,18 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE #if defined(__AVR_ATmega2560__) // Implement normal stack initialisation but with portLONG instead of portSHORT - usAddress = ( unsigned portLONG ) pxCode; - *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); - pxTopOfStack--; + usAddress = ( unsigned portLONG ) pxCode; + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); + pxTopOfStack--; - usAddress >>= 8; - *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); - pxTopOfStack--; + usAddress >>= 8; + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); + pxTopOfStack--; - // Implemented the 3byte addressing - usAddress >>= 8; - *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); - pxTopOfStack--; + // Implemented the 3byte addressing + usAddress >>= 8; + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); + pxTopOfStack--; // Normal initialisation for over ATmega #else diff --git a/arduino.DuinOS.AVR/HardwareSerial.h b/arduino.DuinOS.AVR/HardwareSerial.h index c2d0ce9..2b1de91 100644 --- a/arduino.DuinOS.AVR/HardwareSerial.h +++ b/arduino.DuinOS.AVR/HardwareSerial.h @@ -53,7 +53,7 @@ class HardwareSerial : public Stream volatile uint8_t *ucsrc, volatile uint8_t *udr, uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udrie, uint8_t u2x); void begin(unsigned long); - void begin(unsigned long, byte); + void begin(unsigned long, uint8_t); void end(); virtual int available(void); virtual int peek(void); diff --git a/arduino.DuinOS.AVR/USBCore.cpp b/arduino.DuinOS.AVR/USBCore.cpp index 8bcf66c..d3e0170 100644 --- a/arduino.DuinOS.AVR/USBCore.cpp +++ b/arduino.DuinOS.AVR/USBCore.cpp @@ -53,6 +53,12 @@ const u16 STRING_IPRODUCT[17] = { (3<<8) | (2+2*16), #if USB_PID == 0x8036 'A','r','d','u','i','n','o',' ','L','e','o','n','a','r','d','o' +#elif USB_PID == 0x8037 + 'A','r','d','u','i','n','o',' ','M','i','c','r','o',' ',' ',' ' +#elif USB_PID == 0x803C + 'A','r','d','u','i','n','o',' ','E','s','p','l','o','r','a',' ' +#elif USB_PID == 0x9208 + 'L','i','l','y','P','a','d','U','S','B',' ',' ',' ',' ',' ',' ' #else 'U','S','B',' ','I','O',' ','B','o','a','r','d',' ',' ',' ',' ' #endif @@ -62,6 +68,8 @@ const u16 STRING_IMANUFACTURER[12] = { (3<<8) | (2+2*11), #if USB_VID == 0x2341 'A','r','d','u','i','n','o',' ','L','L','C' +#elif USB_VID == 0x1b4f + 'S','p','a','r','k','F','u','n',' ',' ',' ' #else 'U','n','k','n','o','w','n',' ',' ',' ',' ' #endif @@ -638,7 +646,11 @@ void USBDevice_::attach() _usbConfiguration = 0; UHWCON = 0x01; // power internal reg USBCON = (1< +#include +#include +#include + + +#define __MALLOC_MARGIN__ 120 + + +struct __freelist { + size_t sz; + struct __freelist *nx; +}; + +/* + * Exported interface: + * + * When extending the data segment, the allocator will not try to go + * beyond the current stack limit, decreased by __malloc_margin bytes. + * Thus, all possible stack frames of interrupt routines that could + * interrupt the current function, plus all further nested function + * calls must not require more stack space, or they'll risk to collide + * with the data segment. + */ + + +#define STACK_POINTER() ((char *)AVR_STACK_POINTER_REG) +extern char __heap_start; +char *__brkval = &__heap_start; // first location not yet allocated +struct __freelist *__flp; // freelist pointer (head of freelist) +char *__brkval_maximum = 100; + +void * +malloc(size_t len) +{ + struct __freelist *fp1, *fp2, *sfp1, *sfp2; + char *cp; + size_t s, avail; + + /* + * Our minimum chunk size is the size of a pointer (plus the + * size of the "sz" field, but we don't need to account for + * this), otherwise we could not possibly fit a freelist entry + * into the chunk later. + */ + if (len < sizeof(struct __freelist) - sizeof(size_t)) + len = sizeof(struct __freelist) - sizeof(size_t); + + /* + * First, walk the free list and try finding a chunk that + * would match exactly. If we found one, we are done. While + * walking, note down the smallest chunk we found that would + * still fit the request -- we need it for step 2. + * + */ + for (s = 0, fp1 = __flp, fp2 = 0; + fp1; + fp2 = fp1, fp1 = fp1->nx) { + if (fp1->sz < len) + continue; + if (fp1->sz == len) { + /* + * Found it. Disconnect the chunk from the + * freelist, and return it. + */ + if (fp2) + fp2->nx = fp1->nx; + else + __flp = fp1->nx; + return &(fp1->nx); + } + else { + if (s == 0 || fp1->sz < s) { + /* this is the smallest chunk found so far */ + s = fp1->sz; + sfp1 = fp1; + sfp2 = fp2; + } + } + } + /* + * Step 2: If we found a chunk on the freelist that would fit + * (but was too large), look it up again and use it, since it + * is our closest match now. Since the freelist entry needs + * to be split into two entries then, watch out that the + * difference between the requested size and the size of the + * chunk found is large enough for another freelist entry; if + * not, just enlarge the request size to what we have found, + * and use the entire chunk. + */ + if (s) { + if (s - len < sizeof(struct __freelist)) { + /* Disconnect it from freelist and return it. */ + if (sfp2) + sfp2->nx = sfp1->nx; + else + __flp = sfp1->nx; + return &(sfp1->nx); + } + /* + * Split them up. Note that we leave the first part + * as the new (smaller) freelist entry, and return the + * upper portion to the caller. This saves us the + * work to fix up the freelist chain; we just need to + * fixup the size of the current entry, and note down + * the size of the new chunk before returning it to + * the caller. + */ + cp = (char *)sfp1; + s -= len; + cp += s; + sfp2 = (struct __freelist *)cp; + sfp2->sz = len; + sfp1->sz = s - sizeof(size_t); + return &(sfp2->nx); + } + /* + * Step 3: If the request could not be satisfied from a + * freelist entry, just prepare a new chunk. This means we + * need to obtain more memory first. The largest address just + * not allocated so far is remembered in the brkval variable. + * Under Unix, the "break value" was the end of the data + * segment as dynamically requested from the operating system. + * Since we don't have an operating system, just make sure + * that we don't collide with the stack. + */ + cp = STACK_POINTER() - __MALLOC_MARGIN__; + if (cp <= __brkval) + /* + * Memory exhausted. + */ + return 0; + avail = cp - __brkval; + /* + * Both tests below are needed to catch the case len >= 0xfffe. + */ + if (avail >= len && avail >= len + sizeof(size_t)) { + fp1 = (struct __freelist *)__brkval; + __brkval += len + sizeof(size_t); + __brkval_maximum = __brkval; + fp1->sz = len; + return &(fp1->nx); + } + /* + * Step 4: There's no help, just fail. :-/ + */ + return 0; +} + + +void +free(void *p) +{ + struct __freelist *fp1, *fp2, *fpnew; + char *cp1, *cp2, *cpnew; + + /* ISO C says free(NULL) must be a no-op */ + if (p == 0) + return; + + cpnew = p; + cpnew -= sizeof(size_t); + fpnew = (struct __freelist *)cpnew; + fpnew->nx = 0; + + /* + * Trivial case first: if there's no freelist yet, our entry + * will be the only one on it. If this is the last entry, we + * can reduce __brkval instead. + */ + if (__flp == 0) { + if ((char *)p + fpnew->sz == __brkval) + __brkval = cpnew; + else + __flp = fpnew; + return; + } + + /* + * Now, find the position where our new entry belongs onto the + * freelist. Try to aggregate the chunk with adjacent chunks + * if possible. + */ + for (fp1 = __flp, fp2 = 0; + fp1; + fp2 = fp1, fp1 = fp1->nx) { + if (fp1 < fpnew) + continue; + cp1 = (char *)fp1; + fpnew->nx = fp1; + if ((char *)&(fpnew->nx) + fpnew->sz == cp1) { + /* upper chunk adjacent, assimilate it */ + fpnew->sz += fp1->sz + sizeof(size_t); + fpnew->nx = fp1->nx; + } + if (fp2 == 0) { + /* new head of freelist */ + __flp = fpnew; + return; + } + break; + } + /* + * Note that we get here either if we hit the "break" above, + * or if we fell off the end of the loop. The latter means + * we've got a new topmost chunk. Either way, try aggregating + * with the lower chunk if possible. + */ + fp2->nx = fpnew; + cp2 = (char *)&(fp2->nx); + if (cp2 + fp2->sz == cpnew) { + /* lower junk adjacent, merge */ + fp2->sz += fpnew->sz + sizeof(size_t); + fp2->nx = fpnew->nx; + } + /* + * If there's a new topmost chunk, lower __brkval instead. + */ + for (fp1 = __flp, fp2 = 0; + fp1->nx != 0; + fp2 = fp1, fp1 = fp1->nx) + /* advance to entry just before end of list */; + cp2 = (char *)&(fp1->nx); + if (cp2 + fp1->sz == __brkval) { + if (fp2 == NULL) + /* Freelist is empty now. */ + __flp = NULL; + else + fp2->nx = NULL; + __brkval = cp2 - sizeof(size_t); + } +} + + + +void * +realloc(void *ptr, size_t len) +{ + struct __freelist *fp1, *fp2, *fp3, *ofp3; + char *cp, *cp1; + void *memp; + size_t s, incr; + + /* Trivial case, required by C standard. */ + if (ptr == 0) + return malloc(len); + + cp1 = (char *)ptr; + cp1 -= sizeof(size_t); + fp1 = (struct __freelist *)cp1; + + cp = (char *)ptr + len; /* new next pointer */ + if (cp < cp1) + /* Pointer wrapped across top of RAM, fail. */ + return 0; + + /* + * See whether we are growing or shrinking. When shrinking, + * we split off a chunk for the released portion, and call + * free() on it. Therefore, we can only shrink if the new + * size is at least sizeof(struct __freelist) smaller than the + * previous size. + */ + if (len <= fp1->sz) { + /* The first test catches a possible unsigned int + * rollover condition. */ + if (fp1->sz <= sizeof(struct __freelist) || + len > fp1->sz - sizeof(struct __freelist)) + return ptr; + fp2 = (struct __freelist *)cp; + fp2->sz = fp1->sz - len - sizeof(size_t); + fp1->sz = len; + free(&(fp2->nx)); + return ptr; + } + + /* + * If we get here, we are growing. First, see whether there + * is space in the free list on top of our current chunk. + */ + incr = len - fp1->sz; + cp = (char *)ptr + fp1->sz; + fp2 = (struct __freelist *)cp; + for (s = 0, ofp3 = 0, fp3 = __flp; + fp3; + ofp3 = fp3, fp3 = fp3->nx) { + if (fp3 == fp2 && fp3->sz + sizeof(size_t) >= incr) { + /* found something that fits */ + if (fp3->sz + sizeof(size_t) - incr > sizeof(struct __freelist)) { + /* split off a new freelist entry */ + cp = (char *)ptr + len; + fp2 = (struct __freelist *)cp; + fp2->nx = fp3->nx; + fp2->sz = fp3->sz - incr; + fp1->sz = len; + } else { + /* it just fits, so use it entirely */ + fp1->sz += fp3->sz + sizeof(size_t); + fp2 = fp3->nx; + } + if (ofp3) + ofp3->nx = fp2; + else + __flp = fp2; + return ptr; + } + /* + * Find the largest chunk on the freelist while + * walking it. + */ + if (fp3->sz > s) + s = fp3->sz; + } + /* + * If we are the topmost chunk in memory, and there was no + * large enough chunk on the freelist that could be re-used + * (by a call to malloc() below), quickly extend the + * allocation area if possible, without need to copy the old + * data. + */ + if (__brkval == (char *)ptr + fp1->sz && len > s) { + cp = (char *)ptr + len; + cp1 = STACK_POINTER() - __MALLOC_MARGIN__; + if (cp < cp1) { + __brkval = cp; + __brkval_maximum = cp; + fp1->sz = len; + return ptr; + } + /* If that failed, we are out of luck. */ + return 0; + } + + /* + * Call malloc() for a new chunk, then copy over the data, and + * release the old region. + */ + if ((memp = malloc(len)) == 0) + return 0; + memcpy(memp, ptr, fp1->sz); + free(ptr); + return memp; +} + diff --git a/arduino.DuinOS.AVR/new.cpp b/arduino.DuinOS.AVR/new.cpp index 0f6d422..b81031e 100644 --- a/arduino.DuinOS.AVR/new.cpp +++ b/arduino.DuinOS.AVR/new.cpp @@ -5,10 +5,20 @@ void * operator new(size_t size) return malloc(size); } +void * operator new[](size_t size) +{ + return malloc(size); +} + void operator delete(void * ptr) { free(ptr); -} +} + +void operator delete[](void * ptr) +{ + free(ptr); +} int __cxa_guard_acquire(__guard *g) {return !*(char *)(g);}; void __cxa_guard_release (__guard *g) {*(char *)g = 1;}; diff --git a/arduino.DuinOS.AVR/new.h b/arduino.DuinOS.AVR/new.h index cd940ce..991c86c 100644 --- a/arduino.DuinOS.AVR/new.h +++ b/arduino.DuinOS.AVR/new.h @@ -8,7 +8,9 @@ #include void * operator new(size_t size); -void operator delete(void * ptr); +void * operator new[](size_t size); +void operator delete(void * ptr); +void operator delete[](void * ptr); __extension__ typedef int __guard __attribute__((mode (__DI__))); From 931ffb63ec2bd03e80754f6de8bcd764c3aaa031 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Fri, 22 Feb 2013 10:43:25 -0300 Subject: [PATCH 37/56] =?UTF-8?q?Atualiza=C3=A7=C3=A3o=20do=20DuinOS=20par?= =?UTF-8?q?a=20o=20FreeRTOS=20V7.4.0=20Ouveram=20diversos=20ajustes=20desd?= =?UTF-8?q?e=20a=20vers=C3=A3o=20V7.3.0=20e=20alguns=20est=C3=A3o=20listad?= =?UTF-8?q?os=20abaixo,=20este=20commit=20sincroniza=20o=20trabalho=20do?= =?UTF-8?q?=20FreeRTOS=20com=20o=20DuinOS.=20=C3=89=20importante=20ressalt?= =?UTF-8?q?ar=20que=20o=20heap=5F=3F.c=20foi=20ajustado=20o=20que=20pode?= =?UTF-8?q?=20trazer=20melhorias=20no=20alocamento=20de=20memoria=20e=20ma?= =?UTF-8?q?is=20estabilidade=20ao=20seu=20c=C3=B3digo.=20Mais=20detalhes?= =?UTF-8?q?=20veja=20o=20log=20de=20atualiza=C3=A7=C3=B5es=20em=20http://f?= =?UTF-8?q?reertos.svn.sourceforge.net/viewvc/freertos/trunk/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1831: Prepare for V7.4.0 release. 1829: Correct spelling of xSuspendedTaskList in eTaskConfirmSleepModeStatus(). 1828: Add default definition for configUSE_QUEUE_SETS. Add eTaskConfirmSleepModeStatus() (not yet tested). Only call prvQueueUnregisterQueue() when a queue or semaphore is deleted if configQUEUE_REGISTRY_SIZE > 0. Back out change that checks the configUSE_PORT_OPTMISED_TASK_SELECTION value before uxPriorityUsedOnEntry is set in vTaskPrioritySet as it generated more warnings (with other compilers) than it fixed. --- arduino.DuinOS.AVR/DuinOS/FreeRTOS.h | 81 +- arduino.DuinOS.AVR/DuinOS/StackMacros.h | 50 +- arduino.DuinOS.AVR/DuinOS/croutine.c | 94 +-- arduino.DuinOS.AVR/DuinOS/croutine.h | 50 +- arduino.DuinOS.AVR/DuinOS/heap_1.c | 79 +- arduino.DuinOS.AVR/DuinOS/heap_2.c | 131 ++-- arduino.DuinOS.AVR/DuinOS/heap_3.c | 48 +- arduino.DuinOS.AVR/DuinOS/heap_4.c | 82 +- arduino.DuinOS.AVR/DuinOS/list.c | 50 +- arduino.DuinOS.AVR/DuinOS/list.h | 50 +- arduino.DuinOS.AVR/DuinOS/mpu_wrappers.h | 58 +- arduino.DuinOS.AVR/DuinOS/port.c | 70 +- arduino.DuinOS.AVR/DuinOS/portable.h | 50 +- arduino.DuinOS.AVR/DuinOS/portmacro.h | 50 +- arduino.DuinOS.AVR/DuinOS/projdefs.h | 50 +- arduino.DuinOS.AVR/DuinOS/queue.c | 947 +++++++++++++++-------- arduino.DuinOS.AVR/DuinOS/queue.h | 272 +++++-- arduino.DuinOS.AVR/DuinOS/semphr.h | 50 +- arduino.DuinOS.AVR/DuinOS/task.h | 149 ++-- arduino.DuinOS.AVR/DuinOS/tasks.c | 312 ++++---- arduino.DuinOS.AVR/DuinOS/timers.c | 50 +- arduino.DuinOS.AVR/DuinOS/timers.h | 50 +- 22 files changed, 1738 insertions(+), 1085 deletions(-) diff --git a/arduino.DuinOS.AVR/DuinOS/FreeRTOS.h b/arduino.DuinOS.AVR/DuinOS/FreeRTOS.h index 99df4ac..5024639 100644 --- a/arduino.DuinOS.AVR/DuinOS/FreeRTOS.h +++ b/arduino.DuinOS.AVR/DuinOS/FreeRTOS.h @@ -1,7 +1,7 @@ /* - FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd. - FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** @@ -29,20 +29,23 @@ FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - >>>NOTE<<< The modification to the GPL is included to allow you to + + >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS - kernel. FreeRTOS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. You should have received a copy of the GNU General Public - License and the FreeRTOS license exception along with FreeRTOS; if not it - can be viewed here: http://www.freertos.org/a00114.html and also obtained - by writing to Richard Barry, contact details for whom are available on the - FreeRTOS WEB site. + kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License + and the FreeRTOS license exception along with FreeRTOS; if not itcan be + viewed here: http://www.freertos.org/a00114.html and also obtained by + writing to Real Time Engineers Ltd., contact details for whom are available + on the FreeRTOS WEB site. 1 tab == 4 spaces! - + *************************************************************************** * * * Having a problem? Start by reading the FAQ "My application does * @@ -52,18 +55,21 @@ * * *************************************************************************** - - http://www.FreeRTOS.org - Documentation, training, latest versions, license - and contact details. - + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool. + including FreeRTOS+Trace - an indispensable productivity tool, and our new + fully thread aware and reentrant UDP/IP stack. - Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell - the code with commercial support, indemnification, and middleware, under - the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also - provide a safety engineered and independently SIL3 certified version under - the SafeRTOS brand: http://www.SafeRTOS.com. + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems, who sell the code with commercial support, + indemnification and middleware, under the OpenRTOS brand. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. */ #ifndef INC_FREERTOS_H @@ -129,11 +135,11 @@ typedef portBASE_TYPE (*pdTASK_HOOK_CODE)( void * ); #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. #endif -#ifndef INCLUDE_vTaskDelete +#ifndef INCLUDE_vTaskDelete #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. #endif -#ifndef INCLUDE_vTaskSuspend +#ifndef INCLUDE_vTaskSuspend #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. #endif @@ -161,6 +167,10 @@ typedef portBASE_TYPE (*pdTASK_HOOK_CODE)( void * ); #define INCLUDE_xQueueGetMutexHolder 0 #endif +#ifndef INCLUDE_xSemaphoreGetMutexHolder + #define INCLUDE_xSemaphoreGetMutexHolder INCLUDE_xQueueGetMutexHolder +#endif + #ifndef INCLUDE_pcTaskGetTaskName #define INCLUDE_pcTaskGetTaskName 0 #endif @@ -173,8 +183,8 @@ typedef portBASE_TYPE (*pdTASK_HOOK_CODE)( void * ); #define INCLUDE_uxTaskGetStackHighWaterMark 0 #endif -#ifndef INCLUDE_eTaskStateGet - #define INCLUDE_eTaskStateGet 0 +#ifndef INCLUDE_eTaskGetState + #define INCLUDE_eTaskGetState 0 #endif #ifndef configUSE_RECURSIVE_MUTEXES @@ -316,7 +326,7 @@ typedef portBASE_TYPE (*pdTASK_HOOK_CODE)( void * ); #ifndef traceTASK_PRIORITY_DISINHERIT /* Called when a task releases a mutex, the holding of which had resulted in - the task inheriting the priority of a higher priority task. + the task inheriting the priority of a higher priority task. pxTCBOfMutexHolder is a pointer to the TCB of the task that is releasing the mutex. uxOriginalPriority is the task's configured (base) priority. */ #define traceTASK_PRIORITY_DISINHERIT( pxTCBOfMutexHolder, uxOriginalPriority ) @@ -348,7 +358,7 @@ typedef portBASE_TYPE (*pdTASK_HOOK_CODE)( void * ); #define traceMOVED_TASK_TO_READY_STATE( pxTCB ) #endif -#ifndef traceQUEUE_CREATE +#ifndef traceQUEUE_CREATE #define traceQUEUE_CREATE( pxNewQueue ) #endif @@ -534,6 +544,14 @@ typedef portBASE_TYPE (*pdTASK_HOOK_CODE)( void * ); #define portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime ) #endif +#ifndef configEXPECTED_IDLE_TIME_BEFORE_SLEEP + #define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 2 +#endif + +#if configEXPECTED_IDLE_TIME_BEFORE_SLEEP < 2 + #error configEXPECTED_IDLE_TIME_BEFORE_SLEEP must not be less than 2 +#endif + #ifndef configUSE_TICKLESS_IDLE #define configUSE_TICKLESS_IDLE 0 #endif @@ -546,5 +564,12 @@ typedef portBASE_TYPE (*pdTASK_HOOK_CODE)( void * ); #define configPOST_SLEEP_PROCESSING( x ) #endif +#ifndef configUSE_QUEUE_SETS + #define configUSE_QUEUE_SETS 0 +#endif + +/* For backward compatability. */ +#define eTaskStateGet eTaskGetState + #endif /* INC_FREERTOS_H */ diff --git a/arduino.DuinOS.AVR/DuinOS/StackMacros.h b/arduino.DuinOS.AVR/DuinOS/StackMacros.h index 7f2af14..d808009 100644 --- a/arduino.DuinOS.AVR/DuinOS/StackMacros.h +++ b/arduino.DuinOS.AVR/DuinOS/StackMacros.h @@ -1,7 +1,7 @@ /* - FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd. - FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** @@ -29,20 +29,23 @@ FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - >>>NOTE<<< The modification to the GPL is included to allow you to + + >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS - kernel. FreeRTOS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. You should have received a copy of the GNU General Public - License and the FreeRTOS license exception along with FreeRTOS; if not it - can be viewed here: http://www.freertos.org/a00114.html and also obtained - by writing to Richard Barry, contact details for whom are available on the - FreeRTOS WEB site. + kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License + and the FreeRTOS license exception along with FreeRTOS; if not itcan be + viewed here: http://www.freertos.org/a00114.html and also obtained by + writing to Real Time Engineers Ltd., contact details for whom are available + on the FreeRTOS WEB site. 1 tab == 4 spaces! - + *************************************************************************** * * * Having a problem? Start by reading the FAQ "My application does * @@ -52,18 +55,21 @@ * * *************************************************************************** - - http://www.FreeRTOS.org - Documentation, training, latest versions, license - and contact details. - + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool. + including FreeRTOS+Trace - an indispensable productivity tool, and our new + fully thread aware and reentrant UDP/IP stack. - Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell - the code with commercial support, indemnification, and middleware, under - the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also - provide a safety engineered and independently SIL3 certified version under - the SafeRTOS brand: http://www.SafeRTOS.com. + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems, who sell the code with commercial support, + indemnification and middleware, under the OpenRTOS brand. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. */ #ifndef STACK_MACROS_H diff --git a/arduino.DuinOS.AVR/DuinOS/croutine.c b/arduino.DuinOS.AVR/DuinOS/croutine.c index d428dcc..38c12c5 100644 --- a/arduino.DuinOS.AVR/DuinOS/croutine.c +++ b/arduino.DuinOS.AVR/DuinOS/croutine.c @@ -1,7 +1,7 @@ /* - FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd. - FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** @@ -29,20 +29,23 @@ FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - >>>NOTE<<< The modification to the GPL is included to allow you to + + >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS - kernel. FreeRTOS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. You should have received a copy of the GNU General Public - License and the FreeRTOS license exception along with FreeRTOS; if not it - can be viewed here: http://www.freertos.org/a00114.html and also obtained - by writing to Richard Barry, contact details for whom are available on the - FreeRTOS WEB site. + kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License + and the FreeRTOS license exception along with FreeRTOS; if not itcan be + viewed here: http://www.freertos.org/a00114.html and also obtained by + writing to Real Time Engineers Ltd., contact details for whom are available + on the FreeRTOS WEB site. 1 tab == 4 spaces! - + *************************************************************************** * * * Having a problem? Start by reading the FAQ "My application does * @@ -52,18 +55,21 @@ * * *************************************************************************** - - http://www.FreeRTOS.org - Documentation, training, latest versions, license - and contact details. - + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool. + including FreeRTOS+Trace - an indispensable productivity tool, and our new + fully thread aware and reentrant UDP/IP stack. + + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems, who sell the code with commercial support, + indemnification and middleware, under the OpenRTOS brand. - Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell - the code with commercial support, indemnification, and middleware, under - the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also - provide a safety engineered and independently SIL3 certified version under - the SafeRTOS brand: http://www.SafeRTOS.com. + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. */ #include "FreeRTOS.h" @@ -85,7 +91,7 @@ static xList xDelayedCoRoutineList1; /*< Delayed co-routines. */ static xList xDelayedCoRoutineList2; /*< Delayed co-routines (two lists are used - one for delays that have overflowed the current tick count. */ static xList * pxDelayedCoRoutineList; /*< Points to the delayed co-routine list currently being used. */ static xList * pxOverflowDelayedCoRoutineList; /*< Points to the delayed co-routine list currently being used to hold co-routines that have overflowed the current tick count. */ -static xList xPendingReadyCoRoutineList; /*< Holds co-routines that have been readied by an external event. They cannot be added directly to the ready lists as the ready lists cannot be accessed by interrupts. */ +static xList xPendingReadyCoRoutineList; /*< Holds co-routines that have been readied by an external event. They cannot be added directly to the ready lists as the ready lists cannot be accessed by interrupts. */ /* Other file private variables. --------------------------------*/ corCRCB * pxCurrentCoRoutine = NULL; @@ -109,7 +115,7 @@ static portTickType xCoRoutineTickCount = 0, xLastTickCount = 0, xPassedTicks = uxTopCoRoutineReadyPriority = pxCRCB->uxPriority; \ } \ vListInsertEnd( ( xList * ) &( pxReadyCoRoutineLists[ pxCRCB->uxPriority ] ), &( pxCRCB->xGenericListItem ) ); \ -} +} /* * Utility to ready all the lists used by the scheduler. This is called @@ -175,10 +181,10 @@ corCRCB *pxCoRoutine; in a list. */ listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xGenericListItem ), pxCoRoutine ); listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xEventListItem ), pxCoRoutine ); - + /* Event lists are always in priority order. */ listSET_LIST_ITEM_VALUE( &( pxCoRoutine->xEventListItem ), configMAX_PRIORITIES - ( portTickType ) uxPriority ); - + /* Now the co-routine has been initialised it can be added to the ready list at the correct priority. */ prvAddCoRoutineToReadyQueue( pxCoRoutine ); @@ -186,11 +192,11 @@ corCRCB *pxCoRoutine; xReturn = pdPASS; } else - { + { xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY; } - - return xReturn; + + return xReturn; } /*-----------------------------------------------------------*/ @@ -243,14 +249,14 @@ static void prvCheckPendingReadyList( void ) /* The pending ready list can be accessed by an ISR. */ portDISABLE_INTERRUPTS(); - { - pxUnblockedCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( (&xPendingReadyCoRoutineList) ); + { + pxUnblockedCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( (&xPendingReadyCoRoutineList) ); uxListRemove( &( pxUnblockedCRCB->xEventListItem ) ); } portENABLE_INTERRUPTS(); uxListRemove( &( pxUnblockedCRCB->xGenericListItem ) ); - prvAddCoRoutineToReadyQueue( pxUnblockedCRCB ); + prvAddCoRoutineToReadyQueue( pxUnblockedCRCB ); } } /*-----------------------------------------------------------*/ @@ -282,11 +288,11 @@ corCRCB *pxCRCB; { pxCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedCoRoutineList ); - if( xCoRoutineTickCount < listGET_LIST_ITEM_VALUE( &( pxCRCB->xGenericListItem ) ) ) - { - /* Timeout not yet expired. */ - break; - } + if( xCoRoutineTickCount < listGET_LIST_ITEM_VALUE( &( pxCRCB->xGenericListItem ) ) ) + { + /* Timeout not yet expired. */ + break; + } portDISABLE_INTERRUPTS(); { @@ -295,18 +301,18 @@ corCRCB *pxCRCB; have been moved to the pending ready list and the following line is still valid. Also the pvContainer parameter will have been set to NULL so the following lines are also valid. */ - uxListRemove( &( pxCRCB->xGenericListItem ) ); + uxListRemove( &( pxCRCB->xGenericListItem ) ); - /* Is the co-routine waiting on an event also? */ - if( pxCRCB->xEventListItem.pvContainer ) - { - uxListRemove( &( pxCRCB->xEventListItem ) ); + /* Is the co-routine waiting on an event also? */ + if( pxCRCB->xEventListItem.pvContainer ) + { + uxListRemove( &( pxCRCB->xEventListItem ) ); } } portENABLE_INTERRUPTS(); - prvAddCoRoutineToReadyQueue( pxCRCB ); - } + prvAddCoRoutineToReadyQueue( pxCRCB ); + } } xLastTickCount = xCoRoutineTickCount; diff --git a/arduino.DuinOS.AVR/DuinOS/croutine.h b/arduino.DuinOS.AVR/DuinOS/croutine.h index f4f1931..361bd1e 100644 --- a/arduino.DuinOS.AVR/DuinOS/croutine.h +++ b/arduino.DuinOS.AVR/DuinOS/croutine.h @@ -1,7 +1,7 @@ /* - FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd. - FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** @@ -29,20 +29,23 @@ FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - >>>NOTE<<< The modification to the GPL is included to allow you to + + >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS - kernel. FreeRTOS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. You should have received a copy of the GNU General Public - License and the FreeRTOS license exception along with FreeRTOS; if not it - can be viewed here: http://www.freertos.org/a00114.html and also obtained - by writing to Richard Barry, contact details for whom are available on the - FreeRTOS WEB site. + kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License + and the FreeRTOS license exception along with FreeRTOS; if not itcan be + viewed here: http://www.freertos.org/a00114.html and also obtained by + writing to Real Time Engineers Ltd., contact details for whom are available + on the FreeRTOS WEB site. 1 tab == 4 spaces! - + *************************************************************************** * * * Having a problem? Start by reading the FAQ "My application does * @@ -52,18 +55,21 @@ * * *************************************************************************** - - http://www.FreeRTOS.org - Documentation, training, latest versions, license - and contact details. - + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool. + including FreeRTOS+Trace - an indispensable productivity tool, and our new + fully thread aware and reentrant UDP/IP stack. - Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell - the code with commercial support, indemnification, and middleware, under - the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also - provide a safety engineered and independently SIL3 certified version under - the SafeRTOS brand: http://www.SafeRTOS.com. + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems, who sell the code with commercial support, + indemnification and middleware, under the OpenRTOS brand. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. */ #ifndef CO_ROUTINE_H diff --git a/arduino.DuinOS.AVR/DuinOS/heap_1.c b/arduino.DuinOS.AVR/DuinOS/heap_1.c index 65e2cd7..5577ef3 100644 --- a/arduino.DuinOS.AVR/DuinOS/heap_1.c +++ b/arduino.DuinOS.AVR/DuinOS/heap_1.c @@ -1,7 +1,7 @@ /* - FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd. - FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** @@ -29,20 +29,23 @@ FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - >>>NOTE<<< The modification to the GPL is included to allow you to + + >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS - kernel. FreeRTOS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. You should have received a copy of the GNU General Public - License and the FreeRTOS license exception along with FreeRTOS; if not it - can be viewed here: http://www.freertos.org/a00114.html and also obtained - by writing to Richard Barry, contact details for whom are available on the - FreeRTOS WEB site. + kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License + and the FreeRTOS license exception along with FreeRTOS; if not itcan be + viewed here: http://www.freertos.org/a00114.html and also obtained by + writing to Real Time Engineers Ltd., contact details for whom are available + on the FreeRTOS WEB site. 1 tab == 4 spaces! - + *************************************************************************** * * * Having a problem? Start by reading the FAQ "My application does * @@ -52,18 +55,21 @@ * * *************************************************************************** - - http://www.FreeRTOS.org - Documentation, training, latest versions, license - and contact details. - + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool. + including FreeRTOS+Trace - an indispensable productivity tool, and our new + fully thread aware and reentrant UDP/IP stack. - Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell - the code with commercial support, indemnification, and middleware, under - the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also - provide a safety engineered and independently SIL3 certified version under - the SafeRTOS brand: http://www.SafeRTOS.com. + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems, who sell the code with commercial support, + indemnification and middleware, under the OpenRTOS brand. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. */ @@ -86,24 +92,19 @@ task.h is included from an application file. */ #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE -/* Allocate the memory for the heap. The struct is used to force byte -alignment without using any non-portable code. */ -static union xRTOS_HEAP -{ - #if portBYTE_ALIGNMENT == 8 - volatile portDOUBLE dDummy; - #else - volatile unsigned long ulDummy; - #endif - unsigned char ucHeap[ configTOTAL_HEAP_SIZE ]; -} xHeap; +/* A few bytes might be lost to byte aligning the heap start address. */ +#define configADJUSTED_HEAP_SIZE ( configTOTAL_HEAP_SIZE - portBYTE_ALIGNMENT ) +/* Allocate the memory for the heap. */ +static unsigned char ucHeap[ configTOTAL_HEAP_SIZE ]; static size_t xNextFreeByte = ( size_t ) 0; + /*-----------------------------------------------------------*/ void *pvPortMalloc( size_t xWantedSize ) { void *pvReturn = NULL; +static unsigned char *pucAlignedHeap = NULL; /* Ensure that blocks are always aligned to the required number of bytes. */ #if portBYTE_ALIGNMENT != 1 @@ -116,13 +117,19 @@ void *pvReturn = NULL; vTaskSuspendAll(); { + if( pucAlignedHeap == NULL ) + { + /* Ensure the heap starts on a correctly aligned boundary. */ + pucAlignedHeap = ( unsigned char * ) ( ( ( portPOINTER_SIZE_TYPE ) &ucHeap[ portBYTE_ALIGNMENT ] ) & ( ( portPOINTER_SIZE_TYPE ) ~portBYTE_ALIGNMENT_MASK ) ); + } + /* Check there is enough room left for the allocation. */ - if( ( ( xNextFreeByte + xWantedSize ) < configTOTAL_HEAP_SIZE ) && + if( ( ( xNextFreeByte + xWantedSize ) < configADJUSTED_HEAP_SIZE ) && ( ( xNextFreeByte + xWantedSize ) > xNextFreeByte ) )/* Check for overflow. */ { /* Return the next free byte then increment the index past this block. */ - pvReturn = &( xHeap.ucHeap[ xNextFreeByte ] ); + pvReturn = pucAlignedHeap + xNextFreeByte; xNextFreeByte += xWantedSize; } } @@ -163,7 +170,7 @@ void vPortInitialiseBlocks( void ) size_t xPortGetFreeHeapSize( void ) { - return ( configTOTAL_HEAP_SIZE - xNextFreeByte ); + return ( configADJUSTED_HEAP_SIZE - xNextFreeByte ); } diff --git a/arduino.DuinOS.AVR/DuinOS/heap_2.c b/arduino.DuinOS.AVR/DuinOS/heap_2.c index bd827a9..749872e 100644 --- a/arduino.DuinOS.AVR/DuinOS/heap_2.c +++ b/arduino.DuinOS.AVR/DuinOS/heap_2.c @@ -1,7 +1,7 @@ /* - FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd. - FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** @@ -29,20 +29,23 @@ FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - >>>NOTE<<< The modification to the GPL is included to allow you to + + >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS - kernel. FreeRTOS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. You should have received a copy of the GNU General Public - License and the FreeRTOS license exception along with FreeRTOS; if not it - can be viewed here: http://www.freertos.org/a00114.html and also obtained - by writing to Richard Barry, contact details for whom are available on the - FreeRTOS WEB site. + kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License + and the FreeRTOS license exception along with FreeRTOS; if not itcan be + viewed here: http://www.freertos.org/a00114.html and also obtained by + writing to Real Time Engineers Ltd., contact details for whom are available + on the FreeRTOS WEB site. 1 tab == 4 spaces! - + *************************************************************************** * * * Having a problem? Start by reading the FAQ "My application does * @@ -52,27 +55,30 @@ * * *************************************************************************** - - http://www.FreeRTOS.org - Documentation, training, latest versions, license - and contact details. - + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool. + including FreeRTOS+Trace - an indispensable productivity tool, and our new + fully thread aware and reentrant UDP/IP stack. - Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell - the code with commercial support, indemnification, and middleware, under - the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also - provide a safety engineered and independently SIL3 certified version under - the SafeRTOS brand: http://www.SafeRTOS.com. + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems, who sell the code with commercial support, + indemnification and middleware, under the OpenRTOS brand. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. */ /* * A sample implementation of pvPortMalloc() and vPortFree() that permits * allocated blocks to be freed, but does not combine adjacent free blocks - * into a single larger block (and so will fragment memory). See heap_4.c for + * into a single larger block (and so will fragment memory). See heap_4.c for * an aquivalent that does combine adjacent blocks into single larger blocks. * - * See heap_1.c, heap_3.c and heap_4.c for alternative implementations, and the + * See heap_1.c, heap_3.c and heap_4.c for alternative implementations, and the * memory management pages of http://www.FreeRTOS.org for more information. */ #include @@ -87,17 +93,16 @@ task.h is included from an application file. */ #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE -/* Allocate the memory for the heap. The struct is used to force byte -alignment without using any non-portable code. */ -static union xRTOS_HEAP -{ - #if portBYTE_ALIGNMENT == 8 - volatile portDOUBLE dDummy; - #else - volatile unsigned long ulDummy; - #endif - unsigned char ucHeap[ configTOTAL_HEAP_SIZE ]; -} xHeap; +/* A few bytes might be lost to byte aligning the heap start address. */ +#define configADJUSTED_HEAP_SIZE ( configTOTAL_HEAP_SIZE - portBYTE_ALIGNMENT ) + +/* + * Initialises the heap structures before their first use. + */ +static void prvHeapInit( void ); + +/* Allocate the memory for the heap. */ +static unsigned char ucHeap[ configTOTAL_HEAP_SIZE ]; /* Define the linked list structure. This is used to link free blocks in order of their size. */ @@ -116,7 +121,7 @@ static xBlockLink xStart, xEnd; /* Keeps track of the number of free bytes remaining, but says nothing about fragmentation. */ -static size_t xFreeBytesRemaining = configTOTAL_HEAP_SIZE; +static size_t xFreeBytesRemaining = configADJUSTED_HEAP_SIZE; /* STATIC FUNCTIONS ARE DEFINED AS MACROS TO MINIMIZE THE FUNCTION CALL DEPTH. */ @@ -146,27 +151,6 @@ size_t xBlockSize; \ } /*-----------------------------------------------------------*/ -#define prvHeapInit() \ -{ \ -xBlockLink *pxFirstFreeBlock; \ - \ - /* xStart is used to hold a pointer to the first item in the list of free */ \ - /* blocks. The void cast is used to prevent compiler warnings. */ \ - xStart.pxNextFreeBlock = ( void * ) xHeap.ucHeap; \ - xStart.xBlockSize = ( size_t ) 0; \ - \ - /* xEnd is used to mark the end of the list of free blocks. */ \ - xEnd.xBlockSize = configTOTAL_HEAP_SIZE; \ - xEnd.pxNextFreeBlock = NULL; \ - \ - /* To start with there is a single free block that is sized to take up the \ - entire heap space. */ \ - pxFirstFreeBlock = ( void * ) xHeap.ucHeap; \ - pxFirstFreeBlock->xBlockSize = configTOTAL_HEAP_SIZE; \ - pxFirstFreeBlock->pxNextFreeBlock = &xEnd; \ -} -/*-----------------------------------------------------------*/ - void *pvPortMalloc( size_t xWantedSize ) { xBlockLink *pxBlock, *pxPreviousBlock, *pxNewBlockLink; @@ -197,7 +181,7 @@ void *pvReturn = NULL; } } - if( ( xWantedSize > 0 ) && ( xWantedSize < configTOTAL_HEAP_SIZE ) ) + if( ( xWantedSize > 0 ) && ( xWantedSize < configADJUSTED_HEAP_SIZE ) ) { /* Blocks are stored in byte order - traverse the list from the start (smallest) block until one of adequate size is found. */ @@ -236,7 +220,7 @@ void *pvReturn = NULL; /* Insert the new block into the list of free blocks. */ prvInsertBlockIntoFreeList( ( pxNewBlockLink ) ); } - + xFreeBytesRemaining -= pxBlock->xBlockSize; } } @@ -268,7 +252,8 @@ xBlockLink *pxLink; before it. */ puc -= heapSTRUCT_SIZE; - /* This casting is to keep the compiler from issuing warnings. */ + /* This unexpected casting is to keep some compilers from issuing + byte alignment warnings. */ pxLink = ( void * ) puc; vTaskSuspendAll(); @@ -292,3 +277,29 @@ void vPortInitialiseBlocks( void ) { /* This just exists to keep the linker quiet. */ } +/*-----------------------------------------------------------*/ + +static void prvHeapInit( void ) +{ +xBlockLink *pxFirstFreeBlock; +unsigned char *pucAlignedHeap; + + /* Ensure the heap starts on a correctly aligned boundary. */ + pucAlignedHeap = ( unsigned char * ) ( ( ( portPOINTER_SIZE_TYPE ) &ucHeap[ portBYTE_ALIGNMENT ] ) & ( ( portPOINTER_SIZE_TYPE ) ~portBYTE_ALIGNMENT_MASK ) ); + + /* xStart is used to hold a pointer to the first item in the list of free + blocks. The void cast is used to prevent compiler warnings. */ + xStart.pxNextFreeBlock = ( void * ) pucAlignedHeap; + xStart.xBlockSize = ( size_t ) 0; + + /* xEnd is used to mark the end of the list of free blocks. */ + xEnd.xBlockSize = configADJUSTED_HEAP_SIZE; + xEnd.pxNextFreeBlock = NULL; + + /* To start with there is a single free block that is sized to take up the + entire heap space. */ + pxFirstFreeBlock = ( void * ) pucAlignedHeap; + pxFirstFreeBlock->xBlockSize = configADJUSTED_HEAP_SIZE; + pxFirstFreeBlock->pxNextFreeBlock = &xEnd; +} +/*-----------------------------------------------------------*/ diff --git a/arduino.DuinOS.AVR/DuinOS/heap_3.c b/arduino.DuinOS.AVR/DuinOS/heap_3.c index 074835e..4bdb2f9 100644 --- a/arduino.DuinOS.AVR/DuinOS/heap_3.c +++ b/arduino.DuinOS.AVR/DuinOS/heap_3.c @@ -1,7 +1,7 @@ /* FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. - FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** @@ -29,20 +29,23 @@ FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - >>>NOTE<<< The modification to the GPL is included to allow you to + + >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS - kernel. FreeRTOS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. You should have received a copy of the GNU General Public - License and the FreeRTOS license exception along with FreeRTOS; if not it - can be viewed here: http://www.freertos.org/a00114.html and also obtained - by writing to Richard Barry, contact details for whom are available on the - FreeRTOS WEB site. + kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License + and the FreeRTOS license exception along with FreeRTOS; if not itcan be + viewed here: http://www.freertos.org/a00114.html and also obtained by + writing to Real Time Engineers Ltd., contact details for whom are available + on the FreeRTOS WEB site. 1 tab == 4 spaces! - + *************************************************************************** * * * Having a problem? Start by reading the FAQ "My application does * @@ -52,18 +55,21 @@ * * *************************************************************************** - - http://www.FreeRTOS.org - Documentation, training, latest versions, license - and contact details. - + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool. + including FreeRTOS+Trace - an indispensable productivity tool, and our new + fully thread aware and reentrant UDP/IP stack. - Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell - the code with commercial support, indemnification, and middleware, under - the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also - provide a safety engineered and independently SIL3 certified version under - the SafeRTOS brand: http://www.SafeRTOS.com. + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems, who sell the code with commercial support, + indemnification and middleware, under the OpenRTOS brand. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. */ diff --git a/arduino.DuinOS.AVR/DuinOS/heap_4.c b/arduino.DuinOS.AVR/DuinOS/heap_4.c index d40fea1..b56bd28 100644 --- a/arduino.DuinOS.AVR/DuinOS/heap_4.c +++ b/arduino.DuinOS.AVR/DuinOS/heap_4.c @@ -1,7 +1,7 @@ /* - FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd. - FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** @@ -29,20 +29,23 @@ FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - >>>NOTE<<< The modification to the GPL is included to allow you to + + >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS - kernel. FreeRTOS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. You should have received a copy of the GNU General Public - License and the FreeRTOS license exception along with FreeRTOS; if not it - can be viewed here: http://www.freertos.org/a00114.html and also obtained - by writing to Richard Barry, contact details for whom are available on the - FreeRTOS WEB site. + kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License + and the FreeRTOS license exception along with FreeRTOS; if not itcan be + viewed here: http://www.freertos.org/a00114.html and also obtained by + writing to Real Time Engineers Ltd., contact details for whom are available + on the FreeRTOS WEB site. 1 tab == 4 spaces! - + *************************************************************************** * * * Having a problem? Start by reading the FAQ "My application does * @@ -52,18 +55,21 @@ * * *************************************************************************** - - http://www.FreeRTOS.org - Documentation, training, latest versions, license - and contact details. - + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool. + including FreeRTOS+Trace - an indispensable productivity tool, and our new + fully thread aware and reentrant UDP/IP stack. - Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell - the code with commercial support, indemnification, and middleware, under - the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also - provide a safety engineered and independently SIL3 certified version under - the SafeRTOS brand: http://www.SafeRTOS.com. + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems, who sell the code with commercial support, + indemnification and middleware, under the OpenRTOS brand. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. */ /* @@ -89,17 +95,11 @@ task.h is included from an application file. */ /* Block sizes must not get too small. */ #define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( heapSTRUCT_SIZE * 2 ) ) -/* Allocate the memory for the heap. The struct is used to force byte -alignment without using any non-portable code. */ -static union xRTOS_HEAP -{ - #if portBYTE_ALIGNMENT == 8 - volatile portDOUBLE dDummy; - #else - volatile unsigned long ulDummy; - #endif - unsigned char ucHeap[ configTOTAL_HEAP_SIZE ]; -} xHeap; +/* A few bytes might be lost to byte aligning the heap start address. */ +#define configADJUSTED_HEAP_SIZE ( configTOTAL_HEAP_SIZE - portBYTE_ALIGNMENT ) + +/* Allocate the memory for the heap. */ +static unsigned char ucHeap[ configTOTAL_HEAP_SIZE ]; /* Define the linked list structure. This is used to link free blocks in order of their memory address. */ @@ -132,14 +132,14 @@ block must by correctly byte aligned. */ static const unsigned short heapSTRUCT_SIZE = ( sizeof( xBlockLink ) + portBYTE_ALIGNMENT - ( sizeof( xBlockLink ) % portBYTE_ALIGNMENT ) ); /* Ensure the pxEnd pointer will end up on the correct byte alignment. */ -static const size_t xTotalHeapSize = ( ( size_t ) configTOTAL_HEAP_SIZE ) & ( ( size_t ) ~portBYTE_ALIGNMENT_MASK ); +static const size_t xTotalHeapSize = ( ( size_t ) configADJUSTED_HEAP_SIZE ) & ( ( size_t ) ~portBYTE_ALIGNMENT_MASK ); /* Create a couple of list links to mark the start and end of the list. */ static xBlockLink xStart, *pxEnd = NULL; /* Keeps track of the number of free bytes remaining, but says nothing about fragmentation. */ -static size_t xFreeBytesRemaining = ( ( size_t ) configTOTAL_HEAP_SIZE ) & ( ( size_t ) ~portBYTE_ALIGNMENT_MASK ); +static size_t xFreeBytesRemaining = ( ( size_t ) configADJUSTED_HEAP_SIZE ) & ( ( size_t ) ~portBYTE_ALIGNMENT_MASK ); /* STATIC FUNCTIONS ARE DEFINED AS MACROS TO MINIMIZE THE FUNCTION CALL DEPTH. */ @@ -275,19 +275,19 @@ void vPortInitialiseBlocks( void ) static void prvHeapInit( void ) { xBlockLink *pxFirstFreeBlock; -unsigned char *pucHeapEnd; +unsigned char *pucHeapEnd, *pucAlignedHeap; - /* Ensure the start of the heap is aligned. */ - configASSERT( ( ( ( unsigned long ) xHeap.ucHeap ) & ( ( unsigned long ) portBYTE_ALIGNMENT_MASK ) ) == 0UL ); + /* Ensure the heap starts on a correctly aligned boundary. */ + pucAlignedHeap = ( unsigned char * ) ( ( ( portPOINTER_SIZE_TYPE ) &ucHeap[ portBYTE_ALIGNMENT ] ) & ( ( portPOINTER_SIZE_TYPE ) ~portBYTE_ALIGNMENT_MASK ) ); /* xStart is used to hold a pointer to the first item in the list of free blocks. The void cast is used to prevent compiler warnings. */ - xStart.pxNextFreeBlock = ( void * ) xHeap.ucHeap; + xStart.pxNextFreeBlock = ( void * ) pucAlignedHeap; xStart.xBlockSize = ( size_t ) 0; /* pxEnd is used to mark the end of the list of free blocks and is inserted at the end of the heap space. */ - pucHeapEnd = xHeap.ucHeap + xTotalHeapSize; + pucHeapEnd = pucAlignedHeap + xTotalHeapSize; pucHeapEnd -= heapSTRUCT_SIZE; pxEnd = ( void * ) pucHeapEnd; configASSERT( ( ( ( unsigned long ) pxEnd ) & ( ( unsigned long ) portBYTE_ALIGNMENT_MASK ) ) == 0UL ); @@ -296,7 +296,7 @@ unsigned char *pucHeapEnd; /* To start with there is a single free block that is sized to take up the entire heap space, minus the space taken by pxEnd. */ - pxFirstFreeBlock = ( void * ) xHeap.ucHeap; + pxFirstFreeBlock = ( void * ) pucAlignedHeap; pxFirstFreeBlock->xBlockSize = xTotalHeapSize - heapSTRUCT_SIZE; pxFirstFreeBlock->pxNextFreeBlock = pxEnd; diff --git a/arduino.DuinOS.AVR/DuinOS/list.c b/arduino.DuinOS.AVR/DuinOS/list.c index f3749f0..07baf5f 100644 --- a/arduino.DuinOS.AVR/DuinOS/list.c +++ b/arduino.DuinOS.AVR/DuinOS/list.c @@ -1,7 +1,7 @@ /* - FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd. - FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** @@ -29,20 +29,23 @@ FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - >>>NOTE<<< The modification to the GPL is included to allow you to + + >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS - kernel. FreeRTOS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. You should have received a copy of the GNU General Public - License and the FreeRTOS license exception along with FreeRTOS; if not it - can be viewed here: http://www.freertos.org/a00114.html and also obtained - by writing to Richard Barry, contact details for whom are available on the - FreeRTOS WEB site. + kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License + and the FreeRTOS license exception along with FreeRTOS; if not itcan be + viewed here: http://www.freertos.org/a00114.html and also obtained by + writing to Real Time Engineers Ltd., contact details for whom are available + on the FreeRTOS WEB site. 1 tab == 4 spaces! - + *************************************************************************** * * * Having a problem? Start by reading the FAQ "My application does * @@ -52,18 +55,21 @@ * * *************************************************************************** - - http://www.FreeRTOS.org - Documentation, training, latest versions, license - and contact details. - + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool. + including FreeRTOS+Trace - an indispensable productivity tool, and our new + fully thread aware and reentrant UDP/IP stack. - Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell - the code with commercial support, indemnification, and middleware, under - the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also - provide a safety engineered and independently SIL3 certified version under - the SafeRTOS brand: http://www.SafeRTOS.com. + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems, who sell the code with commercial support, + indemnification and middleware, under the OpenRTOS brand. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. */ diff --git a/arduino.DuinOS.AVR/DuinOS/list.h b/arduino.DuinOS.AVR/DuinOS/list.h index efaff25..a08a771 100644 --- a/arduino.DuinOS.AVR/DuinOS/list.h +++ b/arduino.DuinOS.AVR/DuinOS/list.h @@ -1,7 +1,7 @@ /* - FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd. - FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** @@ -29,20 +29,23 @@ FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - >>>NOTE<<< The modification to the GPL is included to allow you to + + >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS - kernel. FreeRTOS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. You should have received a copy of the GNU General Public - License and the FreeRTOS license exception along with FreeRTOS; if not it - can be viewed here: http://www.freertos.org/a00114.html and also obtained - by writing to Richard Barry, contact details for whom are available on the - FreeRTOS WEB site. + kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License + and the FreeRTOS license exception along with FreeRTOS; if not itcan be + viewed here: http://www.freertos.org/a00114.html and also obtained by + writing to Real Time Engineers Ltd., contact details for whom are available + on the FreeRTOS WEB site. 1 tab == 4 spaces! - + *************************************************************************** * * * Having a problem? Start by reading the FAQ "My application does * @@ -52,18 +55,21 @@ * * *************************************************************************** - - http://www.FreeRTOS.org - Documentation, training, latest versions, license - and contact details. - + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool. + including FreeRTOS+Trace - an indispensable productivity tool, and our new + fully thread aware and reentrant UDP/IP stack. - Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell - the code with commercial support, indemnification, and middleware, under - the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also - provide a safety engineered and independently SIL3 certified version under - the SafeRTOS brand: http://www.SafeRTOS.com. + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems, who sell the code with commercial support, + indemnification and middleware, under the OpenRTOS brand. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. */ /* diff --git a/arduino.DuinOS.AVR/DuinOS/mpu_wrappers.h b/arduino.DuinOS.AVR/DuinOS/mpu_wrappers.h index 299e8d0..b5bc82d 100644 --- a/arduino.DuinOS.AVR/DuinOS/mpu_wrappers.h +++ b/arduino.DuinOS.AVR/DuinOS/mpu_wrappers.h @@ -1,7 +1,7 @@ /* - FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd. - FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** @@ -29,20 +29,23 @@ FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - >>>NOTE<<< The modification to the GPL is included to allow you to + + >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS - kernel. FreeRTOS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. You should have received a copy of the GNU General Public - License and the FreeRTOS license exception along with FreeRTOS; if not it - can be viewed here: http://www.freertos.org/a00114.html and also obtained - by writing to Richard Barry, contact details for whom are available on the - FreeRTOS WEB site. + kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License + and the FreeRTOS license exception along with FreeRTOS; if not itcan be + viewed here: http://www.freertos.org/a00114.html and also obtained by + writing to Real Time Engineers Ltd., contact details for whom are available + on the FreeRTOS WEB site. 1 tab == 4 spaces! - + *************************************************************************** * * * Having a problem? Start by reading the FAQ "My application does * @@ -52,18 +55,21 @@ * * *************************************************************************** - - http://www.FreeRTOS.org - Documentation, training, latest versions, license - and contact details. - + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool. + including FreeRTOS+Trace - an indispensable productivity tool, and our new + fully thread aware and reentrant UDP/IP stack. - Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell - the code with commercial support, indemnification, and middleware, under - the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also - provide a safety engineered and independently SIL3 certified version under - the SafeRTOS brand: http://www.SafeRTOS.com. + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems, who sell the code with commercial support, + indemnification and middleware, under the OpenRTOS brand. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. */ #ifndef MPU_WRAPPERS_H @@ -85,7 +91,7 @@ only for ports that are using the MPU. */ #define vTaskDelay MPU_vTaskDelay #define uxTaskPriorityGet MPU_uxTaskPriorityGet #define vTaskPrioritySet MPU_vTaskPrioritySet - #define eTaskStateGet MPU_eTaskStateGet + #define eTaskGetState MPU_eTaskGetState #define vTaskSuspend MPU_vTaskSuspend #define xTaskIsTaskSuspended MPU_xTaskIsTaskSuspended #define vTaskResume MPU_vTaskResume @@ -101,6 +107,7 @@ only for ports that are using the MPU. */ #define uxTaskGetStackHighWaterMark MPU_uxTaskGetStackHighWaterMark #define xTaskGetCurrentTaskHandle MPU_xTaskGetCurrentTaskHandle #define xTaskGetSchedulerState MPU_xTaskGetSchedulerState + #define xTaskGetIdleTaskHandle MPU_xTaskGetIdleTaskHandle #define xQueueGenericCreate MPU_xQueueGenericCreate #define xQueueCreateMutex MPU_xQueueCreateMutex @@ -113,6 +120,11 @@ only for ports that are using the MPU. */ #define xQueueGenericReceive MPU_xQueueGenericReceive #define uxQueueMessagesWaiting MPU_uxQueueMessagesWaiting #define vQueueDelete MPU_vQueueDelete + #define xQueueGenericReset MPU_xQueueGenericReset + #define xQueueCreateSet MPU_xQueueCreateSet + #define xQueueSelectFromSet MPU_xQueueSelectFromSet + #define xQueueAddToSet MPU_xQueueAddToSet + #define xQueueRemoveFromSet MPU_xQueueRemoveFromSet #define pvPortMalloc MPU_pvPortMalloc #define vPortFree MPU_vPortFree diff --git a/arduino.DuinOS.AVR/DuinOS/port.c b/arduino.DuinOS.AVR/DuinOS/port.c index 4c2d6ba..04bc16f 100644 --- a/arduino.DuinOS.AVR/DuinOS/port.c +++ b/arduino.DuinOS.AVR/DuinOS/port.c @@ -1,7 +1,7 @@ /* - FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd. - FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** @@ -29,20 +29,23 @@ FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - >>>NOTE<<< The modification to the GPL is included to allow you to + + >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS - kernel. FreeRTOS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. You should have received a copy of the GNU General Public - License and the FreeRTOS license exception along with FreeRTOS; if not it - can be viewed here: http://www.freertos.org/a00114.html and also obtained - by writing to Richard Barry, contact details for whom are available on the - FreeRTOS WEB site. + kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License + and the FreeRTOS license exception along with FreeRTOS; if not itcan be + viewed here: http://www.freertos.org/a00114.html and also obtained by + writing to Real Time Engineers Ltd., contact details for whom are available + on the FreeRTOS WEB site. 1 tab == 4 spaces! - + *************************************************************************** * * * Having a problem? Start by reading the FAQ "My application does * @@ -52,18 +55,21 @@ * * *************************************************************************** - - http://www.FreeRTOS.org - Documentation, training, latest versions, license - and contact details. - + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool. + including FreeRTOS+Trace - an indispensable productivity tool, and our new + fully thread aware and reentrant UDP/IP stack. - Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell - the code with commercial support, indemnification, and middleware, under - the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also - provide a safety engineered and independently SIL3 certified version under - the SafeRTOS brand: http://www.SafeRTOS.com. + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems, who sell the code with commercial support, + indemnification and middleware, under the OpenRTOS brand. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. */ /* @@ -251,18 +257,18 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE #if defined(__AVR_ATmega2560__) // Implement normal stack initialisation but with portLONG instead of portSHORT - usAddress = ( unsigned portLONG ) pxCode; - *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); - pxTopOfStack--; + usAddress = ( unsigned portLONG ) pxCode; + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); + pxTopOfStack--; - usAddress >>= 8; - *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); - pxTopOfStack--; + usAddress >>= 8; + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); + pxTopOfStack--; - // Implemented the 3byte addressing - usAddress >>= 8; - *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); - pxTopOfStack--; + // Implemented the 3byte addressing + usAddress >>= 8; + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); + pxTopOfStack--; // Normal initialisation for over ATmega #else diff --git a/arduino.DuinOS.AVR/DuinOS/portable.h b/arduino.DuinOS.AVR/DuinOS/portable.h index bdf1e8f..cb35389 100644 --- a/arduino.DuinOS.AVR/DuinOS/portable.h +++ b/arduino.DuinOS.AVR/DuinOS/portable.h @@ -1,7 +1,7 @@ /* - FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd. - FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** @@ -29,20 +29,23 @@ FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - >>>NOTE<<< The modification to the GPL is included to allow you to + + >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS - kernel. FreeRTOS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. You should have received a copy of the GNU General Public - License and the FreeRTOS license exception along with FreeRTOS; if not it - can be viewed here: http://www.freertos.org/a00114.html and also obtained - by writing to Richard Barry, contact details for whom are available on the - FreeRTOS WEB site. + kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License + and the FreeRTOS license exception along with FreeRTOS; if not itcan be + viewed here: http://www.freertos.org/a00114.html and also obtained by + writing to Real Time Engineers Ltd., contact details for whom are available + on the FreeRTOS WEB site. 1 tab == 4 spaces! - + *************************************************************************** * * * Having a problem? Start by reading the FAQ "My application does * @@ -52,18 +55,21 @@ * * *************************************************************************** - - http://www.FreeRTOS.org - Documentation, training, latest versions, license - and contact details. - + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool. + including FreeRTOS+Trace - an indispensable productivity tool, and our new + fully thread aware and reentrant UDP/IP stack. - Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell - the code with commercial support, indemnification, and middleware, under - the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also - provide a safety engineered and independently SIL3 certified version under - the SafeRTOS brand: http://www.SafeRTOS.com. + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems, who sell the code with commercial support, + indemnification and middleware, under the OpenRTOS brand. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. */ /*----------------------------------------------------------- diff --git a/arduino.DuinOS.AVR/DuinOS/portmacro.h b/arduino.DuinOS.AVR/DuinOS/portmacro.h index bef20ad..ba81029 100644 --- a/arduino.DuinOS.AVR/DuinOS/portmacro.h +++ b/arduino.DuinOS.AVR/DuinOS/portmacro.h @@ -1,7 +1,7 @@ /* - FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd. - FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** @@ -29,20 +29,23 @@ FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - >>>NOTE<<< The modification to the GPL is included to allow you to + + >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS - kernel. FreeRTOS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. You should have received a copy of the GNU General Public - License and the FreeRTOS license exception along with FreeRTOS; if not it - can be viewed here: http://www.freertos.org/a00114.html and also obtained - by writing to Richard Barry, contact details for whom are available on the - FreeRTOS WEB site. + kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License + and the FreeRTOS license exception along with FreeRTOS; if not itcan be + viewed here: http://www.freertos.org/a00114.html and also obtained by + writing to Real Time Engineers Ltd., contact details for whom are available + on the FreeRTOS WEB site. 1 tab == 4 spaces! - + *************************************************************************** * * * Having a problem? Start by reading the FAQ "My application does * @@ -52,18 +55,21 @@ * * *************************************************************************** - - http://www.FreeRTOS.org - Documentation, training, latest versions, license - and contact details. - + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool. + including FreeRTOS+Trace - an indispensable productivity tool, and our new + fully thread aware and reentrant UDP/IP stack. - Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell - the code with commercial support, indemnification, and middleware, under - the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also - provide a safety engineered and independently SIL3 certified version under - the SafeRTOS brand: http://www.SafeRTOS.com. + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems, who sell the code with commercial support, + indemnification and middleware, under the OpenRTOS brand. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. */ /* diff --git a/arduino.DuinOS.AVR/DuinOS/projdefs.h b/arduino.DuinOS.AVR/DuinOS/projdefs.h index 9001cb5..2d5ae42 100644 --- a/arduino.DuinOS.AVR/DuinOS/projdefs.h +++ b/arduino.DuinOS.AVR/DuinOS/projdefs.h @@ -1,7 +1,7 @@ /* - FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd. - FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** @@ -29,20 +29,23 @@ FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - >>>NOTE<<< The modification to the GPL is included to allow you to + + >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS - kernel. FreeRTOS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. You should have received a copy of the GNU General Public - License and the FreeRTOS license exception along with FreeRTOS; if not it - can be viewed here: http://www.freertos.org/a00114.html and also obtained - by writing to Richard Barry, contact details for whom are available on the - FreeRTOS WEB site. + kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License + and the FreeRTOS license exception along with FreeRTOS; if not itcan be + viewed here: http://www.freertos.org/a00114.html and also obtained by + writing to Real Time Engineers Ltd., contact details for whom are available + on the FreeRTOS WEB site. 1 tab == 4 spaces! - + *************************************************************************** * * * Having a problem? Start by reading the FAQ "My application does * @@ -52,18 +55,21 @@ * * *************************************************************************** - - http://www.FreeRTOS.org - Documentation, training, latest versions, license - and contact details. - + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool. + including FreeRTOS+Trace - an indispensable productivity tool, and our new + fully thread aware and reentrant UDP/IP stack. - Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell - the code with commercial support, indemnification, and middleware, under - the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also - provide a safety engineered and independently SIL3 certified version under - the SafeRTOS brand: http://www.SafeRTOS.com. + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems, who sell the code with commercial support, + indemnification and middleware, under the OpenRTOS brand. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. */ #ifndef PROJDEFS_H diff --git a/arduino.DuinOS.AVR/DuinOS/queue.c b/arduino.DuinOS.AVR/DuinOS/queue.c index c4e3712..75bebd1 100644 --- a/arduino.DuinOS.AVR/DuinOS/queue.c +++ b/arduino.DuinOS.AVR/DuinOS/queue.c @@ -1,7 +1,7 @@ /* - FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd. - FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** @@ -29,20 +29,23 @@ FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - >>>NOTE<<< The modification to the GPL is included to allow you to + + >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS - kernel. FreeRTOS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. You should have received a copy of the GNU General Public - License and the FreeRTOS license exception along with FreeRTOS; if not it - can be viewed here: http://www.freertos.org/a00114.html and also obtained - by writing to Richard Barry, contact details for whom are available on the - FreeRTOS WEB site. + kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License + and the FreeRTOS license exception along with FreeRTOS; if not itcan be + viewed here: http://www.freertos.org/a00114.html and also obtained by + writing to Real Time Engineers Ltd., contact details for whom are available + on the FreeRTOS WEB site. 1 tab == 4 spaces! - + *************************************************************************** * * * Having a problem? Start by reading the FAQ "My application does * @@ -52,18 +55,21 @@ * * *************************************************************************** - - http://www.FreeRTOS.org - Documentation, training, latest versions, license - and contact details. - + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool. + including FreeRTOS+Trace - an indispensable productivity tool, and our new + fully thread aware and reentrant UDP/IP stack. - Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell - the code with commercial support, indemnification, and middleware, under - the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also - provide a safety engineered and independently SIL3 certified version under - the SafeRTOS brand: http://www.SafeRTOS.com. + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems, who sell the code with commercial support, + indemnification and middleware, under the OpenRTOS brand. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. */ #include @@ -76,6 +82,7 @@ task.h is included from an application file. */ #include "FreeRTOS.h" #include "task.h" +#include "queue.h" #if ( configUSE_CO_ROUTINES == 1 ) #include "croutine.h" @@ -83,20 +90,12 @@ task.h is included from an application file. */ #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE -/*----------------------------------------------------------- - * PUBLIC LIST API documented in list.h - *----------------------------------------------------------*/ - /* Constants used with the cRxLock and xTxLock structure members. */ #define queueUNLOCKED ( ( signed portBASE_TYPE ) -1 ) #define queueLOCKED_UNMODIFIED ( ( signed portBASE_TYPE ) 0 ) #define queueERRONEOUS_UNBLOCK ( -1 ) -/* For internal use only. */ -#define queueSEND_TO_BACK ( 0 ) -#define queueSEND_TO_FRONT ( 1 ) - /* Effectively make a union out of the xQUEUE structure. */ #define pxMutexHolder pcTail #define uxQueueType pcHead @@ -109,12 +108,6 @@ zero. */ #define queueDONT_BLOCK ( ( portTickType ) 0U ) #define queueMUTEX_GIVE_BLOCK_TIME ( ( portTickType ) 0U ) -/* These definitions *must* match those in queue.h. */ -#define queueQUEUE_TYPE_BASE ( 0U ) -#define queueQUEUE_TYPE_MUTEX ( 1U ) -#define queueQUEUE_TYPE_COUNTING_SEMAPHORE ( 2U ) -#define queueQUEUE_TYPE_BINARY_SEMAPHORE ( 3U ) -#define queueQUEUE_TYPE_RECURSIVE_MUTEX ( 4U ) /* * Definition of the queue used by the scheduler. @@ -122,11 +115,11 @@ zero. */ */ typedef struct QueueDefinition { - signed char *pcHead; /*< Points to the beginning of the queue storage area. */ - signed char *pcTail; /*< Points to the byte at the end of the queue storage area. Once more byte is allocated than necessary to store the queue items, this is used as a marker. */ + signed char *pcHead; /*< Points to the beginning of the queue storage area. */ + signed char *pcTail; /*< Points to the byte at the end of the queue storage area. Once more byte is allocated than necessary to store the queue items, this is used as a marker. */ - signed char *pcWriteTo; /*< Points to the free next place in the storage area. */ - signed char *pcReadFrom; /*< Points to the last place that a queued item was read from. */ + signed char *pcWriteTo; /*< Points to the free next place in the storage area. */ + signed char *pcReadFrom; /*< Points to the last place that a queued item was read from. */ xList xTasksWaitingToSend; /*< List of tasks that are blocked waiting to post onto this queue. Stored in priority order. */ xList xTasksWaitingToReceive; /*< List of tasks that are blocked waiting to read from this queue. Stored in priority order. */ @@ -143,60 +136,18 @@ typedef struct QueueDefinition unsigned char ucQueueType; #endif + #if ( configUSE_QUEUE_SETS == 1 ) + struct QueueDefinition *pxQueueSetContainer; + #endif + } xQUEUE; /*-----------------------------------------------------------*/ -/* - * Inside this file xQueueHandle is a pointer to a xQUEUE structure. - * To keep the definition private the API header file defines it as a - * pointer to void. - */ -typedef xQUEUE * xQueueHandle; - -/* - * Prototypes for public functions are included here so we don't have to - * include the API header file (as it defines xQueueHandle differently). These - * functions are documented in the API header file. - */ -xQueueHandle xQueueGenericCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize, unsigned char ucQueueType ) PRIVILEGED_FUNCTION; -signed portBASE_TYPE xQueueGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION; -unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION; -void vQueueDelete( xQueueHandle xQueue ) PRIVILEGED_FUNCTION; -signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION; -signed portBASE_TYPE xQueueGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking ) PRIVILEGED_FUNCTION; -signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; -xQueueHandle xQueueCreateMutex( unsigned char ucQueueType ) PRIVILEGED_FUNCTION; -xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount ) PRIVILEGED_FUNCTION; -portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime ) PRIVILEGED_FUNCTION; -portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle xMutex ) PRIVILEGED_FUNCTION; -signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION; -signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking ) PRIVILEGED_FUNCTION; -signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION; -signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION; -unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION; -void vQueueWaitForMessageRestricted( xQueueHandle pxQueue, portTickType xTicksToWait ) PRIVILEGED_FUNCTION; -unsigned char ucQueueGetQueueNumber( xQueueHandle pxQueue ) PRIVILEGED_FUNCTION; -void vQueueSetQueueNumber( xQueueHandle pxQueue, unsigned char ucQueueNumber ) PRIVILEGED_FUNCTION; -unsigned char ucQueueGetQueueType( xQueueHandle pxQueue ) PRIVILEGED_FUNCTION; -portBASE_TYPE xQueueGenericReset( xQueueHandle pxQueue, portBASE_TYPE xNewQueue ) PRIVILEGED_FUNCTION; -xTaskHandle xQueueGetMutexHolder( xQueueHandle xSemaphore ) PRIVILEGED_FUNCTION; - -/* - * Co-routine queue functions differ from task queue functions. Co-routines are - * an optional component. - */ -#if configUSE_CO_ROUTINES == 1 - signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken ) PRIVILEGED_FUNCTION; - signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken ) PRIVILEGED_FUNCTION; - signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait ) PRIVILEGED_FUNCTION; - signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait ) PRIVILEGED_FUNCTION; -#endif - /* * The queue registry is just a means for kernel aware debuggers to locate * queue structures. It has no other purpose so is an optional component. */ -#if configQUEUE_REGISTRY_SIZE > 0 +#if ( configQUEUE_REGISTRY_SIZE > 0 ) /* The type stored within the queue registry array. This allows a name to be assigned to each queue making kernel aware debugging a little @@ -214,9 +165,9 @@ xTaskHandle xQueueGetMutexHolder( xQueueHandle xSemaphore ) PRIVILEGED_FUNCTION; /* Removes a queue from the registry by simply setting the pcQueueName member to NULL. */ - static void vQueueUnregisterQueue( xQueueHandle xQueue ) PRIVILEGED_FUNCTION; - void vQueueAddToRegistry( xQueueHandle xQueue, signed char *pcQueueName ) PRIVILEGED_FUNCTION; -#endif + static void prvQueueUnregisterQueue( xQueueHandle xQueue ) PRIVILEGED_FUNCTION; + +#endif /* configQUEUE_REGISTRY_SIZE */ /* * Unlocks a queue locked by a call to prvLockQueue. Locking a queue does not @@ -226,21 +177,21 @@ xTaskHandle xQueueGetMutexHolder( xQueueHandle xSemaphore ) PRIVILEGED_FUNCTION; * to indicate that a task may require unblocking. When the queue in unlocked * these lock counts are inspected, and the appropriate action taken. */ -static void prvUnlockQueue( xQueueHandle pxQueue ) PRIVILEGED_FUNCTION; +static void prvUnlockQueue( xQUEUE *pxQueue ) PRIVILEGED_FUNCTION; /* * Uses a critical section to determine if there is any data in a queue. * * @return pdTRUE if the queue contains no items, otherwise pdFALSE. */ -static signed portBASE_TYPE prvIsQueueEmpty( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION; +static signed portBASE_TYPE prvIsQueueEmpty( const xQUEUE *pxQueue ) PRIVILEGED_FUNCTION; /* * Uses a critical section to determine if there is any space in a queue. * * @return pdTRUE if there is no space, otherwise pdFALSE; */ -static signed portBASE_TYPE prvIsQueueFull( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION; +static signed portBASE_TYPE prvIsQueueFull( const xQUEUE *pxQueue ) PRIVILEGED_FUNCTION; /* * Copies an item into the queue, either at the front of the queue or the @@ -252,6 +203,15 @@ static void prvCopyDataToQueue( xQUEUE *pxQueue, const void *pvItemToQueue, port * Copies an item out of a queue. */ static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void *pvBuffer ) PRIVILEGED_FUNCTION; + +#if ( configUSE_QUEUE_SETS == 1 ) + /* + * Checks to see if a queue is a member of a queue set, and if so, notifies + * the queue set that the queue contains data. + */ + static portBASE_TYPE prvNotifyQueueSetContainer( xQUEUE *pxQueue, portBASE_TYPE xCopyPosition ); +#endif + /*-----------------------------------------------------------*/ /* @@ -273,13 +233,11 @@ static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void *pvBuffer ) taskEXIT_CRITICAL() /*-----------------------------------------------------------*/ - -/*----------------------------------------------------------- - * PUBLIC QUEUE MANAGEMENT API documented in queue.h - *----------------------------------------------------------*/ - -portBASE_TYPE xQueueGenericReset( xQueueHandle pxQueue, portBASE_TYPE xNewQueue ) +portBASE_TYPE xQueueGenericReset( xQueueHandle xQueue, portBASE_TYPE xNewQueue ) { +xQUEUE *pxQueue; + + pxQueue = ( xQUEUE * ) xQueue; configASSERT( pxQueue ); taskENTER_CRITICAL(); @@ -349,12 +307,19 @@ xQueueHandle xReturn = NULL; pxNewQueue->uxLength = uxQueueLength; pxNewQueue->uxItemSize = uxItemSize; xQueueGenericReset( pxNewQueue, pdTRUE ); + #if ( configUSE_TRACE_FACILITY == 1 ) { pxNewQueue->ucQueueType = ucQueueType; } #endif /* configUSE_TRACE_FACILITY */ + #if( configUSE_QUEUE_SETS == 1 ) + { + pxNewQueue->pxQueueSetContainer = NULL; + } + #endif /* configUSE_QUEUE_SETS */ + traceQUEUE_CREATE( pxNewQueue ); xReturn = pxNewQueue; } @@ -410,6 +375,12 @@ xQueueHandle xReturn = NULL; } #endif + #if ( configUSE_QUEUE_SETS == 1 ) + { + pxNewQueue->pxQueueSetContainer = NULL; + } + #endif + /* Ensure the event queues start with the correct state. */ vListInitialise( &( pxNewQueue->xTasksWaitingToSend ) ); vListInitialise( &( pxNewQueue->xTasksWaitingToReceive ) ); @@ -431,7 +402,7 @@ xQueueHandle xReturn = NULL; #endif /* configUSE_MUTEXES */ /*-----------------------------------------------------------*/ -#if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xQueueGetMutexHolder == 1 ) ) +#if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) ) void* xQueueGetMutexHolder( xQueueHandle xSemaphore ) { @@ -444,9 +415,9 @@ xQueueHandle xReturn = NULL; following critical section exiting and the function returning. */ taskENTER_CRITICAL(); { - if( xSemaphore->uxQueueType == queueQUEUE_IS_MUTEX ) + if( ( ( xQUEUE * ) xSemaphore )->uxQueueType == queueQUEUE_IS_MUTEX ) { - pxReturn = ( void * ) xSemaphore->pxMutexHolder; + pxReturn = ( void * ) ( ( xQUEUE * ) xSemaphore )->pxMutexHolder; } else { @@ -463,10 +434,12 @@ xQueueHandle xReturn = NULL; #if ( configUSE_RECURSIVE_MUTEXES == 1 ) - portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle pxMutex ) + portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle xMutex ) { portBASE_TYPE xReturn; + xQUEUE *pxMutex; + pxMutex = ( xQUEUE * ) xMutex; configASSERT( pxMutex ); /* If this is the task that holds the mutex then pxMutexHolder will not @@ -510,12 +483,14 @@ xQueueHandle xReturn = NULL; #endif /* configUSE_RECURSIVE_MUTEXES */ /*-----------------------------------------------------------*/ -#if configUSE_RECURSIVE_MUTEXES == 1 +#if ( configUSE_RECURSIVE_MUTEXES == 1 ) - portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle pxMutex, portTickType xBlockTime ) + portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime ) { portBASE_TYPE xReturn; + xQUEUE *pxMutex; + pxMutex = ( xQUEUE * ) xMutex; configASSERT( pxMutex ); /* Comments regarding mutual exclusion as per those within @@ -550,17 +525,17 @@ xQueueHandle xReturn = NULL; #endif /* configUSE_RECURSIVE_MUTEXES */ /*-----------------------------------------------------------*/ -#if configUSE_COUNTING_SEMAPHORES == 1 +#if ( configUSE_COUNTING_SEMAPHORES == 1 ) xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount ) { - xQueueHandle pxHandle; + xQueueHandle xHandle; - pxHandle = xQueueGenericCreate( ( unsigned portBASE_TYPE ) uxCountValue, queueSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_COUNTING_SEMAPHORE ); + xHandle = xQueueGenericCreate( ( unsigned portBASE_TYPE ) uxCountValue, queueSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_COUNTING_SEMAPHORE ); - if( pxHandle != NULL ) + if( xHandle != NULL ) { - pxHandle->uxMessagesWaiting = uxInitialCount; + ( ( xQUEUE * ) xHandle )->uxMessagesWaiting = uxInitialCount; traceCREATE_COUNTING_SEMAPHORE(); } @@ -569,18 +544,20 @@ xQueueHandle xReturn = NULL; traceCREATE_COUNTING_SEMAPHORE_FAILED(); } - configASSERT( pxHandle ); - return pxHandle; + configASSERT( xHandle ); + return xHandle; } #endif /* configUSE_COUNTING_SEMAPHORES */ /*-----------------------------------------------------------*/ -signed portBASE_TYPE xQueueGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition ) +signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition ) { signed portBASE_TYPE xEntryTimeSet = pdFALSE; xTimeOutType xTimeOut; +xQUEUE *pxQueue; + pxQueue = ( xQUEUE * ) xQueue; configASSERT( pxQueue ); configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) ); @@ -598,19 +575,52 @@ xTimeOutType xTimeOut; traceQUEUE_SEND( pxQueue ); prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition ); - /* If there was a task waiting for data to arrive on the - queue then unblock it now. */ - if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + #if ( configUSE_QUEUE_SETS == 1 ) { - if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) == pdTRUE ) + if( pxQueue->pxQueueSetContainer != NULL ) { - /* The unblocked task has a priority higher than - our own so yield immediately. Yes it is ok to do - this from within the critical section - the kernel - takes care of that. */ - portYIELD_WITHIN_API(); + if( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) == pdTRUE ) + { + /* The queue is a member of a queue set, and posting + to the queue set caused a higher priority task to + unblock. A context switch is required. */ + portYIELD_WITHIN_API(); + } + } + else + { + /* If there was a task waiting for data to arrive on the + queue then unblock it now. */ + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) == pdTRUE ) + { + /* The unblocked task has a priority higher than + our own so yield immediately. Yes it is ok to + do this from within the critical section - the + kernel takes care of that. */ + portYIELD_WITHIN_API(); + } + } + } + } + #else /* configUSE_QUEUE_SETS */ + { + /* If there was a task waiting for data to arrive on the + queue then unblock it now. */ + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) == pdTRUE ) + { + /* The unblocked task has a priority higher than + our own so yield immediately. Yes it is ok to do + this from within the critical section - the kernel + takes care of that. */ + portYIELD_WITHIN_API(); + } } } + #endif /* configUSE_QUEUE_SETS */ taskEXIT_CRITICAL(); @@ -695,13 +705,15 @@ xTimeOutType xTimeOut; } /*-----------------------------------------------------------*/ -#if configUSE_ALTERNATIVE_API == 1 +#if ( configUSE_ALTERNATIVE_API == 1 ) - signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition ) + signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition ) { signed portBASE_TYPE xEntryTimeSet = pdFALSE; xTimeOutType xTimeOut; + xQUEUE *pxQueue; + pxQueue = ( xQUEUE * ) xQueue; configASSERT( pxQueue ); configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) ); @@ -772,14 +784,16 @@ xTimeOutType xTimeOut; #endif /* configUSE_ALTERNATIVE_API */ /*-----------------------------------------------------------*/ -#if configUSE_ALTERNATIVE_API == 1 +#if ( configUSE_ALTERNATIVE_API == 1 ) - signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking ) + signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking ) { signed portBASE_TYPE xEntryTimeSet = pdFALSE; xTimeOutType xTimeOut; signed char *pcOriginalReadPosition; + xQUEUE *pxQueue; + pxQueue = ( xQUEUE * ) xQueue; configASSERT( pxQueue ); configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) ); @@ -903,11 +917,13 @@ xTimeOutType xTimeOut; #endif /* configUSE_ALTERNATIVE_API */ /*-----------------------------------------------------------*/ -signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition ) +signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle xQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition ) { signed portBASE_TYPE xReturn; unsigned portBASE_TYPE uxSavedInterruptStatus; +xQUEUE *pxQueue; + pxQueue = ( xQUEUE * ) xQueue; configASSERT( pxQueue ); configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) ); @@ -928,18 +944,53 @@ unsigned portBASE_TYPE uxSavedInterruptStatus; be done when the queue is unlocked later. */ if( pxQueue->xTxLock == queueUNLOCKED ) { - if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + #if ( configUSE_QUEUE_SETS == 1 ) { - if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + if( pxQueue->pxQueueSetContainer != NULL ) { - /* The task waiting has a higher priority so record that a - context switch is required. */ - if( pxHigherPriorityTaskWoken != NULL ) + if( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) == pdTRUE ) { - *pxHigherPriorityTaskWoken = pdTRUE; + /* The queue is a member of a queue set, and posting + to the queue set caused a higher priority task to + unblock. A context switch is required. */ + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } + } + } + else + { + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The task waiting has a higher priority so record that a + context switch is required. */ + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } + } } } } + #else /* configUSE_QUEUE_SETS */ + { + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The task waiting has a higher priority so record that a + context switch is required. */ + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } + } + } + } + #endif /* configUSE_QUEUE_SETS */ } else { @@ -962,12 +1013,14 @@ unsigned portBASE_TYPE uxSavedInterruptStatus; } /*-----------------------------------------------------------*/ -signed portBASE_TYPE xQueueGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking ) +signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking ) { signed portBASE_TYPE xEntryTimeSet = pdFALSE; xTimeOutType xTimeOut; signed char *pcOriginalReadPosition; +xQUEUE *pxQueue; + pxQueue = ( xQUEUE * ) xQueue; configASSERT( pxQueue ); configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) ); @@ -1018,7 +1071,7 @@ signed char *pcOriginalReadPosition; { traceQUEUE_PEEK( pxQueue ); - /* We are not removing the data, so reset our read + /* The data is not being removed, so reset the read pointer. */ pxQueue->pcReadFrom = pcOriginalReadPosition; @@ -1111,11 +1164,13 @@ signed char *pcOriginalReadPosition; } /*-----------------------------------------------------------*/ -signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken ) +signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle xQueue, void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken ) { signed portBASE_TYPE xReturn; unsigned portBASE_TYPE uxSavedInterruptStatus; +xQUEUE *pxQueue; + pxQueue = ( xQUEUE * ) xQueue; configASSERT( pxQueue ); configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) ); @@ -1168,38 +1223,45 @@ unsigned portBASE_TYPE uxSavedInterruptStatus; } /*-----------------------------------------------------------*/ -unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle pxQueue ) +unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue ) { unsigned portBASE_TYPE uxReturn; - configASSERT( pxQueue ); + configASSERT( xQueue ); taskENTER_CRITICAL(); - uxReturn = pxQueue->uxMessagesWaiting; + uxReturn = ( ( xQUEUE * ) xQueue )->uxMessagesWaiting; taskEXIT_CRITICAL(); return uxReturn; } /*-----------------------------------------------------------*/ -unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue ) +unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle xQueue ) { unsigned portBASE_TYPE uxReturn; - configASSERT( pxQueue ); + configASSERT( xQueue ); - uxReturn = pxQueue->uxMessagesWaiting; + uxReturn = ( ( xQUEUE * ) xQueue )->uxMessagesWaiting; return uxReturn; } /*-----------------------------------------------------------*/ -void vQueueDelete( xQueueHandle pxQueue ) +void vQueueDelete( xQueueHandle xQueue ) { +xQUEUE *pxQueue; + + pxQueue = ( xQUEUE * ) xQueue; configASSERT( pxQueue ); traceQUEUE_DELETE( pxQueue ); - vQueueUnregisterQueue( pxQueue ); + #if ( configQUEUE_REGISTRY_SIZE > 0 ) + { + prvQueueUnregisterQueue( pxQueue ); + } + #endif vPortFree( pxQueue->pcHead ); vPortFree( pxQueue ); } @@ -1207,32 +1269,32 @@ void vQueueDelete( xQueueHandle pxQueue ) #if ( configUSE_TRACE_FACILITY == 1 ) - unsigned char ucQueueGetQueueNumber( xQueueHandle pxQueue ) + unsigned char ucQueueGetQueueNumber( xQueueHandle xQueue ) { - return pxQueue->ucQueueNumber; + return ( ( xQUEUE * ) xQueue )->ucQueueNumber; } -#endif +#endif /* configUSE_TRACE_FACILITY */ /*-----------------------------------------------------------*/ #if ( configUSE_TRACE_FACILITY == 1 ) - void vQueueSetQueueNumber( xQueueHandle pxQueue, unsigned char ucQueueNumber ) + void vQueueSetQueueNumber( xQueueHandle xQueue, unsigned char ucQueueNumber ) { - pxQueue->ucQueueNumber = ucQueueNumber; + ( ( xQUEUE * ) xQueue )->ucQueueNumber = ucQueueNumber; } -#endif +#endif /* configUSE_TRACE_FACILITY */ /*-----------------------------------------------------------*/ #if ( configUSE_TRACE_FACILITY == 1 ) - unsigned char ucQueueGetQueueType( xQueueHandle pxQueue ) + unsigned char ucQueueGetQueueType( xQueueHandle xQueue ) { - return pxQueue->ucQueueType; + return ( ( xQUEUE * ) xQueue )->ucQueueType; } -#endif +#endif /* configUSE_TRACE_FACILITY */ /*-----------------------------------------------------------*/ static void prvCopyDataToQueue( xQUEUE *pxQueue, const void *pvItemToQueue, portBASE_TYPE xPosition ) @@ -1287,7 +1349,7 @@ static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void *pvBuffer ) } /*-----------------------------------------------------------*/ -static void prvUnlockQueue( xQueueHandle pxQueue ) +static void prvUnlockQueue( xQUEUE *pxQueue ) { /* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. */ @@ -1302,23 +1364,58 @@ static void prvUnlockQueue( xQueueHandle pxQueue ) { /* Data was posted while the queue was locked. Are any tasks blocked waiting for data to become available? */ - if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + #if ( configUSE_QUEUE_SETS == 1 ) { - /* Tasks that are removed from the event list will get added to - the pending ready list as the scheduler is still suspended. */ - if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + if( pxQueue->pxQueueSetContainer != NULL ) { - /* The task waiting has a higher priority so record that a - context switch is required. */ - vTaskMissedYield(); + if( prvNotifyQueueSetContainer( pxQueue, queueSEND_TO_BACK ) == pdTRUE ) + { + /* The queue is a member of a queue set, and posting to + the queue set caused a higher priority task to unblock. + A context switch is required. */ + vTaskMissedYield(); + } + } + else + { + /* Tasks that are removed from the event list will get added to + the pending ready list as the scheduler is still suspended. */ + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The task waiting has a higher priority so record that a + context switch is required. */ + vTaskMissedYield(); + } + } + else + { + break; + } } - - --( pxQueue->xTxLock ); } - else + #else /* configUSE_QUEUE_SETS */ { - break; + /* Tasks that are removed from the event list will get added to + the pending ready list as the scheduler is still suspended. */ + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The task waiting has a higher priority so record that a + context switch is required. */ + vTaskMissedYield(); + } + } + else + { + break; + } } + #endif /* configUSE_QUEUE_SETS */ + + --( pxQueue->xTxLock ); } pxQueue->xTxLock = queueUNLOCKED; @@ -1351,265 +1448,312 @@ static void prvUnlockQueue( xQueueHandle pxQueue ) } /*-----------------------------------------------------------*/ -static signed portBASE_TYPE prvIsQueueEmpty( const xQueueHandle pxQueue ) +static signed portBASE_TYPE prvIsQueueEmpty( const xQUEUE *pxQueue ) { signed portBASE_TYPE xReturn; taskENTER_CRITICAL(); - xReturn = ( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 ); + { + if( pxQueue->uxMessagesWaiting == 0 ) + { + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + } taskEXIT_CRITICAL(); return xReturn; } /*-----------------------------------------------------------*/ -signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue ) +signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle xQueue ) { signed portBASE_TYPE xReturn; - configASSERT( pxQueue ); - xReturn = ( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 ); + configASSERT( xQueue ); + if( ( ( xQUEUE * ) xQueue )->uxMessagesWaiting == 0 ) + { + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } return xReturn; } /*-----------------------------------------------------------*/ -static signed portBASE_TYPE prvIsQueueFull( const xQueueHandle pxQueue ) +static signed portBASE_TYPE prvIsQueueFull( const xQUEUE *pxQueue ) { signed portBASE_TYPE xReturn; taskENTER_CRITICAL(); - xReturn = ( pxQueue->uxMessagesWaiting == pxQueue->uxLength ); + { + if( pxQueue->uxMessagesWaiting == pxQueue->uxLength ) + { + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + } taskEXIT_CRITICAL(); return xReturn; } /*-----------------------------------------------------------*/ -signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue ) +signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle xQueue ) { signed portBASE_TYPE xReturn; - configASSERT( pxQueue ); - xReturn = ( pxQueue->uxMessagesWaiting == pxQueue->uxLength ); + configASSERT( xQueue ); + if( ( ( xQUEUE * ) xQueue )->uxMessagesWaiting == ( ( xQUEUE * ) xQueue )->uxLength ) + { + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } return xReturn; } /*-----------------------------------------------------------*/ -#if configUSE_CO_ROUTINES == 1 -signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait ) -{ -signed portBASE_TYPE xReturn; +#if ( configUSE_CO_ROUTINES == 1 ) - /* If the queue is already full we may have to block. A critical section - is required to prevent an interrupt removing something from the queue - between the check to see if the queue is full and blocking on the queue. */ - portDISABLE_INTERRUPTS(); + signed portBASE_TYPE xQueueCRSend( xQueueHandle xQueue, const void *pvItemToQueue, portTickType xTicksToWait ) { - if( prvIsQueueFull( pxQueue ) != pdFALSE ) + signed portBASE_TYPE xReturn; + xQUEUE *pxQueue; + + pxQueue = ( xQUEUE * ) xQueue; + + /* If the queue is already full we may have to block. A critical section + is required to prevent an interrupt removing something from the queue + between the check to see if the queue is full and blocking on the queue. */ + portDISABLE_INTERRUPTS(); { - /* The queue is full - do we want to block or just leave without - posting? */ - if( xTicksToWait > ( portTickType ) 0 ) - { - /* As this is called from a coroutine we cannot block directly, but - return indicating that we need to block. */ - vCoRoutineAddToDelayedList( xTicksToWait, &( pxQueue->xTasksWaitingToSend ) ); - portENABLE_INTERRUPTS(); - return errQUEUE_BLOCKED; - } - else + if( prvIsQueueFull( pxQueue ) != pdFALSE ) { - portENABLE_INTERRUPTS(); - return errQUEUE_FULL; + /* The queue is full - do we want to block or just leave without + posting? */ + if( xTicksToWait > ( portTickType ) 0 ) + { + /* As this is called from a coroutine we cannot block directly, but + return indicating that we need to block. */ + vCoRoutineAddToDelayedList( xTicksToWait, &( pxQueue->xTasksWaitingToSend ) ); + portENABLE_INTERRUPTS(); + return errQUEUE_BLOCKED; + } + else + { + portENABLE_INTERRUPTS(); + return errQUEUE_FULL; + } } } - } - portENABLE_INTERRUPTS(); - - portNOP(); + portENABLE_INTERRUPTS(); - portDISABLE_INTERRUPTS(); - { - if( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) + portDISABLE_INTERRUPTS(); { - /* There is room in the queue, copy the data into the queue. */ - prvCopyDataToQueue( pxQueue, pvItemToQueue, queueSEND_TO_BACK ); - xReturn = pdPASS; - - /* Were any co-routines waiting for data to become available? */ - if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + if( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) { - /* In this instance the co-routine could be placed directly - into the ready list as we are within a critical section. - Instead the same pending ready list mechanism is used as if - the event were caused from within an interrupt. */ - if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + /* There is room in the queue, copy the data into the queue. */ + prvCopyDataToQueue( pxQueue, pvItemToQueue, queueSEND_TO_BACK ); + xReturn = pdPASS; + + /* Were any co-routines waiting for data to become available? */ + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) { - /* The co-routine waiting has a higher priority so record - that a yield might be appropriate. */ - xReturn = errQUEUE_YIELD; + /* In this instance the co-routine could be placed directly + into the ready list as we are within a critical section. + Instead the same pending ready list mechanism is used as if + the event were caused from within an interrupt. */ + if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The co-routine waiting has a higher priority so record + that a yield might be appropriate. */ + xReturn = errQUEUE_YIELD; + } } } + else + { + xReturn = errQUEUE_FULL; + } } - else - { - xReturn = errQUEUE_FULL; - } + portENABLE_INTERRUPTS(); + + return xReturn; } - portENABLE_INTERRUPTS(); - return xReturn; -} -#endif +#endif /* configUSE_CO_ROUTINES */ /*-----------------------------------------------------------*/ -#if configUSE_CO_ROUTINES == 1 -signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait ) -{ -signed portBASE_TYPE xReturn; +#if ( configUSE_CO_ROUTINES == 1 ) - /* If the queue is already empty we may have to block. A critical section - is required to prevent an interrupt adding something to the queue - between the check to see if the queue is empty and blocking on the queue. */ - portDISABLE_INTERRUPTS(); + signed portBASE_TYPE xQueueCRReceive( xQueueHandle xQueue, void *pvBuffer, portTickType xTicksToWait ) { - if( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 ) + signed portBASE_TYPE xReturn; + xQUEUE *pxQueue; + + pxQueue = ( xQUEUE * ) xQueue; + + /* If the queue is already empty we may have to block. A critical section + is required to prevent an interrupt adding something to the queue + between the check to see if the queue is empty and blocking on the queue. */ + portDISABLE_INTERRUPTS(); { - /* There are no messages in the queue, do we want to block or just - leave with nothing? */ - if( xTicksToWait > ( portTickType ) 0 ) - { - /* As this is a co-routine we cannot block directly, but return - indicating that we need to block. */ - vCoRoutineAddToDelayedList( xTicksToWait, &( pxQueue->xTasksWaitingToReceive ) ); - portENABLE_INTERRUPTS(); - return errQUEUE_BLOCKED; - } - else + if( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 ) { - portENABLE_INTERRUPTS(); - return errQUEUE_FULL; + /* There are no messages in the queue, do we want to block or just + leave with nothing? */ + if( xTicksToWait > ( portTickType ) 0 ) + { + /* As this is a co-routine we cannot block directly, but return + indicating that we need to block. */ + vCoRoutineAddToDelayedList( xTicksToWait, &( pxQueue->xTasksWaitingToReceive ) ); + portENABLE_INTERRUPTS(); + return errQUEUE_BLOCKED; + } + else + { + portENABLE_INTERRUPTS(); + return errQUEUE_FULL; + } } } - } - portENABLE_INTERRUPTS(); - - portNOP(); + portENABLE_INTERRUPTS(); - portDISABLE_INTERRUPTS(); - { - if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 ) + portDISABLE_INTERRUPTS(); { - /* Data is available from the queue. */ - pxQueue->pcReadFrom += pxQueue->uxItemSize; - if( pxQueue->pcReadFrom >= pxQueue->pcTail ) + if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 ) { - pxQueue->pcReadFrom = pxQueue->pcHead; - } - --( pxQueue->uxMessagesWaiting ); - memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->pcReadFrom, ( unsigned ) pxQueue->uxItemSize ); + /* Data is available from the queue. */ + pxQueue->pcReadFrom += pxQueue->uxItemSize; + if( pxQueue->pcReadFrom >= pxQueue->pcTail ) + { + pxQueue->pcReadFrom = pxQueue->pcHead; + } + --( pxQueue->uxMessagesWaiting ); + memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->pcReadFrom, ( unsigned ) pxQueue->uxItemSize ); - xReturn = pdPASS; + xReturn = pdPASS; - /* Were any co-routines waiting for space to become available? */ - if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE ) - { - /* In this instance the co-routine could be placed directly - into the ready list as we are within a critical section. - Instead the same pending ready list mechanism is used as if - the event were caused from within an interrupt. */ - if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE ) + /* Were any co-routines waiting for space to become available? */ + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE ) { - xReturn = errQUEUE_YIELD; + /* In this instance the co-routine could be placed directly + into the ready list as we are within a critical section. + Instead the same pending ready list mechanism is used as if + the event were caused from within an interrupt. */ + if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE ) + { + xReturn = errQUEUE_YIELD; + } } } + else + { + xReturn = pdFAIL; + } } - else - { - xReturn = pdFAIL; - } + portENABLE_INTERRUPTS(); + + return xReturn; } - portENABLE_INTERRUPTS(); - return xReturn; -} -#endif +#endif /* configUSE_CO_ROUTINES */ /*-----------------------------------------------------------*/ +#if ( configUSE_CO_ROUTINES == 1 ) - -#if configUSE_CO_ROUTINES == 1 -signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken ) -{ - /* Cannot block within an ISR so if there is no space on the queue then - exit without doing anything. */ - if( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) + signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle xQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken ) { - prvCopyDataToQueue( pxQueue, pvItemToQueue, queueSEND_TO_BACK ); + xQUEUE *pxQueue; + + pxQueue = ( xQUEUE * ) xQueue; - /* We only want to wake one co-routine per ISR, so check that a - co-routine has not already been woken. */ - if( xCoRoutinePreviouslyWoken == pdFALSE ) + /* Cannot block within an ISR so if there is no space on the queue then + exit without doing anything. */ + if( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) { - if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + prvCopyDataToQueue( pxQueue, pvItemToQueue, queueSEND_TO_BACK ); + + /* We only want to wake one co-routine per ISR, so check that a + co-routine has not already been woken. */ + if( xCoRoutinePreviouslyWoken == pdFALSE ) { - if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) { - return pdTRUE; + if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + return pdTRUE; + } } } } + + return xCoRoutinePreviouslyWoken; } - return xCoRoutinePreviouslyWoken; -} -#endif +#endif /* configUSE_CO_ROUTINES */ /*-----------------------------------------------------------*/ -#if configUSE_CO_ROUTINES == 1 -signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxCoRoutineWoken ) -{ -signed portBASE_TYPE xReturn; +#if ( configUSE_CO_ROUTINES == 1 ) - /* We cannot block from an ISR, so check there is data available. If - not then just leave without doing anything. */ - if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 ) + signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle xQueue, void *pvBuffer, signed portBASE_TYPE *pxCoRoutineWoken ) { - /* Copy the data from the queue. */ - pxQueue->pcReadFrom += pxQueue->uxItemSize; - if( pxQueue->pcReadFrom >= pxQueue->pcTail ) - { - pxQueue->pcReadFrom = pxQueue->pcHead; - } - --( pxQueue->uxMessagesWaiting ); - memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->pcReadFrom, ( unsigned ) pxQueue->uxItemSize ); + signed portBASE_TYPE xReturn; + xQUEUE * pxQueue; - if( ( *pxCoRoutineWoken ) == pdFALSE ) + pxQueue = ( xQUEUE * ) xQueue; + + /* We cannot block from an ISR, so check there is data available. If + not then just leave without doing anything. */ + if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 ) { - if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE ) + /* Copy the data from the queue. */ + pxQueue->pcReadFrom += pxQueue->uxItemSize; + if( pxQueue->pcReadFrom >= pxQueue->pcTail ) + { + pxQueue->pcReadFrom = pxQueue->pcHead; + } + --( pxQueue->uxMessagesWaiting ); + memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->pcReadFrom, ( unsigned ) pxQueue->uxItemSize ); + + if( ( *pxCoRoutineWoken ) == pdFALSE ) { - if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE ) + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE ) { - *pxCoRoutineWoken = pdTRUE; + if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE ) + { + *pxCoRoutineWoken = pdTRUE; + } } } + + xReturn = pdPASS; + } + else + { + xReturn = pdFAIL; } - xReturn = pdPASS; - } - else - { - xReturn = pdFAIL; + return xReturn; } - return xReturn; -} -#endif +#endif /* configUSE_CO_ROUTINES */ /*-----------------------------------------------------------*/ -#if configQUEUE_REGISTRY_SIZE > 0 +#if ( configQUEUE_REGISTRY_SIZE > 0 ) void vQueueAddToRegistry( xQueueHandle xQueue, signed char *pcQueueName ) { @@ -1629,12 +1773,12 @@ signed portBASE_TYPE xReturn; } } -#endif +#endif /* configQUEUE_REGISTRY_SIZE */ /*-----------------------------------------------------------*/ -#if configQUEUE_REGISTRY_SIZE > 0 +#if ( configQUEUE_REGISTRY_SIZE > 0 ) - static void vQueueUnregisterQueue( xQueueHandle xQueue ) + static void prvQueueUnregisterQueue( xQueueHandle xQueue ) { unsigned portBASE_TYPE ux; @@ -1652,13 +1796,17 @@ signed portBASE_TYPE xReturn; } -#endif +#endif /* configQUEUE_REGISTRY_SIZE */ /*-----------------------------------------------------------*/ -#if configUSE_TIMERS == 1 +#if ( configUSE_TIMERS == 1 ) - void vQueueWaitForMessageRestricted( xQueueHandle pxQueue, portTickType xTicksToWait ) + void vQueueWaitForMessageRestricted( xQueueHandle xQueue, portTickType xTicksToWait ) { + xQUEUE *pxQueue; + + pxQueue = ( xQUEUE * ) xQueue; + /* This function should not be called by application code hence the 'Restricted' in its name. It is not part of the public API. It is designed for use by kernel code, and has special calling requirements. @@ -1682,5 +1830,140 @@ signed portBASE_TYPE xReturn; prvUnlockQueue( pxQueue ); } -#endif +#endif /* configUSE_TIMERS */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_QUEUE_SETS == 1 ) + + xQueueSetHandle xQueueCreateSet( unsigned portBASE_TYPE uxEventQueueLength ) + { + xQueueSetHandle pxQueue; + + pxQueue = xQueueGenericCreate( uxEventQueueLength, sizeof( xQUEUE * ), queueQUEUE_TYPE_SET ); + + return pxQueue; + } + +#endif /* configUSE_QUEUE_SETS */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_QUEUE_SETS == 1 ) + + portBASE_TYPE xQueueAddToSet( xQueueSetMemberHandle xQueueOrSemaphore, xQueueSetHandle xQueueSet ) + { + portBASE_TYPE xReturn; + + if( ( ( xQUEUE * ) xQueueOrSemaphore )->pxQueueSetContainer != NULL ) + { + xReturn = pdFAIL; + } + else + { + taskENTER_CRITICAL(); + { + ( ( xQUEUE * ) xQueueOrSemaphore )->pxQueueSetContainer = xQueueSet; + } + taskEXIT_CRITICAL(); + xReturn = pdPASS; + } + + return xReturn; + } + +#endif /* configUSE_QUEUE_SETS */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_QUEUE_SETS == 1 ) + + portBASE_TYPE xQueueRemoveFromSet( xQueueSetMemberHandle xQueueOrSemaphore, xQueueSetHandle xQueueSet ) + { + portBASE_TYPE xReturn; + xQUEUE *pxQueueOrSemaphore; + + pxQueueOrSemaphore = ( xQUEUE * ) xQueueOrSemaphore; + + if( pxQueueOrSemaphore->pxQueueSetContainer != xQueueSet ) + { + /* The queue was not a member of the set. */ + xReturn = pdFAIL; + } + else if( pxQueueOrSemaphore->uxMessagesWaiting != 0 ) + { + /* It is dangerous to remove a queue from a set when the queue is + not empty because the queue set will still hold pending events for + the queue. */ + xReturn = pdFAIL; + } + else + { + taskENTER_CRITICAL(); + { + /* The queue is no longer contained in the set. */ + pxQueueOrSemaphore->pxQueueSetContainer = NULL; + } + taskEXIT_CRITICAL(); + xReturn = pdPASS; + } + + return xReturn; + } + +#endif /* configUSE_QUEUE_SETS */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_QUEUE_SETS == 1 ) + + xQueueSetMemberHandle xQueueSelectFromSet( xQueueSetHandle xQueueSet, portTickType xBlockTimeTicks ) + { + xQueueSetMemberHandle xReturn = NULL; + + xQueueGenericReceive( ( xQueueHandle ) xQueueSet, &xReturn, xBlockTimeTicks, pdFALSE ); + return xReturn; + } + +#endif /* configUSE_QUEUE_SETS */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_QUEUE_SETS == 1 ) + + xQueueSetMemberHandle xQueueSelectFromSetFromISR( xQueueSetHandle xQueueSet ) + { + xQueueSetMemberHandle xReturn = NULL; + + xQueueReceiveFromISR( ( xQueueHandle ) xQueueSet, &xReturn, NULL ); + return xReturn; + } + +#endif /* configUSE_QUEUE_SETS */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_QUEUE_SETS == 1 ) + + static portBASE_TYPE prvNotifyQueueSetContainer( xQUEUE *pxQueue, portBASE_TYPE xCopyPosition ) + { + xQUEUE *pxQueueSetContainer = pxQueue->pxQueueSetContainer; + portBASE_TYPE xReturn = pdFALSE; + + configASSERT( pxQueueSetContainer ); + configASSERT( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength ); + + if( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength ) + { + traceQUEUE_SEND( pxQueueSetContainer ); + /* The data copies is the handle of the queue that contains data. */ + prvCopyDataToQueue( pxQueueSetContainer, &pxQueue, xCopyPosition ); + if( listLIST_IS_EMPTY( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The task waiting has a higher priority */ + xReturn = pdTRUE; + } + } + } + + return xReturn; + } + +#endif /* configUSE_QUEUE_SETS */ diff --git a/arduino.DuinOS.AVR/DuinOS/queue.h b/arduino.DuinOS.AVR/DuinOS/queue.h index 40562cf..bb4a0ff 100644 --- a/arduino.DuinOS.AVR/DuinOS/queue.h +++ b/arduino.DuinOS.AVR/DuinOS/queue.h @@ -1,7 +1,7 @@ /* - FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd. - FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** @@ -29,20 +29,23 @@ FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - >>>NOTE<<< The modification to the GPL is included to allow you to + + >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS - kernel. FreeRTOS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. You should have received a copy of the GNU General Public - License and the FreeRTOS license exception along with FreeRTOS; if not it - can be viewed here: http://www.freertos.org/a00114.html and also obtained - by writing to Richard Barry, contact details for whom are available on the - FreeRTOS WEB site. + kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License + and the FreeRTOS license exception along with FreeRTOS; if not itcan be + viewed here: http://www.freertos.org/a00114.html and also obtained by + writing to Real Time Engineers Ltd., contact details for whom are available + on the FreeRTOS WEB site. 1 tab == 4 spaces! - + *************************************************************************** * * * Having a problem? Start by reading the FAQ "My application does * @@ -52,18 +55,21 @@ * * *************************************************************************** - - http://www.FreeRTOS.org - Documentation, training, latest versions, license - and contact details. - + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool. + including FreeRTOS+Trace - an indispensable productivity tool, and our new + fully thread aware and reentrant UDP/IP stack. - Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell - the code with commercial support, indemnification, and middleware, under - the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also - provide a safety engineered and independently SIL3 certified version under - the SafeRTOS brand: http://www.SafeRTOS.com. + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems, who sell the code with commercial support, + indemnification and middleware, under the OpenRTOS brand. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. */ @@ -82,12 +88,25 @@ extern "C" { #include "mpu_wrappers.h" /** - * Type by which queues are referenced. For example, a call to xQueueCreate - * returns (via a pointer parameter) an xQueueHandle variable that can then - * be used as a parameter to xQueueSend(), xQueueReceive(), etc. + * Type by which queues are referenced. For example, a call to xQueueCreate() + * returns an xQueueHandle variable that can then be used as a parameter to + * xQueueSend(), xQueueReceive(), etc. */ typedef void * xQueueHandle; +/** + * Type by which queue sets are referenced. For example, a call to + * xQueueCreateSet() returns an xQueueSet variable that can then be used as a + * parameter to xQueueSelectFromSet(), xQueueAddToSet(), etc. + */ +typedef void * xQueueSetHandle; + +/** + * Queue sets can contain both queues and semaphores, so the + * xQueueSetMemberHandle is defined as a type to be used where a parameter or + * return value can be either an xQueueHandle or an xSemaphoreHandle. + */ +typedef void * xQueueSetMemberHandle; /* For internal use only. */ #define queueSEND_TO_BACK ( 0 ) @@ -95,6 +114,7 @@ typedef void * xQueueHandle; /* For internal use only. These definitions *must* match those in queue.c. */ #define queueQUEUE_TYPE_BASE ( 0U ) +#define queueQUEUE_TYPE_SET ( 0U ) #define queueQUEUE_TYPE_MUTEX ( 1U ) #define queueQUEUE_TYPE_COUNTING_SEMAPHORE ( 2U ) #define queueQUEUE_TYPE_BINARY_SEMAPHORE ( 3U ) @@ -492,7 +512,7 @@ typedef void * xQueueHandle; * \defgroup xQueueSend xQueueSend * \ingroup QueueManagement */ -signed portBASE_TYPE xQueueGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition ); +signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition ); /** * queue. h @@ -515,7 +535,7 @@ signed portBASE_TYPE xQueueGenericSend( xQueueHandle pxQueue, const void * const * * This macro must not be used in an interrupt service routine. * - * @param pxQueue The handle to the queue from which the item is to be + * @param xQueue The handle to the queue from which the item is to be * received. * * @param pvBuffer Pointer to the buffer into which the received item will @@ -608,7 +628,7 @@ signed portBASE_TYPE xQueueGenericSend( xQueueHandle pxQueue, const void * const * This function must not be used in an interrupt service routine. See * xQueueReceiveFromISR for an alternative that can. * - * @param pxQueue The handle to the queue from which the item is to be + * @param xQueue The handle to the queue from which the item is to be * received. * * @param pvBuffer Pointer to the buffer into which the received item will @@ -702,7 +722,7 @@ signed portBASE_TYPE xQueueGenericSend( xQueueHandle pxQueue, const void * const * This function must not be used in an interrupt service routine. See * xQueueReceiveFromISR for an alternative that can. * - * @param pxQueue The handle to the queue from which the item is to be + * @param xQueue The handle to the queue from which the item is to be * received. * * @param pvBuffer Pointer to the buffer into which the received item will @@ -807,13 +827,13 @@ unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue ); * \page vQueueDelete vQueueDelete * \ingroup QueueManagement */ -void vQueueDelete( xQueueHandle pxQueue ); +void vQueueDelete( xQueueHandle xQueue ); /** * queue. h *
  portBASE_TYPE xQueueSendToFrontFromISR(
-										 xQueueHandle pxQueue,
+										 xQueueHandle xQueue,
 										 const void *pvItemToQueue,
 										 portBASE_TYPE *pxHigherPriorityTaskWoken
 									  );
@@ -877,14 +897,14 @@ void vQueueDelete( xQueueHandle pxQueue );
  * \defgroup xQueueSendFromISR xQueueSendFromISR
  * \ingroup QueueManagement
  */
-#define xQueueSendToFrontFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( pxQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_FRONT )
+#define xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_FRONT )
 
 
 /**
  * queue. h
  * 
  portBASE_TYPE xQueueSendToBackFromISR(
-										 xQueueHandle pxQueue,
+										 xQueueHandle xQueue,
 										 const void *pvItemToQueue,
 										 portBASE_TYPE *pxHigherPriorityTaskWoken
 									  );
@@ -948,13 +968,13 @@ void vQueueDelete( xQueueHandle pxQueue );
  * \defgroup xQueueSendFromISR xQueueSendFromISR
  * \ingroup QueueManagement
  */
-#define xQueueSendToBackFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( pxQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
+#define xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
 
 /**
  * queue. h
  * 
  portBASE_TYPE xQueueSendFromISR(
-									 xQueueHandle pxQueue,
+									 xQueueHandle xQueue,
 									 const void *pvItemToQueue,
 									 portBASE_TYPE *pxHigherPriorityTaskWoken
 								);
@@ -1022,13 +1042,13 @@ void vQueueDelete( xQueueHandle pxQueue );
  * \defgroup xQueueSendFromISR xQueueSendFromISR
  * \ingroup QueueManagement
  */
-#define xQueueSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( pxQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
+#define xQueueSendFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
 
 /**
  * queue. h
  * 
  portBASE_TYPE xQueueGenericSendFromISR(
-										   xQueueHandle	pxQueue,
+										   xQueueHandle		xQueue,
 										   const	void	*pvItemToQueue,
 										   portBASE_TYPE	*pxHigherPriorityTaskWoken,
 										   portBASE_TYPE	xCopyPosition
@@ -1100,22 +1120,22 @@ void vQueueDelete( xQueueHandle pxQueue );
  * \defgroup xQueueSendFromISR xQueueSendFromISR
  * \ingroup QueueManagement
  */
-signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition );
+signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle xQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition );
 
 /**
  * queue. h
  * 
  portBASE_TYPE xQueueReceiveFromISR(
-									   xQueueHandle	pxQueue,
+									   xQueueHandle	xQueue,
 									   void	*pvBuffer,
-									   portBASE_TYPE	*pxTaskWoken
+									   portBASE_TYPE *pxTaskWoken
 								   );
  * 
* * Receive an item from a queue. It is safe to use this function from within an * interrupt service routine. * - * @param pxQueue The handle to the queue from which the item is to be + * @param xQueue The handle to the queue from which the item is to be * received. * * @param pvBuffer Pointer to the buffer into which the received item will @@ -1189,15 +1209,15 @@ signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR * \ingroup QueueManagement */ -signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken ); +signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle xQueue, void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken ); /* * Utilities to query queues that are safe to use from an ISR. These utilities * should be used only from witin an ISR, or within a critical section. */ -signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue ); -signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue ); -unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue ); +signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle xQueue ); +signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle xQueue ); +unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle xQueue ); /* @@ -1214,8 +1234,8 @@ unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue * responsiveness to gain execution speed, whereas the fully featured API * sacrifices execution speed to ensure better interrupt responsiveness. */ -signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition ); -signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking ); +signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition ); +signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking ); #define xQueueAltSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT ) #define xQueueAltSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK ) #define xQueueAltReceive( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdFALSE ) @@ -1230,14 +1250,14 @@ signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const * should not be called directly from application code. Instead use the macro * wrappers defined within croutine.h. */ -signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken ); -signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken ); -signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait ); -signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait ); +signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle xQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken ); +signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle xQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken ); +signed portBASE_TYPE xQueueCRSend( xQueueHandle xQueue, const void *pvItemToQueue, portTickType xTicksToWait ); +signed portBASE_TYPE xQueueCRReceive( xQueueHandle xQueue, void *pvBuffer, portTickType xTicksToWait ); /* - * For internal use only. Use xSemaphoreCreateMutex(), - * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling + * For internal use only. Use xSemaphoreCreateMutex(), + * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling * these functions directly. */ xQueueHandle xQueueCreateMutex( unsigned char ucQueueType ); @@ -1248,7 +1268,7 @@ void* xQueueGetMutexHolder( xQueueHandle xSemaphore ); * For internal use only. Use xSemaphoreTakeMutexRecursive() or * xSemaphoreGiveMutexRecursive() instead of calling these functions directly. */ -portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle pxMutex, portTickType xBlockTime ); +portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime ); portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle pxMutex ); /* @@ -1257,7 +1277,7 @@ portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle pxMutex ); * reset because there are tasks blocked on the queue waiting to either * receive from the queue or send to the queue. */ -#define xQueueReset( pxQueue ) xQueueGenericReset( pxQueue, pdFALSE ) +#define xQueueReset( xQueue ) xQueueGenericReset( xQueue, pdFALSE ) /* * The registry is provided as a means for kernel aware debuggers to @@ -1284,14 +1304,150 @@ portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle pxMutex ); #endif /* - * Generic version of the queue creation function, which is in turn called by + * Generic version of the queue creation function, which is in turn called by * any queue, semaphore or mutex creation function or macro. */ xQueueHandle xQueueGenericCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize, unsigned char ucQueueType ); +/* + * Queue sets provide a mechanism to allow a task to block (pend) on a read + * operation from multiple queues or semaphores simultaneously. + * + * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this + * function. + * + * A queue set must be explicitly created using a call to xQueueCreateSet() + * before it can be used. Once created, standard FreeRTOS queues and semaphores + * can be added to the set using calls to xQueueAddToSet(). + * xQueueSelectFromSet() is then used to determine which, if any, of the queues + * or semaphores contained in the set is in a state where a queue read or + * semaphore take operation would be successful. + * + * Note 1: See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html + * for reasons why queue sets are very rarely needed in practice as there are + * simpler methods of blocking on multiple objects. + * + * Note 2: Blocking on a queue set that contains a mutex will not cause the + * mutex holder to inherit the priority of the blocked task. + * + * Note 3: An additional 4 bytes of RAM is required for each space in a every + * queue added to a queue set. Therefore counting semaphores that have a high + * maximum count value should not be added to a queue set. + * + * Note 4: A receive (in the case of a queue) or take (in the case of a + * semaphore) operation must not be performed on a member of a queue set unless + * a call to xQueueSelectFromSet() has first returned a handle to that set member. + * + * @param uxEventQueueLength Queue sets store events that occur on + * the queues and semaphores contained in the set. uxEventQueueLength specifies + * the maximum number of events that can be queued at once. To be absolutely + * certain that events are not lost uxEventQueueLength should be set to the + * total sum of the length of the queues added to the set, where binary + * semaphores and mutexes have a length of 1, and counting semaphores have a + * length set by their maximum count value. Examples: + * + If a queue set is to hold a queue of length 5, another queue of length 12, + * and a binary semaphore, then uxEventQueueLength should be set to + * (5 + 12 + 1), or 18. + * + If a queue set is to hold three binary semaphores then uxEventQueueLength + * should be set to (1 + 1 + 1 ), or 3. + * + If a queue set is to hold a counting semaphore that has a maximum count of + * 5, and a counting semaphore that has a maximum count of 3, then + * uxEventQueueLength should be set to (5 + 3), or 8. + * + * @return If the queue set is created successfully then a handle to the created + * queue set is returned. Otherwise NULL is returned. + */ +xQueueSetHandle xQueueCreateSet( unsigned portBASE_TYPE uxEventQueueLength ); + +/* + * Adds a queue or semaphore to a queue set that was previously created by a + * call to xQueueCreateSet(). + * + * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this + * function. + * + * Note 1: A receive (in the case of a queue) or take (in the case of a + * semaphore) operation must not be performed on a member of a queue set unless + * a call to xQueueSelectFromSet() has first returned a handle to that set member. + * + * @param xQueueOrSemaphore The handle of the queue or semaphore being added to + * the queue set (cast to an xQueueSetMemberHandle type). + * + * @param xQueueSet The handle of the queue set to which the queue or semaphore + * is being added. + * + * @return If the queue or semaphore was successfully added to the queue set + * then pdPASS is returned. If the queue could not be successfully added to the + * queue set because it is already a member of a different queue set then pdFAIL + * is returned. + */ +portBASE_TYPE xQueueAddToSet( xQueueSetMemberHandle xQueueOrSemaphore, xQueueSetHandle xQueueSet ); + +/* + * Removes a queue or semaphore from a queue set. A queue or semaphore can only + * be removed from a set if the queue or semaphore is empty. + * + * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this + * function. + * + * @param xQueueOrSemaphore The handle of the queue or semaphore being removed + * from the queue set (cast to an xQueueSetMemberHandle type). + * + * @param xQueueSet The handle of the queue set in which the queue or semaphore + * is included. + * + * @return If the queue or semaphore was successfully removed from the queue set + * then pdPASS is returned. If the queue was not in the queue set, or the + * queue (or semaphore) was not empty, then pdFAIL is returned. + */ +portBASE_TYPE xQueueRemoveFromSet( xQueueSetMemberHandle xQueueOrSemaphore, xQueueSetHandle xQueueSet ); + +/* + * xQueueSelectFromSet() selects from the members of a queue set a queue or + * semaphore that either contains data (in the case of a queue) or is available + * to take (in the case of a semaphore). xQueueSelectFromSet() effectively + * allows a task to block (pend) on a read operation on all the queues and + * semaphores in a queue set simultaneously. + * + * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this + * function. + * + * Note 1: See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html + * for reasons why queue sets are very rarely needed in practice as there are + * simpler methods of blocking on multiple objects. + * + * Note 2: Blocking on a queue set that contains a mutex will not cause the + * mutex holder to inherit the priority of the blocked task. + * + * Note 3: A receive (in the case of a queue) or take (in the case of a + * semaphore) operation must not be performed on a member of a queue set unless + * a call to xQueueSelectFromSet() has first returned a handle to that set member. + * + * @param xQueueSet The queue set on which the task will (potentially) block. + * + * @param xBlockTimeTicks The maximum time, in ticks, that the calling task will + * remain in the Blocked state (with other tasks executing) to wait for a member + * of the queue set to be ready for a successful queue read or semaphore take + * operation. + * + * @return xQueueSelectFromSet() will return the handle of a queue (cast to + * a xQueueSetMemberHandle type) contained in the queue set that contains data, + * or the handle of a semaphore (cast to a xQueueSetMemberHandle type) contained + * in the queue set that is available, or NULL if no such queue or semaphore + * exists before before the specified block time expires. + */ +xQueueSetMemberHandle xQueueSelectFromSet( xQueueSetHandle xQueueSet, portTickType xBlockTimeTicks ); + +/* + * A version of xQueueSelectFromSet() that can be used from an ISR. + */ +xQueueSetMemberHandle xQueueSelectFromSetFromISR( xQueueSetHandle xQueueSet ); + /* Not public API functions. */ -void vQueueWaitForMessageRestricted( xQueueHandle pxQueue, portTickType xTicksToWait ); -portBASE_TYPE xQueueGenericReset( xQueueHandle pxQueue, portBASE_TYPE xNewQueue ); +void vQueueWaitForMessageRestricted( xQueueHandle xQueue, portTickType xTicksToWait ); +portBASE_TYPE xQueueGenericReset( xQueueHandle xQueue, portBASE_TYPE xNewQueue ); +void vQueueSetQueueNumber( xQueueHandle xQueue, unsigned char ucQueueNumber ) PRIVILEGED_FUNCTION; +unsigned char ucQueueGetQueueType( xQueueHandle xQueue ) PRIVILEGED_FUNCTION; #ifdef __cplusplus diff --git a/arduino.DuinOS.AVR/DuinOS/semphr.h b/arduino.DuinOS.AVR/DuinOS/semphr.h index ef2dac2..7ac1ab0 100644 --- a/arduino.DuinOS.AVR/DuinOS/semphr.h +++ b/arduino.DuinOS.AVR/DuinOS/semphr.h @@ -1,7 +1,7 @@ /* - FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd. - FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** @@ -29,20 +29,23 @@ FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - >>>NOTE<<< The modification to the GPL is included to allow you to + + >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS - kernel. FreeRTOS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. You should have received a copy of the GNU General Public - License and the FreeRTOS license exception along with FreeRTOS; if not it - can be viewed here: http://www.freertos.org/a00114.html and also obtained - by writing to Richard Barry, contact details for whom are available on the - FreeRTOS WEB site. + kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License + and the FreeRTOS license exception along with FreeRTOS; if not itcan be + viewed here: http://www.freertos.org/a00114.html and also obtained by + writing to Real Time Engineers Ltd., contact details for whom are available + on the FreeRTOS WEB site. 1 tab == 4 spaces! - + *************************************************************************** * * * Having a problem? Start by reading the FAQ "My application does * @@ -52,18 +55,21 @@ * * *************************************************************************** - - http://www.FreeRTOS.org - Documentation, training, latest versions, license - and contact details. - + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool. + including FreeRTOS+Trace - an indispensable productivity tool, and our new + fully thread aware and reentrant UDP/IP stack. - Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell - the code with commercial support, indemnification, and middleware, under - the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also - provide a safety engineered and independently SIL3 certified version under - the SafeRTOS brand: http://www.SafeRTOS.com. + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems, who sell the code with commercial support, + indemnification and middleware, under the OpenRTOS brand. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. */ #ifndef SEMAPHORE_H diff --git a/arduino.DuinOS.AVR/DuinOS/task.h b/arduino.DuinOS.AVR/DuinOS/task.h index b6a7818..42a57e4 100644 --- a/arduino.DuinOS.AVR/DuinOS/task.h +++ b/arduino.DuinOS.AVR/DuinOS/task.h @@ -1,6 +1,8 @@ /* - FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd. + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** * * @@ -27,42 +29,47 @@ FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - >>>NOTE<<< The modification to the GPL is included to allow you to + + >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS - kernel. FreeRTOS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. You should have received a copy of the GNU General Public - License and the FreeRTOS license exception along with FreeRTOS; if not it - can be viewed here: http://www.freertos.org/a00114.html and also obtained - by writing to Richard Barry, contact details for whom are available on the - FreeRTOS WEB site. + kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License + and the FreeRTOS license exception along with FreeRTOS; if not itcan be + viewed here: http://www.freertos.org/a00114.html and also obtained by + writing to Real Time Engineers Ltd., contact details for whom are available + on the FreeRTOS WEB site. 1 tab == 4 spaces! - *************************************************************************** * * * Having a problem? Start by reading the FAQ "My application does * - * not run, what could be wrong? * - * * - * http://www.FreeRTOS.org/FAQHelp.html * - * * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * *************************************************************************** - - http://www.FreeRTOS.org - Documentation, training, latest information, - license and contact details. - - http://www.FreeRTOS.org/plus - Selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool. - - Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell - the code with commercial support, indemnification, and middleware, under - the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also - provide a safety engineered and independently SIL3 certified version under - the SafeRTOS brand: http://www.SafeRTOS.com. + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool, and our new + fully thread aware and reentrant UDP/IP stack. + + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems, who sell the code with commercial support, + indemnification and middleware, under the OpenRTOS brand. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. */ @@ -84,7 +91,7 @@ extern "C" { * MACROS AND DEFINITIONS *----------------------------------------------------------*/ -#define tskKERNEL_VERSION_NUMBER "V7.3.0" +#define tskKERNEL_VERSION_NUMBER "V7.4.0" /** * task. h @@ -131,7 +138,7 @@ typedef struct xTASK_PARAMTERS xMemoryRegion xRegions[ portNUM_CONFIGURABLE_REGIONS ]; } xTaskParameters; -/* Task states returned by eTaskStateGet. */ +/* Task states returned by eTaskGetState. */ typedef enum { eRunning = 0, /* A task is querying the state of itself, so must be running. */ @@ -141,6 +148,15 @@ typedef enum eDeleted /* The task being queried has been deleted, but its TCB has not yet been freed. */ } eTaskState; +/* Possible return values for eTaskConfirmSleepModeStatus(). */ +typedef enum +{ + eAbortSleep = 0, /* A task has been made ready or a context switch pended since portSUPPORESS_TICKS_AND_SLEEP() was called - abort entering a sleep mode. */ + eStandardSleep, /* Enter a sleep mode that will not last any longer than the expected idle time. */ + eNoTasksWaitingTimeout /* No tasks are waiting for a timeout so it is safe to enter a sleep mode that can only be exited by an external interrupt. */ +} eSleepModeStatus; + + /* * Defines the priority used by the idle task. This must not be modified. * @@ -332,7 +348,7 @@ static const xTaskParameters xCheckTaskParameters = // the task, with appropriate access permissions. Different processors have // different memory alignment requirements - refer to the FreeRTOS documentation // for full information. - { + { // Base address Length Parameters { cReadWriteArray, 32, portMPU_REGION_READ_WRITE }, { cReadOnlyArray, 32, portMPU_REGION_READ_ONLY }, @@ -383,7 +399,7 @@ xTaskHandle xHandle; // ucOneKByte array. The other two of the maximum 3 definable regions are // unused so set to zero. static const xMemoryRegion xAltRegions[ portNUM_CONFIGURABLE_REGIONS ] = -{ +{ // Base address Length Parameters { ucOneKByte, 1024, portMPU_REGION_READ_WRITE }, { 0, 0, 0 }, @@ -399,7 +415,7 @@ void vATask( void *pvParameters ) // for this purpose. NULL is used as the task handle to indicate that this // function should modify the MPU regions of the calling task. vTaskAllocateMPURegions( NULL, xAltRegions ); - + // Now the task can continue its function, but from this point on can only // access its stack and the ucOneKByte array (unless any other statically // defined or shared regions have been declared elsewhere). @@ -412,7 +428,7 @@ void vTaskAllocateMPURegions( xTaskHandle xTask, const xMemoryRegion * const pxR /** * task. h - *
void vTaskDelete( xTaskHandle pxTask );
+ *
void vTaskDelete( xTaskHandle xTask );
* * INCLUDE_vTaskDelete must be defined as 1 for this function to be available. * See the configuration section for more information. @@ -430,7 +446,7 @@ void vTaskAllocateMPURegions( xTaskHandle xTask, const xMemoryRegion * const pxR * See the demo application file death.c for sample code that utilises * vTaskDelete (). * - * @param pxTask The handle of the task to be deleted. Passing NULL will + * @param xTask The handle of the task to be deleted. Passing NULL will * cause the calling task to be deleted. * * Example usage: @@ -449,7 +465,7 @@ void vTaskAllocateMPURegions( xTaskHandle xTask, const xMemoryRegion * const pxR * \defgroup vTaskDelete vTaskDelete * \ingroup Tasks */ -void vTaskDelete( xTaskHandle pxTaskToDelete ) PRIVILEGED_FUNCTION; +void vTaskDelete( xTaskHandle xTaskToDelete ) PRIVILEGED_FUNCTION; /*----------------------------------------------------------- * TASK CONTROL API @@ -566,17 +582,17 @@ void vTaskDelayUntil( portTickType * const pxPreviousWakeTime, portTickType xTim /** * task. h - *
unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask );
+ *
unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle xTask );
* * INCLUDE_xTaskPriorityGet must be defined as 1 for this function to be available. * See the configuration section for more information. * * Obtain the priority of any task. * - * @param pxTask Handle of the task to be queried. Passing a NULL + * @param xTask Handle of the task to be queried. Passing a NULL * handle results in the priority of the calling task being returned. * - * @return The priority of pxTask. + * @return The priority of xTask. * * Example usage:
@@ -609,29 +625,29 @@ void vTaskDelayUntil( portTickType * const pxPreviousWakeTime, portTickType xTim
  * \defgroup uxTaskPriorityGet uxTaskPriorityGet
  * \ingroup TaskCtrl
  */
-unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask ) PRIVILEGED_FUNCTION;
+unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle xTask ) PRIVILEGED_FUNCTION;
 
 /**
  * task. h
- * 
eTaskState eTaskStateGet( xTaskHandle pxTask );
+ *
eTaskState eTaskGetState( xTaskHandle xTask );
* - * INCLUDE_eTaskStateGet must be defined as 1 for this function to be available. + * INCLUDE_eTaskGetState must be defined as 1 for this function to be available. * See the configuration section for more information. * - * Obtain the state of any task. States are encoded by the eTaskState + * Obtain the state of any task. States are encoded by the eTaskState * enumerated type. * - * @param pxTask Handle of the task to be queried. + * @param xTask Handle of the task to be queried. * - * @return The state of pxTask at the time the function was called. Note the + * @return The state of xTask at the time the function was called. Note the * state of the task might change between the function being called, and the * functions return value being tested by the calling task. */ -eTaskState eTaskStateGet( xTaskHandle pxTask ) PRIVILEGED_FUNCTION; +eTaskState eTaskGetState( xTaskHandle xTask ) PRIVILEGED_FUNCTION; /** * task. h - *
void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority );
+ *
void vTaskPrioritySet( xTaskHandle xTask, unsigned portBASE_TYPE uxNewPriority );
* * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available. * See the configuration section for more information. @@ -641,7 +657,7 @@ eTaskState eTaskStateGet( xTaskHandle pxTask ) PRIVILEGED_FUNCTION; * A context switch will occur before the function returns if the priority * being set is higher than the currently executing task. * - * @param pxTask Handle to the task for which the priority is being set. + * @param xTask Handle to the task for which the priority is being set. * Passing a NULL handle results in the priority of the calling task being set. * * @param uxNewPriority The priority to which the task will be set. @@ -669,11 +685,11 @@ eTaskState eTaskStateGet( xTaskHandle pxTask ) PRIVILEGED_FUNCTION; * \defgroup vTaskPrioritySet vTaskPrioritySet * \ingroup TaskCtrl */ -void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority ) PRIVILEGED_FUNCTION; +void vTaskPrioritySet( xTaskHandle xTask, unsigned portBASE_TYPE uxNewPriority ) PRIVILEGED_FUNCTION; /** * task. h - *
void vTaskSuspend( xTaskHandle pxTaskToSuspend );
+ *
void vTaskSuspend( xTaskHandle xTaskToSuspend );
* * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available. * See the configuration section for more information. @@ -685,7 +701,7 @@ void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority * i.e. calling vTaskSuspend () twice on the same task still only requires one * call to vTaskResume () to ready the suspended task. * - * @param pxTaskToSuspend Handle to the task being suspended. Passing a NULL + * @param xTaskToSuspend Handle to the task being suspended. Passing a NULL * handle will cause the calling task to be suspended. * * Example usage: @@ -720,11 +736,11 @@ void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority * \defgroup vTaskSuspend vTaskSuspend * \ingroup TaskCtrl */ -void vTaskSuspend( xTaskHandle pxTaskToSuspend ) PRIVILEGED_FUNCTION; +void vTaskSuspend( xTaskHandle xTaskToSuspend ) PRIVILEGED_FUNCTION; /** * task. h - *
void vTaskResume( xTaskHandle pxTaskToResume );
+ *
void vTaskResume( xTaskHandle xTaskToResume );
* * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available. * See the configuration section for more information. @@ -735,7 +751,7 @@ void vTaskSuspend( xTaskHandle pxTaskToSuspend ) PRIVILEGED_FUNCTION; * will be made available for running again by a single call to * vTaskResume (). * - * @param pxTaskToResume Handle to the task being readied. + * @param xTaskToResume Handle to the task being readied. * * Example usage:
@@ -769,11 +785,11 @@ void vTaskSuspend( xTaskHandle pxTaskToSuspend ) PRIVILEGED_FUNCTION;
  * \defgroup vTaskResume vTaskResume
  * \ingroup TaskCtrl
  */
-void vTaskResume( xTaskHandle pxTaskToResume ) PRIVILEGED_FUNCTION;
+void vTaskResume( xTaskHandle xTaskToResume ) PRIVILEGED_FUNCTION;
 
 /**
  * task. h
- * 
void xTaskResumeFromISR( xTaskHandle pxTaskToResume );
+ *
void xTaskResumeFromISR( xTaskHandle xTaskToResume );
* * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be * available. See the configuration section for more information. @@ -784,12 +800,12 @@ void vTaskResume( xTaskHandle pxTaskToResume ) PRIVILEGED_FUNCTION; * will be made available for running again by a single call to * xTaskResumeFromISR (). * - * @param pxTaskToResume Handle to the task being readied. + * @param xTaskToResume Handle to the task being readied. * * \defgroup vTaskResumeFromISR vTaskResumeFromISR * \ingroup TaskCtrl */ -portBASE_TYPE xTaskResumeFromISR( xTaskHandle pxTaskToResume ) PRIVILEGED_FUNCTION; +portBASE_TYPE xTaskResumeFromISR( xTaskHandle xTaskToResume ) PRIVILEGED_FUNCTION; /*----------------------------------------------------------- * SCHEDULER CONTROL @@ -1174,7 +1190,7 @@ constant. */ portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, void *pvParameter ) PRIVILEGED_FUNCTION; /** - * xTaskGetIdleTaskHandle() is only available if + * xTaskGetIdleTaskHandle() is only available if * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h. * * Simply returns the handle of the idle task. It is not valid to call @@ -1314,7 +1330,7 @@ signed portBASE_TYPE xTaskGenericCreate( pdTASK_CODE pxTaskCode, const signed ch */ unsigned portBASE_TYPE uxTaskGetTaskNumber( xTaskHandle xTask ); -/* +/* * Set the uxTCBNumber of the task referenced by the xTask parameter to * ucHandle. */ @@ -1329,6 +1345,21 @@ void vTaskSetTaskNumber( xTaskHandle xTask, unsigned portBASE_TYPE uxHandle ); */ void vTaskStepTick( portTickType xTicksToJump ); +/* + * Provided for use within portSUPPRESS_TICKS_AND_SLEEP() to allow the port + * specific sleep function to determine if it is ok to proceed with the sleep, + * and if it is ok to proceed, if it is ok to sleep indefinitely. + * + * This function is necessary because portSUPPRESS_TICKS_AND_SLEEP() is only + * called with the scheduler suspended, not from within a critical section. It + * is therefore possible for an interrupt to request a context switch between + * portSUPPRESS_TICKS_AND_SLEEP() and the low power mode actually being + * entered. eTaskConfirmSleepModeStatus() should be called from a short + * critical section between the timer being stopped and the sleep mode being + * entered to ensure it is ok to proceed into the sleep mode. + */ +eSleepModeStatus eTaskConfirmSleepModeStatus( void ); + #ifdef __cplusplus } #endif diff --git a/arduino.DuinOS.AVR/DuinOS/tasks.c b/arduino.DuinOS.AVR/DuinOS/tasks.c index 56fc505..3c6567b 100644 --- a/arduino.DuinOS.AVR/DuinOS/tasks.c +++ b/arduino.DuinOS.AVR/DuinOS/tasks.c @@ -1,5 +1,5 @@ /* - FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd. FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. @@ -29,17 +29,20 @@ FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - >>>NOTE<<< The modification to the GPL is included to allow you to + + >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS - kernel. FreeRTOS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. You should have received a copy of the GNU General Public - License and the FreeRTOS license exception along with FreeRTOS; if not it - can be viewed here: http://www.freertos.org/a00114.html and also obtained - by writing to Richard Barry, contact details for whom are available on the - FreeRTOS WEB site. + kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License + and the FreeRTOS license exception along with FreeRTOS; if not itcan be + viewed here: http://www.freertos.org/a00114.html and also obtained by + writing to Real Time Engineers Ltd., contact details for whom are available + on the FreeRTOS WEB site. 1 tab == 4 spaces! @@ -53,17 +56,20 @@ *************************************************************************** - http://www.FreeRTOS.org - Documentation, training, latest versions, license - and contact details. + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool. - - Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell - the code with commercial support, indemnification, and middleware, under - the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also - provide a safety engineered and independently SIL3 certified version under - the SafeRTOS brand: http://www.SafeRTOS.com. + including FreeRTOS+Trace - an indispensable productivity tool, and our new + fully thread aware and reentrant UDP/IP stack. + + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems, who sell the code with commercial support, + indemnification and middleware, under the OpenRTOS brand. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. */ /* Standard includes. */ @@ -84,6 +90,13 @@ task.h is included from an application file. */ #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE +/* Sanity check the configuration. */ +#if configUSE_TICKLESS_IDLE != 0 + #if INCLUDE_vTaskSuspend != 1 + #error INCLUDE_vTaskSuspend must be set to 1 if configUSE_TICKLESS_IDLE is not set to 0 + #endif /* INCLUDE_vTaskSuspend */ +#endif /* configUSE_TICKLESS_IDLE */ + /* * Defines the size, in words, of the stack allocated to the idle task. */ @@ -214,7 +227,7 @@ PRIVILEGED_DATA static volatile portTickType xNextTaskUnblockTime = ( portTic /*-----------------------------------------------------------*/ -#if configUSE_PORT_OPTIMISED_TASK_SELECTION == 0 +#if ( configUSE_PORT_OPTIMISED_TASK_SELECTION == 0 ) /* If configUSE_PORT_OPTIMISED_TASK_SELECTION is 0 then task selection is performed in a generic way that is not optimised to any particular @@ -373,7 +386,7 @@ portTickType xItemValue; \ #define prvGetTCBFromHandle( pxHandle ) ( ( ( pxHandle ) == NULL ) ? ( tskTCB * ) pxCurrentTCB : ( tskTCB * ) ( pxHandle ) ) /* Callback function prototypes. --------------------------*/ -extern void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName ); +extern void vApplicationStackOverflowHook( xTaskHandle xTask, signed char *pcTaskName ); extern void vApplicationTickHook( void ); /* File private functions. --------------------------------*/ @@ -526,7 +539,7 @@ tskTCB * pxNewTCB; /* Check the alignment of the calculated top of stack is correct. */ configASSERT( ( ( ( unsigned long ) pxTopOfStack & ( unsigned long ) portBYTE_ALIGNMENT_MASK ) == 0UL ) ); } - #else + #else /* portSTACK_GROWTH */ { pxTopOfStack = pxNewTCB->pxStack; @@ -538,7 +551,7 @@ tskTCB * pxNewTCB; other extreme of the stack space. */ pxNewTCB->pxEndOfStack = pxNewTCB->pxStack + ( usStackDepth - 1 ); } - #endif + #endif /* portSTACK_GROWTH */ /* Setup the newly allocated TCB with the initial state of the task. */ prvInitialiseTCBVariables( pxNewTCB, pcName, uxPriority, xRegions, usStackDepth ); @@ -551,11 +564,11 @@ tskTCB * pxNewTCB; { pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pxTaskCode, pvParameters, xRunPrivileged ); } - #else + #else /* portUSING_MPU_WRAPPERS */ { pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pxTaskCode, pvParameters ); } - #endif + #endif /* portUSING_MPU_WRAPPERS */ /* Check the alignment of the initialised stack. */ portALIGNMENT_ASSERT_pxCurrentTCB( ( ( ( unsigned long ) pxNewTCB->pxTopOfStack & ( unsigned long ) portBYTE_ALIGNMENT_MASK ) == 0UL ) ); @@ -608,19 +621,20 @@ tskTCB * pxNewTCB; uxTopUsedPriority = pxNewTCB->uxPriority; } + uxTaskNumber++; + #if ( configUSE_TRACE_FACILITY == 1 ) { /* Add a counter into the TCB for tracing only. */ pxNewTCB->uxTCBNumber = uxTaskNumber; } - #endif - uxTaskNumber++; + #endif /* configUSE_TRACE_FACILITY */ traceTASK_CREATE( pxNewTCB ); prvAddTaskToReadyQueue( pxNewTCB ); xReturn = pdPASS; - portSETUP_TCB( pxNewTCB ); + portSETUP_TCB( pxNewTCB ); } taskEXIT_CRITICAL(); } @@ -649,7 +663,7 @@ tskTCB * pxNewTCB; #if ( INCLUDE_vTaskDelete == 1 ) - void vTaskDelete( xTaskHandle pxTaskToDelete ) + void vTaskDelete( xTaskHandle xTaskToDelete ) { tskTCB *pxTCB; @@ -657,13 +671,13 @@ tskTCB * pxNewTCB; { /* Ensure a yield is performed if the current task is being deleted. */ - if( pxTaskToDelete == pxCurrentTCB ) + if( xTaskToDelete == pxCurrentTCB ) { - pxTaskToDelete = NULL; + xTaskToDelete = NULL; } /* If null is passed in here then we are deleting ourselves. */ - pxTCB = prvGetTCBFromHandle( pxTaskToDelete ); + pxTCB = prvGetTCBFromHandle( xTaskToDelete ); /* Remove task from the ready list and place in the termination list. This will stop the task from be scheduled. The idle task will check @@ -698,14 +712,14 @@ tskTCB * pxNewTCB; /* Force a reschedule if we have just deleted the current task. */ if( xSchedulerRunning != pdFALSE ) { - if( ( void * ) pxTaskToDelete == NULL ) + if( ( void * ) xTaskToDelete == NULL ) { portYIELD_WITHIN_API(); } } } -#endif +#endif /* INCLUDE_vTaskDelete */ @@ -785,7 +799,7 @@ tskTCB * pxNewTCB; } } -#endif +#endif /* INCLUDE_vTaskDelayUntil */ /*-----------------------------------------------------------*/ #if ( INCLUDE_vTaskDelay == 1 ) @@ -837,18 +851,18 @@ tskTCB * pxNewTCB; } } -#endif +#endif /* INCLUDE_vTaskDelay */ /*-----------------------------------------------------------*/ -#if ( INCLUDE_eTaskStateGet == 1 ) +#if ( INCLUDE_eTaskGetState == 1 ) - eTaskState eTaskStateGet( xTaskHandle pxTask ) + eTaskState eTaskGetState( xTaskHandle xTask ) { eTaskState eReturn; xList *pxStateList; tskTCB *pxTCB; - pxTCB = ( tskTCB * ) pxTask; + pxTCB = ( tskTCB * ) xTask; if( pxTCB == pxCurrentTCB ) { @@ -899,12 +913,12 @@ tskTCB * pxNewTCB; return eReturn; } -#endif +#endif /* INCLUDE_eTaskGetState */ /*-----------------------------------------------------------*/ #if ( INCLUDE_uxTaskPriorityGet == 1 ) - unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask ) + unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle xTask ) { tskTCB *pxTCB; unsigned portBASE_TYPE uxReturn; @@ -913,7 +927,7 @@ tskTCB * pxNewTCB; { /* If null is passed in here then we are changing the priority of the calling function. */ - pxTCB = prvGetTCBFromHandle( pxTask ); + pxTCB = prvGetTCBFromHandle( xTask ); uxReturn = pxTCB->uxPriority; } taskEXIT_CRITICAL(); @@ -921,12 +935,12 @@ tskTCB * pxNewTCB; return uxReturn; } -#endif +#endif /* INCLUDE_uxTaskPriorityGet */ /*-----------------------------------------------------------*/ #if ( INCLUDE_vTaskPrioritySet == 1 ) - void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority ) + void vTaskPrioritySet( xTaskHandle xTask, unsigned portBASE_TYPE uxNewPriority ) { tskTCB *pxTCB; unsigned portBASE_TYPE uxCurrentPriority, uxPriorityUsedOnEntry; @@ -942,14 +956,14 @@ tskTCB * pxNewTCB; taskENTER_CRITICAL(); { - if( pxTask == pxCurrentTCB ) + if( xTask == ( xTaskHandle ) pxCurrentTCB ) { - pxTask = NULL; + xTask = NULL; } /* If null is passed in here then we are changing the priority of the calling function. */ - pxTCB = prvGetTCBFromHandle( pxTask ); + pxTCB = prvGetTCBFromHandle( xTask ); traceTASK_PRIORITY_SET( pxTCB, uxNewPriority ); @@ -969,7 +983,7 @@ tskTCB * pxNewTCB; priority than the calling task. */ if( uxNewPriority > uxCurrentPriority ) { - if( pxTask != NULL ) + if( xTask != NULL ) { /* The priority of another task is being raised. If we were raising the priority of the currently running task @@ -978,7 +992,7 @@ tskTCB * pxNewTCB; xYieldRequired = pdTRUE; } } - else if( pxTask == NULL ) + else if( xTask == NULL ) { /* Setting our own priority down means there may now be another task of higher priority that is ready to execute. */ @@ -1039,12 +1053,12 @@ tskTCB * pxNewTCB; ( void ) uxPriorityUsedOnEntry; } -#endif +#endif /* INCLUDE_vTaskPrioritySet */ /*-----------------------------------------------------------*/ #if ( INCLUDE_vTaskSuspend == 1 ) - void vTaskSuspend( xTaskHandle pxTaskToSuspend ) + void vTaskSuspend( xTaskHandle xTaskToSuspend ) { tskTCB *pxTCB; @@ -1052,13 +1066,13 @@ tskTCB * pxNewTCB; { /* Ensure a yield is performed if the current task is being suspended. */ - if( pxTaskToSuspend == pxCurrentTCB ) + if( xTaskToSuspend == ( xTaskHandle ) pxCurrentTCB ) { - pxTaskToSuspend = NULL; + xTaskToSuspend = NULL; } /* If null is passed in here then we are suspending ourselves. */ - pxTCB = prvGetTCBFromHandle( pxTaskToSuspend ); + pxTCB = prvGetTCBFromHandle( xTaskToSuspend ); traceTASK_SUSPEND( pxTCB ); @@ -1078,7 +1092,7 @@ tskTCB * pxNewTCB; } taskEXIT_CRITICAL(); - if( ( void * ) pxTaskToSuspend == NULL ) + if( ( void * ) xTaskToSuspend == NULL ) { if( xSchedulerRunning != pdFALSE ) { @@ -1106,7 +1120,7 @@ tskTCB * pxNewTCB; } } -#endif +#endif /* INCLUDE_vTaskSuspend */ /*-----------------------------------------------------------*/ #if ( INCLUDE_vTaskSuspend == 1 ) @@ -1140,21 +1154,21 @@ tskTCB * pxNewTCB; return xReturn; } -#endif +#endif /* INCLUDE_vTaskSuspend */ /*-----------------------------------------------------------*/ #if ( INCLUDE_vTaskSuspend == 1 ) - void vTaskResume( xTaskHandle pxTaskToResume ) + void vTaskResume( xTaskHandle xTaskToResume ) { tskTCB *pxTCB; /* It does not make sense to resume the calling task. */ - configASSERT( pxTaskToResume ); + configASSERT( xTaskToResume ); /* Remove the task from whichever list it is currently in, and place it in the ready list. */ - pxTCB = ( tskTCB * ) pxTaskToResume; + pxTCB = ( tskTCB * ) xTaskToResume; /* The parameter cannot be NULL as it is impossible to resume the currently executing task. */ @@ -1184,21 +1198,21 @@ tskTCB * pxNewTCB; } } -#endif +#endif /* INCLUDE_vTaskSuspend */ /*-----------------------------------------------------------*/ #if ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) ) - portBASE_TYPE xTaskResumeFromISR( xTaskHandle pxTaskToResume ) + portBASE_TYPE xTaskResumeFromISR( xTaskHandle xTaskToResume ) { portBASE_TYPE xYieldRequired = pdFALSE; tskTCB *pxTCB; unsigned portBASE_TYPE uxSavedInterruptStatus; - configASSERT( pxTaskToResume ); + configASSERT( xTaskToResume ); - pxTCB = ( tskTCB * ) pxTaskToResume; + pxTCB = ( tskTCB * ) xTaskToResume; uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); { @@ -1226,7 +1240,7 @@ tskTCB * pxNewTCB; return xYieldRequired; } -#endif +#endif /* ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) ) */ @@ -1252,7 +1266,7 @@ portBASE_TYPE xReturn; /* Create the idle task without storing its handle. */ xReturn = xTaskCreate( prvIdleTask, ( signed char * ) "IDLE", tskIDLE_STACK_SIZE, ( void * ) NULL, ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), NULL ); } - #endif + #endif /* INCLUDE_xTaskGetIdleTaskHandle */ #if ( configUSE_TIMERS == 1 ) { @@ -1261,7 +1275,7 @@ portBASE_TYPE xReturn; xReturn = xTimerCreateTimerTask(); } } - #endif + #endif /* configUSE_TIMERS */ if( xReturn == pdPASS ) { @@ -1295,9 +1309,13 @@ portBASE_TYPE xReturn; /* Should only reach here if a task calls xTaskEndScheduler(). */ } } - - /* This line will only be reached if the kernel could not be started. */ - configASSERT( xReturn ); + else + { + /* This line will only be reached if the kernel could not be started, + because there was not enough FreeRTOS heap to create the idle task + or the timer task. */ + configASSERT( xReturn ); + } } /*-----------------------------------------------------------*/ @@ -1322,10 +1340,10 @@ void vTaskSuspendAll( void ) #if ( configUSE_TICKLESS_IDLE != 0 ) - portTickType prvGetExpectedIdleTime( void ) + static portTickType prvGetExpectedIdleTime( void ) { portTickType xReturn; - + if( pxCurrentTCB->uxPriority > tskIDLE_PRIORITY ) { xReturn = 0; @@ -1341,11 +1359,11 @@ void vTaskSuspendAll( void ) { xReturn = xNextTaskUnblockTime - xTickCount; } - + return xReturn; } -#endif /* configUSE_TICKLESS_IDLE != 0 */ +#endif /* configUSE_TICKLESS_IDLE */ /*----------------------------------------------------------*/ signed portBASE_TYPE xTaskResumeAll( void ) @@ -1423,6 +1441,7 @@ signed portBASE_TYPE xAlreadyYielded = pdFALSE; return xAlreadyYielded; } +/*-----------------------------------------------------------*/ @@ -1483,7 +1502,7 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void ) return &( pxTCB->pcTaskName[ 0 ] ); } -#endif +#endif /* INCLUDE_pcTaskGetTaskName */ /*-----------------------------------------------------------*/ #if ( configUSE_TRACE_FACILITY == 1 ) @@ -1546,7 +1565,7 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void ) xTaskResumeAll(); } -#endif +#endif /* configUSE_TRACE_FACILITY */ /*----------------------------------------------------------*/ #if ( configGENERATE_RUN_TIME_STATS == 1 ) @@ -1621,7 +1640,7 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void ) xTaskResumeAll(); } -#endif +#endif /* configGENERATE_RUN_TIME_STATS */ /*----------------------------------------------------------*/ #if ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) @@ -1634,22 +1653,23 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void ) return xIdleTaskHandle; } -#endif +#endif /* INCLUDE_xTaskGetIdleTaskHandle */ /*----------------------------------------------------------*/ /* This conditional compilation should use inequality to 0, not equality to 1. -This is to ensure vTaskStepTick() is available when user defined low power mode +This is to ensure vTaskStepTick() is available when user defined low power mode implementations require configUSE_TICKLESS_IDLE to be set to a value other than 1. */ #if ( configUSE_TICKLESS_IDLE != 0 ) void vTaskStepTick( portTickType xTicksToJump ) { - configASSERT( xTicksToJump <= xNextTaskUnblockTime ); + configASSERT( ( xTickCount + xTicksToJump ) <= xNextTaskUnblockTime ); xTickCount += xTicksToJump; } -#endif +#endif /* configUSE_TICKLESS_IDLE */ +/*----------------------------------------------------------*/ /*----------------------------------------------------------- * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES @@ -1726,7 +1746,7 @@ tskTCB * pxTCB; vApplicationTickHook(); } } - #endif + #endif /* configUSE_TICK_HOOK */ } /*-----------------------------------------------------------*/ @@ -1753,7 +1773,7 @@ tskTCB * pxTCB; taskEXIT_CRITICAL(); } -#endif +#endif /* configUSE_APPLICATION_TASK_TAG */ /*-----------------------------------------------------------*/ #if ( configUSE_APPLICATION_TASK_TAG == 1 ) @@ -1782,7 +1802,7 @@ tskTCB * pxTCB; return xReturn; } -#endif +#endif /* configUSE_APPLICATION_TASK_TAG */ /*-----------------------------------------------------------*/ #if ( configUSE_APPLICATION_TASK_TAG == 1 ) @@ -1814,7 +1834,7 @@ tskTCB * pxTCB; return xReturn; } -#endif +#endif /* configUSE_APPLICATION_TASK_TAG */ /*-----------------------------------------------------------*/ void vTaskSwitchContext( void ) @@ -1845,7 +1865,7 @@ void vTaskSwitchContext( void ) pxCurrentTCB->ulRunTimeCounter += ( ulTotalRunTime - ulTaskSwitchedInTime ); ulTaskSwitchedInTime = ulTotalRunTime; } - #endif + #endif /* configGENERATE_RUN_TIME_STATS */ taskFIRST_CHECK_FOR_STACK_OVERFLOW(); taskSECOND_CHECK_FOR_STACK_OVERFLOW(); @@ -1898,14 +1918,14 @@ portTickType xTimeToWake; prvAddCurrentTaskToDelayedList( xTimeToWake ); } } - #else + #else /* INCLUDE_vTaskSuspend */ { /* Calculate the time at which the task should be woken if the event does not occur. This may overflow but this doesn't matter. */ xTimeToWake = xTickCount + xTicksToWait; prvAddCurrentTaskToDelayedList( xTimeToWake ); } - #endif + #endif /* INCLUDE_vTaskSuspend */ } /*-----------------------------------------------------------*/ @@ -1942,7 +1962,7 @@ portTickType xTimeToWake; /* Calculate the time at which the task should be woken if the event does not occur. This may overflow but this doesn't matter. */ xTimeToWake = xTickCount + xTicksToWait; - + traceTASK_DELAY_UNTIL(); prvAddCurrentTaskToDelayedList( xTimeToWake ); } @@ -2062,6 +2082,7 @@ void vTaskMissedYield( void ) /*-----------------------------------------------------------*/ #if ( configUSE_TRACE_FACILITY == 1 ) + unsigned portBASE_TYPE uxTaskGetTaskNumber( xTaskHandle xTask ) { unsigned portBASE_TYPE uxReturn; @@ -2079,10 +2100,12 @@ void vTaskMissedYield( void ) return uxReturn; } -#endif + +#endif /* configUSE_TRACE_FACILITY */ /*-----------------------------------------------------------*/ #if ( configUSE_TRACE_FACILITY == 1 ) + void vTaskSetTaskNumber( xTaskHandle xTask, unsigned portBASE_TYPE uxHandle ) { tskTCB *pxTCB; @@ -2093,8 +2116,8 @@ void vTaskMissedYield( void ) pxTCB->uxTaskNumber = uxHandle; } } -#endif +#endif /* configUSE_TRACE_FACILITY */ /* * ----------------------------------------------------------- @@ -2125,7 +2148,7 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters ) will automatically get the processor anyway. */ taskYIELD(); } - #endif + #endif /* configUSE_PREEMPTION */ #if ( ( configUSE_PREEMPTION == 1 ) && ( configIDLE_SHOULD_YIELD == 1 ) ) { @@ -2143,7 +2166,7 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters ) taskYIELD(); } } - #endif + #endif /* ( ( configUSE_PREEMPTION == 1 ) && ( configIDLE_SHOULD_YIELD == 1 ) ) */ #if ( configUSE_IDLE_HOOK == 1 ) { @@ -2156,7 +2179,7 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters ) CALL A FUNCTION THAT MIGHT BLOCK. */ vApplicationIdleHook(); } - #endif + #endif /* configUSE_IDLE_HOOK */ /* This conditional compilation should use inequality to 0, not equality to 1. This is to ensure portSUPPRESS_TICKS_AND_SLEEP() is called when @@ -2165,13 +2188,6 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters ) #if ( configUSE_TICKLESS_IDLE != 0 ) { portTickType xExpectedIdleTime; - /* If the expected idle time is 1 then the idle time would end at - the end of the current time slice. The idle time must be at least - 2 to ensure any pended ticks between this point and the tick being - stopped can be legitimately stepped over when the tick suppression - routines returns. */ - const portTickType xMinimumExpectedIdleTime = ( portTickType ) 2; - /* It is not desirable to suspend then resume the scheduler on each iteration of the idle task. Therefore, a preliminary test of the expected idle time is performed without the @@ -2179,7 +2195,7 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters ) valid. */ xExpectedIdleTime = prvGetExpectedIdleTime(); - if( xExpectedIdleTime >= xMinimumExpectedIdleTime ) + if( xExpectedIdleTime >= configEXPECTED_IDLE_TIME_BEFORE_SLEEP ) { vTaskSuspendAll(); { @@ -2189,7 +2205,7 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters ) configASSERT( xNextTaskUnblockTime >= xTickCount ); xExpectedIdleTime = prvGetExpectedIdleTime(); - if( xExpectedIdleTime >= xMinimumExpectedIdleTime ) + if( xExpectedIdleTime >= configEXPECTED_IDLE_TIME_BEFORE_SLEEP ) { portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime ); } @@ -2197,14 +2213,50 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters ) xTaskResumeAll(); } } - #endif + #endif /* configUSE_TICKLESS_IDLE */ } } /*lint !e715 pvParameters is not accessed but all task functions require the same prototype. */ +/*-----------------------------------------------------------*/ +#if configUSE_TICKLESS_IDLE != 0 + eSleepModeStatus eTaskConfirmSleepModeStatus( void ) + { + eSleepModeStatus eReturn = eStandardSleep; + if( listCURRENT_LIST_LENGTH( &xPendingReadyList ) != 0 ) + { + /* A task was made ready while the scheduler was suspended. */ + eReturn = eAbortSleep; + } + else if( xMissedYield != pdFALSE ) + { + /* A yield was pended while the scheduler was suspended. */ + eReturn = eAbortSleep; + } + else + { + #if configUSE_TIMERS == 0 + { + /* The idle task exists in addition to the application tasks. */ + const unsigned portBASE_TYPE uxNonApplicationTasks = 1; + + /* If timers are not being used and all the tasks are in the + suspended list (which might mean they have an infinite block + time rather than actually being suspended) then it is safe to + turn all clocks off and just wait for external interrupts. */ + if( listCURRENT_LIST_LENGTH( &xSuspendedTaskList ) == ( uxCurrentNumberOfTasks - uxNonApplicationTasks ) ) + { + eReturn = eNoTasksWaitingTimeout; + } + } + #endif /* configUSE_TIMERS */ + } - + return eReturn; + } +#endif /* configUSE_TICKLESS_IDLE */ +/*-----------------------------------------------------------*/ /*----------------------------------------------------------- @@ -2221,7 +2273,7 @@ static void prvInitialiseTCBVariables( tskTCB *pxTCB, const signed char * const /* Don't bring strncpy into the build unnecessarily. */ strncpy( ( char * ) pxTCB->pcTaskName, ( const char * ) pcName, ( unsigned short ) configMAX_TASK_NAME_LEN ); } - #endif + #endif /* configMAX_TASK_NAME_LEN */ pxTCB->pcTaskName[ ( unsigned short ) configMAX_TASK_NAME_LEN - ( unsigned short ) 1 ] = ( signed char ) '\0'; /* This is used as an array index so must ensure it's not too large. First @@ -2236,7 +2288,7 @@ static void prvInitialiseTCBVariables( tskTCB *pxTCB, const signed char * const { pxTCB->uxBasePriority = uxPriority; } - #endif + #endif /* configUSE_MUTEXES */ vListInitialiseItem( &( pxTCB->xGenericListItem ) ); vListInitialiseItem( &( pxTCB->xEventListItem ) ); @@ -2253,30 +2305,30 @@ static void prvInitialiseTCBVariables( tskTCB *pxTCB, const signed char * const { pxTCB->uxCriticalNesting = ( unsigned portBASE_TYPE ) 0U; } - #endif + #endif /* portCRITICAL_NESTING_IN_TCB */ #if ( configUSE_APPLICATION_TASK_TAG == 1 ) { pxTCB->pxTaskTag = NULL; } - #endif + #endif /* configUSE_APPLICATION_TASK_TAG */ #if ( configGENERATE_RUN_TIME_STATS == 1 ) { pxTCB->ulRunTimeCounter = 0UL; } - #endif + #endif /* configGENERATE_RUN_TIME_STATS */ #if ( portUSING_MPU_WRAPPERS == 1 ) { vPortStoreTaskMPUSettings( &( pxTCB->xMPUSettings ), xRegions, pxTCB->pxStack, usStackDepth ); } - #else + #else /* portUSING_MPU_WRAPPERS */ { ( void ) xRegions; ( void ) usStackDepth; } - #endif + #endif /* portUSING_MPU_WRAPPERS */ } /*-----------------------------------------------------------*/ @@ -2296,8 +2348,9 @@ static void prvInitialiseTCBVariables( tskTCB *pxTCB, const signed char * const vPortStoreTaskMPUSettings( &( pxTCB->xMPUSettings ), xRegions, NULL, 0 ); } - /*-----------------------------------------------------------*/ -#endif + +#endif /* portUSING_MPU_WRAPPERS */ +/*-----------------------------------------------------------*/ static void prvInitialiseTaskLists( void ) { @@ -2316,13 +2369,13 @@ unsigned portBASE_TYPE uxPriority; { vListInitialise( ( xList * ) &xTasksWaitingTermination ); } - #endif + #endif /* INCLUDE_vTaskDelete */ #if ( INCLUDE_vTaskSuspend == 1 ) { vListInitialise( ( xList * ) &xSuspendedTaskList ); } - #endif + #endif /* INCLUDE_vTaskSuspend */ /* Start with pxDelayedTaskList using list1 and the pxOverflowDelayedTaskList using list2. */ @@ -2362,7 +2415,7 @@ static void prvCheckTasksWaitingTermination( void ) } } } - #endif + #endif /* vTaskDelete */ } /*-----------------------------------------------------------*/ @@ -2453,7 +2506,7 @@ tskTCB *pxNewTCB; } while( pxNextTCB != pxFirstTCB ); } -#endif +#endif /* configUSE_TRACE_FACILITY */ /*-----------------------------------------------------------*/ #if ( configGENERATE_RUN_TIME_STATS == 1 ) @@ -2524,7 +2577,7 @@ tskTCB *pxNewTCB; } while( pxNextTCB != pxFirstTCB ); } -#endif +#endif /* configGENERATE_RUN_TIME_STATS */ /*-----------------------------------------------------------*/ #if ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) ) @@ -2544,7 +2597,7 @@ tskTCB *pxNewTCB; return usCount; } -#endif +#endif /* ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) ) */ /*-----------------------------------------------------------*/ #if ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) @@ -2572,7 +2625,7 @@ tskTCB *pxNewTCB; return uxReturn; } -#endif +#endif /* INCLUDE_uxTaskGetStackHighWaterMark */ /*-----------------------------------------------------------*/ #if ( INCLUDE_vTaskDelete == 1 ) @@ -2590,9 +2643,7 @@ tskTCB *pxNewTCB; vPortFree( pxTCB ); } -#endif - - +#endif /* INCLUDE_vTaskDelete */ /*-----------------------------------------------------------*/ #if ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) ) @@ -2609,8 +2660,7 @@ tskTCB *pxNewTCB; return xReturn; } -#endif - +#endif /* ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) ) */ /*-----------------------------------------------------------*/ #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) @@ -2638,7 +2688,7 @@ tskTCB *pxNewTCB; return xReturn; } -#endif +#endif /* ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) */ /*-----------------------------------------------------------*/ #if ( configUSE_MUTEXES == 1 ) @@ -2680,7 +2730,7 @@ tskTCB *pxNewTCB; } } -#endif +#endif /* configUSE_MUTEXES */ /*-----------------------------------------------------------*/ #if ( configUSE_MUTEXES == 1 ) @@ -2710,7 +2760,7 @@ tskTCB *pxNewTCB; } } -#endif +#endif /* configUSE_MUTEXES */ /*-----------------------------------------------------------*/ #if ( portCRITICAL_NESTING_IN_TCB == 1 ) @@ -2725,7 +2775,7 @@ tskTCB *pxNewTCB; } } -#endif +#endif /* portCRITICAL_NESTING_IN_TCB */ /*-----------------------------------------------------------*/ #if ( portCRITICAL_NESTING_IN_TCB == 1 ) @@ -2746,7 +2796,7 @@ tskTCB *pxNewTCB; } } -#endif +#endif /* portCRITICAL_NESTING_IN_TCB */ /*-----------------------------------------------------------*/ diff --git a/arduino.DuinOS.AVR/DuinOS/timers.c b/arduino.DuinOS.AVR/DuinOS/timers.c index bc4ef06..ddfdb70 100644 --- a/arduino.DuinOS.AVR/DuinOS/timers.c +++ b/arduino.DuinOS.AVR/DuinOS/timers.c @@ -1,7 +1,7 @@ /* - FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd. - FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** @@ -29,20 +29,23 @@ FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - >>>NOTE<<< The modification to the GPL is included to allow you to + + >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS - kernel. FreeRTOS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. You should have received a copy of the GNU General Public - License and the FreeRTOS license exception along with FreeRTOS; if not it - can be viewed here: http://www.freertos.org/a00114.html and also obtained - by writing to Richard Barry, contact details for whom are available on the - FreeRTOS WEB site. + kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License + and the FreeRTOS license exception along with FreeRTOS; if not itcan be + viewed here: http://www.freertos.org/a00114.html and also obtained by + writing to Real Time Engineers Ltd., contact details for whom are available + on the FreeRTOS WEB site. 1 tab == 4 spaces! - + *************************************************************************** * * * Having a problem? Start by reading the FAQ "My application does * @@ -52,18 +55,21 @@ * * *************************************************************************** - - http://www.FreeRTOS.org - Documentation, training, latest versions, license - and contact details. - + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool. + including FreeRTOS+Trace - an indispensable productivity tool, and our new + fully thread aware and reentrant UDP/IP stack. - Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell - the code with commercial support, indemnification, and middleware, under - the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also - provide a safety engineered and independently SIL3 certified version under - the SafeRTOS brand: http://www.SafeRTOS.com. + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems, who sell the code with commercial support, + indemnification and middleware, under the OpenRTOS brand. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. */ /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining diff --git a/arduino.DuinOS.AVR/DuinOS/timers.h b/arduino.DuinOS.AVR/DuinOS/timers.h index 0d998a5..b8bd73e 100644 --- a/arduino.DuinOS.AVR/DuinOS/timers.h +++ b/arduino.DuinOS.AVR/DuinOS/timers.h @@ -1,7 +1,7 @@ /* - FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd. - FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** @@ -29,20 +29,23 @@ FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - >>>NOTE<<< The modification to the GPL is included to allow you to + + >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS - kernel. FreeRTOS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. You should have received a copy of the GNU General Public - License and the FreeRTOS license exception along with FreeRTOS; if not it - can be viewed here: http://www.freertos.org/a00114.html and also obtained - by writing to Richard Barry, contact details for whom are available on the - FreeRTOS WEB site. + kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License + and the FreeRTOS license exception along with FreeRTOS; if not itcan be + viewed here: http://www.freertos.org/a00114.html and also obtained by + writing to Real Time Engineers Ltd., contact details for whom are available + on the FreeRTOS WEB site. 1 tab == 4 spaces! - + *************************************************************************** * * * Having a problem? Start by reading the FAQ "My application does * @@ -52,18 +55,21 @@ * * *************************************************************************** - - http://www.FreeRTOS.org - Documentation, training, latest versions, license - and contact details. - + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool. + including FreeRTOS+Trace - an indispensable productivity tool, and our new + fully thread aware and reentrant UDP/IP stack. - Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell - the code with commercial support, indemnification, and middleware, under - the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also - provide a safety engineered and independently SIL3 certified version under - the SafeRTOS brand: http://www.SafeRTOS.com. + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems, who sell the code with commercial support, + indemnification and middleware, under the OpenRTOS brand. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. */ From 3d6d8c1ecdc7ef1bb2c659a4ce3371f995a2516f Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Fri, 22 Feb 2013 11:25:55 -0300 Subject: [PATCH 38/56] =?UTF-8?q?Atualiza=C3=A7=C3=A3o=20do=20codigo=20par?= =?UTF-8?q?a=20os=20ultimos=20ajustes=20no=20Arduino=201.5.x=20Separa?= =?UTF-8?q?=C3=A7=C3=A3o=20do=20arquivo=20FreeRTOSConfig,=20criando=20um?= =?UTF-8?q?=20arquivo=20para=20cada=20chip=20atmega=20facilitando=20assim?= =?UTF-8?q?=20o=20gerenciamento=20e=20compara=C3=A7=C3=A3o=20dos=20paramet?= =?UTF-8?q?ros.=20Pequenos=20ajustes=20no=20c=C3=B3digo,=20como=20formata?= =?UTF-8?q?=C3=A7=C3=A3o.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arduino.DuinOS.AVR/Arduino.h | 2 + arduino.DuinOS.AVR/DuinOS/.gitignore | 2 + arduino.DuinOS.AVR/DuinOS/portable.h | 239 ------------ arduino.DuinOS.AVR/DuinOS/tasks.c | 3 - arduino.DuinOS.AVR/FreeRTOSConfig.h | 356 +++++------------- arduino.DuinOS.AVR/FreeRTOSConfigATmega1280.h | 44 +++ .../FreeRTOSConfigATmega1284P.h | 44 +++ arduino.DuinOS.AVR/FreeRTOSConfigATmega168P.h | 43 +++ arduino.DuinOS.AVR/FreeRTOSConfigATmega2560.h | 42 +++ arduino.DuinOS.AVR/FreeRTOSConfigATmega328P.h | 43 +++ arduino.DuinOS.AVR/FreeRTOSConfigATmega644.h | 44 +++ arduino.DuinOS.AVR/FreeRTOSConfigATtiny.h | 42 +++ arduino.DuinOS.AVR/HardwareSerial.cpp | 3 +- arduino.DuinOS.AVR/HardwareSerial.h | 16 - arduino.DuinOS.AVR/hooks.c | 28 ++ arduino.DuinOS.AVR/main.cpp | 33 +- arduino.DuinOS.AVR/malloc.c | 4 +- arduino.DuinOS.AVR/merge-todo.ext | 9 + arduino.DuinOS.AVR/wiring.c | 1 + temp.txt | 10 + 20 files changed, 456 insertions(+), 552 deletions(-) create mode 100644 arduino.DuinOS.AVR/FreeRTOSConfigATmega1280.h create mode 100644 arduino.DuinOS.AVR/FreeRTOSConfigATmega1284P.h create mode 100644 arduino.DuinOS.AVR/FreeRTOSConfigATmega168P.h create mode 100644 arduino.DuinOS.AVR/FreeRTOSConfigATmega2560.h create mode 100644 arduino.DuinOS.AVR/FreeRTOSConfigATmega328P.h create mode 100644 arduino.DuinOS.AVR/FreeRTOSConfigATmega644.h create mode 100644 arduino.DuinOS.AVR/FreeRTOSConfigATtiny.h create mode 100644 arduino.DuinOS.AVR/hooks.c create mode 100644 arduino.DuinOS.AVR/merge-todo.ext create mode 100644 temp.txt diff --git a/arduino.DuinOS.AVR/Arduino.h b/arduino.DuinOS.AVR/Arduino.h index fda08f0..dc42a76 100644 --- a/arduino.DuinOS.AVR/Arduino.h +++ b/arduino.DuinOS.AVR/Arduino.h @@ -15,6 +15,8 @@ extern "C"{ #endif +void yield(void); + #define HIGH 0x1 #define LOW 0x0 diff --git a/arduino.DuinOS.AVR/DuinOS/.gitignore b/arduino.DuinOS.AVR/DuinOS/.gitignore index 61045a0..5e5461c 100644 --- a/arduino.DuinOS.AVR/DuinOS/.gitignore +++ b/arduino.DuinOS.AVR/DuinOS/.gitignore @@ -1 +1,3 @@ /port.c.corr +/timer0_init_wiring.c.corr +/timer0_port.c.corr diff --git a/arduino.DuinOS.AVR/DuinOS/portable.h b/arduino.DuinOS.AVR/DuinOS/portable.h index cb35389..cffda76 100644 --- a/arduino.DuinOS.AVR/DuinOS/portable.h +++ b/arduino.DuinOS.AVR/DuinOS/portable.h @@ -78,245 +78,6 @@ #ifndef PORTABLE_H #define PORTABLE_H - -/* Include the macro file relevant to the port being used. */ - -#ifdef OPEN_WATCOM_INDUSTRIAL_PC_PORT - #include "..\..\Source\portable\owatcom\16bitdos\pc\portmacro.h" - typedef void ( __interrupt __far *pxISR )(); -#endif - -#ifdef OPEN_WATCOM_FLASH_LITE_186_PORT - #include "..\..\Source\portable\owatcom\16bitdos\flsh186\portmacro.h" - typedef void ( __interrupt __far *pxISR )(); -#endif - -#ifdef GCC_MEGA_AVR - #include "../portable/GCC/ATMega323/portmacro.h" -#endif - -#ifdef IAR_MEGA_AVR - #include "../portable/IAR/ATMega323/portmacro.h" -#endif - -#ifdef MPLAB_PIC24_PORT - #include "..\..\Source\portable\MPLAB\PIC24_dsPIC\portmacro.h" -#endif - -#ifdef MPLAB_DSPIC_PORT - #include "..\..\Source\portable\MPLAB\PIC24_dsPIC\portmacro.h" -#endif - -#ifdef MPLAB_PIC18F_PORT - #include "..\..\Source\portable\MPLAB\PIC18F\portmacro.h" -#endif - -#ifdef MPLAB_PIC32MX_PORT - #include "..\..\Source\portable\MPLAB\PIC32MX\portmacro.h" -#endif - -#ifdef _FEDPICC - #include "libFreeRTOS/Include/portmacro.h" -#endif - -#ifdef SDCC_CYGNAL - #include "../../Source/portable/SDCC/Cygnal/portmacro.h" -#endif - -#ifdef GCC_ARM7 - #include "../../Source/portable/GCC/ARM7_LPC2000/portmacro.h" -#endif - -#ifdef GCC_ARM7_ECLIPSE - #include "portmacro.h" -#endif - -#ifdef ROWLEY_LPC23xx - #include "../../Source/portable/GCC/ARM7_LPC23xx/portmacro.h" -#endif - -#ifdef IAR_MSP430 - #include "..\..\Source\portable\IAR\MSP430\portmacro.h" -#endif - -#ifdef GCC_MSP430 - #include "../../Source/portable/GCC/MSP430F449/portmacro.h" -#endif - -#ifdef ROWLEY_MSP430 - #include "../../Source/portable/Rowley/MSP430F449/portmacro.h" -#endif - -#ifdef ARM7_LPC21xx_KEIL_RVDS - #include "..\..\Source\portable\RVDS\ARM7_LPC21xx\portmacro.h" -#endif - -#ifdef SAM7_GCC - #include "../../Source/portable/GCC/ARM7_AT91SAM7S/portmacro.h" -#endif - -#ifdef SAM7_IAR - #include "..\..\Source\portable\IAR\AtmelSAM7S64\portmacro.h" -#endif - -#ifdef SAM9XE_IAR - #include "..\..\Source\portable\IAR\AtmelSAM9XE\portmacro.h" -#endif - -#ifdef LPC2000_IAR - #include "..\..\Source\portable\IAR\LPC2000\portmacro.h" -#endif - -#ifdef STR71X_IAR - #include "..\..\Source\portable\IAR\STR71x\portmacro.h" -#endif - -#ifdef STR75X_IAR - #include "..\..\Source\portable\IAR\STR75x\portmacro.h" -#endif - -#ifdef STR75X_GCC - #include "..\..\Source\portable\GCC\STR75x\portmacro.h" -#endif - -#ifdef STR91X_IAR - #include "..\..\Source\portable\IAR\STR91x\portmacro.h" -#endif - -#ifdef GCC_H8S - #include "../../Source/portable/GCC/H8S2329/portmacro.h" -#endif - -#ifdef GCC_AT91FR40008 - #include "../../Source/portable/GCC/ARM7_AT91FR40008/portmacro.h" -#endif - -#ifdef RVDS_ARMCM3_LM3S102 - #include "../../Source/portable/RVDS/ARM_CM3/portmacro.h" -#endif - -#ifdef GCC_ARMCM3_LM3S102 - #include "../../Source/portable/GCC/ARM_CM3/portmacro.h" -#endif - -#ifdef GCC_ARMCM3 - #include "../../Source/portable/GCC/ARM_CM3/portmacro.h" -#endif - -#ifdef IAR_ARM_CM3 - #include "../../Source/portable/IAR/ARM_CM3/portmacro.h" -#endif - -#ifdef IAR_ARMCM3_LM - #include "../../Source/portable/IAR/ARM_CM3/portmacro.h" -#endif - -#ifdef HCS12_CODE_WARRIOR - #include "../../Source/portable/CodeWarrior/HCS12/portmacro.h" -#endif - -#ifdef MICROBLAZE_GCC - #include "../../Source/portable/GCC/MicroBlaze/portmacro.h" -#endif - -#ifdef TERN_EE - #include "..\..\Source\portable\Paradigm\Tern_EE\small\portmacro.h" -#endif - -#ifdef GCC_HCS12 - #include "../../Source/portable/GCC/HCS12/portmacro.h" -#endif - -#ifdef GCC_MCF5235 - #include "../../Source/portable/GCC/MCF5235/portmacro.h" -#endif - -#ifdef COLDFIRE_V2_GCC - #include "../../../Source/portable/GCC/ColdFire_V2/portmacro.h" -#endif - -#ifdef COLDFIRE_V2_CODEWARRIOR - #include "../../Source/portable/CodeWarrior/ColdFire_V2/portmacro.h" -#endif - -#ifdef GCC_PPC405 - #include "../../Source/portable/GCC/PPC405_Xilinx/portmacro.h" -#endif - -#ifdef GCC_PPC440 - #include "../../Source/portable/GCC/PPC440_Xilinx/portmacro.h" -#endif - -#ifdef _16FX_SOFTUNE - #include "..\..\Source\portable\Softune\MB96340\portmacro.h" -#endif - -#ifdef BCC_INDUSTRIAL_PC_PORT - /* A short file name has to be used in place of the normal - FreeRTOSConfig.h when using the Borland compiler. */ - #include "frconfig.h" - #include "..\portable\BCC\16BitDOS\PC\prtmacro.h" - typedef void ( __interrupt __far *pxISR )(); -#endif - -#ifdef BCC_FLASH_LITE_186_PORT - /* A short file name has to be used in place of the normal - FreeRTOSConfig.h when using the Borland compiler. */ - #include "frconfig.h" - #include "..\portable\BCC\16BitDOS\flsh186\prtmacro.h" - typedef void ( __interrupt __far *pxISR )(); -#endif - -#ifdef __GNUC__ - #ifdef __AVR32_AVR32A__ - #include "portmacro.h" - #endif -#endif - -#ifdef __ICCAVR32__ - #ifdef __CORE__ - #if __CORE__ == __AVR32A__ - #include "portmacro.h" - #endif - #endif -#endif - -#ifdef __91467D - #include "portmacro.h" -#endif - -#ifdef __96340 - #include "portmacro.h" -#endif - - -#ifdef __IAR_V850ES_Fx3__ - #include "../../Source/portable/IAR/V850ES/portmacro.h" -#endif - -#ifdef __IAR_V850ES_Jx3__ - #include "../../Source/portable/IAR/V850ES/portmacro.h" -#endif - -#ifdef __IAR_V850ES_Jx3_L__ - #include "../../Source/portable/IAR/V850ES/portmacro.h" -#endif - -#ifdef __IAR_V850ES_Jx2__ - #include "../../Source/portable/IAR/V850ES/portmacro.h" -#endif - -#ifdef __IAR_V850ES_Hx2__ - #include "../../Source/portable/IAR/V850ES/portmacro.h" -#endif - -#ifdef __IAR_78K0R_Kx3__ - #include "../../Source/portable/IAR/78K0R/portmacro.h" -#endif - -#ifdef __IAR_78K0R_Kx3L__ - #include "../../Source/portable/IAR/78K0R/portmacro.h" -#endif /* Catch all to ensure portmacro.h is included in the build. Newer demos have the path as part of the project options, rather than as relative from diff --git a/arduino.DuinOS.AVR/DuinOS/tasks.c b/arduino.DuinOS.AVR/DuinOS/tasks.c index 3c6567b..846f0b2 100644 --- a/arduino.DuinOS.AVR/DuinOS/tasks.c +++ b/arduino.DuinOS.AVR/DuinOS/tasks.c @@ -1242,9 +1242,6 @@ tskTCB * pxNewTCB; #endif /* ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) ) */ - - - /*----------------------------------------------------------- * PUBLIC SCHEDULER CONTROL documented in task.h *----------------------------------------------------------*/ diff --git a/arduino.DuinOS.AVR/FreeRTOSConfig.h b/arduino.DuinOS.AVR/FreeRTOSConfig.h index b0b1ce3..084de96 100644 --- a/arduino.DuinOS.AVR/FreeRTOSConfig.h +++ b/arduino.DuinOS.AVR/FreeRTOSConfig.h @@ -1,53 +1,53 @@ /* - FreeRTOS.org V5.3.0 - Copyright (C) 2003-2009 Richard Barry. + FreeRTOS.org V5.3.0 - Copyright (C) 2003-2009 Richard Barry. - This file is part of the FreeRTOS.org distribution. + This file is part of the FreeRTOS.org distribution. - FreeRTOS.org is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License (version 2) as published - by the Free Software Foundation and modified by the FreeRTOS exception. - **NOTE** The exception to the GPL is included to allow you to distribute a - combined work that includes FreeRTOS.org without being obliged to provide - the source code for any proprietary components. Alternative commercial - license and support terms are also available upon request. See the - licensing section of http://www.FreeRTOS.org for full details. + FreeRTOS.org is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License (version 2) as published + by the Free Software Foundation and modified by the FreeRTOS exception. + **NOTE** The exception to the GPL is included to allow you to distribute a + combined work that includes FreeRTOS.org without being obliged to provide + the source code for any proprietary components. Alternative commercial + license and support terms are also available upon request. See the + licensing section of http://www.FreeRTOS.org for full details. - FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. + FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. - You should have received a copy of the GNU General Public License along - with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59 - Temple Place, Suite 330, Boston, MA 02111-1307 USA. + You should have received a copy of the GNU General Public License along + with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59 + Temple Place, Suite 330, Boston, MA 02111-1307 USA. - *************************************************************************** - * * - * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation * - * * - * This is a concise, step by step, 'hands on' guide that describes both * - * general multitasking concepts and FreeRTOS specifics. It presents and * - * explains numerous examples that are written using the FreeRTOS API. * - * Full source code for all the examples is provided in an accompanying * - * .zip file. * - * * - *************************************************************************** + *************************************************************************** + * * + * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation * + * * + * This is a concise, step by step, 'hands on' guide that describes both * + * general multitasking concepts and FreeRTOS specifics. It presents and * + * explains numerous examples that are written using the FreeRTOS API. * + * Full source code for all the examples is provided in an accompanying * + * .zip file. * + * * + *************************************************************************** - 1 tab == 4 spaces! + 1 tab == 4 spaces! - Please ensure to read the configuration and relevant port sections of the - online documentation. + Please ensure to read the configuration and relevant port sections of the + online documentation. - http://www.FreeRTOS.org - Documentation, latest information, license and - contact details. + http://www.FreeRTOS.org - Documentation, latest information, license and + contact details. - http://www.SafeRTOS.com - A version that is certified for use in safety - critical systems. + http://www.SafeRTOS.com - A version that is certified for use in safety + critical systems. - http://www.OpenRTOS.com - Commercial support, development, porting, - licensing and training services. -*/ + http://www.OpenRTOS.com - Commercial support, development, porting, + licensing and training services. + */ #ifndef FREERTOS_CONFIG_H #define FREERTOS_CONFIG_H @@ -60,269 +60,83 @@ * These definitions should be adjusted for your particular hardware and * application requirements. * + * For each atmega or attiny chip have a file, you can reutilizes a existent + * or create a new. + * * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. * * See http://www.freertos.org/a00110.html. *----------------------------------------------------------*/ -// XXX: rsanders testing -#define portBYTE_ALIGNMENT 1 -#define DUINOS_USE_HEAP2 1 - #ifndef FREERTOS_ARDUINO - #define FREERTOS_ARDUINO 1 +#define FREERTOS_ARDUINO 1 #endif - -//##2009.10.29: These values may be improved: #if defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) - - //##Multiplo.Brain.M644: - #define configUSE_PREEMPTION 1 - #define configUSE_IDLE_HOOK 0 - #define configUSE_TICK_HOOK 1 - - //##20091029: Use compiler defined freq.: - #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) - //#define configCPU_CLOCK_HZ ( ( unsigned portLONG ) 18432000 ) - - #define configTICK_RATE_HZ ( ( portTickType ) 1000 ) - //##For these big cpus, it's possible to define more priorities if necessary: - #define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 3 ) - #define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 85 ) - //##Run experiments to test this value: - #define configTOTAL_HEAP_SIZE ( (size_t ) ( 2048 ) ) - //#define configMAX_TASK_NAME_LEN ( 8 ) - #define configMAX_TASK_NAME_LEN ( 16 ) - #define configUSE_TRACE_FACILITY 0 - #define configUSE_16_BIT_TICKS 1 - #define configIDLE_SHOULD_YIELD 0 - #define configQUEUE_REGISTRY_SIZE 0 - - /* Co-routine definitions. */ - //##2009.10.20: defined as "0": - #define configUSE_CO_ROUTINES 0 - #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) - - /* Set the following definitions to 1 to include the API function, or zero - to exclude the API function. */ - #define INCLUDE_vTaskPrioritySet 1 - #define INCLUDE_uxTaskPriorityGet 1 - //##If the following value is set to 1, change the memory managment scheme to heap_2.c: - #define INCLUDE_vTaskDelete 0 - #define INCLUDE_vTaskCleanUpResources 0 - #define INCLUDE_vTaskSuspend 1 - #define INCLUDE_vTaskDelayUntil 1 - #define INCLUDE_vTaskDelay 1 +#include "FreeRTOSConfigATmega644.h" #elif defined(__AVR_ATmega1284P__) - - //##Multiplo.Brain.M1284 - #define configUSE_PREEMPTION 1 - #define configUSE_IDLE_HOOK 0 - #define configUSE_TICK_HOOK 1 - - //##20091029: Use compiler defined freq.: - #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) - //#define configCPU_CLOCK_HZ ( ( unsigned portLONG ) 18432000 ) - - #define configTICK_RATE_HZ ( ( portTickType ) 1000 ) - //##For these big cpus, it's possible to define more priorities if necessary: - #define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 3 ) - #define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 85 ) - //##Run experiments to test this value: - #define configTOTAL_HEAP_SIZE ( (size_t ) ( 4096 ) ) - //#define configMAX_TASK_NAME_LEN ( 8 ) - #define configMAX_TASK_NAME_LEN ( 16 ) - #define configUSE_TRACE_FACILITY 0 - #define configUSE_16_BIT_TICKS 1 - #define configIDLE_SHOULD_YIELD 0 - #define configQUEUE_REGISTRY_SIZE 0 - - /* Co-routine definitions. */ - //##2009.10.20: defined as "0": - #define configUSE_CO_ROUTINES 0 - #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) - - /* Set the following definitions to 1 to include the API function, or zero - to exclude the API function. */ - #define INCLUDE_vTaskPrioritySet 1 - #define INCLUDE_uxTaskPriorityGet 1 - //##If the following value is set to 1, change the memory managment scheme to heap_2.c: - #define INCLUDE_vTaskDelete 0 - #define INCLUDE_vTaskCleanUpResources 0 - #define INCLUDE_vTaskSuspend 1 - #define INCLUDE_vTaskDelayUntil 1 - #define INCLUDE_vTaskDelay 1 +#include "FreeRTOSConfigATmega1284P.h" #elif defined(__AVR_ATmega1280__) - //##Arduino Mega? Not tested yet: - - #define configUSE_PREEMPTION 1 - #define configUSE_IDLE_HOOK 0 - #define configUSE_TICK_HOOK 1 - - //##20091029: Use compiler defined freq.: - #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) - //#define configCPU_CLOCK_HZ ( ( unsigned portLONG ) 16000000 ) +#include "FreeRTOSConfigATmega1280.h" - #define configTICK_RATE_HZ ( ( portTickType ) 1000 ) - //##For these bigger cpus, it's possible to define more priorities if necessary: - #define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 3 ) - #define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 85 ) - //##Run experiments to test this value: - #define configTOTAL_HEAP_SIZE ( (size_t ) ( 4096 ) ) - //#define configMAX_TASK_NAME_LEN ( 8 ) - #define configMAX_TASK_NAME_LEN ( 16 ) - #define configUSE_TRACE_FACILITY 0 - #define configUSE_16_BIT_TICKS 1 - #define configIDLE_SHOULD_YIELD 0 - #define configQUEUE_REGISTRY_SIZE 0 - - /* Co-routine definitions. */ - //##2009.10.20: defined as "0": - #define configUSE_CO_ROUTINES 0 - #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) - - /* Set the following definitions to 1 to include the API function, or zero - to exclude the API function. */ - #define INCLUDE_vTaskPrioritySet 1 - #define INCLUDE_uxTaskPriorityGet 1 - //##If the following value is set to 1, change the memory managment scheme to heap_2.c: - #define INCLUDE_vTaskDelete 0 - #define INCLUDE_vTaskCleanUpResources 0 - #define INCLUDE_vTaskSuspend 1 - #define INCLUDE_vTaskDelayUntil 1 - #define INCLUDE_vTaskDelay 1 - #elif defined(__AVR_ATmega2560__) - //##Arduino Mega 2560? Not tested yet: - //##2010.12.19 reuse the same config that AVR_ATmega1280 for testing - - #define configUSE_PREEMPTION 1 - #define configUSE_IDLE_HOOK 0 - #define configUSE_TICK_HOOK 1 - - //##20091029: Use compiler defined freq.: - #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) - //#define configCPU_CLOCK_HZ ( ( unsigned portLONG ) 16000000 ) - - #define configTICK_RATE_HZ ( ( portTickType ) 1000 ) - //##For these bigger cpus, it's possible to define more priorities if necessary: - #define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 3 ) - #define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 85 ) - //##Run experiments to test this value: - #define configTOTAL_HEAP_SIZE ( (size_t ) ( 4096 ) ) - //#define configMAX_TASK_NAME_LEN ( 8 ) - #define configMAX_TASK_NAME_LEN ( 16 ) - #define configUSE_TRACE_FACILITY 0 - #define configUSE_16_BIT_TICKS 1 - #define configIDLE_SHOULD_YIELD 0 - #define configQUEUE_REGISTRY_SIZE 0 - - /* Co-routine definitions. */ - //##2009.10.20: defined as "0": - #define configUSE_CO_ROUTINES 0 - #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) - - /* Set the following definitions to 1 to include the API function, or zero - to exclude the API function. */ - #define INCLUDE_vTaskPrioritySet 1 - #define INCLUDE_uxTaskPriorityGet 1 - //##If the following value is set to 1, change the memory managment scheme to heap_2.c: - #define INCLUDE_vTaskDelete 1 - #define INCLUDE_vTaskCleanUpResources 0 - #define INCLUDE_vTaskSuspend 1 - #define INCLUDE_vTaskDelayUntil 1 - #define INCLUDE_vTaskDelay 1 +#include "FreeRTOSConfigATmega2560.h" #elif defined(__AVR_ATmega328P__) - //##Mega328p: - - #define configUSE_PREEMPTION 1 - #define configUSE_IDLE_HOOK 0 - #define configUSE_TICK_HOOK 1 - - //##20091029: Use compiler defined freq.: - #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) - //#define configCPU_CLOCK_HZ ( ( unsigned portLONG ) 12000000 ) - - #define configTICK_RATE_HZ ( ( portTickType ) 1000 ) - //##For these bigger cpus, it's possible to define more priorities if necessary: - #define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 3 ) - #define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 85 ) - #define configTOTAL_HEAP_SIZE ( (size_t ) ( 1200 ) ) - #define configMAX_TASK_NAME_LEN ( 8 ) - //#define configMAX_TASK_NAME_LEN ( 16 ) - #define configUSE_TRACE_FACILITY 0 - #define configUSE_16_BIT_TICKS 1 - #define configIDLE_SHOULD_YIELD 0 - #define configQUEUE_REGISTRY_SIZE 0 - #define configUSE_MUTEXES 1 - - /* Co-routine definitions. */ - //##2009.10.20: defined as "0": - #define configUSE_CO_ROUTINES 0 - #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) - - /* Set the following definitions to 1 to include the API function, or zero - to exclude the API function. */ - #define INCLUDE_vTaskPrioritySet 0 - #define INCLUDE_uxTaskPriorityGet 0 - #define INCLUDE_vTaskDelete 0 - #define INCLUDE_vTaskCleanUpResources 0 - #define INCLUDE_vTaskSuspend 1 - #define INCLUDE_vTaskDelayUntil 1 - #define INCLUDE_vTaskDelay 1 +#include "FreeRTOSConfigATmega328P.h" #elif defined(__AVR_ATmega88__) || defined(__AVR_ATmega88P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) - //##Mega88, Mega88p, Mega168, Mega168p: +#include "FreeRTOSConfigATmega168P.h" +#else +#error "Device is not supported by DuinOS" - #define configUSE_PREEMPTION 1 - #define configUSE_IDLE_HOOK 0 - #define configUSE_TICK_HOOK 1 +#endif - //##20091029: Use compiler defined freq.: - #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) - //#define configCPU_CLOCK_HZ ( ( unsigned portLONG ) 12000000 ) +#ifndef configUSE_PREEMPTION +#define configUSE_PREEMPTION 1 +#endif - #define configTICK_RATE_HZ ( ( portTickType ) 1000 ) - //##For these bigger cpus, it's possible to define more priorities if necessary: - #define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 3 ) - #define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 85 ) - //20101220 : decrease heap size from 800 to 500 - see http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1256745982/46#46 - #define configTOTAL_HEAP_SIZE ( (size_t ) ( 500 ) ) - //#define configMAX_TASK_NAME_LEN ( 8 ) - #define configMAX_TASK_NAME_LEN ( 16 ) - #define configUSE_TRACE_FACILITY 0 - #define configUSE_16_BIT_TICKS 1 - #define configIDLE_SHOULD_YIELD 0 - #define configQUEUE_REGISTRY_SIZE 0 +#ifndef configUSE_IDLE_HOOK +#define configUSE_IDLE_HOOK 0 +#endif - /* Co-routine definitions. */ - //##2009.10.20: defined as "0": - #define configUSE_CO_ROUTINES 0 - #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) +#ifndef configUSE_TICK_HOOK +#define configUSE_TICK_HOOK 1 +#endif - /* Set the following definitions to 1 to include the API function, or zero - to exclude the API function. */ - #define INCLUDE_vTaskPrioritySet 0 - #define INCLUDE_uxTaskPriorityGet 0 - #define INCLUDE_vTaskDelete 0 - #define INCLUDE_vTaskCleanUpResources 0 - #define INCLUDE_vTaskSuspend 1 - #define INCLUDE_vTaskDelayUntil 1 - #define INCLUDE_vTaskDelay 1 +#ifndef configCPU_CLOCK_HZ +#define configCPU_CLOCK_HZ ( ( unsigned portLONG ) F_CPU ) +#endif -#else - #error "Device is not supported by DuinOS" +#ifndef configTICK_RATE_HZ +#define configTICK_RATE_HZ ( ( portTickType ) 1000 ) +#endif +#ifndef configMAX_PRIORITIES +#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 3 ) #endif -#if !defined(DUINOS_USE_HEAP1) && ! defined(DUINOS_USE_HEAP2) && !defined(DUINOS_USE_HEAP3) - #define DUINOS_USE_HEAP1 1 + /* setup() and loop() parameters */ +#ifndef configSETUP_STACK_SIZE + #define configSETUP_STACK_SIZE (configMINIMAL_STACK_SIZE) +#endif +#ifndef configLOOP_STACK_SIZE + #define configLOOP_STACK_SIZE (configMINIMAL_STACK_SIZE) +#endif +#ifndef configSETUP_PRIORITY + #define configSETUP_PRIORITY HIGH_PRIORITY +#endif +#ifndef configLOOP_PRIORITY + #define configLOOP_PRIORITY LOW_PRIORITY #endif +#if INCLUDE_vTaskDelete == 1 +#define CONFIG_HEAP_MODEL 2 +#else +#define CONFIG_HEAP_MODEL 1 +#endif #endif /* FREERTOS_CONFIG_H */ diff --git a/arduino.DuinOS.AVR/FreeRTOSConfigATmega1280.h b/arduino.DuinOS.AVR/FreeRTOSConfigATmega1280.h new file mode 100644 index 0000000..c451c13 --- /dev/null +++ b/arduino.DuinOS.AVR/FreeRTOSConfigATmega1280.h @@ -0,0 +1,44 @@ +/* + * FreeRTOSConfigATmega2560.h + * + * Created on: 27/01/2013 + * Author: extracbd + */ + +#ifndef FREERTOSCONFIGATMEGA2560_H_ +#define FREERTOSCONFIGATMEGA2560_H_ + + #define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 85 ) + //##Run experiments to test this value: + #define configTOTAL_HEAP_SIZE ( (size_t ) ( 4096 ) ) + //#define configMAX_TASK_NAME_LEN ( 8 ) + #define configMAX_TASK_NAME_LEN ( 16 ) + #define configUSE_TRACE_FACILITY 0 + #define configUSE_16_BIT_TICKS 1 + #define configIDLE_SHOULD_YIELD 0 + #define configQUEUE_REGISTRY_SIZE 0 + + /* Co-routine definitions. */ + //##2009.10.20: defined as "0": + #define configUSE_CO_ROUTINES 0 + #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + + /* setup() and loop() parameters */ + #define configSETUP_STACK_SIZE (configMINIMAL_STACK_SIZE * 2) + #define configLOOP_STACK_SIZE (configMINIMAL_STACK_SIZE) + #define configSETUP_PRIORITY HIGH_PRIORITY; + #define configLOOP_PRIORITY LOW_PRIORITY; + + /* Set the following definitions to 1 to include the API function, or zero + to exclude the API function. */ + #define INCLUDE_vTaskPrioritySet 1 + #define INCLUDE_uxTaskPriorityGet 1 + //##If the following value is set to 1, change the memory managment scheme to heap_2.c: + #define INCLUDE_vTaskDelete 0 + #define INCLUDE_vTaskCleanUpResources 0 + #define INCLUDE_vTaskSuspend 1 + #define INCLUDE_vTaskDelayUntil 1 + #define INCLUDE_vTaskDelay 1 + #define INCLUDE_xTaskGetSchedulerState 0 + +#endif /* FREERTOSCONFIGATMEGA2560_H_ */ diff --git a/arduino.DuinOS.AVR/FreeRTOSConfigATmega1284P.h b/arduino.DuinOS.AVR/FreeRTOSConfigATmega1284P.h new file mode 100644 index 0000000..8163c45 --- /dev/null +++ b/arduino.DuinOS.AVR/FreeRTOSConfigATmega1284P.h @@ -0,0 +1,44 @@ +/* + * FreeRTOSConfigATmega1284P.h + * + * Created on: 27/01/2013 + * Author: extracbd + */ + +#ifndef FREERTOSCONFIGATMEGA1284P_H_ +#define FREERTOSCONFIGATMEGA1284P_H_ + + #define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 85 ) + //##Run experiments to test this value: + #define configTOTAL_HEAP_SIZE ( (size_t ) ( 4096 ) ) + //#define configMAX_TASK_NAME_LEN ( 8 ) + #define configMAX_TASK_NAME_LEN ( 16 ) + #define configUSE_TRACE_FACILITY 0 + #define configUSE_16_BIT_TICKS 1 + #define configIDLE_SHOULD_YIELD 0 + #define configQUEUE_REGISTRY_SIZE 0 + + /* Co-routine definitions. */ + //##2009.10.20: defined as "0": + #define configUSE_CO_ROUTINES 0 + #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + + /* setup() and loop() parameters */ + #define configSETUP_STACK_SIZE (configMINIMAL_STACK_SIZE * 2) + #define configLOOP_STACK_SIZE (configMINIMAL_STACK_SIZE) + #define configSETUP_PRIORITY HIGH_PRIORITY; + #define configLOOP_PRIORITY LOW_PRIORITY; + + /* Set the following definitions to 1 to include the API function, or zero + to exclude the API function. */ + #define INCLUDE_vTaskPrioritySet 1 + #define INCLUDE_uxTaskPriorityGet 1 + //##If the following value is set to 1, change the memory managment scheme to heap_2.c: + #define INCLUDE_vTaskDelete 0 + #define INCLUDE_vTaskCleanUpResources 0 + #define INCLUDE_vTaskSuspend 1 + #define INCLUDE_vTaskDelayUntil 1 + #define INCLUDE_vTaskDelay 1 + #define INCLUDE_xTaskGetSchedulerState 0 + +#endif /* FREERTOSCONFIGATMEGA1284P_H_ */ diff --git a/arduino.DuinOS.AVR/FreeRTOSConfigATmega168P.h b/arduino.DuinOS.AVR/FreeRTOSConfigATmega168P.h new file mode 100644 index 0000000..baf2f8b --- /dev/null +++ b/arduino.DuinOS.AVR/FreeRTOSConfigATmega168P.h @@ -0,0 +1,43 @@ +/* + * FreeRTOSConfigATmega168P.h + * + * Created on: 27/01/2013 + * Author: extracbd + */ + +#ifndef FREERTOSCONFIGATMEGA168P_H_ +#define FREERTOSCONFIGATMEGA168P_H_ + + #define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 85 ) + //20101220 : decrease heap size from 800 to 500 - see http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1256745982/46#46 + #define configTOTAL_HEAP_SIZE ( (size_t ) ( 500 ) ) + //#define configMAX_TASK_NAME_LEN ( 8 ) + #define configMAX_TASK_NAME_LEN ( 16 ) + #define configUSE_TRACE_FACILITY 0 + #define configUSE_16_BIT_TICKS 1 + #define configIDLE_SHOULD_YIELD 0 + #define configQUEUE_REGISTRY_SIZE 0 + + /* Co-routine definitions. */ + //##2009.10.20: defined as "0": + #define configUSE_CO_ROUTINES 0 + #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + + /* setup() and loop() parameters */ + #define configSETUP_STACK_SIZE (configMINIMAL_STACK_SIZE * 2) + #define configLOOP_STACK_SIZE (configMINIMAL_STACK_SIZE) + #define configSETUP_PRIORITY HIGH_PRIORITY; + #define configSETUP_PRIORITY LOW_PRIORITY; + + /* Set the following definitions to 1 to include the API function, or zero + to exclude the API function. */ + #define INCLUDE_vTaskPrioritySet 0 + #define INCLUDE_uxTaskPriorityGet 0 + #define INCLUDE_vTaskDelete 0 + #define INCLUDE_vTaskCleanUpResources 0 + #define INCLUDE_vTaskSuspend 1 + #define INCLUDE_vTaskDelayUntil 1 + #define INCLUDE_vTaskDelay 1 + #define INCLUDE_xTaskGetSchedulerState 0 + +#endif /* FREERTOSCONFIGATMEGA168P_H_ */ diff --git a/arduino.DuinOS.AVR/FreeRTOSConfigATmega2560.h b/arduino.DuinOS.AVR/FreeRTOSConfigATmega2560.h new file mode 100644 index 0000000..f9b6fc7 --- /dev/null +++ b/arduino.DuinOS.AVR/FreeRTOSConfigATmega2560.h @@ -0,0 +1,42 @@ +/* + * FreeRTOSConfigATmega2560.h + * + * Created on: 27/01/2013 + * Author: extracbd + */ + +#ifndef FREERTOSCONFIGATMEGA2560_H_ +#define FREERTOSCONFIGATMEGA2560_H_ + +#define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 85 ) +#define configTOTAL_HEAP_SIZE ( (size_t ) ( 4096 ) ) +#define configMAX_TASK_NAME_LEN ( 16 ) +#define configUSE_TRACE_FACILITY 0 +#define configUSE_16_BIT_TICKS 1 +#define configIDLE_SHOULD_YIELD 0 +#define configQUEUE_REGISTRY_SIZE 0 + +/* Co-routine definitions. */ +//##2009.10.20: defined as "0": +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + +/* setup() and loop() parameters */ +#define configSETUP_STACK_SIZE (configMINIMAL_STACK_SIZE * 4) +#define configLOOP_STACK_SIZE (configMINIMAL_STACK_SIZE * 2) +#define configSETUP_PRIORITY HIGH_PRIORITY; +#define configLOOP_PRIORITY LOW_PRIORITY; + +/* Set the following definitions to 1 to include the API function, or zero + to exclude the API function. */ +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +//##If the following value is set to 1, change the memory managment scheme to heap_2.c: +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetSchedulerState 1 + +#endif /* FREERTOSCONFIGATMEGA2560_H_ */ diff --git a/arduino.DuinOS.AVR/FreeRTOSConfigATmega328P.h b/arduino.DuinOS.AVR/FreeRTOSConfigATmega328P.h new file mode 100644 index 0000000..5fd959f --- /dev/null +++ b/arduino.DuinOS.AVR/FreeRTOSConfigATmega328P.h @@ -0,0 +1,43 @@ +/* + * FreeRTOSConfigATmega328P.h + * + * Created on: 27/01/2013 + * Author: extracbd + */ + +#ifndef FREERTOSCONFIGATMEGA328P_H_ +#define FREERTOSCONFIGATMEGA328P_H_ + + #define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 85 ) + #define configTOTAL_HEAP_SIZE ( (size_t ) ( 1200 ) ) + #define configMAX_TASK_NAME_LEN ( 8 ) + //#define configMAX_TASK_NAME_LEN ( 16 ) + #define configUSE_TRACE_FACILITY 0 + #define configUSE_16_BIT_TICKS 1 + #define configIDLE_SHOULD_YIELD 0 + #define configQUEUE_REGISTRY_SIZE 0 + #define configUSE_MUTEXES 1 + + /* Co-routine definitions. */ + //##2009.10.20: defined as "0": + #define configUSE_CO_ROUTINES 0 + #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + + /* setup() and loop() parameters */ + #define configSETUP_STACK_SIZE (configMINIMAL_STACK_SIZE * 2) + #define configLOOP_STACK_SIZE (configMINIMAL_STACK_SIZE) + #define configSETUP_PRIORITY HIGH_PRIORITY; + #define configSETUP_PRIORITY LOW_PRIORITY; + + /* Set the following definitions to 1 to include the API function, or zero + to exclude the API function. */ + #define INCLUDE_vTaskPrioritySet 0 + #define INCLUDE_uxTaskPriorityGet 0 + #define INCLUDE_vTaskDelete 0 + #define INCLUDE_vTaskCleanUpResources 0 + #define INCLUDE_vTaskSuspend 1 + #define INCLUDE_vTaskDelayUntil 1 + #define INCLUDE_vTaskDelay 1 + #define INCLUDE_xTaskGetSchedulerState 0 + +#endif /* FREERTOSCONFIGATMEGA328P_H_ */ diff --git a/arduino.DuinOS.AVR/FreeRTOSConfigATmega644.h b/arduino.DuinOS.AVR/FreeRTOSConfigATmega644.h new file mode 100644 index 0000000..8dbfb51 --- /dev/null +++ b/arduino.DuinOS.AVR/FreeRTOSConfigATmega644.h @@ -0,0 +1,44 @@ +/* + * FreeRTOSConfigATmega644.h + * + * Created on: 27/01/2013 + * Author: extracbd + */ + +#ifndef FREERTOSCONFIGATMEGA644_H_ +#define FREERTOSCONFIGATMEGA644_H_ + +#define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 85 ) +//##Run experiments to test this value: +#define configTOTAL_HEAP_SIZE ( (size_t ) ( 2048 ) ) +//#define configMAX_TASK_NAME_LEN ( 8 ) +#define configMAX_TASK_NAME_LEN ( 16 ) +#define configUSE_TRACE_FACILITY 0 +#define configUSE_16_BIT_TICKS 1 +#define configIDLE_SHOULD_YIELD 0 +#define configQUEUE_REGISTRY_SIZE 0 + +/* Co-routine definitions. */ +//##2009.10.20: defined as "0": +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + + /* setup() and loop() parameters */ + #define configSETUP_STACK_SIZE (configMINIMAL_STACK_SIZE * 2) + #define configLOOP_STACK_SIZE (configMINIMAL_STACK_SIZE) + #define configSETUP_PRIORITY HIGH_PRIORITY; + #define configSETUP_PRIORITY LOW_PRIORITY; + +/* Set the following definitions to 1 to include the API function, or zero + to exclude the API function. */ +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +//##If the following value is set to 1, change the memory managment scheme to heap_2.c: +#define INCLUDE_vTaskDelete 0 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetSchedulerState 0 + +#endif /* FREERTOSCONFIGATMEGA644_H_ */ diff --git a/arduino.DuinOS.AVR/FreeRTOSConfigATtiny.h b/arduino.DuinOS.AVR/FreeRTOSConfigATtiny.h new file mode 100644 index 0000000..ed55806 --- /dev/null +++ b/arduino.DuinOS.AVR/FreeRTOSConfigATtiny.h @@ -0,0 +1,42 @@ +/* + * FreeRTOSConfigATmega168P.h + * + * Created on: 27/01/2013 + * Author: extracbd + */ + +#ifndef FREERTOSCONFIGATMEGA168P_H_ +#define FREERTOSCONFIGATMEGA168P_H_ + + #define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 60 ) + //20101220 : decrease heap size from 800 to 500 - see http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1256745982/46#46 + #define configTOTAL_HEAP_SIZE ( (size_t ) ( 250 ) ) + #define configMAX_TASK_NAME_LEN ( 8 ) + #define configUSE_TRACE_FACILITY 0 + #define configUSE_16_BIT_TICKS 1 + #define configIDLE_SHOULD_YIELD 0 + #define configQUEUE_REGISTRY_SIZE 0 + + /* Co-routine definitions. */ + //##2009.10.20: defined as "0": + #define configUSE_CO_ROUTINES 1 + #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + + /* setup() and loop() parameters */ + #define configSETUP_STACK_SIZE (configMINIMAL_STACK_SIZE * 1.5) + #define configLOOP_STACK_SIZE (configMINIMAL_STACK_SIZE) + #define configSETUP_PRIORITY HIGH_PRIORITY; + #define configSETUP_PRIORITY LOW_PRIORITY; + + /* Set the following definitions to 1 to include the API function, or zero + to exclude the API function. */ + #define INCLUDE_vTaskPrioritySet 0 + #define INCLUDE_uxTaskPriorityGet 0 + #define INCLUDE_vTaskDelete 0 + #define INCLUDE_vTaskCleanUpResources 0 + #define INCLUDE_vTaskSuspend 1 + #define INCLUDE_vTaskDelayUntil 1 + #define INCLUDE_vTaskDelay 1 + #define INCLUDE_xTaskGetSchedulerState 0 + +#endif /* FREERTOSCONFIGATMEGA168P_H_ */ diff --git a/arduino.DuinOS.AVR/HardwareSerial.cpp b/arduino.DuinOS.AVR/HardwareSerial.cpp index 719f3f6..794a7be 100644 --- a/arduino.DuinOS.AVR/HardwareSerial.cpp +++ b/arduino.DuinOS.AVR/HardwareSerial.cpp @@ -36,8 +36,7 @@ /* * on ATmega8, the uart and its bits are not numbered, so there is no "TXC0" - * definition. It is slightly cleaner to define this here instead of having - * conditional code in the cpp module. + * definition. */ #if !defined(TXC0) #if defined(TXC) diff --git a/arduino.DuinOS.AVR/HardwareSerial.h b/arduino.DuinOS.AVR/HardwareSerial.h index 2b1de91..a73117f 100644 --- a/arduino.DuinOS.AVR/HardwareSerial.h +++ b/arduino.DuinOS.AVR/HardwareSerial.h @@ -110,22 +110,6 @@ class HardwareSerial : public Stream extern HardwareSerial Serial3; #endif -/* - * on ATmega8, the uart and its bits are not numbered, so there is no "TXC0" - * definition. It is slightly cleaner to define this here instead of having - * conditional code in the cpp module. - */ -#if !defined(TXC0) -#if defined(TXC) -#define TXC0 TXC -#elif defined(TXC1) -// Some devices have uart1 but no uart0 -#define TXC0 TXC1 -#else -#error TXC0 not definable in HardwareSerial.h -#endif -#endif - extern void serialEventRun(void) __attribute__((weak)); #endif diff --git a/arduino.DuinOS.AVR/hooks.c b/arduino.DuinOS.AVR/hooks.c new file mode 100644 index 0000000..affd77b --- /dev/null +++ b/arduino.DuinOS.AVR/hooks.c @@ -0,0 +1,28 @@ +/* + Copyright (c) 2012 Arduino. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +/** + * Empty yield() hook. + * + * This function is intended to be used by library writers to build + * libraries or sketches that supports cooperative threads. + * + * Its defined as a weak symbol and it can be redefined to implement a + * real cooperative scheduler. + */ +#define yield() nextTask() \ No newline at end of file diff --git a/arduino.DuinOS.AVR/main.cpp b/arduino.DuinOS.AVR/main.cpp index dfa6280..4a7fe71 100644 --- a/arduino.DuinOS.AVR/main.cpp +++ b/arduino.DuinOS.AVR/main.cpp @@ -1,19 +1,16 @@ +#include #include - -unsigned portBASE_TYPE mainSetupPriority; -unsigned portBASE_TYPE mainSetupStackSize; -unsigned portBASE_TYPE mainLoopPriority; -unsigned portBASE_TYPE mainLoopStackSize; +unsigned portBASE_TYPE mainSetupPriority = configSETUP_PRIORITY; +unsigned portBASE_TYPE mainSetupStackSize = configMINIMAL_STACK_SIZE * 5; +unsigned portBASE_TYPE mainLoopPriority = configLOOP_PRIORITY; +unsigned portBASE_TYPE mainLoopStackSize = configMINIMAL_STACK_SIZE; xTaskHandle xHandleLoop; xTaskHandle xHandleSetup; void main_Task(void *pvParameters) { -#if INCLUDE_vTaskDelete - vTaskDelete(xHandleSetup); -#endif for (;;) { loop(); if (serialEventRun) serialEventRun(); @@ -25,30 +22,28 @@ void setup_Task(void *pvParameters) { setup(); - vTaskResume(xHandleLoop); - vTaskSuspend(NULL); + + xTaskCreate(main_Task, (signed portCHAR *) "main", mainLoopStackSize, NULL, mainLoopPriority, &xHandleLoop); + +#if INCLUDE_vTaskDelete + vTaskDelete(xHandleSetup); +#else + while(true) vTaskSuspend(NULL); +#endif } int main(void) { - mainSetupPriority = HIGH_PRIORITY; - mainSetupStackSize = configMINIMAL_STACK_SIZE * 2; - mainLoopPriority = LOW_PRIORITY; - mainLoopStackSize = configMINIMAL_STACK_SIZE; + init(); #if defined(USBCON) USBDevice.attach(); #endif -// setup(); - xTaskCreate(setup_Task, (signed portCHAR *) "setup", mainSetupStackSize, NULL, mainSetupStackSize, &xHandleSetup); - xTaskCreate(main_Task, (signed portCHAR *) "main", mainLoopStackSize, NULL, mainLoopPriority, &xHandleLoop); - vTaskSuspend(xHandleLoop); - vTaskStartScheduler(); for (;;); diff --git a/arduino.DuinOS.AVR/malloc.c b/arduino.DuinOS.AVR/malloc.c index 7115672..9c56600 100644 --- a/arduino.DuinOS.AVR/malloc.c +++ b/arduino.DuinOS.AVR/malloc.c @@ -32,7 +32,7 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - + #include #include @@ -58,7 +58,7 @@ struct __freelist { * calls must not require more stack space, or they'll risk to collide * with the data segment. */ - + #define STACK_POINTER() ((char *)AVR_STACK_POINTER_REG) extern char __heap_start; diff --git a/arduino.DuinOS.AVR/merge-todo.ext b/arduino.DuinOS.AVR/merge-todo.ext new file mode 100644 index 0000000..a3b12d7 --- /dev/null +++ b/arduino.DuinOS.AVR/merge-todo.ext @@ -0,0 +1,9 @@ +merge-todo.ext + + Created on: 29/01/2013 + Author: Carlos Delfino (consultoria@carlosdelfino.eti.br) + +Ao fazer o Merge dos Branchs e Tags verificar sempre os itens abaixo: + +O Arquivo portable.h deve ser verificado já que tirei deste as verificaçòes a chamadas para multiplataforma + diff --git a/arduino.DuinOS.AVR/wiring.c b/arduino.DuinOS.AVR/wiring.c index 5b9167d..b2587ee 100644 --- a/arduino.DuinOS.AVR/wiring.c +++ b/arduino.DuinOS.AVR/wiring.c @@ -115,6 +115,7 @@ void delay(unsigned long ms) uint16_t start = (uint16_t)micros(); while (ms > 0) { + yield(); if (((uint16_t)micros() - start) >= 1000) { ms--; start += 1000; diff --git a/temp.txt b/temp.txt new file mode 100644 index 0000000..b1a4597 --- /dev/null +++ b/temp.txt @@ -0,0 +1,10 @@ +Atualização do DuinOS para o FreeRTOS V7.4.0 +1831: +Prepare for V7.4.0 release. +1829: +Correct spelling of xSuspendedTaskList in eTaskConfirmSleepModeStatus(). +1828: +Add default definition for configUSE_QUEUE_SETS. +Add eTaskConfirmSleepModeStatus() (not yet tested). +Only call prvQueueUnregisterQueue() when a queue or semaphore is deleted if configQUEUE_REGISTRY_SIZE > 0. +Back out change that checks the configUSE_PORT_OPTMISED_TASK_SELECTION value before uxPriorityUsedOnEntry is set in vTaskPrioritySet as it generated more warnings (with other compilers) than it fixed. From 8ed11c4f98a5b84c99a9b7811b7c6f6aa8014ead Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Fri, 22 Feb 2013 12:01:26 -0300 Subject: [PATCH 39/56] =?UTF-8?q?Corre=C3=A7=C3=A3o=20no=20arquivo=20task.?= =?UTF-8?q?c=20devido=20a=20erros=20inseridos=20no=20ultimo=20merge=20com?= =?UTF-8?q?=20o=20FreeRTOS=20V7.4.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arduino.DuinOS.AVR/DuinOS/tasks.c | 45 ++----------------------------- 1 file changed, 2 insertions(+), 43 deletions(-) diff --git a/arduino.DuinOS.AVR/DuinOS/tasks.c b/arduino.DuinOS.AVR/DuinOS/tasks.c index 846f0b2..51b75b4 100644 --- a/arduino.DuinOS.AVR/DuinOS/tasks.c +++ b/arduino.DuinOS.AVR/DuinOS/tasks.c @@ -491,12 +491,6 @@ static tskTCB *prvAllocateTCBAndStack( unsigned short usStackDepth, portSTACK_TY /*lint +e956 */ - - -/*----------------------------------------------------------- - * TASK CREATION API documented in task.h - *----------------------------------------------------------*/ - signed portBASE_TYPE xTaskGenericCreate( pdTASK_CODE pxTaskCode, const signed char * const pcName, unsigned short usStackDepth, void *pvParameters, unsigned portBASE_TYPE uxPriority, xTaskHandle *pxCreatedTask, portSTACK_TYPE *puxStackBuffer, const xMemoryRegion * const xRegions ) { signed portBASE_TYPE xReturn; @@ -720,15 +714,7 @@ tskTCB * pxNewTCB; } #endif /* INCLUDE_vTaskDelete */ - - - - - - -/*----------------------------------------------------------- - * TASK CONTROL API documented in task.h - *----------------------------------------------------------*/ +/*-----------------------------------------------------------*/ #if ( INCLUDE_vTaskDelayUntil == 1 ) @@ -1241,11 +1227,7 @@ tskTCB * pxNewTCB; } #endif /* ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) ) */ - -/*----------------------------------------------------------- - * PUBLIC SCHEDULER CONTROL documented in task.h - *----------------------------------------------------------*/ - +/*-----------------------------------------------------------*/ void vTaskStartScheduler( void ) { @@ -1440,17 +1422,6 @@ signed portBASE_TYPE xAlreadyYielded = pdFALSE; } /*-----------------------------------------------------------*/ - - - - - -/*----------------------------------------------------------- - * PUBLIC TASK UTILITIES documented in task.h - *----------------------------------------------------------*/ - - - portTickType xTaskGetTickCount( void ) { portTickType xTicks; @@ -1668,11 +1639,6 @@ implementations require configUSE_TICKLESS_IDLE to be set to a value other than #endif /* configUSE_TICKLESS_IDLE */ /*----------------------------------------------------------*/ -/*----------------------------------------------------------- - * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES - * documented in task.h - *----------------------------------------------------------*/ - void vTaskIncrementTick( void ) { tskTCB * pxTCB; @@ -2255,13 +2221,6 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters ) #endif /* configUSE_TICKLESS_IDLE */ /*-----------------------------------------------------------*/ - -/*----------------------------------------------------------- - * File private functions documented at the top of the file. - *----------------------------------------------------------*/ - - - static void prvInitialiseTCBVariables( tskTCB *pxTCB, const signed char * const pcName, unsigned portBASE_TYPE uxPriority, const xMemoryRegion * const xRegions, unsigned short usStackDepth ) { /* Store the function name in the TCB. */ From 8bdfe8864a17a80d54bc1f43060b8d0b57c383ed Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Fri, 22 Feb 2013 12:05:11 -0300 Subject: [PATCH 40/56] =?UTF-8?q?Corre=C3=A7=C3=A3o=20nas=20constantes=20q?= =?UTF-8?q?ue=20define=20prioridade=20do=20Loop=20e=20Setup.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arduino.DuinOS.AVR/FreeRTOSConfigATmega1280.h | 4 ++-- arduino.DuinOS.AVR/FreeRTOSConfigATmega1284P.h | 4 ++-- arduino.DuinOS.AVR/FreeRTOSConfigATmega168P.h | 4 ++-- arduino.DuinOS.AVR/FreeRTOSConfigATmega2560.h | 4 ++-- arduino.DuinOS.AVR/FreeRTOSConfigATmega328P.h | 4 ++-- arduino.DuinOS.AVR/FreeRTOSConfigATmega644.h | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/arduino.DuinOS.AVR/FreeRTOSConfigATmega1280.h b/arduino.DuinOS.AVR/FreeRTOSConfigATmega1280.h index c451c13..25bf1c4 100644 --- a/arduino.DuinOS.AVR/FreeRTOSConfigATmega1280.h +++ b/arduino.DuinOS.AVR/FreeRTOSConfigATmega1280.h @@ -26,8 +26,8 @@ /* setup() and loop() parameters */ #define configSETUP_STACK_SIZE (configMINIMAL_STACK_SIZE * 2) #define configLOOP_STACK_SIZE (configMINIMAL_STACK_SIZE) - #define configSETUP_PRIORITY HIGH_PRIORITY; - #define configLOOP_PRIORITY LOW_PRIORITY; + #define configSETUP_PRIORITY HIGH_PRIORITY + #define configLOOP_PRIORITY LOW_PRIORITY /* Set the following definitions to 1 to include the API function, or zero to exclude the API function. */ diff --git a/arduino.DuinOS.AVR/FreeRTOSConfigATmega1284P.h b/arduino.DuinOS.AVR/FreeRTOSConfigATmega1284P.h index 8163c45..9d162fd 100644 --- a/arduino.DuinOS.AVR/FreeRTOSConfigATmega1284P.h +++ b/arduino.DuinOS.AVR/FreeRTOSConfigATmega1284P.h @@ -26,8 +26,8 @@ /* setup() and loop() parameters */ #define configSETUP_STACK_SIZE (configMINIMAL_STACK_SIZE * 2) #define configLOOP_STACK_SIZE (configMINIMAL_STACK_SIZE) - #define configSETUP_PRIORITY HIGH_PRIORITY; - #define configLOOP_PRIORITY LOW_PRIORITY; + #define configSETUP_PRIORITY HIGH_PRIORITY + #define configLOOP_PRIORITY LOW_PRIORITY /* Set the following definitions to 1 to include the API function, or zero to exclude the API function. */ diff --git a/arduino.DuinOS.AVR/FreeRTOSConfigATmega168P.h b/arduino.DuinOS.AVR/FreeRTOSConfigATmega168P.h index baf2f8b..1dea86c 100644 --- a/arduino.DuinOS.AVR/FreeRTOSConfigATmega168P.h +++ b/arduino.DuinOS.AVR/FreeRTOSConfigATmega168P.h @@ -26,8 +26,8 @@ /* setup() and loop() parameters */ #define configSETUP_STACK_SIZE (configMINIMAL_STACK_SIZE * 2) #define configLOOP_STACK_SIZE (configMINIMAL_STACK_SIZE) - #define configSETUP_PRIORITY HIGH_PRIORITY; - #define configSETUP_PRIORITY LOW_PRIORITY; + #define configSETUP_PRIORITY HIGH_PRIORITY + #define configSETUP_PRIORITY LOW_PRIORITY /* Set the following definitions to 1 to include the API function, or zero to exclude the API function. */ diff --git a/arduino.DuinOS.AVR/FreeRTOSConfigATmega2560.h b/arduino.DuinOS.AVR/FreeRTOSConfigATmega2560.h index f9b6fc7..b0d55ed 100644 --- a/arduino.DuinOS.AVR/FreeRTOSConfigATmega2560.h +++ b/arduino.DuinOS.AVR/FreeRTOSConfigATmega2560.h @@ -24,8 +24,8 @@ /* setup() and loop() parameters */ #define configSETUP_STACK_SIZE (configMINIMAL_STACK_SIZE * 4) #define configLOOP_STACK_SIZE (configMINIMAL_STACK_SIZE * 2) -#define configSETUP_PRIORITY HIGH_PRIORITY; -#define configLOOP_PRIORITY LOW_PRIORITY; +#define configSETUP_PRIORITY HIGH_PRIORITY +#define configLOOP_PRIORITY LOW_PRIORITY /* Set the following definitions to 1 to include the API function, or zero to exclude the API function. */ diff --git a/arduino.DuinOS.AVR/FreeRTOSConfigATmega328P.h b/arduino.DuinOS.AVR/FreeRTOSConfigATmega328P.h index 5fd959f..a1df325 100644 --- a/arduino.DuinOS.AVR/FreeRTOSConfigATmega328P.h +++ b/arduino.DuinOS.AVR/FreeRTOSConfigATmega328P.h @@ -26,8 +26,8 @@ /* setup() and loop() parameters */ #define configSETUP_STACK_SIZE (configMINIMAL_STACK_SIZE * 2) #define configLOOP_STACK_SIZE (configMINIMAL_STACK_SIZE) - #define configSETUP_PRIORITY HIGH_PRIORITY; - #define configSETUP_PRIORITY LOW_PRIORITY; + #define configSETUP_PRIORITY HIGH_PRIORITY + #define configSETUP_PRIORITY LOW_PRIORITY /* Set the following definitions to 1 to include the API function, or zero to exclude the API function. */ diff --git a/arduino.DuinOS.AVR/FreeRTOSConfigATmega644.h b/arduino.DuinOS.AVR/FreeRTOSConfigATmega644.h index 8dbfb51..95196cd 100644 --- a/arduino.DuinOS.AVR/FreeRTOSConfigATmega644.h +++ b/arduino.DuinOS.AVR/FreeRTOSConfigATmega644.h @@ -26,8 +26,8 @@ /* setup() and loop() parameters */ #define configSETUP_STACK_SIZE (configMINIMAL_STACK_SIZE * 2) #define configLOOP_STACK_SIZE (configMINIMAL_STACK_SIZE) - #define configSETUP_PRIORITY HIGH_PRIORITY; - #define configSETUP_PRIORITY LOW_PRIORITY; + #define configSETUP_PRIORITY HIGH_PRIORITY + #define configSETUP_PRIORITY LOW_PRIORITY /* Set the following definitions to 1 to include the API function, or zero to exclude the API function. */ From 6c910f754447e6c4961bfd6c5496720518dfa61f Mon Sep 17 00:00:00 2001 From: Nicolas Sanz Date: Mon, 11 Mar 2013 16:57:14 -0400 Subject: [PATCH 41/56] Added the ability to save RAMPZ and EIND registers (Atmega2560 has it) (cherry picked from commit 001281e45fcb0a2ef89d8f149776f41ae867731a) --- arduino.DuinOS.AVR/DuinOS/port.c | 182 +++++++++++++++++++++++++------ 1 file changed, 146 insertions(+), 36 deletions(-) diff --git a/arduino.DuinOS.AVR/DuinOS/port.c b/arduino.DuinOS.AVR/DuinOS/port.c index 04bc16f..5692621 100644 --- a/arduino.DuinOS.AVR/DuinOS/port.c +++ b/arduino.DuinOS.AVR/DuinOS/port.c @@ -1,7 +1,7 @@ /* - FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd. + FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. - FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** @@ -29,23 +29,20 @@ FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - - >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to + >>>NOTE<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS - kernel. - - FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - details. You should have received a copy of the GNU General Public License - and the FreeRTOS license exception along with FreeRTOS; if not itcan be - viewed here: http://www.freertos.org/a00114.html and also obtained by - writing to Real Time Engineers Ltd., contact details for whom are available - on the FreeRTOS WEB site. + kernel. FreeRTOS is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. You should have received a copy of the GNU General Public + License and the FreeRTOS license exception along with FreeRTOS; if not it + can be viewed here: http://www.freertos.org/a00114.html and also obtained + by writing to Richard Barry, contact details for whom are available on the + FreeRTOS WEB site. 1 tab == 4 spaces! - + *************************************************************************** * * * Having a problem? Start by reading the FAQ "My application does * @@ -55,21 +52,18 @@ * * *************************************************************************** - - http://www.FreeRTOS.org - Documentation, books, training, latest versions, - license and Real Time Engineers Ltd. contact details. - + + http://www.FreeRTOS.org - Documentation, training, latest versions, license + and contact details. + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool, and our new - fully thread aware and reentrant UDP/IP stack. + including FreeRTOS+Trace - an indispensable productivity tool. - http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High - Integrity Systems, who sell the code with commercial support, - indemnification and middleware, under the OpenRTOS brand. - - http://www.SafeRTOS.com - High Integrity Systems also provide a safety - engineered and independently SIL3 certified version for use in safety and - mission critical applications that require provable dependability. + Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell + the code with commercial support, indemnification, and middleware, under + the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also + provide a safety engineered and independently SIL3 certified version under + the SafeRTOS brand: http://www.SafeRTOS.com. */ /* @@ -125,7 +119,56 @@ extern volatile tskTCB * volatile pxCurrentTCB; * The interrupts will have been disabled during the call to portSAVE_CONTEXT() * so we need not worry about reading/writing to the stack pointer. */ - +#if defined(__AVR_ATmega2560__) +#define portSAVE_CONTEXT() \ + asm volatile ( "push r0 \n\t" \ + "in r0, __SREG__ \n\t" \ + "cli \n\t" \ + "push r0 \n\t" \ + "push r0 \n\t" \ + "in r0, 0x3b \n\t" \ + "push r0 \n\t" \ + "in r0, 0x3c \n\t" \ + "push r1 \n\t" \ + "clr r1 \n\t" \ + "push r2 \n\t" \ + "push r3 \n\t" \ + "push r4 \n\t" \ + "push r5 \n\t" \ + "push r6 \n\t" \ + "push r7 \n\t" \ + "push r8 \n\t" \ + "push r9 \n\t" \ + "push r10 \n\t" \ + "push r11 \n\t" \ + "push r12 \n\t" \ + "push r13 \n\t" \ + "push r14 \n\t" \ + "push r15 \n\t" \ + "push r16 \n\t" \ + "push r17 \n\t" \ + "push r18 \n\t" \ + "push r19 \n\t" \ + "push r20 \n\t" \ + "push r21 \n\t" \ + "push r22 \n\t" \ + "push r23 \n\t" \ + "push r24 \n\t" \ + "push r25 \n\t" \ + "push r26 \n\t" \ + "push r27 \n\t" \ + "push r28 \n\t" \ + "push r29 \n\t" \ + "push r30 \n\t" \ + "push r31 \n\t" \ + "lds r26, pxCurrentTCB \n\t" \ + "lds r27, pxCurrentTCB + 1 \n\t" \ + "in r0, 0x3d \n\t" \ + "st x+, r0 \n\t" \ + "in r0, 0x3e \n\t" \ + "st x+, r0 \n\t" \ + ); +#else #define portSAVE_CONTEXT() \ asm volatile ( "push r0 \n\t" \ "in r0, __SREG__ \n\t" \ @@ -170,12 +213,14 @@ extern volatile tskTCB * volatile pxCurrentTCB; "in r0, 0x3e \n\t" \ "st x+, r0 \n\t" \ ); +#endif /* * Opposite to portSAVE_CONTEXT(). Interrupts will have been disabled during * the context save so we can write to the stack pointer. */ +#if defined(__AVR_ATmega2560__) #define portRESTORE_CONTEXT() \ asm volatile ( "lds r26, pxCurrentTCB \n\t" \ "lds r27, pxCurrentTCB + 1 \n\t" \ @@ -215,9 +260,61 @@ extern volatile tskTCB * volatile pxCurrentTCB; "pop r2 \n\t" \ "pop r1 \n\t" \ "pop r0 \n\t" \ + "out 0x3c, r0 \n\t" \ + "pop r0 \n\t" \ + "out 0x3b, r0 \n\t" \ + "pop r0 \n\t" \ "out __SREG__, r0 \n\t" \ "pop r0 \n\t" \ ); +#else +#define portRESTORE_CONTEXT() \ + asm volatile ( "lds r26, pxCurrentTCB \n\t" \ + "lds r27, pxCurrentTCB + 1 \n\t" \ + "ld r28, x+ \n\t" \ + "out __SP_L__, r28 \n\t" \ + "ld r29, x+ \n\t" \ + "out __SP_H__, r29 \n\t" \ + "pop r31 \n\t" \ + "pop r30 \n\t" \ + "pop r29 \n\t" \ + "pop r28 \n\t" \ + "pop r27 \n\t" \ + "pop r26 \n\t" \ + "pop r25 \n\t" \ + "pop r24 \n\t" \ + "pop r23 \n\t" \ + "pop r22 \n\t" \ + "pop r21 \n\t" \ + "pop r20 \n\t" \ + "pop r19 \n\t" \ + "pop r18 \n\t" \ + "pop r17 \n\t" \ + "pop r16 \n\t" \ + "pop r15 \n\t" \ + "pop r14 \n\t" \ + "pop r13 \n\t" \ + "pop r12 \n\t" \ + "pop r11 \n\t" \ + "pop r10 \n\t" \ + "pop r9 \n\t" \ + "pop r8 \n\t" \ + "pop r7 \n\t" \ + "pop r6 \n\t" \ + "pop r5 \n\t" \ + "pop r4 \n\t" \ + "pop r3 \n\t" \ + "pop r2 \n\t" \ + "pop r1 \n\t" \ + "pop r0 \n\t" \ + "out 0x3c, r0 \n\t" \ + "pop r0 \n\t" \ + "out 0x3b, r0 \n\t" \ + "pop r0 \n\t" \ + "out __SREG__, r0 \n\t" \ + "pop r0 \n\t" \ + ); +#endif /*-----------------------------------------------------------*/ @@ -232,13 +329,14 @@ static void prvSetupTimerInterrupt( void ); */ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ) { - /* ATmega2560 DuinOS port by SkyWodd */ -#if defined(__AVR_ATmega2560__) - unsigned portLONG usAddress; // ATMega2560 have 22bit Program Counter register -#else - unsigned portSHORT usAddress; // over ATmega have 16bit Program Counter register -#endif - +#if defined(__AVR_ATmega2560__) + /* ATmega2560 DuinOS port by SkyWodd + * Corrected by NiesteSzeck*/ + unsigned portLONG usAddress; // ATMega2560 have 17bit Program Counter register +#else + unsigned portSHORT usAddress; // over ATmega have 16bit Program Counter register +#endif + /* Place a few bytes of known values on the bottom of the stack. This is just useful for debugging. */ @@ -292,6 +390,18 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE *pxTopOfStack = portFLAGS_INT_ENABLED; pxTopOfStack--; +#if defined(__AVR_ATmega2560__) + + /* The Atmega2560 has two more register that we are saving + * The EIND and AMPZ and wea re going to initialize + * this registers to 0 (default initial values) + */ + *pxTopOfStack = ( portSTACK_TYPE ) 0x00; /* EIND */ + pxTopOfStack--; + *pxTopOfStack = ( portSTACK_TYPE ) 0x00; /* RAMPZ */ + pxTopOfStack--; + +#endif /* Now the remaining registers. The compiler expects R1 to be 0. */ *pxTopOfStack = ( portSTACK_TYPE ) 0x00; /* R1 */ From 3abe8a53828a192bebef64e4627f86715dade588 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Wed, 13 Mar 2013 13:52:59 -0300 Subject: [PATCH 42/56] added step to merge process description file. --- arduino.DuinOS.AVR/merge-todo.ext | 1 + 1 file changed, 1 insertion(+) diff --git a/arduino.DuinOS.AVR/merge-todo.ext b/arduino.DuinOS.AVR/merge-todo.ext index a3b12d7..abc26a7 100644 --- a/arduino.DuinOS.AVR/merge-todo.ext +++ b/arduino.DuinOS.AVR/merge-todo.ext @@ -7,3 +7,4 @@ Ao fazer o Merge dos Branchs e Tags verificar sempre os itens abaixo: O Arquivo portable.h deve ser verificado já que tirei deste as verificaçòes a chamadas para multiplataforma +Sempre ler o arquivo: http://www.freertos.org/History.txt \ No newline at end of file From 2681f94107db02fb93da0a76348578000c71c91c Mon Sep 17 00:00:00 2001 From: Nicolas Sanz Date: Fri, 15 Mar 2013 15:45:23 -0300 Subject: [PATCH 43/56] updated to freeRTOS v7.4.0 --- arduino.DuinOS.AVR/DuinOS/port.c | 52 ++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/arduino.DuinOS.AVR/DuinOS/port.c b/arduino.DuinOS.AVR/DuinOS/port.c index 5692621..e6ab38d 100644 --- a/arduino.DuinOS.AVR/DuinOS/port.c +++ b/arduino.DuinOS.AVR/DuinOS/port.c @@ -1,7 +1,7 @@ /* - FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. + FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd. - FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT + FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** @@ -29,20 +29,23 @@ FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - >>>NOTE<<< The modification to the GPL is included to allow you to + + >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS - kernel. FreeRTOS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. You should have received a copy of the GNU General Public - License and the FreeRTOS license exception along with FreeRTOS; if not it - can be viewed here: http://www.freertos.org/a00114.html and also obtained - by writing to Richard Barry, contact details for whom are available on the - FreeRTOS WEB site. + kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. You should have received a copy of the GNU General Public License + and the FreeRTOS license exception along with FreeRTOS; if not itcan be + viewed here: http://www.freertos.org/a00114.html and also obtained by + writing to Real Time Engineers Ltd., contact details for whom are available + on the FreeRTOS WEB site. 1 tab == 4 spaces! - + *************************************************************************** * * * Having a problem? Start by reading the FAQ "My application does * @@ -52,18 +55,21 @@ * * *************************************************************************** - - http://www.FreeRTOS.org - Documentation, training, latest versions, license - and contact details. - + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool. + including FreeRTOS+Trace - an indispensable productivity tool, and our new + fully thread aware and reentrant UDP/IP stack. - Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell - the code with commercial support, indemnification, and middleware, under - the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also - provide a safety engineered and independently SIL3 certified version under - the SafeRTOS brand: http://www.SafeRTOS.com. + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems, who sell the code with commercial support, + indemnification and middleware, under the OpenRTOS brand. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. */ /* @@ -80,7 +86,7 @@ Changes from V2.6.0 #include "FreeRTOS.h" #include "task.h" -#include "wiring_private.h" +#include "wiring_private.h" /*----------------------------------------------------------- * Implementation of functions defined in portable.h for the AVR port. From df66f4c5a68d08890272a46f22c8ae087d7e9391 Mon Sep 17 00:00:00 2001 From: Nicolas Sanz Date: Fri, 15 Mar 2013 15:46:30 -0300 Subject: [PATCH 44/56] repaired some errors saving the stack --- arduino.DuinOS.AVR/DuinOS/port.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/arduino.DuinOS.AVR/DuinOS/port.c b/arduino.DuinOS.AVR/DuinOS/port.c index e6ab38d..a1f36b3 100644 --- a/arduino.DuinOS.AVR/DuinOS/port.c +++ b/arduino.DuinOS.AVR/DuinOS/port.c @@ -131,10 +131,10 @@ extern volatile tskTCB * volatile pxCurrentTCB; "in r0, __SREG__ \n\t" \ "cli \n\t" \ "push r0 \n\t" \ - "push r0 \n\t" \ "in r0, 0x3b \n\t" \ "push r0 \n\t" \ "in r0, 0x3c \n\t" \ + "push r0 \n\t" \ "push r1 \n\t" \ "clr r1 \n\t" \ "push r2 \n\t" \ @@ -313,10 +313,6 @@ extern volatile tskTCB * volatile pxCurrentTCB; "pop r2 \n\t" \ "pop r1 \n\t" \ "pop r0 \n\t" \ - "out 0x3c, r0 \n\t" \ - "pop r0 \n\t" \ - "out 0x3b, r0 \n\t" \ - "pop r0 \n\t" \ "out __SREG__, r0 \n\t" \ "pop r0 \n\t" \ ); @@ -399,7 +395,7 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE #if defined(__AVR_ATmega2560__) /* The Atmega2560 has two more register that we are saving - * The EIND and AMPZ and wea re going to initialize + * The EIND and RAMPZ and we are going to initialize * this registers to 0 (default initial values) */ *pxTopOfStack = ( portSTACK_TYPE ) 0x00; /* EIND */ From 3741b89c7dcbe9b554b910c1efb0a51506379499 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Wed, 20 Mar 2013 16:08:10 -0300 Subject: [PATCH 45/56] added new property for identify the Board. build.board. --- hardware/duinos/boards.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hardware/duinos/boards.txt b/hardware/duinos/boards.txt index 530ac01..4f25471 100644 --- a/hardware/duinos/boards.txt +++ b/hardware/duinos/boards.txt @@ -19,6 +19,7 @@ uno_DuinOS.bootloader.file=optiboot/optiboot_atmega328.hex uno_DuinOS.build.mcu=atmega328p uno_DuinOS.build.f_cpu=16000000L +uno_DuinOS.build.board=ARDUINO_UNO uno_DuinOS.build.core=arduino.DuinOS.AVR uno_DuinOS.build.variant=standard @@ -40,6 +41,7 @@ mega2560_DuinOS.bootloader.lock_bits=0x0F mega2560_DuinOS.build.mcu=atmega2560 mega2560_DuinOS.build.f_cpu=16000000L +mega2560_DuinOS.build.board=ARDUINO_MEGA2560 mega2560_DuinOS.build.core=arduino.DuinOS.AVR mega2560_DuinOS.build.variant=mega @@ -61,6 +63,7 @@ mega_DuinOS.bootloader.lock_bits=0x0F mega_DuinOS.build.mcu=atmega1280 mega_DuinOS.build.f_cpu=16000000L +mega_DuinOS.build.board=ARDUINO_MEGA mega_DuinOS.build.core=arduino.DuinOS.AVR mega_DuinOS.build.variant=mega From 06e5b4c731966236e8ee70431e5f5e21be1aeda5 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Thu, 21 Mar 2013 01:14:19 -0300 Subject: [PATCH 46/56] Pins 5 and 6 on the Arduino UNO and pins 7 and 13 in the Arduino MEGA TIMER0 use to control the PWM, Timer 0 as being used by DuinOS, insert the option to disable by setting the property using your DISABLED_BY_DUINOS --- variants/mega/pins_arduino.h | 379 +++++++++++++++++++++++++++++++ variants/standard/pins_arduino.h | 227 ++++++++++++++++++ 2 files changed, 606 insertions(+) create mode 100644 variants/mega/pins_arduino.h create mode 100644 variants/standard/pins_arduino.h diff --git a/variants/mega/pins_arduino.h b/variants/mega/pins_arduino.h new file mode 100644 index 0000000..4ef6b9f --- /dev/null +++ b/variants/mega/pins_arduino.h @@ -0,0 +1,379 @@ +/* + pins_arduino.h - Pin definition functions for Arduino + Part of Arduino - http://www.arduino.cc/ + + Copyright (c) 2007 David A. Mellis + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General + Public License along with this library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, + Boston, MA 02111-1307 USA + + $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $ +*/ + +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +#define NUM_DIGITAL_PINS 70 +#define NUM_ANALOG_INPUTS 16 +#define analogInputToDigitalPin(p) ((p < 16) ? (p) + 54 : -1) +#define digitalPinHasPWM(p) (((p) >= 2 && (p) <= 13) || ((p) >= 44 && (p)<= 46)) + +static const uint8_t SS = 53; +static const uint8_t MOSI = 51; +static const uint8_t MISO = 50; +static const uint8_t SCK = 52; + +static const uint8_t SDA = 20; +static const uint8_t SCL = 21; +static const uint8_t LED_BUILTIN = 13; + +static const uint8_t A0 = 54; +static const uint8_t A1 = 55; +static const uint8_t A2 = 56; +static const uint8_t A3 = 57; +static const uint8_t A4 = 58; +static const uint8_t A5 = 59; +static const uint8_t A6 = 60; +static const uint8_t A7 = 61; +static const uint8_t A8 = 62; +static const uint8_t A9 = 63; +static const uint8_t A10 = 64; +static const uint8_t A11 = 65; +static const uint8_t A12 = 66; +static const uint8_t A13 = 67; +static const uint8_t A14 = 68; +static const uint8_t A15 = 69; + +// A majority of the pins are NOT PCINTs, SO BE WARNED (i.e. you cannot use them as receive pins) +// Only pins available for RECEIVE (TRANSMIT can be on any pin): +// (I've deliberately left out pin mapping to the Hardware USARTs - seems senseless to me) +// Pins: 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69 + +#define digitalPinToPCICR(p) ( (((p) >= 10) && ((p) <= 13)) || \ + (((p) >= 50) && ((p) <= 53)) || \ + (((p) >= 62) && ((p) <= 69)) ? (&PCICR) : ((uint8_t *)0) ) + +#define digitalPinToPCICRbit(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? 0 : \ + ( (((p) >= 62) && ((p) <= 69)) ? 2 : \ + 0 ) ) + +#define digitalPinToPCMSK(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? (&PCMSK0) : \ + ( (((p) >= 62) && ((p) <= 69)) ? (&PCMSK2) : \ + ((uint8_t *)0) ) ) + +#define digitalPinToPCMSKbit(p) ( (((p) >= 10) && ((p) <= 13)) ? ((p) - 6) : \ + ( ((p) == 50) ? 3 : \ + ( ((p) == 51) ? 2 : \ + ( ((p) == 52) ? 1 : \ + ( ((p) == 53) ? 0 : \ + ( (((p) >= 62) && ((p) <= 69)) ? ((p) - 62) : \ + 0 ) ) ) ) ) ) + +#ifdef ARDUINO_MAIN + +const uint16_t PROGMEM port_to_mode_PGM[] = { + NOT_A_PORT, + (uint16_t) &DDRA, + (uint16_t) &DDRB, + (uint16_t) &DDRC, + (uint16_t) &DDRD, + (uint16_t) &DDRE, + (uint16_t) &DDRF, + (uint16_t) &DDRG, + (uint16_t) &DDRH, + NOT_A_PORT, + (uint16_t) &DDRJ, + (uint16_t) &DDRK, + (uint16_t) &DDRL, +}; + +const uint16_t PROGMEM port_to_output_PGM[] = { + NOT_A_PORT, + (uint16_t) &PORTA, + (uint16_t) &PORTB, + (uint16_t) &PORTC, + (uint16_t) &PORTD, + (uint16_t) &PORTE, + (uint16_t) &PORTF, + (uint16_t) &PORTG, + (uint16_t) &PORTH, + NOT_A_PORT, + (uint16_t) &PORTJ, + (uint16_t) &PORTK, + (uint16_t) &PORTL, +}; + +const uint16_t PROGMEM port_to_input_PGM[] = { + NOT_A_PIN, + (uint16_t) &PINA, + (uint16_t) &PINB, + (uint16_t) &PINC, + (uint16_t) &PIND, + (uint16_t) &PINE, + (uint16_t) &PINF, + (uint16_t) &PING, + (uint16_t) &PINH, + NOT_A_PIN, + (uint16_t) &PINJ, + (uint16_t) &PINK, + (uint16_t) &PINL, +}; + +const uint8_t PROGMEM digital_pin_to_port_PGM[] = { + // PORTLIST + // ------------------------------------------- + PE , // PE 0 ** 0 ** USART0_RX + PE , // PE 1 ** 1 ** USART0_TX + PE , // PE 4 ** 2 ** PWM2 + PE , // PE 5 ** 3 ** PWM3 + PG , // PG 5 ** 4 ** PWM4 + PE , // PE 3 ** 5 ** PWM5 + PH , // PH 3 ** 6 ** PWM6 + PH , // PH 4 ** 7 ** PWM7 + PH , // PH 5 ** 8 ** PWM8 + PH , // PH 6 ** 9 ** PWM9 + PB , // PB 4 ** 10 ** PWM10 + PB , // PB 5 ** 11 ** PWM11 + PB , // PB 6 ** 12 ** PWM12 + PB , // PB 7 ** 13 ** PWM13 + PJ , // PJ 1 ** 14 ** USART3_TX + PJ , // PJ 0 ** 15 ** USART3_RX + PH , // PH 1 ** 16 ** USART2_TX + PH , // PH 0 ** 17 ** USART2_RX + PD , // PD 3 ** 18 ** USART1_TX + PD , // PD 2 ** 19 ** USART1_RX + PD , // PD 1 ** 20 ** I2C_SDA + PD , // PD 0 ** 21 ** I2C_SCL + PA , // PA 0 ** 22 ** D22 + PA , // PA 1 ** 23 ** D23 + PA , // PA 2 ** 24 ** D24 + PA , // PA 3 ** 25 ** D25 + PA , // PA 4 ** 26 ** D26 + PA , // PA 5 ** 27 ** D27 + PA , // PA 6 ** 28 ** D28 + PA , // PA 7 ** 29 ** D29 + PC , // PC 7 ** 30 ** D30 + PC , // PC 6 ** 31 ** D31 + PC , // PC 5 ** 32 ** D32 + PC , // PC 4 ** 33 ** D33 + PC , // PC 3 ** 34 ** D34 + PC , // PC 2 ** 35 ** D35 + PC , // PC 1 ** 36 ** D36 + PC , // PC 0 ** 37 ** D37 + PD , // PD 7 ** 38 ** D38 + PG , // PG 2 ** 39 ** D39 + PG , // PG 1 ** 40 ** D40 + PG , // PG 0 ** 41 ** D41 + PL , // PL 7 ** 42 ** D42 + PL , // PL 6 ** 43 ** D43 + PL , // PL 5 ** 44 ** D44 + PL , // PL 4 ** 45 ** D45 + PL , // PL 3 ** 46 ** D46 + PL , // PL 2 ** 47 ** D47 + PL , // PL 1 ** 48 ** D48 + PL , // PL 0 ** 49 ** D49 + PB , // PB 3 ** 50 ** SPI_MISO + PB , // PB 2 ** 51 ** SPI_MOSI + PB , // PB 1 ** 52 ** SPI_SCK + PB , // PB 0 ** 53 ** SPI_SS + PF , // PF 0 ** 54 ** A0 + PF , // PF 1 ** 55 ** A1 + PF , // PF 2 ** 56 ** A2 + PF , // PF 3 ** 57 ** A3 + PF , // PF 4 ** 58 ** A4 + PF , // PF 5 ** 59 ** A5 + PF , // PF 6 ** 60 ** A6 + PF , // PF 7 ** 61 ** A7 + PK , // PK 0 ** 62 ** A8 + PK , // PK 1 ** 63 ** A9 + PK , // PK 2 ** 64 ** A10 + PK , // PK 3 ** 65 ** A11 + PK , // PK 4 ** 66 ** A12 + PK , // PK 5 ** 67 ** A13 + PK , // PK 6 ** 68 ** A14 + PK , // PK 7 ** 69 ** A15 +}; + +const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = { + // PIN IN PORT + // ------------------------------------------- + _BV( 0 ) , // PE 0 ** 0 ** USART0_RX + _BV( 1 ) , // PE 1 ** 1 ** USART0_TX + _BV( 4 ) , // PE 4 ** 2 ** PWM2 + _BV( 5 ) , // PE 5 ** 3 ** PWM3 + _BV( 5 ) , // PG 5 ** 4 ** PWM4 + _BV( 3 ) , // PE 3 ** 5 ** PWM5 + _BV( 3 ) , // PH 3 ** 6 ** PWM6 + _BV( 4 ) , // PH 4 ** 7 ** PWM7 + _BV( 5 ) , // PH 5 ** 8 ** PWM8 + _BV( 6 ) , // PH 6 ** 9 ** PWM9 + _BV( 4 ) , // PB 4 ** 10 ** PWM10 + _BV( 5 ) , // PB 5 ** 11 ** PWM11 + _BV( 6 ) , // PB 6 ** 12 ** PWM12 + _BV( 7 ) , // PB 7 ** 13 ** PWM13 + _BV( 1 ) , // PJ 1 ** 14 ** USART3_TX + _BV( 0 ) , // PJ 0 ** 15 ** USART3_RX + _BV( 1 ) , // PH 1 ** 16 ** USART2_TX + _BV( 0 ) , // PH 0 ** 17 ** USART2_RX + _BV( 3 ) , // PD 3 ** 18 ** USART1_TX + _BV( 2 ) , // PD 2 ** 19 ** USART1_RX + _BV( 1 ) , // PD 1 ** 20 ** I2C_SDA + _BV( 0 ) , // PD 0 ** 21 ** I2C_SCL + _BV( 0 ) , // PA 0 ** 22 ** D22 + _BV( 1 ) , // PA 1 ** 23 ** D23 + _BV( 2 ) , // PA 2 ** 24 ** D24 + _BV( 3 ) , // PA 3 ** 25 ** D25 + _BV( 4 ) , // PA 4 ** 26 ** D26 + _BV( 5 ) , // PA 5 ** 27 ** D27 + _BV( 6 ) , // PA 6 ** 28 ** D28 + _BV( 7 ) , // PA 7 ** 29 ** D29 + _BV( 7 ) , // PC 7 ** 30 ** D30 + _BV( 6 ) , // PC 6 ** 31 ** D31 + _BV( 5 ) , // PC 5 ** 32 ** D32 + _BV( 4 ) , // PC 4 ** 33 ** D33 + _BV( 3 ) , // PC 3 ** 34 ** D34 + _BV( 2 ) , // PC 2 ** 35 ** D35 + _BV( 1 ) , // PC 1 ** 36 ** D36 + _BV( 0 ) , // PC 0 ** 37 ** D37 + _BV( 7 ) , // PD 7 ** 38 ** D38 + _BV( 2 ) , // PG 2 ** 39 ** D39 + _BV( 1 ) , // PG 1 ** 40 ** D40 + _BV( 0 ) , // PG 0 ** 41 ** D41 + _BV( 7 ) , // PL 7 ** 42 ** D42 + _BV( 6 ) , // PL 6 ** 43 ** D43 + _BV( 5 ) , // PL 5 ** 44 ** D44 + _BV( 4 ) , // PL 4 ** 45 ** D45 + _BV( 3 ) , // PL 3 ** 46 ** D46 + _BV( 2 ) , // PL 2 ** 47 ** D47 + _BV( 1 ) , // PL 1 ** 48 ** D48 + _BV( 0 ) , // PL 0 ** 49 ** D49 + _BV( 3 ) , // PB 3 ** 50 ** SPI_MISO + _BV( 2 ) , // PB 2 ** 51 ** SPI_MOSI + _BV( 1 ) , // PB 1 ** 52 ** SPI_SCK + _BV( 0 ) , // PB 0 ** 53 ** SPI_SS + _BV( 0 ) , // PF 0 ** 54 ** A0 + _BV( 1 ) , // PF 1 ** 55 ** A1 + _BV( 2 ) , // PF 2 ** 56 ** A2 + _BV( 3 ) , // PF 3 ** 57 ** A3 + _BV( 4 ) , // PF 4 ** 58 ** A4 + _BV( 5 ) , // PF 5 ** 59 ** A5 + _BV( 6 ) , // PF 6 ** 60 ** A6 + _BV( 7 ) , // PF 7 ** 61 ** A7 + _BV( 0 ) , // PK 0 ** 62 ** A8 + _BV( 1 ) , // PK 1 ** 63 ** A9 + _BV( 2 ) , // PK 2 ** 64 ** A10 + _BV( 3 ) , // PK 3 ** 65 ** A11 + _BV( 4 ) , // PK 4 ** 66 ** A12 + _BV( 5 ) , // PK 5 ** 67 ** A13 + _BV( 6 ) , // PK 6 ** 68 ** A14 + _BV( 7 ) , // PK 7 ** 69 ** A15 +}; + +const uint8_t PROGMEM digital_pin_to_timer_PGM[] = { + // TIMERS + // ------------------------------------------- + NOT_ON_TIMER , // PE 0 ** 0 ** USART0_RX + NOT_ON_TIMER , // PE 1 ** 1 ** USART0_TX + TIMER3B , // PE 4 ** 2 ** PWM2 + TIMER3C , // PE 5 ** 3 ** PWM3 +/* CDCP - START + * disabled because DuinOS uses timer 0 for its kernel + */ +#ifdef DISABLED_BY_DUINOS + NOT_ON_TIMER, +#else + TIMER0B , // PG 5 ** 4 ** PWM4 +#endif +/* CDCP - END */ + TIMER3A , // PE 3 ** 5 ** PWM5 + TIMER4A , // PH 3 ** 6 ** PWM6 + TIMER4B , // PH 4 ** 7 ** PWM7 + TIMER4C , // PH 5 ** 8 ** PWM8 + TIMER2B , // PH 6 ** 9 ** PWM9 + TIMER2A , // PB 4 ** 10 ** PWM10 + TIMER1A , // PB 5 ** 11 ** PWM11 + TIMER1B , // PB 6 ** 12 ** PWM12 +/* CDCP - BEGIN + * disabled because DuinOS uses timer 0 for its kernel + */ +#ifdef DISABLED_BY_DUINOS + NOT_ON_TIMER, +#else + TIMER0A , // PB 7 ** 13 ** PWM13 +#endif +/* CDCP - END + NOT_ON_TIMER , // PJ 1 ** 14 ** USART3_TX + NOT_ON_TIMER , // PJ 0 ** 15 ** USART3_RX + NOT_ON_TIMER , // PH 1 ** 16 ** USART2_TX + NOT_ON_TIMER , // PH 0 ** 17 ** USART2_RX + NOT_ON_TIMER , // PD 3 ** 18 ** USART1_TX + NOT_ON_TIMER , // PD 2 ** 19 ** USART1_RX + NOT_ON_TIMER , // PD 1 ** 20 ** I2C_SDA + NOT_ON_TIMER , // PD 0 ** 21 ** I2C_SCL + NOT_ON_TIMER , // PA 0 ** 22 ** D22 + NOT_ON_TIMER , // PA 1 ** 23 ** D23 + NOT_ON_TIMER , // PA 2 ** 24 ** D24 + NOT_ON_TIMER , // PA 3 ** 25 ** D25 + NOT_ON_TIMER , // PA 4 ** 26 ** D26 + NOT_ON_TIMER , // PA 5 ** 27 ** D27 + NOT_ON_TIMER , // PA 6 ** 28 ** D28 + NOT_ON_TIMER , // PA 7 ** 29 ** D29 + NOT_ON_TIMER , // PC 7 ** 30 ** D30 + NOT_ON_TIMER , // PC 6 ** 31 ** D31 + NOT_ON_TIMER , // PC 5 ** 32 ** D32 + NOT_ON_TIMER , // PC 4 ** 33 ** D33 + NOT_ON_TIMER , // PC 3 ** 34 ** D34 + NOT_ON_TIMER , // PC 2 ** 35 ** D35 + NOT_ON_TIMER , // PC 1 ** 36 ** D36 + NOT_ON_TIMER , // PC 0 ** 37 ** D37 + NOT_ON_TIMER , // PD 7 ** 38 ** D38 + NOT_ON_TIMER , // PG 2 ** 39 ** D39 + NOT_ON_TIMER , // PG 1 ** 40 ** D40 + NOT_ON_TIMER , // PG 0 ** 41 ** D41 + NOT_ON_TIMER , // PL 7 ** 42 ** D42 + NOT_ON_TIMER , // PL 6 ** 43 ** D43 + TIMER5C , // PL 5 ** 44 ** D44 + TIMER5B , // PL 4 ** 45 ** D45 + TIMER5A , // PL 3 ** 46 ** D46 + NOT_ON_TIMER , // PL 2 ** 47 ** D47 + NOT_ON_TIMER , // PL 1 ** 48 ** D48 + NOT_ON_TIMER , // PL 0 ** 49 ** D49 + NOT_ON_TIMER , // PB 3 ** 50 ** SPI_MISO + NOT_ON_TIMER , // PB 2 ** 51 ** SPI_MOSI + NOT_ON_TIMER , // PB 1 ** 52 ** SPI_SCK + NOT_ON_TIMER , // PB 0 ** 53 ** SPI_SS + NOT_ON_TIMER , // PF 0 ** 54 ** A0 + NOT_ON_TIMER , // PF 1 ** 55 ** A1 + NOT_ON_TIMER , // PF 2 ** 56 ** A2 + NOT_ON_TIMER , // PF 3 ** 57 ** A3 + NOT_ON_TIMER , // PF 4 ** 58 ** A4 + NOT_ON_TIMER , // PF 5 ** 59 ** A5 + NOT_ON_TIMER , // PF 6 ** 60 ** A6 + NOT_ON_TIMER , // PF 7 ** 61 ** A7 + NOT_ON_TIMER , // PK 0 ** 62 ** A8 + NOT_ON_TIMER , // PK 1 ** 63 ** A9 + NOT_ON_TIMER , // PK 2 ** 64 ** A10 + NOT_ON_TIMER , // PK 3 ** 65 ** A11 + NOT_ON_TIMER , // PK 4 ** 66 ** A12 + NOT_ON_TIMER , // PK 5 ** 67 ** A13 + NOT_ON_TIMER , // PK 6 ** 68 ** A14 + NOT_ON_TIMER , // PK 7 ** 69 ** A15 +}; + +#endif + +#endif diff --git a/variants/standard/pins_arduino.h b/variants/standard/pins_arduino.h new file mode 100644 index 0000000..ff3e227 --- /dev/null +++ b/variants/standard/pins_arduino.h @@ -0,0 +1,227 @@ +/* + pins_arduino.h - Pin definition functions for Arduino + Part of Arduino - http://www.arduino.cc/ + + Copyright (c) 2007 David A. Mellis + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General + Public License along with this library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, + Boston, MA 02111-1307 USA + + $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $ +*/ + +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +#define NUM_DIGITAL_PINS 20 +#define NUM_ANALOG_INPUTS 6 +#define analogInputToDigitalPin(p) ((p < 6) ? (p) + 14 : -1) + +#if defined(__AVR_ATmega8__) +#define digitalPinHasPWM(p) ((p) == 9 || (p) == 10 || (p) == 11) +#else +#define digitalPinHasPWM(p) ((p) == 3 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11) +#endif + +static const uint8_t SS = 10; +static const uint8_t MOSI = 11; +static const uint8_t MISO = 12; +static const uint8_t SCK = 13; + +static const uint8_t SDA = 18; +static const uint8_t SCL = 19; +static const uint8_t LED_BUILTIN = 13; + +static const uint8_t A0 = 14; +static const uint8_t A1 = 15; +static const uint8_t A2 = 16; +static const uint8_t A3 = 17; +static const uint8_t A4 = 18; +static const uint8_t A5 = 19; +static const uint8_t A6 = 20; +static const uint8_t A7 = 21; + +#define digitalPinToPCICR(p) (((p) >= 0 && (p) <= 21) ? (&PCICR) : ((uint8_t *)0)) +#define digitalPinToPCICRbit(p) (((p) <= 7) ? 2 : (((p) <= 13) ? 0 : 1)) +#define digitalPinToPCMSK(p) (((p) <= 7) ? (&PCMSK2) : (((p) <= 13) ? (&PCMSK0) : (((p) <= 21) ? (&PCMSK1) : ((uint8_t *)0)))) +#define digitalPinToPCMSKbit(p) (((p) <= 7) ? (p) : (((p) <= 13) ? ((p) - 8) : ((p) - 14))) + +#ifdef ARDUINO_MAIN + +// On the Arduino board, digital pins are also used +// for the analog output (software PWM). Analog input +// pins are a separate set. + +// ATMEL ATMEGA8 & 168 / ARDUINO +// +// +-\/-+ +// PC6 1| |28 PC5 (AI 5) +// (D 0) PD0 2| |27 PC4 (AI 4) +// (D 1) PD1 3| |26 PC3 (AI 3) +// (D 2) PD2 4| |25 PC2 (AI 2) +// PWM+ (D 3) PD3 5| |24 PC1 (AI 1) +// (D 4) PD4 6| |23 PC0 (AI 0) +// VCC 7| |22 GND +// GND 8| |21 AREF +// PB6 9| |20 AVCC +// PB7 10| |19 PB5 (D 13) +// PWM+ (D 5) PD5 11| |18 PB4 (D 12) +// PWM+ (D 6) PD6 12| |17 PB3 (D 11) PWM +// (D 7) PD7 13| |16 PB2 (D 10) PWM +// (D 8) PB0 14| |15 PB1 (D 9) PWM +// +----+ +// +// (PWM+ indicates the additional PWM pins on the ATmega168.) + +// ATMEL ATMEGA1280 / ARDUINO +// +// 0-7 PE0-PE7 works +// 8-13 PB0-PB5 works +// 14-21 PA0-PA7 works +// 22-29 PH0-PH7 works +// 30-35 PG5-PG0 works +// 36-43 PC7-PC0 works +// 44-51 PJ7-PJ0 works +// 52-59 PL7-PL0 works +// 60-67 PD7-PD0 works +// A0-A7 PF0-PF7 +// A8-A15 PK0-PK7 + + +// these arrays map port names (e.g. port B) to the +// appropriate addresses for various functions (e.g. reading +// and writing) +const uint16_t PROGMEM port_to_mode_PGM[] = { + NOT_A_PORT, + NOT_A_PORT, + (uint16_t) &DDRB, + (uint16_t) &DDRC, + (uint16_t) &DDRD, +}; + +const uint16_t PROGMEM port_to_output_PGM[] = { + NOT_A_PORT, + NOT_A_PORT, + (uint16_t) &PORTB, + (uint16_t) &PORTC, + (uint16_t) &PORTD, +}; + +const uint16_t PROGMEM port_to_input_PGM[] = { + NOT_A_PORT, + NOT_A_PORT, + (uint16_t) &PINB, + (uint16_t) &PINC, + (uint16_t) &PIND, +}; + +const uint8_t PROGMEM digital_pin_to_port_PGM[] = { + PD, /* 0 */ + PD, + PD, + PD, + PD, + PD, + PD, + PD, + PB, /* 8 */ + PB, + PB, + PB, + PB, + PB, + PC, /* 14 */ + PC, + PC, + PC, + PC, + PC, +}; + +const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = { + _BV(0), /* 0, port D */ + _BV(1), + _BV(2), + _BV(3), + _BV(4), + _BV(5), + _BV(6), + _BV(7), + _BV(0), /* 8, port B */ + _BV(1), + _BV(2), + _BV(3), + _BV(4), + _BV(5), + _BV(0), /* 14, port C */ + _BV(1), + _BV(2), + _BV(3), + _BV(4), + _BV(5), +}; + +const uint8_t PROGMEM digital_pin_to_timer_PGM[] = { + NOT_ON_TIMER, /* 0 - port D */ + NOT_ON_TIMER, + NOT_ON_TIMER, + // on the ATmega168, digital pin 3 has hardware pwm +#if defined(__AVR_ATmega8__) + NOT_ON_TIMER, +#else + TIMER2B, +#endif + NOT_ON_TIMER, + // on the ATmega168, digital pins 5 and 6 have hardware pwm +#if defined(__AVR_ATmega8__) + NOT_ON_TIMER, + NOT_ON_TIMER, +#else +/* CDCP - BEGIN + * disabled because DuinOS uses timer 0 for its kernel + */ +#ifdef DISABLED_BY_DUINOS + NOT_ON_TIMER, + NOT_ON_TIMER, +#else + TIMER0B, + TIMER0A, +#endif +/* CDCP - END */ +#endif + NOT_ON_TIMER, + NOT_ON_TIMER, /* 8 - port B */ + TIMER1A, + TIMER1B, +#if defined(__AVR_ATmega8__) + TIMER2, +#else + TIMER2A, +#endif + NOT_ON_TIMER, + NOT_ON_TIMER, + NOT_ON_TIMER, + NOT_ON_TIMER, /* 14 - port C */ + NOT_ON_TIMER, + NOT_ON_TIMER, + NOT_ON_TIMER, + NOT_ON_TIMER, +}; + +#endif + +#endif From abb57f58a2fd78fe843cd629ef654d041ae7fd64 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Mon, 25 Mar 2013 18:06:37 -0300 Subject: [PATCH 47/56] A new approach to identify the presence of register RAMPZ and ENDI and using Program Counter (PC) greater than 17 bits. Merge from specific branch for test. --- arduino.DuinOS.AVR/DuinOS/port.c | 140 +++++++++---------------------- 1 file changed, 41 insertions(+), 99 deletions(-) diff --git a/arduino.DuinOS.AVR/DuinOS/port.c b/arduino.DuinOS.AVR/DuinOS/port.c index a1f36b3..feb69ea 100644 --- a/arduino.DuinOS.AVR/DuinOS/port.c +++ b/arduino.DuinOS.AVR/DuinOS/port.c @@ -125,62 +125,27 @@ extern volatile tskTCB * volatile pxCurrentTCB; * The interrupts will have been disabled during the call to portSAVE_CONTEXT() * so we need not worry about reading/writing to the stack pointer. */ -#if defined(__AVR_ATmega2560__) #define portSAVE_CONTEXT() \ asm volatile ( "push r0 \n\t" \ "in r0, __SREG__ \n\t" \ "cli \n\t" \ "push r0 \n\t" \ - "in r0, 0x3b \n\t" \ + ); +/* CDCP - begin*/ +#if defined(__AVR_HAVE_RAMPZ__) + /* + * have RAMPZ Extended Z-pointer Register for ELPM/SPM + * the uC have extend program memory + * 0x3b --> RAMPZ + * 0x3c --> EIND + */ + asm volatile ( "in r0, 0x3b \n\t" \ "push r0 \n\t" \ "in r0, 0x3c \n\t" \ "push r0 \n\t" \ - "push r1 \n\t" \ - "clr r1 \n\t" \ - "push r2 \n\t" \ - "push r3 \n\t" \ - "push r4 \n\t" \ - "push r5 \n\t" \ - "push r6 \n\t" \ - "push r7 \n\t" \ - "push r8 \n\t" \ - "push r9 \n\t" \ - "push r10 \n\t" \ - "push r11 \n\t" \ - "push r12 \n\t" \ - "push r13 \n\t" \ - "push r14 \n\t" \ - "push r15 \n\t" \ - "push r16 \n\t" \ - "push r17 \n\t" \ - "push r18 \n\t" \ - "push r19 \n\t" \ - "push r20 \n\t" \ - "push r21 \n\t" \ - "push r22 \n\t" \ - "push r23 \n\t" \ - "push r24 \n\t" \ - "push r25 \n\t" \ - "push r26 \n\t" \ - "push r27 \n\t" \ - "push r28 \n\t" \ - "push r29 \n\t" \ - "push r30 \n\t" \ - "push r31 \n\t" \ - "lds r26, pxCurrentTCB \n\t" \ - "lds r27, pxCurrentTCB + 1 \n\t" \ - "in r0, 0x3d \n\t" \ - "st x+, r0 \n\t" \ - "in r0, 0x3e \n\t" \ - "st x+, r0 \n\t" \ ); -#else -#define portSAVE_CONTEXT() \ - asm volatile ( "push r0 \n\t" \ - "in r0, __SREG__ \n\t" \ - "cli \n\t" \ - "push r0 \n\t" \ - "push r1 \n\t" \ +#endif + asm volatile ( "push r1 \n\t" \ "clr r1 \n\t" \ "push r2 \n\t" \ "push r3 \n\t" \ @@ -219,14 +184,13 @@ extern volatile tskTCB * volatile pxCurrentTCB; "in r0, 0x3e \n\t" \ "st x+, r0 \n\t" \ ); -#endif + /* * Opposite to portSAVE_CONTEXT(). Interrupts will have been disabled during * the context save so we can write to the stack pointer. */ -#if defined(__AVR_ATmega2560__) #define portRESTORE_CONTEXT() \ asm volatile ( "lds r26, pxCurrentTCB \n\t" \ "lds r27, pxCurrentTCB + 1 \n\t" \ @@ -266,57 +230,25 @@ extern volatile tskTCB * volatile pxCurrentTCB; "pop r2 \n\t" \ "pop r1 \n\t" \ "pop r0 \n\t" \ - "out 0x3c, r0 \n\t" \ + ); + +#if defined(__AVR_HAVE_RAMPZ__) + /* + * have RAMPZ Extended Z-pointer Register for ELPM/SPM + * the uC have extend program memory + * 0x3b --> RAMPZ + * 0x3c --> EIND + */ +asm volatile ( "out 0x3c, r0 \n\t" \ "pop r0 \n\t" \ "out 0x3b, r0 \n\t" \ "pop r0 \n\t" \ - "out __SREG__, r0 \n\t" \ - "pop r0 \n\t" \ ); -#else -#define portRESTORE_CONTEXT() \ - asm volatile ( "lds r26, pxCurrentTCB \n\t" \ - "lds r27, pxCurrentTCB + 1 \n\t" \ - "ld r28, x+ \n\t" \ - "out __SP_L__, r28 \n\t" \ - "ld r29, x+ \n\t" \ - "out __SP_H__, r29 \n\t" \ - "pop r31 \n\t" \ - "pop r30 \n\t" \ - "pop r29 \n\t" \ - "pop r28 \n\t" \ - "pop r27 \n\t" \ - "pop r26 \n\t" \ - "pop r25 \n\t" \ - "pop r24 \n\t" \ - "pop r23 \n\t" \ - "pop r22 \n\t" \ - "pop r21 \n\t" \ - "pop r20 \n\t" \ - "pop r19 \n\t" \ - "pop r18 \n\t" \ - "pop r17 \n\t" \ - "pop r16 \n\t" \ - "pop r15 \n\t" \ - "pop r14 \n\t" \ - "pop r13 \n\t" \ - "pop r12 \n\t" \ - "pop r11 \n\t" \ - "pop r10 \n\t" \ - "pop r9 \n\t" \ - "pop r8 \n\t" \ - "pop r7 \n\t" \ - "pop r6 \n\t" \ - "pop r5 \n\t" \ - "pop r4 \n\t" \ - "pop r3 \n\t" \ - "pop r2 \n\t" \ - "pop r1 \n\t" \ - "pop r0 \n\t" \ - "out __SREG__, r0 \n\t" \ +#endif + +asm volatile ( "out __SREG__, r0 \n\t" \ "pop r0 \n\t" \ ); -#endif /*-----------------------------------------------------------*/ @@ -331,10 +263,12 @@ static void prvSetupTimerInterrupt( void ); */ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ) { -#if defined(__AVR_ATmega2560__) - /* ATmega2560 DuinOS port by SkyWodd - * Corrected by NiesteSzeck*/ +/* CDCP + * __AVR_3_BYTE_PC__ is not official, and only exist after version 4.1 of GCC + */ +#if defined(__AVR_HAVE_RAMPZ__) || defined(__AVR_3_BYTE_PC__) unsigned portLONG usAddress; // ATMega2560 have 17bit Program Counter register + // Other future uControler can have up 22, or 24 bits. #else unsigned portSHORT usAddress; // over ATmega have 16bit Program Counter register #endif @@ -355,7 +289,10 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE /*lint -e950 -e611 -e923 Lint doesn't like this much - but nothing I can do about it. */ -#if defined(__AVR_ATmega2560__) +/* CDCP + * __AVR_3_BYTE_PC__ is not official + */ +#if defined(__AVR_HAVE_RAMPZ__) || defined(__AVR_3_BYTE_PC__) // Implement normal stack initialisation but with portLONG instead of portSHORT usAddress = ( unsigned portLONG ) pxCode; *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); @@ -392,7 +329,12 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE *pxTopOfStack = portFLAGS_INT_ENABLED; pxTopOfStack--; -#if defined(__AVR_ATmega2560__) + /* CDCP - begin*/ +#if defined(__AVR_HAVE_RAMPZ__) + /* + * have RAMPZ Extended Z-pointer Register for ELPM/SPM + * the uC have extend program memory + */ /* The Atmega2560 has two more register that we are saving * The EIND and RAMPZ and we are going to initialize From be0a2d398ec226dfd9f246b5ba392cd535912d7a Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Tue, 26 Mar 2013 12:31:59 -0300 Subject: [PATCH 48/56] using the model heap2.h the others were removed. --- arduino.DuinOS.AVR/DuinOS/heap_1.c | 177 -------------- arduino.DuinOS.AVR/DuinOS/heap_3.c | 138 ----------- arduino.DuinOS.AVR/DuinOS/heap_4.c | 359 ----------------------------- 3 files changed, 674 deletions(-) delete mode 100644 arduino.DuinOS.AVR/DuinOS/heap_1.c delete mode 100644 arduino.DuinOS.AVR/DuinOS/heap_3.c delete mode 100644 arduino.DuinOS.AVR/DuinOS/heap_4.c diff --git a/arduino.DuinOS.AVR/DuinOS/heap_1.c b/arduino.DuinOS.AVR/DuinOS/heap_1.c deleted file mode 100644 index 5577ef3..0000000 --- a/arduino.DuinOS.AVR/DuinOS/heap_1.c +++ /dev/null @@ -1,177 +0,0 @@ -/* - FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd. - - FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT - http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. - - *************************************************************************** - * * - * FreeRTOS tutorial books are available in pdf and paperback. * - * Complete, revised, and edited pdf reference manuals are also * - * available. * - * * - * Purchasing FreeRTOS documentation will not only help you, by * - * ensuring you get running as quickly as possible and with an * - * in-depth knowledge of how to use FreeRTOS, it will also help * - * the FreeRTOS project to continue with its mission of providing * - * professional grade, cross platform, de facto standard solutions * - * for microcontrollers - completely free of charge! * - * * - * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * - * * - * Thank you for using FreeRTOS, and thank you for your support! * - * * - *************************************************************************** - - - This file is part of the FreeRTOS distribution. - - FreeRTOS is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License (version 2) as published by the - Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - - >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to - distribute a combined work that includes FreeRTOS without being obliged to - provide the source code for proprietary components outside of the FreeRTOS - kernel. - - FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - details. You should have received a copy of the GNU General Public License - and the FreeRTOS license exception along with FreeRTOS; if not itcan be - viewed here: http://www.freertos.org/a00114.html and also obtained by - writing to Real Time Engineers Ltd., contact details for whom are available - on the FreeRTOS WEB site. - - 1 tab == 4 spaces! - - *************************************************************************** - * * - * Having a problem? Start by reading the FAQ "My application does * - * not run, what could be wrong?" * - * * - * http://www.FreeRTOS.org/FAQHelp.html * - * * - *************************************************************************** - - - http://www.FreeRTOS.org - Documentation, books, training, latest versions, - license and Real Time Engineers Ltd. contact details. - - http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool, and our new - fully thread aware and reentrant UDP/IP stack. - - http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High - Integrity Systems, who sell the code with commercial support, - indemnification and middleware, under the OpenRTOS brand. - - http://www.SafeRTOS.com - High Integrity Systems also provide a safety - engineered and independently SIL3 certified version for use in safety and - mission critical applications that require provable dependability. -*/ - - -/* - * The simplest possible implementation of pvPortMalloc(). Note that this - * implementation does NOT allow allocated memory to be freed again. - * - * See heap_2.c, heap_3.c and heap_4.c for alternative implementations, and the - * memory management pages of http://www.FreeRTOS.org for more information. - */ -#include - -/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining -all the API functions to use the MPU wrappers. That should only be done when -task.h is included from an application file. */ -#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE - -#include "FreeRTOS.h" -#include "task.h" - -#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE - -/* A few bytes might be lost to byte aligning the heap start address. */ -#define configADJUSTED_HEAP_SIZE ( configTOTAL_HEAP_SIZE - portBYTE_ALIGNMENT ) - -/* Allocate the memory for the heap. */ -static unsigned char ucHeap[ configTOTAL_HEAP_SIZE ]; -static size_t xNextFreeByte = ( size_t ) 0; - -/*-----------------------------------------------------------*/ - -void *pvPortMalloc( size_t xWantedSize ) -{ -void *pvReturn = NULL; -static unsigned char *pucAlignedHeap = NULL; - - /* Ensure that blocks are always aligned to the required number of bytes. */ - #if portBYTE_ALIGNMENT != 1 - if( xWantedSize & portBYTE_ALIGNMENT_MASK ) - { - /* Byte alignment required. */ - xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ); - } - #endif - - vTaskSuspendAll(); - { - if( pucAlignedHeap == NULL ) - { - /* Ensure the heap starts on a correctly aligned boundary. */ - pucAlignedHeap = ( unsigned char * ) ( ( ( portPOINTER_SIZE_TYPE ) &ucHeap[ portBYTE_ALIGNMENT ] ) & ( ( portPOINTER_SIZE_TYPE ) ~portBYTE_ALIGNMENT_MASK ) ); - } - - /* Check there is enough room left for the allocation. */ - if( ( ( xNextFreeByte + xWantedSize ) < configADJUSTED_HEAP_SIZE ) && - ( ( xNextFreeByte + xWantedSize ) > xNextFreeByte ) )/* Check for overflow. */ - { - /* Return the next free byte then increment the index past this - block. */ - pvReturn = pucAlignedHeap + xNextFreeByte; - xNextFreeByte += xWantedSize; - } - } - xTaskResumeAll(); - - #if( configUSE_MALLOC_FAILED_HOOK == 1 ) - { - if( pvReturn == NULL ) - { - extern void vApplicationMallocFailedHook( void ); - vApplicationMallocFailedHook(); - } - } - #endif - - return pvReturn; -} -/*-----------------------------------------------------------*/ - -void vPortFree( void *pv ) -{ - /* Memory cannot be freed using this scheme. See heap_2.c, heap_3.c and - heap_4.c for alternative implementations, and the memory management pages of - http://www.FreeRTOS.org for more information. */ - ( void ) pv; - - /* Force an assert as it is invalid to call this function. */ - configASSERT( pv == NULL ); -} -/*-----------------------------------------------------------*/ - -void vPortInitialiseBlocks( void ) -{ - /* Only required when static memory is not cleared. */ - xNextFreeByte = ( size_t ) 0; -} -/*-----------------------------------------------------------*/ - -size_t xPortGetFreeHeapSize( void ) -{ - return ( configADJUSTED_HEAP_SIZE - xNextFreeByte ); -} - - - diff --git a/arduino.DuinOS.AVR/DuinOS/heap_3.c b/arduino.DuinOS.AVR/DuinOS/heap_3.c deleted file mode 100644 index 4bdb2f9..0000000 --- a/arduino.DuinOS.AVR/DuinOS/heap_3.c +++ /dev/null @@ -1,138 +0,0 @@ -/* - FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd. - - FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT - http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. - - *************************************************************************** - * * - * FreeRTOS tutorial books are available in pdf and paperback. * - * Complete, revised, and edited pdf reference manuals are also * - * available. * - * * - * Purchasing FreeRTOS documentation will not only help you, by * - * ensuring you get running as quickly as possible and with an * - * in-depth knowledge of how to use FreeRTOS, it will also help * - * the FreeRTOS project to continue with its mission of providing * - * professional grade, cross platform, de facto standard solutions * - * for microcontrollers - completely free of charge! * - * * - * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * - * * - * Thank you for using FreeRTOS, and thank you for your support! * - * * - *************************************************************************** - - - This file is part of the FreeRTOS distribution. - - FreeRTOS is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License (version 2) as published by the - Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - - >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to - distribute a combined work that includes FreeRTOS without being obliged to - provide the source code for proprietary components outside of the FreeRTOS - kernel. - - FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - details. You should have received a copy of the GNU General Public License - and the FreeRTOS license exception along with FreeRTOS; if not itcan be - viewed here: http://www.freertos.org/a00114.html and also obtained by - writing to Real Time Engineers Ltd., contact details for whom are available - on the FreeRTOS WEB site. - - 1 tab == 4 spaces! - - *************************************************************************** - * * - * Having a problem? Start by reading the FAQ "My application does * - * not run, what could be wrong?" * - * * - * http://www.FreeRTOS.org/FAQHelp.html * - * * - *************************************************************************** - - - http://www.FreeRTOS.org - Documentation, books, training, latest versions, - license and Real Time Engineers Ltd. contact details. - - http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool, and our new - fully thread aware and reentrant UDP/IP stack. - - http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High - Integrity Systems, who sell the code with commercial support, - indemnification and middleware, under the OpenRTOS brand. - - http://www.SafeRTOS.com - High Integrity Systems also provide a safety - engineered and independently SIL3 certified version for use in safety and - mission critical applications that require provable dependability. -*/ - - -/* - * Implementation of pvPortMalloc() and vPortFree() that relies on the - * compilers own malloc() and free() implementations. - * - * This file can only be used if the linker is configured to to generate - * a heap memory area. - * - * See heap_1.c, heap_2.c and heap_4.c for alternative implementations, and the - * memory management pages of http://www.FreeRTOS.org for more information. - */ - -#include - -/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining -all the API functions to use the MPU wrappers. That should only be done when -task.h is included from an application file. */ -#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE - -#include "FreeRTOS.h" -#include "task.h" - -#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE - -/*-----------------------------------------------------------*/ - -void *pvPortMalloc( size_t xWantedSize ) -{ -void *pvReturn; - - vTaskSuspendAll(); - { - pvReturn = malloc( xWantedSize ); - } - xTaskResumeAll(); - - #if( configUSE_MALLOC_FAILED_HOOK == 1 ) - { - if( pvReturn == NULL ) - { - extern void vApplicationMallocFailedHook( void ); - vApplicationMallocFailedHook(); - } - } - #endif - - return pvReturn; -} -/*-----------------------------------------------------------*/ - -void vPortFree( void *pv ) -{ - if( pv ) - { - vTaskSuspendAll(); - { - free( pv ); - } - xTaskResumeAll(); - } -} - - - diff --git a/arduino.DuinOS.AVR/DuinOS/heap_4.c b/arduino.DuinOS.AVR/DuinOS/heap_4.c deleted file mode 100644 index b56bd28..0000000 --- a/arduino.DuinOS.AVR/DuinOS/heap_4.c +++ /dev/null @@ -1,359 +0,0 @@ -/* - FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd. - - FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT - http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. - - *************************************************************************** - * * - * FreeRTOS tutorial books are available in pdf and paperback. * - * Complete, revised, and edited pdf reference manuals are also * - * available. * - * * - * Purchasing FreeRTOS documentation will not only help you, by * - * ensuring you get running as quickly as possible and with an * - * in-depth knowledge of how to use FreeRTOS, it will also help * - * the FreeRTOS project to continue with its mission of providing * - * professional grade, cross platform, de facto standard solutions * - * for microcontrollers - completely free of charge! * - * * - * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * - * * - * Thank you for using FreeRTOS, and thank you for your support! * - * * - *************************************************************************** - - - This file is part of the FreeRTOS distribution. - - FreeRTOS is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License (version 2) as published by the - Free Software Foundation AND MODIFIED BY the FreeRTOS exception. - - >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to - distribute a combined work that includes FreeRTOS without being obliged to - provide the source code for proprietary components outside of the FreeRTOS - kernel. - - FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - details. You should have received a copy of the GNU General Public License - and the FreeRTOS license exception along with FreeRTOS; if not itcan be - viewed here: http://www.freertos.org/a00114.html and also obtained by - writing to Real Time Engineers Ltd., contact details for whom are available - on the FreeRTOS WEB site. - - 1 tab == 4 spaces! - - *************************************************************************** - * * - * Having a problem? Start by reading the FAQ "My application does * - * not run, what could be wrong?" * - * * - * http://www.FreeRTOS.org/FAQHelp.html * - * * - *************************************************************************** - - - http://www.FreeRTOS.org - Documentation, books, training, latest versions, - license and Real Time Engineers Ltd. contact details. - - http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool, and our new - fully thread aware and reentrant UDP/IP stack. - - http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High - Integrity Systems, who sell the code with commercial support, - indemnification and middleware, under the OpenRTOS brand. - - http://www.SafeRTOS.com - High Integrity Systems also provide a safety - engineered and independently SIL3 certified version for use in safety and - mission critical applications that require provable dependability. -*/ - -/* - * A sample implementation of pvPortMalloc() and vPortFree() that combines - * (coalescences) adjacent memory blocks as they are freed, and in so doing - * limits memory fragmentation. - * - * See heap_1.c, heap_2.c and heap_3.c for alternative implementations, and the - * memory management pages of http://www.FreeRTOS.org for more information. - */ -#include - -/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining -all the API functions to use the MPU wrappers. That should only be done when -task.h is included from an application file. */ -#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE - -#include "FreeRTOS.h" -#include "task.h" - -#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE - -/* Block sizes must not get too small. */ -#define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( heapSTRUCT_SIZE * 2 ) ) - -/* A few bytes might be lost to byte aligning the heap start address. */ -#define configADJUSTED_HEAP_SIZE ( configTOTAL_HEAP_SIZE - portBYTE_ALIGNMENT ) - -/* Allocate the memory for the heap. */ -static unsigned char ucHeap[ configTOTAL_HEAP_SIZE ]; - -/* Define the linked list structure. This is used to link free blocks in order -of their memory address. */ -typedef struct A_BLOCK_LINK -{ - struct A_BLOCK_LINK *pxNextFreeBlock; /*<< The next free block in the list. */ - size_t xBlockSize; /*<< The size of the free block. */ -} xBlockLink; - -/*-----------------------------------------------------------*/ - -/* - * Inserts a block of memory that is being freed into the correct position in - * the list of free memory blocks. The block being freed will be merged with - * the block in front it and/or the block behind it if the memory blocks are - * adjacent to each other. - */ -static void prvInsertBlockIntoFreeList( xBlockLink *pxBlockToInsert ); - -/* - * Called automatically to setup the required heap structures the first time - * pvPortMalloc() is called. - */ -static void prvHeapInit( void ); - -/*-----------------------------------------------------------*/ - -/* The size of the structure placed at the beginning of each allocated memory -block must by correctly byte aligned. */ -static const unsigned short heapSTRUCT_SIZE = ( sizeof( xBlockLink ) + portBYTE_ALIGNMENT - ( sizeof( xBlockLink ) % portBYTE_ALIGNMENT ) ); - -/* Ensure the pxEnd pointer will end up on the correct byte alignment. */ -static const size_t xTotalHeapSize = ( ( size_t ) configADJUSTED_HEAP_SIZE ) & ( ( size_t ) ~portBYTE_ALIGNMENT_MASK ); - -/* Create a couple of list links to mark the start and end of the list. */ -static xBlockLink xStart, *pxEnd = NULL; - -/* Keeps track of the number of free bytes remaining, but says nothing about -fragmentation. */ -static size_t xFreeBytesRemaining = ( ( size_t ) configADJUSTED_HEAP_SIZE ) & ( ( size_t ) ~portBYTE_ALIGNMENT_MASK ); - -/* STATIC FUNCTIONS ARE DEFINED AS MACROS TO MINIMIZE THE FUNCTION CALL DEPTH. */ - -/*-----------------------------------------------------------*/ - -void *pvPortMalloc( size_t xWantedSize ) -{ -xBlockLink *pxBlock, *pxPreviousBlock, *pxNewBlockLink; -void *pvReturn = NULL; - - vTaskSuspendAll(); - { - /* If this is the first call to malloc then the heap will require - initialisation to setup the list of free blocks. */ - if( pxEnd == NULL ) - { - prvHeapInit(); - } - - /* The wanted size is increased so it can contain a xBlockLink - structure in addition to the requested amount of bytes. */ - if( xWantedSize > 0 ) - { - xWantedSize += heapSTRUCT_SIZE; - - /* Ensure that blocks are always aligned to the required number of - bytes. */ - if( xWantedSize & portBYTE_ALIGNMENT_MASK ) - { - /* Byte alignment required. */ - xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ); - } - } - - if( ( xWantedSize > 0 ) && ( xWantedSize < xTotalHeapSize ) ) - { - /* Traverse the list from the start (lowest address) block until one - of adequate size is found. */ - pxPreviousBlock = &xStart; - pxBlock = xStart.pxNextFreeBlock; - while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock != NULL ) ) - { - pxPreviousBlock = pxBlock; - pxBlock = pxBlock->pxNextFreeBlock; - } - - /* If the end marker was reached then a block of adequate size was - not found. */ - if( pxBlock != pxEnd ) - { - /* Return the memory space - jumping over the xBlockLink structure - at its start. */ - pvReturn = ( void * ) ( ( ( unsigned char * ) pxPreviousBlock->pxNextFreeBlock ) + heapSTRUCT_SIZE ); - - /* This block is being returned for use so must be taken out of - the list of free blocks. */ - pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock; - - /* If the block is larger than required it can be split into two. */ - if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE ) - { - /* This block is to be split into two. Create a new block - following the number of bytes requested. The void cast is - used to prevent byte alignment warnings from the compiler. */ - pxNewBlockLink = ( void * ) ( ( ( unsigned char * ) pxBlock ) + xWantedSize ); - - /* Calculate the sizes of two blocks split from the single - block. */ - pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize; - pxBlock->xBlockSize = xWantedSize; - - /* Insert the new block into the list of free blocks. */ - prvInsertBlockIntoFreeList( ( pxNewBlockLink ) ); - } - - xFreeBytesRemaining -= pxBlock->xBlockSize; - } - } - } - xTaskResumeAll(); - - #if( configUSE_MALLOC_FAILED_HOOK == 1 ) - { - if( pvReturn == NULL ) - { - extern void vApplicationMallocFailedHook( void ); - vApplicationMallocFailedHook(); - } - } - #endif - - return pvReturn; -} -/*-----------------------------------------------------------*/ - -void vPortFree( void *pv ) -{ -unsigned char *puc = ( unsigned char * ) pv; -xBlockLink *pxLink; - - if( pv != NULL ) - { - /* The memory being freed will have an xBlockLink structure immediately - before it. */ - puc -= heapSTRUCT_SIZE; - - /* This casting is to keep the compiler from issuing warnings. */ - pxLink = ( void * ) puc; - - vTaskSuspendAll(); - { - /* Add this block to the list of free blocks. */ - xFreeBytesRemaining += pxLink->xBlockSize; - prvInsertBlockIntoFreeList( ( ( xBlockLink * ) pxLink ) ); - } - xTaskResumeAll(); - } -} -/*-----------------------------------------------------------*/ - -size_t xPortGetFreeHeapSize( void ) -{ - return xFreeBytesRemaining; -} -/*-----------------------------------------------------------*/ - -void vPortInitialiseBlocks( void ) -{ - /* This just exists to keep the linker quiet. */ -} -/*-----------------------------------------------------------*/ - -static void prvHeapInit( void ) -{ -xBlockLink *pxFirstFreeBlock; -unsigned char *pucHeapEnd, *pucAlignedHeap; - - /* Ensure the heap starts on a correctly aligned boundary. */ - pucAlignedHeap = ( unsigned char * ) ( ( ( portPOINTER_SIZE_TYPE ) &ucHeap[ portBYTE_ALIGNMENT ] ) & ( ( portPOINTER_SIZE_TYPE ) ~portBYTE_ALIGNMENT_MASK ) ); - - /* xStart is used to hold a pointer to the first item in the list of free - blocks. The void cast is used to prevent compiler warnings. */ - xStart.pxNextFreeBlock = ( void * ) pucAlignedHeap; - xStart.xBlockSize = ( size_t ) 0; - - /* pxEnd is used to mark the end of the list of free blocks and is inserted - at the end of the heap space. */ - pucHeapEnd = pucAlignedHeap + xTotalHeapSize; - pucHeapEnd -= heapSTRUCT_SIZE; - pxEnd = ( void * ) pucHeapEnd; - configASSERT( ( ( ( unsigned long ) pxEnd ) & ( ( unsigned long ) portBYTE_ALIGNMENT_MASK ) ) == 0UL ); - pxEnd->xBlockSize = 0; - pxEnd->pxNextFreeBlock = NULL; - - /* To start with there is a single free block that is sized to take up the - entire heap space, minus the space taken by pxEnd. */ - pxFirstFreeBlock = ( void * ) pucAlignedHeap; - pxFirstFreeBlock->xBlockSize = xTotalHeapSize - heapSTRUCT_SIZE; - pxFirstFreeBlock->pxNextFreeBlock = pxEnd; - - /* The heap now contains pxEnd. */ - xFreeBytesRemaining -= heapSTRUCT_SIZE; -} -/*-----------------------------------------------------------*/ - -static void prvInsertBlockIntoFreeList( xBlockLink *pxBlockToInsert ) -{ -xBlockLink *pxIterator; -unsigned char *puc; - - /* Iterate through the list until a block is found that has a higher address - than the block being inserted. */ - for( pxIterator = &xStart; pxIterator->pxNextFreeBlock < pxBlockToInsert; pxIterator = pxIterator->pxNextFreeBlock ) - { - /* Nothing to do here, just iterate to the right position. */ - } - - /* Do the block being inserted, and the block it is being inserted after - make a contiguous block of memory? */ - puc = ( unsigned char * ) pxIterator; - if( ( puc + pxIterator->xBlockSize ) == ( unsigned char * ) pxBlockToInsert ) - { - pxIterator->xBlockSize += pxBlockToInsert->xBlockSize; - pxBlockToInsert = pxIterator; - } - - /* Do the block being inserted, and the block it is being inserted before - make a contiguous block of memory? */ - puc = ( unsigned char * ) pxBlockToInsert; - if( ( puc + pxBlockToInsert->xBlockSize ) == ( unsigned char * ) pxIterator->pxNextFreeBlock ) - { - if( pxIterator->pxNextFreeBlock != pxEnd ) - { - /* Form one big block from the two blocks. */ - pxBlockToInsert->xBlockSize += pxIterator->pxNextFreeBlock->xBlockSize; - pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock->pxNextFreeBlock; - } - else - { - pxBlockToInsert->pxNextFreeBlock = pxEnd; - } - } - else - { - pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock; - } - - /* If the block being inserted plugged a gab, so was merged with the block - before and the block after, then it's pxNextFreeBlock pointer will have - already been set, and should not be set here as that would make it point - to itself. */ - if( pxIterator != pxBlockToInsert ) - { - pxIterator->pxNextFreeBlock = pxBlockToInsert; - } -} - From 346c864732256459e7ff92385a948a3d642c10eb Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Tue, 26 Mar 2013 12:34:05 -0300 Subject: [PATCH 49/56] adjustment of the format. --- arduino.DuinOS.AVR/DuinOS/port.c | 120 ++++++++++++++--------------- arduino.DuinOS.AVR/DuinOS/timers.h | 14 ++-- 2 files changed, 66 insertions(+), 68 deletions(-) diff --git a/arduino.DuinOS.AVR/DuinOS/port.c b/arduino.DuinOS.AVR/DuinOS/port.c index feb69ea..f2bdc59 100644 --- a/arduino.DuinOS.AVR/DuinOS/port.c +++ b/arduino.DuinOS.AVR/DuinOS/port.c @@ -292,33 +292,33 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE /* CDCP * __AVR_3_BYTE_PC__ is not official */ -#if defined(__AVR_HAVE_RAMPZ__) || defined(__AVR_3_BYTE_PC__) - // Implement normal stack initialisation but with portLONG instead of portSHORT - usAddress = ( unsigned portLONG ) pxCode; - *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); - pxTopOfStack--; - - usAddress >>= 8; - *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); - pxTopOfStack--; - - // Implemented the 3byte addressing - usAddress >>= 8; - *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); - pxTopOfStack--; - -// Normal initialisation for over ATmega -#else +#if defined(__AVR_HAVE_RAMPZ__) || defined(__AVR_3_BYTE_PC__) + // Implement normal stack initialisation but with portLONG instead of portSHORT + usAddress = ( unsigned portLONG ) pxCode; + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); + pxTopOfStack--; + + usAddress >>= 8; + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); + pxTopOfStack--; + + // Implemented the 3byte addressing + usAddress >>= 8; + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); + pxTopOfStack--; + +// Normal initialisation for over ATmega +#else /* The start of the task code will be popped off the stack last, so place it on first. */ - usAddress = ( unsigned portSHORT ) pxCode; - *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff ); + usAddress = ( unsigned portSHORT ) pxCode; + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff ); pxTopOfStack--; usAddress >>= 8; - *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff ); + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff ); pxTopOfStack--; -#endif +#endif /* Next simulate the stack as if after a call to portSAVE_CONTEXT(). portSAVE_CONTEXT places the flags on the stack immediately after r0 @@ -396,12 +396,12 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxTopOfStack--; /* Place the parameter on the stack in the expected location. */ - usAddress = ( unsigned portSHORT ) pvParameters; - *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff ); + usAddress = ( unsigned portSHORT ) pvParameters; + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff ); pxTopOfStack--; usAddress >>= 8; - *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff ); + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff ); pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x26; /* R26 X */ @@ -485,42 +485,42 @@ void vPortYieldFromTick( void ) */ static void prvSetupTimerInterrupt( void ) { - // on the ATmega168, timer 0 is also used for fast hardware pwm - // (using phase-correct PWM would mean that timer 0 overflowed half as often - // resulting in different millis() behavior on the ATmega8 and ATmega168) -#if defined(TCCR0A) && defined(WGM01) - sbi(TCCR0A, WGM01); - sbi(TCCR0A, WGM00); -#endif - - // set timer 0 prescale factor to 64 -#if defined(__AVR_ATmega128__) - // CPU specific: different values for the ATmega128 - sbi(TCCR0, CS02); -#elif defined(TCCR0) && defined(CS01) && defined(CS00) - // this combination is for the standard atmega8 - sbi(TCCR0, CS01); - sbi(TCCR0, CS00); -#elif defined(TCCR0B) && defined(CS01) && defined(CS00) - // this combination is for the standard 168/328/1280/2560 - sbi(TCCR0B, CS01); - sbi(TCCR0B, CS00); -#elif defined(TCCR0A) && defined(CS01) && defined(CS00) - // this combination is for the __AVR_ATmega645__ series - sbi(TCCR0A, CS01); - sbi(TCCR0A, CS00); -#else - #error Timer 0 prescale factor 64 not set correctly -#endif - - // enable timer 0 overflow interrupt -#if defined(TIMSK) && defined(TOIE0) - sbi(TIMSK, TOIE0); -#elif defined(TIMSK0) && defined(TOIE0) - sbi(TIMSK0, TOIE0); -#else - #error Timer 0 overflow interrupt not set correctly -#endif + // on the ATmega168, timer 0 is also used for fast hardware pwm + // (using phase-correct PWM would mean that timer 0 overflowed half as often + // resulting in different millis() behavior on the ATmega8 and ATmega168) +#if defined(TCCR0A) && defined(WGM01) + sbi(TCCR0A, WGM01); + sbi(TCCR0A, WGM00); +#endif + + // set timer 0 prescale factor to 64 +#if defined(__AVR_ATmega128__) + // CPU specific: different values for the ATmega128 + sbi(TCCR0, CS02); +#elif defined(TCCR0) && defined(CS01) && defined(CS00) + // this combination is for the standard atmega8 + sbi(TCCR0, CS01); + sbi(TCCR0, CS00); +#elif defined(TCCR0B) && defined(CS01) && defined(CS00) + // this combination is for the standard 168/328/1280/2560 + sbi(TCCR0B, CS01); + sbi(TCCR0B, CS00); +#elif defined(TCCR0A) && defined(CS01) && defined(CS00) + // this combination is for the __AVR_ATmega645__ series + sbi(TCCR0A, CS01); + sbi(TCCR0A, CS00); +#else + #error Timer 0 prescale factor 64 not set correctly +#endif + + // enable timer 0 overflow interrupt +#if defined(TIMSK) && defined(TOIE0) + sbi(TIMSK, TOIE0); +#elif defined(TIMSK0) && defined(TOIE0) + sbi(TIMSK0, TOIE0); +#else + #error Timer 0 overflow interrupt not set correctly +#endif } /*-----------------------------------------------------------*/ diff --git a/arduino.DuinOS.AVR/DuinOS/timers.h b/arduino.DuinOS.AVR/DuinOS/timers.h index b8bd73e..0851fd3 100644 --- a/arduino.DuinOS.AVR/DuinOS/timers.h +++ b/arduino.DuinOS.AVR/DuinOS/timers.h @@ -45,7 +45,7 @@ on the FreeRTOS WEB site. 1 tab == 4 spaces! - + *************************************************************************** * * * Having a problem? Start by reading the FAQ "My application does * @@ -63,13 +63,11 @@ including FreeRTOS+Trace - an indispensable productivity tool, and our new fully thread aware and reentrant UDP/IP stack. - http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High - Integrity Systems, who sell the code with commercial support, - indemnification and middleware, under the OpenRTOS brand. - - http://www.SafeRTOS.com - High Integrity Systems also provide a safety - engineered and independently SIL3 certified version for use in safety and - mission critical applications that require provable dependability. + Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell + the code with commercial support, indemnification, and middleware, under + the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also + provide a safety engineered and independently SIL3 certified version under + the SafeRTOS brand: http://www.SafeRTOS.com. */ From 50806cd9f4d15d41276601e70047b97d35c2820c Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Tue, 26 Mar 2013 12:35:13 -0300 Subject: [PATCH 50/56] The DuinOS need Timer0, it must be disabled. Still per test. --- arduino.DuinOS.AVR/wiring_analog.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arduino.DuinOS.AVR/wiring_analog.c b/arduino.DuinOS.AVR/wiring_analog.c index 23b01c6..31c77ad 100644 --- a/arduino.DuinOS.AVR/wiring_analog.c +++ b/arduino.DuinOS.AVR/wiring_analog.c @@ -125,6 +125,9 @@ void analogWrite(uint8_t pin, int val) OCR0 = val; // set pwm duty break; #endif +#ifdef DISABLED_BY_DUINOS + +// disabled because DuinOS uses timer 0 for its kernel #if defined(TCCR0A) && defined(COM0A1) case TIMER0A: @@ -141,7 +144,7 @@ void analogWrite(uint8_t pin, int val) OCR0B = val; // set pwm duty break; #endif - +#endif #if defined(TCCR1A) && defined(COM1A1) case TIMER1A: // connect pwm to pin on timer 1, channel A From 57ea03b769896df3b4f34830cc9c50b0439192fc Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Tue, 26 Mar 2013 12:35:51 -0300 Subject: [PATCH 51/56] removal of commented code that is no longer used. --- arduino.DuinOS.AVR/wiring.c | 39 ------------------------------------- 1 file changed, 39 deletions(-) diff --git a/arduino.DuinOS.AVR/wiring.c b/arduino.DuinOS.AVR/wiring.c index b2587ee..f866f1c 100644 --- a/arduino.DuinOS.AVR/wiring.c +++ b/arduino.DuinOS.AVR/wiring.c @@ -197,45 +197,6 @@ void init() // this needs to be called before setup() or some functions won't // work there sei(); - -/* - // on the ATmega168, timer 0 is also used for fast hardware pwm - // (using phase-correct PWM would mean that timer 0 overflowed half as often - // resulting in different millis() behavior on the ATmega8 and ATmega168) -#if defined(TCCR0A) && defined(WGM01) - sbi(TCCR0A, WGM01); - sbi(TCCR0A, WGM00); -#endif - - // set timer 0 prescale factor to 64 -#if defined(__AVR_ATmega128__) - // CPU specific: different values for the ATmega128 - sbi(TCCR0, CS02); -#elif defined(TCCR0) && defined(CS01) && defined(CS00) - // this combination is for the standard atmega8 - sbi(TCCR0, CS01); - sbi(TCCR0, CS00); -#elif defined(TCCR0B) && defined(CS01) && defined(CS00) - // this combination is for the standard 168/328/1280/2560 - sbi(TCCR0B, CS01); - sbi(TCCR0B, CS00); -#elif defined(TCCR0A) && defined(CS01) && defined(CS00) - // this combination is for the __AVR_ATmega645__ series - sbi(TCCR0A, CS01); - sbi(TCCR0A, CS00); -#else - #error Timer 0 prescale factor 64 not set correctly -#endif - - // enable timer 0 overflow interrupt -#if defined(TIMSK) && defined(TOIE0) - sbi(TIMSK, TOIE0); -#elif defined(TIMSK0) && defined(TOIE0) - sbi(TIMSK0, TOIE0); -#else - #error Timer 0 overflow interrupt not set correctly -#endif -*/ // timers 1 and 2 are used for phase-correct hardware pwm // this is better for motors as it ensures an even waveform From bd95d370cd30cecf34cb0e168743ff8dbf64c211 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Sun, 31 Mar 2013 02:51:22 -0300 Subject: [PATCH 52/56] The proposed solution to improve the presentation of the code in port.c was not a good result in initial tests I did worked, but I was using in a function and in this case macros are then researched the impact of using functions inline, and so I thought acclaim, besides the fact that the result be the same when properly parameterized. http://www.parashift.com/c++-faq/inline-vs-macros.html --- arduino.DuinOS.AVR/DuinOS/port.c | 313 +++++++++++++++---------------- 1 file changed, 156 insertions(+), 157 deletions(-) diff --git a/arduino.DuinOS.AVR/DuinOS/port.c b/arduino.DuinOS.AVR/DuinOS/port.c index feb69ea..5d30fc2 100644 --- a/arduino.DuinOS.AVR/DuinOS/port.c +++ b/arduino.DuinOS.AVR/DuinOS/port.c @@ -125,13 +125,13 @@ extern volatile tskTCB * volatile pxCurrentTCB; * The interrupts will have been disabled during the call to portSAVE_CONTEXT() * so we need not worry about reading/writing to the stack pointer. */ -#define portSAVE_CONTEXT() \ - asm volatile ( "push r0 \n\t" \ - "in r0, __SREG__ \n\t" \ - "cli \n\t" \ - "push r0 \n\t" \ +inline void portSAVE_CONTEXT() __attribute__((__always_inline__,__noreturn__)); +inline void portSAVE_CONTEXT(){ + asm volatile ( "push r0 \n\t" + "in r0, __SREG__ \n\t" + "cli \n\t" + "push r0 \n\t" ); -/* CDCP - begin*/ #if defined(__AVR_HAVE_RAMPZ__) /* * have RAMPZ Extended Z-pointer Register for ELPM/SPM @@ -139,99 +139,98 @@ extern volatile tskTCB * volatile pxCurrentTCB; * 0x3b --> RAMPZ * 0x3c --> EIND */ - asm volatile ( "in r0, 0x3b \n\t" \ - "push r0 \n\t" \ - "in r0, 0x3c \n\t" \ - "push r0 \n\t" \ + asm volatile ( "in r0, 0x3b \n\t" + "push r0 \n\t" + "in r0, 0x3c \n\t" + "push r0 \n\t" ); #endif - asm volatile ( "push r1 \n\t" \ - "clr r1 \n\t" \ - "push r2 \n\t" \ - "push r3 \n\t" \ - "push r4 \n\t" \ - "push r5 \n\t" \ - "push r6 \n\t" \ - "push r7 \n\t" \ - "push r8 \n\t" \ - "push r9 \n\t" \ - "push r10 \n\t" \ - "push r11 \n\t" \ - "push r12 \n\t" \ - "push r13 \n\t" \ - "push r14 \n\t" \ - "push r15 \n\t" \ - "push r16 \n\t" \ - "push r17 \n\t" \ - "push r18 \n\t" \ - "push r19 \n\t" \ - "push r20 \n\t" \ - "push r21 \n\t" \ - "push r22 \n\t" \ - "push r23 \n\t" \ - "push r24 \n\t" \ - "push r25 \n\t" \ - "push r26 \n\t" \ - "push r27 \n\t" \ - "push r28 \n\t" \ - "push r29 \n\t" \ - "push r30 \n\t" \ - "push r31 \n\t" \ - "lds r26, pxCurrentTCB \n\t" \ - "lds r27, pxCurrentTCB + 1 \n\t" \ - "in r0, 0x3d \n\t" \ - "st x+, r0 \n\t" \ - "in r0, 0x3e \n\t" \ - "st x+, r0 \n\t" \ + asm volatile ( "push r1 \n\t" + "clr r1 \n\t" + "push r2 \n\t" + "push r3 \n\t" + "push r4 \n\t" + "push r5 \n\t" + "push r6 \n\t" + "push r7 \n\t" + "push r8 \n\t" + "push r9 \n\t" + "push r10 \n\t" + "push r11 \n\t" + "push r12 \n\t" + "push r13 \n\t" + "push r14 \n\t" + "push r15 \n\t" + "push r16 \n\t" + "push r17 \n\t" + "push r18 \n\t" + "push r19 \n\t" + "push r20 \n\t" + "push r21 \n\t" + "push r22 \n\t" + "push r23 \n\t" + "push r24 \n\t" + "push r25 \n\t" + "push r26 \n\t" + "push r27 \n\t" + "push r28 \n\t" + "push r29 \n\t" + "push r30 \n\t" + "push r31 \n\t" + "lds r26, pxCurrentTCB \n\t" + "lds r27, pxCurrentTCB + 1 \n\t" + "in r0, 0x3d \n\t" + "st x+, r0 \n\t" + "in r0, 0x3e \n\t" + "st x+, r0 \n\t" ); - +} /* * Opposite to portSAVE_CONTEXT(). Interrupts will have been disabled during * the context save so we can write to the stack pointer. */ - -#define portRESTORE_CONTEXT() \ - asm volatile ( "lds r26, pxCurrentTCB \n\t" \ - "lds r27, pxCurrentTCB + 1 \n\t" \ - "ld r28, x+ \n\t" \ - "out __SP_L__, r28 \n\t" \ - "ld r29, x+ \n\t" \ - "out __SP_H__, r29 \n\t" \ - "pop r31 \n\t" \ - "pop r30 \n\t" \ - "pop r29 \n\t" \ - "pop r28 \n\t" \ - "pop r27 \n\t" \ - "pop r26 \n\t" \ - "pop r25 \n\t" \ - "pop r24 \n\t" \ - "pop r23 \n\t" \ - "pop r22 \n\t" \ - "pop r21 \n\t" \ - "pop r20 \n\t" \ - "pop r19 \n\t" \ - "pop r18 \n\t" \ - "pop r17 \n\t" \ - "pop r16 \n\t" \ - "pop r15 \n\t" \ - "pop r14 \n\t" \ - "pop r13 \n\t" \ - "pop r12 \n\t" \ - "pop r11 \n\t" \ - "pop r10 \n\t" \ - "pop r9 \n\t" \ - "pop r8 \n\t" \ - "pop r7 \n\t" \ - "pop r6 \n\t" \ - "pop r5 \n\t" \ - "pop r4 \n\t" \ - "pop r3 \n\t" \ - "pop r2 \n\t" \ - "pop r1 \n\t" \ - "pop r0 \n\t" \ +inline void portRESTORE_CONTEXT() __attribute__((__always_inline__,__noreturn__)); +inline void portRESTORE_CONTEXT(){ + asm volatile ( "lds r26, pxCurrentTCB \n\t" + "lds r27, pxCurrentTCB + 1 \n\t" + "ld r28, x+ \n\t" + "out __SP_L__, r28 \n\t" + "ld r29, x+ \n\t" + "out __SP_H__, r29 \n\t" + "pop r31 \n\t" + "pop r30 \n\t" + "pop r29 \n\t" + "pop r28 \n\t" + "pop r27 \n\t" + "pop r26 \n\t" + "pop r25 \n\t" + "pop r24 \n\t" + "pop r23 \n\t" + "pop r22 \n\t" + "pop r21 \n\t" + "pop r20 \n\t" + "pop r19 \n\t" + "pop r18 \n\t" + "pop r17 \n\t" + "pop r16 \n\t" + "pop r15 \n\t" + "pop r14 \n\t" + "pop r13 \n\t" + "pop r12 \n\t" + "pop r11 \n\t" + "pop r10 \n\t" + "pop r9 \n\t" + "pop r8 \n\t" + "pop r7 \n\t" + "pop r6 \n\t" + "pop r5 \n\t" + "pop r4 \n\t" + "pop r3 \n\t" + "pop r2 \n\t" + "pop r1 \n\t" + "pop r0 \n\t" ); - #if defined(__AVR_HAVE_RAMPZ__) /* * have RAMPZ Extended Z-pointer Register for ELPM/SPM @@ -239,17 +238,17 @@ extern volatile tskTCB * volatile pxCurrentTCB; * 0x3b --> RAMPZ * 0x3c --> EIND */ -asm volatile ( "out 0x3c, r0 \n\t" \ - "pop r0 \n\t" \ - "out 0x3b, r0 \n\t" \ - "pop r0 \n\t" \ + asm volatile ( "out 0x3c, r0 \n\t" + "pop r0 \n\t" + "out 0x3b, r0 \n\t" + "pop r0 \n\t" ); #endif -asm volatile ( "out __SREG__, r0 \n\t" \ - "pop r0 \n\t" \ +asm volatile ( "out __SREG__, r0 \n\t" + "pop r0 \n\t" ); - +} /*-----------------------------------------------------------*/ /* @@ -292,33 +291,33 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE /* CDCP * __AVR_3_BYTE_PC__ is not official */ -#if defined(__AVR_HAVE_RAMPZ__) || defined(__AVR_3_BYTE_PC__) - // Implement normal stack initialisation but with portLONG instead of portSHORT - usAddress = ( unsigned portLONG ) pxCode; - *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); - pxTopOfStack--; - - usAddress >>= 8; - *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); - pxTopOfStack--; - - // Implemented the 3byte addressing - usAddress >>= 8; - *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); - pxTopOfStack--; - -// Normal initialisation for over ATmega -#else +#if defined(__AVR_HAVE_RAMPZ__) || defined(__AVR_3_BYTE_PC__) + // Implement normal stack initialisation but with portLONG instead of portSHORT + usAddress = ( unsigned portLONG ) pxCode; + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); + pxTopOfStack--; + + usAddress >>= 8; + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); + pxTopOfStack--; + + // Implemented the 3byte addressing + usAddress >>= 8; + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); + pxTopOfStack--; + +// Normal initialisation for over ATmega +#else /* The start of the task code will be popped off the stack last, so place it on first. */ - usAddress = ( unsigned portSHORT ) pxCode; - *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff ); + usAddress = ( unsigned portSHORT ) pxCode; + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff ); pxTopOfStack--; usAddress >>= 8; - *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff ); + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff ); pxTopOfStack--; -#endif +#endif /* Next simulate the stack as if after a call to portSAVE_CONTEXT(). portSAVE_CONTEXT places the flags on the stack immediately after r0 @@ -396,12 +395,12 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxTopOfStack--; /* Place the parameter on the stack in the expected location. */ - usAddress = ( unsigned portSHORT ) pvParameters; - *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff ); + usAddress = ( unsigned portSHORT ) pvParameters; + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff ); pxTopOfStack--; usAddress >>= 8; - *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff ); + *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff ); pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x26; /* R26 X */ @@ -485,42 +484,42 @@ void vPortYieldFromTick( void ) */ static void prvSetupTimerInterrupt( void ) { - // on the ATmega168, timer 0 is also used for fast hardware pwm - // (using phase-correct PWM would mean that timer 0 overflowed half as often - // resulting in different millis() behavior on the ATmega8 and ATmega168) -#if defined(TCCR0A) && defined(WGM01) - sbi(TCCR0A, WGM01); - sbi(TCCR0A, WGM00); -#endif - - // set timer 0 prescale factor to 64 -#if defined(__AVR_ATmega128__) - // CPU specific: different values for the ATmega128 - sbi(TCCR0, CS02); -#elif defined(TCCR0) && defined(CS01) && defined(CS00) - // this combination is for the standard atmega8 - sbi(TCCR0, CS01); - sbi(TCCR0, CS00); -#elif defined(TCCR0B) && defined(CS01) && defined(CS00) - // this combination is for the standard 168/328/1280/2560 - sbi(TCCR0B, CS01); - sbi(TCCR0B, CS00); -#elif defined(TCCR0A) && defined(CS01) && defined(CS00) - // this combination is for the __AVR_ATmega645__ series - sbi(TCCR0A, CS01); - sbi(TCCR0A, CS00); -#else - #error Timer 0 prescale factor 64 not set correctly -#endif - - // enable timer 0 overflow interrupt -#if defined(TIMSK) && defined(TOIE0) - sbi(TIMSK, TOIE0); -#elif defined(TIMSK0) && defined(TOIE0) - sbi(TIMSK0, TOIE0); -#else - #error Timer 0 overflow interrupt not set correctly -#endif + // on the ATmega168, timer 0 is also used for fast hardware pwm + // (using phase-correct PWM would mean that timer 0 overflowed half as often + // resulting in different millis() behavior on the ATmega8 and ATmega168) +#if defined(TCCR0A) && defined(WGM01) + sbi(TCCR0A, WGM01); + sbi(TCCR0A, WGM00); +#endif + + // set timer 0 prescale factor to 64 +#if defined(__AVR_ATmega128__) + // CPU specific: different values for the ATmega128 + sbi(TCCR0, CS02); +#elif defined(TCCR0) && defined(CS01) && defined(CS00) + // this combination is for the standard atmega8 + sbi(TCCR0, CS01); + sbi(TCCR0, CS00); +#elif defined(TCCR0B) && defined(CS01) && defined(CS00) + // this combination is for the standard 168/328/1280/2560 + sbi(TCCR0B, CS01); + sbi(TCCR0B, CS00); +#elif defined(TCCR0A) && defined(CS01) && defined(CS00) + // this combination is for the __AVR_ATmega645__ series + sbi(TCCR0A, CS01); + sbi(TCCR0A, CS00); +#else + #error Timer 0 prescale factor 64 not set correctly +#endif + + // enable timer 0 overflow interrupt +#if defined(TIMSK) && defined(TOIE0) + sbi(TIMSK, TOIE0); +#elif defined(TIMSK0) && defined(TOIE0) + sbi(TIMSK0, TOIE0); +#else + #error Timer 0 overflow interrupt not set correctly +#endif } /*-----------------------------------------------------------*/ From 79cf64e176906e1fe2d3ae25ebc6f93ef83a0a44 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Sun, 31 Mar 2013 03:09:02 -0300 Subject: [PATCH 53/56] Comment Removed --- arduino.DuinOS.AVR/wiring.c | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/arduino.DuinOS.AVR/wiring.c b/arduino.DuinOS.AVR/wiring.c index f866f1c..b0e73e9 100644 --- a/arduino.DuinOS.AVR/wiring.c +++ b/arduino.DuinOS.AVR/wiring.c @@ -41,13 +41,6 @@ volatile unsigned long timer0_overflow_count = 0; volatile unsigned long timer0_millis = 0; static unsigned char timer0_fract = 0; -/* -#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) -SIGNAL(TIM0_OVF_vect) -#else -SIGNAL(TIMER0_OVF_vect) -#endif -*/ void vApplicationTickHook(void) { // copy these to local variables so they can be stored in registers @@ -109,21 +102,6 @@ unsigned long micros() { return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond()); } -/* -void delay(unsigned long ms) -{ - uint16_t start = (uint16_t)micros(); - - while (ms > 0) { - yield(); - if (((uint16_t)micros() - start) >= 1000) { - ms--; - start += 1000; - } - } -} -*/ - /* Delay for the given number of microseconds. Assumes a 8 or 16 MHz clock. */ void delayMicroseconds(unsigned int us) { From d936b26584d157017d09f4142e29eed5005898b6 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Mon, 1 Apr 2013 04:59:48 -0300 Subject: [PATCH 54/56] Fixed type parameter to the function defnition Once the function is always_inline it need not be noreturn not naked. --- arduino.DuinOS.AVR/DuinOS/port.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arduino.DuinOS.AVR/DuinOS/port.c b/arduino.DuinOS.AVR/DuinOS/port.c index 5d30fc2..b98da00 100644 --- a/arduino.DuinOS.AVR/DuinOS/port.c +++ b/arduino.DuinOS.AVR/DuinOS/port.c @@ -125,7 +125,7 @@ extern volatile tskTCB * volatile pxCurrentTCB; * The interrupts will have been disabled during the call to portSAVE_CONTEXT() * so we need not worry about reading/writing to the stack pointer. */ -inline void portSAVE_CONTEXT() __attribute__((__always_inline__,__noreturn__)); +inline void portSAVE_CONTEXT() __attribute__((__always_inline__)); inline void portSAVE_CONTEXT(){ asm volatile ( "push r0 \n\t" "in r0, __SREG__ \n\t" @@ -190,7 +190,7 @@ inline void portSAVE_CONTEXT(){ * Opposite to portSAVE_CONTEXT(). Interrupts will have been disabled during * the context save so we can write to the stack pointer. */ -inline void portRESTORE_CONTEXT() __attribute__((__always_inline__,__noreturn__)); +inline void portRESTORE_CONTEXT() __attribute__((__always_inline__)); inline void portRESTORE_CONTEXT(){ asm volatile ( "lds r26, pxCurrentTCB \n\t" "lds r27, pxCurrentTCB + 1 \n\t" From d9cef95cf045ba048917f5f131c8efe3670a046f Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Mon, 1 Apr 2013 05:00:20 -0300 Subject: [PATCH 55/56] Auxiliary function defined as the Task naked and always_inline The Once the function is always_inline it need not be noreturn not naked. function used in Infinite Loop task is just an object to facilitate the use of the macro that facilitates the access to Task structure for use in the FreeRTOS, so this function must be inserted into the code so which are optimum and avoiding headers function. --- arduino.DuinOS.AVR/DuinOS.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/arduino.DuinOS.AVR/DuinOS.h b/arduino.DuinOS.AVR/DuinOS.h index fc6a161..95dccfc 100644 --- a/arduino.DuinOS.AVR/DuinOS.h +++ b/arduino.DuinOS.AVR/DuinOS.h @@ -34,21 +34,22 @@ extern unsigned portBASE_TYPE mainLoopStackSize; #define NORMAL_PRIORITY (tskIDLE_PRIORITY + 1) #define HIGH_PRIORITY (tskIDLE_PRIORITY + 2) -#define taskLoop(name)\ -void name##Function();\ -xTaskHandle name;\ +#define taskLoop(name) \ +static inline void name##Function() __attribute__((__section__(".text.lowtext"),__naked__,__always_inline__)); \ +void name##_Task(void *) __attribute__((__section__(".text.lowtext"))); \ +xTaskHandle name; \ void name##_Task(void *pvParameters)\ {\ for(;;)\ name##Function();\ }\ -void name##Function() +static inline void name##Function() //This macro enables the forward declaration of a task, to allow other tasks previous defined (with the //taskLoop()macro use and reference them: #define declareTaskLoop(name)\ extern xTaskHandle name;\ - void name##_Task(void*) + void name##_Task(void *) __attribute__((__section__(".text.lowtext"))) #define createTaskLoop(name, priority)\ From 14b8d64b987d6a00dd6ac3839cf1c8fed2e3b634 Mon Sep 17 00:00:00 2001 From: Carlos Delfino Carvalho Pinheiro Date: Sat, 6 Apr 2013 13:39:41 -0300 Subject: [PATCH 56/56] Branch created for us to discuss the types of adjustments on stackpointer and ProgramPointer and some issues about allocation above 64Kb/128Kb --- arduino.DuinOS.AVR/DuinOS/port.c | 53 +++++++-------------------- arduino.DuinOS.AVR/DuinOS/portmacro.h | 8 +++- 2 files changed, 20 insertions(+), 41 deletions(-) diff --git a/arduino.DuinOS.AVR/DuinOS/port.c b/arduino.DuinOS.AVR/DuinOS/port.c index b98da00..a668247 100644 --- a/arduino.DuinOS.AVR/DuinOS/port.c +++ b/arduino.DuinOS.AVR/DuinOS/port.c @@ -262,16 +262,14 @@ static void prvSetupTimerInterrupt( void ); */ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ) { -/* CDCP - * __AVR_3_BYTE_PC__ is not official, and only exist after version 4.1 of GCC - */ -#if defined(__AVR_HAVE_RAMPZ__) || defined(__AVR_3_BYTE_PC__) - unsigned portLONG usAddress; // ATMega2560 have 17bit Program Counter register - // Other future uControler can have up 22, or 24 bits. -#else - unsigned portSHORT usAddress; // over ATmega have 16bit Program Counter register -#endif - + /* + * ATMega2560 have 17bit Program Counter register + * Other future uControler can have up 22, or 24 bits. + * Other ATmega have 16bit Program Counter register. + * but, GCC use a trampoline section over 64K to get + * Function Point with 2 bytes. + */ + unsigned portSHORT usAddress; // over ATmega have 16bit Program Counter register /* Place a few bytes of known values on the bottom of the stack. This is just useful for debugging. */ @@ -288,26 +286,6 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE /*lint -e950 -e611 -e923 Lint doesn't like this much - but nothing I can do about it. */ -/* CDCP - * __AVR_3_BYTE_PC__ is not official - */ -#if defined(__AVR_HAVE_RAMPZ__) || defined(__AVR_3_BYTE_PC__) - // Implement normal stack initialisation but with portLONG instead of portSHORT - usAddress = ( unsigned portLONG ) pxCode; - *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); - pxTopOfStack--; - - usAddress >>= 8; - *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); - pxTopOfStack--; - - // Implemented the 3byte addressing - usAddress >>= 8; - *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portLONG ) 0x000000ff ); - pxTopOfStack--; - -// Normal initialisation for over ATmega -#else /* The start of the task code will be popped off the stack last, so place it on first. */ usAddress = ( unsigned portSHORT ) pxCode; @@ -317,7 +295,6 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE usAddress >>= 8; *pxTopOfStack = ( portSTACK_TYPE ) ( usAddress & ( unsigned portSHORT ) 0x00ff ); pxTopOfStack--; -#endif /* Next simulate the stack as if after a call to portSAVE_CONTEXT(). portSAVE_CONTEXT places the flags on the stack immediately after r0 @@ -328,17 +305,13 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE *pxTopOfStack = portFLAGS_INT_ENABLED; pxTopOfStack--; - /* CDCP - begin*/ + #if defined(__AVR_HAVE_RAMPZ__) - /* - * have RAMPZ Extended Z-pointer Register for ELPM/SPM - * the uC have extend program memory + /* CDCP: + * The Atmega2560 has two more register that we are saving + * The EIND and RAMPZ and we are going to initialize + * this registers to 0 (default initial values) */ - - /* The Atmega2560 has two more register that we are saving - * The EIND and RAMPZ and we are going to initialize - * this registers to 0 (default initial values) - */ *pxTopOfStack = ( portSTACK_TYPE ) 0x00; /* EIND */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x00; /* RAMPZ */ diff --git a/arduino.DuinOS.AVR/DuinOS/portmacro.h b/arduino.DuinOS.AVR/DuinOS/portmacro.h index ba81029..2dc20bd 100644 --- a/arduino.DuinOS.AVR/DuinOS/portmacro.h +++ b/arduino.DuinOS.AVR/DuinOS/portmacro.h @@ -102,9 +102,15 @@ extern "C" { #define portDOUBLE double #define portLONG long #define portSHORT int -#define portSTACK_TYPE unsigned portCHAR +#define portSTACK_TYPE unsigned int /* CDCP: stack size on avr8 is 1024 (0x0400) max, two bytes. */ #define portBASE_TYPE char +/* CDCP: + * ATmega256x/ATmega128x even the pointer is two bytes, + * since GCC uses the "trampoline" to adjust the addresses above 64K. + */ +#define portPOINTER_SIZE_TYPE unsigned int + #if( configUSE_16_BIT_TICKS == 1 ) typedef unsigned portSHORT portTickType; #define portMAX_DELAY ( portTickType ) 0xffff