]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTUS_APS3_GCC/Demo/RegTest.c
80a403c35ffaf1522ed98ff19734d019aa2bec26
[freertos] / FreeRTOS / Demo / CORTUS_APS3_GCC / Demo / RegTest.c
1 /*\r
2     FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd.\r
3 \r
4     FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME.  PLEASE VISIT\r
5     http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
10      *    Complete, revised, and edited pdf reference manuals are also       *\r
11      *    available.                                                         *\r
12      *                                                                       *\r
13      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
14      *    ensuring you get running as quickly as possible and with an        *\r
15      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
16      *    the FreeRTOS project to continue with its mission of providing     *\r
17      *    professional grade, cross platform, de facto standard solutions    *\r
18      *    for microcontrollers - completely free of charge!                  *\r
19      *                                                                       *\r
20      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
21      *                                                                       *\r
22      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
23      *                                                                       *\r
24     ***************************************************************************\r
25 \r
26 \r
27     This file is part of the FreeRTOS distribution.\r
28 \r
29     FreeRTOS is free software; you can redistribute it and/or modify it under\r
30     the terms of the GNU General Public License (version 2) as published by the\r
31     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
32 \r
33     >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to\r
34     distribute a combined work that includes FreeRTOS without being obliged to\r
35     provide the source code for proprietary components outside of the FreeRTOS\r
36     kernel.\r
37 \r
38     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
39     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
40     FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more\r
41     details. You should have received a copy of the GNU General Public License\r
42     and the FreeRTOS license exception along with FreeRTOS; if not itcan be\r
43     viewed here: http://www.freertos.org/a00114.html and also obtained by\r
44     writing to Real Time Engineers Ltd., contact details for whom are available\r
45     on the FreeRTOS WEB site.\r
46 \r
47     1 tab == 4 spaces!\r
48 \r
49     ***************************************************************************\r
50      *                                                                       *\r
51      *    Having a problem?  Start by reading the FAQ "My application does   *\r
52      *    not run, what could be wrong?"                                     *\r
53      *                                                                       *\r
54      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
55      *                                                                       *\r
56     ***************************************************************************\r
57 \r
58 \r
59     http://www.FreeRTOS.org - Documentation, books, training, latest versions, \r
60     license and Real Time Engineers Ltd. contact details.\r
61 \r
62     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
63     including FreeRTOS+Trace - an indispensable productivity tool, and our new\r
64     fully thread aware and reentrant UDP/IP stack.\r
65 \r
66     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High \r
67     Integrity Systems, who sell the code with commercial support, \r
68     indemnification and middleware, under the OpenRTOS brand.\r
69     \r
70     http://www.SafeRTOS.com - High Integrity Systems also provide a safety \r
71     engineered and independently SIL3 certified version for use in safety and \r
72     mission critical applications that require provable dependability.\r
73 */\r
74 \r
75 #include "FreeRTOS.h"\r
76 #include "task.h"\r
77 \r
78 /*\r
79  * Two test tasks that fill the CPU registers with known values before\r
80  * continuously looping round checking that each register still contains its\r
81  * expected value.  Both tasks use a separate set of values, with an incorrect\r
82  * value being found at any time being indicative of an error in the context\r
83  * switch mechanism.  One of the tasks uses a yield instruction to increase the\r
84  * test coverage.  The nature of these tasks necessitates that they are written\r
85  * in assembly code.\r
86  */\r
87 static void vRegTest1( void *pvParameters );\r
88 static void vRegTest2( void *pvParameters );\r
89 \r
90 /*\r
91  * A task that tests the management of the Interrupt Controller (IC) during a\r
92  * context switch.  The state of the IC current mask level must be maintained\r
93  * across context switches.  Also, yields must be able to be performed when the\r
94  * interrupt controller mask is not zero.  This task tests both these\r
95  * requirements.\r
96  */\r
97 static void prvICCheck1Task( void *pvParameters );\r
98 \r
99 /* Counters used to ensure the tasks are still running. */\r
100 static volatile unsigned long ulRegTest1Counter = 0UL, ulRegTest2Counter = 0UL, ulICTestCounter = 0UL;\r
101 \r
102 /* Handle to the task that checks the interrupt controller behaviour.  This is\r
103 used by the traceTASK_SWITCHED_OUT() macro, which is defined in\r
104 FreeRTOSConfig.h and can be removed - it is just for the purpose of this test. */\r
105 xTaskHandle xICTestTask = NULL;\r
106 \r
107 /* Variable that gets set to pdTRUE by traceTASK_SWITCHED_OUT each time\r
108 is switched out. */\r
109 volatile unsigned long ulTaskSwitchedOut;\r
110 /*-----------------------------------------------------------*/\r
111 \r
112 void vStartRegTestTasks( void )\r
113 {\r
114         xTaskCreate( vRegTest1, ( signed char * ) "RTest1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
115         xTaskCreate( vRegTest2, ( signed char * ) "RTest1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
116         xTaskCreate( prvICCheck1Task, ( signed char * ) "ICCheck", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xICTestTask );\r
117 }\r
118 /*-----------------------------------------------------------*/\r
119 \r
120 static void vRegTest1( void *pvParameters )\r
121 {\r
122         __asm volatile\r
123         (\r
124                 "       mov             r2, #0x02                                                       \n" /* Fill the registers with known values, r0 is always 0 and r1 is the stack pointer. */\r
125                 "       mov             r3, #0x03                                                       \n"\r
126                 "       mov             r4, #0x04                                                       \n"\r
127                 "       mov             r5, #0x05                                                       \n"\r
128                 "       mov             r6, #0x06                                                       \n"\r
129                 "       mov             r7, #0x07                                                       \n"\r
130                 "       mov             r8, #0x08                                                       \n"\r
131                 "       mov             r9, #0x09                                                       \n"\r
132                 "       mov             r10, #0x0a                                                      \n"\r
133                 "       mov             r11, #0x0b                                                      \n"\r
134                 "       mov             r12, #0x0c                                                      \n"\r
135                 "       mov             r13, #0x0d                                                      \n"\r
136                 "       mov             r14, #0x0e                                                      \n"\r
137                 "       mov             r15, #0x0f                                                      \n"\r
138                 "                                                                                               \n"\r
139                 "reg_check_loop_1:                                                              \n"\r
140                 "       trap    #31                                                                     \n"\r
141                 "       cmp             r2, #0x02                                                       \n" /* Check that each register still contains the expected value, jump to an infinite loop if an error is found. */\r
142                 "       bne.s   reg_check_error_1                                       \n"\r
143                 "       cmp             r3, #0x03                                                       \n"\r
144                 "       bne.s   reg_check_error_1                                       \n"\r
145                 "       cmp             r4, #0x04                                                       \n"\r
146                 "       bne.s   reg_check_error_1                                       \n"\r
147                 "       cmp             r5, #0x05                                                       \n"\r
148                 "       bne.s   reg_check_error_1                                       \n"\r
149                 "       cmp             r6, #0x06                                                       \n"\r
150                 "       bne.s   reg_check_error_1                                       \n"\r
151                 "       cmp             r7, #0x07                                                       \n"\r
152                 "       bne.s   reg_check_error_1                                       \n"\r
153                 "       cmp             r8, #0x08                                                       \n"\r
154                 "       bne.s   reg_check_error_1                                       \n"\r
155                 "       cmp             r9, #0x09                                                       \n"\r
156                 "       bne.s   reg_check_error_1                                       \n"\r
157                 "       cmp             r10, #0x0a                                                      \n"\r
158                 "       bne.s   reg_check_error_1                                       \n"\r
159                 "       cmp             r11, #0x0b                                                      \n"\r
160                 "       bne.s   reg_check_error_1                                       \n"\r
161                 "       cmp             r12, #0x0c                                                      \n"\r
162                 "       bne.s   reg_check_error_1                                       \n"\r
163                 "       cmp             r13, #0x0d                                                      \n"\r
164                 "       bne.s   reg_check_error_1                                       \n"\r
165                 "       cmp             r14, #0x0e                                                      \n"\r
166                 "       bne.s   reg_check_error_1                                       \n"\r
167                 "       cmp             r15, #0x0f                                                      \n"\r
168                 "       bne.s   reg_check_error_1                                       \n"\r
169                 "                                                                                               \n"\r
170                 "       ld              r2, [r0]+short(ulRegTest1Counter)       \n" /* Increment the loop counter to show that this task is still running error free. */\r
171                 "       add             r2, #1                                                          \n"\r
172                 "       st              r2, [r0]+short(ulRegTest1Counter)       \n"\r
173                 "       mov             r2, #0x02                                                       \n"\r
174                 "                                                                                               \n"\r
175                 "       bra.s   reg_check_loop_1                                        \n" /* Do it all again. */\r
176                 "                                                                                               \n"\r
177                 "reg_check_error_1:                                                             \n"\r
178                         "bra.s          .                                                               \n"\r
179         );\r
180 }\r
181 /*-----------------------------------------------------------*/\r
182 \r
183 static void vRegTest2( void *pvParameters )\r
184 {\r
185         __asm volatile\r
186         (\r
187                 "       mov             r2, #0x12                                                       \n" /* Fill the registers with known values, r0 is always 0 and r1 is the stack pointer. */\r
188                 "       mov             r3, #0x13                                                       \n"\r
189                 "       mov             r4, #0x14                                                       \n"\r
190                 "       mov             r5, #0x15                                                       \n"\r
191                 "       mov             r6, #0x16                                                       \n"\r
192                 "       mov             r7, #0x17                                                       \n"\r
193                 "       mov             r8, #0x18                                                       \n"\r
194                 "       mov             r9, #0x19                                                       \n"\r
195                 "       mov             r10, #0x1a                                                      \n"\r
196                 "       mov             r11, #0x1b                                                      \n"\r
197                 "       mov             r12, #0x1c                                                      \n"\r
198                 "       mov             r13, #0x1d                                                      \n"\r
199                 "       mov             r14, #0x1e                                                      \n"\r
200                 "       mov             r15, #0x1f                                                      \n"\r
201                 "                                                                                               \n"\r
202                 "reg_check_loop_2:                                                              \n"\r
203                 "       cmp             r2, #0x12                                                       \n" /* Check that each register still contains the expected value, jump to an infinite loop if an error is found. */\r
204                 "       bne.s   reg_check_error_2                                       \n"\r
205                 "       cmp             r3, #0x13                                                       \n"\r
206                 "       bne.s   reg_check_error_2                                       \n"\r
207                 "       cmp             r4, #0x14                                                       \n"\r
208                 "       bne.s   reg_check_error_2                                       \n"\r
209                 "       cmp             r5, #0x15                                                       \n"\r
210                 "       bne.s   reg_check_error_2                                       \n"\r
211                 "       cmp             r6, #0x16                                                       \n"\r
212                 "       bne.s   reg_check_error_2                                       \n"\r
213                 "       cmp             r7, #0x17                                                       \n"\r
214                 "       bne.s   reg_check_error_2                                       \n"\r
215                 "       cmp             r8, #0x18                                                       \n"\r
216                 "       bne.s   reg_check_error_2                                       \n"\r
217                 "       cmp             r9, #0x19                                                       \n"\r
218                 "       bne.s   reg_check_error_2                                       \n"\r
219                 "       cmp             r10, #0x1a                                                      \n"\r
220                 "       bne.s   reg_check_error_2                                       \n"\r
221                 "       cmp             r11, #0x1b                                                      \n"\r
222                 "       bne.s   reg_check_error_2                                       \n"\r
223                 "       cmp             r12, #0x1c                                                      \n"\r
224                 "       bne.s   reg_check_error_2                                       \n"\r
225                 "       cmp             r13, #0x1d                                                      \n"\r
226                 "       bne.s   reg_check_error_2                                       \n"\r
227                 "       cmp             r14, #0x1e                                                      \n"\r
228                 "       bne.s   reg_check_error_2                                       \n"\r
229                 "       cmp             r15, #0x1f                                                      \n"\r
230                 "       bne.s   reg_check_error_2                                       \n"\r
231                 "                                                                                               \n"\r
232                 "       ld              r2, [r0]+short(ulRegTest2Counter)       \n" /* Increment the loop counter to show that this task is still running error free. */\r
233                 "       add             r2, #1                                                          \n"\r
234                 "       st              r2, [r0]+short(ulRegTest2Counter)       \n"\r
235                 "       mov             r2, #0x12                                                       \n"\r
236                 "                                                                                               \n"\r
237                 "       bra.s   reg_check_loop_2                                        \n" /* Do it all again. */\r
238                 "                                                                                               \n"\r
239                 "reg_check_error_2:                                                             \n"\r
240                         "bra.s          .                                                               \n"\r
241         );\r
242 }\r
243 /*-----------------------------------------------------------*/\r
244 \r
245 static void prvICCheck1Task( void *pvParameters )\r
246 {\r
247 long lICCheckStatus = pdPASS;\r
248 \r
249         for( ;; )\r
250         {\r
251                 /* At this point the interrupt mask should be zero. */\r
252                 if( ic->cpl != 0 )\r
253                 {\r
254                         lICCheckStatus = pdFAIL;\r
255                 }\r
256 \r
257                 /* If we yield here, it should still be 0 when the task next runs.\r
258                 ulTaskSwitchedOut is just used to check that a switch does actually\r
259                 happen. */\r
260                 ulTaskSwitchedOut = pdFALSE;\r
261                 taskYIELD();\r
262                 if( ( ulTaskSwitchedOut != pdTRUE ) || ( ic->cpl != 0 ) )\r
263                 {\r
264                         lICCheckStatus = pdFAIL;\r
265                 }\r
266 \r
267                 /* Set the interrupt mask to portSYSTEM_INTERRUPT_PRIORITY_LEVEL + 1,\r
268                 before checking it is as expected. */\r
269                 taskENTER_CRITICAL();\r
270                 if( ic->cpl != ( portSYSTEM_INTERRUPT_PRIORITY_LEVEL + 1 ) )\r
271                 {\r
272                         lICCheckStatus = pdFAIL;\r
273                 }\r
274 \r
275                 /* If we yield here, it should still be\r
276                 portSYSTEM_INTERRUPT_PRIORITY_LEVEL + 10 when the task next runs.  */\r
277                 ulTaskSwitchedOut = pdFALSE;\r
278                 taskYIELD();\r
279                 if( ( ulTaskSwitchedOut != pdTRUE ) || ( ic->cpl != ( portSYSTEM_INTERRUPT_PRIORITY_LEVEL + 1 ) ) )\r
280                 {\r
281                         lICCheckStatus = pdFAIL;\r
282                 }\r
283 \r
284                 /* Return the interrupt mask to its default state. */\r
285                 taskEXIT_CRITICAL();\r
286 \r
287                 /* Just increment a loop counter so the check task knows if this task\r
288                 is still running or not. */\r
289                 if( lICCheckStatus == pdPASS )\r
290                 {\r
291                         ulICTestCounter++;\r
292                 }\r
293         }\r
294 }\r
295 /*-----------------------------------------------------------*/\r
296 \r
297 portBASE_TYPE xAreRegTestTasksStillRunning( void )\r
298 {\r
299 static unsigned long ulLastCounter1 = 0UL, ulLastCounter2 = 0UL, ulLastICTestCounter = 0UL;\r
300 long lReturn;\r
301 \r
302         /* Check that both loop counters are still incrementing, indicating that\r
303         both reg test tasks are still running error free. */\r
304         if( ulLastCounter1 == ulRegTest1Counter )\r
305         {\r
306                 lReturn = pdFAIL;\r
307         }\r
308         else if( ulLastCounter2 == ulRegTest2Counter )\r
309         {\r
310                 lReturn = pdFAIL;\r
311         }\r
312         else if( ulLastICTestCounter == ulICTestCounter )\r
313         {\r
314                 lReturn = pdFAIL;\r
315         }\r
316         else\r
317         {\r
318                 lReturn = pdPASS;\r
319         }\r
320 \r
321         ulLastCounter1 = ulRegTest1Counter;\r
322         ulLastCounter2 = ulRegTest2Counter;\r
323         ulLastICTestCounter = ulICTestCounter;\r
324 \r
325         return lReturn;\r
326 }\r
327 \r
328 \r
329 \r
330 \r
331 \r
332 \r
333 \r
334 \r
335 \r
336 \r
337 \r
338 \r
339 \r
340 \r