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