2 FreeRTOS.org V5.1.2 - Copyright (C) 2003-2009 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 ***************************************************************************
\r
29 * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *
\r
31 * This is a concise, step by step, 'hands on' guide that describes both *
\r
32 * general multitasking concepts and FreeRTOS specifics. It presents and *
\r
33 * explains numerous examples that are written using the FreeRTOS API. *
\r
34 * Full source code for all the examples is provided in an accompanying *
\r
37 ***************************************************************************
\r
38 ***************************************************************************
\r
40 Please ensure to read the configuration and relevant port sections of the
\r
41 online documentation.
\r
43 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
46 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
49 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
50 licensing and training services.
\r
54 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
55 * documentation provides more details of the demo application tasks.
\r
57 * Main. c also creates a task called "Check". This only executes every three
\r
58 * seconds but has the highest priority so is guaranteed to get processor time.
\r
59 * Its main function is to check that all the other tasks are still operational.
\r
60 * Each task that does not flash an LED maintains a unique count that is
\r
61 * incremented each time the task successfully completes its function. Should
\r
62 * any error occur within such a task the count is permanently halted. The
\r
63 * check task inspects the count of each task to ensure it has changed since
\r
64 * the last time the check task executed. If all the count variables have
\r
65 * changed all the tasks are still executing error free, and the check task
\r
66 * toggles an LED. Should any task contain an error at any time the LED toggle
\r
69 * The LED flash and communications test tasks do not maintain a count.
\r
75 + Changed the baud rate for the serial test from 19200 to 57600.
\r
79 + The integer and comtest tasks are now used when the cooperative scheduler
\r
80 is being used. Previously they were only used with the preemptive
\r
85 + Set the baud rate to 38400. This has a smaller error percentage with an
\r
86 8MHz clock (according to the manual).
\r
90 + Delay periods are now specified using variables and constants of
\r
91 portTickType rather than unsigned portLONG.
\r
95 + File can now be built using either the IAR or WinAVR compiler.
\r
99 + The IAR and WinAVR AVR ports are now maintained separately.
\r
101 Changes from V4.0.5
\r
103 + Modified to demonstrate the use of co-routines.
\r
106 #include <stdlib.h>
\r
107 #include <string.h>
\r
109 #ifdef GCC_MEGA_AVR
\r
110 /* EEPROM routines used only with the WinAVR compiler. */
\r
111 #include <avr/eeprom.h>
\r
114 /* Scheduler include files. */
\r
115 #include "FreeRTOS.h"
\r
117 #include "croutine.h"
\r
119 /* Demo file headers. */
\r
121 #include "integer.h"
\r
122 #include "serial.h"
\r
123 #include "comtest.h"
\r
124 #include "crflash.h"
\r
126 #include "partest.h"
\r
127 #include "regtest.h"
\r
129 /* Priority definitions for most of the tasks in the demo application. Some
\r
130 tasks just use the idle priority. */
\r
131 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
132 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
133 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
134 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
136 /* Baud rate used by the serial port tasks. */
\r
137 #define mainCOM_TEST_BAUD_RATE ( ( unsigned portLONG ) 38400 )
\r
139 /* LED used by the serial port tasks. This is toggled on each character Tx,
\r
140 and mainCOM_TEST_LED + 1 is toggles on each character Rx. */
\r
141 #define mainCOM_TEST_LED ( 4 )
\r
143 /* LED that is toggled by the check task. The check task periodically checks
\r
144 that all the other tasks are operating without error. If no errors are found
\r
145 the LED is toggled. If an error is found at any time the LED is never toggles
\r
147 #define mainCHECK_TASK_LED ( 7 )
\r
149 /* The period between executions of the check task. */
\r
150 #define mainCHECK_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
152 /* An address in the EEPROM used to count resets. This is used to check that
\r
153 the demo application is not unexpectedly resetting. */
\r
154 #define mainRESET_COUNT_ADDRESS ( ( void * ) 0x50 )
\r
156 /* The number of coroutines to create. */
\r
157 #define mainNUM_FLASH_COROUTINES ( 3 )
\r
160 * The task function for the "Check" task.
\r
162 static void vErrorChecks( void *pvParameters );
\r
165 * Checks the unique counts of other tasks to ensure they are still operational.
\r
166 * Flashes an LED if everything is okay.
\r
168 static void prvCheckOtherTasksAreStillRunning( void );
\r
171 * Called on boot to increment a count stored in the EEPROM. This is used to
\r
172 * ensure the CPU does not reset unexpectedly.
\r
174 static void prvIncrementResetCount( void );
\r
177 * Idle hook is used to scheduler co-routines.
\r
179 void vApplicationIdleHook( void );
\r
181 portSHORT main( void )
\r
183 prvIncrementResetCount();
\r
185 /* Setup the LED's for output. */
\r
186 vParTestInitialise();
\r
188 /* Create the standard demo tasks. */
\r
189 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
190 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
191 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
192 vStartRegTestTasks();
\r
194 /* Create the tasks defined within this file. */
\r
195 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
197 /* Create the co-routines that flash the LED's. */
\r
198 vStartFlashCoRoutines( mainNUM_FLASH_COROUTINES );
\r
200 /* In this port, to use preemptive scheduler define configUSE_PREEMPTION
\r
201 as 1 in portmacro.h. To use the cooperative scheduler define
\r
202 configUSE_PREEMPTION as 0. */
\r
203 vTaskStartScheduler();
\r
207 /*-----------------------------------------------------------*/
\r
209 static void vErrorChecks( void *pvParameters )
\r
211 static volatile unsigned portLONG ulDummyVariable = 3UL;
\r
213 /* The parameters are not used. */
\r
214 ( void ) pvParameters;
\r
216 /* Cycle for ever, delaying then checking all the other tasks are still
\r
217 operating without error. */
\r
220 vTaskDelay( mainCHECK_PERIOD );
\r
222 /* Perform a bit of 32bit maths to ensure the registers used by the
\r
223 integer tasks get some exercise. The result here is not important -
\r
224 see the demo application documentation for more info. */
\r
225 ulDummyVariable *= 3;
\r
227 prvCheckOtherTasksAreStillRunning();
\r
230 /*-----------------------------------------------------------*/
\r
232 static void prvCheckOtherTasksAreStillRunning( void )
\r
234 static portBASE_TYPE xErrorHasOccurred = pdFALSE;
\r
236 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
238 xErrorHasOccurred = pdTRUE;
\r
241 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
243 xErrorHasOccurred = pdTRUE;
\r
246 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
248 xErrorHasOccurred = pdTRUE;
\r
251 if( xAreRegTestTasksStillRunning() != pdTRUE )
\r
253 xErrorHasOccurred = pdTRUE;
\r
256 if( xErrorHasOccurred == pdFALSE )
\r
258 /* Toggle the LED if everything is okay so we know if an error occurs even if not
\r
259 using console IO. */
\r
260 vParTestToggleLED( mainCHECK_TASK_LED );
\r
263 /*-----------------------------------------------------------*/
\r
265 static void prvIncrementResetCount( void )
\r
267 unsigned portCHAR ucCount;
\r
268 const unsigned portCHAR ucReadBit = ( unsigned portCHAR ) 0x01;
\r
269 const unsigned portCHAR ucWrite1 = ( unsigned portCHAR ) 0x04;
\r
270 const unsigned portCHAR ucWrite2 = ( unsigned portCHAR ) 0x02;
\r
272 /* Increment the EEPROM value at 0x00.
\r
274 Setup the EEPROM address. */
\r
278 /* Set the read enable bit. */
\r
281 /* Wait for the read. */
\r
282 while( EECR & ucReadBit );
\r
284 /* The byte is ready. */
\r
287 /* Increment the reset count, then write the byte back. */
\r
291 EECR = ( ucWrite1 | ucWrite2 );
\r
293 /*-----------------------------------------------------------*/
\r
295 void vApplicationIdleHook( void )
\r
297 vCoRoutineSchedule();
\r