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 a software timer, then
\r
41 * starts the scheduler. The web documentation provides more details of the
\r
42 * standard demo application tasks, which provide no particular functionality,
\r
43 * 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 * "Reg test" tasks - These fill both the core and floating point registers with
\r
49 * known values, then check that each register maintains its expected value for
\r
50 * the lifetime of the task. Each task uses a different set of values. The reg
\r
51 * test tasks execute with a very low priority, so get preempted very
\r
52 * frequently. A register containing an unexpected value is indicative of an
\r
53 * error in the context switching mechanism.
\r
55 * "Check" timer - The check software timer period is initially set to three
\r
56 * seconds. The callback function associated with the check software timer
\r
57 * checks that all the standard demo tasks, and the register check tasks, are
\r
58 * not only still executing, but are executing without reporting any errors. If
\r
59 * the check software timer discovers that a task has either stalled, or
\r
60 * reported an error, then it changes its own execution period from the initial
\r
61 * three seconds, to just 200ms. The check software timer callback function
\r
62 * also toggles the single LED each time it is called. This provides a visual
\r
63 * indication of the system status: If the LED toggles every three seconds,
\r
64 * then no issues have been discovered. If the LED toggles every 200ms, then
\r
65 * an issue has been discovered with at least one task.
\r
68 /* Standard includes. */
\r
71 /* Kernel includes. */
\r
72 #include "FreeRTOS.h"
\r
77 /* Standard demo application includes. */
\r
79 #include "semtest.h"
\r
80 #include "dynamic.h"
\r
81 #include "blocktim.h"
\r
82 #include "countsem.h"
\r
83 #include "GenQTest.h"
\r
84 #include "recmutex.h"
\r
86 /* Priorities for the demo application tasks. */
\r
87 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
88 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1UL )
\r
89 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
90 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3UL )
\r
91 #define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
93 /* A block time of zero simply means "don't block". */
\r
94 #define mainDONT_BLOCK ( 0UL )
\r
96 /* The period after which the check timer will expire, in ms, provided no errors
\r
97 have been reported by any of the standard demo tasks. ms are converted to the
\r
98 equivalent in ticks using the portTICK_PERIOD_MS constant. */
\r
99 #define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_PERIOD_MS )
\r
101 /* The period at which the check timer will expire, in ms, if an error has been
\r
102 reported in one of the standard demo tasks. ms are converted to the equivalent
\r
103 in ticks using the portTICK_PERIOD_MS constant. */
\r
104 #define mainERROR_CHECK_TIMER_PERIOD_MS ( 200UL / portTICK_PERIOD_MS )
\r
106 /*-----------------------------------------------------------*/
\r
109 * The check timer callback function, as described at the top of this file.
\r
111 static void prvCheckTimerCallback( TimerHandle_t xTimer );
\r
114 * Register check tasks, and the tasks used to write over and check the contents
\r
115 * of the FPU registers, as described at the top of this file. The nature of
\r
116 * these files necessitates that they are written in an assembly file.
\r
118 static void prvRegTest1Task( void *pvParameters ) __attribute__((naked));
\r
119 static void prvRegTest2Task( void *pvParameters ) __attribute__((naked));
\r
121 /*-----------------------------------------------------------*/
\r
123 /* The following two variables are used to communicate the status of the
\r
124 register check tasks to the check software timer. If the variables keep
\r
125 incrementing, then the register check tasks have not discovered any errors. If
\r
126 a variable stops incrementing, then an error has been found. */
\r
127 volatile unsigned long ulRegTest1LoopCounter = 0UL, ulRegTest2LoopCounter = 0UL;
\r
129 /*-----------------------------------------------------------*/
\r
131 void main_full( void )
\r
133 TimerHandle_t xCheckTimer = NULL;
\r
135 /* Start all the other standard demo/test tasks. The have not particular
\r
136 functionality, but do demonstrate how to use the FreeRTOS API and test the
\r
138 vStartDynamicPriorityTasks();
\r
139 vCreateBlockTimeTasks();
\r
140 vStartCountingSemaphoreTasks();
\r
141 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
142 vStartRecursiveMutexTasks();
\r
143 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
144 vStartMathTasks( mainFLOP_TASK_PRIORITY );
\r
146 /* Create the register check tasks, as described at the top of this
\r
148 xTaskCreate( prvRegTest1Task, "Reg1", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );
\r
149 xTaskCreate( prvRegTest2Task, "Reg2", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );
\r
151 /* Create the software timer that performs the 'check' functionality,
\r
152 as described at the top of this file. */
\r
153 xCheckTimer = xTimerCreate( "CheckTimer", /* A text name, purely to help debugging. */
\r
154 ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */
\r
155 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
156 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
157 prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */
\r
160 if( xCheckTimer != NULL )
\r
162 xTimerStart( xCheckTimer, mainDONT_BLOCK );
\r
165 /* Start the scheduler. */
\r
166 vTaskStartScheduler();
\r
168 /* If all is well, the scheduler will now be running, and the following line
\r
169 will never be reached. If the following line does execute, then there was
\r
170 insufficient FreeRTOS heap memory available for the idle and/or timer tasks
\r
171 to be created. See the memory management section on the FreeRTOS web site
\r
172 for more details. */
\r
175 /*-----------------------------------------------------------*/
\r
177 static void prvCheckTimerCallback( TimerHandle_t xTimer )
\r
179 static long lChangedTimerPeriodAlready = pdFALSE;
\r
180 static unsigned long ulLastRegTest1Value = 0, ulLastRegTest2Value = 0;
\r
181 unsigned long ulErrorFound = pdFALSE;
\r
183 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
184 that they are all still running, and that none have detected an error. */
\r
186 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
188 ulErrorFound = pdTRUE;
\r
191 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
193 ulErrorFound = pdTRUE;
\r
196 if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
198 ulErrorFound = pdTRUE;
\r
201 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
203 ulErrorFound = pdTRUE;
\r
206 if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
208 ulErrorFound = pdTRUE;
\r
211 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
213 ulErrorFound = pdTRUE;
\r
216 /* Check that the register test 1 task is still running. */
\r
217 if( ulLastRegTest1Value == ulRegTest1LoopCounter )
\r
219 ulErrorFound = pdTRUE;
\r
221 ulLastRegTest1Value = ulRegTest1LoopCounter;
\r
223 /* Check that the register test 2 task is still running. */
\r
224 if( ulLastRegTest2Value == ulRegTest2LoopCounter )
\r
226 ulErrorFound = pdTRUE;
\r
228 ulLastRegTest2Value = ulRegTest2LoopCounter;
\r
230 /* Toggle the check LED to give an indication of the system status. If
\r
231 the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then
\r
232 everything is ok. A faster toggle indicates an error. */
\r
233 configTOGGLE_LED();
\r
235 /* Have any errors been latch in ulErrorFound? If so, shorten the
\r
236 period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.
\r
237 This will result in an increase in the rate at which mainCHECK_LED
\r
239 if( ulErrorFound != pdFALSE )
\r
241 if( lChangedTimerPeriodAlready == pdFALSE )
\r
243 lChangedTimerPeriodAlready = pdTRUE;
\r
245 /* This call to xTimerChangePeriod() uses a zero block time.
\r
246 Functions called from inside of a timer callback function must
\r
247 *never* attempt to block. */
\r
248 xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );
\r
252 /*-----------------------------------------------------------*/
\r
254 /* This is a naked function. */
\r
255 static void prvRegTest1Task( void *pvParameters )
\r
259 " /* Fill the core registers with known values. */ \n"
\r
270 " mov r10, #110 \n"
\r
271 " mov r11, #111 \n"
\r
272 " mov r12, #112 \n"
\r
274 " /* Fill the VFP registers with known values. */ \n"
\r
275 " vmov d0, r0, r1 \n"
\r
276 " vmov d1, r2, r3 \n"
\r
277 " vmov d2, r4, r5 \n"
\r
278 " vmov d3, r6, r7 \n"
\r
279 " vmov d4, r8, r9 \n"
\r
280 " vmov d5, r10, r11 \n"
\r
281 " vmov d6, r0, r1 \n"
\r
282 " vmov d7, r2, r3 \n"
\r
283 " vmov d8, r4, r5 \n"
\r
284 " vmov d9, r6, r7 \n"
\r
285 " vmov d10, r8, r9 \n"
\r
286 " vmov d11, r10, r11 \n"
\r
287 " vmov d12, r0, r1 \n"
\r
288 " vmov d13, r2, r3 \n"
\r
289 " vmov d14, r4, r5 \n"
\r
290 " vmov d15, r6, r7 \n"
\r
293 " /* Check all the VFP registers still contain the values set above.\n"
\r
294 " First save registers that are clobbered by the test. */ \n"
\r
295 " push { r0-r1 } \n"
\r
297 " vmov r0, r1, d0 \n"
\r
299 " bne reg1_error_loopf \n"
\r
301 " bne reg1_error_loopf \n"
\r
302 " vmov r0, r1, d1 \n"
\r
304 " bne reg1_error_loopf \n"
\r
306 " bne reg1_error_loopf \n"
\r
307 " vmov r0, r1, d2 \n"
\r
309 " bne reg1_error_loopf \n"
\r
311 " bne reg1_error_loopf \n"
\r
312 " vmov r0, r1, d3 \n"
\r
314 " bne reg1_error_loopf \n"
\r
316 " bne reg1_error_loopf \n"
\r
317 " vmov r0, r1, d4 \n"
\r
319 " bne reg1_error_loopf \n"
\r
321 " bne reg1_error_loopf \n"
\r
322 " vmov r0, r1, d5 \n"
\r
324 " bne reg1_error_loopf \n"
\r
326 " bne reg1_error_loopf \n"
\r
327 " vmov r0, r1, d6 \n"
\r
329 " bne reg1_error_loopf \n"
\r
331 " bne reg1_error_loopf \n"
\r
332 " vmov r0, r1, d7 \n"
\r
334 " bne reg1_error_loopf \n"
\r
336 " bne reg1_error_loopf \n"
\r
337 " vmov r0, r1, d8 \n"
\r
339 " bne reg1_error_loopf \n"
\r
341 " bne reg1_error_loopf \n"
\r
342 " vmov r0, r1, d9 \n"
\r
344 " bne reg1_error_loopf \n"
\r
346 " bne reg1_error_loopf \n"
\r
347 " vmov r0, r1, d10 \n"
\r
349 " bne reg1_error_loopf \n"
\r
351 " bne reg1_error_loopf \n"
\r
352 " vmov r0, r1, d11 \n"
\r
354 " bne reg1_error_loopf \n"
\r
356 " bne reg1_error_loopf \n"
\r
357 " vmov r0, r1, d12 \n"
\r
359 " bne reg1_error_loopf \n"
\r
361 " bne reg1_error_loopf \n"
\r
362 " vmov r0, r1, d13 \n"
\r
364 " bne reg1_error_loopf \n"
\r
366 " bne reg1_error_loopf \n"
\r
367 " vmov r0, r1, d14 \n"
\r
369 " bne reg1_error_loopf \n"
\r
371 " bne reg1_error_loopf \n"
\r
372 " vmov r0, r1, d15 \n"
\r
374 " bne reg1_error_loopf \n"
\r
376 " bne reg1_error_loopf \n"
\r
378 " /* Restore the registers that were clobbered by the test. */\n"
\r
381 " /* VFP register test passed. Jump to the core register test. */\n"
\r
382 " b reg1_loopf_pass \n"
\r
384 "reg1_error_loopf: \n"
\r
385 " /* If this line is hit then a VFP register value was found to be\n"
\r
386 " incorrect. */ \n"
\r
387 " b reg1_error_loopf \n"
\r
389 "reg1_loopf_pass: \n"
\r
392 " bne reg1_error_loop \n"
\r
394 " bne reg1_error_loop \n"
\r
396 " bne reg1_error_loop \n"
\r
398 " bne reg1_error_loop \n"
\r
400 " bne reg1_error_loop \n"
\r
402 " bne reg1_error_loop \n"
\r
404 " bne reg1_error_loop \n"
\r
406 " bne reg1_error_loop \n"
\r
408 " bne reg1_error_loop \n"
\r
410 " bne reg1_error_loop \n"
\r
411 " cmp r10, #110 \n"
\r
412 " bne reg1_error_loop \n"
\r
413 " cmp r11, #111 \n"
\r
414 " bne reg1_error_loop \n"
\r
415 " cmp r12, #112 \n"
\r
416 " bne reg1_error_loop \n"
\r
418 " /* Everything passed, increment the loop counter. */ \n"
\r
419 " push { r0-r1 } \n"
\r
420 " ldr r0, =ulRegTest1LoopCounter \n"
\r
422 " adds r1, r1, #1 \n"
\r
424 " pop { r0-r1 } \n"
\r
426 " /* Start again. */ \n"
\r
429 "reg1_error_loop: \n"
\r
430 " /* If this line is hit then there was an error in a core register value.\n"
\r
431 " The loop ensures the loop counter stops incrementing. */\n"
\r
432 " b reg1_error_loop \n"
\r
436 /*-----------------------------------------------------------*/
\r
438 /* This is a naked function. */
\r
439 static void prvRegTest2Task( void *pvParameters )
\r
443 " /* Set all the core registers to known values. */ \n"
\r
458 " /* Set all the VFP to known values. */ \n"
\r
459 " vmov d0, r0, r1 \n"
\r
460 " vmov d1, r2, r3 \n"
\r
461 " vmov d2, r4, r5 \n"
\r
462 " vmov d3, r6, r7 \n"
\r
463 " vmov d4, r8, r9 \n"
\r
464 " vmov d5, r10, r11 \n"
\r
465 " vmov d6, r0, r1 \n"
\r
466 " vmov d7, r2, r3 \n"
\r
467 " vmov d8, r4, r5 \n"
\r
468 " vmov d9, r6, r7 \n"
\r
469 " vmov d10, r8, r9 \n"
\r
470 " vmov d11, r10, r11 \n"
\r
471 " vmov d12, r0, r1 \n"
\r
472 " vmov d13, r2, r3 \n"
\r
473 " vmov d14, r4, r5 \n"
\r
474 " vmov d15, r6, r7 \n"
\r
478 " /* Check all the VFP registers still contain the values set above.\n"
\r
479 " First save registers that are clobbered by the test. */ \n"
\r
480 " push { r0-r1 } \n"
\r
482 " vmov r0, r1, d0 \n"
\r
484 " bne reg2_error_loopf \n"
\r
486 " bne reg2_error_loopf \n"
\r
487 " vmov r0, r1, d1 \n"
\r
489 " bne reg2_error_loopf \n"
\r
491 " bne reg2_error_loopf \n"
\r
492 " vmov r0, r1, d2 \n"
\r
494 " bne reg2_error_loopf \n"
\r
496 " bne reg2_error_loopf \n"
\r
497 " vmov r0, r1, d3 \n"
\r
499 " bne reg2_error_loopf \n"
\r
501 " bne reg2_error_loopf \n"
\r
502 " vmov r0, r1, d4 \n"
\r
504 " bne reg2_error_loopf \n"
\r
506 " bne reg2_error_loopf \n"
\r
507 " vmov r0, r1, d5 \n"
\r
509 " bne reg2_error_loopf \n"
\r
511 " bne reg2_error_loopf \n"
\r
512 " vmov r0, r1, d6 \n"
\r
514 " bne reg2_error_loopf \n"
\r
516 " bne reg2_error_loopf \n"
\r
517 " vmov r0, r1, d7 \n"
\r
519 " bne reg2_error_loopf \n"
\r
521 " bne reg2_error_loopf \n"
\r
522 " vmov r0, r1, d8 \n"
\r
524 " bne reg2_error_loopf \n"
\r
526 " bne reg2_error_loopf \n"
\r
527 " vmov r0, r1, d9 \n"
\r
529 " bne reg2_error_loopf \n"
\r
531 " bne reg2_error_loopf \n"
\r
532 " vmov r0, r1, d10 \n"
\r
534 " bne reg2_error_loopf \n"
\r
536 " bne reg2_error_loopf \n"
\r
537 " vmov r0, r1, d11 \n"
\r
539 " bne reg2_error_loopf \n"
\r
541 " bne reg2_error_loopf \n"
\r
542 " vmov r0, r1, d12 \n"
\r
544 " bne reg2_error_loopf \n"
\r
546 " bne reg2_error_loopf \n"
\r
547 " vmov r0, r1, d13 \n"
\r
549 " bne reg2_error_loopf \n"
\r
551 " bne reg2_error_loopf \n"
\r
552 " vmov r0, r1, d14 \n"
\r
554 " bne reg2_error_loopf \n"
\r
556 " bne reg2_error_loopf \n"
\r
557 " vmov r0, r1, d15 \n"
\r
559 " bne reg2_error_loopf \n"
\r
561 " bne reg2_error_loopf \n"
\r
563 " /* Restore the registers that were clobbered by the test. */\n"
\r
566 " /* VFP register test passed. Jump to the core register test. */\n"
\r
567 " b reg2_loopf_pass \n"
\r
569 "reg2_error_loopf: \n"
\r
570 " /* If this line is hit then a VFP register value was found to be\n"
\r
571 " incorrect. */ \n"
\r
572 " b reg2_error_loopf \n"
\r
574 "reg2_loopf_pass: \n"
\r
577 " bne reg2_error_loop \n"
\r
579 " bne reg2_error_loop \n"
\r
581 " bne reg2_error_loop \n"
\r
583 " bne reg2_error_loop \n"
\r
585 " bne reg2_error_loop \n"
\r
587 " bne reg2_error_loop \n"
\r
589 " bne reg2_error_loop \n"
\r
591 " bne reg2_error_loop \n"
\r
593 " bne reg2_error_loop \n"
\r
595 " bne reg2_error_loop \n"
\r
597 " bne reg2_error_loop \n"
\r
599 " bne reg2_error_loop \n"
\r
601 " bne reg2_error_loop \n"
\r
603 " /* Increment the loop counter to indicate this test is still functioning\n"
\r
604 " correctly. */ \n"
\r
605 " push { r0-r1 } \n"
\r
606 " ldr r0, =ulRegTest2LoopCounter \n"
\r
608 " adds r1, r1, #1 \n"
\r
611 " /* Yield to increase test coverage. */ \n"
\r
612 " movs r0, #0x01 \n"
\r
613 " ldr r1, =0xe000ed04 \n" /*NVIC_INT_CTRL */
\r
614 " lsl r0, #28 \n" /* Shift to PendSV bit */
\r
617 " pop { r0-r1 } \n"
\r
619 " /* Start again. */ \n"
\r
622 "reg2_error_loop: \n"
\r
623 " /* If this line is hit then there was an error in a core register value.\n"
\r
624 " This loop ensures the loop counter variable stops incrementing. */\n"
\r
625 " b reg2_error_loop \n"
\r