]> git.sur5r.net Git - freertos/blob - Demo/MicroBlaze_Spartan-6_EthernetLite/SDKProjects/RTOSDemoSource/RegisterTests.c
Update register test tasks to include a manual yield. Include the death tasks in...
[freertos] / Demo / MicroBlaze_Spartan-6_EthernetLite / SDKProjects / RTOSDemoSource / RegisterTests.c
1 /*\r
2     FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.\r
3         \r
4 \r
5     ***************************************************************************\r
6      *                                                                       *\r
7      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
8      *    Complete, revised, and edited pdf reference manuals are also       *\r
9      *    available.                                                         *\r
10      *                                                                       *\r
11      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
12      *    ensuring you get running as quickly as possible and with an        *\r
13      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
14      *    the FreeRTOS project to continue with its mission of providing     *\r
15      *    professional grade, cross platform, de facto standard solutions    *\r
16      *    for microcontrollers - completely free of charge!                  *\r
17      *                                                                       *\r
18      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
19      *                                                                       *\r
20      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
21      *                                                                       *\r
22     ***************************************************************************\r
23 \r
24 \r
25     This file is part of the FreeRTOS distribution.\r
26 \r
27     FreeRTOS is free software; you can redistribute it and/or modify it under\r
28     the terms of the GNU General Public License (version 2) as published by the\r
29     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
30     >>>NOTE<<< The modification to the GPL is included to allow you to\r
31     distribute a combined work that includes FreeRTOS without being obliged to\r
32     provide the source code for proprietary components outside of the FreeRTOS\r
33     kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
34     WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
35     or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
36     more details. You should have received a copy of the GNU General Public\r
37     License and the FreeRTOS license exception along with FreeRTOS; if not it\r
38     can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
39     by writing to Richard Barry, contact details for whom are available on the\r
40     FreeRTOS WEB site.\r
41 \r
42     1 tab == 4 spaces!\r
43 \r
44     http://www.FreeRTOS.org - Documentation, latest information, license and\r
45     contact details.\r
46 \r
47     http://www.SafeRTOS.com - A version that is certified for use in safety\r
48     critical systems.\r
49 \r
50     http://www.OpenRTOS.com - Commercial support, development, porting,\r
51     licensing and training services.\r
52 */\r
53 \r
54 /* Scheduler includes. */\r
55 #include "FreeRTOS.h"\r
56 #include "task.h"\r
57 \r
58 /*\r
59  * The register test task as described at the top of this file.\r
60  */\r
61 void vRegisterTest1( void *pvParameters );\r
62 void vRegisterTest2( void *pvParameters );\r
63 \r
64 /* Variables that are incremented on each iteration of the reg test tasks -\r
65 provided the tasks have not reported any errors.  The check task inspects these\r
66 variables to ensure they are still incrementing as expected.  If a variable\r
67 stops incrementing then it is likely that its associate task has stalled. */\r
68 volatile unsigned long ulRegTest1CycleCount = 0UL, ulRegTest2CycleCount = 0UL;\r
69 \r
70 /*-----------------------------------------------------------*/\r
71 \r
72 void vRegisterTest1( void *pvParameters )\r
73 {\r
74 //_RB_ Why can R5 not be used in this test?\r
75 \r
76         /* This task uses an infinite loop that is implemented in the assembly \r
77         code.\r
78         \r
79         First fill the registers with known values. */\r
80         asm volatile (  "       addi r3, r0, 3          \n\t" \\r
81                                         "       addi r4, r0, 4          \n\t" \\r
82                                         "       addi r6, r0, 6          \n\t" \\r
83                                         "       addi r7, r0, 7          \n\t" \\r
84                                         "       addi r8, r0, 8          \n\t" \\r
85                                         "       addi r9, r0, 9          \n\t" \\r
86                                         "       addi r10, r0, 10        \n\t" \\r
87                                         "       addi r11, r0, 11        \n\t" \\r
88                                         "       addi r12, r0, 12        \n\t" \\r
89                                         "       addi r16, r0, 16        \n\t" \\r
90                                         "       addi r19, r0, 19        \n\t" \\r
91                                         "       addi r20, r0, 20        \n\t" \\r
92                                         "       addi r21, r0, 21        \n\t" \\r
93                                         "       addi r22, r0, 22        \n\t" \\r
94                                         "       addi r23, r0, 23        \n\t" \\r
95                                         "       addi r24, r0, 24        \n\t" \\r
96                                         "       addi r25, r0, 25        \n\t" \\r
97                                         "       addi r26, r0, 26        \n\t" \\r
98                                         "       addi r27, r0, 27        \n\t" \\r
99                                         "       addi r28, r0, 28        \n\t" \\r
100                                         "       addi r29, r0, 29        \n\t" \\r
101                                         "       addi r30, r0, 30        \n\t" \\r
102                                         "       addi r31, r0, 31        \n\t"\r
103                                 );\r
104 \r
105         /* Now test the register values to ensure they contain the same value that\r
106         was written to them above.       This task will get preempted frequently so \r
107         other tasks are likely to have executed since the register values were \r
108         written. */\r
109 \r
110         asm volatile (  "Loop_Start_1:                          \n\t" \\r
111                                         "       xori r18, r3, 3                 \n\t" \\r
112                                         "       bnei r18, Error_Loop_1  \n\t" \\r
113                                         "       xori r18, r4, 4                 \n\t" \\r
114                                         "       bnei r18, Error_Loop_1  \n\t" \\r
115                                         "       xori r18, r6, 6                 \n\t" \\r
116                                         "       bnei r18, Error_Loop_1  \n\t" \\r
117                                         "       xori r18, r7, 7                 \n\t" \\r
118                                         "       bnei r18, Error_Loop_1  \n\t" \\r
119                                         "       xori r18, r8, 8                 \n\t" \\r
120                                         "       bnei r18, Error_Loop_1  \n\t" \\r
121                                         "       xori r18, r9, 9                 \n\t" \\r
122                                         "       bnei r18, Error_Loop_1  \n\t" \\r
123                                         "       xori r18, r10, 10               \n\t" \\r
124                                         "       bnei r18, Error_Loop_1  \n\t" \\r
125                                         "       xori r18, r11, 11               \n\t" \\r
126                                         "       bnei r18, Error_Loop_1  \n\t" \\r
127                                         "       xori r18, r12, 12               \n\t" \\r
128                                         "       bnei r18, Error_Loop_1  \n\t" \\r
129                                         "       xori r18, r16, 16               \n\t" \\r
130                                         "       bnei r18, Error_Loop_1  \n\t" \\r
131                                         "       xori r18, r19, 19               \n\t" \\r
132                                         "       bnei r18, Error_Loop_1  \n\t" \\r
133                                         "       xori r18, r20, 20               \n\t" \\r
134                                         "       bnei r18, Error_Loop_1  \n\t" \\r
135                                         "       xori r18, r21, 21               \n\t" \\r
136                                         "       bnei r18, Error_Loop_1  \n\t" \\r
137                                         "       xori r18, r22, 22               \n\t" \\r
138                                         "       bnei r18, Error_Loop_1  \n\t" \\r
139                                         "       xori r18, r23, 23               \n\t" \\r
140                                         "       bnei r18, Error_Loop_1  \n\t" \\r
141                                         "       xori r18, r24, 24               \n\t" \\r
142                                         "       bnei r18, Error_Loop_1  \n\t" \\r
143                                         "       xori r18, r25, 25               \n\t" \\r
144                                         "       bnei r18, Error_Loop_1  \n\t" \\r
145                                         "       xori r18, r26, 26               \n\t" \\r
146                                         "       bnei r18, Error_Loop_1  \n\t" \\r
147                                         "       xori r18, r27, 27               \n\t" \\r
148                                         "       bnei r18, Error_Loop_1  \n\t" \\r
149                                         "       xori r18, r28, 28               \n\t" \\r
150                                         "       bnei r18, Error_Loop_1  \n\t" \\r
151                                         "       xori r18, r29, 29               \n\t" \\r
152                                         "       bnei r18, Error_Loop_1  \n\t" \\r
153                                         "       xori r18, r30, 30               \n\t" \\r
154                                         "       bnei r18, Error_Loop_1  \n\t" \\r
155                                         "       xori r18, r31, 31               \n\t" \\r
156                                         "       bnei r18, Error_Loop_1  \n\t"\r
157                                  );\r
158 \r
159         /* If this task has not branched to the error loop, then everything is ok,\r
160         and the check variable should be incremented to indicate that this task\r
161         is still running.  Then, brach back to the top to check the registers\r
162         again. */\r
163         asm volatile (  "       lwi r18, r0, ulRegTest1CycleCount       \n\t" \\r
164                                         "       addik r18, r18, 1                                       \n\t" \\r
165                                         "       swi r18, r0, ulRegTest1CycleCount       \n\t" \\r
166                                         "                                                                               \n\t" \\r
167                                         "       bri Loop_Start_1 "\r
168                                  );\r
169 \r
170          /* The test function will branch here if it discovers an error.  This part\r
171         of the code just sits in a NULL loop, which prevents the check variable\r
172         incrementing any further to allow the check timer to recognize that this\r
173         test has failed. */\r
174         asm volatile (  "Error_Loop_1:                  \n\t" \\r
175                                         "       bri 0                           \n\t" \\r
176                                         "       nop                                     \n\t" \\r
177                                  );\r
178 }\r
179 /*-----------------------------------------------------------*/\r
180 \r
181 void vRegisterTest2( void *pvParameters )\r
182 {\r
183         /* This task uses an infinite loop that is implemented in the assembly \r
184         code.\r
185         \r
186         First fill the registers with known values. */\r
187         asm volatile (  "       addi r16, r0, 1016      \n\t" \\r
188                                         "       addi r19, r0, 1019      \n\t" \\r
189                                         "       addi r20, r0, 1020      \n\t" \\r
190                                         "       addi r21, r0, 1021      \n\t" \\r
191                                         "       addi r22, r0, 1022      \n\t" \\r
192                                         "       addi r23, r0, 1023      \n\t" \\r
193                                         "       addi r24, r0, 1024      \n\t" \\r
194                                         "       addi r25, r0, 1025      \n\t" \\r
195                                         "       addi r26, r0, 1026      \n\t" \\r
196                                         "       addi r27, r0, 1027      \n\t" \\r
197                                         "       addi r28, r0, 1028      \n\t" \\r
198                                         "       addi r29, r0, 1029      \n\t" \\r
199                                         "       addi r30, r0, 1030      \n\t" \\r
200                                         "       addi r31, r0, 1031      \n\t" \\r
201                                         "                                                       " \\r
202                                         "Loop_Start_2:                          "\r
203                                 );\r
204 \r
205         taskYIELD();\r
206 \r
207         asm volatile (  "       addi r3, r0, 103        \n\t" \\r
208                                         "       addi r4, r0, 104        \n\t" \\r
209                                         "       addi r6, r0, 106        \n\t" \\r
210                                         "       addi r7, r0, 107        \n\t" \\r
211                                         "       addi r8, r0, 108        \n\t" \\r
212                                         "       addi r9, r0, 109        \n\t" \\r
213                                         "       addi r10, r0, 1010      \n\t" \\r
214                                         "       addi r11, r0, 1011      \n\t" \\r
215                                         "       addi r12, r0, 1012      \n\t" \\r
216                                 );\r
217 \r
218         /* taskYIELD() could have changed temporaries - set them back to those\r
219         expected by the reg test task. */\r
220 \r
221         /* Now test the register values to ensure they contain the same value that\r
222         was written to them above.       This task will get preempted frequently so \r
223         other tasks are likely to have executed since the register values were \r
224         written. */\r
225         asm volatile (  "       xori r18, r3, 103               \n\t" \\r
226                                         "       bnei r18, Error_Loop_2  \n\t" \\r
227                                         "       xori r18, r4, 104               \n\t" \\r
228                                         "       bnei r18, Error_Loop_2  \n\t" \\r
229                                         "       xori r18, r6, 106               \n\t" \\r
230                                         "       bnei r18, Error_Loop_2  \n\t" \\r
231                                         "       xori r18, r7, 107               \n\t" \\r
232                                         "       bnei r18, Error_Loop_2  \n\t" \\r
233                                         "       xori r18, r8, 108               \n\t" \\r
234                                         "       bnei r18, Error_Loop_2  \n\t" \\r
235                                         "       xori r18, r9, 109               \n\t" \\r
236                                         "       bnei r18, Error_Loop_2  \n\t" \\r
237                                         "       xori r18, r10, 1010             \n\t" \\r
238                                         "       bnei r18, Error_Loop_2  \n\t" \\r
239                                         "       xori r18, r11, 1011             \n\t" \\r
240                                         "       bnei r18, Error_Loop_2  \n\t" \\r
241                                         "       xori r18, r12, 1012             \n\t" \\r
242                                         "       bnei r18, Error_Loop_2  \n\t" \\r
243                                         "       xori r18, r16, 1016             \n\t" \\r
244                                         "       bnei r18, Error_Loop_2  \n\t" \\r
245                                         "       xori r18, r19, 1019             \n\t" \\r
246                                         "       bnei r18, Error_Loop_2  \n\t" \\r
247                                         "       xori r18, r20, 1020             \n\t" \\r
248                                         "       bnei r18, Error_Loop_2  \n\t" \\r
249                                         "       xori r18, r21, 1021             \n\t" \\r
250                                         "       bnei r18, Error_Loop_2  \n\t" \\r
251                                         "       xori r18, r22, 1022             \n\t" \\r
252                                         "       bnei r18, Error_Loop_2  \n\t" \\r
253                                         "       xori r18, r23, 1023             \n\t" \\r
254                                         "       bnei r18, Error_Loop_2  \n\t" \\r
255                                         "       xori r18, r24, 1024             \n\t" \\r
256                                         "       bnei r18, Error_Loop_2  \n\t" \\r
257                                         "       xori r18, r25, 1025             \n\t" \\r
258                                         "       bnei r18, Error_Loop_2  \n\t" \\r
259                                         "       xori r18, r26, 1026             \n\t" \\r
260                                         "       bnei r18, Error_Loop_2  \n\t" \\r
261                                         "       xori r18, r27, 1027             \n\t" \\r
262                                         "       bnei r18, Error_Loop_2  \n\t" \\r
263                                         "       xori r18, r28, 1028             \n\t" \\r
264                                         "       bnei r18, Error_Loop_2  \n\t" \\r
265                                         "       xori r18, r29, 1029             \n\t" \\r
266                                         "       bnei r18, Error_Loop_2  \n\t" \\r
267                                         "       xori r18, r30, 1030             \n\t" \\r
268                                         "       bnei r18, Error_Loop_2  \n\t" \\r
269                                         "       xori r18, r31, 1031             \n\t" \\r
270                                         "       bnei r18, Error_Loop_2  \n\t"\r
271                                  );\r
272 \r
273         /* If this task has not branched to the error loop, then everything is ok,\r
274         and the check variable should be incremented to indicate that this task\r
275         is still running.  Then, brach back to the top to check the registers\r
276         again. */\r
277         asm volatile (  "       lwi r18, r0, ulRegTest2CycleCount       \n\t" \\r
278                                         "       addik r18, r18, 1                                       \n\t" \\r
279                                         "       swi r18, r0, ulRegTest2CycleCount       \n\t" \\r
280                                         "                                                                               \n\t" \\r
281                                         "       bri Loop_Start_2 "\r
282                                  );\r
283 \r
284          /* The test function will branch here if it discovers an error.  This part\r
285         of the code just sits in a NULL loop, which prevents the check variable\r
286         incrementing any further to allow the check timer to recognize that this\r
287         test has failed. */\r
288         asm volatile (  "Error_Loop_2:                  \n\t" \\r
289                                         "       bri 0                           \n\t" \\r
290                                         "       nop                                     \n\t" \\r
291                                  );\r
292 }\r
293 \r
294 \r
295 \r
296 \r
297 \r
298 \r