2 FreeRTOS.org V4.1.3 - Copyright (C) 2003-2006 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
27 See http://www.FreeRTOS.org for documentation, latest information, license
\r
28 and contact details. Please ensure to read the configuration and relevant
\r
29 port sections of the online documentation.
\r
30 ***************************************************************************
\r
34 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
35 * documentation provides more details of the demo application tasks.
\r
37 * Main. c also creates a task called "Check". This only executes every three
\r
38 * seconds but has the highest priority so is guaranteed to get processor time.
\r
39 * Its main function is to check that all the other tasks are still operational.
\r
40 * Each task that does not flash an LED maintains a unique count that is
\r
41 * incremented each time the task successfully completes its function. Should
\r
42 * any error occur within such a task the count is permanently halted. The
\r
43 * check task inspects the count of each task to ensure it has changed since
\r
44 * the last time the check task executed. If all the count variables have
\r
45 * changed all the tasks are still executing error free, and the check task
\r
46 * toggles an LED. Should any task contain an error at any time the LED toggle
\r
49 * The LED flash and communications test tasks do not maintain a count.
\r
55 + Changed the baud rate for the serial test from 19200 to 57600.
\r
59 + The integer and comtest tasks are now used when the cooperative scheduler
\r
60 is being used. Previously they were only used with the preemptive
\r
65 + Set the baud rate to 38400. This has a smaller error percentage with an
\r
66 8MHz clock (according to the manual).
\r
70 + Delay periods are now specified using variables and constants of
\r
71 portTickType rather than unsigned portLONG.
\r
75 + File can now be built using either the IAR or WinAVR compiler.
\r
79 + The IAR and WinAVR AVR ports are now maintained separately.
\r
83 + Modified to demonstrate the use of co-routines.
\r
90 /* EEPROM routines used only with the WinAVR compiler. */
\r
91 #include <avr/eeprom.h>
\r
94 /* Scheduler include files. */
\r
95 #include "FreeRTOS.h"
\r
97 #include "croutine.h"
\r
99 /* Demo file headers. */
\r
101 #include "integer.h"
\r
102 #include "serial.h"
\r
103 #include "comtest.h"
\r
104 #include "crflash.h"
\r
106 #include "partest.h"
\r
107 #include "regtest.h"
\r
109 /* Priority definitions for most of the tasks in the demo application. Some
\r
110 tasks just use the idle priority. */
\r
111 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
112 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
113 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
114 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
116 /* Baud rate used by the serial port tasks. */
\r
117 #define mainCOM_TEST_BAUD_RATE ( ( unsigned portLONG ) 38400 )
\r
119 /* LED used by the serial port tasks. This is toggled on each character Tx,
\r
120 and mainCOM_TEST_LED + 1 is toggles on each character Rx. */
\r
121 #define mainCOM_TEST_LED ( 4 )
\r
123 /* LED that is toggled by the check task. The check task periodically checks
\r
124 that all the other tasks are operating without error. If no errors are found
\r
125 the LED is toggled. If an error is found at any time the LED is never toggles
\r
127 #define mainCHECK_TASK_LED ( 7 )
\r
129 /* The period between executions of the check task. */
\r
130 #define mainCHECK_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
132 /* An address in the EEPROM used to count resets. This is used to check that
\r
133 the demo application is not unexpectedly resetting. */
\r
134 #define mainRESET_COUNT_ADDRESS ( ( void * ) 0x50 )
\r
136 /* The number of coroutines to create. */
\r
137 #define mainNUM_FLASH_COROUTINES ( 3 )
\r
140 * The task function for the "Check" task.
\r
142 static void vErrorChecks( void *pvParameters );
\r
145 * Checks the unique counts of other tasks to ensure they are still operational.
\r
146 * Flashes an LED if everything is okay.
\r
148 static void prvCheckOtherTasksAreStillRunning( void );
\r
151 * Called on boot to increment a count stored in the EEPROM. This is used to
\r
152 * ensure the CPU does not reset unexpectedly.
\r
154 static void prvIncrementResetCount( void );
\r
157 * Idle hook is used to scheduler co-routines.
\r
159 void vApplicationIdleHook( void );
\r
161 portSHORT main( void )
\r
163 prvIncrementResetCount();
\r
165 /* Setup the LED's for output. */
\r
166 vParTestInitialise();
\r
168 /* Create the standard demo tasks. */
\r
169 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
170 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
171 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
172 vStartRegTestTasks();
\r
174 /* Create the tasks defined within this file. */
\r
175 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
177 /* Create the co-routines that flash the LED's. */
\r
178 vStartFlashCoRoutines( mainNUM_FLASH_COROUTINES );
\r
180 /* In this port, to use preemptive scheduler define configUSE_PREEMPTION
\r
181 as 1 in portmacro.h. To use the cooperative scheduler define
\r
182 configUSE_PREEMPTION as 0. */
\r
183 vTaskStartScheduler();
\r
187 /*-----------------------------------------------------------*/
\r
189 static void vErrorChecks( void *pvParameters )
\r
191 static volatile unsigned portLONG ulDummyVariable = 3UL;
\r
193 /* The parameters are not used. */
\r
194 ( void ) pvParameters;
\r
196 /* Cycle for ever, delaying then checking all the other tasks are still
\r
197 operating without error. */
\r
200 vTaskDelay( mainCHECK_PERIOD );
\r
202 /* Perform a bit of 32bit maths to ensure the registers used by the
\r
203 integer tasks get some exercise. The result here is not important -
\r
204 see the demo application documentation for more info. */
\r
205 ulDummyVariable *= 3;
\r
207 prvCheckOtherTasksAreStillRunning();
\r
210 /*-----------------------------------------------------------*/
\r
212 static void prvCheckOtherTasksAreStillRunning( void )
\r
214 static portBASE_TYPE xErrorHasOccurred = pdFALSE;
\r
216 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
218 xErrorHasOccurred = pdTRUE;
\r
221 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
223 xErrorHasOccurred = pdTRUE;
\r
226 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
228 xErrorHasOccurred = pdTRUE;
\r
231 if( xAreRegTestTasksStillRunning() != pdTRUE )
\r
233 xErrorHasOccurred = pdTRUE;
\r
236 if( xErrorHasOccurred == pdFALSE )
\r
238 /* Toggle the LED if everything is okay so we know if an error occurs even if not
\r
239 using console IO. */
\r
240 vParTestToggleLED( mainCHECK_TASK_LED );
\r
243 /*-----------------------------------------------------------*/
\r
245 static void prvIncrementResetCount( void )
\r
247 unsigned portCHAR ucCount;
\r
248 const unsigned portCHAR ucReadBit = ( unsigned portCHAR ) 0x01;
\r
249 const unsigned portCHAR ucWrite1 = ( unsigned portCHAR ) 0x04;
\r
250 const unsigned portCHAR ucWrite2 = ( unsigned portCHAR ) 0x02;
\r
252 /* Increment the EEPROM value at 0x00.
\r
254 Setup the EEPROM address. */
\r
258 /* Set the read enable bit. */
\r
261 /* Wait for the read. */
\r
262 while( EECR & ucReadBit );
\r
264 /* The byte is ready. */
\r
267 /* Increment the reset count, then write the byte back. */
\r
271 EECR = ( ucWrite1 | ucWrite2 );
\r
273 /*-----------------------------------------------------------*/
\r
275 void vApplicationIdleHook( void )
\r
277 vCoRoutineSchedule();
\r