2 FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
5 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
10 * Complete, revised, and edited pdf reference manuals are also *
\r
13 * Purchasing FreeRTOS documentation will not only help you, by *
\r
14 * ensuring you get running as quickly as possible and with an *
\r
15 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
16 * the FreeRTOS project to continue with its mission of providing *
\r
17 * professional grade, cross platform, de facto standard solutions *
\r
18 * for microcontrollers - completely free of charge! *
\r
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
22 * Thank you for using FreeRTOS, and thank you for your support! *
\r
24 ***************************************************************************
\r
27 This file is part of the FreeRTOS distribution.
\r
29 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
30 the terms of the GNU General Public License (version 2) as published by the
\r
31 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
33 >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
\r
34 distribute a combined work that includes FreeRTOS without being obliged to
\r
35 provide the source code for proprietary components outside of the FreeRTOS
\r
38 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
39 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
40 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
\r
41 details. You should have received a copy of the GNU General Public License
\r
42 and the FreeRTOS license exception along with FreeRTOS; if not itcan be
\r
43 viewed here: http://www.freertos.org/a00114.html and also obtained by
\r
44 writing to Real Time Engineers Ltd., contact details for whom are available
\r
45 on the FreeRTOS WEB site.
\r
49 ***************************************************************************
\r
51 * Having a problem? Start by reading the FAQ "My application does *
\r
52 * not run, what could be wrong?" *
\r
54 * http://www.FreeRTOS.org/FAQHelp.html *
\r
56 ***************************************************************************
\r
59 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
60 license and Real Time Engineers Ltd. contact details.
\r
62 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
63 including FreeRTOS+Trace - an indispensable productivity tool, and our new
\r
64 fully thread aware and reentrant UDP/IP stack.
\r
66 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
67 Integrity Systems, who sell the code with commercial support,
\r
68 indemnification and middleware, under the OpenRTOS brand.
\r
70 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
71 engineered and independently SIL3 certified version for use in safety and
\r
72 mission critical applications that require provable dependability.
\r
76 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
77 * documentation provides more details of the demo application tasks.
\r
79 * Main. c also creates a task called "Check". This only executes every three
\r
80 * seconds but has the highest priority so is guaranteed to get processor time.
\r
81 * Its main function is to check that all the other tasks are still operational.
\r
82 * Each task that does not flash an LED maintains a unique count that is
\r
83 * incremented each time the task successfully completes its function. Should
\r
84 * any error occur within such a task the count is permanently halted. The
\r
85 * check task inspects the count of each task to ensure it has changed since
\r
86 * the last time the check task executed. If all the count variables have
\r
87 * changed all the tasks are still executing error free, and the check task
\r
88 * toggles an LED. Should any task contain an error at any time the LED toggle
\r
91 * The LED flash and communications test tasks do not maintain a count.
\r
97 + Changed the baud rate for the serial test from 19200 to 57600.
\r
101 + The integer and comtest tasks are now used when the cooperative scheduler
\r
102 is being used. Previously they were only used with the preemptive
\r
105 Changes from V1.2.5
\r
107 + Set the baud rate to 38400. This has a smaller error percentage with an
\r
108 8MHz clock (according to the manual).
\r
110 Changes from V2.0.0
\r
112 + Delay periods are now specified using variables and constants of
\r
113 portTickType rather than unsigned long.
\r
115 Changes from V2.6.1
\r
117 + The IAR and WinAVR AVR ports are now maintained separately.
\r
119 Changes from V4.0.5
\r
121 + Modified to demonstrate the use of co-routines.
\r
125 #include <stdlib.h>
\r
126 #include <string.h>
\r
128 #ifdef GCC_MEGA_AVR
\r
129 /* EEPROM routines used only with the WinAVR compiler. */
\r
130 #include <avr/eeprom.h>
\r
133 /* Scheduler include files. */
\r
134 #include "FreeRTOS.h"
\r
136 #include "croutine.h"
\r
138 /* Demo file headers. */
\r
140 #include "integer.h"
\r
141 #include "serial.h"
\r
142 #include "comtest.h"
\r
143 #include "crflash.h"
\r
145 #include "partest.h"
\r
146 #include "regtest.h"
\r
148 /* Priority definitions for most of the tasks in the demo application. Some
\r
149 tasks just use the idle priority. */
\r
150 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
151 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
152 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
153 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
155 /* Baud rate used by the serial port tasks. */
\r
156 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 38400 )
\r
158 /* LED used by the serial port tasks. This is toggled on each character Tx,
\r
159 and mainCOM_TEST_LED + 1 is toggles on each character Rx. */
\r
160 #define mainCOM_TEST_LED ( 4 )
\r
162 /* LED that is toggled by the check task. The check task periodically checks
\r
163 that all the other tasks are operating without error. If no errors are found
\r
164 the LED is toggled. If an error is found at any time the LED is never toggles
\r
166 #define mainCHECK_TASK_LED ( 7 )
\r
168 /* The period between executions of the check task. */
\r
169 #define mainCHECK_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
171 /* An address in the EEPROM used to count resets. This is used to check that
\r
172 the demo application is not unexpectedly resetting. */
\r
173 #define mainRESET_COUNT_ADDRESS ( ( void * ) 0x50 )
\r
175 /* The number of coroutines to create. */
\r
176 #define mainNUM_FLASH_COROUTINES ( 3 )
\r
179 * The task function for the "Check" task.
\r
181 static void vErrorChecks( void *pvParameters );
\r
184 * Checks the unique counts of other tasks to ensure they are still operational.
\r
185 * Flashes an LED if everything is okay.
\r
187 static void prvCheckOtherTasksAreStillRunning( void );
\r
190 * Called on boot to increment a count stored in the EEPROM. This is used to
\r
191 * ensure the CPU does not reset unexpectedly.
\r
193 static void prvIncrementResetCount( void );
\r
196 * The idle hook is used to scheduler co-routines.
\r
198 void vApplicationIdleHook( void );
\r
200 /*-----------------------------------------------------------*/
\r
204 prvIncrementResetCount();
\r
206 /* Setup the LED's for output. */
\r
207 vParTestInitialise();
\r
209 /* Create the standard demo tasks. */
\r
210 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
211 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
212 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
213 vStartRegTestTasks();
\r
215 /* Create the tasks defined within this file. */
\r
216 xTaskCreate( vErrorChecks, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
218 /* Create the co-routines that flash the LED's. */
\r
219 vStartFlashCoRoutines( mainNUM_FLASH_COROUTINES );
\r
221 /* In this port, to use preemptive scheduler define configUSE_PREEMPTION
\r
222 as 1 in portmacro.h. To use the cooperative scheduler define
\r
223 configUSE_PREEMPTION as 0. */
\r
224 vTaskStartScheduler();
\r
228 /*-----------------------------------------------------------*/
\r
230 static void vErrorChecks( void *pvParameters )
\r
232 static volatile unsigned long ulDummyVariable = 3UL;
\r
234 /* The parameters are not used. */
\r
235 ( void ) pvParameters;
\r
237 /* Cycle for ever, delaying then checking all the other tasks are still
\r
238 operating without error. */
\r
241 vTaskDelay( mainCHECK_PERIOD );
\r
243 /* Perform a bit of 32bit maths to ensure the registers used by the
\r
244 integer tasks get some exercise. The result here is not important -
\r
245 see the demo application documentation for more info. */
\r
246 ulDummyVariable *= 3;
\r
248 prvCheckOtherTasksAreStillRunning();
\r
251 /*-----------------------------------------------------------*/
\r
253 static void prvCheckOtherTasksAreStillRunning( void )
\r
255 static portBASE_TYPE xErrorHasOccurred = pdFALSE;
\r
257 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
259 xErrorHasOccurred = pdTRUE;
\r
262 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
264 xErrorHasOccurred = pdTRUE;
\r
267 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
269 xErrorHasOccurred = pdTRUE;
\r
272 if( xAreRegTestTasksStillRunning() != pdTRUE )
\r
274 xErrorHasOccurred = pdTRUE;
\r
277 if( xErrorHasOccurred == pdFALSE )
\r
279 /* Toggle the LED if everything is okay so we know if an error occurs even if not
\r
280 using console IO. */
\r
281 vParTestToggleLED( mainCHECK_TASK_LED );
\r
284 /*-----------------------------------------------------------*/
\r
286 static void prvIncrementResetCount( void )
\r
288 unsigned char ucCount;
\r
290 eeprom_read_block( &ucCount, mainRESET_COUNT_ADDRESS, sizeof( ucCount ) );
\r
292 eeprom_write_byte( mainRESET_COUNT_ADDRESS, ucCount );
\r
294 /*-----------------------------------------------------------*/
\r
296 void vApplicationIdleHook( void )
\r
298 vCoRoutineSchedule();
\r