]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/NiosII_CycloneIII_DBC3C40_GCC/RTOSDemo/main.c
422dc9c1660e7de5cf5af1c7fd43f40956d8e9e3
[freertos] / FreeRTOS / Demo / NiosII_CycloneIII_DBC3C40_GCC / RTOSDemo / main.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 /*\r
97  * Creates all the demo application tasks, then starts the scheduler.\r
98  * In addition to the standard demo tasks, the following tasks and tests are\r
99  * defined and/or created within this file:\r
100  *\r
101  * "Check" task -  This only executes every five seconds but has the highest\r
102  * priority so is guaranteed to get processor time.  Its main function is to \r
103  * check that all the standard demo tasks are still operational.  The check\r
104  * task will write an error message to the console should an error be detected\r
105  * within any of the demo tasks.  The check task also toggles the LED defined\r
106  * by mainCHECK_LED every 5 seconds while the system is error free, with the\r
107  * toggle rate increasing to every 500ms should an error occur.\r
108  * \r
109  * "Reg test" tasks - These fill the registers with known values, then check\r
110  * that each register still contains its expected value.  Each task uses\r
111  * different values.  The tasks run with very low priority so get preempted very\r
112  * frequently.  A register containing an unexpected value is indicative of an\r
113  * error in the context switching mechanism.\r
114  *\r
115  * See the online documentation for this demo for more information on interrupt\r
116  * usage.\r
117  */\r
118 \r
119 /* Standard includes. */\r
120 #include <stddef.h>\r
121 #include <stdio.h>\r
122 #include <string.h>\r
123 \r
124 /* Scheduler includes. */\r
125 #include "FreeRTOS.h"\r
126 #include "task.h"\r
127 #include "queue.h"\r
128 \r
129 /* Demo application includes. */\r
130 #include "partest.h"\r
131 #include "flash.h"\r
132 #include "blocktim.h"\r
133 #include "semtest.h"\r
134 #include "serial.h"\r
135 #include "comtest.h"\r
136 #include "GenQTest.h"\r
137 #include "QPeek.h"\r
138 #include "integer.h"\r
139 #include "PollQ.h"\r
140 #include "BlockQ.h"\r
141 #include "dynamic.h"\r
142 #include "countsem.h"\r
143 #include "recmutex.h"\r
144 #include "death.h"\r
145 \r
146 /*-----------------------------------------------------------*/\r
147 \r
148 #error The batch file Demo\NiosII_CycloneIII_DBC3C40_GCC\CreateProjectDirectoryStructure.bat must be executed before the project is imported into the workspace.  Failure to do this will result in the include paths stored in the project being deleted.  Remove this line after CreateProjectDirectoryStructure.bat has been executed.\r
149 \r
150 /*-----------------------------------------------------------*/\r
151 \r
152 /* The rate at which the LED controlled by the 'check' task will toggle when no\r
153 errors have been detected. */\r
154 #define mainNO_ERROR_PERIOD     ( 5000 )\r
155 \r
156 /* The rate at which the LED controlled by the 'check' task will toggle when an\r
157 error has been detected. */\r
158 #define mainERROR_PERIOD        ( 500 )\r
159 \r
160 /* The LED toggled by the Check task. */\r
161 #define mainCHECK_LED       ( 7 )\r
162 \r
163 /* The first LED used by the ComTest tasks.  One LED toggles each time a \r
164 character is transmitted, and one each time a character is received and\r
165 verified as being the expected character. */\r
166 #define mainCOMTEST_LED     ( 4 )\r
167 \r
168 /* Priority definitions for the tasks in the demo application. */\r
169 #define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
170 #define mainCREATOR_TASK_PRIORITY       ( tskIDLE_PRIORITY + 3 )\r
171 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )\r
172 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 2 )\r
173 #define mainQUEUE_BLOCK_PRIORITY        ( tskIDLE_PRIORITY + 3 )\r
174 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
175 #define mainSEMAPHORE_TASK_PRIORITY     ( tskIDLE_PRIORITY + 1 )\r
176 #define mainGENERIC_QUEUE_PRIORITY      ( tskIDLE_PRIORITY )\r
177 #define mainREG_TEST_PRIORITY       ( tskIDLE_PRIORITY )\r
178 \r
179 /* Misc. */\r
180 #define mainDONT_WAIT                                           ( 0 )\r
181 \r
182 /* The parameters passed to the reg test tasks.  This is just done to check\r
183 the parameter passing mechanism is working correctly. */\r
184 #define mainREG_TEST_1_PARAMETER    ( ( void * ) 0x12345678 )\r
185 #define mainREG_TEST_2_PARAMETER    ( ( void * ) 0x87654321 )\r
186 \r
187 /*-----------------------------------------------------------*/\r
188 \r
189 /*\r
190  * Setup the processor ready for the demo.\r
191  */\r
192 static void prvSetupHardware( void );\r
193 \r
194 /*\r
195  * Execute all of the check functions to ensure the tests haven't failed.\r
196  */ \r
197 static void prvCheckTask( void *pvParameters );\r
198 \r
199 /*\r
200  * The register test (or RegTest) tasks as described at the top of this file.\r
201  */\r
202 static void prvFirstRegTestTask( void *pvParameters );\r
203 static void prvSecondRegTestTask( void *pvParameters );\r
204 \r
205 /*-----------------------------------------------------------*/\r
206 \r
207 /* Counters that are incremented on each iteration of the RegTest tasks\r
208 so long as no errors have been detected. */\r
209 volatile unsigned long ulRegTest1Counter = 0UL, ulRegTest2Counter = 0UL;\r
210 \r
211 /*-----------------------------------------------------------*/\r
212 \r
213 /*\r
214  * Create the demo tasks then start the scheduler.\r
215  */\r
216 int main( void )\r
217 {\r
218     /* Configure any hardware required for this demo. */\r
219         prvSetupHardware();\r
220     \r
221         /* Create all the other standard demo tasks.  These serve no purpose other\r
222     than to test the port and demonstrate the use of the FreeRTOS API. */\r
223         vStartLEDFlashTasks( tskIDLE_PRIORITY );\r
224         vStartIntegerMathTasks( mainGENERIC_QUEUE_PRIORITY );\r
225         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
226         vStartBlockingQueueTasks( mainQUEUE_BLOCK_PRIORITY );\r
227         vCreateBlockTimeTasks();\r
228         vStartSemaphoreTasks( mainSEMAPHORE_TASK_PRIORITY );\r
229         vStartDynamicPriorityTasks();\r
230         vStartQueuePeekTasks();\r
231         vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );\r
232         vStartCountingSemaphoreTasks();\r
233         vStartRecursiveMutexTasks();\r
234     vAltStartComTestTasks( mainCOM_TEST_PRIORITY, 0, mainCOMTEST_LED );\r
235     \r
236         /* prvCheckTask uses sprintf so requires more stack. */\r
237         xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
238     \r
239     /* The RegTest tasks as described at the top of this file. */\r
240     xTaskCreate( prvFirstRegTestTask, "Rreg1", configMINIMAL_STACK_SIZE, mainREG_TEST_1_PARAMETER, mainREG_TEST_PRIORITY, NULL );\r
241     xTaskCreate( prvSecondRegTestTask, "Rreg2", configMINIMAL_STACK_SIZE, mainREG_TEST_2_PARAMETER, mainREG_TEST_PRIORITY, NULL );\r
242 \r
243         /* This task has to be created last as it keeps account of the number of tasks\r
244         it expects to see running. */\r
245         vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
246 \r
247     /* Finally start the scheduler. */\r
248         vTaskStartScheduler();\r
249     \r
250         /* Will only reach here if there is insufficient heap available to start\r
251         the scheduler. */\r
252         for( ;; );\r
253 }\r
254 /*-----------------------------------------------------------*/\r
255 \r
256 static void prvSetupHardware( void )\r
257 {\r
258     /* Setup the digital IO for the LED's. */\r
259     vParTestInitialise();\r
260 }\r
261 /*-----------------------------------------------------------*/\r
262 \r
263 void vApplicationStackOverflowHook( void )\r
264 {\r
265         /* Look at pxCurrentTCB to see which task overflowed its stack. */\r
266         for( ;; )\r
267     {\r
268                 asm( "break" );\r
269     }\r
270 }\r
271 /*-----------------------------------------------------------*/\r
272 \r
273 void _general_exception_handler( unsigned long ulCause, unsigned long ulStatus )\r
274 {\r
275         /* This overrides the definition provided by the kernel.  Other exceptions \r
276         should be handled here. */\r
277         for( ;; )\r
278     {\r
279                 asm( "break" );\r
280     }\r
281 }\r
282 /*-----------------------------------------------------------*/\r
283 \r
284 static void prvCheckTask( void *pvParameters )\r
285 {\r
286 TickType_t xLastExecutionTime, ulTicksToWait = mainNO_ERROR_PERIOD;\r
287 unsigned long ulLastRegTest1 = 0UL, ulLastRegTest2 = 0UL;\r
288 const char * pcMessage;\r
289 \r
290         /* Initialise the variable used to control our iteration rate prior to\r
291         its first use. */\r
292         xLastExecutionTime = xTaskGetTickCount();\r
293 \r
294         for( ;; )\r
295         {\r
296                 /* Wait until it is time to run the tests again. */\r
297                 vTaskDelayUntil( &xLastExecutionTime, ulTicksToWait );\r
298                 \r
299                 /* Have any of the standard demo tasks detected an error in their \r
300                 operation? */\r
301                 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
302                 {\r
303                         ulTicksToWait = mainERROR_PERIOD;\r
304                         pcMessage = "Error: Integer Maths.\n";\r
305                 }\r
306                 else if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
307                 {\r
308                         ulTicksToWait = mainERROR_PERIOD;\r
309                         pcMessage = "Error: GenQ.\n";\r
310                 }\r
311                 else if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
312                 {\r
313                         ulTicksToWait = mainERROR_PERIOD;\r
314                         pcMessage = "Error: BlockQ.\n";\r
315                 }\r
316                 else if( xArePollingQueuesStillRunning() != pdTRUE )\r
317                 {\r
318                         ulTicksToWait = mainERROR_PERIOD;\r
319                         pcMessage = "Error: PollQ.\n";\r
320                 }\r
321                 else if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
322                 {\r
323                         ulTicksToWait = mainERROR_PERIOD;\r
324                         pcMessage = "Error: PeekQ.\n";\r
325                 }\r
326                 else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
327                 {\r
328                         ulTicksToWait = mainERROR_PERIOD;\r
329                         pcMessage = "Error: Block Time.\n";\r
330                 }\r
331                 else if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
332             {\r
333                 ulTicksToWait = mainERROR_PERIOD;\r
334                         pcMessage = "Error: Semaphore Test.\n";\r
335             }\r
336             else if( xAreComTestTasksStillRunning() != pdTRUE )\r
337             {\r
338                 ulTicksToWait = mainERROR_PERIOD;\r
339                         pcMessage = "Error: Comm Test.\n";\r
340             }\r
341                 else if( xIsCreateTaskStillRunning() != pdTRUE )\r
342                 {\r
343                         ulTicksToWait = mainERROR_PERIOD;\r
344                         pcMessage = "Error: Suicidal Tasks.\n";\r
345                 }\r
346                 else if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
347                 {\r
348                         ulTicksToWait = mainERROR_PERIOD;\r
349                         pcMessage = "Error: Dynamic Priority.\n";\r
350                 }\r
351                 else if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )\r
352                 {\r
353                         ulTicksToWait = mainERROR_PERIOD;\r
354                         pcMessage = "Error: Count Semaphore.\n";\r
355                 }\r
356                 else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
357                 {\r
358                         ulTicksToWait = mainERROR_PERIOD;\r
359                         pcMessage = "Error: Recursive Mutex.\n";\r
360                 }\r
361         else if( ulLastRegTest1 == ulRegTest1Counter )\r
362         {\r
363             /* ulRegTest1Counter is no longer being incremented, indicating\r
364             that an error has been discovered in prvFirstRegTestTask(). */\r
365             ulTicksToWait = mainERROR_PERIOD;\r
366             pcMessage = "Error: Reg Test1.\n";\r
367         }\r
368         else if( ulLastRegTest2 == ulRegTest2Counter )\r
369         {\r
370             /* ulRegTest2Counter is no longer being incremented, indicating\r
371             that an error has been discovered in prvSecondRegTestTask(). */            \r
372             ulTicksToWait = mainERROR_PERIOD;\r
373             pcMessage = "Error: Reg Test2.\n";\r
374         }\r
375                 else\r
376                 {\r
377                         pcMessage = NULL;\r
378                 }\r
379         \r
380         /* Remember the counter values this time around so a counter failing\r
381         to be incremented correctly can be spotted. */\r
382         ulLastRegTest1 = ulRegTest1Counter;\r
383         ulLastRegTest2 = ulRegTest2Counter;\r
384         \r
385         /* Print out an error message if there is one.  Mutual exclusion is \r
386         not used as this is the only task accessing stdout. */\r
387         if( pcMessage != NULL )\r
388         {\r
389             printf( pcMessage );\r
390         }\r
391         \r
392         /* Provide visual feedback of the system status.  If the LED is toggled\r
393         every 5 seconds then no errors have been found.  If the LED is toggled\r
394         every 500ms then at least one error has been found. */\r
395         vParTestToggleLED( mainCHECK_LED );\r
396         }\r
397 }\r
398 /*-----------------------------------------------------------*/\r
399 \r
400 static void prvFirstRegTestTask( void *pvParameters )\r
401 {\r
402     /* Check the parameters are passed in as expected. */\r
403     if( pvParameters != mainREG_TEST_1_PARAMETER )\r
404     {\r
405         /* Don't execute any further so an error is recognised by the check \r
406         task. */\r
407         vTaskDelete( NULL );\r
408     }\r
409     \r
410     /* Fill registers with known values, then check that each register still\r
411     contains its expected value.  An incorrect value is indicative of an error\r
412     in the context switching process. \r
413     \r
414     If no errors are found ulRegTest1Counter is incremented.  The check task\r
415     will recognise an error if ulRegTest1Counter stops being incremented. \r
416     This task also performs a manual yield in the middle of its execution, just\r
417     to increase the test coverage. */\r
418     asm volatile (\r
419         "   .extern ulRegTest1Counter           \n" \\r
420         "                                       \n" \\r
421         "   addi    r3, r0, 3                   \n" \\r
422         "   addi    r4, r0, 4                   \n" \\r
423         "   addi    r5, r0, 5                   \n" \\r
424         "   addi    r6, r0, 6                   \n" \\r
425         "   addi    r7, r0, 7                   \n" \\r
426         "   addi    r8, r0, 8                   \n" \\r
427         "   addi    r9, r0, 9                   \n" \\r
428         "   addi    r10, r0, 10                   \n" \\r
429         "   addi    r11, r0, 11                   \n" \\r
430         "   addi    r12, r0, 12                   \n" \\r
431         "   addi    r13, r0, 13                   \n" \\r
432         "   addi    r14, r0, 14                   \n" \\r
433         "   addi    r15, r0, 15                   \n" \\r
434         "   addi    r16, r0, 16                   \n" \\r
435         "   addi    r17, r0, 17                   \n" \\r
436         "   addi    r18, r0, 18                   \n" \\r
437         "   addi    r19, r0, 19                   \n" \\r
438         "   addi    r20, r0, 20                   \n" \\r
439         "   addi    r21, r0, 21                   \n" \\r
440         "   addi    r22, r0, 22                   \n" \\r
441         "   addi    r23, r0, 23                   \n" \\r
442         "   addi    r28, r0, 28                   \n" \\r
443         "   addi    r31, r0, 31                   \n" \\r
444         "RegTest1:                              \n" \\r
445         "   addi    r2, r0, 0                   \n" \\r
446         "   trap                                \n" \\r
447         "   bne     r2, r0, RegTest1Error       \n" \\r
448         "   addi    r2, r0, 3                   \n" \\r
449         "   bne     r2, r3, RegTest1Error       \n" \\r
450         "   addi    r2, r0, 4                   \n" \\r
451         "   bne     r2, r4, RegTest1Error       \n" \\r
452         "   addi    r2, r0, 5                   \n" \\r
453         "   bne     r2, r5, RegTest1Error       \n" \\r
454         "   addi    r2, r0, 6                   \n" \\r
455         "   bne     r2, r6, RegTest1Error       \n" \\r
456         "   addi    r2, r0, 7                   \n" \\r
457         "   bne     r2, r7, RegTest1Error       \n" \\r
458         "   addi    r2, r0, 8                   \n" \\r
459         "   bne     r2, r8, RegTest1Error       \n" \\r
460         "   addi    r2, r0, 9                   \n" \\r
461         "   bne     r2, r9, RegTest1Error       \n" \\r
462         "   addi    r2, r0, 10                   \n" \\r
463         "   bne     r2, r10, RegTest1Error       \n" \\r
464         "   addi    r2, r0, 11                   \n" \\r
465         "   bne     r2, r11, RegTest1Error       \n" \\r
466         "   addi    r2, r0, 12                   \n" \\r
467         "   bne     r2, r12, RegTest1Error       \n" \\r
468         "   addi    r2, r0, 13                   \n" \\r
469         "   bne     r2, r13, RegTest1Error       \n" \\r
470         "   addi    r2, r0, 14                   \n" \\r
471         "   bne     r2, r14, RegTest1Error       \n" \\r
472         "   addi    r2, r0, 15                   \n" \\r
473         "   bne     r2, r15, RegTest1Error       \n" \\r
474         "   addi    r2, r0, 16                   \n" \\r
475         "   bne     r2, r16, RegTest1Error       \n" \\r
476         "   addi    r2, r0, 17                   \n" \\r
477         "   bne     r2, r17, RegTest1Error       \n" \\r
478         "   addi    r2, r0, 18                   \n" \\r
479         "   bne     r2, r18, RegTest1Error       \n" \\r
480         "   addi    r2, r0, 19                   \n" \\r
481         "   bne     r2, r19, RegTest1Error       \n" \\r
482         "   addi    r2, r0, 20                   \n" \\r
483         "   bne     r2, r20, RegTest1Error       \n" \\r
484         "   addi    r2, r0, 21                   \n" \\r
485         "   bne     r2, r21, RegTest1Error       \n" \\r
486         "   addi    r2, r0, 22                   \n" \\r
487         "   bne     r2, r22, RegTest1Error       \n" \\r
488         "   addi    r2, r0, 23                   \n" \\r
489         "   bne     r2, r23, RegTest1Error       \n" \\r
490         "   addi    r2, r0, 28                   \n" \\r
491         "   bne     r2, r28, RegTest1Error       \n" \\r
492         "   addi    r2, r0, 31                   \n" \\r
493         "   bne     r2, r31, RegTest1Error       \n" \\r
494         "   ldw     r2, %gprel(ulRegTest1Counter)(gp)       \n" \\r
495         "   addi    r2, r2, 1                   \n" \\r
496         "   stw     r2, %gprel(ulRegTest1Counter)(gp)       \n" \\r
497         "   br      RegTest1                    \n" \\r
498         "RegTest1Error:                         \n" \\r
499         "   br      RegTest1Error               \n"\r
500     );\r
501 }\r
502 /*-----------------------------------------------------------*/\r
503 \r
504 static void prvSecondRegTestTask( void *pvParameters )\r
505 {\r
506     /* Check the parameters are passed in as expected. */\r
507     if( pvParameters != mainREG_TEST_2_PARAMETER )\r
508     {\r
509         /* Don't execute any further so an error is recognised by the check \r
510         task. */\r
511         vTaskDelete( NULL );\r
512     }\r
513     \r
514     /* Fill registers with known values, then check that each register still\r
515     contains its expected value.  An incorrect value is indicative of an error\r
516     in the context switching process. \r
517     \r
518     If no errors are found ulRegTest2Counter is incremented.  The check task\r
519     will recognise an error if ulRegTest2Counter stops being incremented. */\r
520     asm volatile (\r
521         "   .extern ulRegTest2Counter           \n" \\r
522         "                                       \n" \\r
523         "   addi    r3, r0, 3                   \n" \\r
524         "   addi    r4, r0, 4                   \n" \\r
525         "   addi    r5, r0, 5                   \n" \\r
526         "   addi    r6, r0, 6                   \n" \\r
527         "   addi    r7, r0, 7                   \n" \\r
528         "   addi    r8, r0, 8                   \n" \\r
529         "   addi    r9, r0, 9                   \n" \\r
530         "   addi    r10, r0, 10                   \n" \\r
531         "   addi    r11, r0, 11                   \n" \\r
532         "   addi    r12, r0, 12                   \n" \\r
533         "   addi    r13, r0, 13                   \n" \\r
534         "   addi    r14, r0, 14                   \n" \\r
535         "   addi    r15, r0, 15                   \n" \\r
536         "   addi    r16, r0, 16                   \n" \\r
537         "   addi    r17, r0, 17                   \n" \\r
538         "   addi    r18, r0, 18                   \n" \\r
539         "   addi    r19, r0, 19                   \n" \\r
540         "   addi    r20, r0, 20                   \n" \\r
541         "   addi    r21, r0, 21                   \n" \\r
542         "   addi    r22, r0, 22                   \n" \\r
543         "   addi    r23, r0, 23                   \n" \\r
544         "   addi    r28, r0, 28                   \n" \\r
545         "   addi    r31, r0, 31                   \n" \\r
546         "RegTest2:                              \n" \\r
547         "   addi    r2, r0, 0                   \n" \\r
548         "   bne     r2, r0, RegTest2Error       \n" \\r
549         "   addi    r2, r0, 3                   \n" \\r
550         "   bne     r2, r3, RegTest2Error       \n" \\r
551         "   addi    r2, r0, 4                   \n" \\r
552         "   bne     r2, r4, RegTest2Error       \n" \\r
553         "   addi    r2, r0, 5                   \n" \\r
554         "   bne     r2, r5, RegTest2Error       \n" \\r
555         "   addi    r2, r0, 6                   \n" \\r
556         "   bne     r2, r6, RegTest2Error       \n" \\r
557         "   addi    r2, r0, 7                   \n" \\r
558         "   bne     r2, r7, RegTest2Error       \n" \\r
559         "   addi    r2, r0, 8                   \n" \\r
560         "   bne     r2, r8, RegTest2Error       \n" \\r
561         "   addi    r2, r0, 9                   \n" \\r
562         "   bne     r2, r9, RegTest2Error       \n" \\r
563         "   addi    r2, r0, 10                   \n" \\r
564         "   bne     r2, r10, RegTest2Error       \n" \\r
565         "   addi    r2, r0, 11                   \n" \\r
566         "   bne     r2, r11, RegTest2Error       \n" \\r
567         "   addi    r2, r0, 12                   \n" \\r
568         "   bne     r2, r12, RegTest2Error       \n" \\r
569         "   addi    r2, r0, 13                   \n" \\r
570         "   bne     r2, r13, RegTest2Error       \n" \\r
571         "   addi    r2, r0, 14                   \n" \\r
572         "   bne     r2, r14, RegTest2Error       \n" \\r
573         "   addi    r2, r0, 15                   \n" \\r
574         "   bne     r2, r15, RegTest2Error       \n" \\r
575         "   addi    r2, r0, 16                   \n" \\r
576         "   bne     r2, r16, RegTest2Error       \n" \\r
577         "   addi    r2, r0, 17                   \n" \\r
578         "   bne     r2, r17, RegTest2Error       \n" \\r
579         "   addi    r2, r0, 18                   \n" \\r
580         "   bne     r2, r18, RegTest2Error       \n" \\r
581         "   addi    r2, r0, 19                   \n" \\r
582         "   bne     r2, r19, RegTest2Error       \n" \\r
583         "   addi    r2, r0, 20                   \n" \\r
584         "   bne     r2, r20, RegTest2Error       \n" \\r
585         "   addi    r2, r0, 21                   \n" \\r
586         "   bne     r2, r21, RegTest2Error       \n" \\r
587         "   addi    r2, r0, 22                   \n" \\r
588         "   bne     r2, r22, RegTest2Error       \n" \\r
589         "   addi    r2, r0, 23                   \n" \\r
590         "   bne     r2, r23, RegTest2Error       \n" \\r
591         "   addi    r2, r0, 28                   \n" \\r
592         "   bne     r2, r28, RegTest2Error       \n" \\r
593         "   addi    r2, r0, 31                   \n" \\r
594         "   bne     r2, r31, RegTest2Error       \n" \\r
595         "   ldw     r2, %gprel(ulRegTest2Counter)(gp)       \n" \\r
596         "   addi    r2, r2, 1                   \n" \\r
597         "   stw     r2, %gprel(ulRegTest2Counter)(gp)       \n" \\r
598         "   br      RegTest2                    \n" \\r
599         "RegTest2Error:                         \n" \\r
600         "   br      RegTest2Error               \n"\r
601     );\r
602 }\r
603 /*-----------------------------------------------------------*/\r
604 \r