]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RX600_RX62N-RDK_GNURX/RTOSDemo/main-full.c
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Demo / RX600_RX62N-RDK_GNURX / RTOSDemo / main-full.c
1 /*\r
2  * FreeRTOS Kernel V10.0.0\r
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software. If you wish to use our Amazon\r
14  * FreeRTOS name, please do so in a fair use way that does not cause confusion.\r
15  *\r
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22  *\r
23  * http://www.FreeRTOS.org\r
24  * http://aws.amazon.com/freertos\r
25  *\r
26  * 1 tab == 4 spaces!\r
27  */\r
28 \r
29 /* ****************************************************************************\r
30  * This project includes a lot of tasks and tests and is therefore complex.\r
31  * If you would prefer a much simpler project to get started with then select\r
32  * the 'Blinky' build configuration within the HEW IDE.\r
33  * ****************************************************************************\r
34  *\r
35  * Creates all the demo application tasks, then starts the scheduler.  The web\r
36  * documentation provides more details of the standard demo application tasks,\r
37  * which provide no particular functionality but do provide a good example of\r
38  * how to use the FreeRTOS API.  The tasks defined in flop.c are included in the\r
39  * set of standard demo tasks to ensure the floating point unit gets some\r
40  * exercise.\r
41  *\r
42  * In addition to the standard demo tasks, the following tasks and tests are\r
43  * defined and/or created within this file:\r
44  *\r
45  * Webserver ("uIP") task - This serves a number of dynamically generated WEB\r
46  * pages to a standard WEB browser.  The IP and MAC addresses are configured by\r
47  * constants defined at the bottom of FreeRTOSConfig.h.  Use either a standard\r
48  * Ethernet cable to connect through a hug, or a cross over (point to point)\r
49  * cable to connect directly.  Ensure the IP address used is compatible with the\r
50  * IP address of the machine running the browser - the easiest way to achieve\r
51  * this is to ensure the first three octets of the IP addresses are the same.\r
52  *\r
53  * "Reg test" tasks - These fill the registers with known values, then check\r
54  * that each register still contains its expected value.  Each task uses\r
55  * different values.  The tasks run with very low priority so get preempted\r
56  * very frequently.  A check variable is incremented on each iteration of the\r
57  * test loop.  A register containing an unexpected value is indicative of an\r
58  * error in the context switching mechanism and will result in a branch to a\r
59  * null loop - which in turn will prevent the check variable from incrementing\r
60  * any further and allow the check task (described below) to determine that an\r
61  * error has occurred.  The nature of the reg test tasks necessitates that they\r
62  * are written in assembly code.\r
63  *\r
64  * "Check" task - This only executes every five seconds but has a high priority\r
65  * to ensure it gets processor time.  Its main function is to check that all the\r
66  * standard demo tasks are still operational.  While no errors have been\r
67  * discovered the check task will toggle LED 5 every 5 seconds - the toggle\r
68  * rate increasing to 200ms being a visual indication that at least one task has\r
69  * reported unexpected behaviour.\r
70  *\r
71  * "High frequency timer test" - A high frequency periodic interrupt is\r
72  * generated using a timer - the interrupt is assigned a priority above\r
73  * configMAX_SYSCALL_INTERRUPT_PRIORITY so should not be effected by anything\r
74  * the kernel is doing.  The frequency and priority of the interrupt, in\r
75  * combination with other standard tests executed in this demo, should result\r
76  * in interrupts nesting at least 3 and probably 4 deep.  This test is only\r
77  * included in build configurations that have the optimiser switched on.  In\r
78  * optimised builds the count of high frequency ticks is used as the time base\r
79  * for the run time stats.\r
80  *\r
81  * *NOTE 1* If LED5 is toggling every 5 seconds then all the demo application\r
82  * tasks are executing as expected and no errors have been reported in any\r
83  * tasks.  The toggle rate increasing to 200ms indicates that at least one task\r
84  * has reported unexpected behaviour.\r
85  *\r
86  * *NOTE 2* vApplicationSetupTimerInterrupt() is called by the kernel to let\r
87  * the application set up a timer to generate the tick interrupt.  In this\r
88  * example a compare match timer is used for this purpose.\r
89  *\r
90  * *NOTE 3* The CPU must be in Supervisor mode when the scheduler is started.\r
91  * The PowerON_Reset_PC() supplied in resetprg.c with this demo has\r
92  * Change_PSW_PM_to_UserMode() commented out to ensure this is the case.\r
93  *\r
94  * *NOTE 4* The IntQueue common demo tasks test interrupt nesting and make use\r
95  * of all the 8bit timers (as two cascaded 16bit units).\r
96 */\r
97 \r
98 /* Hardware specific includes. */\r
99 #include "iodefine.h"\r
100 \r
101 /* Kernel includes. */\r
102 #include "FreeRTOS.h"\r
103 #include "task.h"\r
104 \r
105 /* Standard demo includes. */\r
106 #include "partest.h"\r
107 #include "flash.h"\r
108 #include "IntQueue.h"\r
109 #include "BlockQ.h"\r
110 #include "death.h"\r
111 #include "integer.h"\r
112 #include "blocktim.h"\r
113 #include "semtest.h"\r
114 #include "PollQ.h"\r
115 #include "GenQTest.h"\r
116 #include "QPeek.h"\r
117 #include "recmutex.h"\r
118 #include "flop.h"\r
119 \r
120 /* Values that are passed into the reg test tasks using the task parameter.  The\r
121 tasks check that the values are passed in correctly. */\r
122 #define mainREG_TEST_1_PARAMETER        ( 0x12121212UL )\r
123 #define mainREG_TEST_2_PARAMETER        ( 0x12345678UL )\r
124 \r
125 /* Priorities at which the tasks are created. */\r
126 #define mainCHECK_TASK_PRIORITY         ( configMAX_PRIORITIES - 1 )\r
127 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 1 )\r
128 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
129 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
130 #define mainCREATOR_TASK_PRIORITY   ( tskIDLE_PRIORITY + 3 )\r
131 #define mainFLASH_TASK_PRIORITY         ( tskIDLE_PRIORITY + 1 )\r
132 #define mainuIP_TASK_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
133 #define mainINTEGER_TASK_PRIORITY   ( tskIDLE_PRIORITY )\r
134 #define mainGEN_QUEUE_TASK_PRIORITY     ( tskIDLE_PRIORITY )\r
135 #define mainFLOP_TASK_PRIORITY          ( tskIDLE_PRIORITY )\r
136 \r
137 /* The WEB server uses string handling functions, which in turn use a bit more\r
138 stack than most of the other tasks. */\r
139 #define mainuIP_STACK_SIZE                      ( configMINIMAL_STACK_SIZE * 3 )\r
140 \r
141 /* The LED toggled by the check task. */\r
142 #define mainCHECK_LED                           ( 5 )\r
143 \r
144 /* The rate at which mainCHECK_LED will toggle when all the tasks are running\r
145 without error.  Controlled by the check task as described at the top of this\r
146 file. */\r
147 #define mainNO_ERROR_CYCLE_TIME         ( 5000 / portTICK_PERIOD_MS )\r
148 \r
149 /* The rate at which mainCHECK_LED will toggle when an error has been reported\r
150 by at least one task.  Controlled by the check task as described at the top of\r
151 this file. */\r
152 #define mainERROR_CYCLE_TIME            ( 200 / portTICK_PERIOD_MS )\r
153 \r
154 \r
155 /*\r
156  * vApplicationMallocFailedHook() will only be called if\r
157  * configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook\r
158  * function that will execute if a call to pvPortMalloc() fails.\r
159  * pvPortMalloc() is called internally by the kernel whenever a task, queue or\r
160  * semaphore is created.  It is also called by various parts of the demo\r
161  * application.\r
162  */\r
163 void vApplicationMallocFailedHook( void );\r
164 \r
165 /*\r
166  * vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set to 1\r
167  * in FreeRTOSConfig.h.  It is a hook function that is called on each iteration\r
168  * of the idle task.  It is essential that code added to this hook function\r
169  * never attempts to block in any way (for example, call xQueueReceive() with\r
170  * a block time specified).  If the application makes use of the vTaskDelete()\r
171  * API function (as this demo application does) then it is also important that\r
172  * vApplicationIdleHook() is permitted to return to its calling function because\r
173  * it is the responsibility of the idle task to clean up memory allocated by the\r
174  * kernel to any task that has since been deleted.\r
175  */\r
176 void vApplicationIdleHook( void );\r
177 \r
178 /*\r
179  * vApplicationStackOverflowHook() will only be called if\r
180  * configCHECK_FOR_STACK_OVERFLOW is set to a non-zero value.  The handle and\r
181  * name of the offending task should be passed in the function parameters, but\r
182  * it is possible that the stack overflow will have corrupted these - in which\r
183  * case pxCurrentTCB can be inspected to find the same information.\r
184  */\r
185 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
186 \r
187 /*\r
188  * The reg test tasks as described at the top of this file.\r
189  */\r
190 static void prvRegTest1Task( void *pvParameters );\r
191 static void prvRegTest2Task( void *pvParameters );\r
192 \r
193 /*\r
194  * The actual implementation of the reg test functionality, which, because of\r
195  * the direct register access, have to be in assembly.\r
196  */\r
197 static void prvRegTest1Implementation( void ) __attribute__((naked));\r
198 static void prvRegTest2Implementation( void ) __attribute__((naked));\r
199 \r
200 \r
201 /*\r
202  * The check task as described at the top of this file.\r
203  */\r
204 static void prvCheckTask( void *pvParameters );\r
205 \r
206 /*\r
207  * Contains the implementation of the WEB server.\r
208  */\r
209 extern void vuIP_Task( void *pvParameters );\r
210 \r
211 /*-----------------------------------------------------------*/\r
212 \r
213 /* Variables that are incremented on each iteration of the reg test tasks -\r
214 provided the tasks have not reported any errors.  The check task inspects these\r
215 variables to ensure they are still incrementing as expected.  If a variable\r
216 stops incrementing then it is likely that its associate task has stalled. */\r
217 unsigned long ulRegTest1CycleCount = 0UL, ulRegTest2CycleCount = 0UL;\r
218 \r
219 /* The status message that is displayed at the bottom of the "task stats" web\r
220 page, which is served by the uIP task.  This will report any errors picked up\r
221 by the reg test task. */\r
222 static const char *pcStatusMessage = NULL;\r
223 \r
224 /*-----------------------------------------------------------*/\r
225 \r
226 int main(void)\r
227 {\r
228 extern void HardwareSetup( void );\r
229 \r
230         /* Renesas provided CPU configuration routine.  The clocks are configured in\r
231         here. */\r
232         HardwareSetup();\r
233 \r
234         /* Turn all LEDs off. */\r
235         vParTestInitialise();\r
236 \r
237         /* Start the reg test tasks which test the context switching mechanism. */\r
238         xTaskCreate( prvRegTest1Task, "RegTst1", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_1_PARAMETER, tskIDLE_PRIORITY, NULL );\r
239         xTaskCreate( prvRegTest2Task, "RegTst2", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_2_PARAMETER, tskIDLE_PRIORITY, NULL );\r
240 \r
241         /* The web server task. */\r
242         xTaskCreate( vuIP_Task, "uIP", mainuIP_STACK_SIZE, NULL, mainuIP_TASK_PRIORITY, NULL );\r
243 \r
244         /* Start the check task as described at the top of this file. */\r
245         xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
246 \r
247         /* Create the standard demo tasks. */\r
248         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
249         vCreateBlockTimeTasks();\r
250         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
251         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
252         vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );\r
253         vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
254         vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );\r
255         vStartQueuePeekTasks();\r
256         vStartRecursiveMutexTasks();\r
257         vStartInterruptQueueTasks();\r
258         vStartMathTasks( mainFLOP_TASK_PRIORITY );\r
259 \r
260         /* The suicide tasks must be created last as they need to know how many\r
261         tasks were running prior to their creation in order to ascertain whether\r
262         or not the correct/expected number of tasks are running at any given time. */\r
263         vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
264 \r
265         /* Start the tasks running. */\r
266         vTaskStartScheduler();\r
267 \r
268         /* If all is well we will never reach here as the scheduler will now be\r
269         running.  If we do reach here then it is likely that there was insufficient\r
270         heap available for the idle task to be created. */\r
271         for( ;; );\r
272         \r
273         return 0;\r
274 }\r
275 /*-----------------------------------------------------------*/\r
276 \r
277 static void prvCheckTask( void *pvParameters )\r
278 {\r
279 static volatile unsigned long ulLastRegTest1CycleCount = 0UL, ulLastRegTest2CycleCount = 0UL;\r
280 TickType_t xNextWakeTime, xCycleFrequency = mainNO_ERROR_CYCLE_TIME;\r
281 extern void vSetupHighFrequencyTimer( void );\r
282 \r
283         /* If this is being executed then the kernel has been started.  Start the high\r
284         frequency timer test as described at the top of this file.  This is only\r
285         included in the optimised build configuration - otherwise it takes up too much\r
286         CPU time. */\r
287         #ifdef INCLUDE_HIGH_FREQUENCY_TIMER_TEST\r
288                 vSetupHighFrequencyTimer();\r
289         #endif\r
290 \r
291         /* Initialise xNextWakeTime - this only needs to be done once. */\r
292         xNextWakeTime = xTaskGetTickCount();\r
293 \r
294         for( ;; )\r
295         {\r
296                 /* Place this task in the blocked state until it is time to run again. */\r
297                 vTaskDelayUntil( &xNextWakeTime, xCycleFrequency );\r
298 \r
299                 /* Check the standard demo tasks are running without error. */\r
300                 if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
301                 {                       \r
302                         pcStatusMessage = "Error: GenQueue";\r
303                 }\r
304                 else if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
305                 {\r
306                         pcStatusMessage = "Error: QueuePeek\r\n";\r
307                 }\r
308                 else if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
309                 {\r
310                         pcStatusMessage = "Error: BlockQueue\r\n";\r
311                 }\r
312                 else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
313                 {\r
314                         pcStatusMessage = "Error: BlockTime\r\n";\r
315                 }\r
316             else if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
317             {\r
318                         pcStatusMessage = "Error: SemTest\r\n";\r
319             }\r
320             else if( xArePollingQueuesStillRunning() != pdTRUE )\r
321             {\r
322                         pcStatusMessage = "Error: PollQueue\r\n";\r
323             }\r
324             else if( xIsCreateTaskStillRunning() != pdTRUE )\r
325             {\r
326                         pcStatusMessage = "Error: Death\r\n";\r
327             }\r
328             else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
329             {\r
330                         pcStatusMessage = "Error: IntMath\r\n";\r
331             }\r
332             else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
333             {\r
334                         pcStatusMessage = "Error: RecMutex\r\n";\r
335             }\r
336                 else if( xAreIntQueueTasksStillRunning() != pdPASS )\r
337                 {\r
338                         pcStatusMessage = "Error: IntQueue\r\n";\r
339                 }\r
340                 else if( xAreMathsTaskStillRunning() != pdPASS )\r
341                 {\r
342                         pcStatusMessage = "Error: Flop\r\n";\r
343                 }\r
344 \r
345                 /* Check the reg test tasks are still cycling.  They will stop incrementing\r
346                 their loop counters if they encounter an error. */\r
347                 if( ulRegTest1CycleCount == ulLastRegTest1CycleCount )\r
348                 {\r
349                         pcStatusMessage = "Error: RegTest1\r\n";\r
350                 }\r
351 \r
352                 if( ulRegTest2CycleCount == ulLastRegTest2CycleCount )\r
353                 {\r
354                         pcStatusMessage = "Error: RegTest2\r\n";\r
355                 }\r
356 \r
357                 ulLastRegTest1CycleCount = ulRegTest1CycleCount;\r
358                 ulLastRegTest2CycleCount = ulRegTest2CycleCount;\r
359 \r
360                 /* Toggle the check LED to give an indication of the system status.  If\r
361                 the LED toggles every 5 seconds then everything is ok.  A faster toggle\r
362                 indicates an error. */\r
363                 vParTestToggleLED( mainCHECK_LED );\r
364 \r
365                 /* Ensure the LED toggles at a faster rate if an error has occurred. */\r
366                 if( pcStatusMessage != NULL )\r
367                 {\r
368                         /* Increase the rate at which this task cycles, which will increase the\r
369                         rate at which mainCHECK_LED flashes to give visual feedback that an error\r
370                         has occurred. */\r
371                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
372                 }\r
373         }\r
374 }\r
375 /*-----------------------------------------------------------*/\r
376 \r
377 /* The RX port uses this callback function to configure its tick interrupt.\r
378 This allows the application to choose the tick interrupt source. */\r
379 void vApplicationSetupTimerInterrupt( void )\r
380 {\r
381         /* Enable compare match timer 0. */\r
382         MSTP( CMT0 ) = 0;\r
383 \r
384         /* Interrupt on compare match. */\r
385         CMT0.CMCR.BIT.CMIE = 1;\r
386 \r
387         /* Set the compare match value. */\r
388         CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );\r
389 \r
390         /* Divide the PCLK by 8. */\r
391         CMT0.CMCR.BIT.CKS = 0;\r
392 \r
393         /* Enable the interrupt... */\r
394         _IEN( _CMT0_CMI0 ) = 1;\r
395 \r
396         /* ...and set its priority to the application defined kernel priority. */\r
397         _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;\r
398 \r
399         /* Start the timer. */\r
400         CMT.CMSTR0.BIT.STR0 = 1;\r
401 }\r
402 /*-----------------------------------------------------------*/\r
403 \r
404 /* This function is explained by the comments above its prototype at the top\r
405 of this file. */\r
406 void vApplicationMallocFailedHook( void )\r
407 {\r
408         for( ;; );\r
409 }\r
410 /*-----------------------------------------------------------*/\r
411 \r
412 /* This function is explained by the comments above its prototype at the top\r
413 of this file. */\r
414 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
415 {\r
416         for( ;; );\r
417 }\r
418 /*-----------------------------------------------------------*/\r
419 \r
420 /* This function is explained by the comments above its prototype at the top\r
421 of this file. */\r
422 void vApplicationIdleHook( void )\r
423 {\r
424 }\r
425 /*-----------------------------------------------------------*/\r
426 \r
427 /* This function is explained in the comments at the top of this file. */\r
428 static void prvRegTest1Task( void *pvParameters )\r
429 {\r
430         if( ( ( unsigned long ) pvParameters ) != mainREG_TEST_1_PARAMETER )\r
431         {\r
432                 /* The parameter did not contain the expected value. */\r
433                 for( ;; )\r
434                 {\r
435                         /* Stop the tick interrupt so its obvious something has gone wrong. */\r
436                         taskDISABLE_INTERRUPTS();\r
437                 }\r
438         }\r
439 \r
440         /* This is an asm function that never returns. */\r
441         prvRegTest1Implementation();\r
442 }\r
443 /*-----------------------------------------------------------*/\r
444 \r
445 /* This function is explained in the comments at the top of this file. */\r
446 static void prvRegTest2Task( void *pvParameters )\r
447 {\r
448         if( ( ( unsigned long ) pvParameters ) != mainREG_TEST_2_PARAMETER )\r
449         {\r
450                 /* The parameter did not contain the expected value. */\r
451                 for( ;; )\r
452                 {\r
453                         /* Stop the tick interrupt so its obvious something has gone wrong. */\r
454                         taskDISABLE_INTERRUPTS();\r
455                 }\r
456         }\r
457 \r
458         /* This is an asm function that never returns. */\r
459         prvRegTest2Implementation();\r
460 }\r
461 /*-----------------------------------------------------------*/\r
462 \r
463 char *pcGetTaskStatusMessage( void )\r
464 {\r
465         /* Not bothered about a critical section here although technically because of\r
466         the task priorities the pointer could change it will be atomic if not near\r
467         atomic and its not critical. */\r
468         if( pcStatusMessage == NULL )\r
469         {\r
470                 return "All tasks running without error";\r
471         }\r
472         else\r
473         {\r
474                 return ( char * ) pcStatusMessage;\r
475         }\r
476 }\r
477 /*-----------------------------------------------------------*/\r
478 \r
479 /* This function is explained in the comments at the top of this file. */\r
480 static void prvRegTest1Implementation( void )\r
481 {\r
482         __asm volatile\r
483         (\r
484                         /* Put a known value in each register. */\r
485                         "MOV    #1, R1                                          \n" \\r
486                         "MOV    #2, R2                                          \n" \\r
487                         "MOV    #3, R3                                          \n" \\r
488                         "MOV    #4, R4                                          \n" \\r
489                         "MOV    #5, R5                                          \n" \\r
490                         "MOV    #6, R6                                          \n" \\r
491                         "MOV    #7, R7                                          \n" \\r
492                         "MOV    #8, R8                                          \n" \\r
493                         "MOV    #9, R9                                          \n" \\r
494                         "MOV    #10, R10                                        \n" \\r
495                         "MOV    #11, R11                                        \n" \\r
496                         "MOV    #12, R12                                        \n" \\r
497                         "MOV    #13, R13                                        \n" \\r
498                         "MOV    #14, R14                                        \n" \\r
499                         "MOV    #15, R15                                        \n" \\r
500                         \r
501                         /* Loop, checking each iteration that each register still contains the\r
502                         expected value. */\r
503                 "TestLoop1:                                                             \n" \\r
504 \r
505                         /* Push the registers that are going to get clobbered. */\r
506                         "PUSHM  R14-R15                                         \n" \\r
507                         \r
508                         /* Increment the loop counter to show this task is still getting CPU time. */\r
509                         "MOV    #_ulRegTest1CycleCount, R14     \n" \\r
510                         "MOV    [ R14 ], R15                            \n" \\r
511                         "ADD    #1, R15                                         \n" \\r
512                         "MOV    R15, [ R14 ]                            \n" \\r
513                         \r
514                         /* Yield to extend the test coverage.  Set the bit in the ITU SWINTR register. */\r
515                         "MOV    #1, R14                                         \n" \\r
516                         "MOV    #0872E0H, R15                           \n" \\r
517                         "MOV.B  R14, [R15]                                      \n" \\r
518                         "NOP                                                            \n" \\r
519                         "NOP                                                            \n" \\r
520                         \r
521                         /* Restore the clobbered registers. */\r
522                         "POPM   R14-R15                                         \n" \\r
523                         \r
524                         /* Now compare each register to ensure it still contains the value that was\r
525                         set before this loop was entered. */\r
526                         "CMP    #1, R1                                          \n" \\r
527                         "BNE    RegTest1Error                           \n" \\r
528                         "CMP    #2, R2                                          \n" \\r
529                         "BNE    RegTest1Error                           \n" \\r
530                         "CMP    #3, R3                                          \n" \\r
531                         "BNE    RegTest1Error                           \n" \\r
532                         "CMP    #4, R4                                          \n" \\r
533                         "BNE    RegTest1Error                           \n" \\r
534                         "CMP    #5, R5                                          \n" \\r
535                         "BNE    RegTest1Error                           \n" \\r
536                         "CMP    #6, R6                                          \n" \\r
537                         "BNE    RegTest1Error                           \n" \\r
538                         "CMP    #7, R7                                          \n" \\r
539                         "BNE    RegTest1Error                           \n" \\r
540                         "CMP    #8, R8                                          \n" \\r
541                         "BNE    RegTest1Error                           \n" \\r
542                         "CMP    #9, R9                                          \n" \\r
543                         "BNE    RegTest1Error                           \n" \\r
544                         "CMP    #10, R10                                        \n" \\r
545                         "BNE    RegTest1Error                           \n" \\r
546                         "CMP    #11, R11                                        \n" \\r
547                         "BNE    RegTest1Error                           \n" \\r
548                         "CMP    #12, R12                                        \n" \\r
549                         "BNE    RegTest1Error                           \n" \\r
550                         "CMP    #13, R13                                        \n" \\r
551                         "BNE    RegTest1Error                           \n" \\r
552                         "CMP    #14, R14                                        \n" \\r
553                         "BNE    RegTest1Error                           \n" \\r
554                         "CMP    #15, R15                                        \n" \\r
555                         "BNE    RegTest1Error                           \n" \\r
556 \r
557                         /* All comparisons passed, start a new itteratio of this loop. */\r
558                         "BRA            TestLoop1                               \n" \\r
559                         \r
560                 "RegTest1Error:                                                 \n" \\r
561                         /* A compare failed, just loop here so the loop counter stops incrementing\r
562                         - causing the check task to indicate the error. */\r
563                         "BRA RegTest1Error                                        "\r
564         );\r
565 }\r
566 /*-----------------------------------------------------------*/\r
567 \r
568 /* This function is explained in the comments at the top of this file. */\r
569 static void prvRegTest2Implementation( void )\r
570 {\r
571         __asm volatile\r
572         (\r
573                         /* Put a known value in each register. */\r
574                         "MOV    #10H, R1                                        \n" \\r
575                         "MOV    #20H, R2                                        \n" \\r
576                         "MOV    #30H, R3                                        \n" \\r
577                         "MOV    #40H, R4                                        \n" \\r
578                         "MOV    #50H, R5                                        \n" \\r
579                         "MOV    #60H, R6                                        \n" \\r
580                         "MOV    #70H, R7                                        \n" \\r
581                         "MOV    #80H, R8                                        \n" \\r
582                         "MOV    #90H, R9                                        \n" \\r
583                         "MOV    #100H, R10                                      \n" \\r
584                         "MOV    #110H, R11                                      \n" \\r
585                         "MOV    #120H, R12                                      \n" \\r
586                         "MOV    #130H, R13                                      \n" \\r
587                         "MOV    #140H, R14                                      \n" \\r
588                         "MOV    #150H, R15                                      \n" \\r
589                         \r
590                         /* Loop, checking each iteration that each register still contains the\r
591                         expected value. */\r
592                 "TestLoop2:                                                             \n" \\r
593 \r
594                         /* Push the registers that are going to get clobbered. */\r
595                         "PUSHM  R14-R15                                         \n" \\r
596                         \r
597                         /* Increment the loop counter to show this task is still getting CPU time. */\r
598                         "MOV    #_ulRegTest2CycleCount, R14     \n" \\r
599                         "MOV    [ R14 ], R15                            \n" \\r
600                         "ADD    #1, R15                                         \n" \\r
601                         "MOV    R15, [ R14 ]                            \n" \\r
602                         \r
603                         /* Restore the clobbered registers. */\r
604                         "POPM   R14-R15                                         \n" \\r
605                         \r
606                         /* Now compare each register to ensure it still contains the value that was\r
607                         set before this loop was entered. */\r
608                         "CMP    #10H, R1                                        \n" \\r
609                         "BNE    RegTest2Error                           \n" \\r
610                         "CMP    #20H, R2                                        \n" \\r
611                         "BNE    RegTest2Error                           \n" \\r
612                         "CMP    #30H, R3                                        \n" \\r
613                         "BNE    RegTest2Error                           \n" \\r
614                         "CMP    #40H, R4                                        \n" \\r
615                         "BNE    RegTest2Error                           \n" \\r
616                         "CMP    #50H, R5                                        \n" \\r
617                         "BNE    RegTest2Error                           \n" \\r
618                         "CMP    #60H, R6                                        \n" \\r
619                         "BNE    RegTest2Error                           \n" \\r
620                         "CMP    #70H, R7                                        \n" \\r
621                         "BNE    RegTest2Error                           \n" \\r
622                         "CMP    #80H, R8                                        \n" \\r
623                         "BNE    RegTest2Error                           \n" \\r
624                         "CMP    #90H, R9                                        \n" \\r
625                         "BNE    RegTest2Error                           \n" \\r
626                         "CMP    #100H, R10                                      \n" \\r
627                         "BNE    RegTest2Error                           \n" \\r
628                         "CMP    #110H, R11                                      \n" \\r
629                         "BNE    RegTest2Error                           \n" \\r
630                         "CMP    #120H, R12                                      \n" \\r
631                         "BNE    RegTest2Error                           \n" \\r
632                         "CMP    #130H, R13                                      \n" \\r
633                         "BNE    RegTest2Error                           \n" \\r
634                         "CMP    #140H, R14                                      \n" \\r
635                         "BNE    RegTest2Error                           \n" \\r
636                         "CMP    #150H, R15                                      \n" \\r
637                         "BNE    RegTest2Error                           \n" \\r
638 \r
639                         /* All comparisons passed, start a new itteratio of this loop. */\r
640                         "BRA    TestLoop2                                       \n" \\r
641                         \r
642                 "RegTest2Error:                                                 \n" \\r
643                         /* A compare failed, just loop here so the loop counter stops incrementing\r
644                         - causing the check task to indicate the error. */\r
645                         "BRA RegTest2Error                                        "\r
646         );\r
647 }\r
648 \r