2 * FreeRTOS Kernel V10.1.1
\r
3 * Copyright (C) 2018 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 /* FreeRTOS includes. */
\r
29 #include "FreeRTOS.h"
\r
34 * "Reg test" tasks - These fill the registers with known values, then check
\r
35 * that each register maintains its expected value for the lifetime of the
\r
36 * task. Each task uses a different set of values. The reg test tasks execute
\r
37 * with a very low priority, so get preempted very frequently. A register
\r
38 * containing an unexpected value is indicative of an error in the context
\r
39 * switching mechanism.
\r
42 void vRegTest1Implementation( void *pvParameters );
\r
43 void vRegTest2Implementation( void *pvParameters );
\r
44 void vRegTest3Implementation( void );
\r
45 void vRegTest4Implementation( void );
\r
48 * Used as an easy way of deleting a task from inline assembly.
\r
50 extern void vMainDeleteMe( void ) __attribute__((noinline));
\r
53 * Used by the first two reg test tasks and a software timer callback function
\r
54 * to send messages to the check task. The message just lets the check task
\r
55 * know that the tasks and timer are still functioning correctly. If a reg test
\r
56 * task detects an error it will delete itself, and in so doing prevent itself
\r
57 * from sending any more 'I'm Alive' messages to the check task.
\r
59 extern void vMainSendImAlive( QueueHandle_t xHandle, uint32_t ulTaskNumber );
\r
61 /* The queue used to send a message to the check task. */
\r
62 extern QueueHandle_t xGlobalScopeCheckQueue;
\r
64 /*-----------------------------------------------------------*/
\r
66 void vRegTest1Implementation( void *pvParameters )
\r
68 /* This task is created in privileged mode so can access the file scope
\r
69 queue variable. Take a stack copy of this before the task is set into user
\r
70 mode. Once this task is in user mode the file scope queue variable will no
\r
71 longer be accessible but the stack copy will. */
\r
72 QueueHandle_t xQueue = xGlobalScopeCheckQueue;
\r
73 const TickType_t xDelayTime = pdMS_TO_TICKS( 100UL );
\r
75 /* Now the queue handle has been obtained the task can switch to user
\r
76 mode. This is just one method of passing a handle into a protected
\r
77 task, the other reg test task uses the task parameter instead. */
\r
78 portSWITCH_TO_USER_MODE();
\r
80 /* First check that the parameter value is as expected. */
\r
81 if( pvParameters != ( void * ) configREG_TEST_TASK_1_PARAMETER )
\r
83 /* Error detected. Delete the task so it stops communicating with
\r
90 #if defined ( __GNUC__ )
\r
92 /* This task tests the kernel context switch mechanism by reading and
\r
93 writing directly to registers - which requires the test to be written
\r
94 in assembly code. */
\r
97 " MOV R4, #104 \n" /* Set registers to a known value. R0 to R1 are done in the loop below. */
\r
102 " MOV R10, #110 \n"
\r
103 " MOV R11, #111 \n"
\r
105 " MOV R0, #100 \n" /* Set the scratch registers to known values - done inside the loop as they get clobbered. */
\r
109 " MOV R12, #112 \n"
\r
110 " SVC #1 \n" /* Yield just to increase test coverage. */
\r
111 " CMP R0, #100 \n" /* Check all the registers still contain their expected values. */
\r
112 " BNE vMainDeleteMe \n" /* Value was not as expected, delete the task so it stops communicating with the check task. */
\r
114 " BNE vMainDeleteMe \n"
\r
116 " BNE vMainDeleteMe \n"
\r
118 " BNE vMainDeleteMe \n"
\r
120 " BNE vMainDeleteMe \n"
\r
122 " BNE vMainDeleteMe \n"
\r
124 " BNE vMainDeleteMe \n"
\r
126 " BNE vMainDeleteMe \n"
\r
128 " BNE vMainDeleteMe \n"
\r
129 " CMP R10, #110 \n"
\r
130 " BNE vMainDeleteMe \n"
\r
131 " CMP R11, #111 \n"
\r
132 " BNE vMainDeleteMe \n"
\r
133 " CMP R12, #112 \n"
\r
134 " BNE vMainDeleteMe \n"
\r
135 :::"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r8", "r9", "r10", "r11", "r12"
\r
138 #endif /* __GNUC__ */
\r
140 /* Send configREG_TEST_1_STILL_EXECUTING to the check task to indicate that this
\r
141 task is still functioning. */
\r
142 vMainSendImAlive( xQueue, configREG_TEST_1_STILL_EXECUTING );
\r
143 vTaskDelay( xDelayTime );
\r
145 #if defined ( __GNUC__ )
\r
147 /* Go back to check all the register values again. */
\r
148 __asm volatile( " B reg1loop " );
\r
150 #endif /* __GNUC__ */
\r
153 /*-----------------------------------------------------------*/
\r
155 void vRegTest2Implementation( void *pvParameters )
\r
157 /* The queue handle is passed in as the task parameter. This is one method of
\r
158 passing data into a protected task, the other reg test task uses a different
\r
160 QueueHandle_t xQueue = ( QueueHandle_t ) pvParameters;
\r
161 const TickType_t xDelayTime = pdMS_TO_TICKS( 100UL );
\r
165 #if defined ( __GNUC__ )
\r
167 /* This task tests the kernel context switch mechanism by reading and
\r
168 writing directly to registers - which requires the test to be written
\r
169 in assembly code. */
\r
172 " MOV R4, #4 \n" /* Set registers to a known value. R0 to R1 are done in the loop below. */
\r
175 " MOV R8, #8 \n" /* Frame pointer is omitted as it must not be changed. */
\r
180 " MOV R0, #13 \n" /* Set the scratch registers to known values - done inside the loop as they get clobbered. */
\r
185 " CMP R0, #13 \n" /* Check all the registers still contain their expected values. */
\r
186 " BNE vMainDeleteMe \n" /* Value was not as expected, delete the task so it stops communicating with the check task */
\r
188 " BNE vMainDeleteMe \n"
\r
190 " BNE vMainDeleteMe \n"
\r
192 " BNE vMainDeleteMe \n"
\r
194 " BNE vMainDeleteMe \n"
\r
196 " BNE vMainDeleteMe \n"
\r
198 " BNE vMainDeleteMe \n"
\r
200 " BNE vMainDeleteMe \n"
\r
202 " BNE vMainDeleteMe \n"
\r
204 " BNE vMainDeleteMe \n"
\r
206 " BNE vMainDeleteMe \n"
\r
208 " BNE vMainDeleteMe \n"
\r
209 :::"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r8", "r9", "r10", "r11", "r12"
\r
212 #endif /* __GNUC__ */
\r
214 /* Send configREG_TEST_2_STILL_EXECUTING to the check task to indicate
\r
215 that this task is still functioning. */
\r
216 vMainSendImAlive( xQueue, configREG_TEST_2_STILL_EXECUTING );
\r
217 vTaskDelay( xDelayTime );
\r
219 #if defined ( __GNUC__ )
\r
221 /* Go back to check all the register values again. */
\r
222 __asm volatile( " B reg2loop " );
\r
224 #endif /* __GNUC__ */
\r
227 /*-----------------------------------------------------------*/
\r
229 __asm void vRegTest3Implementation( void )
\r
231 extern pulRegTest3LoopCounter
\r
235 /* Fill the core registers with known values. */
\r
250 /* Fill the VFP registers with known values. */
\r
270 /* Check all the VFP registers still contain the values set above.
\r
271 First save registers that are clobbered by the test. */
\r
276 bne reg1_error_loopf
\r
278 bne reg1_error_loopf
\r
281 bne reg1_error_loopf
\r
283 bne reg1_error_loopf
\r
286 bne reg1_error_loopf
\r
288 bne reg1_error_loopf
\r
291 bne reg1_error_loopf
\r
293 bne reg1_error_loopf
\r
296 bne reg1_error_loopf
\r
298 bne reg1_error_loopf
\r
301 bne reg1_error_loopf
\r
303 bne reg1_error_loopf
\r
306 bne reg1_error_loopf
\r
308 bne reg1_error_loopf
\r
311 bne reg1_error_loopf
\r
313 bne reg1_error_loopf
\r
316 bne reg1_error_loopf
\r
318 bne reg1_error_loopf
\r
321 bne reg1_error_loopf
\r
323 bne reg1_error_loopf
\r
326 bne reg1_error_loopf
\r
328 bne reg1_error_loopf
\r
331 bne reg1_error_loopf
\r
333 bne reg1_error_loopf
\r
336 bne reg1_error_loopf
\r
338 bne reg1_error_loopf
\r
341 bne reg1_error_loopf
\r
343 bne reg1_error_loopf
\r
346 bne reg1_error_loopf
\r
348 bne reg1_error_loopf
\r
351 bne reg1_error_loopf
\r
353 bne reg1_error_loopf
\r
355 /* Restore the registers that were clobbered by the test. */
\r
358 /* VFP register test passed. Jump to the core register test. */
\r
362 /* If this line is hit then a VFP register value was found to be incorrect. */
\r
368 bne reg1_error_loop
\r
370 bne reg1_error_loop
\r
372 bne reg1_error_loop
\r
374 bne reg1_error_loop
\r
376 bne reg1_error_loop
\r
378 bne reg1_error_loop
\r
380 bne reg1_error_loop
\r
382 bne reg1_error_loop
\r
384 bne reg1_error_loop
\r
386 bne reg1_error_loop
\r
388 bne reg1_error_loop
\r
390 bne reg1_error_loop
\r
392 bne reg1_error_loop
\r
394 /* Everything passed, increment the loop counter. */
\r
396 ldr r0, =pulRegTest3LoopCounter
\r
407 /* If this line is hit then there was an error in a core register value.
\r
408 The loop ensures the loop counter stops incrementing. */
\r
413 /*-----------------------------------------------------------*/
\r
415 __asm void vRegTest4Implementation( void )
\r
417 extern pulRegTest4LoopCounter;
\r
421 /* Set all the core registers to known values. */
\r
436 /* Set all the VFP to known values. */
\r
456 /* Check all the VFP registers still contain the values set above.
\r
457 First save registers that are clobbered by the test. */
\r
462 bne reg2_error_loopf
\r
464 bne reg2_error_loopf
\r
467 bne reg2_error_loopf
\r
469 bne reg2_error_loopf
\r
472 bne reg2_error_loopf
\r
474 bne reg2_error_loopf
\r
477 bne reg2_error_loopf
\r
479 bne reg2_error_loopf
\r
482 bne reg2_error_loopf
\r
484 bne reg2_error_loopf
\r
487 bne reg2_error_loopf
\r
489 bne reg2_error_loopf
\r
492 bne reg2_error_loopf
\r
494 bne reg2_error_loopf
\r
497 bne reg2_error_loopf
\r
499 bne reg2_error_loopf
\r
502 bne reg2_error_loopf
\r
504 bne reg2_error_loopf
\r
507 bne reg2_error_loopf
\r
509 bne reg2_error_loopf
\r
512 bne reg2_error_loopf
\r
514 bne reg2_error_loopf
\r
517 bne reg2_error_loopf
\r
519 bne reg2_error_loopf
\r
522 bne reg2_error_loopf
\r
524 bne reg2_error_loopf
\r
527 bne reg2_error_loopf
\r
529 bne reg2_error_loopf
\r
532 bne reg2_error_loopf
\r
534 bne reg2_error_loopf
\r
537 bne reg2_error_loopf
\r
539 bne reg2_error_loopf
\r
541 /* Restore the registers that were clobbered by the test. */
\r
544 /* VFP register test passed. Jump to the core register test. */
\r
548 /* If this line is hit then a VFP register value was found to be
\r
555 bne reg2_error_loop
\r
557 bne reg2_error_loop
\r
559 bne reg2_error_loop
\r
561 bne reg2_error_loop
\r
563 bne reg2_error_loop
\r
565 bne reg2_error_loop
\r
567 bne reg2_error_loop
\r
569 bne reg2_error_loop
\r
571 bne reg2_error_loop
\r
573 bne reg2_error_loop
\r
575 bne reg2_error_loop
\r
577 bne reg2_error_loop
\r
579 bne reg2_error_loop
\r
581 /* Increment the loop counter so the check task knows this task is
\r
584 ldr r0, =pulRegTest4LoopCounter
\r
591 /* Yield to increase test coverage. */
\r
598 /* If this line is hit then there was an error in a core register value.
\r
599 This loop ensures the loop counter variable stops incrementing. */
\r
603 /*-----------------------------------------------------------*/
\r
605 /* Fault handlers are here for convenience as they use compiler specific syntax
\r
606 and this file is specific to the Keil compiler. */
\r
607 void hard_fault_handler( uint32_t * hardfault_args )
\r
609 volatile uint32_t stacked_r0;
\r
610 volatile uint32_t stacked_r1;
\r
611 volatile uint32_t stacked_r2;
\r
612 volatile uint32_t stacked_r3;
\r
613 volatile uint32_t stacked_r12;
\r
614 volatile uint32_t stacked_lr;
\r
615 volatile uint32_t stacked_pc;
\r
616 volatile uint32_t stacked_psr;
\r
618 stacked_r0 = ((uint32_t) hardfault_args[ 0 ]);
\r
619 stacked_r1 = ((uint32_t) hardfault_args[ 1 ]);
\r
620 stacked_r2 = ((uint32_t) hardfault_args[ 2 ]);
\r
621 stacked_r3 = ((uint32_t) hardfault_args[ 3 ]);
\r
623 stacked_r12 = ((uint32_t) hardfault_args[ 4 ]);
\r
624 stacked_lr = ((uint32_t) hardfault_args[ 5 ]);
\r
625 stacked_pc = ((uint32_t) hardfault_args[ 6 ]);
\r
626 stacked_psr = ((uint32_t) hardfault_args[ 7 ]);
\r
628 /* Inspect stacked_pc to locate the offending instruction. */
\r
631 /*-----------------------------------------------------------*/
\r
633 void HardFault_Handler( void );
\r
634 __asm void HardFault_Handler( void )
\r
636 extern hard_fault_handler
\r
643 ldr r2, hard_fault_handler
\r
646 /*-----------------------------------------------------------*/
\r
648 void MemManage_Handler( void );
\r
649 __asm void MemManage_Handler( void )
\r
651 extern hard_fault_handler
\r
658 ldr r2, hard_fault_handler
\r
661 /*-----------------------------------------------------------*/
\r