2 * FreeRTOS Kernel V10.3.0
\r
3 * Copyright (C) 2020 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
28 /******************************************************************************
\r
29 * NOTE 1: This project provides two demo applications. A simple blinky style
\r
30 * project, and a more comprehensive test and demo application. The
\r
31 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select
\r
32 * between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY
\r
33 * in main.c. This file implements the comprehensive test and demo version.
\r
35 * NOTE 2: This file only contains the source code that is specific to the
\r
36 * full demo. Generic functions, such FreeRTOS hook functions, and functions
\r
37 * required to configure the hardware, are defined in main.c.
\r
38 ******************************************************************************
\r
40 * main_full() creates all the demo application tasks and software timers,
\r
41 * then starts the scheduler. The web documentation provides more details of
\r
42 * the standard demo application tasks, which provide no particular
\r
43 * functionality, but do provide a good example of how to use the FreeRTOS API.
\r
45 * In addition to the standard demo tasks, the following tasks and tests are
\r
46 * defined and/or created within this file:
\r
48 * "Check" timer - The check software timer period is set to three seconds.
\r
49 * The callback function associated with the check software timer checks that
\r
50 * all the standard demo tasks are not only still executing, but are executing
\r
51 * without reporting any errors. If the check software timer discovers that a
\r
52 * task has either stalled, or reported an error, then the error is logged and
\r
53 * the check software timer toggles the red LEDs. If an error has never been
\r
54 * latched, the check software timer toggles the green LEDs. Therefore, if the
\r
55 * system is executing correctly, the green LEDs will toggle every three
\r
56 * seconds, and if an error has ever been detected, the red LEDs will toggle
\r
57 * every three seconds.
\r
59 * "Reg test" tasks - These fill both the core and floating point registers
\r
60 * with known values, then check that each register maintains its expected
\r
61 * value for the lifetime of the tasks. Each task uses a different set of
\r
62 * values. The reg test tasks execute with a very low priority, so get
\r
63 * preempted very frequently. A register containing an unexpected value is
\r
64 * indicative of an error in the context switching mechanism.
\r
66 * "LED" software timer - The callback function associated with the LED
\r
67 * software time maintains a pattern of spinning white LEDs.
\r
69 * See the documentation page for this demo on the FreeRTOS.org web site for
\r
70 * full information, including hardware setup requirements.
\r
73 /* Standard includes. */
\r
76 /* Kernel includes. */
\r
77 #include "FreeRTOS.h"
\r
82 /* Standard demo application includes. */
\r
83 #include "integer.h"
\r
85 #include "semtest.h"
\r
86 #include "dynamic.h"
\r
88 #include "blocktim.h"
\r
89 #include "countsem.h"
\r
90 #include "GenQTest.h"
\r
91 #include "recmutex.h"
\r
93 #include "partest.h"
\r
96 #include "comtest.h"
\r
98 /* Priorities for the demo application tasks. */
\r
99 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
100 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1UL )
\r
101 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
102 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3UL )
\r
103 #define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
104 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
105 #define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
107 /* A block time of zero simply means "don't block". */
\r
108 #define mainDONT_BLOCK ( 0UL )
\r
110 /* The period after which the check timer will expire, converted to ticks. */
\r
111 #define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_PERIOD_MS )
\r
113 /* The period after which the LED timer will expire, converted to ticks. */
\r
114 #define mainLED_TIMER_PERIOD_MS ( 75UL / portTICK_PERIOD_MS )
\r
116 /* Constants for the ComTest tasks. */
\r
117 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 19200 )
\r
118 #define mainCOM_TEST_LED ( 100 )
\r
120 /*-----------------------------------------------------------*/
\r
123 * The check timer callback function, as described at the top of this file.
\r
125 static void prvCheckTimerCallback( TimerHandle_t xTimer );
\r
128 * The LED timer callback function, as described at the top of this file.
\r
130 static void prvLEDTimerCallback( TimerHandle_t xTimer );
\r
133 * The reg test tasks, as described at the top of this file.
\r
135 extern void vRegTestTask1( void *pvParameters );
\r
136 extern void vRegTestTask2( void *pvParameters );
\r
138 /*-----------------------------------------------------------*/
\r
140 /* Variables that are incremented on each iteration of the reg test tasks -
\r
141 provided the tasks have not reported any errors. The check task inspects these
\r
142 variables to ensure they are still incrementing as expected. If a variable
\r
143 stops incrementing then it is likely that its associate task has stalled. */
\r
144 volatile unsigned long ulRegTest1Counter = 0, ulRegTest2Counter = 0;
\r
146 /*-----------------------------------------------------------*/
\r
148 void main_full( void )
\r
150 TimerHandle_t xTimer = NULL;
\r
152 /* Start all the standard demo/test tasks. These have not particular
\r
153 functionality, but do demonstrate how to use the FreeRTOS API, and test the
\r
155 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
156 vStartDynamicPriorityTasks();
\r
157 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
158 vCreateBlockTimeTasks();
\r
159 vStartCountingSemaphoreTasks();
\r
160 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
161 vStartRecursiveMutexTasks();
\r
162 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
163 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
164 vStartMathTasks( mainFLOP_TASK_PRIORITY );
\r
165 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
167 /* Create the register test tasks, as described at the top of this file. */
\r
168 xTaskCreate( vRegTestTask1, "Reg1...", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
169 xTaskCreate( vRegTestTask2, "Reg2...", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
172 /* Create the software timer that performs the 'check' functionality,
\r
173 as described at the top of this file. */
\r
174 xTimer = xTimerCreate( "CheckTimer", /* A text name, purely to help debugging. */
\r
175 ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */
\r
176 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
177 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
178 prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */
\r
181 if( xTimer != NULL )
\r
183 xTimerStart( xTimer, mainDONT_BLOCK );
\r
186 /* Create the software timer that performs the 'LED spin' functionality,
\r
187 as described at the top of this file. */
\r
188 xTimer = xTimerCreate( "LEDTimer", /* A text name, purely to help debugging. */
\r
189 ( mainLED_TIMER_PERIOD_MS ),/* The timer period, in this case 75ms. */
\r
190 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
191 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
192 prvLEDTimerCallback /* The callback function that toggles the white LEDs. */
\r
195 if( xTimer != NULL )
\r
197 xTimerStart( xTimer, mainDONT_BLOCK );
\r
200 /* The set of tasks created by the following function call have to be
\r
201 created last as they keep account of the number of tasks they expect to see
\r
203 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
205 /* Start the scheduler. */
\r
206 vTaskStartScheduler();
\r
208 /* If all is well, the scheduler will now be running, and the following line
\r
209 will never be reached. If the following line does execute, then there was
\r
210 insufficient FreeRTOS heap memory available for the idle and/or timer tasks
\r
211 to be created. See the memory management section on the FreeRTOS web site
\r
212 for more details. */
\r
215 /*-----------------------------------------------------------*/
\r
217 static void prvCheckTimerCallback( TimerHandle_t xTimer )
\r
219 static long lChangeToRedLEDsAlready = pdFALSE;
\r
220 static unsigned long ulLastRegTest1Counter = 0, ulLastRegTest2Counter = 0;
\r
221 unsigned long ulErrorFound = pdFALSE;
\r
222 /* LEDs are defaulted to use the Green LEDs. The Red LEDs are used if an error
\r
224 static unsigned long ulLED1 = 8, ulLED2 = 11;
\r
225 const unsigned long ulRedLED1 = 6, ulRedLED2 = 9;
\r
227 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
228 they are all still running, and that none have detected an error. */
\r
230 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
232 ulErrorFound = pdTRUE;
\r
235 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
237 ulErrorFound = pdTRUE;
\r
240 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
242 ulErrorFound = pdTRUE;
\r
245 if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
247 ulErrorFound = pdTRUE;
\r
250 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
252 ulErrorFound = pdTRUE;
\r
255 if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
257 ulErrorFound = pdTRUE;
\r
260 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
262 ulErrorFound = pdTRUE;
\r
265 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
267 ulErrorFound = pdTRUE;
\r
270 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
272 ulErrorFound = pdTRUE;
\r
275 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
277 ulErrorFound = pdTRUE;
\r
280 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
282 ulErrorFound = pdTRUE;
\r
285 /* Check the reg test tasks are still cycling. They will stop
\r
286 incrementing their loop counters if they encounter an error. */
\r
287 if( ulRegTest1Counter == ulLastRegTest1Counter )
\r
289 ulErrorFound = pdTRUE;
\r
292 if( ulRegTest2Counter == ulLastRegTest2Counter )
\r
294 ulErrorFound = pdTRUE;
\r
297 ulLastRegTest1Counter = ulRegTest1Counter;
\r
298 ulLastRegTest2Counter = ulRegTest2Counter;
\r
300 /* Toggle the check LEDs to give an indication of the system status. If
\r
301 the green LEDs are toggling, then no errors have been detected. If the red
\r
302 LEDs are toggling, then an error has been reported in at least one task. */
\r
303 vParTestToggleLED( ulLED1 );
\r
304 vParTestToggleLED( ulLED2 );
\r
306 /* Have any errors been latch in ulErrorFound? If so, ensure the gree LEDs
\r
307 are off, then switch to using the red LEDs. */
\r
308 if( ulErrorFound != pdFALSE )
\r
310 if( lChangeToRedLEDsAlready == pdFALSE )
\r
312 lChangeToRedLEDsAlready = pdTRUE;
\r
314 /* An error has been found. Switch to use the red LEDs. */
\r
315 vParTestSetLED( ulLED1, pdFALSE );
\r
316 vParTestSetLED( ulLED2, pdFALSE );
\r
317 ulLED1 = ulRedLED1;
\r
318 ulLED2 = ulRedLED2;
\r
322 /*-----------------------------------------------------------*/
\r
324 static void prvLEDTimerCallback( TimerHandle_t xTimer )
\r
326 const unsigned long ulNumWhiteLEDs = 6;
\r
327 static unsigned long ulLit1 = 2, ulLit2 = 1;
\r
329 vParTestSetLED( ulLit2, pdFALSE );
\r
334 if( ulLit1 >= ulNumWhiteLEDs )
\r
339 vParTestSetLED( ulLit1, pdTRUE );
\r
341 /*-----------------------------------------------------------*/
\r