2 FreeRTOS V7.1.1 - Copyright (C) 2012 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 ***************************************************************************
\r
46 * Having a problem? Start by reading the FAQ "My application does *
\r
47 * not run, what could be wrong? *
\r
49 * http://www.FreeRTOS.org/FAQHelp.html *
\r
51 ***************************************************************************
\r
54 http://www.FreeRTOS.org - Documentation, training, latest information,
\r
55 license and contact details.
\r
57 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
58 including FreeRTOS+Trace - an indispensable productivity tool.
\r
60 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
61 the code with commercial support, indemnification, and middleware, under
\r
62 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
63 provide a safety engineered and independently SIL3 certified version under
\r
64 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
68 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
69 * documentation provides more details of the demo application tasks.
\r
71 * Main. c also creates a task called "Check". This only executes every three
\r
72 * seconds but has the highest priority so is guaranteed to get processor time.
\r
73 * Its main function is to check that all the other tasks are still operational.
\r
74 * Each task that does not flash an LED maintains a unique count that is
\r
75 * incremented each time the task successfully completes its function. Should
\r
76 * any error occur within such a task the count is permanently halted. The
\r
77 * check task inspects the count of each task to ensure it has changed since
\r
78 * the last time the check task executed. If all the count variables have
\r
79 * changed all the tasks are still executing error free, and the check task
\r
80 * toggles an LED. Should any task contain an error at any time the LED toggle
\r
83 * The LED flash and communications test tasks do not maintain a count.
\r
89 + Changed the baud rate for the serial test from 19200 to 57600.
\r
93 + The integer and comtest tasks are now used when the cooperative scheduler
\r
94 is being used. Previously they were only used with the preemptive
\r
99 + Set the baud rate to 38400. This has a smaller error percentage with an
\r
100 8MHz clock (according to the manual).
\r
102 Changes from V2.0.0
\r
104 + Delay periods are now specified using variables and constants of
\r
105 portTickType rather than unsigned long.
\r
107 Changes from V2.2.0
\r
109 + File can now be built using either the IAR or WinAVR compiler.
\r
111 Changes from V2.6.1
\r
113 + The IAR and WinAVR AVR ports are now maintained separately.
\r
115 Changes from V4.0.5
\r
117 + Modified to demonstrate the use of co-routines.
\r
120 #include <stdlib.h>
\r
121 #include <string.h>
\r
123 #ifdef GCC_MEGA_AVR
\r
124 /* EEPROM routines used only with the WinAVR compiler. */
\r
125 #include <avr/eeprom.h>
\r
128 /* Scheduler include files. */
\r
129 #include "FreeRTOS.h"
\r
131 #include "croutine.h"
\r
133 /* Demo file headers. */
\r
135 #include "integer.h"
\r
136 #include "serial.h"
\r
137 #include "comtest.h"
\r
138 #include "crflash.h"
\r
140 #include "partest.h"
\r
141 #include "regtest.h"
\r
143 /* Priority definitions for most of the tasks in the demo application. Some
\r
144 tasks just use the idle priority. */
\r
145 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
146 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
147 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
148 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
150 /* Baud rate used by the serial port tasks. */
\r
151 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 38400 )
\r
153 /* LED used by the serial port tasks. This is toggled on each character Tx,
\r
154 and mainCOM_TEST_LED + 1 is toggles on each character Rx. */
\r
155 #define mainCOM_TEST_LED ( 4 )
\r
157 /* LED that is toggled by the check task. The check task periodically checks
\r
158 that all the other tasks are operating without error. If no errors are found
\r
159 the LED is toggled. If an error is found at any time the LED is never toggles
\r
161 #define mainCHECK_TASK_LED ( 7 )
\r
163 /* The period between executions of the check task. */
\r
164 #define mainCHECK_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
166 /* An address in the EEPROM used to count resets. This is used to check that
\r
167 the demo application is not unexpectedly resetting. */
\r
168 #define mainRESET_COUNT_ADDRESS ( ( void * ) 0x50 )
\r
170 /* The number of coroutines to create. */
\r
171 #define mainNUM_FLASH_COROUTINES ( 3 )
\r
174 * The task function for the "Check" task.
\r
176 static void vErrorChecks( void *pvParameters );
\r
179 * Checks the unique counts of other tasks to ensure they are still operational.
\r
180 * Flashes an LED if everything is okay.
\r
182 static void prvCheckOtherTasksAreStillRunning( void );
\r
185 * Called on boot to increment a count stored in the EEPROM. This is used to
\r
186 * ensure the CPU does not reset unexpectedly.
\r
188 static void prvIncrementResetCount( void );
\r
191 * Idle hook is used to scheduler co-routines.
\r
193 void vApplicationIdleHook( void );
\r
197 prvIncrementResetCount();
\r
199 /* Setup the LED's for output. */
\r
200 vParTestInitialise();
\r
202 /* Create the standard demo tasks. */
\r
203 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
204 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
205 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
206 vStartRegTestTasks();
\r
208 /* Create the tasks defined within this file. */
\r
209 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
211 /* Create the co-routines that flash the LED's. */
\r
212 vStartFlashCoRoutines( mainNUM_FLASH_COROUTINES );
\r
214 /* In this port, to use preemptive scheduler define configUSE_PREEMPTION
\r
215 as 1 in portmacro.h. To use the cooperative scheduler define
\r
216 configUSE_PREEMPTION as 0. */
\r
217 vTaskStartScheduler();
\r
221 /*-----------------------------------------------------------*/
\r
223 static void vErrorChecks( void *pvParameters )
\r
225 static volatile unsigned long ulDummyVariable = 3UL;
\r
227 /* The parameters are not used. */
\r
228 ( void ) pvParameters;
\r
230 /* Cycle for ever, delaying then checking all the other tasks are still
\r
231 operating without error. */
\r
234 vTaskDelay( mainCHECK_PERIOD );
\r
236 /* Perform a bit of 32bit maths to ensure the registers used by the
\r
237 integer tasks get some exercise. The result here is not important -
\r
238 see the demo application documentation for more info. */
\r
239 ulDummyVariable *= 3;
\r
241 prvCheckOtherTasksAreStillRunning();
\r
244 /*-----------------------------------------------------------*/
\r
246 static void prvCheckOtherTasksAreStillRunning( void )
\r
248 static portBASE_TYPE xErrorHasOccurred = pdFALSE;
\r
250 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
252 xErrorHasOccurred = pdTRUE;
\r
255 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
257 xErrorHasOccurred = pdTRUE;
\r
260 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
262 xErrorHasOccurred = pdTRUE;
\r
265 if( xAreRegTestTasksStillRunning() != pdTRUE )
\r
267 xErrorHasOccurred = pdTRUE;
\r
270 if( xErrorHasOccurred == pdFALSE )
\r
272 /* Toggle the LED if everything is okay so we know if an error occurs even if not
\r
273 using console IO. */
\r
274 vParTestToggleLED( mainCHECK_TASK_LED );
\r
277 /*-----------------------------------------------------------*/
\r
279 static void prvIncrementResetCount( void )
\r
281 unsigned char ucCount;
\r
282 const unsigned char ucReadBit = ( unsigned char ) 0x01;
\r
283 const unsigned char ucWrite1 = ( unsigned char ) 0x04;
\r
284 const unsigned char ucWrite2 = ( unsigned char ) 0x02;
\r
286 /* Increment the EEPROM value at 0x00.
\r
288 Setup the EEPROM address. */
\r
292 /* Set the read enable bit. */
\r
295 /* Wait for the read. */
\r
296 while( EECR & ucReadBit );
\r
298 /* The byte is ready. */
\r
301 /* Increment the reset count, then write the byte back. */
\r
305 EECR = ( ucWrite1 | ucWrite2 );
\r
307 /*-----------------------------------------------------------*/
\r
309 void vApplicationIdleHook( void )
\r
311 vCoRoutineSchedule();
\r