2 FreeRTOS V7.5.1 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
65 #include "FreeRTOS.h"
\r
69 * Two test tasks that fill the CPU registers with known values before
\r
70 * continuously looping round checking that each register still contains its
\r
71 * expected value. Both tasks use a separate set of values, with an incorrect
\r
72 * value being found at any time being indicative of an error in the context
\r
73 * switch mechanism. One of the tasks uses a yield instruction to increase the
\r
74 * test coverage. The nature of these tasks necessitates that they are written
\r
77 static void vRegTest1( void *pvParameters );
\r
78 static void vRegTest2( void *pvParameters );
\r
81 * A task that tests the management of the Interrupt Controller (IC) during a
\r
82 * context switch. The state of the IC current mask level must be maintained
\r
83 * across context switches. Also, yields must be able to be performed when the
\r
84 * interrupt controller mask is not zero. This task tests both these
\r
87 static void prvICCheck1Task( void *pvParameters );
\r
89 /* Counters used to ensure the tasks are still running. */
\r
90 static volatile unsigned long ulRegTest1Counter = 0UL, ulRegTest2Counter = 0UL, ulICTestCounter = 0UL;
\r
92 /* Handle to the task that checks the interrupt controller behaviour. This is
\r
93 used by the traceTASK_SWITCHED_OUT() macro, which is defined in
\r
94 FreeRTOSConfig.h and can be removed - it is just for the purpose of this test. */
\r
95 xTaskHandle xICTestTask = NULL;
\r
97 /* Variable that gets set to pdTRUE by traceTASK_SWITCHED_OUT each time
\r
99 volatile unsigned long ulTaskSwitchedOut;
\r
100 /*-----------------------------------------------------------*/
\r
102 void vStartRegTestTasks( void )
\r
104 xTaskCreate( vRegTest1, ( signed char * ) "RTest1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
105 xTaskCreate( vRegTest2, ( signed char * ) "RTest1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
106 xTaskCreate( prvICCheck1Task, ( signed char * ) "ICCheck", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xICTestTask );
\r
108 /*-----------------------------------------------------------*/
\r
110 static void vRegTest1( void *pvParameters )
\r
114 " mov r2, #0x02 \n" /* Fill the registers with known values, r0 is always 0 and r1 is the stack pointer. */
\r
115 " mov r3, #0x03 \n"
\r
116 " mov r4, #0x04 \n"
\r
117 " mov r5, #0x05 \n"
\r
118 " mov r6, #0x06 \n"
\r
119 " mov r7, #0x07 \n"
\r
120 " mov r8, #0x08 \n"
\r
121 " mov r9, #0x09 \n"
\r
122 " mov r10, #0x0a \n"
\r
123 " mov r11, #0x0b \n"
\r
124 " mov r12, #0x0c \n"
\r
125 " mov r13, #0x0d \n"
\r
126 " mov r14, #0x0e \n"
\r
127 " mov r15, #0x0f \n"
\r
129 "reg_check_loop_1: \n"
\r
131 " cmp r2, #0x02 \n" /* Check that each register still contains the expected value, jump to an infinite loop if an error is found. */
\r
132 " bne.s reg_check_error_1 \n"
\r
133 " cmp r3, #0x03 \n"
\r
134 " bne.s reg_check_error_1 \n"
\r
135 " cmp r4, #0x04 \n"
\r
136 " bne.s reg_check_error_1 \n"
\r
137 " cmp r5, #0x05 \n"
\r
138 " bne.s reg_check_error_1 \n"
\r
139 " cmp r6, #0x06 \n"
\r
140 " bne.s reg_check_error_1 \n"
\r
141 " cmp r7, #0x07 \n"
\r
142 " bne.s reg_check_error_1 \n"
\r
143 " cmp r8, #0x08 \n"
\r
144 " bne.s reg_check_error_1 \n"
\r
145 " cmp r9, #0x09 \n"
\r
146 " bne.s reg_check_error_1 \n"
\r
147 " cmp r10, #0x0a \n"
\r
148 " bne.s reg_check_error_1 \n"
\r
149 " cmp r11, #0x0b \n"
\r
150 " bne.s reg_check_error_1 \n"
\r
151 " cmp r12, #0x0c \n"
\r
152 " bne.s reg_check_error_1 \n"
\r
153 " cmp r13, #0x0d \n"
\r
154 " bne.s reg_check_error_1 \n"
\r
155 " cmp r14, #0x0e \n"
\r
156 " bne.s reg_check_error_1 \n"
\r
157 " cmp r15, #0x0f \n"
\r
158 " bne.s reg_check_error_1 \n"
\r
160 " ld r2, [r0]+short(ulRegTest1Counter) \n" /* Increment the loop counter to show that this task is still running error free. */
\r
162 " st r2, [r0]+short(ulRegTest1Counter) \n"
\r
163 " mov r2, #0x02 \n"
\r
165 " bra.s reg_check_loop_1 \n" /* Do it all again. */
\r
167 "reg_check_error_1: \n"
\r
171 /*-----------------------------------------------------------*/
\r
173 static void vRegTest2( void *pvParameters )
\r
177 " mov r2, #0x12 \n" /* Fill the registers with known values, r0 is always 0 and r1 is the stack pointer. */
\r
178 " mov r3, #0x13 \n"
\r
179 " mov r4, #0x14 \n"
\r
180 " mov r5, #0x15 \n"
\r
181 " mov r6, #0x16 \n"
\r
182 " mov r7, #0x17 \n"
\r
183 " mov r8, #0x18 \n"
\r
184 " mov r9, #0x19 \n"
\r
185 " mov r10, #0x1a \n"
\r
186 " mov r11, #0x1b \n"
\r
187 " mov r12, #0x1c \n"
\r
188 " mov r13, #0x1d \n"
\r
189 " mov r14, #0x1e \n"
\r
190 " mov r15, #0x1f \n"
\r
192 "reg_check_loop_2: \n"
\r
193 " cmp r2, #0x12 \n" /* Check that each register still contains the expected value, jump to an infinite loop if an error is found. */
\r
194 " bne.s reg_check_error_2 \n"
\r
195 " cmp r3, #0x13 \n"
\r
196 " bne.s reg_check_error_2 \n"
\r
197 " cmp r4, #0x14 \n"
\r
198 " bne.s reg_check_error_2 \n"
\r
199 " cmp r5, #0x15 \n"
\r
200 " bne.s reg_check_error_2 \n"
\r
201 " cmp r6, #0x16 \n"
\r
202 " bne.s reg_check_error_2 \n"
\r
203 " cmp r7, #0x17 \n"
\r
204 " bne.s reg_check_error_2 \n"
\r
205 " cmp r8, #0x18 \n"
\r
206 " bne.s reg_check_error_2 \n"
\r
207 " cmp r9, #0x19 \n"
\r
208 " bne.s reg_check_error_2 \n"
\r
209 " cmp r10, #0x1a \n"
\r
210 " bne.s reg_check_error_2 \n"
\r
211 " cmp r11, #0x1b \n"
\r
212 " bne.s reg_check_error_2 \n"
\r
213 " cmp r12, #0x1c \n"
\r
214 " bne.s reg_check_error_2 \n"
\r
215 " cmp r13, #0x1d \n"
\r
216 " bne.s reg_check_error_2 \n"
\r
217 " cmp r14, #0x1e \n"
\r
218 " bne.s reg_check_error_2 \n"
\r
219 " cmp r15, #0x1f \n"
\r
220 " bne.s reg_check_error_2 \n"
\r
222 " ld r2, [r0]+short(ulRegTest2Counter) \n" /* Increment the loop counter to show that this task is still running error free. */
\r
224 " st r2, [r0]+short(ulRegTest2Counter) \n"
\r
225 " mov r2, #0x12 \n"
\r
227 " bra.s reg_check_loop_2 \n" /* Do it all again. */
\r
229 "reg_check_error_2: \n"
\r
233 /*-----------------------------------------------------------*/
\r
235 static void prvICCheck1Task( void *pvParameters )
\r
237 long lICCheckStatus = pdPASS;
\r
241 /* At this point the interrupt mask should be zero. */
\r
244 lICCheckStatus = pdFAIL;
\r
247 /* If we yield here, it should still be 0 when the task next runs.
\r
248 ulTaskSwitchedOut is just used to check that a switch does actually
\r
250 ulTaskSwitchedOut = pdFALSE;
\r
252 if( ( ulTaskSwitchedOut != pdTRUE ) || ( ic->cpl != 0 ) )
\r
254 lICCheckStatus = pdFAIL;
\r
257 /* Set the interrupt mask to portSYSTEM_INTERRUPT_PRIORITY_LEVEL + 1,
\r
258 before checking it is as expected. */
\r
259 taskENTER_CRITICAL();
\r
260 if( ic->cpl != ( portSYSTEM_INTERRUPT_PRIORITY_LEVEL + 1 ) )
\r
262 lICCheckStatus = pdFAIL;
\r
265 /* If we yield here, it should still be
\r
266 portSYSTEM_INTERRUPT_PRIORITY_LEVEL + 10 when the task next runs. */
\r
267 ulTaskSwitchedOut = pdFALSE;
\r
269 if( ( ulTaskSwitchedOut != pdTRUE ) || ( ic->cpl != ( portSYSTEM_INTERRUPT_PRIORITY_LEVEL + 1 ) ) )
\r
271 lICCheckStatus = pdFAIL;
\r
274 /* Return the interrupt mask to its default state. */
\r
275 taskEXIT_CRITICAL();
\r
277 /* Just increment a loop counter so the check task knows if this task
\r
278 is still running or not. */
\r
279 if( lICCheckStatus == pdPASS )
\r
285 /*-----------------------------------------------------------*/
\r
287 portBASE_TYPE xAreRegTestTasksStillRunning( void )
\r
289 static unsigned long ulLastCounter1 = 0UL, ulLastCounter2 = 0UL, ulLastICTestCounter = 0UL;
\r
292 /* Check that both loop counters are still incrementing, indicating that
\r
293 both reg test tasks are still running error free. */
\r
294 if( ulLastCounter1 == ulRegTest1Counter )
\r
298 else if( ulLastCounter2 == ulRegTest2Counter )
\r
302 else if( ulLastICTestCounter == ulICTestCounter )
\r
311 ulLastCounter1 = ulRegTest1Counter;
\r
312 ulLastCounter2 = ulRegTest2Counter;
\r
313 ulLastICTestCounter = ulICTestCounter;
\r