2 * FreeRTOS Kernel V10.0.0
\r
3 * Copyright (C) 2017 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. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
29 /******************************************************************************
\r
30 * NOTE 1: This project provides two demo applications. A simple blinky style
\r
31 * project, and a more comprehensive test and demo application. The
\r
32 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select
\r
33 * between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY
\r
34 * in main.c. This file implements the comprehensive test and demo version.
\r
36 * NOTE 2: This file only contains the source code that is specific to the
\r
37 * full demo. Generic functions, such FreeRTOS hook functions, and functions
\r
38 * required to configure the hardware, are defined in main.c.
\r
39 ******************************************************************************
\r
41 * main_full() creates all the demo application tasks and a software timer, then
\r
42 * starts the scheduler. The web documentation provides more details of the
\r
43 * standard demo application tasks, which provide no particular functionality,
\r
44 * but do provide a good example of how to use the FreeRTOS API.
\r
46 * In addition to the standard demo tasks, the following tasks and tests are
\r
47 * defined and/or created within this file:
\r
49 * "Reg test" tasks - These fill both the core and floating point registers with
\r
50 * known values, then check that each register maintains its expected value for
\r
51 * the lifetime of the task. Each task uses a different set of values. The reg
\r
52 * test tasks execute with a very low priority, so get preempted very
\r
53 * frequently. A register containing an unexpected value is indicative of an
\r
54 * error in the context switching mechanism.
\r
56 * "Check" timer - The check software timer period is initially set to three
\r
57 * seconds. The callback function associated with the check software timer
\r
58 * checks that all the standard demo tasks, and the register check tasks, are
\r
59 * not only still executing, but are executing without reporting any errors. If
\r
60 * the check software timer discovers that a task has either stalled, or
\r
61 * reported an error, then it changes its own execution period from the initial
\r
62 * three seconds, to just 200ms. The check software timer callback function
\r
63 * also toggles the single LED each time it is called. This provides a visual
\r
64 * indication of the system status: If the LED toggles every three seconds,
\r
65 * then no issues have been discovered. If the LED toggles every 200ms, then
\r
66 * an issue has been discovered with at least one task.
\r
69 /* Standard includes. */
\r
72 /* Kernel includes. */
\r
73 #include "FreeRTOS.h"
\r
78 /* Standard demo application includes. */
\r
80 #include "semtest.h"
\r
81 #include "dynamic.h"
\r
82 #include "blocktim.h"
\r
83 #include "countsem.h"
\r
84 #include "GenQTest.h"
\r
85 #include "recmutex.h"
\r
87 /* Priorities for the demo application tasks. */
\r
88 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
89 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1UL )
\r
90 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
91 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3UL )
\r
92 #define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
94 /* A block time of zero simply means "don't block". */
\r
95 #define mainDONT_BLOCK ( 0UL )
\r
97 /* The period after which the check timer will expire, in ms, provided no errors
\r
98 have been reported by any of the standard demo tasks. ms are converted to the
\r
99 equivalent in ticks using the portTICK_PERIOD_MS constant. */
\r
100 #define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_PERIOD_MS )
\r
102 /* The period at which the check timer will expire, in ms, if an error has been
\r
103 reported in one of the standard demo tasks. ms are converted to the equivalent
\r
104 in ticks using the portTICK_PERIOD_MS constant. */
\r
105 #define mainERROR_CHECK_TIMER_PERIOD_MS ( 200UL / portTICK_PERIOD_MS )
\r
107 /*-----------------------------------------------------------*/
\r
110 * The check timer callback function, as described at the top of this file.
\r
112 static void prvCheckTimerCallback( TimerHandle_t xTimer );
\r
115 * Register check tasks, and the tasks used to write over and check the contents
\r
116 * of the FPU registers, as described at the top of this file. The nature of
\r
117 * these files necessitates that they are written in an assembly file.
\r
119 static void prvRegTest1Task( void *pvParameters ) __attribute__((naked));
\r
120 static void prvRegTest2Task( void *pvParameters ) __attribute__((naked));
\r
122 /*-----------------------------------------------------------*/
\r
124 /* The following two variables are used to communicate the status of the
\r
125 register check tasks to the check software timer. If the variables keep
\r
126 incrementing, then the register check tasks have not discovered any errors. If
\r
127 a variable stops incrementing, then an error has been found. */
\r
128 volatile unsigned long ulRegTest1LoopCounter = 0UL, ulRegTest2LoopCounter = 0UL;
\r
130 /*-----------------------------------------------------------*/
\r
132 void main_full( void )
\r
134 TimerHandle_t xCheckTimer = NULL;
\r
136 /* Start all the other standard demo/test tasks. The have not particular
\r
137 functionality, but do demonstrate how to use the FreeRTOS API and test the
\r
139 vStartDynamicPriorityTasks();
\r
140 vCreateBlockTimeTasks();
\r
141 vStartCountingSemaphoreTasks();
\r
142 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
143 vStartRecursiveMutexTasks();
\r
144 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
145 vStartMathTasks( mainFLOP_TASK_PRIORITY );
\r
147 /* Create the register check tasks, as described at the top of this
\r
149 xTaskCreate( prvRegTest1Task, "Reg1", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );
\r
150 xTaskCreate( prvRegTest2Task, "Reg2", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );
\r
152 /* Create the software timer that performs the 'check' functionality,
\r
153 as described at the top of this file. */
\r
154 xCheckTimer = xTimerCreate( "CheckTimer", /* A text name, purely to help debugging. */
\r
155 ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */
\r
156 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
157 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
158 prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */
\r
161 if( xCheckTimer != NULL )
\r
163 xTimerStart( xCheckTimer, mainDONT_BLOCK );
\r
166 /* Start the scheduler. */
\r
167 vTaskStartScheduler();
\r
169 /* If all is well, the scheduler will now be running, and the following line
\r
170 will never be reached. If the following line does execute, then there was
\r
171 insufficient FreeRTOS heap memory available for the idle and/or timer tasks
\r
172 to be created. See the memory management section on the FreeRTOS web site
\r
173 for more details. */
\r
176 /*-----------------------------------------------------------*/
\r
178 static void prvCheckTimerCallback( TimerHandle_t xTimer )
\r
180 static long lChangedTimerPeriodAlready = pdFALSE;
\r
181 static unsigned long ulLastRegTest1Value = 0, ulLastRegTest2Value = 0;
\r
182 unsigned long ulErrorFound = pdFALSE;
\r
184 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
185 that they are all still running, and that none have detected an error. */
\r
187 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
189 ulErrorFound = pdTRUE;
\r
192 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
194 ulErrorFound = pdTRUE;
\r
197 if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
199 ulErrorFound = pdTRUE;
\r
202 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
204 ulErrorFound = pdTRUE;
\r
207 if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
209 ulErrorFound = pdTRUE;
\r
212 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
214 ulErrorFound = pdTRUE;
\r
217 /* Check that the register test 1 task is still running. */
\r
218 if( ulLastRegTest1Value == ulRegTest1LoopCounter )
\r
220 ulErrorFound = pdTRUE;
\r
222 ulLastRegTest1Value = ulRegTest1LoopCounter;
\r
224 /* Check that the register test 2 task is still running. */
\r
225 if( ulLastRegTest2Value == ulRegTest2LoopCounter )
\r
227 ulErrorFound = pdTRUE;
\r
229 ulLastRegTest2Value = ulRegTest2LoopCounter;
\r
231 /* Toggle the check LED to give an indication of the system status. If
\r
232 the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then
\r
233 everything is ok. A faster toggle indicates an error. */
\r
234 configTOGGLE_LED();
\r
236 /* Have any errors been latch in ulErrorFound? If so, shorten the
\r
237 period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.
\r
238 This will result in an increase in the rate at which mainCHECK_LED
\r
240 if( ulErrorFound != pdFALSE )
\r
242 if( lChangedTimerPeriodAlready == pdFALSE )
\r
244 lChangedTimerPeriodAlready = pdTRUE;
\r
246 /* This call to xTimerChangePeriod() uses a zero block time.
\r
247 Functions called from inside of a timer callback function must
\r
248 *never* attempt to block. */
\r
249 xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );
\r
253 /*-----------------------------------------------------------*/
\r
255 /* This is a naked function. */
\r
256 static void prvRegTest1Task( void *pvParameters )
\r
260 " /* Fill the core registers with known values. */ \n"
\r
271 " mov r10, #110 \n"
\r
272 " mov r11, #111 \n"
\r
273 " mov r12, #112 \n"
\r
275 " /* Fill the VFP registers with known values. */ \n"
\r
276 " vmov d0, r0, r1 \n"
\r
277 " vmov d1, r2, r3 \n"
\r
278 " vmov d2, r4, r5 \n"
\r
279 " vmov d3, r6, r7 \n"
\r
280 " vmov d4, r8, r9 \n"
\r
281 " vmov d5, r10, r11 \n"
\r
282 " vmov d6, r0, r1 \n"
\r
283 " vmov d7, r2, r3 \n"
\r
284 " vmov d8, r4, r5 \n"
\r
285 " vmov d9, r6, r7 \n"
\r
286 " vmov d10, r8, r9 \n"
\r
287 " vmov d11, r10, r11 \n"
\r
288 " vmov d12, r0, r1 \n"
\r
289 " vmov d13, r2, r3 \n"
\r
290 " vmov d14, r4, r5 \n"
\r
291 " vmov d15, r6, r7 \n"
\r
294 " /* Check all the VFP registers still contain the values set above.\n"
\r
295 " First save registers that are clobbered by the test. */ \n"
\r
296 " push { r0-r1 } \n"
\r
298 " vmov r0, r1, d0 \n"
\r
300 " bne reg1_error_loopf \n"
\r
302 " bne reg1_error_loopf \n"
\r
303 " vmov r0, r1, d1 \n"
\r
305 " bne reg1_error_loopf \n"
\r
307 " bne reg1_error_loopf \n"
\r
308 " vmov r0, r1, d2 \n"
\r
310 " bne reg1_error_loopf \n"
\r
312 " bne reg1_error_loopf \n"
\r
313 " vmov r0, r1, d3 \n"
\r
315 " bne reg1_error_loopf \n"
\r
317 " bne reg1_error_loopf \n"
\r
318 " vmov r0, r1, d4 \n"
\r
320 " bne reg1_error_loopf \n"
\r
322 " bne reg1_error_loopf \n"
\r
323 " vmov r0, r1, d5 \n"
\r
325 " bne reg1_error_loopf \n"
\r
327 " bne reg1_error_loopf \n"
\r
328 " vmov r0, r1, d6 \n"
\r
330 " bne reg1_error_loopf \n"
\r
332 " bne reg1_error_loopf \n"
\r
333 " vmov r0, r1, d7 \n"
\r
335 " bne reg1_error_loopf \n"
\r
337 " bne reg1_error_loopf \n"
\r
338 " vmov r0, r1, d8 \n"
\r
340 " bne reg1_error_loopf \n"
\r
342 " bne reg1_error_loopf \n"
\r
343 " vmov r0, r1, d9 \n"
\r
345 " bne reg1_error_loopf \n"
\r
347 " bne reg1_error_loopf \n"
\r
348 " vmov r0, r1, d10 \n"
\r
350 " bne reg1_error_loopf \n"
\r
352 " bne reg1_error_loopf \n"
\r
353 " vmov r0, r1, d11 \n"
\r
355 " bne reg1_error_loopf \n"
\r
357 " bne reg1_error_loopf \n"
\r
358 " vmov r0, r1, d12 \n"
\r
360 " bne reg1_error_loopf \n"
\r
362 " bne reg1_error_loopf \n"
\r
363 " vmov r0, r1, d13 \n"
\r
365 " bne reg1_error_loopf \n"
\r
367 " bne reg1_error_loopf \n"
\r
368 " vmov r0, r1, d14 \n"
\r
370 " bne reg1_error_loopf \n"
\r
372 " bne reg1_error_loopf \n"
\r
373 " vmov r0, r1, d15 \n"
\r
375 " bne reg1_error_loopf \n"
\r
377 " bne reg1_error_loopf \n"
\r
379 " /* Restore the registers that were clobbered by the test. */\n"
\r
382 " /* VFP register test passed. Jump to the core register test. */\n"
\r
383 " b reg1_loopf_pass \n"
\r
385 "reg1_error_loopf: \n"
\r
386 " /* If this line is hit then a VFP register value was found to be\n"
\r
387 " incorrect. */ \n"
\r
388 " b reg1_error_loopf \n"
\r
390 "reg1_loopf_pass: \n"
\r
393 " bne reg1_error_loop \n"
\r
395 " bne reg1_error_loop \n"
\r
397 " bne reg1_error_loop \n"
\r
399 " bne reg1_error_loop \n"
\r
401 " bne reg1_error_loop \n"
\r
403 " bne reg1_error_loop \n"
\r
405 " bne reg1_error_loop \n"
\r
407 " bne reg1_error_loop \n"
\r
409 " bne reg1_error_loop \n"
\r
411 " bne reg1_error_loop \n"
\r
412 " cmp r10, #110 \n"
\r
413 " bne reg1_error_loop \n"
\r
414 " cmp r11, #111 \n"
\r
415 " bne reg1_error_loop \n"
\r
416 " cmp r12, #112 \n"
\r
417 " bne reg1_error_loop \n"
\r
419 " /* Everything passed, increment the loop counter. */ \n"
\r
420 " push { r0-r1 } \n"
\r
421 " ldr r0, =ulRegTest1LoopCounter \n"
\r
423 " adds r1, r1, #1 \n"
\r
425 " pop { r0-r1 } \n"
\r
427 " /* Start again. */ \n"
\r
430 "reg1_error_loop: \n"
\r
431 " /* If this line is hit then there was an error in a core register value.\n"
\r
432 " The loop ensures the loop counter stops incrementing. */\n"
\r
433 " b reg1_error_loop \n"
\r
437 /*-----------------------------------------------------------*/
\r
439 /* This is a naked function. */
\r
440 static void prvRegTest2Task( void *pvParameters )
\r
444 " /* Set all the core registers to known values. */ \n"
\r
459 " /* Set all the VFP to known values. */ \n"
\r
460 " vmov d0, r0, r1 \n"
\r
461 " vmov d1, r2, r3 \n"
\r
462 " vmov d2, r4, r5 \n"
\r
463 " vmov d3, r6, r7 \n"
\r
464 " vmov d4, r8, r9 \n"
\r
465 " vmov d5, r10, r11 \n"
\r
466 " vmov d6, r0, r1 \n"
\r
467 " vmov d7, r2, r3 \n"
\r
468 " vmov d8, r4, r5 \n"
\r
469 " vmov d9, r6, r7 \n"
\r
470 " vmov d10, r8, r9 \n"
\r
471 " vmov d11, r10, r11 \n"
\r
472 " vmov d12, r0, r1 \n"
\r
473 " vmov d13, r2, r3 \n"
\r
474 " vmov d14, r4, r5 \n"
\r
475 " vmov d15, r6, r7 \n"
\r
479 " /* Check all the VFP registers still contain the values set above.\n"
\r
480 " First save registers that are clobbered by the test. */ \n"
\r
481 " push { r0-r1 } \n"
\r
483 " vmov r0, r1, d0 \n"
\r
485 " bne reg2_error_loopf \n"
\r
487 " bne reg2_error_loopf \n"
\r
488 " vmov r0, r1, d1 \n"
\r
490 " bne reg2_error_loopf \n"
\r
492 " bne reg2_error_loopf \n"
\r
493 " vmov r0, r1, d2 \n"
\r
495 " bne reg2_error_loopf \n"
\r
497 " bne reg2_error_loopf \n"
\r
498 " vmov r0, r1, d3 \n"
\r
500 " bne reg2_error_loopf \n"
\r
502 " bne reg2_error_loopf \n"
\r
503 " vmov r0, r1, d4 \n"
\r
505 " bne reg2_error_loopf \n"
\r
507 " bne reg2_error_loopf \n"
\r
508 " vmov r0, r1, d5 \n"
\r
510 " bne reg2_error_loopf \n"
\r
512 " bne reg2_error_loopf \n"
\r
513 " vmov r0, r1, d6 \n"
\r
515 " bne reg2_error_loopf \n"
\r
517 " bne reg2_error_loopf \n"
\r
518 " vmov r0, r1, d7 \n"
\r
520 " bne reg2_error_loopf \n"
\r
522 " bne reg2_error_loopf \n"
\r
523 " vmov r0, r1, d8 \n"
\r
525 " bne reg2_error_loopf \n"
\r
527 " bne reg2_error_loopf \n"
\r
528 " vmov r0, r1, d9 \n"
\r
530 " bne reg2_error_loopf \n"
\r
532 " bne reg2_error_loopf \n"
\r
533 " vmov r0, r1, d10 \n"
\r
535 " bne reg2_error_loopf \n"
\r
537 " bne reg2_error_loopf \n"
\r
538 " vmov r0, r1, d11 \n"
\r
540 " bne reg2_error_loopf \n"
\r
542 " bne reg2_error_loopf \n"
\r
543 " vmov r0, r1, d12 \n"
\r
545 " bne reg2_error_loopf \n"
\r
547 " bne reg2_error_loopf \n"
\r
548 " vmov r0, r1, d13 \n"
\r
550 " bne reg2_error_loopf \n"
\r
552 " bne reg2_error_loopf \n"
\r
553 " vmov r0, r1, d14 \n"
\r
555 " bne reg2_error_loopf \n"
\r
557 " bne reg2_error_loopf \n"
\r
558 " vmov r0, r1, d15 \n"
\r
560 " bne reg2_error_loopf \n"
\r
562 " bne reg2_error_loopf \n"
\r
564 " /* Restore the registers that were clobbered by the test. */\n"
\r
567 " /* VFP register test passed. Jump to the core register test. */\n"
\r
568 " b reg2_loopf_pass \n"
\r
570 "reg2_error_loopf: \n"
\r
571 " /* If this line is hit then a VFP register value was found to be\n"
\r
572 " incorrect. */ \n"
\r
573 " b reg2_error_loopf \n"
\r
575 "reg2_loopf_pass: \n"
\r
578 " bne reg2_error_loop \n"
\r
580 " bne reg2_error_loop \n"
\r
582 " bne reg2_error_loop \n"
\r
584 " bne reg2_error_loop \n"
\r
586 " bne reg2_error_loop \n"
\r
588 " bne reg2_error_loop \n"
\r
590 " bne reg2_error_loop \n"
\r
592 " bne reg2_error_loop \n"
\r
594 " bne reg2_error_loop \n"
\r
596 " bne reg2_error_loop \n"
\r
598 " bne reg2_error_loop \n"
\r
600 " bne reg2_error_loop \n"
\r
602 " bne reg2_error_loop \n"
\r
604 " /* Increment the loop counter to indicate this test is still functioning\n"
\r
605 " correctly. */ \n"
\r
606 " push { r0-r1 } \n"
\r
607 " ldr r0, =ulRegTest2LoopCounter \n"
\r
609 " adds r1, r1, #1 \n"
\r
612 " /* Yield to increase test coverage. */ \n"
\r
613 " movs r0, #0x01 \n"
\r
614 " ldr r1, =0xe000ed04 \n" /*NVIC_INT_CTRL */
\r
615 " lsl r0, #28 \n" /* Shift to PendSV bit */
\r
618 " pop { r0-r1 } \n"
\r
620 " /* Start again. */ \n"
\r
623 "reg2_error_loop: \n"
\r
624 " /* If this line is hit then there was an error in a core register value.\n"
\r
625 " This loop ensures the loop counter variable stops incrementing. */\n"
\r
626 " b reg2_error_loop \n"
\r