]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTUS_APS3_GCC/Demo/RegTest.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Demo / CORTUS_APS3_GCC / Demo / RegTest.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\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
11  *\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
14  *\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
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 #include "FreeRTOS.h"\r
29 #include "task.h"\r
30 \r
31 /*\r
32  * Two test tasks that fill the CPU registers with known values before\r
33  * continuously looping round checking that each register still contains its\r
34  * expected value.  Both tasks use a separate set of values, with an incorrect\r
35  * value being found at any time being indicative of an error in the context\r
36  * switch mechanism.  One of the tasks uses a yield instruction to increase the\r
37  * test coverage.  The nature of these tasks necessitates that they are written\r
38  * in assembly code.\r
39  */\r
40 static void vRegTest1( void *pvParameters );\r
41 static void vRegTest2( void *pvParameters );\r
42 \r
43 /* Counters used to ensure the tasks are still running. */\r
44 static volatile unsigned long ulRegTest1Counter = 0UL, ulRegTest2Counter = 0UL;\r
45 \r
46 /*-----------------------------------------------------------*/\r
47 \r
48 void vStartRegTestTasks( void )\r
49 {\r
50         xTaskCreate( vRegTest1, "RTest1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
51         xTaskCreate( vRegTest2, "RTest1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
52 }\r
53 /*-----------------------------------------------------------*/\r
54 \r
55 static void vRegTest1( void *pvParameters )\r
56 {\r
57         __asm volatile\r
58         (\r
59                 "       mov             r2, #0x02                                                       \n" /* Fill the registers with known values, r0 is always 0 and r1 is the stack pointer. */\r
60                 "       mov             r3, #0x03                                                       \n"\r
61                 "       mov             r4, #0x04                                                       \n"\r
62                 "       mov             r5, #0x05                                                       \n"\r
63                 "       mov             r6, #0x06                                                       \n"\r
64                 "       mov             r7, #0x07                                                       \n"\r
65                 "       mov             r8, #0x08                                                       \n"\r
66                 "       mov             r9, #0x09                                                       \n"\r
67                 "       mov             r10, #0x0a                                                      \n"\r
68                 "       mov             r11, #0x0b                                                      \n"\r
69                 "       mov             r12, #0x0c                                                      \n"\r
70                 "       mov             r13, #0x0d                                                      \n"\r
71                 "       mov             r14, #0x0e                                                      \n"\r
72                 "       mov             r15, #0x0f                                                      \n"\r
73                 "                                                                                               \n"\r
74                 "reg_check_loop_1:                                                              \n"\r
75                 "       trap    #31                                                                     \n"\r
76                 "       cmp             r2, #0x02                                                       \n" /* Check that each register still contains the expected value, jump to an infinite loop if an error is found. */\r
77                 "       bne.s   reg_check_error_1                                       \n"\r
78                 "       cmp             r3, #0x03                                                       \n"\r
79                 "       bne.s   reg_check_error_1                                       \n"\r
80                 "       cmp             r4, #0x04                                                       \n"\r
81                 "       bne.s   reg_check_error_1                                       \n"\r
82                 "       cmp             r5, #0x05                                                       \n"\r
83                 "       bne.s   reg_check_error_1                                       \n"\r
84                 "       cmp             r6, #0x06                                                       \n"\r
85                 "       bne.s   reg_check_error_1                                       \n"\r
86                 "       cmp             r7, #0x07                                                       \n"\r
87                 "       bne.s   reg_check_error_1                                       \n"\r
88                 "       cmp             r8, #0x08                                                       \n"\r
89                 "       bne.s   reg_check_error_1                                       \n"\r
90                 "       cmp             r9, #0x09                                                       \n"\r
91                 "       bne.s   reg_check_error_1                                       \n"\r
92                 "       cmp             r10, #0x0a                                                      \n"\r
93                 "       bne.s   reg_check_error_1                                       \n"\r
94                 "       cmp             r11, #0x0b                                                      \n"\r
95                 "       bne.s   reg_check_error_1                                       \n"\r
96                 "       cmp             r12, #0x0c                                                      \n"\r
97                 "       bne.s   reg_check_error_1                                       \n"\r
98                 "       cmp             r13, #0x0d                                                      \n"\r
99                 "       bne.s   reg_check_error_1                                       \n"\r
100                 "       cmp             r14, #0x0e                                                      \n"\r
101                 "       bne.s   reg_check_error_1                                       \n"\r
102                 "       cmp             r15, #0x0f                                                      \n"\r
103                 "       bne.s   reg_check_error_1                                       \n"\r
104                 "                                                                                               \n"\r
105                 "       ld              r2, [r0]+short(ulRegTest1Counter)       \n" /* Increment the loop counter to show that this task is still running error free. */\r
106                 "       add             r2, #1                                                          \n"\r
107                 "       st              r2, [r0]+short(ulRegTest1Counter)       \n"\r
108                 "       mov             r2, #0x02                                                       \n"\r
109                 "                                                                                               \n"\r
110                 "       bra.s   reg_check_loop_1                                        \n" /* Do it all again. */\r
111                 "                                                                                               \n"\r
112                 "reg_check_error_1:                                                             \n"\r
113                         "bra.s          .                                                               \n"\r
114         );\r
115 }\r
116 /*-----------------------------------------------------------*/\r
117 \r
118 static void vRegTest2( void *pvParameters )\r
119 {\r
120         __asm volatile\r
121         (\r
122                 "       mov             r2, #0x12                                                       \n" /* Fill the registers with known values, r0 is always 0 and r1 is the stack pointer. */\r
123                 "       mov             r3, #0x13                                                       \n"\r
124                 "       mov             r4, #0x14                                                       \n"\r
125                 "       mov             r5, #0x15                                                       \n"\r
126                 "       mov             r6, #0x16                                                       \n"\r
127                 "       mov             r7, #0x17                                                       \n"\r
128                 "       mov             r8, #0x18                                                       \n"\r
129                 "       mov             r9, #0x19                                                       \n"\r
130                 "       mov             r10, #0x1a                                                      \n"\r
131                 "       mov             r11, #0x1b                                                      \n"\r
132                 "       mov             r12, #0x1c                                                      \n"\r
133                 "       mov             r13, #0x1d                                                      \n"\r
134                 "       mov             r14, #0x1e                                                      \n"\r
135                 "       mov             r15, #0x1f                                                      \n"\r
136                 "                                                                                               \n"\r
137                 "reg_check_loop_2:                                                              \n"\r
138                 "       cmp             r2, #0x12                                                       \n" /* Check that each register still contains the expected value, jump to an infinite loop if an error is found. */\r
139                 "       bne.s   reg_check_error_2                                       \n"\r
140                 "       cmp             r3, #0x13                                                       \n"\r
141                 "       bne.s   reg_check_error_2                                       \n"\r
142                 "       cmp             r4, #0x14                                                       \n"\r
143                 "       bne.s   reg_check_error_2                                       \n"\r
144                 "       cmp             r5, #0x15                                                       \n"\r
145                 "       bne.s   reg_check_error_2                                       \n"\r
146                 "       cmp             r6, #0x16                                                       \n"\r
147                 "       bne.s   reg_check_error_2                                       \n"\r
148                 "       cmp             r7, #0x17                                                       \n"\r
149                 "       bne.s   reg_check_error_2                                       \n"\r
150                 "       cmp             r8, #0x18                                                       \n"\r
151                 "       bne.s   reg_check_error_2                                       \n"\r
152                 "       cmp             r9, #0x19                                                       \n"\r
153                 "       bne.s   reg_check_error_2                                       \n"\r
154                 "       cmp             r10, #0x1a                                                      \n"\r
155                 "       bne.s   reg_check_error_2                                       \n"\r
156                 "       cmp             r11, #0x1b                                                      \n"\r
157                 "       bne.s   reg_check_error_2                                       \n"\r
158                 "       cmp             r12, #0x1c                                                      \n"\r
159                 "       bne.s   reg_check_error_2                                       \n"\r
160                 "       cmp             r13, #0x1d                                                      \n"\r
161                 "       bne.s   reg_check_error_2                                       \n"\r
162                 "       cmp             r14, #0x1e                                                      \n"\r
163                 "       bne.s   reg_check_error_2                                       \n"\r
164                 "       cmp             r15, #0x1f                                                      \n"\r
165                 "       bne.s   reg_check_error_2                                       \n"\r
166                 "                                                                                               \n"\r
167                 "       ld              r2, [r0]+short(ulRegTest2Counter)       \n" /* Increment the loop counter to show that this task is still running error free. */\r
168                 "       add             r2, #1                                                          \n"\r
169                 "       st              r2, [r0]+short(ulRegTest2Counter)       \n"\r
170                 "       mov             r2, #0x12                                                       \n"\r
171                 "                                                                                               \n"\r
172                 "       bra.s   reg_check_loop_2                                        \n" /* Do it all again. */\r
173                 "                                                                                               \n"\r
174                 "reg_check_error_2:                                                             \n"\r
175                         "bra.s          .                                                               \n"\r
176         );\r
177 }\r
178 /*-----------------------------------------------------------*/\r
179 \r
180 portBASE_TYPE xAreRegTestTasksStillRunning( void )\r
181 {\r
182 static unsigned long ulLastCounter1 = 0UL, ulLastCounter2 = 0UL;\r
183 long lReturn;\r
184 \r
185         /* Check that both loop counters are still incrementing, indicating that\r
186         both reg test tasks are still running error free. */\r
187         if( ulLastCounter1 == ulRegTest1Counter )\r
188         {\r
189                 lReturn = pdFAIL;\r
190         }\r
191         else if( ulLastCounter2 == ulRegTest2Counter )\r
192         {\r
193                 lReturn = pdFAIL;\r
194         }\r
195         else\r
196         {\r
197                 lReturn = pdPASS;\r
198         }\r
199 \r
200         ulLastCounter1 = ulRegTest1Counter;\r
201         ulLastCounter2 = ulRegTest2Counter;\r
202 \r
203         return lReturn;\r
204 }\r