2 FreeRTOS V7.6.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
28 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
29 >>! the source code for proprietary components outside of the FreeRTOS
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
67 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
68 * documentation provides more details of the demo application tasks.
\r
70 * Main. c also creates a task called "Check". This only executes every three
\r
71 * seconds but has the highest priority so is guaranteed to get processor time.
\r
72 * Its main function is to check that all the other tasks are still operational.
\r
73 * Each task that does not flash an LED maintains a unique count that is
\r
74 * incremented each time the task successfully completes its function. Should
\r
75 * any error occur within such a task the count is permanently halted. The
\r
76 * check task inspects the count of each task to ensure it has changed since
\r
77 * the last time the check task executed. If all the count variables have
\r
78 * changed all the tasks are still executing error free, and the check task
\r
79 * toggles an LED. Should any task contain an error at any time the LED toggle
\r
82 * The LED flash and communications test tasks do not maintain a count.
\r
88 + Changed the baud rate for the serial test from 19200 to 57600.
\r
92 + The integer and comtest tasks are now used when the cooperative scheduler
\r
93 is being used. Previously they were only used with the preemptive
\r
98 + Set the baud rate to 38400. This has a smaller error percentage with an
\r
99 8MHz clock (according to the manual).
\r
101 Changes from V2.0.0
\r
103 + Delay periods are now specified using variables and constants of
\r
104 portTickType rather than unsigned long.
\r
106 Changes from V2.2.0
\r
108 + File can now be built using either the IAR or WinAVR compiler.
\r
110 Changes from V2.6.1
\r
112 + The IAR and WinAVR AVR ports are now maintained separately.
\r
114 Changes from V4.0.5
\r
116 + Modified to demonstrate the use of co-routines.
\r
119 #include <stdlib.h>
\r
120 #include <string.h>
\r
122 #ifdef GCC_MEGA_AVR
\r
123 /* EEPROM routines used only with the WinAVR compiler. */
\r
124 #include <avr/eeprom.h>
\r
127 /* Scheduler include files. */
\r
128 #include "FreeRTOS.h"
\r
130 #include "croutine.h"
\r
132 /* Demo file headers. */
\r
134 #include "integer.h"
\r
135 #include "serial.h"
\r
136 #include "comtest.h"
\r
137 #include "crflash.h"
\r
139 #include "partest.h"
\r
140 #include "regtest.h"
\r
142 /* Priority definitions for most of the tasks in the demo application. Some
\r
143 tasks just use the idle priority. */
\r
144 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
145 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
146 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
147 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
149 /* Baud rate used by the serial port tasks. */
\r
150 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 38400 )
\r
152 /* LED used by the serial port tasks. This is toggled on each character Tx,
\r
153 and mainCOM_TEST_LED + 1 is toggles on each character Rx. */
\r
154 #define mainCOM_TEST_LED ( 4 )
\r
156 /* LED that is toggled by the check task. The check task periodically checks
\r
157 that all the other tasks are operating without error. If no errors are found
\r
158 the LED is toggled. If an error is found at any time the LED is never toggles
\r
160 #define mainCHECK_TASK_LED ( 7 )
\r
162 /* The period between executions of the check task. */
\r
163 #define mainCHECK_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
165 /* An address in the EEPROM used to count resets. This is used to check that
\r
166 the demo application is not unexpectedly resetting. */
\r
167 #define mainRESET_COUNT_ADDRESS ( ( void * ) 0x50 )
\r
169 /* The number of coroutines to create. */
\r
170 #define mainNUM_FLASH_COROUTINES ( 3 )
\r
173 * The task function for the "Check" task.
\r
175 static void vErrorChecks( void *pvParameters );
\r
178 * Checks the unique counts of other tasks to ensure they are still operational.
\r
179 * Flashes an LED if everything is okay.
\r
181 static void prvCheckOtherTasksAreStillRunning( void );
\r
184 * Called on boot to increment a count stored in the EEPROM. This is used to
\r
185 * ensure the CPU does not reset unexpectedly.
\r
187 static void prvIncrementResetCount( void );
\r
190 * Idle hook is used to scheduler co-routines.
\r
192 void vApplicationIdleHook( void );
\r
196 prvIncrementResetCount();
\r
198 /* Setup the LED's for output. */
\r
199 vParTestInitialise();
\r
201 /* Create the standard demo tasks. */
\r
202 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
203 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
204 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
205 vStartRegTestTasks();
\r
207 /* Create the tasks defined within this file. */
\r
208 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
210 /* Create the co-routines that flash the LED's. */
\r
211 vStartFlashCoRoutines( mainNUM_FLASH_COROUTINES );
\r
213 /* In this port, to use preemptive scheduler define configUSE_PREEMPTION
\r
214 as 1 in portmacro.h. To use the cooperative scheduler define
\r
215 configUSE_PREEMPTION as 0. */
\r
216 vTaskStartScheduler();
\r
220 /*-----------------------------------------------------------*/
\r
222 static void vErrorChecks( void *pvParameters )
\r
224 static volatile unsigned long ulDummyVariable = 3UL;
\r
226 /* The parameters are not used. */
\r
227 ( void ) pvParameters;
\r
229 /* Cycle for ever, delaying then checking all the other tasks are still
\r
230 operating without error. */
\r
233 vTaskDelay( mainCHECK_PERIOD );
\r
235 /* Perform a bit of 32bit maths to ensure the registers used by the
\r
236 integer tasks get some exercise. The result here is not important -
\r
237 see the demo application documentation for more info. */
\r
238 ulDummyVariable *= 3;
\r
240 prvCheckOtherTasksAreStillRunning();
\r
243 /*-----------------------------------------------------------*/
\r
245 static void prvCheckOtherTasksAreStillRunning( void )
\r
247 static portBASE_TYPE xErrorHasOccurred = pdFALSE;
\r
249 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
251 xErrorHasOccurred = pdTRUE;
\r
254 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
256 xErrorHasOccurred = pdTRUE;
\r
259 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
261 xErrorHasOccurred = pdTRUE;
\r
264 if( xAreRegTestTasksStillRunning() != pdTRUE )
\r
266 xErrorHasOccurred = pdTRUE;
\r
269 if( xErrorHasOccurred == pdFALSE )
\r
271 /* Toggle the LED if everything is okay so we know if an error occurs even if not
\r
272 using console IO. */
\r
273 vParTestToggleLED( mainCHECK_TASK_LED );
\r
276 /*-----------------------------------------------------------*/
\r
278 static void prvIncrementResetCount( void )
\r
280 unsigned char ucCount;
\r
281 const unsigned char ucReadBit = ( unsigned char ) 0x01;
\r
282 const unsigned char ucWrite1 = ( unsigned char ) 0x04;
\r
283 const unsigned char ucWrite2 = ( unsigned char ) 0x02;
\r
285 /* Increment the EEPROM value at 0x00.
\r
287 Setup the EEPROM address. */
\r
291 /* Set the read enable bit. */
\r
294 /* Wait for the read. */
\r
295 while( EECR & ucReadBit );
\r
297 /* The byte is ready. */
\r
300 /* Increment the reset count, then write the byte back. */
\r
304 EECR = ( ucWrite1 | ucWrite2 );
\r
306 /*-----------------------------------------------------------*/
\r
308 void vApplicationIdleHook( void )
\r
310 vCoRoutineSchedule();
\r