2 * FreeRTOS Kernel V10.2.1
\r
3 * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
29 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
30 * documentation provides more details of the demo application tasks.
\r
32 * Main. c also creates a task called "Check". This only executes every three
\r
33 * seconds but has the highest priority so is guaranteed to get processor time.
\r
34 * Its main function is to check that all the other tasks are still operational.
\r
35 * Each task that does not flash an LED maintains a unique count that is
\r
36 * incremented each time the task successfully completes its function. Should
\r
37 * any error occur within such a task the count is permanently halted. The
\r
38 * check task inspects the count of each task to ensure it has changed since
\r
39 * the last time the check task executed. If all the count variables have
\r
40 * changed all the tasks are still executing error free, and the check task
\r
41 * toggles an LED. Should any task contain an error at any time the LED toggle
\r
44 * The LED flash and communications test tasks do not maintain a count.
\r
50 + Changed the baud rate for the serial test from 19200 to 57600.
\r
54 + The integer and comtest tasks are now used when the cooperative scheduler
\r
55 is being used. Previously they were only used with the preemptive
\r
60 + Set the baud rate to 38400. This has a smaller error percentage with an
\r
61 8MHz clock (according to the manual).
\r
65 + Delay periods are now specified using variables and constants of
\r
66 TickType_t rather than unsigned long.
\r
70 + The IAR and WinAVR AVR ports are now maintained separately.
\r
74 + Modified to demonstrate the use of co-routines.
\r
82 /* EEPROM routines used only with the WinAVR compiler. */
\r
83 #include <avr/eeprom.h>
\r
86 /* Scheduler include files. */
\r
87 #include "FreeRTOS.h"
\r
89 #include "croutine.h"
\r
91 /* Demo file headers. */
\r
93 #include "integer.h"
\r
95 #include "comtest.h"
\r
96 #include "crflash.h"
\r
98 #include "partest.h"
\r
99 #include "regtest.h"
\r
101 /* Priority definitions for most of the tasks in the demo application. Some
\r
102 tasks just use the idle priority. */
\r
103 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
104 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
105 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
106 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
108 /* Baud rate used by the serial port tasks. */
\r
109 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 38400 )
\r
111 /* LED used by the serial port tasks. This is toggled on each character Tx,
\r
112 and mainCOM_TEST_LED + 1 is toggles on each character Rx. */
\r
113 #define mainCOM_TEST_LED ( 4 )
\r
115 /* LED that is toggled by the check task. The check task periodically checks
\r
116 that all the other tasks are operating without error. If no errors are found
\r
117 the LED is toggled. If an error is found at any time the LED is never toggles
\r
119 #define mainCHECK_TASK_LED ( 7 )
\r
121 /* The period between executions of the check task. */
\r
122 #define mainCHECK_PERIOD ( ( TickType_t ) 3000 / portTICK_PERIOD_MS )
\r
124 /* An address in the EEPROM used to count resets. This is used to check that
\r
125 the demo application is not unexpectedly resetting. */
\r
126 #define mainRESET_COUNT_ADDRESS ( ( void * ) 0x50 )
\r
128 /* The number of coroutines to create. */
\r
129 #define mainNUM_FLASH_COROUTINES ( 3 )
\r
132 * The task function for the "Check" task.
\r
134 static void vErrorChecks( void *pvParameters );
\r
137 * Checks the unique counts of other tasks to ensure they are still operational.
\r
138 * Flashes an LED if everything is okay.
\r
140 static void prvCheckOtherTasksAreStillRunning( void );
\r
143 * Called on boot to increment a count stored in the EEPROM. This is used to
\r
144 * ensure the CPU does not reset unexpectedly.
\r
146 static void prvIncrementResetCount( void );
\r
149 * The idle hook is used to scheduler co-routines.
\r
151 void vApplicationIdleHook( void );
\r
153 /*-----------------------------------------------------------*/
\r
157 prvIncrementResetCount();
\r
159 /* Setup the LED's for output. */
\r
160 vParTestInitialise();
\r
162 /* Create the standard demo tasks. */
\r
163 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
164 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
165 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
166 vStartRegTestTasks();
\r
168 /* Create the tasks defined within this file. */
\r
169 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
171 /* Create the co-routines that flash the LED's. */
\r
172 vStartFlashCoRoutines( mainNUM_FLASH_COROUTINES );
\r
174 /* In this port, to use preemptive scheduler define configUSE_PREEMPTION
\r
175 as 1 in portmacro.h. To use the cooperative scheduler define
\r
176 configUSE_PREEMPTION as 0. */
\r
177 vTaskStartScheduler();
\r
181 /*-----------------------------------------------------------*/
\r
183 static void vErrorChecks( void *pvParameters )
\r
185 static volatile unsigned long ulDummyVariable = 3UL;
\r
187 /* The parameters are not used. */
\r
188 ( void ) pvParameters;
\r
190 /* Cycle for ever, delaying then checking all the other tasks are still
\r
191 operating without error. */
\r
194 vTaskDelay( mainCHECK_PERIOD );
\r
196 /* Perform a bit of 32bit maths to ensure the registers used by the
\r
197 integer tasks get some exercise. The result here is not important -
\r
198 see the demo application documentation for more info. */
\r
199 ulDummyVariable *= 3;
\r
201 prvCheckOtherTasksAreStillRunning();
\r
204 /*-----------------------------------------------------------*/
\r
206 static void prvCheckOtherTasksAreStillRunning( void )
\r
208 static portBASE_TYPE xErrorHasOccurred = pdFALSE;
\r
210 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
212 xErrorHasOccurred = pdTRUE;
\r
215 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
217 xErrorHasOccurred = pdTRUE;
\r
220 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
222 xErrorHasOccurred = pdTRUE;
\r
225 if( xAreRegTestTasksStillRunning() != pdTRUE )
\r
227 xErrorHasOccurred = pdTRUE;
\r
230 if( xErrorHasOccurred == pdFALSE )
\r
232 /* Toggle the LED if everything is okay so we know if an error occurs even if not
\r
233 using console IO. */
\r
234 vParTestToggleLED( mainCHECK_TASK_LED );
\r
237 /*-----------------------------------------------------------*/
\r
239 static void prvIncrementResetCount( void )
\r
241 unsigned char ucCount;
\r
243 eeprom_read_block( &ucCount, mainRESET_COUNT_ADDRESS, sizeof( ucCount ) );
\r
245 eeprom_write_byte( mainRESET_COUNT_ADDRESS, ucCount );
\r
247 /*-----------------------------------------------------------*/
\r
249 void vApplicationIdleHook( void )
\r
251 vCoRoutineSchedule();
\r