]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTUS_APS3_GCC/Demo/RegTest.c
Update version number to 9.0.0rc2.
[freertos] / FreeRTOS / Demo / CORTUS_APS3_GCC / Demo / RegTest.c
1 /*\r
2     FreeRTOS V9.0.0rc2 - 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 #include "FreeRTOS.h"\r
71 #include "task.h"\r
72 \r
73 /*\r
74  * Two test tasks that fill the CPU registers with known values before\r
75  * continuously looping round checking that each register still contains its\r
76  * expected value.  Both tasks use a separate set of values, with an incorrect\r
77  * value being found at any time being indicative of an error in the context\r
78  * switch mechanism.  One of the tasks uses a yield instruction to increase the\r
79  * test coverage.  The nature of these tasks necessitates that they are written\r
80  * in assembly code.\r
81  */\r
82 static void vRegTest1( void *pvParameters );\r
83 static void vRegTest2( void *pvParameters );\r
84 \r
85 /* Counters used to ensure the tasks are still running. */\r
86 static volatile unsigned long ulRegTest1Counter = 0UL, ulRegTest2Counter = 0UL;\r
87 \r
88 /*-----------------------------------------------------------*/\r
89 \r
90 void vStartRegTestTasks( void )\r
91 {\r
92         xTaskCreate( vRegTest1, "RTest1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
93         xTaskCreate( vRegTest2, "RTest1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
94 }\r
95 /*-----------------------------------------------------------*/\r
96 \r
97 static void vRegTest1( void *pvParameters )\r
98 {\r
99         __asm volatile\r
100         (\r
101                 "       mov             r2, #0x02                                                       \n" /* Fill the registers with known values, r0 is always 0 and r1 is the stack pointer. */\r
102                 "       mov             r3, #0x03                                                       \n"\r
103                 "       mov             r4, #0x04                                                       \n"\r
104                 "       mov             r5, #0x05                                                       \n"\r
105                 "       mov             r6, #0x06                                                       \n"\r
106                 "       mov             r7, #0x07                                                       \n"\r
107                 "       mov             r8, #0x08                                                       \n"\r
108                 "       mov             r9, #0x09                                                       \n"\r
109                 "       mov             r10, #0x0a                                                      \n"\r
110                 "       mov             r11, #0x0b                                                      \n"\r
111                 "       mov             r12, #0x0c                                                      \n"\r
112                 "       mov             r13, #0x0d                                                      \n"\r
113                 "       mov             r14, #0x0e                                                      \n"\r
114                 "       mov             r15, #0x0f                                                      \n"\r
115                 "                                                                                               \n"\r
116                 "reg_check_loop_1:                                                              \n"\r
117                 "       trap    #31                                                                     \n"\r
118                 "       cmp             r2, #0x02                                                       \n" /* Check that each register still contains the expected value, jump to an infinite loop if an error is found. */\r
119                 "       bne.s   reg_check_error_1                                       \n"\r
120                 "       cmp             r3, #0x03                                                       \n"\r
121                 "       bne.s   reg_check_error_1                                       \n"\r
122                 "       cmp             r4, #0x04                                                       \n"\r
123                 "       bne.s   reg_check_error_1                                       \n"\r
124                 "       cmp             r5, #0x05                                                       \n"\r
125                 "       bne.s   reg_check_error_1                                       \n"\r
126                 "       cmp             r6, #0x06                                                       \n"\r
127                 "       bne.s   reg_check_error_1                                       \n"\r
128                 "       cmp             r7, #0x07                                                       \n"\r
129                 "       bne.s   reg_check_error_1                                       \n"\r
130                 "       cmp             r8, #0x08                                                       \n"\r
131                 "       bne.s   reg_check_error_1                                       \n"\r
132                 "       cmp             r9, #0x09                                                       \n"\r
133                 "       bne.s   reg_check_error_1                                       \n"\r
134                 "       cmp             r10, #0x0a                                                      \n"\r
135                 "       bne.s   reg_check_error_1                                       \n"\r
136                 "       cmp             r11, #0x0b                                                      \n"\r
137                 "       bne.s   reg_check_error_1                                       \n"\r
138                 "       cmp             r12, #0x0c                                                      \n"\r
139                 "       bne.s   reg_check_error_1                                       \n"\r
140                 "       cmp             r13, #0x0d                                                      \n"\r
141                 "       bne.s   reg_check_error_1                                       \n"\r
142                 "       cmp             r14, #0x0e                                                      \n"\r
143                 "       bne.s   reg_check_error_1                                       \n"\r
144                 "       cmp             r15, #0x0f                                                      \n"\r
145                 "       bne.s   reg_check_error_1                                       \n"\r
146                 "                                                                                               \n"\r
147                 "       ld              r2, [r0]+short(ulRegTest1Counter)       \n" /* Increment the loop counter to show that this task is still running error free. */\r
148                 "       add             r2, #1                                                          \n"\r
149                 "       st              r2, [r0]+short(ulRegTest1Counter)       \n"\r
150                 "       mov             r2, #0x02                                                       \n"\r
151                 "                                                                                               \n"\r
152                 "       bra.s   reg_check_loop_1                                        \n" /* Do it all again. */\r
153                 "                                                                                               \n"\r
154                 "reg_check_error_1:                                                             \n"\r
155                         "bra.s          .                                                               \n"\r
156         );\r
157 }\r
158 /*-----------------------------------------------------------*/\r
159 \r
160 static void vRegTest2( void *pvParameters )\r
161 {\r
162         __asm volatile\r
163         (\r
164                 "       mov             r2, #0x12                                                       \n" /* Fill the registers with known values, r0 is always 0 and r1 is the stack pointer. */\r
165                 "       mov             r3, #0x13                                                       \n"\r
166                 "       mov             r4, #0x14                                                       \n"\r
167                 "       mov             r5, #0x15                                                       \n"\r
168                 "       mov             r6, #0x16                                                       \n"\r
169                 "       mov             r7, #0x17                                                       \n"\r
170                 "       mov             r8, #0x18                                                       \n"\r
171                 "       mov             r9, #0x19                                                       \n"\r
172                 "       mov             r10, #0x1a                                                      \n"\r
173                 "       mov             r11, #0x1b                                                      \n"\r
174                 "       mov             r12, #0x1c                                                      \n"\r
175                 "       mov             r13, #0x1d                                                      \n"\r
176                 "       mov             r14, #0x1e                                                      \n"\r
177                 "       mov             r15, #0x1f                                                      \n"\r
178                 "                                                                                               \n"\r
179                 "reg_check_loop_2:                                                              \n"\r
180                 "       cmp             r2, #0x12                                                       \n" /* Check that each register still contains the expected value, jump to an infinite loop if an error is found. */\r
181                 "       bne.s   reg_check_error_2                                       \n"\r
182                 "       cmp             r3, #0x13                                                       \n"\r
183                 "       bne.s   reg_check_error_2                                       \n"\r
184                 "       cmp             r4, #0x14                                                       \n"\r
185                 "       bne.s   reg_check_error_2                                       \n"\r
186                 "       cmp             r5, #0x15                                                       \n"\r
187                 "       bne.s   reg_check_error_2                                       \n"\r
188                 "       cmp             r6, #0x16                                                       \n"\r
189                 "       bne.s   reg_check_error_2                                       \n"\r
190                 "       cmp             r7, #0x17                                                       \n"\r
191                 "       bne.s   reg_check_error_2                                       \n"\r
192                 "       cmp             r8, #0x18                                                       \n"\r
193                 "       bne.s   reg_check_error_2                                       \n"\r
194                 "       cmp             r9, #0x19                                                       \n"\r
195                 "       bne.s   reg_check_error_2                                       \n"\r
196                 "       cmp             r10, #0x1a                                                      \n"\r
197                 "       bne.s   reg_check_error_2                                       \n"\r
198                 "       cmp             r11, #0x1b                                                      \n"\r
199                 "       bne.s   reg_check_error_2                                       \n"\r
200                 "       cmp             r12, #0x1c                                                      \n"\r
201                 "       bne.s   reg_check_error_2                                       \n"\r
202                 "       cmp             r13, #0x1d                                                      \n"\r
203                 "       bne.s   reg_check_error_2                                       \n"\r
204                 "       cmp             r14, #0x1e                                                      \n"\r
205                 "       bne.s   reg_check_error_2                                       \n"\r
206                 "       cmp             r15, #0x1f                                                      \n"\r
207                 "       bne.s   reg_check_error_2                                       \n"\r
208                 "                                                                                               \n"\r
209                 "       ld              r2, [r0]+short(ulRegTest2Counter)       \n" /* Increment the loop counter to show that this task is still running error free. */\r
210                 "       add             r2, #1                                                          \n"\r
211                 "       st              r2, [r0]+short(ulRegTest2Counter)       \n"\r
212                 "       mov             r2, #0x12                                                       \n"\r
213                 "                                                                                               \n"\r
214                 "       bra.s   reg_check_loop_2                                        \n" /* Do it all again. */\r
215                 "                                                                                               \n"\r
216                 "reg_check_error_2:                                                             \n"\r
217                         "bra.s          .                                                               \n"\r
218         );\r
219 }\r
220 /*-----------------------------------------------------------*/\r
221 \r
222 portBASE_TYPE xAreRegTestTasksStillRunning( void )\r
223 {\r
224 static unsigned long ulLastCounter1 = 0UL, ulLastCounter2 = 0UL;\r
225 long lReturn;\r
226 \r
227         /* Check that both loop counters are still incrementing, indicating that\r
228         both reg test tasks are still running error free. */\r
229         if( ulLastCounter1 == ulRegTest1Counter )\r
230         {\r
231                 lReturn = pdFAIL;\r
232         }\r
233         else if( ulLastCounter2 == ulRegTest2Counter )\r
234         {\r
235                 lReturn = pdFAIL;\r
236         }\r
237         else\r
238         {\r
239                 lReturn = pdPASS;\r
240         }\r
241 \r
242         ulLastCounter1 = ulRegTest1Counter;\r
243         ulLastCounter2 = ulRegTest2Counter;\r
244 \r
245         return lReturn;\r
246 }\r