2 FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd.
\r
4 This file is part of the FreeRTOS distribution.
\r
6 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
7 the terms of the GNU General Public License (version 2) as published by the
\r
8 Free Software Foundation and modified by the FreeRTOS exception.
\r
9 **NOTE** The exception to the GPL is included to allow you to distribute a
\r
10 combined work that includes FreeRTOS without being obliged to provide the
\r
11 source code for proprietary components outside of the FreeRTOS kernel.
\r
12 Alternative commercial license and support terms are also available upon
\r
13 request. See the licensing section of http://www.FreeRTOS.org for full
\r
16 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
21 You should have received a copy of the GNU General Public License along
\r
22 with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
\r
23 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
26 ***************************************************************************
\r
28 * The FreeRTOS eBook and reference manual are available to purchase for a *
\r
29 * small fee. Help yourself get started quickly while also helping the *
\r
30 * FreeRTOS project! See http://www.FreeRTOS.org/Documentation for details *
\r
32 ***************************************************************************
\r
36 Please ensure to read the configuration and relevant port sections of the
\r
37 online documentation.
\r
39 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
42 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
45 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
46 licensing and training services.
\r
50 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
51 * documentation provides more details of the demo application tasks.
\r
53 * Main. c also creates a task called "Check". This only executes every three
\r
54 * seconds but has the highest priority so is guaranteed to get processor time.
\r
55 * Its main function is to check that all the other tasks are still operational.
\r
56 * Each task that does not flash an LED maintains a unique count that is
\r
57 * incremented each time the task successfully completes its function. Should
\r
58 * any error occur within such a task the count is permanently halted. The
\r
59 * check task inspects the count of each task to ensure it has changed since
\r
60 * the last time the check task executed. If all the count variables have
\r
61 * changed all the tasks are still executing error free, and the check task
\r
62 * toggles an LED. Should any task contain an error at any time the LED toggle
\r
65 * The LED flash and communications test tasks do not maintain a count.
\r
71 + Changed the baud rate for the serial test from 19200 to 57600.
\r
75 + The integer and comtest tasks are now used when the cooperative scheduler
\r
76 is being used. Previously they were only used with the preemptive
\r
81 + Set the baud rate to 38400. This has a smaller error percentage with an
\r
82 8MHz clock (according to the manual).
\r
86 + Delay periods are now specified using variables and constants of
\r
87 portTickType rather than unsigned long.
\r
91 + File can now be built using either the IAR or WinAVR compiler.
\r
95 + The IAR and WinAVR AVR ports are now maintained separately.
\r
99 + Modified to demonstrate the use of co-routines.
\r
102 #include <stdlib.h>
\r
103 #include <string.h>
\r
105 #ifdef GCC_MEGA_AVR
\r
106 /* EEPROM routines used only with the WinAVR compiler. */
\r
107 #include <avr/eeprom.h>
\r
110 /* Scheduler include files. */
\r
111 #include "FreeRTOS.h"
\r
113 #include "croutine.h"
\r
115 /* Demo file headers. */
\r
117 #include "integer.h"
\r
118 #include "serial.h"
\r
119 #include "comtest.h"
\r
120 #include "crflash.h"
\r
122 #include "partest.h"
\r
123 #include "regtest.h"
\r
125 /* Priority definitions for most of the tasks in the demo application. Some
\r
126 tasks just use the idle priority. */
\r
127 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
128 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
129 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
130 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
132 /* Baud rate used by the serial port tasks. */
\r
133 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 38400 )
\r
135 /* LED used by the serial port tasks. This is toggled on each character Tx,
\r
136 and mainCOM_TEST_LED + 1 is toggles on each character Rx. */
\r
137 #define mainCOM_TEST_LED ( 4 )
\r
139 /* LED that is toggled by the check task. The check task periodically checks
\r
140 that all the other tasks are operating without error. If no errors are found
\r
141 the LED is toggled. If an error is found at any time the LED is never toggles
\r
143 #define mainCHECK_TASK_LED ( 7 )
\r
145 /* The period between executions of the check task. */
\r
146 #define mainCHECK_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
148 /* An address in the EEPROM used to count resets. This is used to check that
\r
149 the demo application is not unexpectedly resetting. */
\r
150 #define mainRESET_COUNT_ADDRESS ( ( void * ) 0x50 )
\r
152 /* The number of coroutines to create. */
\r
153 #define mainNUM_FLASH_COROUTINES ( 3 )
\r
156 * The task function for the "Check" task.
\r
158 static void vErrorChecks( void *pvParameters );
\r
161 * Checks the unique counts of other tasks to ensure they are still operational.
\r
162 * Flashes an LED if everything is okay.
\r
164 static void prvCheckOtherTasksAreStillRunning( void );
\r
167 * Called on boot to increment a count stored in the EEPROM. This is used to
\r
168 * ensure the CPU does not reset unexpectedly.
\r
170 static void prvIncrementResetCount( void );
\r
173 * Idle hook is used to scheduler co-routines.
\r
175 void vApplicationIdleHook( void );
\r
179 prvIncrementResetCount();
\r
181 /* Setup the LED's for output. */
\r
182 vParTestInitialise();
\r
184 /* Create the standard demo tasks. */
\r
185 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
186 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
187 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
188 vStartRegTestTasks();
\r
190 /* Create the tasks defined within this file. */
\r
191 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
193 /* Create the co-routines that flash the LED's. */
\r
194 vStartFlashCoRoutines( mainNUM_FLASH_COROUTINES );
\r
196 /* In this port, to use preemptive scheduler define configUSE_PREEMPTION
\r
197 as 1 in portmacro.h. To use the cooperative scheduler define
\r
198 configUSE_PREEMPTION as 0. */
\r
199 vTaskStartScheduler();
\r
203 /*-----------------------------------------------------------*/
\r
205 static void vErrorChecks( void *pvParameters )
\r
207 static volatile unsigned long ulDummyVariable = 3UL;
\r
209 /* The parameters are not used. */
\r
210 ( void ) pvParameters;
\r
212 /* Cycle for ever, delaying then checking all the other tasks are still
\r
213 operating without error. */
\r
216 vTaskDelay( mainCHECK_PERIOD );
\r
218 /* Perform a bit of 32bit maths to ensure the registers used by the
\r
219 integer tasks get some exercise. The result here is not important -
\r
220 see the demo application documentation for more info. */
\r
221 ulDummyVariable *= 3;
\r
223 prvCheckOtherTasksAreStillRunning();
\r
226 /*-----------------------------------------------------------*/
\r
228 static void prvCheckOtherTasksAreStillRunning( void )
\r
230 static portBASE_TYPE xErrorHasOccurred = pdFALSE;
\r
232 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
234 xErrorHasOccurred = pdTRUE;
\r
237 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
239 xErrorHasOccurred = pdTRUE;
\r
242 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
244 xErrorHasOccurred = pdTRUE;
\r
247 if( xAreRegTestTasksStillRunning() != pdTRUE )
\r
249 xErrorHasOccurred = pdTRUE;
\r
252 if( xErrorHasOccurred == pdFALSE )
\r
254 /* Toggle the LED if everything is okay so we know if an error occurs even if not
\r
255 using console IO. */
\r
256 vParTestToggleLED( mainCHECK_TASK_LED );
\r
259 /*-----------------------------------------------------------*/
\r
261 static void prvIncrementResetCount( void )
\r
263 unsigned char ucCount;
\r
264 const unsigned char ucReadBit = ( unsigned char ) 0x01;
\r
265 const unsigned char ucWrite1 = ( unsigned char ) 0x04;
\r
266 const unsigned char ucWrite2 = ( unsigned char ) 0x02;
\r
268 /* Increment the EEPROM value at 0x00.
\r
270 Setup the EEPROM address. */
\r
274 /* Set the read enable bit. */
\r
277 /* Wait for the read. */
\r
278 while( EECR & ucReadBit );
\r
280 /* The byte is ready. */
\r
283 /* Increment the reset count, then write the byte back. */
\r
287 EECR = ( ucWrite1 | ucWrite2 );
\r
289 /*-----------------------------------------------------------*/
\r
291 void vApplicationIdleHook( void )
\r
293 vCoRoutineSchedule();
\r