]> git.sur5r.net Git - freertos/blob - Demo/MicroBlaze_Spartan-6_EthernetLite/SDKProjects/RTOSDemoSource/RegisterTests.c
Add a register test to the new MicroBlaze demo - still a work in progress.
[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 \r
57 /*\r
58  * The register test task as described at the top of this file.\r
59  */\r
60 void vRegisterTest1( void *pvParameters );\r
61 void vRegisterTest2( void *pvParameters );\r
62 \r
63 /* Variables that are incremented on each iteration of the reg test tasks -\r
64 provided the tasks have not reported any errors.  The check task inspects these\r
65 variables to ensure they are still incrementing as expected.  If a variable\r
66 stops incrementing then it is likely that its associate task has stalled. */\r
67 volatile unsigned long ulRegTest1CycleCount = 0UL, ulRegTest2CycleCount = 0UL;\r
68 \r
69 /*-----------------------------------------------------------*/\r
70 \r
71 void vRegisterTest1( void *pvParameters )\r
72 {\r
73 //_RB_ Why can R5 not be used in this test?\r
74 \r
75         /* This task uses an infinite loop that is implemented in the assembly \r
76         code.\r
77         \r
78         First fill the registers with known values. */\r
79         asm volatile (  "       addi r3, r0, 3          \n\t" \\r
80                                         "       addi r4, r0, 4          \n\t" \\r
81                                         "       addi r6, r0, 6          \n\t" \\r
82                                         "       addi r7, r0, 7          \n\t" \\r
83                                         "       addi r8, r0, 8          \n\t" \\r
84                                         "       addi r9, r0, 9          \n\t" \\r
85                                         "       addi r10, r0, 10        \n\t" \\r
86                                         "       addi r11, r0, 11        \n\t" \\r
87                                         "       addi r12, r0, 12        \n\t" \\r
88                                         "       addi r16, r0, 16        \n\t" \\r
89                                         "       addi r19, r0, 19        \n\t" \\r
90                                         "       addi r20, r0, 20        \n\t" \\r
91                                         "       addi r21, r0, 21        \n\t" \\r
92                                         "       addi r22, r0, 22        \n\t" \\r
93                                         "       addi r23, r0, 23        \n\t" \\r
94                                         "       addi r24, r0, 24        \n\t" \\r
95                                         "       addi r25, r0, 25        \n\t" \\r
96                                         "       addi r26, r0, 26        \n\t" \\r
97                                         "       addi r27, r0, 27        \n\t" \\r
98                                         "       addi r28, r0, 28        \n\t" \\r
99                                         "       addi r29, r0, 29        \n\t" \\r
100                                         "       addi r30, r0, 30        \n\t" \\r
101                                         "       addi r31, r0, 31        \n\t"\r
102                                 );\r
103 \r
104         /* Now test the register values to ensure they contain the same value that\r
105         was written to them above.       This task will get preempted frequently so \r
106         other tasks are likely to have executed since the register values were \r
107         written. */\r
108 \r
109         asm volatile (  "Loop_Start_1:                          \n\t" \\r
110                                         "       xori r18, r3, 3                 \n\t" \\r
111                                         "       bnei r18, Error_Loop_1  \n\t" \\r
112                                         "       xori r18, r4, 4                 \n\t" \\r
113                                         "       bnei r18, Error_Loop_1  \n\t" \\r
114                                         "       xori r18, r6, 6                 \n\t" \\r
115                                         "       bnei r18, Error_Loop_1  \n\t" \\r
116                                         "       xori r18, r7, 7                 \n\t" \\r
117                                         "       bnei r18, Error_Loop_1  \n\t" \\r
118                                         "       xori r18, r8, 8                 \n\t" \\r
119                                         "       bnei r18, Error_Loop_1  \n\t" \\r
120                                         "       xori r18, r9, 9                 \n\t" \\r
121                                         "       bnei r18, Error_Loop_1  \n\t" \\r
122                                         "       xori r18, r10, 10               \n\t" \\r
123                                         "       bnei r18, Error_Loop_1  \n\t" \\r
124                                         "       xori r18, r11, 11               \n\t" \\r
125                                         "       bnei r18, Error_Loop_1  \n\t" \\r
126                                         "       xori r18, r12, 12               \n\t" \\r
127                                         "       bnei r18, Error_Loop_1  \n\t" \\r
128                                         "       xori r18, r16, 16               \n\t" \\r
129                                         "       bnei r18, Error_Loop_1  \n\t" \\r
130                                         "       xori r18, r19, 19               \n\t" \\r
131                                         "       bnei r18, Error_Loop_1  \n\t" \\r
132                                         "       xori r18, r20, 20               \n\t" \\r
133                                         "       bnei r18, Error_Loop_1  \n\t" \\r
134                                         "       xori r18, r21, 21               \n\t" \\r
135                                         "       bnei r18, Error_Loop_1  \n\t" \\r
136                                         "       xori r18, r22, 22               \n\t" \\r
137                                         "       bnei r18, Error_Loop_1  \n\t" \\r
138                                         "       xori r18, r23, 23               \n\t" \\r
139                                         "       bnei r18, Error_Loop_1  \n\t" \\r
140                                         "       xori r18, r24, 24               \n\t" \\r
141                                         "       bnei r18, Error_Loop_1  \n\t" \\r
142                                         "       xori r18, r25, 25               \n\t" \\r
143                                         "       bnei r18, Error_Loop_1  \n\t" \\r
144                                         "       xori r18, r26, 26               \n\t" \\r
145                                         "       bnei r18, Error_Loop_1  \n\t" \\r
146                                         "       xori r18, r27, 27               \n\t" \\r
147                                         "       bnei r18, Error_Loop_1  \n\t" \\r
148                                         "       xori r18, r28, 28               \n\t" \\r
149                                         "       bnei r18, Error_Loop_1  \n\t" \\r
150                                         "       xori r18, r29, 29               \n\t" \\r
151                                         "       bnei r18, Error_Loop_1  \n\t" \\r
152                                         "       xori r18, r30, 30               \n\t" \\r
153                                         "       bnei r18, Error_Loop_1  \n\t" \\r
154                                         "       xori r18, r31, 31               \n\t" \\r
155                                         "       bnei r18, Error_Loop_1  \n\t"\r
156                                  );\r
157 \r
158         /* If this task has not branched to the error loop, then everything is ok,\r
159         and the check variable should be incremented to indicate that this task\r
160         is still running.  Then, brach back to the top to check the registers\r
161         again. */\r
162         asm volatile (  "       lwi r18, r0, ulRegTest1CycleCount       \n\t" \\r
163                                         "       addik r18, r18, 1                                       \n\t" \\r
164                                         "       swi r18, r0, ulRegTest1CycleCount       \n\t" \\r
165                                         "                                                                               \n\t" \\r
166                                         "       bri Loop_Start_1 "\r
167                                  );\r
168 \r
169          /* The test function will branch here if it discovers an error.  This part\r
170         of the code just sits in a NULL loop, which prevents the check variable\r
171         incrementing any further to allow the check timer to recognize that this\r
172         test has failed. */\r
173         asm volatile (  "Error_Loop_1:                  \n\t" \\r
174                                         "       bri 0                           \n\t" \\r
175                                         "       nop                                     \n\t" \\r
176                                  );\r
177 }\r
178 /*-----------------------------------------------------------*/\r
179 \r
180 void vRegisterTest2( void *pvParameters )\r
181 {\r
182         /* This task uses an infinite loop that is implemented in the assembly \r
183         code.\r
184         \r
185         First fill the registers with known values. */\r
186         asm volatile (  "       addi r3, r0, 103        \n\t" \\r
187                                         "       addi r4, r0, 104        \n\t" \\r
188                                         "       addi r6, r0, 106        \n\t" \\r
189                                         "       addi r7, r0, 107        \n\t" \\r
190                                         "       addi r8, r0, 108        \n\t" \\r
191                                         "       addi r9, r0, 109        \n\t" \\r
192                                         "       addi r10, r0, 1010      \n\t" \\r
193                                         "       addi r11, r0, 1011      \n\t" \\r
194                                         "       addi r12, r0, 1012      \n\t" \\r
195                                         "       addi r16, r0, 1016      \n\t" \\r
196                                         "       addi r19, r0, 1019      \n\t" \\r
197                                         "       addi r20, r0, 1020      \n\t" \\r
198                                         "       addi r21, r0, 1021      \n\t" \\r
199                                         "       addi r22, r0, 1022      \n\t" \\r
200                                         "       addi r23, r0, 1023      \n\t" \\r
201                                         "       addi r24, r0, 1024      \n\t" \\r
202                                         "       addi r25, r0, 1025      \n\t" \\r
203                                         "       addi r26, r0, 1026      \n\t" \\r
204                                         "       addi r27, r0, 1027      \n\t" \\r
205                                         "       addi r28, r0, 1028      \n\t" \\r
206                                         "       addi r29, r0, 1029      \n\t" \\r
207                                         "       addi r30, r0, 1030      \n\t" \\r
208                                         "       addi r31, r0, 1031      \n\t"\r
209                                 );\r
210 \r
211         /* Now test the register values to ensure they contain the same value that\r
212         was written to them above.       This task will get preempted frequently so \r
213         other tasks are likely to have executed since the register values were \r
214         written. */\r
215 \r
216         asm volatile (  "Loop_Start_2:                          \n\t" \\r
217                                         "       xori r18, r3, 103               \n\t" \\r
218                                         "       bnei r18, Error_Loop_2  \n\t" \\r
219                                         "       xori r18, r4, 104               \n\t" \\r
220                                         "       bnei r18, Error_Loop_2  \n\t" \\r
221                                         "       xori r18, r6, 106               \n\t" \\r
222                                         "       bnei r18, Error_Loop_2  \n\t" \\r
223                                         "       xori r18, r7, 107               \n\t" \\r
224                                         "       bnei r18, Error_Loop_2  \n\t" \\r
225                                         "       xori r18, r8, 108               \n\t" \\r
226                                         "       bnei r18, Error_Loop_2  \n\t" \\r
227                                         "       xori r18, r9, 109               \n\t" \\r
228                                         "       bnei r18, Error_Loop_2  \n\t" \\r
229                                         "       xori r18, r10, 1010             \n\t" \\r
230                                         "       bnei r18, Error_Loop_2  \n\t" \\r
231                                         "       xori r18, r11, 1011             \n\t" \\r
232                                         "       bnei r18, Error_Loop_2  \n\t" \\r
233                                         "       xori r18, r12, 1012             \n\t" \\r
234                                         "       bnei r18, Error_Loop_2  \n\t" \\r
235                                         "       xori r18, r16, 1016             \n\t" \\r
236                                         "       bnei r18, Error_Loop_2  \n\t" \\r
237                                         "       xori r18, r19, 1019             \n\t" \\r
238                                         "       bnei r18, Error_Loop_2  \n\t" \\r
239                                         "       xori r18, r20, 1020             \n\t" \\r
240                                         "       bnei r18, Error_Loop_2  \n\t" \\r
241                                         "       xori r18, r21, 1021             \n\t" \\r
242                                         "       bnei r18, Error_Loop_2  \n\t" \\r
243                                         "       xori r18, r22, 1022             \n\t" \\r
244                                         "       bnei r18, Error_Loop_2  \n\t" \\r
245                                         "       xori r18, r23, 1023             \n\t" \\r
246                                         "       bnei r18, Error_Loop_2  \n\t" \\r
247                                         "       xori r18, r24, 1024             \n\t" \\r
248                                         "       bnei r18, Error_Loop_2  \n\t" \\r
249                                         "       xori r18, r25, 1025             \n\t" \\r
250                                         "       bnei r18, Error_Loop_2  \n\t" \\r
251                                         "       xori r18, r26, 1026             \n\t" \\r
252                                         "       bnei r18, Error_Loop_2  \n\t" \\r
253                                         "       xori r18, r27, 1027             \n\t" \\r
254                                         "       bnei r18, Error_Loop_2  \n\t" \\r
255                                         "       xori r18, r28, 1028             \n\t" \\r
256                                         "       bnei r18, Error_Loop_2  \n\t" \\r
257                                         "       xori r18, r29, 1029             \n\t" \\r
258                                         "       bnei r18, Error_Loop_2  \n\t" \\r
259                                         "       xori r18, r30, 1030             \n\t" \\r
260                                         "       bnei r18, Error_Loop_2  \n\t" \\r
261                                         "       xori r18, r31, 1031             \n\t" \\r
262                                         "       bnei r18, Error_Loop_2  \n\t"\r
263                                  );\r
264 \r
265         /* If this task has not branched to the error loop, then everything is ok,\r
266         and the check variable should be incremented to indicate that this task\r
267         is still running.  Then, brach back to the top to check the registers\r
268         again. */\r
269         asm volatile (  "       lwi r18, r0, ulRegTest2CycleCount       \n\t" \\r
270                                         "       addik r18, r18, 1                                       \n\t" \\r
271                                         "       swi r18, r0, ulRegTest2CycleCount       \n\t" \\r
272                                         "                                                                               \n\t" \\r
273                                         "       bri Loop_Start_2 "\r
274                                  );\r
275 \r
276          /* The test function will branch here if it discovers an error.  This part\r
277         of the code just sits in a NULL loop, which prevents the check variable\r
278         incrementing any further to allow the check timer to recognize that this\r
279         test has failed. */\r
280         asm volatile (  "Error_Loop_2:                  \n\t" \\r
281                                         "       bri 0                           \n\t" \\r
282                                         "       nop                                     \n\t" \\r
283                                  );\r
284 }\r
285 \r
286 \r
287 \r
288 \r
289 \r
290 \r