]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTUS_APS3_GCC/Demo/RegTest.c
Update version numbers in preparation for V8.2.0 release candidate 1.
[freertos] / FreeRTOS / Demo / CORTUS_APS3_GCC / Demo / RegTest.c
1 /*\r
2     FreeRTOS V8.2.0rc1 - Copyright (C) 2014 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     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
14     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
15     >>!   obliged to provide the source code for proprietary components     !<<\r
16     >>!   outside of the FreeRTOS kernel.                                   !<<\r
17 \r
18     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
19     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
20     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
21     link: http://www.freertos.org/a00114.html\r
22 \r
23     1 tab == 4 spaces!\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    Having a problem?  Start by reading the FAQ "My application does   *\r
28      *    not run, what could be wrong?".  Have you defined configASSERT()?  *\r
29      *                                                                       *\r
30      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
31      *                                                                       *\r
32     ***************************************************************************\r
33 \r
34     ***************************************************************************\r
35      *                                                                       *\r
36      *    FreeRTOS provides completely free yet professionally developed,    *\r
37      *    robust, strictly quality controlled, supported, and cross          *\r
38      *    platform software that is more than just the market leader, it     *\r
39      *    is the industry's de facto standard.                               *\r
40      *                                                                       *\r
41      *    Help yourself get started quickly while simultaneously helping     *\r
42      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
43      *    tutorial book, reference manual, or both:                          *\r
44      *    http://www.FreeRTOS.org/Documentation                              *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     ***************************************************************************\r
49      *                                                                       *\r
50      *   Investing in training allows your team to be as productive as       *\r
51      *   possible as early as possible, lowering your overall development    *\r
52      *   cost, and enabling you to bring a more robust product to market     *\r
53      *   earlier than would otherwise be possible.  Richard Barry is both    *\r
54      *   the architect and key author of FreeRTOS, and so also the world's   *\r
55      *   leading authority on what is the world's most popular real time     *\r
56      *   kernel for deeply embedded MCU designs.  Obtaining your training    *\r
57      *   from Richard ensures your team will gain directly from his in-depth *\r
58      *   product knowledge and years of usage experience.  Contact Real Time *\r
59      *   Engineers Ltd to enquire about the FreeRTOS Masterclass, presented  *\r
60      *   by Richard Barry:  http://www.FreeRTOS.org/contact\r
61      *                                                                       *\r
62     ***************************************************************************\r
63 \r
64     ***************************************************************************\r
65      *                                                                       *\r
66      *    You are receiving this top quality software for free.  Please play *\r
67      *    fair and reciprocate by reporting any suspected issues and         *\r
68      *    participating in the community forum:                              *\r
69      *    http://www.FreeRTOS.org/support                                    *\r
70      *                                                                       *\r
71      *    Thank you!                                                         *\r
72      *                                                                       *\r
73     ***************************************************************************\r
74 \r
75     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
76     license and Real Time Engineers Ltd. contact details.\r
77 \r
78     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
79     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
80     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
81 \r
82     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
83     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
84 \r
85     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
86     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
87     licenses offer ticketed support, indemnification and commercial middleware.\r
88 \r
89     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
90     engineered and independently SIL3 certified version for use in safety and\r
91     mission critical applications that require provable dependability.\r
92 \r
93     1 tab == 4 spaces!\r
94 */\r
95 \r
96 #include "FreeRTOS.h"\r
97 #include "task.h"\r
98 \r
99 /*\r
100  * Two test tasks that fill the CPU registers with known values before\r
101  * continuously looping round checking that each register still contains its\r
102  * expected value.  Both tasks use a separate set of values, with an incorrect\r
103  * value being found at any time being indicative of an error in the context\r
104  * switch mechanism.  One of the tasks uses a yield instruction to increase the\r
105  * test coverage.  The nature of these tasks necessitates that they are written\r
106  * in assembly code.\r
107  */\r
108 static void vRegTest1( void *pvParameters );\r
109 static void vRegTest2( void *pvParameters );\r
110 \r
111 /* Counters used to ensure the tasks are still running. */\r
112 static volatile unsigned long ulRegTest1Counter = 0UL, ulRegTest2Counter = 0UL;\r
113 \r
114 /*-----------------------------------------------------------*/\r
115 \r
116 void vStartRegTestTasks( void )\r
117 {\r
118         xTaskCreate( vRegTest1, "RTest1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
119         xTaskCreate( vRegTest2, "RTest1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
120 }\r
121 /*-----------------------------------------------------------*/\r
122 \r
123 static void vRegTest1( void *pvParameters )\r
124 {\r
125         __asm volatile\r
126         (\r
127                 "       mov             r2, #0x02                                                       \n" /* Fill the registers with known values, r0 is always 0 and r1 is the stack pointer. */\r
128                 "       mov             r3, #0x03                                                       \n"\r
129                 "       mov             r4, #0x04                                                       \n"\r
130                 "       mov             r5, #0x05                                                       \n"\r
131                 "       mov             r6, #0x06                                                       \n"\r
132                 "       mov             r7, #0x07                                                       \n"\r
133                 "       mov             r8, #0x08                                                       \n"\r
134                 "       mov             r9, #0x09                                                       \n"\r
135                 "       mov             r10, #0x0a                                                      \n"\r
136                 "       mov             r11, #0x0b                                                      \n"\r
137                 "       mov             r12, #0x0c                                                      \n"\r
138                 "       mov             r13, #0x0d                                                      \n"\r
139                 "       mov             r14, #0x0e                                                      \n"\r
140                 "       mov             r15, #0x0f                                                      \n"\r
141                 "                                                                                               \n"\r
142                 "reg_check_loop_1:                                                              \n"\r
143                 "       trap    #31                                                                     \n"\r
144                 "       cmp             r2, #0x02                                                       \n" /* Check that each register still contains the expected value, jump to an infinite loop if an error is found. */\r
145                 "       bne.s   reg_check_error_1                                       \n"\r
146                 "       cmp             r3, #0x03                                                       \n"\r
147                 "       bne.s   reg_check_error_1                                       \n"\r
148                 "       cmp             r4, #0x04                                                       \n"\r
149                 "       bne.s   reg_check_error_1                                       \n"\r
150                 "       cmp             r5, #0x05                                                       \n"\r
151                 "       bne.s   reg_check_error_1                                       \n"\r
152                 "       cmp             r6, #0x06                                                       \n"\r
153                 "       bne.s   reg_check_error_1                                       \n"\r
154                 "       cmp             r7, #0x07                                                       \n"\r
155                 "       bne.s   reg_check_error_1                                       \n"\r
156                 "       cmp             r8, #0x08                                                       \n"\r
157                 "       bne.s   reg_check_error_1                                       \n"\r
158                 "       cmp             r9, #0x09                                                       \n"\r
159                 "       bne.s   reg_check_error_1                                       \n"\r
160                 "       cmp             r10, #0x0a                                                      \n"\r
161                 "       bne.s   reg_check_error_1                                       \n"\r
162                 "       cmp             r11, #0x0b                                                      \n"\r
163                 "       bne.s   reg_check_error_1                                       \n"\r
164                 "       cmp             r12, #0x0c                                                      \n"\r
165                 "       bne.s   reg_check_error_1                                       \n"\r
166                 "       cmp             r13, #0x0d                                                      \n"\r
167                 "       bne.s   reg_check_error_1                                       \n"\r
168                 "       cmp             r14, #0x0e                                                      \n"\r
169                 "       bne.s   reg_check_error_1                                       \n"\r
170                 "       cmp             r15, #0x0f                                                      \n"\r
171                 "       bne.s   reg_check_error_1                                       \n"\r
172                 "                                                                                               \n"\r
173                 "       ld              r2, [r0]+short(ulRegTest1Counter)       \n" /* Increment the loop counter to show that this task is still running error free. */\r
174                 "       add             r2, #1                                                          \n"\r
175                 "       st              r2, [r0]+short(ulRegTest1Counter)       \n"\r
176                 "       mov             r2, #0x02                                                       \n"\r
177                 "                                                                                               \n"\r
178                 "       bra.s   reg_check_loop_1                                        \n" /* Do it all again. */\r
179                 "                                                                                               \n"\r
180                 "reg_check_error_1:                                                             \n"\r
181                         "bra.s          .                                                               \n"\r
182         );\r
183 }\r
184 /*-----------------------------------------------------------*/\r
185 \r
186 static void vRegTest2( void *pvParameters )\r
187 {\r
188         __asm volatile\r
189         (\r
190                 "       mov             r2, #0x12                                                       \n" /* Fill the registers with known values, r0 is always 0 and r1 is the stack pointer. */\r
191                 "       mov             r3, #0x13                                                       \n"\r
192                 "       mov             r4, #0x14                                                       \n"\r
193                 "       mov             r5, #0x15                                                       \n"\r
194                 "       mov             r6, #0x16                                                       \n"\r
195                 "       mov             r7, #0x17                                                       \n"\r
196                 "       mov             r8, #0x18                                                       \n"\r
197                 "       mov             r9, #0x19                                                       \n"\r
198                 "       mov             r10, #0x1a                                                      \n"\r
199                 "       mov             r11, #0x1b                                                      \n"\r
200                 "       mov             r12, #0x1c                                                      \n"\r
201                 "       mov             r13, #0x1d                                                      \n"\r
202                 "       mov             r14, #0x1e                                                      \n"\r
203                 "       mov             r15, #0x1f                                                      \n"\r
204                 "                                                                                               \n"\r
205                 "reg_check_loop_2:                                                              \n"\r
206                 "       cmp             r2, #0x12                                                       \n" /* Check that each register still contains the expected value, jump to an infinite loop if an error is found. */\r
207                 "       bne.s   reg_check_error_2                                       \n"\r
208                 "       cmp             r3, #0x13                                                       \n"\r
209                 "       bne.s   reg_check_error_2                                       \n"\r
210                 "       cmp             r4, #0x14                                                       \n"\r
211                 "       bne.s   reg_check_error_2                                       \n"\r
212                 "       cmp             r5, #0x15                                                       \n"\r
213                 "       bne.s   reg_check_error_2                                       \n"\r
214                 "       cmp             r6, #0x16                                                       \n"\r
215                 "       bne.s   reg_check_error_2                                       \n"\r
216                 "       cmp             r7, #0x17                                                       \n"\r
217                 "       bne.s   reg_check_error_2                                       \n"\r
218                 "       cmp             r8, #0x18                                                       \n"\r
219                 "       bne.s   reg_check_error_2                                       \n"\r
220                 "       cmp             r9, #0x19                                                       \n"\r
221                 "       bne.s   reg_check_error_2                                       \n"\r
222                 "       cmp             r10, #0x1a                                                      \n"\r
223                 "       bne.s   reg_check_error_2                                       \n"\r
224                 "       cmp             r11, #0x1b                                                      \n"\r
225                 "       bne.s   reg_check_error_2                                       \n"\r
226                 "       cmp             r12, #0x1c                                                      \n"\r
227                 "       bne.s   reg_check_error_2                                       \n"\r
228                 "       cmp             r13, #0x1d                                                      \n"\r
229                 "       bne.s   reg_check_error_2                                       \n"\r
230                 "       cmp             r14, #0x1e                                                      \n"\r
231                 "       bne.s   reg_check_error_2                                       \n"\r
232                 "       cmp             r15, #0x1f                                                      \n"\r
233                 "       bne.s   reg_check_error_2                                       \n"\r
234                 "                                                                                               \n"\r
235                 "       ld              r2, [r0]+short(ulRegTest2Counter)       \n" /* Increment the loop counter to show that this task is still running error free. */\r
236                 "       add             r2, #1                                                          \n"\r
237                 "       st              r2, [r0]+short(ulRegTest2Counter)       \n"\r
238                 "       mov             r2, #0x12                                                       \n"\r
239                 "                                                                                               \n"\r
240                 "       bra.s   reg_check_loop_2                                        \n" /* Do it all again. */\r
241                 "                                                                                               \n"\r
242                 "reg_check_error_2:                                                             \n"\r
243                         "bra.s          .                                                               \n"\r
244         );\r
245 }\r
246 /*-----------------------------------------------------------*/\r
247 \r
248 portBASE_TYPE xAreRegTestTasksStillRunning( void )\r
249 {\r
250 static unsigned long ulLastCounter1 = 0UL, ulLastCounter2 = 0UL;\r
251 long lReturn;\r
252 \r
253         /* Check that both loop counters are still incrementing, indicating that\r
254         both reg test tasks are still running error free. */\r
255         if( ulLastCounter1 == ulRegTest1Counter )\r
256         {\r
257                 lReturn = pdFAIL;\r
258         }\r
259         else if( ulLastCounter2 == ulRegTest2Counter )\r
260         {\r
261                 lReturn = pdFAIL;\r
262         }\r
263         else\r
264         {\r
265                 lReturn = pdPASS;\r
266         }\r
267 \r
268         ulLastCounter1 = ulRegTest1Counter;\r
269         ulLastCounter2 = ulRegTest2Counter;\r
270 \r
271         return lReturn;\r
272 }\r