]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_EFM32_Pearl_Gecko_Simplicity_Studio/Full_Demo/RegTest.c
58ab98d358fe1ae1ccd523a05ab13397aa5953aa
[freertos] / FreeRTOS / Demo / CORTEX_EFM32_Pearl_Gecko_Simplicity_Studio / Full_Demo / RegTest.c
1 /*\r
2     FreeRTOS V9.0.0rc1 - Copyright (C) 2016 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \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
12 \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
19 \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
24 \r
25     ***************************************************************************\r
26      *                                                                       *\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
31      *                                                                       *\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
36      *                                                                       *\r
37     ***************************************************************************\r
38 \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
42 \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
46 \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
51 \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
55 \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
58 \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
62 \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
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 \r
70 /*\r
71  * "Reg test" tasks - These fill the registers with known values, then check\r
72  * that each register maintains its expected value for the lifetime of the\r
73  * task.  Each task uses a different set of values.  The reg test tasks execute\r
74  * with a very low priority, so get preempted very frequently.  A register\r
75  * containing an unexpected value is indicative of an error in the context\r
76  * switching mechanism.\r
77  */\r
78 \r
79 void vRegTest1Implementation( void ) __attribute__ ((naked));\r
80 void vRegTest2Implementation( void ) __attribute__ ((naked));\r
81 \r
82 void vRegTest1Implementation( void )\r
83 {\r
84         __asm volatile\r
85         (\r
86                 ".extern ulRegTest1LoopCounter \n"\r
87 \r
88                 /* Fill the core registers with known values. */\r
89                 "mov r0, #100                                   \n"\r
90                 "mov r1, #101                                   \n"\r
91                 "mov r2, #102                                   \n"\r
92                 "mov r3, #103                                   \n"\r
93                 "mov r4, #104                                   \n"\r
94                 "mov r5, #105                                   \n"\r
95                 "mov r6, #106                                   \n"\r
96                 "mov r7, #107                                   \n"\r
97                 "mov r8, #108                                   \n"\r
98                 "mov r9, #109                                   \n"\r
99                 "mov r10, #110                                  \n"\r
100                 "mov r11, #111                                  \n"\r
101                 "mov r12, #112                                  \n"\r
102 \r
103                 /* Fill the VFP registers with known values. */\r
104                 "vmov d0, r0, r1                                \n"\r
105                 "vmov d1, r2, r3                                \n"\r
106                 "vmov d2, r4, r5                                \n"\r
107                 "vmov d3, r6, r7                                \n"\r
108                 "vmov d4, r8, r9                                \n"\r
109                 "vmov d5, r10, r11                              \n"\r
110                 "vmov d6, r0, r1                                \n"\r
111                 "vmov d7, r2, r3                                \n"\r
112                 "vmov d8, r4, r5                                \n"\r
113                 "vmov d9, r6, r7                                \n"\r
114                 "vmov d10, r8, r9                               \n"\r
115                 "vmov d11, r10, r11                             \n"\r
116                 "vmov d12, r0, r1                               \n"\r
117                 "vmov d13, r2, r3                               \n"\r
118                 "vmov d14, r4, r5                               \n"\r
119                 "vmov d15, r6, r7                               \n"\r
120 \r
121         "reg1_loop:                                                     \n"\r
122                 /* Check all the VFP registers still contain the values set above.\r
123                 First save registers that are clobbered by the test. */\r
124                 "push { r0-r1 }                                 \n"\r
125 \r
126                 "vmov r0, r1, d0                                \n"\r
127                 "cmp r0, #100                                   \n"\r
128                 "bne reg1_error_loopf                   \n"\r
129                 "cmp r1, #101                                   \n"\r
130                 "bne reg1_error_loopf                   \n"\r
131                 "vmov r0, r1, d1                                \n"\r
132                 "cmp r0, #102                                   \n"\r
133                 "bne reg1_error_loopf                   \n"\r
134                 "cmp r1, #103                                   \n"\r
135                 "bne reg1_error_loopf                   \n"\r
136                 "vmov r0, r1, d2                                \n"\r
137                 "cmp r0, #104                                   \n"\r
138                 "bne reg1_error_loopf                   \n"\r
139                 "cmp r1, #105                                   \n"\r
140                 "bne reg1_error_loopf                   \n"\r
141                 "vmov r0, r1, d3                                \n"\r
142                 "cmp r0, #106                                   \n"\r
143                 "bne reg1_error_loopf                   \n"\r
144                 "cmp r1, #107                                   \n"\r
145                 "bne reg1_error_loopf                   \n"\r
146                 "vmov r0, r1, d4                                \n"\r
147                 "cmp r0, #108                                   \n"\r
148                 "bne reg1_error_loopf                   \n"\r
149                 "cmp r1, #109                                   \n"\r
150                 "bne reg1_error_loopf                   \n"\r
151                 "vmov r0, r1, d5                                \n"\r
152                 "cmp r0, #110                                   \n"\r
153                 "bne reg1_error_loopf                   \n"\r
154                 "cmp r1, #111                                   \n"\r
155                 "bne reg1_error_loopf                   \n"\r
156                 "vmov r0, r1, d6                                \n"\r
157                 "cmp r0, #100                                   \n"\r
158                 "bne reg1_error_loopf                   \n"\r
159                 "cmp r1, #101                                   \n"\r
160                 "bne reg1_error_loopf                   \n"\r
161                 "vmov r0, r1, d7                                \n"\r
162                 "cmp r0, #102                                   \n"\r
163                 "bne reg1_error_loopf                   \n"\r
164                 "cmp r1, #103                                   \n"\r
165                 "bne reg1_error_loopf                   \n"\r
166                 "vmov r0, r1, d8                                \n"\r
167                 "cmp r0, #104                                   \n"\r
168                 "bne reg1_error_loopf                   \n"\r
169                 "cmp r1, #105                                   \n"\r
170                 "bne reg1_error_loopf                   \n"\r
171                 "vmov r0, r1, d9                                \n"\r
172                 "cmp r0, #106                                   \n"\r
173                 "bne reg1_error_loopf                   \n"\r
174                 "cmp r1, #107                                   \n"\r
175                 "bne reg1_error_loopf                   \n"\r
176                 "vmov r0, r1, d10                               \n"\r
177                 "cmp r0, #108                                   \n"\r
178                 "bne reg1_error_loopf                   \n"\r
179                 "cmp r1, #109                                   \n"\r
180                 "bne reg1_error_loopf                   \n"\r
181                 "vmov r0, r1, d11                               \n"\r
182                 "cmp r0, #110                                   \n"\r
183                 "bne reg1_error_loopf                   \n"\r
184                 "cmp r1, #111                                   \n"\r
185                 "bne reg1_error_loopf                   \n"\r
186                 "vmov r0, r1, d12                               \n"\r
187                 "cmp r0, #100                                   \n"\r
188                 "bne reg1_error_loopf                   \n"\r
189                 "cmp r1, #101                                   \n"\r
190                 "bne reg1_error_loopf                   \n"\r
191                 "vmov r0, r1, d13                               \n"\r
192                 "cmp r0, #102                                   \n"\r
193                 "bne reg1_error_loopf                   \n"\r
194                 "cmp r1, #103                                   \n"\r
195                 "bne reg1_error_loopf                   \n"\r
196                 "vmov r0, r1, d14                               \n"\r
197                 "cmp r0, #104                                   \n"\r
198                 "bne reg1_error_loopf                   \n"\r
199                 "cmp r1, #105                                   \n"\r
200                 "bne reg1_error_loopf                   \n"\r
201                 "vmov r0, r1, d15                               \n"\r
202                 "cmp r0, #106                                   \n"\r
203                 "bne reg1_error_loopf                   \n"\r
204                 "cmp r1, #107                                   \n"\r
205                 "bne reg1_error_loopf                   \n"\r
206 \r
207                 /* Restore the registers that were clobbered by the test. */\r
208                 "pop {r0-r1}                                    \n"\r
209 \r
210                 /* VFP register test passed.  Jump to the core register test. */\r
211                 "b reg1_loopf_pass                              \n"\r
212 \r
213         "reg1_error_loopf:                                      \n"\r
214                 /* If this line is hit then a VFP register value was found to be\r
215                 incorrect. */\r
216                 "b reg1_error_loopf                             \n"\r
217 \r
218         "reg1_loopf_pass:                                       \n"\r
219 \r
220                 "cmp    r0, #100                                \n"\r
221                 "bne    reg1_error_loop                 \n"\r
222                 "cmp    r1, #101                                \n"\r
223                 "bne    reg1_error_loop                 \n"\r
224                 "cmp    r2, #102                                \n"\r
225                 "bne    reg1_error_loop                 \n"\r
226                 "cmp r3, #103                                   \n"\r
227                 "bne    reg1_error_loop                 \n"\r
228                 "cmp    r4, #104                                \n"\r
229                 "bne    reg1_error_loop                 \n"\r
230                 "cmp    r5, #105                                \n"\r
231                 "bne    reg1_error_loop                 \n"\r
232                 "cmp    r6, #106                                \n"\r
233                 "bne    reg1_error_loop                 \n"\r
234                 "cmp    r7, #107                                \n"\r
235                 "bne    reg1_error_loop                 \n"\r
236                 "cmp    r8, #108                                \n"\r
237                 "bne    reg1_error_loop                 \n"\r
238                 "cmp    r9, #109                                \n"\r
239                 "bne    reg1_error_loop                 \n"\r
240                 "cmp    r10, #110                               \n"\r
241                 "bne    reg1_error_loop                 \n"\r
242                 "cmp    r11, #111                               \n"\r
243                 "bne    reg1_error_loop                 \n"\r
244                 "cmp    r12, #112                               \n"\r
245                 "bne    reg1_error_loop                 \n"\r
246 \r
247                 /* Everything passed, increment the loop counter. */\r
248                 "push { r0-r1 }                                 \n"\r
249                 "ldr    r0, =ulRegTest1LoopCounter      \n"\r
250                 "ldr r1, [r0]                                   \n"\r
251                 "adds r1, r1, #1                                \n"\r
252                 "str r1, [r0]                                   \n"\r
253                 "pop { r0-r1 }                                  \n"\r
254 \r
255                 /* Start again. */\r
256                 "b reg1_loop                                    \n"\r
257 \r
258         "reg1_error_loop:                                       \n"\r
259                 /* If this line is hit then there was an error in a core register value.\r
260                 The loop ensures the loop counter stops incrementing. */\r
261                 "b reg1_error_loop                              \n"\r
262                 "nop                                                    \n"\r
263         ); /* __asm volatile. */\r
264 }\r
265 /*-----------------------------------------------------------*/\r
266 \r
267 void vRegTest2Implementation( void )\r
268 {\r
269         __asm volatile\r
270         (\r
271                 ".extern ulRegTest2LoopCounter  \n"\r
272 \r
273                 /* Set all the core registers to known values. */\r
274                 "mov r0, #-1                                    \n"\r
275                 "mov r1, #1                                             \n"\r
276                 "mov r2, #2                                             \n"\r
277                 "mov r3, #3                                             \n"\r
278                 "mov r4, #4                                             \n"\r
279                 "mov r5, #5                                             \n"\r
280                 "mov r6, #6                                             \n"\r
281                 "mov r7, #7                                             \n"\r
282                 "mov r8, #8                                             \n"\r
283                 "mov r9, #9                                             \n"\r
284                 "mov r10, #10                                   \n"\r
285                 "mov r11, #11                                   \n"\r
286                 "mov r12, #12                                   \n"\r
287 \r
288                 /* Set all the VFP to known values. */\r
289                 "vmov d0, r0, r1                                \n"\r
290                 "vmov d1, r2, r3                                \n"\r
291                 "vmov d2, r4, r5                                \n"\r
292                 "vmov d3, r6, r7                                \n"\r
293                 "vmov d4, r8, r9                                \n"\r
294                 "vmov d5, r10, r11                              \n"\r
295                 "vmov d6, r0, r1                                \n"\r
296                 "vmov d7, r2, r3                                \n"\r
297                 "vmov d8, r4, r5                                \n"\r
298                 "vmov d9, r6, r7                                \n"\r
299                 "vmov d10, r8, r9                               \n"\r
300                 "vmov d11, r10, r11                             \n"\r
301                 "vmov d12, r0, r1                               \n"\r
302                 "vmov d13, r2, r3                               \n"\r
303                 "vmov d14, r4, r5                               \n"\r
304                 "vmov d15, r6, r7                               \n"\r
305 \r
306         "reg2_loop:                                                     \n"\r
307 \r
308                 /* Check all the VFP registers still contain the values set above.\r
309                 First save registers that are clobbered by the test. */\r
310                 "push { r0-r1 }                                 \n"\r
311 \r
312                 "vmov r0, r1, d0                                \n"\r
313                 "cmp r0, #-1                                    \n"\r
314                 "bne reg2_error_loopf                   \n"\r
315                 "cmp r1, #1                                             \n"\r
316                 "bne reg2_error_loopf                   \n"\r
317                 "vmov r0, r1, d1                                \n"\r
318                 "cmp r0, #2                                             \n"\r
319                 "bne reg2_error_loopf                   \n"\r
320                 "cmp r1, #3                                             \n"\r
321                 "bne reg2_error_loopf                   \n"\r
322                 "vmov r0, r1, d2                                \n"\r
323                 "cmp r0, #4                                             \n"\r
324                 "bne reg2_error_loopf                   \n"\r
325                 "cmp r1, #5                                             \n"\r
326                 "bne reg2_error_loopf                   \n"\r
327                 "vmov r0, r1, d3                                \n"\r
328                 "cmp r0, #6                                             \n"\r
329                 "bne reg2_error_loopf                   \n"\r
330                 "cmp r1, #7                                             \n"\r
331                 "bne reg2_error_loopf                   \n"\r
332                 "vmov r0, r1, d4                                \n"\r
333                 "cmp r0, #8                                             \n"\r
334                 "bne reg2_error_loopf                   \n"\r
335                 "cmp r1, #9                                             \n"\r
336                 "bne reg2_error_loopf                   \n"\r
337                 "vmov r0, r1, d5                                \n"\r
338                 "cmp r0, #10                                    \n"\r
339                 "bne reg2_error_loopf                   \n"\r
340                 "cmp r1, #11                                    \n"\r
341                 "bne reg2_error_loopf                   \n"\r
342                 "vmov r0, r1, d6                                \n"\r
343                 "cmp r0, #-1                                    \n"\r
344                 "bne reg2_error_loopf                   \n"\r
345                 "cmp r1, #1                                             \n"\r
346                 "bne reg2_error_loopf                   \n"\r
347                 "vmov r0, r1, d7                                \n"\r
348                 "cmp r0, #2                                             \n"\r
349                 "bne reg2_error_loopf                   \n"\r
350                 "cmp r1, #3                                             \n"\r
351                 "bne reg2_error_loopf                   \n"\r
352                 "vmov r0, r1, d8                                \n"\r
353                 "cmp r0, #4                                             \n"\r
354                 "bne reg2_error_loopf                   \n"\r
355                 "cmp r1, #5                                             \n"\r
356                 "bne reg2_error_loopf                   \n"\r
357                 "vmov r0, r1, d9                                \n"\r
358                 "cmp r0, #6                                             \n"\r
359                 "bne reg2_error_loopf                   \n"\r
360                 "cmp r1, #7                                             \n"\r
361                 "bne reg2_error_loopf                   \n"\r
362                 "vmov r0, r1, d10                               \n"\r
363                 "cmp r0, #8                                             \n"\r
364                 "bne reg2_error_loopf                   \n"\r
365                 "cmp r1, #9                                             \n"\r
366                 "bne reg2_error_loopf                   \n"\r
367                 "vmov r0, r1, d11                               \n"\r
368                 "cmp r0, #10                                    \n"\r
369                 "bne reg2_error_loopf                   \n"\r
370                 "cmp r1, #11                                    \n"\r
371                 "bne reg2_error_loopf                   \n"\r
372                 "vmov r0, r1, d12                               \n"\r
373                 "cmp r0, #-1                                    \n"\r
374                 "bne reg2_error_loopf                   \n"\r
375                 "cmp r1, #1                                             \n"\r
376                 "bne reg2_error_loopf                   \n"\r
377                 "vmov r0, r1, d13                               \n"\r
378                 "cmp r0, #2                                             \n"\r
379                 "bne reg2_error_loopf                   \n"\r
380                 "cmp r1, #3                                             \n"\r
381                 "bne reg2_error_loopf                   \n"\r
382                 "vmov r0, r1, d14                               \n"\r
383                 "cmp r0, #4                                             \n"\r
384                 "bne reg2_error_loopf                   \n"\r
385                 "cmp r1, #5                                             \n"\r
386                 "bne reg2_error_loopf                   \n"\r
387                 "vmov r0, r1, d15                               \n"\r
388                 "cmp r0, #6                                             \n"\r
389                 "bne reg2_error_loopf                   \n"\r
390                 "cmp r1, #7                                             \n"\r
391                 "bne reg2_error_loopf                   \n"\r
392 \r
393                 /* Restore the registers that were clobbered by the test. */\r
394                 "pop {r0-r1}                                    \n"\r
395 \r
396                 /* VFP register test passed.  Jump to the core register test. */\r
397                 "b reg2_loopf_pass                              \n"\r
398 \r
399         "reg2_error_loopf:                                      \n"\r
400                 /* If this line is hit then a VFP register value was found to be\r
401                 incorrect. */\r
402                 "b reg2_error_loopf                             \n"\r
403 \r
404         "reg2_loopf_pass:                                       \n"\r
405 \r
406                 "cmp    r0, #-1                                 \n"\r
407                 "bne    reg2_error_loop                 \n"\r
408                 "cmp    r1, #1                                  \n"\r
409                 "bne    reg2_error_loop                 \n"\r
410                 "cmp    r2, #2                                  \n"\r
411                 "bne    reg2_error_loop                 \n"\r
412                 "cmp r3, #3                                             \n"\r
413                 "bne    reg2_error_loop                 \n"\r
414                 "cmp    r4, #4                                  \n"\r
415                 "bne    reg2_error_loop                 \n"\r
416                 "cmp    r5, #5                                  \n"\r
417                 "bne    reg2_error_loop                 \n"\r
418                 "cmp    r6, #6                                  \n"\r
419                 "bne    reg2_error_loop                 \n"\r
420                 "cmp    r7, #7                                  \n"\r
421                 "bne    reg2_error_loop                 \n"\r
422                 "cmp    r8, #8                                  \n"\r
423                 "bne    reg2_error_loop                 \n"\r
424                 "cmp    r9, #9                                  \n"\r
425                 "bne    reg2_error_loop                 \n"\r
426                 "cmp    r10, #10                                \n"\r
427                 "bne    reg2_error_loop                 \n"\r
428                 "cmp    r11, #11                                \n"\r
429                 "bne    reg2_error_loop                 \n"\r
430                 "cmp    r12, #12                                \n"\r
431                 "bne    reg2_error_loop                 \n"\r
432 \r
433                 /* Increment the loop counter to indicate this test is still functioning\r
434                 correctly. */\r
435                 "push { r0-r1 }                                 \n"\r
436                 "ldr    r0, =ulRegTest2LoopCounter      \n"\r
437                 "ldr r1, [r0]                                   \n"\r
438                 "adds r1, r1, #1                                \n"\r
439                 "str r1, [r0]                                   \n"\r
440 \r
441                 /* Yield to increase test coverage. */\r
442                 "movs r0, #0x01                                 \n"\r
443                 "ldr r1, =0xe000ed04                    \n" /*NVIC_INT_CTRL */\r
444                 "lsl r0, r0, #28                                \n" /* Shift to PendSV bit */\r
445                 "str r0, [r1]                                   \n"\r
446                 "dsb                                                    \n"\r
447 \r
448                 "pop { r0-r1 }                                  \n"\r
449 \r
450                 /* Start again. */\r
451                 "b reg2_loop                                    \n"\r
452 \r
453         "reg2_error_loop:                                       \n"\r
454                 /* If this line is hit then there was an error in a core register value.\r
455                 This loop ensures the loop counter variable stops incrementing. */\r
456                 "b reg2_error_loop                              \n"\r
457                 \r
458         ); /* __asm volatile */\r
459 }\r
460 /*-----------------------------------------------------------*/\r
461 \r