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 /* FreeRTOS includes. */
\r
30 #include "FreeRTOS.h"
\r
35 * "Reg test" tasks - These fill the registers with known values, then check
\r
36 * that each register maintains its expected value for the lifetime of the
\r
37 * task. Each task uses a different set of values. The reg test tasks execute
\r
38 * with a very low priority, so get preempted very frequently. A register
\r
39 * containing an unexpected value is indicative of an error in the context
\r
40 * switching mechanism.
\r
43 void vRegTest1Implementation( void *pvParameters );
\r
44 void vRegTest2Implementation( void *pvParameters );
\r
45 void vRegTest3Implementation( void );
\r
46 void vRegTest4Implementation( void );
\r
49 * Used as an easy way of deleting a task from inline assembly.
\r
51 extern void vMainDeleteMe( void ) __attribute__((noinline));
\r
54 * Used by the first two reg test tasks and a software timer callback function
\r
55 * to send messages to the check task. The message just lets the check task
\r
56 * know that the tasks and timer are still functioning correctly. If a reg test
\r
57 * task detects an error it will delete itself, and in so doing prevent itself
\r
58 * from sending any more 'I'm Alive' messages to the check task.
\r
60 extern void vMainSendImAlive( QueueHandle_t xHandle, uint32_t ulTaskNumber );
\r
62 /* The queue used to send a message to the check task. */
\r
63 extern QueueHandle_t xGlobalScopeCheckQueue;
\r
65 /*-----------------------------------------------------------*/
\r
67 void vRegTest1Implementation( void *pvParameters )
\r
69 /* This task is created in privileged mode so can access the file scope
\r
70 queue variable. Take a stack copy of this before the task is set into user
\r
71 mode. Once this task is in user mode the file scope queue variable will no
\r
72 longer be accessible but the stack copy will. */
\r
73 QueueHandle_t xQueue = xGlobalScopeCheckQueue;
\r
74 const TickType_t xDelayTime = pdMS_TO_TICKS( 100UL );
\r
76 /* Now the queue handle has been obtained the task can switch to user
\r
77 mode. This is just one method of passing a handle into a protected
\r
78 task, the other reg test task uses the task parameter instead. */
\r
79 portSWITCH_TO_USER_MODE();
\r
81 /* First check that the parameter value is as expected. */
\r
82 if( pvParameters != ( void * ) configREG_TEST_TASK_1_PARAMETER )
\r
84 /* Error detected. Delete the task so it stops communicating with
\r
91 #if defined ( __GNUC__ )
\r
93 /* This task tests the kernel context switch mechanism by reading and
\r
94 writing directly to registers - which requires the test to be written
\r
95 in assembly code. */
\r
98 " MOV R4, #104 \n" /* Set registers to a known value. R0 to R1 are done in the loop below. */
\r
103 " MOV R10, #110 \n"
\r
104 " MOV R11, #111 \n"
\r
106 " MOV R0, #100 \n" /* Set the scratch registers to known values - done inside the loop as they get clobbered. */
\r
110 " MOV R12, #112 \n"
\r
111 " SVC #1 \n" /* Yield just to increase test coverage. */
\r
112 " CMP R0, #100 \n" /* Check all the registers still contain their expected values. */
\r
113 " BNE vMainDeleteMe \n" /* Value was not as expected, delete the task so it stops communicating with the check task. */
\r
115 " BNE vMainDeleteMe \n"
\r
117 " BNE vMainDeleteMe \n"
\r
119 " BNE vMainDeleteMe \n"
\r
121 " BNE vMainDeleteMe \n"
\r
123 " BNE vMainDeleteMe \n"
\r
125 " BNE vMainDeleteMe \n"
\r
127 " BNE vMainDeleteMe \n"
\r
129 " BNE vMainDeleteMe \n"
\r
130 " CMP R10, #110 \n"
\r
131 " BNE vMainDeleteMe \n"
\r
132 " CMP R11, #111 \n"
\r
133 " BNE vMainDeleteMe \n"
\r
134 " CMP R12, #112 \n"
\r
135 " BNE vMainDeleteMe \n"
\r
136 :::"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r8", "r9", "r10", "r11", "r12"
\r
139 #endif /* __GNUC__ */
\r
141 /* Send configREG_TEST_1_STILL_EXECUTING to the check task to indicate that this
\r
142 task is still functioning. */
\r
143 vMainSendImAlive( xQueue, configREG_TEST_1_STILL_EXECUTING );
\r
144 vTaskDelay( xDelayTime );
\r
146 #if defined ( __GNUC__ )
\r
148 /* Go back to check all the register values again. */
\r
149 __asm volatile( " B reg1loop " );
\r
151 #endif /* __GNUC__ */
\r
154 /*-----------------------------------------------------------*/
\r
156 void vRegTest2Implementation( void *pvParameters )
\r
158 /* The queue handle is passed in as the task parameter. This is one method of
\r
159 passing data into a protected task, the other reg test task uses a different
\r
161 QueueHandle_t xQueue = ( QueueHandle_t ) pvParameters;
\r
162 const TickType_t xDelayTime = pdMS_TO_TICKS( 100UL );
\r
166 #if defined ( __GNUC__ )
\r
168 /* This task tests the kernel context switch mechanism by reading and
\r
169 writing directly to registers - which requires the test to be written
\r
170 in assembly code. */
\r
173 " MOV R4, #4 \n" /* Set registers to a known value. R0 to R1 are done in the loop below. */
\r
176 " MOV R8, #8 \n" /* Frame pointer is omitted as it must not be changed. */
\r
181 " MOV R0, #13 \n" /* Set the scratch registers to known values - done inside the loop as they get clobbered. */
\r
186 " CMP R0, #13 \n" /* Check all the registers still contain their expected values. */
\r
187 " BNE vMainDeleteMe \n" /* Value was not as expected, delete the task so it stops communicating with the check task */
\r
189 " BNE vMainDeleteMe \n"
\r
191 " BNE vMainDeleteMe \n"
\r
193 " BNE vMainDeleteMe \n"
\r
195 " BNE vMainDeleteMe \n"
\r
197 " BNE vMainDeleteMe \n"
\r
199 " BNE vMainDeleteMe \n"
\r
201 " BNE vMainDeleteMe \n"
\r
203 " BNE vMainDeleteMe \n"
\r
205 " BNE vMainDeleteMe \n"
\r
207 " BNE vMainDeleteMe \n"
\r
209 " BNE vMainDeleteMe \n"
\r
210 :::"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r8", "r9", "r10", "r11", "r12"
\r
213 #endif /* __GNUC__ */
\r
215 /* Send configREG_TEST_2_STILL_EXECUTING to the check task to indicate
\r
216 that this task is still functioning. */
\r
217 vMainSendImAlive( xQueue, configREG_TEST_2_STILL_EXECUTING );
\r
218 vTaskDelay( xDelayTime );
\r
220 #if defined ( __GNUC__ )
\r
222 /* Go back to check all the register values again. */
\r
223 __asm volatile( " B reg2loop " );
\r
225 #endif /* __GNUC__ */
\r
228 /*-----------------------------------------------------------*/
\r
230 __asm void vRegTest3Implementation( void )
\r
232 extern pulRegTest3LoopCounter
\r
236 /* Fill the core registers with known values. */
\r
251 /* Fill the VFP registers with known values. */
\r
271 /* Check all the VFP registers still contain the values set above.
\r
272 First save registers that are clobbered by the test. */
\r
277 bne reg1_error_loopf
\r
279 bne reg1_error_loopf
\r
282 bne reg1_error_loopf
\r
284 bne reg1_error_loopf
\r
287 bne reg1_error_loopf
\r
289 bne reg1_error_loopf
\r
292 bne reg1_error_loopf
\r
294 bne reg1_error_loopf
\r
297 bne reg1_error_loopf
\r
299 bne reg1_error_loopf
\r
302 bne reg1_error_loopf
\r
304 bne reg1_error_loopf
\r
307 bne reg1_error_loopf
\r
309 bne reg1_error_loopf
\r
312 bne reg1_error_loopf
\r
314 bne reg1_error_loopf
\r
317 bne reg1_error_loopf
\r
319 bne reg1_error_loopf
\r
322 bne reg1_error_loopf
\r
324 bne reg1_error_loopf
\r
327 bne reg1_error_loopf
\r
329 bne reg1_error_loopf
\r
332 bne reg1_error_loopf
\r
334 bne reg1_error_loopf
\r
337 bne reg1_error_loopf
\r
339 bne reg1_error_loopf
\r
342 bne reg1_error_loopf
\r
344 bne reg1_error_loopf
\r
347 bne reg1_error_loopf
\r
349 bne reg1_error_loopf
\r
352 bne reg1_error_loopf
\r
354 bne reg1_error_loopf
\r
356 /* Restore the registers that were clobbered by the test. */
\r
359 /* VFP register test passed. Jump to the core register test. */
\r
363 /* If this line is hit then a VFP register value was found to be incorrect. */
\r
369 bne reg1_error_loop
\r
371 bne reg1_error_loop
\r
373 bne reg1_error_loop
\r
375 bne reg1_error_loop
\r
377 bne reg1_error_loop
\r
379 bne reg1_error_loop
\r
381 bne reg1_error_loop
\r
383 bne reg1_error_loop
\r
385 bne reg1_error_loop
\r
387 bne reg1_error_loop
\r
389 bne reg1_error_loop
\r
391 bne reg1_error_loop
\r
393 bne reg1_error_loop
\r
395 /* Everything passed, increment the loop counter. */
\r
397 ldr r0, =pulRegTest3LoopCounter
\r
408 /* If this line is hit then there was an error in a core register value.
\r
409 The loop ensures the loop counter stops incrementing. */
\r
414 /*-----------------------------------------------------------*/
\r
416 __asm void vRegTest4Implementation( void )
\r
418 extern pulRegTest4LoopCounter;
\r
422 /* Set all the core registers to known values. */
\r
437 /* Set all the VFP to known values. */
\r
457 /* Check all the VFP registers still contain the values set above.
\r
458 First save registers that are clobbered by the test. */
\r
463 bne reg2_error_loopf
\r
465 bne reg2_error_loopf
\r
468 bne reg2_error_loopf
\r
470 bne reg2_error_loopf
\r
473 bne reg2_error_loopf
\r
475 bne reg2_error_loopf
\r
478 bne reg2_error_loopf
\r
480 bne reg2_error_loopf
\r
483 bne reg2_error_loopf
\r
485 bne reg2_error_loopf
\r
488 bne reg2_error_loopf
\r
490 bne reg2_error_loopf
\r
493 bne reg2_error_loopf
\r
495 bne reg2_error_loopf
\r
498 bne reg2_error_loopf
\r
500 bne reg2_error_loopf
\r
503 bne reg2_error_loopf
\r
505 bne reg2_error_loopf
\r
508 bne reg2_error_loopf
\r
510 bne reg2_error_loopf
\r
513 bne reg2_error_loopf
\r
515 bne reg2_error_loopf
\r
518 bne reg2_error_loopf
\r
520 bne reg2_error_loopf
\r
523 bne reg2_error_loopf
\r
525 bne reg2_error_loopf
\r
528 bne reg2_error_loopf
\r
530 bne reg2_error_loopf
\r
533 bne reg2_error_loopf
\r
535 bne reg2_error_loopf
\r
538 bne reg2_error_loopf
\r
540 bne reg2_error_loopf
\r
542 /* Restore the registers that were clobbered by the test. */
\r
545 /* VFP register test passed. Jump to the core register test. */
\r
549 /* If this line is hit then a VFP register value was found to be
\r
556 bne reg2_error_loop
\r
558 bne reg2_error_loop
\r
560 bne reg2_error_loop
\r
562 bne reg2_error_loop
\r
564 bne reg2_error_loop
\r
566 bne reg2_error_loop
\r
568 bne reg2_error_loop
\r
570 bne reg2_error_loop
\r
572 bne reg2_error_loop
\r
574 bne reg2_error_loop
\r
576 bne reg2_error_loop
\r
578 bne reg2_error_loop
\r
580 bne reg2_error_loop
\r
582 /* Increment the loop counter so the check task knows this task is
\r
585 ldr r0, =pulRegTest4LoopCounter
\r
592 /* Yield to increase test coverage. */
\r
599 /* If this line is hit then there was an error in a core register value.
\r
600 This loop ensures the loop counter variable stops incrementing. */
\r
604 /*-----------------------------------------------------------*/
\r
606 /* Fault handlers are here for convenience as they use compiler specific syntax
\r
607 and this file is specific to the Keil compiler. */
\r
608 void hard_fault_handler( uint32_t * hardfault_args )
\r
610 volatile uint32_t stacked_r0;
\r
611 volatile uint32_t stacked_r1;
\r
612 volatile uint32_t stacked_r2;
\r
613 volatile uint32_t stacked_r3;
\r
614 volatile uint32_t stacked_r12;
\r
615 volatile uint32_t stacked_lr;
\r
616 volatile uint32_t stacked_pc;
\r
617 volatile uint32_t stacked_psr;
\r
619 stacked_r0 = ((uint32_t) hardfault_args[ 0 ]);
\r
620 stacked_r1 = ((uint32_t) hardfault_args[ 1 ]);
\r
621 stacked_r2 = ((uint32_t) hardfault_args[ 2 ]);
\r
622 stacked_r3 = ((uint32_t) hardfault_args[ 3 ]);
\r
624 stacked_r12 = ((uint32_t) hardfault_args[ 4 ]);
\r
625 stacked_lr = ((uint32_t) hardfault_args[ 5 ]);
\r
626 stacked_pc = ((uint32_t) hardfault_args[ 6 ]);
\r
627 stacked_psr = ((uint32_t) hardfault_args[ 7 ]);
\r
629 /* Inspect stacked_pc to locate the offending instruction. */
\r
632 /*-----------------------------------------------------------*/
\r
634 void HardFault_Handler( void );
\r
635 __asm void HardFault_Handler( void )
\r
637 extern hard_fault_handler
\r
644 ldr r2, hard_fault_handler
\r
647 /*-----------------------------------------------------------*/
\r
649 void MemManage_Handler( void );
\r
650 __asm void MemManage_Handler( void )
\r
652 extern hard_fault_handler
\r
659 ldr r2, hard_fault_handler
\r
662 /*-----------------------------------------------------------*/
\r