]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Spartan-6_EthernetLite/SDKProjects/RTOSDemo/RegisterTests.c
Change version number in common files within the FreeRTOS-plus directory and check...
[freertos] / FreeRTOS / Demo / MicroBlaze_Spartan-6_EthernetLite / SDKProjects / RTOSDemo / RegisterTests.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 /* Scheduler includes. */\r
76 #include "FreeRTOS.h"\r
77 #include "task.h"\r
78 \r
79 /*\r
80  * The register test task as described in the comments at the top of main-full.c.\r
81  */\r
82 void vRegisterTest1( void *pvParameters );\r
83 void vRegisterTest2( void *pvParameters );\r
84 \r
85 /* Variables that are incremented on each iteration of the reg test tasks -\r
86 provided the tasks have not reported any errors.  The check timer inspects these\r
87 variables to ensure they are still incrementing as expected.  If a variable\r
88 stops incrementing then it is likely that its associate task has stalled or\r
89 detected an error. */\r
90 volatile unsigned long ulRegTest1CycleCount = 0UL, ulRegTest2CycleCount = 0UL;\r
91 \r
92 /*-----------------------------------------------------------*/\r
93 \r
94 void vRegisterTest1( void *pvParameters )\r
95 {\r
96         /* This task uses an infinite loop that is implemented in the assembly \r
97         code.\r
98         \r
99         First fill the relevant registers with known values. */\r
100         asm volatile (  "       addi r3, r0, 3          \n\t" \\r
101                                         "       addi r4, r0, 4          \n\t" \\r
102                                         "       addi r6, r0, 6          \n\t" \\r
103                                         "       addi r7, r0, 7          \n\t" \\r
104                                         "       addi r8, r0, 8          \n\t" \\r
105                                         "       addi r9, r0, 9          \n\t" \\r
106                                         "       addi r10, r0, 10        \n\t" \\r
107                                         "       addi r11, r0, 11        \n\t" \\r
108                                         "       addi r12, r0, 12        \n\t" \\r
109                                         "       addi r16, r0, 16        \n\t" \\r
110                                         "       addi r19, r0, 19        \n\t" \\r
111                                         "       addi r20, r0, 20        \n\t" \\r
112                                         "       addi r21, r0, 21        \n\t" \\r
113                                         "       addi r22, r0, 22        \n\t" \\r
114                                         "       addi r23, r0, 23        \n\t" \\r
115                                         "       addi r24, r0, 24        \n\t" \\r
116                                         "       addi r25, r0, 25        \n\t" \\r
117                                         "       addi r26, r0, 26        \n\t" \\r
118                                         "       addi r27, r0, 27        \n\t" \\r
119                                         "       addi r28, r0, 28        \n\t" \\r
120                                         "       addi r29, r0, 29        \n\t" \\r
121                                         "       addi r30, r0, 30        \n\t" \\r
122                                         "       addi r31, r0, 31        \n\t"\r
123                                 );\r
124 \r
125         /* Now test the register values to ensure they contain the same value that\r
126         was written to them above.       This task will get preempted frequently so \r
127         other tasks are likely to have executed since the register values were \r
128         written.  If any register contains an unexpected value then the task will\r
129         branch to Error_Loop_1, which in turn prevents it from incrementing its\r
130         loop counter, enabling the check timer to determine that all is not as it\r
131         should be. */\r
132 \r
133         asm volatile (  "Loop_Start_1:                          \n\t" \\r
134                                         "       xori r18, r3, 3                 \n\t" \\r
135                                         "       bnei r18, Error_Loop_1  \n\t" \\r
136                                         "       xori r18, r4, 4                 \n\t" \\r
137                                         "       bnei r18, Error_Loop_1  \n\t" \\r
138                                         "       xori r18, r6, 6                 \n\t" \\r
139                                         "       bnei r18, Error_Loop_1  \n\t" \\r
140                                         "       xori r18, r7, 7                 \n\t" \\r
141                                         "       bnei r18, Error_Loop_1  \n\t" \\r
142                                         "       xori r18, r8, 8                 \n\t" \\r
143                                         "       bnei r18, Error_Loop_1  \n\t" \\r
144                                         "       xori r18, r9, 9                 \n\t" \\r
145                                         "       bnei r18, Error_Loop_1  \n\t" \\r
146                                         "       xori r18, r10, 10               \n\t" \\r
147                                         "       bnei r18, Error_Loop_1  \n\t" \\r
148                                         "       xori r18, r11, 11               \n\t" \\r
149                                         "       bnei r18, Error_Loop_1  \n\t" \\r
150                                         "       xori r18, r12, 12               \n\t" \\r
151                                         "       bnei r18, Error_Loop_1  \n\t" \\r
152                                         "       xori r18, r16, 16               \n\t" \\r
153                                         "       bnei r18, Error_Loop_1  \n\t" \\r
154                                         "       xori r18, r19, 19               \n\t" \\r
155                                         "       bnei r18, Error_Loop_1  \n\t" \\r
156                                         "       xori r18, r20, 20               \n\t" \\r
157                                         "       bnei r18, Error_Loop_1  \n\t" \\r
158                                         "       xori r18, r21, 21               \n\t" \\r
159                                         "       bnei r18, Error_Loop_1  \n\t" \\r
160                                         "       xori r18, r22, 22               \n\t" \\r
161                                         "       bnei r18, Error_Loop_1  \n\t" \\r
162                                         "       xori r18, r23, 23               \n\t" \\r
163                                         "       bnei r18, Error_Loop_1  \n\t" \\r
164                                         "       xori r18, r24, 24               \n\t" \\r
165                                         "       bnei r18, Error_Loop_1  \n\t" \\r
166                                         "       xori r18, r25, 25               \n\t" \\r
167                                         "       bnei r18, Error_Loop_1  \n\t" \\r
168                                         "       xori r18, r26, 26               \n\t" \\r
169                                         "       bnei r18, Error_Loop_1  \n\t" \\r
170                                         "       xori r18, r27, 27               \n\t" \\r
171                                         "       bnei r18, Error_Loop_1  \n\t" \\r
172                                         "       xori r18, r28, 28               \n\t" \\r
173                                         "       bnei r18, Error_Loop_1  \n\t" \\r
174                                         "       xori r18, r29, 29               \n\t" \\r
175                                         "       bnei r18, Error_Loop_1  \n\t" \\r
176                                         "       xori r18, r30, 30               \n\t" \\r
177                                         "       bnei r18, Error_Loop_1  \n\t" \\r
178                                         "       xori r18, r31, 31               \n\t" \\r
179                                         "       bnei r18, Error_Loop_1  \n\t"\r
180                                  );\r
181 \r
182         /* If this task has not branched to the error loop, then everything is ok,\r
183         and the check variable can be incremented to indicate that this task\r
184         is still running.  Then, brach back to the top to check the register\r
185         contents again. */\r
186         asm volatile (  "       lwi r18, r0, ulRegTest1CycleCount       \n\t" \\r
187                                         "       addik r18, r18, 1                                       \n\t" \\r
188                                         "       swi r18, r0, ulRegTest1CycleCount       \n\t" \\r
189                                         "                                                                               \n\t" \\r
190                                         "       bri Loop_Start_1 "\r
191                                  );\r
192 \r
193          /* The test function will branch here if it discovers an error.  This part\r
194         of the code just sits in a NULL loop, which prevents the check variable\r
195         incrementing any further to allow the check timer to recognize that this\r
196         test has failed. */\r
197         asm volatile (  "Error_Loop_1:                  \n\t" \\r
198                                         "       bri 0                           \n\t" \\r
199                                         "       nop                                     \n\t" \\r
200                                  );\r
201 \r
202         ( void ) pvParameters;\r
203 }\r
204 /*-----------------------------------------------------------*/\r
205 \r
206 void vRegisterTest2( void *pvParameters )\r
207 {\r
208         /* This task uses an infinite loop that is implemented in the assembly \r
209         code.\r
210         \r
211         First fill the registers with known values. */\r
212         asm volatile (  "       addi r16, r0, 1016      \n\t" \\r
213                                         "       addi r19, r0, 1019      \n\t" \\r
214                                         "       addi r20, r0, 1020      \n\t" \\r
215                                         "       addi r21, r0, 1021      \n\t" \\r
216                                         "       addi r22, r0, 1022      \n\t" \\r
217                                         "       addi r23, r0, 1023      \n\t" \\r
218                                         "       addi r24, r0, 1024      \n\t" \\r
219                                         "       addi r25, r0, 1025      \n\t" \\r
220                                         "       addi r26, r0, 1026      \n\t" \\r
221                                         "       addi r27, r0, 1027      \n\t" \\r
222                                         "       addi r28, r0, 1028      \n\t" \\r
223                                         "       addi r29, r0, 1029      \n\t" \\r
224                                         "       addi r30, r0, 1030      \n\t" \\r
225                                         "       addi r31, r0, 1031      \n\t" \\r
226                                         "                                                       " \\r
227                                         "Loop_Start_2:                          "\r
228                                 );\r
229 \r
230         /* Unlike vRegisterTest1, vRegisterTest2 performs a yield.  This increases\r
231         the test coverage, but does mean volatile registers need re-loading with \r
232         their exepcted values. */\r
233         taskYIELD();\r
234 \r
235         /* taskYIELD() could have changed temporaries - set them back to those\r
236         expected by the reg test task. */\r
237         asm volatile (  "       addi r3, r0, 103        \n\t" \\r
238                                         "       addi r4, r0, 104        \n\t" \\r
239                                         "       addi r6, r0, 106        \n\t" \\r
240                                         "       addi r7, r0, 107        \n\t" \\r
241                                         "       addi r8, r0, 108        \n\t" \\r
242                                         "       addi r9, r0, 109        \n\t" \\r
243                                         "       addi r10, r0, 1010      \n\t" \\r
244                                         "       addi r11, r0, 1011      \n\t" \\r
245                                         "       addi r12, r0, 1012      \n\t" \\r
246                                 );\r
247 \r
248 \r
249         /* Now test the register values to ensure they contain the same value that\r
250         was written to them above.       This task will get preempted frequently so \r
251         other tasks are likely to have executed since the register values were \r
252         written. */\r
253         asm volatile (  "       xori r18, r3, 103               \n\t" \\r
254                                         "       bnei r18, Error_Loop_2  \n\t" \\r
255                                         "       xori r18, r4, 104               \n\t" \\r
256                                         "       bnei r18, Error_Loop_2  \n\t" \\r
257                                         "       xori r18, r6, 106               \n\t" \\r
258                                         "       bnei r18, Error_Loop_2  \n\t" \\r
259                                         "       xori r18, r7, 107               \n\t" \\r
260                                         "       bnei r18, Error_Loop_2  \n\t" \\r
261                                         "       xori r18, r8, 108               \n\t" \\r
262                                         "       bnei r18, Error_Loop_2  \n\t" \\r
263                                         "       xori r18, r9, 109               \n\t" \\r
264                                         "       bnei r18, Error_Loop_2  \n\t" \\r
265                                         "       xori r18, r10, 1010             \n\t" \\r
266                                         "       bnei r18, Error_Loop_2  \n\t" \\r
267                                         "       xori r18, r11, 1011             \n\t" \\r
268                                         "       bnei r18, Error_Loop_2  \n\t" \\r
269                                         "       xori r18, r12, 1012             \n\t" \\r
270                                         "       bnei r18, Error_Loop_2  \n\t" \\r
271                                         "       xori r18, r16, 1016             \n\t" \\r
272                                         "       bnei r18, Error_Loop_2  \n\t" \\r
273                                         "       xori r18, r19, 1019             \n\t" \\r
274                                         "       bnei r18, Error_Loop_2  \n\t" \\r
275                                         "       xori r18, r20, 1020             \n\t" \\r
276                                         "       bnei r18, Error_Loop_2  \n\t" \\r
277                                         "       xori r18, r21, 1021             \n\t" \\r
278                                         "       bnei r18, Error_Loop_2  \n\t" \\r
279                                         "       xori r18, r22, 1022             \n\t" \\r
280                                         "       bnei r18, Error_Loop_2  \n\t" \\r
281                                         "       xori r18, r23, 1023             \n\t" \\r
282                                         "       bnei r18, Error_Loop_2  \n\t" \\r
283                                         "       xori r18, r24, 1024             \n\t" \\r
284                                         "       bnei r18, Error_Loop_2  \n\t" \\r
285                                         "       xori r18, r25, 1025             \n\t" \\r
286                                         "       bnei r18, Error_Loop_2  \n\t" \\r
287                                         "       xori r18, r26, 1026             \n\t" \\r
288                                         "       bnei r18, Error_Loop_2  \n\t" \\r
289                                         "       xori r18, r27, 1027             \n\t" \\r
290                                         "       bnei r18, Error_Loop_2  \n\t" \\r
291                                         "       xori r18, r28, 1028             \n\t" \\r
292                                         "       bnei r18, Error_Loop_2  \n\t" \\r
293                                         "       xori r18, r29, 1029             \n\t" \\r
294                                         "       bnei r18, Error_Loop_2  \n\t" \\r
295                                         "       xori r18, r30, 1030             \n\t" \\r
296                                         "       bnei r18, Error_Loop_2  \n\t" \\r
297                                         "       xori r18, r31, 1031             \n\t" \\r
298                                         "       bnei r18, Error_Loop_2  \n\t"\r
299                                  );\r
300 \r
301         /* If this task has not branched to the error loop, then everything is ok,\r
302         and the check variable should be incremented to indicate that this task\r
303         is still running.  Then, brach back to the top to check the registers\r
304         again. */\r
305         asm volatile (  "       lwi r18, r0, ulRegTest2CycleCount       \n\t" \\r
306                                         "       addik r18, r18, 1                                       \n\t" \\r
307                                         "       swi r18, r0, ulRegTest2CycleCount       \n\t" \\r
308                                         "                                                                               \n\t" \\r
309                                         "       bri Loop_Start_2 "\r
310                                  );\r
311 \r
312          /* The test function will branch here if it discovers an error.  This part\r
313         of the code just sits in a NULL loop, which prevents the check variable\r
314         incrementing any further to allow the check timer to recognize that this\r
315         test has failed. */\r
316         asm volatile (  "Error_Loop_2:                  \n\t" \\r
317                                         "       bri 0                           \n\t" \\r
318                                         "       nop                                     \n\t" \\r
319                                  );\r
320 \r
321         ( void ) pvParameters;\r
322 }\r
323 \r
324 \r
325 \r
326 \r
327 \r
328 \r