From 8c2dcfeb16c046bf7fb141f66fa3b6e69460ff28 Mon Sep 17 00:00:00 2001 From: richardbarry Date: Mon, 28 Aug 2006 09:35:31 +0000 Subject: [PATCH] Changes to the AVR demo's. IAR demo updated with new critical section method. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@30 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- Demo/AVR_ATMega323_IAR/FreeRTOSConfig.h | 12 +- Demo/AVR_ATMega323_IAR/main.c | 32 +- Demo/AVR_ATMega323_IAR/rtosdemo.dep | 481 ++++++++++++++++-- Demo/AVR_ATMega323_IAR/rtosdemo.ewd | 50 +- Demo/AVR_ATMega323_IAR/rtosdemo.ewp | 120 +++-- Demo/AVR_ATMega323_IAR/settings/rtosdemo.dni | 9 +- Demo/AVR_ATMega323_IAR/settings/rtosdemo.wsdt | 14 +- Demo/AVR_ATMega323_WinAVR/FreeRTOSConfig.h | 4 +- Demo/AVR_ATMega323_WinAVR/main.c | 34 +- Demo/AVR_ATMega323_WinAVR/makefile | 4 +- Demo/Common/Full/events.c | 6 +- Demo/Common/Minimal/crflash.c | 47 +- Source/croutine.c | 30 +- Source/include/croutine.h | 174 +++---- Source/portable/IAR/ATMega323/port.c | 25 + Source/portable/IAR/ATMega323/portmacro.h | 14 +- Source/portable/oWatcom/16BitDOS/PC/port.c | 2 +- 17 files changed, 803 insertions(+), 255 deletions(-) diff --git a/Demo/AVR_ATMega323_IAR/FreeRTOSConfig.h b/Demo/AVR_ATMega323_IAR/FreeRTOSConfig.h index aac4b8fd9..dc25e0f39 100644 --- a/Demo/AVR_ATMega323_IAR/FreeRTOSConfig.h +++ b/Demo/AVR_ATMega323_IAR/FreeRTOSConfig.h @@ -19,13 +19,13 @@ A special exception to the GPL can be applied should you wish to distribute a combined work that includes FreeRTOS.org, without being obliged to provide - the source code for any proprietary components. See the licensing section + the source code for any proprietary components. See the licensing section of http://www.FreeRTOS.org for full details of how and when the exception can be applied. *************************************************************************** - See http://www.FreeRTOS.org for documentation, latest information, license - and contact details. Please ensure to read the configuration and relevant + See http://www.FreeRTOS.org for documentation, latest information, license + and contact details. Please ensure to read the configuration and relevant port sections of the online documentation. *************************************************************************** */ @@ -44,11 +44,11 @@ * application requirements. * * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE - * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. *----------------------------------------------------------*/ #define configUSE_PREEMPTION 1 -#define configUSE_IDLE_HOOK 0 +#define configUSE_IDLE_HOOK 1 #define configUSE_TICK_HOOK 0 #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) 8000000 ) #define configTICK_RATE_HZ ( ( portTickType ) 1000 ) @@ -61,7 +61,7 @@ #define configIDLE_SHOULD_YIELD 1 /* Co-routine definitions. */ -#define configUSE_CO_ROUTINES 0 +#define configUSE_CO_ROUTINES 1 #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) /* Set the following definitions to 1 to include the API function, or zero diff --git a/Demo/AVR_ATMega323_IAR/main.c b/Demo/AVR_ATMega323_IAR/main.c index e9d0994df..9df726621 100644 --- a/Demo/AVR_ATMega323_IAR/main.c +++ b/Demo/AVR_ATMega323_IAR/main.c @@ -90,15 +90,17 @@ Changes from V2.6.1 /* Scheduler include files. */ #include "FreeRTOS.h" #include "task.h" +#include "croutine.h" /* Demo file headers. */ #include "PollQ.h" #include "integer.h" #include "serial.h" #include "comtest.h" -#include "flash.h" +#include "crflash.h" #include "print.h" #include "partest.h" +#include "regtest.h" /* Priority definitions for most of the tasks in the demo application. Some tasks just use the idle priority. */ @@ -127,6 +129,9 @@ again. */ the demo application is not unexpectedly resetting. */ #define mainRESET_COUNT_ADDRESS ( ( void * ) 0x50 ) +/* The number of coroutines to create. */ +#define mainNUM_FLASH_COROUTINES ( 3 ) + /* * The task function for the "Check" task. */ @@ -144,6 +149,11 @@ static void prvCheckOtherTasksAreStillRunning( void ); */ static void prvIncrementResetCount( void ); +/* + * Idle hook is used to scheduler co-routines. + */ +void vApplicationIdleHook( void ); + portSHORT main( void ) { prvIncrementResetCount(); @@ -151,13 +161,18 @@ portSHORT main( void ) /* Setup the LED's for output. */ vParTestInitialise(); + /* Create the standard demo tasks. */ vStartIntegerMathTasks( tskIDLE_PRIORITY ); vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED ); - vStartLEDFlashTasks( mainLED_TASK_PRIORITY ); vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY ); - + vStartRegTestTasks(); + + /* Create the tasks defined within this file. */ xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL ); + /* Create the co-routines that flash the LED's. */ + vStartFlashCoRoutines( mainNUM_FLASH_COROUTINES ); + /* In this port, to use preemptive scheduler define configUSE_PREEMPTION as 1 in portmacro.h. To use the cooperative scheduler define configUSE_PREEMPTION as 0. */ @@ -209,6 +224,11 @@ static portBASE_TYPE xErrorHasOccurred = pdFALSE; xErrorHasOccurred = pdTRUE; } + if( xAreRegTestTasksStillRunning() != pdTRUE ) + { + xErrorHasOccurred = pdTRUE; + } + if( xErrorHasOccurred == pdFALSE ) { /* Toggle the LED if everything is okay so we know if an error occurs even if not @@ -246,4 +266,10 @@ const unsigned portCHAR ucWrite2 = ( unsigned portCHAR ) 0x02; EECR = ucWrite1; EECR = ( ucWrite1 | ucWrite2 ); } +/*-----------------------------------------------------------*/ + +void vApplicationIdleHook( void ) +{ + vCoRoutineSchedule(); +} diff --git a/Demo/AVR_ATMega323_IAR/rtosdemo.dep b/Demo/AVR_ATMega323_IAR/rtosdemo.dep index 4413b92f4..7624e767c 100644 --- a/Demo/AVR_ATMega323_IAR/rtosdemo.dep +++ b/Demo/AVR_ATMega323_IAR/rtosdemo.dep @@ -1,140 +1,553 @@ - 1 + 2 Debug + + $PROJ_DIR$\..\Common\Minimal\flash.c + $PROJ_DIR$\Output\Obj\flash.pbi + $TOOLKIT_DIR$\inc\clib\sysmac.h + $TOOLKIT_DIR$\inc\clib\stdarg.h + $PROJ_DIR$\Output\Obj\regtest.pbi + $PROJ_DIR$\..\..\Source\include\FreeRTOS.h + $PROJ_DIR$\..\Common\include\PollQ.h + $TOOLKIT_DIR$\inc\clib\stddef.h + $TOOLKIT_DIR$\inc\iomacro.h + $PROJ_DIR$\Output\List\PollQ.lst + $PROJ_DIR$\..\Common\include\partest.h + $PROJ_DIR$\Output\Obj\queue.pbi + $PROJ_DIR$\..\Common\include\flash.h + $TOOLKIT_DIR$\inc\clib\string.h + $TOOLKIT_DIR$\inc\clib\stdlib.h + $PROJ_DIR$\..\..\Source\include\queue.h + $PROJ_DIR$\..\..\Source\include\croutine.h + $PROJ_DIR$\..\Common\include\print.h + $PROJ_DIR$\Output\Obj\ParTest.r90 + $PROJ_DIR$\..\Common\include\serial.h + $PROJ_DIR$\Output\Obj\main.r90 + $PROJ_DIR$\Output\Obj\PollQ.r90 + $PROJ_DIR$\FreeRTOSConfig.h + $PROJ_DIR$\Output\Obj\heap_1.r90 + $PROJ_DIR$\Output\Obj\integer.r90 + $TOOLKIT_DIR$\inc\clib\stdio.h + $PROJ_DIR$\Output\List\tasks.s90 + $PROJ_DIR$\Output\List\queue.lst + $PROJ_DIR$\..\Common\include\integer.h + $TOOLKIT_DIR$\src\template\cfgm323.xcl + $PROJ_DIR$\Output\List\ParTest.lst + $PROJ_DIR$\Output\List\comtest.lst + $PROJ_DIR$\Output\List\tasks.lst + $TOOLKIT_DIR$\inc\iom323.h + $PROJ_DIR$\Output\Obj\comtest.r90 + $PROJ_DIR$\Output\Obj\list.pbi + $PROJ_DIR$\Output\Obj\serial.r90 + $PROJ_DIR$\..\..\Source\portable\IAR\ATMega323\portmacro.h + $PROJ_DIR$\regtest.c + $PROJ_DIR$\Output\Obj\crflash.r90 + $PROJ_DIR$\Output\Obj\rtosdemo.pbd + $PROJ_DIR$\Output\Obj\heap_1.pbi + $PROJ_DIR$\Output\Exe\rtosdemo.d90 + $TOOLKIT_DIR$\lib\clib\cl3s-ec-sf.r90 + $PROJ_DIR$\Output\List\integer.s90 + $PROJ_DIR$\Output\List\serial.lst + $PROJ_DIR$\Output\Obj\integer.pbi + $PROJ_DIR$\Output\Exe\rtosdemo.a90 + $PROJ_DIR$\Output\Obj\main.pbi + $PROJ_DIR$\..\..\Source\include\projdefs.h + $PROJ_DIR$\Output\List\regtest.lst + $PROJ_DIR$\Output\Obj\flash.r90 + $PROJ_DIR$\Output\Obj\list.r90 + $PROJ_DIR$\..\..\Source\include\list.h + $PROJ_DIR$\Output\Obj\tasks.r90 + $PROJ_DIR$\Output\Obj\ParTest.pbi + $PROJ_DIR$\..\Common\include\comtest.h + $PROJ_DIR$\Output\List\main.s90 + $PROJ_DIR$\Output\List\serial.s90 + $PROJ_DIR$\Output\List\port.s90 + $PROJ_DIR$\Output\List\heap_1.lst + $PROJ_DIR$\Output\Exe\rtosdemo.cof + $PROJ_DIR$\Output\List\queue.s90 + $PROJ_DIR$\Output\List\PollQ.s90 + $PROJ_DIR$\Output\Obj\port.pbi + $PROJ_DIR$\Output\List\ParTest.s90 + $PROJ_DIR$\Output\List\integer.lst + $PROJ_DIR$\Output\Obj\port.r90 + $PROJ_DIR$\Output\Obj\comtest.pbi + $PROJ_DIR$\..\..\Source\include\task.h + $TOOLKIT_DIR$\src\template\cfg3soim.xcl + $PROJ_DIR$\Output\List\comtest.s90 + $PROJ_DIR$\Output\List\main.lst + $PROJ_DIR$\Output\List\flash.lst + $PROJ_DIR$\Output\List\flash.s90 + $PROJ_DIR$\Output\List\port.lst + $PROJ_DIR$\Output\List\heap_1.s90 + $PROJ_DIR$\Output\List\list.lst + $PROJ_DIR$\Output\List\rtosdemo.map + $PROJ_DIR$\Output\Obj\tasks.pbi + $PROJ_DIR$\Output\Obj\serial.pbi + $PROJ_DIR$\Output\List\list.s90 + $PROJ_DIR$\Output\Obj\PollQ.pbi + $PROJ_DIR$\Output\List\regtest.s90 + $PROJ_DIR$\Output\List\crflash.s90 + $PROJ_DIR$\..\..\Source\list.c + $PROJ_DIR$\..\..\Source\portable\IAR\ATMega323\portmacro.s90 + $PROJ_DIR$\..\Common\Minimal\PollQ.c + $PROJ_DIR$\ParTest\ParTest.c + $PROJ_DIR$\..\..\Source\portable\IAR\ATMega323\port.c + $PROJ_DIR$\..\..\Source\queue.c + $PROJ_DIR$\Output\Obj\portmacro.r90 + $PROJ_DIR$\..\..\Source\tasks.c + $PROJ_DIR$\serial\serial.c + $PROJ_DIR$\..\..\Source\include\portable.h + $PROJ_DIR$\..\..\Source\portable\MemMang\heap_1.c + $PROJ_DIR$\main.c + $PROJ_DIR$\Output\Exe\rtosdemo.elf + $PROJ_DIR$\..\Common\Minimal\comtest.c + $PROJ_DIR$\Output\Exe\rtosdemo.dbg + $PROJ_DIR$\..\Common\include\crflash.h + $PROJ_DIR$\Output\Obj\queue.r90 + $PROJ_DIR$\Output\List\croutine.lst + $PROJ_DIR$\..\Common\Minimal\integer.c + $PROJ_DIR$\Output\Obj\croutine.r90 + $PROJ_DIR$\Output\List\croutine.s90 + $PROJ_DIR$\regtest.h + $PROJ_DIR$\..\..\Source\croutine.c + $PROJ_DIR$\Output\List\crflash.lst + $PROJ_DIR$\Output\Obj\croutine.pbi + $PROJ_DIR$\..\Common\Minimal\crflash.c + $PROJ_DIR$\Output\Obj\regtest.r90 + $PROJ_DIR$\Output\Obj\crflash.pbi + - $PROJ_DIR$\ParTest\ParTest.c + [ROOT_NODE] + + + XLINK + 47 78 + + + + + $PROJ_DIR$\..\Common\Minimal\flash.c ICCAVR - $PROJ_DIR$\Output\Obj\ParTest.r90 + 51 74 73 + + + BICOMP + 1 + + + ICCAVR + 14 2 5 7 49 22 33 8 94 37 69 53 10 12 + + + BICOMP + 14 2 5 7 49 22 33 8 94 37 69 53 10 12 + + - $PROJ_DIR$\serial\serial.c + $PROJ_DIR$\regtest.c + + + ICCAVR + 111 83 50 + + + BICOMP + 4 + + + + + ICCAVR + 5 7 2 49 22 33 8 94 37 69 53 106 + + + BICOMP + 5 7 2 49 22 33 8 94 37 69 53 106 + + + + + $PROJ_DIR$\Output\Obj\rtosdemo.pbd + + + BILINK + 55 82 68 112 109 41 46 35 48 64 11 4 80 79 + + + + + $PROJ_DIR$\Output\Exe\rtosdemo.d90 + + + XLINK + 29 70 18 21 34 51 23 24 52 20 67 91 101 36 54 43 + + + + + $PROJ_DIR$\Output\Exe\rtosdemo.a90 + + + XLINK + 78 + + + + + XLINK + 29 70 18 21 34 39 104 23 24 52 20 67 91 101 111 36 54 43 + + + + + $PROJ_DIR$\Output\Exe\rtosdemo.cof + + + XLINK + 29 70 18 21 34 51 23 24 52 20 67 91 101 36 54 43 + + + + + $PROJ_DIR$\..\..\Source\list.c ICCAVR - $PROJ_DIR$\Output\Obj\serial.r90 + 52 81 77 + + + BICOMP + 35 + + + ICCAVR + 14 2 5 7 49 22 33 8 94 37 53 + + + BICOMP + 14 2 5 7 49 22 33 8 94 37 53 + + $PROJ_DIR$\..\..\Source\portable\IAR\ATMega323\portmacro.s90 AAVR - $PROJ_DIR$\Output\Obj\portmacro.r90 + 91 + + + AAVR + 33 8 + + - $PROJ_DIR$\..\Common\Minimal\comtest.c + $PROJ_DIR$\..\Common\Minimal\PollQ.c ICCAVR - $PROJ_DIR$\Output\Obj\comtest.r90 + 21 63 9 + + + BICOMP + 82 + + + ICCAVR + 14 2 5 7 49 22 33 8 94 37 69 53 15 6 + + + BICOMP + 14 2 5 7 49 22 33 8 94 37 69 53 15 6 + + - $PROJ_DIR$\..\..\Source\tasks.c + $PROJ_DIR$\ParTest\ParTest.c ICCAVR - $PROJ_DIR$\Output\Obj\tasks.r90 + 18 65 30 + + + BICOMP + 55 + + + ICCAVR + 5 7 2 49 22 33 8 94 37 69 53 10 + + + BICOMP + 5 7 2 49 22 33 8 94 37 69 53 10 + + - $PROJ_DIR$\..\Common\Minimal\integer.c + $PROJ_DIR$\..\..\Source\portable\IAR\ATMega323\port.c ICCAVR - $PROJ_DIR$\Output\Obj\integer.r90 + 67 59 75 + + + BICOMP + 64 + + + ICCAVR + 14 2 5 7 49 22 33 8 94 37 69 53 + + + BICOMP + 14 2 5 7 49 22 33 8 94 37 69 53 + + - $PROJ_DIR$\..\..\Source\portable\MemMang\heap_1.c + $PROJ_DIR$\..\..\Source\queue.c ICCAVR - $PROJ_DIR$\Output\Obj\heap_1.r90 + 101 62 27 + + + BICOMP + 11 + + + ICCAVR + 14 2 13 5 7 49 22 33 8 94 37 69 53 16 + + + BICOMP + 14 2 13 5 7 49 22 33 8 94 37 69 53 16 + + - $PROJ_DIR$\..\..\Source\portable\IAR\ATMega323\port.c + $PROJ_DIR$\..\..\Source\tasks.c ICCAVR - $PROJ_DIR$\Output\Obj\port.r90 + 54 26 32 + + + BICOMP + 79 + + + ICCAVR + 25 3 2 14 13 5 7 49 22 33 8 94 37 69 53 + + + BICOMP + 25 3 2 14 13 5 7 49 22 33 8 94 37 69 53 + + - $PROJ_DIR$\..\Common\Minimal\PollQ.c + $PROJ_DIR$\serial\serial.c ICCAVR - $PROJ_DIR$\Output\Obj\PollQ.r90 + 36 58 45 + + + BICOMP + 80 + + + ICCAVR + 14 2 5 7 49 22 33 8 94 37 15 69 53 19 + + + BICOMP + 14 2 5 7 49 22 33 8 94 37 15 69 53 19 + + - $PROJ_DIR$\..\..\Source\queue.c + $PROJ_DIR$\..\..\Source\portable\MemMang\heap_1.c ICCAVR - $PROJ_DIR$\Output\Obj\queue.r90 + 23 76 60 + + + BICOMP + 41 + + + ICCAVR + 14 2 5 7 49 22 33 8 94 37 69 53 + + + BICOMP + 14 2 5 7 49 22 33 8 94 37 69 53 + + - $PROJ_DIR$\..\Common\Minimal\flash.c + $PROJ_DIR$\main.c ICCAVR - $PROJ_DIR$\Output\Obj\flash.r90 + 20 57 72 + + + BICOMP + 48 + + + ICCAVR + 14 2 13 5 7 49 22 33 8 94 37 69 53 16 6 28 19 56 100 17 10 106 + + + BICOMP + 14 2 13 5 7 49 22 33 8 94 37 69 53 16 6 28 19 56 100 17 10 106 + + - $PROJ_DIR$\main.c + $PROJ_DIR$\Output\Exe\rtosdemo.elf + + + XLINK + 29 70 18 21 34 51 23 24 52 20 67 91 101 36 54 43 + + + + + $PROJ_DIR$\..\Common\Minimal\comtest.c ICCAVR - $PROJ_DIR$\Output\Obj\main.r90 + 34 71 31 + + + BICOMP + 68 + + + ICCAVR + 14 2 5 7 49 22 33 8 94 37 69 53 19 56 10 + + + BICOMP + 14 2 5 7 49 22 33 8 94 37 69 53 19 56 10 + + - $PROJ_DIR$\..\..\Source\list.c + $PROJ_DIR$\Output\Exe\rtosdemo.dbg + + + XLINK + 29 70 18 21 34 39 104 23 24 52 20 67 91 101 36 54 43 + + + + + $PROJ_DIR$\..\Common\Minimal\integer.c ICCAVR - $PROJ_DIR$\Output\Obj\list.r90 + 24 44 66 + + + BICOMP + 46 + + + ICCAVR + 14 2 5 7 49 22 33 8 94 37 69 53 28 + + + BICOMP + 14 2 5 7 49 22 33 8 94 37 69 53 28 + + - [ROOT_NODE] + $PROJ_DIR$\..\..\Source\croutine.c - XLINK - $PROJ_DIR$\Output\Exe\rtosdemo.a90 - $PROJ_DIR$\Output\Exe\rtosdemo.d90 + ICCAVR + 104 105 102 + + + BICOMP + 109 + + + ICCAVR + 5 7 2 49 22 33 8 94 37 69 53 16 + + + BICOMP + 5 7 2 49 22 33 8 94 37 69 53 16 + + + + + $PROJ_DIR$\..\Common\Minimal\crflash.c + + + ICCAVR + 39 84 108 + + + BICOMP + 112 + + + + + ICCAVR + 5 7 2 49 22 33 8 94 37 16 53 15 10 100 + + + BICOMP + 5 7 2 49 22 33 8 94 37 16 53 15 10 100 + + - - [MULTI_TOOL] - XLINK - diff --git a/Demo/AVR_ATMega323_IAR/rtosdemo.ewd b/Demo/AVR_ATMega323_IAR/rtosdemo.ewd index b12d95928..736675fdb 100644 --- a/Demo/AVR_ATMega323_IAR/rtosdemo.ewd +++ b/Demo/AVR_ATMega323_IAR/rtosdemo.ewd @@ -10,9 +10,9 @@ 1 C-SPY - 2 + 3 - 11 + 12 1 1 + @@ -255,9 +259,9 @@ JTAGICEAVR - 2 + 3 - 1 + 2 1 1 + + + JTAGICEMKIIAVR - 1 + 2 - 3 + 4 1 1 + + + @@ -595,16 +623,16 @@ 1 - $EW_DIR$\common\plugins\Profiling\Profiling.ewplugin - 1 + $EW_DIR$\common\plugins\Orti\Orti.ewplugin + 0 - $EW_DIR$\common\plugins\Trace\Trace.ewplugin + $EW_DIR$\common\plugins\Profiling\Profiling.ewplugin 1 - $EW_DIR$\common\plugins\Orti\Orti.ewplugin - 0 + $EW_DIR$\common\plugins\Stack\stack.ewplugin + 1 diff --git a/Demo/AVR_ATMega323_IAR/rtosdemo.ewp b/Demo/AVR_ATMega323_IAR/rtosdemo.ewp index b18aa583c..c1b517e0d 100644 --- a/Demo/AVR_ATMega323_IAR/rtosdemo.ewp +++ b/Demo/AVR_ATMega323_IAR/rtosdemo.ewp @@ -127,8 +127,8 @@ @@ -962,45 +970,57 @@ - - $PROJ_DIR$\..\Common\Minimal\comtest.c - - - $PROJ_DIR$\..\Common\Minimal\flash.c - - - $PROJ_DIR$\..\..\Source\portable\MemMang\heap_1.c - - - $PROJ_DIR$\..\Common\Minimal\integer.c - - - $PROJ_DIR$\..\..\Source\list.c - - - $PROJ_DIR$\main.c - - - $PROJ_DIR$\ParTest\ParTest.c - - - $PROJ_DIR$\..\Common\Minimal\PollQ.c - - - $PROJ_DIR$\..\..\Source\portable\IAR\ATMega323\port.c - - - $PROJ_DIR$\..\..\Source\portable\IAR\ATMega323\portmacro.s90 - - - $PROJ_DIR$\..\..\Source\queue.c - - - $PROJ_DIR$\serial\serial.c - - - $PROJ_DIR$\..\..\Source\tasks.c - + + Demo Source + + $PROJ_DIR$\..\Common\Minimal\comtest.c + + + $PROJ_DIR$\..\Common\Minimal\crflash.c + + + $PROJ_DIR$\..\..\Source\portable\MemMang\heap_1.c + + + $PROJ_DIR$\..\Common\Minimal\integer.c + + + $PROJ_DIR$\main.c + + + $PROJ_DIR$\ParTest\ParTest.c + + + $PROJ_DIR$\..\Common\Minimal\PollQ.c + + + $PROJ_DIR$\regtest.c + + + $PROJ_DIR$\serial\serial.c + + + + Kernel Source + + $PROJ_DIR$\..\..\Source\croutine.c + + + $PROJ_DIR$\..\..\Source\list.c + + + $PROJ_DIR$\..\..\Source\portable\IAR\ATMega323\port.c + + + $PROJ_DIR$\..\..\Source\portable\IAR\ATMega323\portmacro.s90 + + + $PROJ_DIR$\..\..\Source\queue.c + + + $PROJ_DIR$\..\..\Source\tasks.c + + diff --git a/Demo/AVR_ATMega323_IAR/settings/rtosdemo.dni b/Demo/AVR_ATMega323_IAR/settings/rtosdemo.dni index cdd173771..9fdf1aa6d 100644 --- a/Demo/AVR_ATMega323_IAR/settings/rtosdemo.dni +++ b/Demo/AVR_ATMega323_IAR/settings/rtosdemo.dni @@ -27,12 +27,15 @@ Wnd8=_ "Locals" "closed" 44 0 1 -1 -1 -1 -1 1139 0 1595 276 100 100 100 100 Wnd9=_ "Terminal I/O" "closed" 44 0 1 -1 -1 -1 -1 1138 522 1595 826 Maximized=_ 0 Count=_ 10 -[Log file] +[TermIOLog] LoggingEnabled=_ 0 LogFile=_ "" -Category=_ 0 -[TermIOLog] +[Log file] LoggingEnabled=_ 0 LogFile=_ "" +Category=_ 0 [Breakpoints] Count=0 +[TraceHelper] +Enabled=0 +ShowSource=1 diff --git a/Demo/AVR_ATMega323_IAR/settings/rtosdemo.wsdt b/Demo/AVR_ATMega323_IAR/settings/rtosdemo.wsdt index f12a20b8b..9f6c956df 100644 --- a/Demo/AVR_ATMega323_IAR/settings/rtosdemo.wsdt +++ b/Demo/AVR_ATMega323_IAR/settings/rtosdemo.wsdt @@ -12,12 +12,12 @@ - 109272727 + 246272727 - 20115330776 + 20115330776 - + TabID-12388-19520 @@ -25,24 +25,24 @@ Workspace - rtosdemortosdemo/portheap.c + rtosdemortosdemo/Demo Sourcertosdemo/Kernel Sourcertosdemo/portheap.c - 0TabID-19172-8303BuildBuild0 + 0TabID-19172-8303BuildBuildTabID-954-28216Debug LogDebug-Log0 - 0100000010000001 + TextEditorC:\E\Dev\FreeRTOS\Demo\AVR_ATMega323_IAR\regtest.c0190661966190TextEditorC:\E\Dev\FreeRTOS\Demo\AVR_ATMega323_IAR\main.c012355005500TextEditorC:\E\Dev\FreeRTOS\Demo\Common\Minimal\crflash.c0170680768070100000010000001 - iaridepm1-2-2718183-2-2185185115625165326115625643431-2-23541602-2-216043561002500318141116250166219 + iaridepm1-2-2619320-2-2162161115714165638230000638889-2-23071402-2-214043091002857317901116429166667 diff --git a/Demo/AVR_ATMega323_WinAVR/FreeRTOSConfig.h b/Demo/AVR_ATMega323_WinAVR/FreeRTOSConfig.h index 5ca2c6479..0b241f7d6 100644 --- a/Demo/AVR_ATMega323_WinAVR/FreeRTOSConfig.h +++ b/Demo/AVR_ATMega323_WinAVR/FreeRTOSConfig.h @@ -46,7 +46,7 @@ *----------------------------------------------------------*/ #define configUSE_PREEMPTION 1 -#define configUSE_IDLE_HOOK 0 +#define configUSE_IDLE_HOOK 1 #define configUSE_TICK_HOOK 0 #define configCPU_CLOCK_HZ ( ( unsigned portLONG ) 8000000 ) #define configTICK_RATE_HZ ( ( portTickType ) 1000 ) @@ -59,7 +59,7 @@ #define configIDLE_SHOULD_YIELD 1 /* Co-routine definitions. */ -#define configUSE_CO_ROUTINES 0 +#define configUSE_CO_ROUTINES 1 #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) /* Set the following definitions to 1 to include the API function, or zero diff --git a/Demo/AVR_ATMega323_WinAVR/main.c b/Demo/AVR_ATMega323_WinAVR/main.c index 6190f0764..a2e6e8315 100644 --- a/Demo/AVR_ATMega323_WinAVR/main.c +++ b/Demo/AVR_ATMega323_WinAVR/main.c @@ -86,15 +86,17 @@ Changes from V2.6.1 /* Scheduler include files. */ #include "FreeRTOS.h" #include "task.h" +#include "croutine.h" /* Demo file headers. */ #include "PollQ.h" #include "integer.h" #include "serial.h" #include "comtest.h" -#include "flash.h" +#include "crflash.h" #include "print.h" #include "partest.h" +#include "regtest.h" /* Priority definitions for most of the tasks in the demo application. Some tasks just use the idle priority. */ @@ -123,6 +125,9 @@ again. */ the demo application is not unexpectedly resetting. */ #define mainRESET_COUNT_ADDRESS ( ( void * ) 0x50 ) +/* The number of coroutines to create. */ +#define mainNUM_FLASH_COROUTINES ( 3 ) + /* * The task function for the "Check" task. */ @@ -140,6 +145,13 @@ static void prvCheckOtherTasksAreStillRunning( void ); */ static void prvIncrementResetCount( void ); +/* + * The idle hook is used to scheduler co-routines. + */ +void vApplicationIdleHook( void ); + +/*-----------------------------------------------------------*/ + portSHORT main( void ) { prvIncrementResetCount(); @@ -147,13 +159,18 @@ portSHORT main( void ) /* Setup the LED's for output. */ vParTestInitialise(); + /* Create the standard demo tasks. */ vStartIntegerMathTasks( tskIDLE_PRIORITY ); vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED ); - vStartLEDFlashTasks( mainLED_TASK_PRIORITY ); vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY ); - + vStartRegTestTasks(); + + /* Create the tasks defined within this file. */ xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL ); + /* Create the co-routines that flash the LED's. */ + vStartFlashCoRoutines( mainNUM_FLASH_COROUTINES ); + /* In this port, to use preemptive scheduler define configUSE_PREEMPTION as 1 in portmacro.h. To use the cooperative scheduler define configUSE_PREEMPTION as 0. */ @@ -205,6 +222,11 @@ static portBASE_TYPE xErrorHasOccurred = pdFALSE; xErrorHasOccurred = pdTRUE; } + if( xAreRegTestTasksStillRunning() != pdTRUE ) + { + xErrorHasOccurred = pdTRUE; + } + if( xErrorHasOccurred == pdFALSE ) { /* Toggle the LED if everything is okay so we know if an error occurs even if not @@ -222,4 +244,10 @@ unsigned portCHAR ucCount; ucCount++; eeprom_write_byte( mainRESET_COUNT_ADDRESS, ucCount ); } +/*-----------------------------------------------------------*/ + +void vApplicationIdleHook( void ) +{ + vCoRoutineSchedule(); +} diff --git a/Demo/AVR_ATMega323_WinAVR/makefile b/Demo/AVR_ATMega323_WinAVR/makefile index 5c48ba064..9bd557d1b 100644 --- a/Demo/AVR_ATMega323_WinAVR/makefile +++ b/Demo/AVR_ATMega323_WinAVR/makefile @@ -53,12 +53,14 @@ SRC = \ main.c \ ParTest/ParTest.c \ serial/serial.c \ +regtest.c \ $(SOURCE_DIR)/tasks.c \ $(SOURCE_DIR)/queue.c \ $(SOURCE_DIR)/list.c \ +$(SOURCE_DIR)/croutine.c \ $(SOURCE_DIR)/portable/MemMang/heap_1.c \ $(PORT_DIR)/port.c \ -$(DEMO_DIR)/flash.c \ +$(DEMO_DIR)/crflash.c \ $(DEMO_DIR)/integer.c \ $(DEMO_DIR)/PollQ.c \ $(DEMO_DIR)/comtest.c diff --git a/Demo/Common/Full/events.c b/Demo/Common/Full/events.c index 668b17fb9..d4fe7053e 100644 --- a/Demo/Common/Full/events.c +++ b/Demo/Common/Full/events.c @@ -39,7 +39,7 @@ * the same queue. The controlling task writes data to the queue, then checks * to see which of the event tasks read the data from the queue. The * controlling task has the lowest priority of all the tasks so is guaranteed - * to always get preempted immediately upon writhing to the queue. + * to always get preempted immediately upon writing to the queue. * * By selectively suspending and resuming the event tasks the controlling task * can check that the highest priority task that is blocked on the queue is the @@ -172,6 +172,10 @@ const portCHAR * const pcTaskStartMsg = "Multi event task started.\r\n"; the counter specific to this task instance. */ ( *pxCounter )++; } + else + { + xHealthStatus = pdFAIL; + } } } /*-----------------------------------------------------------*/ diff --git a/Demo/Common/Minimal/crflash.c b/Demo/Common/Minimal/crflash.c index ae1ad9e1a..279777981 100644 --- a/Demo/Common/Minimal/crflash.c +++ b/Demo/Common/Minimal/crflash.c @@ -19,39 +19,39 @@ A special exception to the GPL can be applied should you wish to distribute a combined work that includes FreeRTOS.org, without being obliged to provide - the source code for any proprietary components. See the licensing section + the source code for any proprietary components. See the licensing section of http://www.FreeRTOS.org for full details of how and when the exception can be applied. *************************************************************************** - See http://www.FreeRTOS.org for documentation, latest information, license - and contact details. Please ensure to read the configuration and relevant + See http://www.FreeRTOS.org for documentation, latest information, license + and contact details. Please ensure to read the configuration and relevant port sections of the online documentation. *************************************************************************** */ -/* +/* * This demo application file demonstrates the use of queues to pass data * between co-routines. * * N represents the number of 'fixed delay' co-routines that are created and * is set during initialisation. * - * N 'fixed delay' co-routines are created that just block for a fixed + * N 'fixed delay' co-routines are created that just block for a fixed * period then post the number of an LED onto a queue. Each such co-routine - * uses a different block period. A single 'flash' co-routine is also created - * that blocks on the same queue, waiting for the number of the next LED it - * should flash. Upon receiving a number it simply toggle the instructed LED - * then blocks on the queue once more. In this manner each LED from LED 0 to + * uses a different block period. A single 'flash' co-routine is also created + * that blocks on the same queue, waiting for the number of the next LED it + * should flash. Upon receiving a number it simply toggle the instructed LED + * then blocks on the queue once more. In this manner each LED from LED 0 to * LED N-1 is caused to flash at a different rate. * * The 'fixed delay' co-routines are created with co-routine priority 0. The * flash co-routine is created with co-routine priority 1. This means that * the queue should never contain more than a single item. This is because * posting to the queue will unblock the 'flash' co-routine, and as this has - * a priority greater than the tasks posting to the queue it is guaranteed to + * a priority greater than the tasks posting to the queue it is guaranteed to * have emptied the queue and blocked once again before the queue can contain - * any more date. An error is indicated if an attempt to post data to the + * any more date. An error is indicated if an attempt to post data to the * queue fails - indicating that the queue is already full. * */ @@ -82,7 +82,7 @@ created. */ /* We don't want to block when posting to the queue. */ #define crfPOSTING_BLOCK_TIME 0 -/* +/* * The 'fixed delay' co-routine as described at the top of the file. */ static void prvFixedDelayCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex ); @@ -134,16 +134,16 @@ static void prvFixedDelayCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_ { /* Even though this is a co-routine the xResult variable does not need to be static as we do not need it to maintain its state between blocks. */ -portBASE_TYPE xResult; -/* The uxIndex parameter of the co-routine function is used as an index into +signed portBASE_TYPE xResult; +/* The uxIndex parameter of the co-routine function is used as an index into the xFlashRates array to obtain the delay period to use. */ -static const portTickType xFlashRates[ crfMAX_FLASH_TASKS ] = { 150 / portTICK_RATE_MS, - 200 / portTICK_RATE_MS, - 250 / portTICK_RATE_MS, - 300 / portTICK_RATE_MS, +static const portTickType xFlashRates[ crfMAX_FLASH_TASKS ] = { 150 / portTICK_RATE_MS, + 200 / portTICK_RATE_MS, + 250 / portTICK_RATE_MS, + 300 / portTICK_RATE_MS, 350 / portTICK_RATE_MS, - 400 / portTICK_RATE_MS, - 450 / portTICK_RATE_MS, + 400 / portTICK_RATE_MS, + 450 / portTICK_RATE_MS, 500 / portTICK_RATE_MS }; /* Co-routines MUST start with a call to crSTART. */ @@ -151,7 +151,7 @@ static const portTickType xFlashRates[ crfMAX_FLASH_TASKS ] = { 150 / portTICK_R for( ;; ) { - /* Post our uxIndex value onto the queue. This is used as the LED to + /* Post our uxIndex value onto the queue. This is used as the LED to flash. */ crQUEUE_SEND( xHandle, xFlashQueue, ( void * ) &uxIndex, crfPOSTING_BLOCK_TIME, &xResult ); @@ -175,12 +175,13 @@ static void prvFlashCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE { /* Even though this is a co-routine the variable do not need to be static as we do not need it to maintain their state between blocks. */ -portBASE_TYPE xResult; +signed portBASE_TYPE xResult; unsigned portBASE_TYPE uxLEDToFlash; /* Co-routines MUST start with a call to crSTART. */ crSTART( xHandle ); - + ( void ) uxIndex; + for( ;; ) { /* Block to wait for the number of the LED to flash. */ diff --git a/Source/croutine.c b/Source/croutine.c index 02ad546bb..6c9f60a55 100644 --- a/Source/croutine.c +++ b/Source/croutine.c @@ -51,8 +51,8 @@ static portTickType xCoRoutineTickCount = 0; #define corINITIAL_STATE ( 0 ) /* - * Place the co-routine represented by pxCRCB into the appropriate ready queue - * for the priority. It is inserted at the end of the list. + * Place the co-routine represented by pxCRCB into the appropriate ready queue + * for the priority. It is inserted at the end of the list. * * This macro accesses the co-routine ready lists and therefore must not be * used from within an ISR. @@ -81,20 +81,20 @@ static void prvInitialiseCoRoutineLists( void ); static inline void prvCheckPendingReadyList( void ); /* - * Macro that looks at the list of co-routines that are currently delayed to + * Macro that looks at the list of co-routines that are currently delayed to * see if any require waking. * - * Co-routines are stored in the queue in the order of their wake time - - * meaning once one co-routine has been found whose timer has not expired + * Co-routines are stored in the queue in the order of their wake time - + * meaning once one co-routine has been found whose timer has not expired * we need not look any further down the list. */ static inline void prvCheckDelayedList( void ); /*-----------------------------------------------------------*/ -portBASE_TYPE xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, unsigned portBASE_TYPE uxPriority, unsigned portBASE_TYPE uxIndex ) +signed portBASE_TYPE xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, unsigned portBASE_TYPE uxPriority, unsigned portBASE_TYPE uxIndex ) { -portBASE_TYPE xReturn; +signed portBASE_TYPE xReturn; corCRCB *pxCoRoutine; /* Allocate the memory that will store the co-routine control block. */ @@ -125,8 +125,8 @@ corCRCB *pxCoRoutine; vListInitialiseItem( &( pxCoRoutine->xGenericListItem ) ); vListInitialiseItem( &( pxCoRoutine->xEventListItem ) ); - /* Set the co-routine control block as a link back from the xListItem. - This is so we can get back to the containing CRCB from a generic item + /* Set the co-routine control block as a link back from the xListItem. + This is so we can get back to the containing CRCB from a generic item in a list. */ listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xGenericListItem ), pxCoRoutine ); listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xEventListItem ), pxCoRoutine ); @@ -190,7 +190,7 @@ portTickType xTimeToWake; static inline void prvCheckPendingReadyList( void ) { /* Are there any co-routines waiting to get moved to the ready list? These - are co-routines that have been readied by an ISR. The ISR cannot access + are co-routines that have been readied by an ISR. The ISR cannot access the ready lists itself. */ while( !listLIST_IS_EMPTY( &xPendingReadyList ) ) { @@ -244,9 +244,9 @@ corCRCB *pxCRCB; portDISABLE_INTERRUPTS(); { - /* The event could have occurred just before this critical + /* The event could have occurred just before this critical section. If this is the case then the generic list item will - have been moved to the pending ready list and the following + 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 ) ); @@ -310,17 +310,17 @@ unsigned portBASE_TYPE uxPriority; vListInitialise( ( xList * ) &xDelayedCoRoutineList2 ); vListInitialise( ( xList * ) &xPendingReadyList ); - /* Start with pxDelayedCoRoutineList using list1 and the + /* Start with pxDelayedCoRoutineList using list1 and the pxOverflowDelayedCoRoutineList using list2. */ pxDelayedCoRoutineList = &xDelayedCoRoutineList1; pxOverflowDelayedCoRoutineList = &xDelayedCoRoutineList2; } /*-----------------------------------------------------------*/ -portBASE_TYPE xCoRoutineRemoveFromEventList( const xList *pxEventList ) +signed portBASE_TYPE xCoRoutineRemoveFromEventList( const xList *pxEventList ) { corCRCB *pxUnblockedCRCB; -portBASE_TYPE xReturn; +signed portBASE_TYPE xReturn; /* This function is called from within an interrupt. It can only access event lists and the pending ready list. */ diff --git a/Source/include/croutine.h b/Source/include/croutine.h index 24f44545a..516997855 100644 --- a/Source/include/croutine.h +++ b/Source/include/croutine.h @@ -34,8 +34,8 @@ #include "list.h" -/* Used to hide the implementation of the co-routine control block. The -control block structure however has to be included in the header due to +/* Used to hide the implementation of the co-routine control block. The +control block structure however has to be included in the header due to the macro implementation of the co-routine functionality. */ typedef void * xCoRoutineHandle; @@ -61,14 +61,14 @@ typedef struct corCoRoutineControlBlock unsigned portBASE_TYPE uxIndex ); * - * Create a new co-routine and add it to the list of co-routines that are + * Create a new co-routine and add it to the list of co-routines that are * ready to run. * - * @param pxCoRoutineCode Pointer to the co-routine function. Co-routine - * functions require special syntax - see the co-routine section of the WEB + * @param pxCoRoutineCode Pointer to the co-routine function. Co-routine + * functions require special syntax - see the co-routine section of the WEB * documentation for more information. * - * @param uxPriority The priority with respect to other co-routines at which + * @param uxPriority The priority with respect to other co-routines at which * the co-routine will run. * * @param uxIndex Used to distinguish between different co-routines that @@ -118,13 +118,13 @@ typedef struct corCoRoutineControlBlock for( uxIndex = 0; uxIndex < 2; uxIndex++ ) { xCoRoutineCreate( vFlashCoRoutine, 0, uxIndex ); - } + } } * \defgroup xCoRoutineCreate xCoRoutineCreate * \ingroup Tasks */ -portBASE_TYPE xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, unsigned portBASE_TYPE uxPriority, unsigned portBASE_TYPE uxIndex ); +signed portBASE_TYPE xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, unsigned portBASE_TYPE uxPriority, unsigned portBASE_TYPE uxIndex ); /** @@ -133,14 +133,14 @@ portBASE_TYPE xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, unsigned portB void vCoRoutineSchedule( void ); * * Run a co-routine. - * + * * vCoRoutineSchedule() executes the highest priority co-routine that is able * to run. The co-routine will execute until it either blocks, yields or is - * preempted by a task. Co-routines execute cooperatively so one + * preempted by a task. Co-routines execute cooperatively so one * co-routine cannot be preempted by another, but can be preempted by a task. * - * If an application comprises of both tasks and co-routines then - * vCoRoutineSchedule should be called from the idle task (in an idle task + * If an application comprises of both tasks and co-routines then + * vCoRoutineSchedule should be called from the idle task (in an idle task * hook). * * Example usage: @@ -152,7 +152,7 @@ portBASE_TYPE xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, unsigned portB vCoRoutineSchedule(); } - // Alternatively, if you do not require any other part of the idle task to + // Alternatively, if you do not require any other part of the idle task to // execute, the idle task hook can call vCoRoutineScheduler() within an // infinite loop. void vApplicationIdleHook( void ) @@ -231,7 +231,7 @@ void vCoRoutineSchedule( void ); #define crEND() } /* - * These macros are intended for internal use by the co-routine implementation + * These macros are intended for internal use by the co-routine implementation * only. The macros should not be used directly by application writers. */ #define crSET_STATE0( xHandle ) ( ( corCRCB * )xHandle)->uxState = (__LINE__ * 2); return; case (__LINE__ * 2): @@ -251,8 +251,8 @@ void vCoRoutineSchedule( void ); * @param xHandle The handle of the co-routine to delay. This is the xHandle * parameter of the co-routine function. * - * @param xTickToDelay The number of ticks that the co-routine should delay - * for. The actual amount of time this equates to is defined by + * @param xTickToDelay The number of ticks that the co-routine should delay + * for. The actual amount of time this equates to is defined by * configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant portTICK_RATE_MS * can be used to convert ticks to milliseconds. * @@ -292,33 +292,33 @@ void vCoRoutineSchedule( void ); /** *
- crQUEUE_SEND( 
-                  xCoRoutineHandle xHandle, 
-                  xQueueHandle pxQueue, 
-                  void *pvItemToQueue, 
-                  portTickType xTicksToWait, 
-                  portBASE_TYPE *pxResult 
+ crQUEUE_SEND(
+                  xCoRoutineHandle xHandle,
+                  xQueueHandle pxQueue,
+                  void *pvItemToQueue,
+                  portTickType xTicksToWait,
+                  portBASE_TYPE *pxResult
              )
* - * The macro's crQUEUE_SEND() and crQUEUE_RECEIVE() are the co-routine - * equivalent to the xQueueSend() and xQueueReceive() functions used by tasks. + * The macro's crQUEUE_SEND() and crQUEUE_RECEIVE() are the co-routine + * equivalent to the xQueueSend() and xQueueReceive() functions used by tasks. * - * crQUEUE_SEND and crQUEUE_RECEIVE can only be used from a co-routine whereas + * crQUEUE_SEND and crQUEUE_RECEIVE can only be used from a co-routine whereas * xQueueSend() and xQueueReceive() can only be used from tasks. * * crQUEUE_SEND can only be called from the co-routine function itself - not * from within a function called by the co-routine function. This is because * co-routines do not maintain their own stack. * - * See the co-routine section of the WEB documentation for information on - * passing data between tasks and co-routines and between ISR's and + * See the co-routine section of the WEB documentation for information on + * passing data between tasks and co-routines and between ISR's and * co-routines. * * @param xHandle The handle of the calling co-routine. This is the xHandle * parameter of the co-routine function. * - * @param pxQueue The handle of the queue on which the data will be posted. - * The handle is obtained as the return value when the queue is created using + * @param pxQueue The handle of the queue on which the data will be posted. + * The handle is obtained as the return value when the queue is created using * the xQueueCreate() API function. * * @param pvItemToQueue A pointer to the data being posted onto the queue. @@ -326,15 +326,15 @@ void vCoRoutineSchedule( void ); * created. This number of bytes is copied from pvItemToQueue into the queue * itself. * - * @param xTickToDelay The number of ticks that the co-routine should block + * @param xTickToDelay The number of ticks that the co-routine should block * to wait for space to become available on the queue, should space not be - * available immediately. The actual amount of time this equates to is defined - * by configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant + * available immediately. The actual amount of time this equates to is defined + * by configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant * portTICK_RATE_MS can be used to convert ticks to milliseconds (see example * below). * * @param pxResult The variable pointed to by pxResult will be set to pdPASS if - * data was successfully posted onto the queue, otherwise it will be set to an + * data was successfully posted onto the queue, otherwise it will be set to an * error defined within ProjDefs.h. * * Example usage: @@ -362,7 +362,7 @@ void vCoRoutineSchedule( void ); // Increment the number to be posted onto the queue. xNumberToPost++; - + // Delay for 100 ticks. crDELAY( xHandle, 100 ); } @@ -391,43 +391,43 @@ void vCoRoutineSchedule( void ); /** * croutine. h *
-  crQUEUE_RECEIVE( 
-                     xCoRoutineHandle xHandle, 
-                     xQueueHandle pxQueue, 
-                     void *pvBuffer, 
-                     portTickType xTicksToWait, 
-                     portBASE_TYPE *pxResult 
+  crQUEUE_RECEIVE(
+                     xCoRoutineHandle xHandle,
+                     xQueueHandle pxQueue,
+                     void *pvBuffer,
+                     portTickType xTicksToWait,
+                     portBASE_TYPE *pxResult
                  )
* - * The macro's crQUEUE_SEND() and crQUEUE_RECEIVE() are the co-routine - * equivalent to the xQueueSend() and xQueueReceive() functions used by tasks. + * The macro's crQUEUE_SEND() and crQUEUE_RECEIVE() are the co-routine + * equivalent to the xQueueSend() and xQueueReceive() functions used by tasks. * - * crQUEUE_SEND and crQUEUE_RECEIVE can only be used from a co-routine whereas + * crQUEUE_SEND and crQUEUE_RECEIVE can only be used from a co-routine whereas * xQueueSend() and xQueueReceive() can only be used from tasks. * * crQUEUE_RECEIVE can only be called from the co-routine function itself - not * from within a function called by the co-routine function. This is because * co-routines do not maintain their own stack. * - * See the co-routine section of the WEB documentation for information on - * passing data between tasks and co-routines and between ISR's and + * See the co-routine section of the WEB documentation for information on + * passing data between tasks and co-routines and between ISR's and * co-routines. * * @param xHandle The handle of the calling co-routine. This is the xHandle * parameter of the co-routine function. * - * @param pxQueue The handle of the queue from which the data will be received. - * The handle is obtained as the return value when the queue is created using + * @param pxQueue The handle of the queue from which the data will be received. + * The handle is obtained as the return value when the queue is created using * the xQueueCreate() API function. * * @param pvBuffer The buffer into which the received item is to be copied. * The number of bytes of each queued item is specified when the queue is * created. This number of bytes is copied into pvBuffer. * - * @param xTickToDelay The number of ticks that the co-routine should block + * @param xTickToDelay The number of ticks that the co-routine should block * to wait for data to become available from the queue, should data not be - * available immediately. The actual amount of time this equates to is defined - * by configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant + * available immediately. The actual amount of time this equates to is defined + * by configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant * portTICK_RATE_MS can be used to convert ticks to milliseconds (see the * crQUEUE_SEND example). * @@ -437,7 +437,7 @@ void vCoRoutineSchedule( void ); * * Example usage:
- // A co-routine receives the number of an LED to flash from a queue.  It 
+ // A co-routine receives the number of an LED to flash from a queue.  It
  // blocks on the queue until the number is received.
  static void prvCoRoutineFlashWorkTask( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
  {
@@ -483,31 +483,31 @@ void vCoRoutineSchedule( void );
 /**
  * croutine. h
  * 
-  crQUEUE_SEND_FROM_ISR( 
-                            xQueueHandle pxQueue, 
-                            void *pvItemToQueue, 
+  crQUEUE_SEND_FROM_ISR(
+                            xQueueHandle pxQueue,
+                            void *pvItemToQueue,
                             portBASE_TYPE xCoRoutinePreviouslyWoken
                        )
* - * The macro's crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() are the - * co-routine equivalent to the xQueueSendFromISR() and xQueueReceiveFromISR() - * functions used by tasks. + * The macro's crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() are the + * co-routine equivalent to the xQueueSendFromISR() and xQueueReceiveFromISR() + * functions used by tasks. * * crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() can only be used to - * pass data between a co-routine and and ISR, whereas xQueueSendFromISR() and + * pass data between a co-routine and and ISR, whereas xQueueSendFromISR() and * xQueueReceiveFromISR() can only be used to pass data between a task and and * ISR. * * crQUEUE_SEND_FROM_ISR can only be called from an ISR to send data to a queue * that is being used from within a co-routine. * - * See the co-routine section of the WEB documentation for information on - * passing data between tasks and co-routines and between ISR's and + * See the co-routine section of the WEB documentation for information on + * passing data between tasks and co-routines and between ISR's and * co-routines. * * @param xQueue The handle to the queue on which the item is to be posted. - * - * @param pvItemToQueue A pointer to the item that is to be placed on the + * + * @param pvItemToQueue A pointer to the item that is to be placed on the * queue. The size of the items the queue will hold was defined when the * queue was created, so this many bytes will be copied from pvItemToQueue * into the queue storage area. @@ -515,9 +515,9 @@ void vCoRoutineSchedule( void ); * @param xCoRoutinePreviouslyWoken This is included so an ISR can post onto * the same queue multiple times from a single interrupt. The first call * should always pass in pdFALSE. Subsequent calls should pass in - * the value returned from the previous call. + * the value returned from the previous call. * - * @return pdTRUE if a co-routine was woken by posting onto the queue. This is + * @return pdTRUE if a co-routine was woken by posting onto the queue. This is * used by the ISR to determine if a context switch may be required following * the ISR. * @@ -537,7 +537,7 @@ void vCoRoutineSchedule( void ); // Wait for data to become available on the queue. This assumes the // queue xCommsRxQueue has already been created! crQUEUE_RECEIVE( xHandle, xCommsRxQueue, &uxLEDToFlash, portMAX_DELAY, &xResult ); - + // Was a character received? if( xResult == pdPASS ) { @@ -561,8 +561,8 @@ void vCoRoutineSchedule( void ); { // Obtain the character from the UART. cRxedChar = UART_RX_REG; - - // Post the character onto a queue. xCRWokenByPost will be pdFALSE + + // Post the character onto a queue. xCRWokenByPost will be pdFALSE // the first time around the loop. If the post causes a co-routine // to be woken (unblocked) then xCRWokenByPost will be set to pdTRUE. // In this manner we can ensure that if more than one co-routine is @@ -580,39 +580,39 @@ void vCoRoutineSchedule( void ); /** * croutine. h *
-  crQUEUE_SEND_FROM_ISR( 
-                            xQueueHandle pxQueue, 
-                            void *pvBuffer, 
+  crQUEUE_SEND_FROM_ISR(
+                            xQueueHandle pxQueue,
+                            void *pvBuffer,
                             portBASE_TYPE * pxCoRoutineWoken
                        )
* - * The macro's crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() are the - * co-routine equivalent to the xQueueSendFromISR() and xQueueReceiveFromISR() - * functions used by tasks. + * The macro's crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() are the + * co-routine equivalent to the xQueueSendFromISR() and xQueueReceiveFromISR() + * functions used by tasks. * * crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() can only be used to - * pass data between a co-routine and and ISR, whereas xQueueSendFromISR() and + * pass data between a co-routine and and ISR, whereas xQueueSendFromISR() and * xQueueReceiveFromISR() can only be used to pass data between a task and and * ISR. * - * crQUEUE_RECEIVE_FROM_ISR can only be called from an ISR to receive data + * crQUEUE_RECEIVE_FROM_ISR can only be called from an ISR to receive data * from a queue that is being used from within a co-routine (a co-routine * posted to the queue). * - * See the co-routine section of the WEB documentation for information on - * passing data between tasks and co-routines and between ISR's and + * See the co-routine section of the WEB documentation for information on + * passing data between tasks and co-routines and between ISR's and * co-routines. * * @param xQueue The handle to the queue on which the item is to be posted. - * + * * @param pvBuffer A pointer to a buffer into which the received item will be * placed. The size of the items the queue will hold was defined when the * queue was created, so this many bytes will be copied from the queue into * pvBuffer. * * @param pxCoRoutineWoken A co-routine may be blocked waiting for space to become - * available on the queue. If crQUEUE_RECEIVE_FROM_ISR causes such a - * co-routine to unblock *pxCoRoutineWoken will get set to pdTRUE, otherwise + * available on the queue. If crQUEUE_RECEIVE_FROM_ISR causes such a + * co-routine to unblock *pxCoRoutineWoken will get set to pdTRUE, otherwise * *pxCoRoutineWoken will remain unchanged. * * @return pdTRUE an item was successfully received from the queue, otherwise @@ -620,7 +620,7 @@ void vCoRoutineSchedule( void ); * * Example usage:
- // A co-routine that posts a character to a queue then blocks for a fixed 
+ // A co-routine that posts a character to a queue then blocks for a fixed
  // period.  The character is incremented each time.
  static void vSendingCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
  {
@@ -636,7 +636,7 @@ void vCoRoutineSchedule( void );
      {
          // Send the next character to the queue.
          crQUEUE_SEND( xHandle, xCoRoutineQueue, &cCharToTx, NO_DELAY, &xResult );
-    
+
          if( xResult == pdPASS )
          {
              // The character was successfully posted to the queue.
@@ -651,7 +651,7 @@ void vCoRoutineSchedule( void );
 		 // from the queue and send it.
 		 ENABLE_RX_INTERRUPT();
 
-		 // Increment to the next character then block for a fixed period. 
+		 // Increment to the next character then block for a fixed period.
 		 // cCharToTx will maintain its value across the delay as it is
 		 // declared static.
 		 cCharToTx++;
@@ -691,11 +691,11 @@ void vCoRoutineSchedule( void );
 
 /*
  * This function is intended for internal use by the co-routine macros only.
- * The macro nature of the co-routine implementation requires that the 
- * prototype appears here.  The function should not be used by application 
+ * The macro nature of the co-routine implementation requires that the
+ * prototype appears here.  The function should not be used by application
  * writers.
  *
- * Removes the current co-routine from its ready list and places it in the 
+ * Removes the current co-routine from its ready list and places it in the
  * appropriate delayed list.
  */
 void vCoRoutineAddToDelayedList( portTickType xTicksToDelay, xList *pxEventList );
@@ -707,7 +707,7 @@ void vCoRoutineAddToDelayedList( portTickType xTicksToDelay, xList *pxEventList
  * Removes the highest priority co-routine from the event list and places it in
  * the pending ready list.
  */
-portBASE_TYPE xCoRoutineRemoveFromEventList( const xList *pxEventList );
+signed portBASE_TYPE xCoRoutineRemoveFromEventList( const xList *pxEventList );
 
 
 #endif /* CO_ROUTINE_H */
diff --git a/Source/portable/IAR/ATMega323/port.c b/Source/portable/IAR/ATMega323/port.c
index 4189923ad..c07cc551c 100644
--- a/Source/portable/IAR/ATMega323/port.c
+++ b/Source/portable/IAR/ATMega323/port.c
@@ -52,6 +52,12 @@
 #define portBYTES_USED_BY_RETURN_ADDRESS		( 2 )
 /*-----------------------------------------------------------*/
 
+/* Stores the critical section nesting.  This must not be initialised to 0.
+It will be initialised when a task starts. */
+#define portNO_CRITICAL_NESTING					( ( unsigned portBASE_TYPE ) 0 )
+unsigned portBASE_TYPE uxCriticalNesting = 0x50;
+
+
 /*
  * Perform hardware setup to enable ticks from timer 1, compare match A.
  */
@@ -221,6 +227,9 @@ portSTACK_TYPE *pxTopOfHardwareStack;
 	pxTopOfStack--;
 	*pxTopOfStack = ( portSTACK_TYPE ) 0x031;	/* R31 */
 
+	pxTopOfStack--;
+	*pxTopOfStack = portNO_CRITICAL_NESTING;	/* Critical nesting is zero when the task starts. */
+
 	/*lint +e950 +e611 +e923 */
 
 	return pxTopOfStack;
@@ -315,6 +324,22 @@ unsigned portCHAR ucHighByte, ucLowByte;
 		vTaskIncrementTick();
 	}
 #endif
+/*-----------------------------------------------------------*/
 
+void vPortEnterCritical( void )
+{
+	portDISABLE_INTERRUPTS();
+	uxCriticalNesting++;
+}
+/*-----------------------------------------------------------*/
+
+void vPortExitCritical( void )
+{
+	uxCriticalNesting--;
+	if( uxCriticalNesting == portNO_CRITICAL_NESTING )
+	{
+		portENABLE_INTERRUPTS();
+	}
+}
 
 	
diff --git a/Source/portable/IAR/ATMega323/portmacro.h b/Source/portable/IAR/ATMega323/portmacro.h
index 69032ab2e..a093709ce 100644
--- a/Source/portable/IAR/ATMega323/portmacro.h
+++ b/Source/portable/IAR/ATMega323/portmacro.h
@@ -70,15 +70,13 @@ Changes from V1.2.3
 /*-----------------------------------------------------------*/	
 
 /* Critical section management. */
-#define portENTER_CRITICAL()	asm( "in r15, 3fh" );		\
-								asm( "cli" );				\
-								asm( "st -y, r15" )
+extern void vPortEnterCritical( void );
+extern void vPortExitCritical( void );
+#define portENTER_CRITICAL()	vPortEnterCritical()
+#define portEXIT_CRITICAL()		vPortExitCritical()
 
-#define portEXIT_CRITICAL()		asm( "ld r15, y+" );		\
-								asm( "out 3fh, r15" )
-
-#define portDISABLE_INTERRUPTS()	asm( "cli" );
-#define portENABLE_INTERRUPTS()		asm( "sti" );
+#define portDISABLE_INTERRUPTS()	asm( "cli" )
+#define portENABLE_INTERRUPTS()		asm( "sei" )
 /*-----------------------------------------------------------*/
 
 /* Architecture specifics. */
diff --git a/Source/portable/oWatcom/16BitDOS/PC/port.c b/Source/portable/oWatcom/16BitDOS/PC/port.c
index 29e41cbaf..0cba00dff 100644
--- a/Source/portable/oWatcom/16BitDOS/PC/port.c
+++ b/Source/portable/oWatcom/16BitDOS/PC/port.c
@@ -288,7 +288,7 @@ unsigned portLONG ulOutput;
 	/* Setup the 8245 to tick at the wanted frequency. */
 	portOUTPUT_BYTE( usPIT_MODE, us8254_CTR0_MODE3 );
 	ulOutput = ulPIT_CONST / ulTickRateHz;
-    
+   
 	portOUTPUT_BYTE( usPIT0, ( unsigned portSHORT )( ulOutput & ( unsigned portLONG ) 0xff ) );
 	ulOutput >>= 8;
 	portOUTPUT_BYTE( usPIT0, ( unsigned portSHORT ) ( ulOutput & ( unsigned portLONG ) 0xff ) );
-- 
2.39.5