2 FreeRTOS V9.0.0 - Copyright (C) 2015 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
70 /* FreeRTOS includes. */
\r
71 #include "FreeRTOS.h"
\r
76 * "Reg test" tasks - These fill the registers with known values, then check
\r
77 * that each register maintains its expected value for the lifetime of the
\r
78 * task. Each task uses a different set of values. The reg test tasks execute
\r
79 * with a very low priority, so get preempted very frequently. A register
\r
80 * containing an unexpected value is indicative of an error in the context
\r
81 * switching mechanism.
\r
84 void vRegTest1Implementation( void *pvParameters );
\r
85 void vRegTest2Implementation( void *pvParameters );
\r
86 void vRegTest3Implementation( void );
\r
87 void vRegTest4Implementation( void );
\r
90 * Used as an easy way of deleting a task from inline assembly.
\r
92 extern void vMainDeleteMe( void ) __attribute__((noinline));
\r
95 * Used by the first two reg test tasks and a software timer callback function
\r
96 * to send messages to the check task. The message just lets the check task
\r
97 * know that the tasks and timer are still functioning correctly. If a reg test
\r
98 * task detects an error it will delete itself, and in so doing prevent itself
\r
99 * from sending any more 'I'm Alive' messages to the check task.
\r
101 extern void vMainSendImAlive( QueueHandle_t xHandle, uint32_t ulTaskNumber );
\r
103 /* The queue used to send a message to the check task. */
\r
104 extern QueueHandle_t xGlobalScopeCheckQueue;
\r
106 /*-----------------------------------------------------------*/
\r
108 void vRegTest1Implementation( void *pvParameters )
\r
110 /* This task is created in privileged mode so can access the file scope
\r
111 queue variable. Take a stack copy of this before the task is set into user
\r
112 mode. Once this task is in user mode the file scope queue variable will no
\r
113 longer be accessible but the stack copy will. */
\r
114 QueueHandle_t xQueue = xGlobalScopeCheckQueue;
\r
115 const TickType_t xDelayTime = pdMS_TO_TICKS( 100UL );
\r
117 /* Now the queue handle has been obtained the task can switch to user
\r
118 mode. This is just one method of passing a handle into a protected
\r
119 task, the other reg test task uses the task parameter instead. */
\r
120 portSWITCH_TO_USER_MODE();
\r
122 /* First check that the parameter value is as expected. */
\r
123 if( pvParameters != ( void * ) configREG_TEST_TASK_1_PARAMETER )
\r
125 /* Error detected. Delete the task so it stops communicating with
\r
132 #if defined ( __GNUC__ )
\r
134 /* This task tests the kernel context switch mechanism by reading and
\r
135 writing directly to registers - which requires the test to be written
\r
136 in assembly code. */
\r
139 " MOV R4, #104 \n" /* Set registers to a known value. R0 to R1 are done in the loop below. */
\r
144 " MOV R10, #110 \n"
\r
145 " MOV R11, #111 \n"
\r
147 " MOV R0, #100 \n" /* Set the scratch registers to known values - done inside the loop as they get clobbered. */
\r
151 " MOV R12, #112 \n"
\r
152 " SVC #1 \n" /* Yield just to increase test coverage. */
\r
153 " CMP R0, #100 \n" /* Check all the registers still contain their expected values. */
\r
154 " BNE vMainDeleteMe \n" /* Value was not as expected, delete the task so it stops communicating with the check task. */
\r
156 " BNE vMainDeleteMe \n"
\r
158 " BNE vMainDeleteMe \n"
\r
160 " BNE vMainDeleteMe \n"
\r
162 " BNE vMainDeleteMe \n"
\r
164 " BNE vMainDeleteMe \n"
\r
166 " BNE vMainDeleteMe \n"
\r
168 " BNE vMainDeleteMe \n"
\r
170 " BNE vMainDeleteMe \n"
\r
171 " CMP R10, #110 \n"
\r
172 " BNE vMainDeleteMe \n"
\r
173 " CMP R11, #111 \n"
\r
174 " BNE vMainDeleteMe \n"
\r
175 " CMP R12, #112 \n"
\r
176 " BNE vMainDeleteMe \n"
\r
177 :::"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r8", "r9", "r10", "r11", "r12"
\r
180 #endif /* __GNUC__ */
\r
182 /* Send configREG_TEST_1_STILL_EXECUTING to the check task to indicate that this
\r
183 task is still functioning. */
\r
184 vMainSendImAlive( xQueue, configREG_TEST_1_STILL_EXECUTING );
\r
185 vTaskDelay( xDelayTime );
\r
187 #if defined ( __GNUC__ )
\r
189 /* Go back to check all the register values again. */
\r
190 __asm volatile( " B reg1loop " );
\r
192 #endif /* __GNUC__ */
\r
195 /*-----------------------------------------------------------*/
\r
197 void vRegTest2Implementation( void *pvParameters )
\r
199 /* The queue handle is passed in as the task parameter. This is one method of
\r
200 passing data into a protected task, the other reg test task uses a different
\r
202 QueueHandle_t xQueue = ( QueueHandle_t ) pvParameters;
\r
203 const TickType_t xDelayTime = pdMS_TO_TICKS( 100UL );
\r
207 #if defined ( __GNUC__ )
\r
209 /* This task tests the kernel context switch mechanism by reading and
\r
210 writing directly to registers - which requires the test to be written
\r
211 in assembly code. */
\r
214 " MOV R4, #4 \n" /* Set registers to a known value. R0 to R1 are done in the loop below. */
\r
217 " MOV R8, #8 \n" /* Frame pointer is omitted as it must not be changed. */
\r
222 " MOV R0, #13 \n" /* Set the scratch registers to known values - done inside the loop as they get clobbered. */
\r
227 " CMP R0, #13 \n" /* Check all the registers still contain their expected values. */
\r
228 " BNE vMainDeleteMe \n" /* Value was not as expected, delete the task so it stops communicating with the check task */
\r
230 " BNE vMainDeleteMe \n"
\r
232 " BNE vMainDeleteMe \n"
\r
234 " BNE vMainDeleteMe \n"
\r
236 " BNE vMainDeleteMe \n"
\r
238 " BNE vMainDeleteMe \n"
\r
240 " BNE vMainDeleteMe \n"
\r
242 " BNE vMainDeleteMe \n"
\r
244 " BNE vMainDeleteMe \n"
\r
246 " BNE vMainDeleteMe \n"
\r
248 " BNE vMainDeleteMe \n"
\r
250 " BNE vMainDeleteMe \n"
\r
251 :::"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r8", "r9", "r10", "r11", "r12"
\r
254 #endif /* __GNUC__ */
\r
256 /* Send configREG_TEST_2_STILL_EXECUTING to the check task to indicate
\r
257 that this task is still functioning. */
\r
258 vMainSendImAlive( xQueue, configREG_TEST_2_STILL_EXECUTING );
\r
259 vTaskDelay( xDelayTime );
\r
261 #if defined ( __GNUC__ )
\r
263 /* Go back to check all the register values again. */
\r
264 __asm volatile( " B reg2loop " );
\r
266 #endif /* __GNUC__ */
\r
269 /*-----------------------------------------------------------*/
\r
271 __asm void vRegTest3Implementation( void )
\r
273 extern pulRegTest3LoopCounter
\r
277 /* Fill the core registers with known values. */
\r
292 /* Fill the VFP registers with known values. */
\r
312 /* Check all the VFP registers still contain the values set above.
\r
313 First save registers that are clobbered by the test. */
\r
318 bne reg1_error_loopf
\r
320 bne reg1_error_loopf
\r
323 bne reg1_error_loopf
\r
325 bne reg1_error_loopf
\r
328 bne reg1_error_loopf
\r
330 bne reg1_error_loopf
\r
333 bne reg1_error_loopf
\r
335 bne reg1_error_loopf
\r
338 bne reg1_error_loopf
\r
340 bne reg1_error_loopf
\r
343 bne reg1_error_loopf
\r
345 bne reg1_error_loopf
\r
348 bne reg1_error_loopf
\r
350 bne reg1_error_loopf
\r
353 bne reg1_error_loopf
\r
355 bne reg1_error_loopf
\r
358 bne reg1_error_loopf
\r
360 bne reg1_error_loopf
\r
363 bne reg1_error_loopf
\r
365 bne reg1_error_loopf
\r
368 bne reg1_error_loopf
\r
370 bne reg1_error_loopf
\r
373 bne reg1_error_loopf
\r
375 bne reg1_error_loopf
\r
378 bne reg1_error_loopf
\r
380 bne reg1_error_loopf
\r
383 bne reg1_error_loopf
\r
385 bne reg1_error_loopf
\r
388 bne reg1_error_loopf
\r
390 bne reg1_error_loopf
\r
393 bne reg1_error_loopf
\r
395 bne reg1_error_loopf
\r
397 /* Restore the registers that were clobbered by the test. */
\r
400 /* VFP register test passed. Jump to the core register test. */
\r
404 /* If this line is hit then a VFP register value was found to be incorrect. */
\r
410 bne reg1_error_loop
\r
412 bne reg1_error_loop
\r
414 bne reg1_error_loop
\r
416 bne reg1_error_loop
\r
418 bne reg1_error_loop
\r
420 bne reg1_error_loop
\r
422 bne reg1_error_loop
\r
424 bne reg1_error_loop
\r
426 bne reg1_error_loop
\r
428 bne reg1_error_loop
\r
430 bne reg1_error_loop
\r
432 bne reg1_error_loop
\r
434 bne reg1_error_loop
\r
436 /* Everything passed, increment the loop counter. */
\r
438 ldr r0, =pulRegTest3LoopCounter
\r
449 /* If this line is hit then there was an error in a core register value.
\r
450 The loop ensures the loop counter stops incrementing. */
\r
455 /*-----------------------------------------------------------*/
\r
457 __asm void vRegTest4Implementation( void )
\r
459 extern pulRegTest4LoopCounter;
\r
463 /* Set all the core registers to known values. */
\r
478 /* Set all the VFP to known values. */
\r
498 /* Check all the VFP registers still contain the values set above.
\r
499 First save registers that are clobbered by the test. */
\r
504 bne reg2_error_loopf
\r
506 bne reg2_error_loopf
\r
509 bne reg2_error_loopf
\r
511 bne reg2_error_loopf
\r
514 bne reg2_error_loopf
\r
516 bne reg2_error_loopf
\r
519 bne reg2_error_loopf
\r
521 bne reg2_error_loopf
\r
524 bne reg2_error_loopf
\r
526 bne reg2_error_loopf
\r
529 bne reg2_error_loopf
\r
531 bne reg2_error_loopf
\r
534 bne reg2_error_loopf
\r
536 bne reg2_error_loopf
\r
539 bne reg2_error_loopf
\r
541 bne reg2_error_loopf
\r
544 bne reg2_error_loopf
\r
546 bne reg2_error_loopf
\r
549 bne reg2_error_loopf
\r
551 bne reg2_error_loopf
\r
554 bne reg2_error_loopf
\r
556 bne reg2_error_loopf
\r
559 bne reg2_error_loopf
\r
561 bne reg2_error_loopf
\r
564 bne reg2_error_loopf
\r
566 bne reg2_error_loopf
\r
569 bne reg2_error_loopf
\r
571 bne reg2_error_loopf
\r
574 bne reg2_error_loopf
\r
576 bne reg2_error_loopf
\r
579 bne reg2_error_loopf
\r
581 bne reg2_error_loopf
\r
583 /* Restore the registers that were clobbered by the test. */
\r
586 /* VFP register test passed. Jump to the core register test. */
\r
590 /* If this line is hit then a VFP register value was found to be
\r
597 bne reg2_error_loop
\r
599 bne reg2_error_loop
\r
601 bne reg2_error_loop
\r
603 bne reg2_error_loop
\r
605 bne reg2_error_loop
\r
607 bne reg2_error_loop
\r
609 bne reg2_error_loop
\r
611 bne reg2_error_loop
\r
613 bne reg2_error_loop
\r
615 bne reg2_error_loop
\r
617 bne reg2_error_loop
\r
619 bne reg2_error_loop
\r
621 bne reg2_error_loop
\r
623 /* Increment the loop counter so the check task knows this task is
\r
626 ldr r0, =pulRegTest4LoopCounter
\r
633 /* Yield to increase test coverage. */
\r
640 /* If this line is hit then there was an error in a core register value.
\r
641 This loop ensures the loop counter variable stops incrementing. */
\r
645 /*-----------------------------------------------------------*/
\r
647 /* Fault handlers are here for convenience as they use compiler specific syntax
\r
648 and this file is specific to the Keil compiler. */
\r
649 void hard_fault_handler( uint32_t * hardfault_args )
\r
651 volatile uint32_t stacked_r0;
\r
652 volatile uint32_t stacked_r1;
\r
653 volatile uint32_t stacked_r2;
\r
654 volatile uint32_t stacked_r3;
\r
655 volatile uint32_t stacked_r12;
\r
656 volatile uint32_t stacked_lr;
\r
657 volatile uint32_t stacked_pc;
\r
658 volatile uint32_t stacked_psr;
\r
660 stacked_r0 = ((uint32_t) hardfault_args[ 0 ]);
\r
661 stacked_r1 = ((uint32_t) hardfault_args[ 1 ]);
\r
662 stacked_r2 = ((uint32_t) hardfault_args[ 2 ]);
\r
663 stacked_r3 = ((uint32_t) hardfault_args[ 3 ]);
\r
665 stacked_r12 = ((uint32_t) hardfault_args[ 4 ]);
\r
666 stacked_lr = ((uint32_t) hardfault_args[ 5 ]);
\r
667 stacked_pc = ((uint32_t) hardfault_args[ 6 ]);
\r
668 stacked_psr = ((uint32_t) hardfault_args[ 7 ]);
\r
670 /* Inspect stacked_pc to locate the offending instruction. */
\r
673 /*-----------------------------------------------------------*/
\r
675 void HardFault_Handler( void );
\r
676 __asm void HardFault_Handler( void )
\r
678 extern hard_fault_handler
\r
685 ldr r2, hard_fault_handler
\r
688 /*-----------------------------------------------------------*/
\r
690 void MemManage_Handler( void );
\r
691 __asm void MemManage_Handler( void )
\r
693 extern hard_fault_handler
\r
700 ldr r2, hard_fault_handler
\r
703 /*-----------------------------------------------------------*/
\r