2 FreeRTOS.org V4.7.2 - Copyright (C) 2003-2008 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
28 Please ensure to read the configuration and relevant port sections of the
\r
29 online documentation.
\r
31 +++ http://www.FreeRTOS.org +++
\r
32 Documentation, latest information, license and contact details.
\r
34 +++ http://www.SafeRTOS.com +++
\r
35 A version that is certified for use in safety critical systems.
\r
37 +++ http://www.OpenRTOS.com +++
\r
38 Commercial support, development, porting, licensing and training services.
\r
40 ***************************************************************************
\r
44 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
45 * documentation provides more details of the demo application tasks.
\r
47 * Main. c also creates a task called "Check". This only executes every three
\r
48 * seconds but has the highest priority so is guaranteed to get processor time.
\r
49 * Its main function is to check that all the other tasks are still operational.
\r
50 * Each task that does not flash an LED maintains a unique count that is
\r
51 * incremented each time the task successfully completes its function. Should
\r
52 * any error occur within such a task the count is permanently halted. The
\r
53 * check task inspects the count of each task to ensure it has changed since
\r
54 * the last time the check task executed. If all the count variables have
\r
55 * changed all the tasks are still executing error free, and the check task
\r
56 * toggles an LED. Should any task contain an error at any time the LED toggle
\r
59 * The LED flash and communications test tasks do not maintain a count.
\r
65 + Changed the baud rate for the serial test from 19200 to 57600.
\r
69 + The integer and comtest tasks are now used when the cooperative scheduler
\r
70 is being used. Previously they were only used with the preemptive
\r
75 + Set the baud rate to 38400. This has a smaller error percentage with an
\r
76 8MHz clock (according to the manual).
\r
80 + Delay periods are now specified using variables and constants of
\r
81 portTickType rather than unsigned portLONG.
\r
85 + The IAR and WinAVR AVR ports are now maintained separately.
\r
89 + Modified to demonstrate the use of co-routines.
\r
97 /* EEPROM routines used only with the WinAVR compiler. */
\r
98 #include <avr/eeprom.h>
\r
101 /* Scheduler include files. */
\r
102 #include "FreeRTOS.h"
\r
104 #include "croutine.h"
\r
106 /* Demo file headers. */
\r
108 #include "integer.h"
\r
109 #include "serial.h"
\r
110 #include "comtest.h"
\r
111 #include "crflash.h"
\r
113 #include "partest.h"
\r
114 #include "regtest.h"
\r
116 /* Priority definitions for most of the tasks in the demo application. Some
\r
117 tasks just use the idle priority. */
\r
118 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
119 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
120 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
121 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
123 /* Baud rate used by the serial port tasks. */
\r
124 #define mainCOM_TEST_BAUD_RATE ( ( unsigned portLONG ) 38400 )
\r
126 /* LED used by the serial port tasks. This is toggled on each character Tx,
\r
127 and mainCOM_TEST_LED + 1 is toggles on each character Rx. */
\r
128 #define mainCOM_TEST_LED ( 4 )
\r
130 /* LED that is toggled by the check task. The check task periodically checks
\r
131 that all the other tasks are operating without error. If no errors are found
\r
132 the LED is toggled. If an error is found at any time the LED is never toggles
\r
134 #define mainCHECK_TASK_LED ( 7 )
\r
136 /* The period between executions of the check task. */
\r
137 #define mainCHECK_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
139 /* An address in the EEPROM used to count resets. This is used to check that
\r
140 the demo application is not unexpectedly resetting. */
\r
141 #define mainRESET_COUNT_ADDRESS ( ( void * ) 0x50 )
\r
143 /* The number of coroutines to create. */
\r
144 #define mainNUM_FLASH_COROUTINES ( 3 )
\r
147 * The task function for the "Check" task.
\r
149 static void vErrorChecks( void *pvParameters );
\r
152 * Checks the unique counts of other tasks to ensure they are still operational.
\r
153 * Flashes an LED if everything is okay.
\r
155 static void prvCheckOtherTasksAreStillRunning( void );
\r
158 * Called on boot to increment a count stored in the EEPROM. This is used to
\r
159 * ensure the CPU does not reset unexpectedly.
\r
161 static void prvIncrementResetCount( void );
\r
164 * The idle hook is used to scheduler co-routines.
\r
166 void vApplicationIdleHook( void );
\r
168 /*-----------------------------------------------------------*/
\r
170 portSHORT main( void )
\r
172 prvIncrementResetCount();
\r
174 /* Setup the LED's for output. */
\r
175 vParTestInitialise();
\r
177 /* Create the standard demo tasks. */
\r
178 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
179 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
180 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
181 vStartRegTestTasks();
\r
183 /* Create the tasks defined within this file. */
\r
184 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
186 /* Create the co-routines that flash the LED's. */
\r
187 vStartFlashCoRoutines( mainNUM_FLASH_COROUTINES );
\r
189 /* In this port, to use preemptive scheduler define configUSE_PREEMPTION
\r
190 as 1 in portmacro.h. To use the cooperative scheduler define
\r
191 configUSE_PREEMPTION as 0. */
\r
192 vTaskStartScheduler();
\r
196 /*-----------------------------------------------------------*/
\r
198 static void vErrorChecks( void *pvParameters )
\r
200 static volatile unsigned portLONG ulDummyVariable = 3UL;
\r
202 /* The parameters are not used. */
\r
203 ( void ) pvParameters;
\r
205 /* Cycle for ever, delaying then checking all the other tasks are still
\r
206 operating without error. */
\r
209 vTaskDelay( mainCHECK_PERIOD );
\r
211 /* Perform a bit of 32bit maths to ensure the registers used by the
\r
212 integer tasks get some exercise. The result here is not important -
\r
213 see the demo application documentation for more info. */
\r
214 ulDummyVariable *= 3;
\r
216 prvCheckOtherTasksAreStillRunning();
\r
219 /*-----------------------------------------------------------*/
\r
221 static void prvCheckOtherTasksAreStillRunning( void )
\r
223 static portBASE_TYPE xErrorHasOccurred = pdFALSE;
\r
225 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
227 xErrorHasOccurred = pdTRUE;
\r
230 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
232 xErrorHasOccurred = pdTRUE;
\r
235 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
237 xErrorHasOccurred = pdTRUE;
\r
240 if( xAreRegTestTasksStillRunning() != pdTRUE )
\r
242 xErrorHasOccurred = pdTRUE;
\r
245 if( xErrorHasOccurred == pdFALSE )
\r
247 /* Toggle the LED if everything is okay so we know if an error occurs even if not
\r
248 using console IO. */
\r
249 vParTestToggleLED( mainCHECK_TASK_LED );
\r
252 /*-----------------------------------------------------------*/
\r
254 static void prvIncrementResetCount( void )
\r
256 unsigned portCHAR ucCount;
\r
258 eeprom_read_block( &ucCount, mainRESET_COUNT_ADDRESS, sizeof( ucCount ) );
\r
260 eeprom_write_byte( mainRESET_COUNT_ADDRESS, ucCount );
\r
262 /*-----------------------------------------------------------*/
\r
264 void vApplicationIdleHook( void )
\r
266 vCoRoutineSchedule();
\r