2 FreeRTOS V7.0.0 - Copyright (C) 2011 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
55 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
56 * documentation provides more details of the demo application tasks.
\r
58 * Main. c also creates a task called "Check". This only executes every three
\r
59 * seconds but has the highest priority so is guaranteed to get processor time.
\r
60 * Its main function is to check that all the other tasks are still operational.
\r
61 * Each task that does not flash an LED maintains a unique count that is
\r
62 * incremented each time the task successfully completes its function. Should
\r
63 * any error occur within such a task the count is permanently halted. The
\r
64 * check task inspects the count of each task to ensure it has changed since
\r
65 * the last time the check task executed. If all the count variables have
\r
66 * changed all the tasks are still executing error free, and the check task
\r
67 * toggles an LED. Should any task contain an error at any time the LED toggle
\r
70 * The LED flash and communications test tasks do not maintain a count.
\r
76 + Changed the baud rate for the serial test from 19200 to 57600.
\r
80 + The integer and comtest tasks are now used when the cooperative scheduler
\r
81 is being used. Previously they were only used with the preemptive
\r
86 + Set the baud rate to 38400. This has a smaller error percentage with an
\r
87 8MHz clock (according to the manual).
\r
91 + Delay periods are now specified using variables and constants of
\r
92 portTickType rather than unsigned long.
\r
96 + The IAR and WinAVR AVR ports are now maintained separately.
\r
100 + Modified to demonstrate the use of co-routines.
\r
104 #include <stdlib.h>
\r
105 #include <string.h>
\r
107 #ifdef GCC_MEGA_AVR
\r
108 /* EEPROM routines used only with the WinAVR compiler. */
\r
109 #include <avr/eeprom.h>
\r
112 /* Scheduler include files. */
\r
113 #include "FreeRTOS.h"
\r
115 #include "croutine.h"
\r
117 /* Demo file headers. */
\r
119 #include "integer.h"
\r
120 #include "serial.h"
\r
121 #include "comtest.h"
\r
122 #include "crflash.h"
\r
124 #include "partest.h"
\r
125 #include "regtest.h"
\r
127 /* Priority definitions for most of the tasks in the demo application. Some
\r
128 tasks just use the idle priority. */
\r
129 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
130 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
131 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
132 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
134 /* Baud rate used by the serial port tasks. */
\r
135 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 38400 )
\r
137 /* LED used by the serial port tasks. This is toggled on each character Tx,
\r
138 and mainCOM_TEST_LED + 1 is toggles on each character Rx. */
\r
139 #define mainCOM_TEST_LED ( 4 )
\r
141 /* LED that is toggled by the check task. The check task periodically checks
\r
142 that all the other tasks are operating without error. If no errors are found
\r
143 the LED is toggled. If an error is found at any time the LED is never toggles
\r
145 #define mainCHECK_TASK_LED ( 7 )
\r
147 /* The period between executions of the check task. */
\r
148 #define mainCHECK_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
150 /* An address in the EEPROM used to count resets. This is used to check that
\r
151 the demo application is not unexpectedly resetting. */
\r
152 #define mainRESET_COUNT_ADDRESS ( ( void * ) 0x50 )
\r
154 /* The number of coroutines to create. */
\r
155 #define mainNUM_FLASH_COROUTINES ( 3 )
\r
158 * The task function for the "Check" task.
\r
160 static void vErrorChecks( void *pvParameters );
\r
163 * Checks the unique counts of other tasks to ensure they are still operational.
\r
164 * Flashes an LED if everything is okay.
\r
166 static void prvCheckOtherTasksAreStillRunning( void );
\r
169 * Called on boot to increment a count stored in the EEPROM. This is used to
\r
170 * ensure the CPU does not reset unexpectedly.
\r
172 static void prvIncrementResetCount( void );
\r
175 * The idle hook is used to scheduler co-routines.
\r
177 void vApplicationIdleHook( void );
\r
179 /*-----------------------------------------------------------*/
\r
183 prvIncrementResetCount();
\r
185 /* Setup the LED's for output. */
\r
186 vParTestInitialise();
\r
188 /* Create the standard demo tasks. */
\r
189 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
190 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
191 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
192 vStartRegTestTasks();
\r
194 /* Create the tasks defined within this file. */
\r
195 xTaskCreate( vErrorChecks, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
197 /* Create the co-routines that flash the LED's. */
\r
198 vStartFlashCoRoutines( mainNUM_FLASH_COROUTINES );
\r
200 /* In this port, to use preemptive scheduler define configUSE_PREEMPTION
\r
201 as 1 in portmacro.h. To use the cooperative scheduler define
\r
202 configUSE_PREEMPTION as 0. */
\r
203 vTaskStartScheduler();
\r
207 /*-----------------------------------------------------------*/
\r
209 static void vErrorChecks( void *pvParameters )
\r
211 static volatile unsigned long ulDummyVariable = 3UL;
\r
213 /* The parameters are not used. */
\r
214 ( void ) pvParameters;
\r
216 /* Cycle for ever, delaying then checking all the other tasks are still
\r
217 operating without error. */
\r
220 vTaskDelay( mainCHECK_PERIOD );
\r
222 /* Perform a bit of 32bit maths to ensure the registers used by the
\r
223 integer tasks get some exercise. The result here is not important -
\r
224 see the demo application documentation for more info. */
\r
225 ulDummyVariable *= 3;
\r
227 prvCheckOtherTasksAreStillRunning();
\r
230 /*-----------------------------------------------------------*/
\r
232 static void prvCheckOtherTasksAreStillRunning( void )
\r
234 static portBASE_TYPE xErrorHasOccurred = pdFALSE;
\r
236 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
238 xErrorHasOccurred = pdTRUE;
\r
241 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
243 xErrorHasOccurred = pdTRUE;
\r
246 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
248 xErrorHasOccurred = pdTRUE;
\r
251 if( xAreRegTestTasksStillRunning() != pdTRUE )
\r
253 xErrorHasOccurred = pdTRUE;
\r
256 if( xErrorHasOccurred == pdFALSE )
\r
258 /* Toggle the LED if everything is okay so we know if an error occurs even if not
\r
259 using console IO. */
\r
260 vParTestToggleLED( mainCHECK_TASK_LED );
\r
263 /*-----------------------------------------------------------*/
\r
265 static void prvIncrementResetCount( void )
\r
267 unsigned char ucCount;
\r
269 eeprom_read_block( &ucCount, mainRESET_COUNT_ADDRESS, sizeof( ucCount ) );
\r
271 eeprom_write_byte( mainRESET_COUNT_ADDRESS, ucCount );
\r
273 /*-----------------------------------------------------------*/
\r
275 void vApplicationIdleHook( void )
\r
277 vCoRoutineSchedule();
\r