2 FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
7 This file is part of the FreeRTOS distribution.
9 FreeRTOS is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License (version 2) as published by the
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
13 ***************************************************************************
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
15 >>! distribute a combined work that includes FreeRTOS without being !<<
16 >>! obliged to provide the source code for proprietary components !<<
17 >>! outside of the FreeRTOS kernel. !<<
18 ***************************************************************************
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
23 link: http://www.freertos.org/a00114.html
25 ***************************************************************************
27 * FreeRTOS provides completely free yet professionally developed, *
28 * robust, strictly quality controlled, supported, and cross *
29 * platform software that is more than just the market leader, it *
30 * is the industry's de facto standard. *
32 * Help yourself get started quickly while simultaneously helping *
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
34 * tutorial book, reference manual, or both: *
35 * http://www.FreeRTOS.org/Documentation *
37 ***************************************************************************
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
40 the FAQ page "My application does not run, what could be wrong?". Have you
41 defined configASSERT()?
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
44 embedded software for free we request you assist our global community by
45 participating in the support forum.
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
48 be as productive as possible as early as possible. Now you can receive
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50 Ltd, and the world's leading authority on the world's leading RTOS.
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
61 licenses offer ticketed support, indemnification and commercial middleware.
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64 engineered and independently SIL3 certified version for use in safety and
65 mission critical applications that require provable dependability.
71 * Creates all the demo application tasks, then starts the scheduler. The WEB
72 * documentation provides more details of the demo application tasks.
74 * Main. c also creates a task called "Check". This only executes every three
75 * seconds but has the highest priority so is guaranteed to get processor time.
76 * Its main function is to check that all the other tasks are still operational.
77 * Each task that does not flash an LED maintains a unique count that is
78 * incremented each time the task successfully completes its function. Should
79 * any error occur within such a task the count is permanently halted. The
80 * check task inspects the count of each task to ensure it has changed since
81 * the last time the check task executed. If all the count variables have
82 * changed all the tasks are still executing error free, and the check task
83 * toggles an LED. Should any task contain an error at any time the LED toggle
86 * The LED flash and communications test tasks do not maintain a count.
92 + Changed the baud rate for the serial test from 19200 to 57600.
96 + The integer and comtest tasks are now used when the cooperative scheduler
97 is being used. Previously they were only used with the preemptive
102 + Set the baud rate to 38400. This has a smaller error percentage with an
103 8MHz clock (according to the manual).
107 + Delay periods are now specified using variables and constants of
108 TickType_t rather than unsigned long.
112 + File can now be built using either the IAR or WinAVR compiler.
116 + The IAR and WinAVR AVR ports are now maintained separately.
120 + Modified to demonstrate the use of co-routines.
127 /* EEPROM routines used only with the WinAVR compiler. */
128 #include <avr/eeprom.h>
131 /* Scheduler include files. */
132 #include "FreeRTOS.h"
134 #include "croutine.h"
136 /* Demo file headers. */
146 /* Priority definitions for most of the tasks in the demo application. Some
147 tasks just use the idle priority. */
148 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
149 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
150 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
151 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
153 /* Baud rate used by the serial port tasks. */
154 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 38400 )
156 /* LED used by the serial port tasks. This is toggled on each character Tx,
157 and mainCOM_TEST_LED + 1 is toggles on each character Rx. */
158 #define mainCOM_TEST_LED ( 4 )
160 /* LED that is toggled by the check task. The check task periodically checks
161 that all the other tasks are operating without error. If no errors are found
162 the LED is toggled. If an error is found at any time the LED is never toggles
164 #define mainCHECK_TASK_LED ( 7 )
166 /* The period between executions of the check task. */
167 #define mainCHECK_PERIOD ( ( TickType_t ) 3000 / portTICK_PERIOD_MS )
169 /* An address in the EEPROM used to count resets. This is used to check that
170 the demo application is not unexpectedly resetting. */
171 #define mainRESET_COUNT_ADDRESS ( ( void * ) 0x50 )
173 /* The number of coroutines to create. */
174 #define mainNUM_FLASH_COROUTINES ( 3 )
177 * The task function for the "Check" task.
179 static void vErrorChecks( void *pvParameters );
182 * Checks the unique counts of other tasks to ensure they are still operational.
183 * Flashes an LED if everything is okay.
185 static void prvCheckOtherTasksAreStillRunning( void );
188 * Called on boot to increment a count stored in the EEPROM. This is used to
189 * ensure the CPU does not reset unexpectedly.
191 static void prvIncrementResetCount( void );
194 * Idle hook is used to scheduler co-routines.
196 void vApplicationIdleHook( void );
200 prvIncrementResetCount();
202 /* Setup the LED's for output. */
203 vParTestInitialise();
205 /* Create the standard demo tasks. */
206 vStartIntegerMathTasks( tskIDLE_PRIORITY );
207 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
208 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
209 vStartRegTestTasks();
211 /* Create the tasks defined within this file. */
212 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
214 /* Create the co-routines that flash the LED's. */
215 vStartFlashCoRoutines( mainNUM_FLASH_COROUTINES );
217 /* In this port, to use preemptive scheduler define configUSE_PREEMPTION
218 as 1 in portmacro.h. To use the cooperative scheduler define
219 configUSE_PREEMPTION as 0. */
220 vTaskStartScheduler();
224 /*-----------------------------------------------------------*/
226 static void vErrorChecks( void *pvParameters )
228 static volatile unsigned long ulDummyVariable = 3UL;
230 /* The parameters are not used. */
231 ( void ) pvParameters;
233 /* Cycle for ever, delaying then checking all the other tasks are still
234 operating without error. */
237 vTaskDelay( mainCHECK_PERIOD );
239 /* Perform a bit of 32bit maths to ensure the registers used by the
240 integer tasks get some exercise. The result here is not important -
241 see the demo application documentation for more info. */
242 ulDummyVariable *= 3;
244 prvCheckOtherTasksAreStillRunning();
247 /*-----------------------------------------------------------*/
249 static void prvCheckOtherTasksAreStillRunning( void )
251 static portBASE_TYPE xErrorHasOccurred = pdFALSE;
253 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
255 xErrorHasOccurred = pdTRUE;
258 if( xAreComTestTasksStillRunning() != pdTRUE )
260 xErrorHasOccurred = pdTRUE;
263 if( xArePollingQueuesStillRunning() != pdTRUE )
265 xErrorHasOccurred = pdTRUE;
268 if( xAreRegTestTasksStillRunning() != pdTRUE )
270 xErrorHasOccurred = pdTRUE;
273 if( xErrorHasOccurred == pdFALSE )
275 /* Toggle the LED if everything is okay so we know if an error occurs even if not
277 vParTestToggleLED( mainCHECK_TASK_LED );
280 /*-----------------------------------------------------------*/
282 static void prvIncrementResetCount( void )
284 unsigned char ucCount;
285 const unsigned char ucReadBit = ( unsigned char ) 0x01;
286 const unsigned char ucWrite1 = ( unsigned char ) 0x04;
287 const unsigned char ucWrite2 = ( unsigned char ) 0x02;
289 /* Increment the EEPROM value at 0x00.
291 Setup the EEPROM address. */
295 /* Set the read enable bit. */
298 /* Wait for the read. */
299 while( EECR & ucReadBit );
301 /* The byte is ready. */
304 /* Increment the reset count, then write the byte back. */
308 EECR = ( ucWrite1 | ucWrite2 );
310 /*-----------------------------------------------------------*/
312 void vApplicationIdleHook( void )
314 vCoRoutineSchedule();