]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RX200_RX210-RSK_Renesas/RTOSDemo/main-full.c
acaefb346107db425c746024f462203dbf61ca65
[freertos] / FreeRTOS / Demo / RX200_RX210-RSK_Renesas / 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.  The Blinky build\r
33  * configuration uses main-blinky.c instead of main-full.c.\r
34  * ****************************************************************************\r
35  *\r
36  * Creates all the demo application tasks, then starts the scheduler.  The web\r
37  * documentation provides more details of the standard demo application tasks,\r
38  * which provide no particular functionality but do provide a good example of\r
39  * how to use the FreeRTOS API.\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  * "Reg test" tasks - These fill the registers with known values, then \r
45  * repeatedly check that each register still contains its expected value for \r
46  * the lifetime of the tasks.  Each task uses different values.  The tasks run \r
47  * with very low priority so get preempted very frequently.  A check variable \r
48  * is incremented on each iteration of the test loop.  A register containing an \r
49  * unexpected value is indicative of an error in the context switching \r
50  * mechanism and will result in a branch to a null loop - which in turn will \r
51  * prevent the check variable from incrementing any further and allow the check \r
52  * timer (described below) to determine that an error has occurred.  The nature \r
53  * of the reg test tasks necessitates that they are written in assembly code.\r
54  *\r
55  * "Check Timer" and Callback Function - The check timer period is initially \r
56  * set to five seconds.  The check timer callback function checks that all the \r
57  * standard demo tasks are not only still executing, but are executing without \r
58  * reporting any errors.  If the check timer discovers that a task has either \r
59  * stalled, or reported an error, then it changes its own period from the \r
60  * initial five seconds, to just 200ms.  The check timer callback function \r
61  * also toggles LED 3 each time it is called.  This provides a visual \r
62  * indication of the system status:  If the LED toggles every five seconds, \r
63  * then no issues have been discovered.  If the LED toggles every 200ms, then \r
64  * an issue has been discovered with at least one task.\r
65  *\r
66  * "High frequency timer test" - A high frequency periodic interrupt is\r
67  * generated using a timer - the interrupt is assigned a priority above\r
68  * configMAX_SYSCALL_INTERRUPT_PRIORITY, so will not be effected by anything\r
69  * the kernel is doing.  The frequency and priority of the interrupt, in\r
70  * combination with other standard tests executed in this demo, will result\r
71  * in interrupts nesting at least 3 and probably 4 deep.  This test is only\r
72  * included in build configurations that have the optimiser switched on.\r
73  *\r
74  * "Button and LCD test" - This creates two tasks.  The first simply scrolls\r
75  * a message back and forth along the top line of the LCD display.  If no\r
76  * buttons are pushed, the second also scrolls a message back and forth, but\r
77  * along the bottom line of the display.  The automatic scrolling of the second\r
78  * line of the display can be started and stopped using button SW2.  Once \r
79  * stopped it can then be manually nudged left using button SW3, and manually\r
80  * nudged right using button SW1.  Button pushes generate an interrupt, and the\r
81  * interrupt communicates with the task using a queue.\r
82  *\r
83  * *NOTE 1* vApplicationSetupTimerInterrupt() is called by the kernel to let\r
84  * the application set up a timer to generate the tick interrupt.  In this\r
85  * example a compare match timer is used for this purpose.\r
86  *\r
87  * *NOTE 2* The CPU must be in Supervisor mode when the scheduler is started.\r
88  * The PowerON_Reset_PC() supplied in resetprg.c with this demo has\r
89  * Change_PSW_PM_to_UserMode() commented out to ensure this is the case.\r
90  *\r
91  * *NOTE 3* The IntQueue common demo tasks test interrupt nesting and make use\r
92  * of all the 8bit timers (as two cascaded 16bit units).\r
93 */\r
94 \r
95 /* Standard includes. */\r
96 #include <string.h>\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 #include "timers.h"\r
105 #include "semphr.h"\r
106 \r
107 /* Standard demo includes. */\r
108 #include "partest.h"\r
109 #include "flash.h"\r
110 #include "IntQueue.h"\r
111 #include "BlockQ.h"\r
112 #include "death.h"\r
113 #include "integer.h"\r
114 #include "blocktim.h"\r
115 #include "semtest.h"\r
116 #include "PollQ.h"\r
117 #include "GenQTest.h"\r
118 #include "QPeek.h"\r
119 #include "recmutex.h"\r
120 \r
121 /* Demo specific tasks. */\r
122 #include "ButtonAndLCD.h"\r
123 \r
124 /* Peripheral includes. */\r
125 #include "lcd.h"\r
126 \r
127 /* Values that are passed into the reg test tasks using the task parameter.  \r
128 The tasks check that the values are passed in correctly. */\r
129 #define mainREG_TEST_1_PARAMETER        ( 0x12121212UL )\r
130 #define mainREG_TEST_2_PARAMETER        ( 0x12345678UL )\r
131 \r
132 /* Priorities at which the tasks are created. */\r
133 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 1 )\r
134 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
135 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
136 #define mainCREATOR_TASK_PRIORITY   ( tskIDLE_PRIORITY + 3 )\r
137 #define mainFLASH_TASK_PRIORITY         ( tskIDLE_PRIORITY + 1 )\r
138 #define mainINTEGER_TASK_PRIORITY   ( tskIDLE_PRIORITY )\r
139 #define mainGEN_QUEUE_TASK_PRIORITY     ( tskIDLE_PRIORITY )\r
140 #define mainFLOP_TASK_PRIORITY          ( tskIDLE_PRIORITY )\r
141 \r
142 /* The LED toggled by the check timer. */\r
143 #define mainCHECK_LED                           ( 3 )\r
144 \r
145 /* The period at which the check timer will expire, in ms, provided no errors\r
146 have been reported by any of the standard demo tasks.  ms are converted to the\r
147 equivalent in ticks using the portTICK_PERIOD_MS constant. */\r
148 #define mainCHECK_TIMER_PERIOD_MS                       ( 5000UL / portTICK_PERIOD_MS )\r
149 \r
150 /* The period at which the check timer will expire, in ms, if an error has been\r
151 reported in one of the standard demo tasks.  ms are converted to the equivalent\r
152 in ticks using the portTICK_PERIOD_MS constant. */\r
153 #define mainERROR_CHECK_TIMER_PERIOD_MS         ( 200UL / portTICK_PERIOD_MS )\r
154 \r
155 /* A block time of zero simple means "Don't Block". */\r
156 #define mainDONT_BLOCK                          ( 0UL )\r
157 \r
158 /*\r
159  * vApplicationMallocFailedHook() will only be called if\r
160  * configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook\r
161  * function that will execute if a call to pvPortMalloc() fails.\r
162  * pvPortMalloc() is called internally by the kernel whenever a task, queue or\r
163  * semaphore is created.  It is also called by various parts of the demo\r
164  * application.\r
165  */\r
166 void vApplicationMallocFailedHook( void );\r
167 \r
168 /*\r
169  * vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set to 1\r
170  * in FreeRTOSConfig.h.  It is a hook function that is called on each iteration\r
171  * of the idle task.  It is essential that code added to this hook function\r
172  * never attempts to block in any way (for example, call xQueueReceive() with\r
173  * a block time specified).  If the application makes use of the vTaskDelete()\r
174  * API function (as this demo application does) then it is also important that\r
175  * vApplicationIdleHook() is permitted to return to its calling function because\r
176  * it is the responsibility of the idle task to clean up memory allocated by the\r
177  * kernel to any task that has since been deleted.\r
178  */\r
179 void vApplicationIdleHook( void );\r
180 \r
181 /*\r
182  * vApplicationStackOverflowHook() will only be called if\r
183  * configCHECK_FOR_STACK_OVERFLOW is set to a non-zero value.  The handle and\r
184  * name of the offending task should be passed in the function parameters, but\r
185  * it is possible that the stack overflow will have corrupted these - in which\r
186  * case pxCurrentTCB can be inspected to find the same information.\r
187  */\r
188 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
189 \r
190 /*\r
191  * The reg test tasks as described at the top of this file.\r
192  */\r
193 static void prvRegTest1Task( void *pvParameters );\r
194 static void prvRegTest2Task( void *pvParameters );\r
195 \r
196 /*\r
197  * The actual implementation of the reg test functionality, which, because of\r
198  * the direct register access, have to be in assembly.\r
199  */\r
200 static void prvRegTest1Implementation( void );\r
201 static void prvRegTest2Implementation( void );\r
202 \r
203 /*\r
204  * The check timer callback function, as described at the top of this file.\r
205  */\r
206 static void prvCheckTimerCallback( TimerHandle_t xTimer );\r
207 \r
208 \r
209 /*-----------------------------------------------------------*/\r
210 \r
211 /* Variables that are incremented on each iteration of the reg test tasks -\r
212 provided the tasks have not reported any errors.  The check timer inspects these\r
213 variables to ensure they are still incrementing as expected.  If a variable\r
214 stops incrementing then it is likely that its associate task has stalled. */\r
215 unsigned long ulRegTest1CycleCount = 0UL, ulRegTest2CycleCount = 0UL;\r
216 \r
217 /* The check timer.  This uses prvCheckTimerCallback() as its callback\r
218 function. */\r
219 static TimerHandle_t xCheckTimer = NULL;\r
220 \r
221 /*-----------------------------------------------------------*/\r
222 \r
223 void main(void)\r
224 {\r
225 extern void HardwareSetup( void );\r
226 \r
227         /* Renesas provided CPU configuration routine.  The clocks are configured in\r
228         here. */\r
229         HardwareSetup();        \r
230 \r
231         /* Turn all LEDs off. */\r
232         vParTestInitialise();\r
233 \r
234         /* Start the reg test tasks which test the context switching mechanism. */\r
235         xTaskCreate( prvRegTest1Task, "RegTst1", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_1_PARAMETER, tskIDLE_PRIORITY, NULL );\r
236         xTaskCreate( prvRegTest2Task, "RegTst2", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_2_PARAMETER, tskIDLE_PRIORITY, NULL );\r
237 \r
238         /* The button and LCD tasks, as described at the top of this file. */\r
239         vStartButtonAndLCDDemo();\r
240 \r
241         /* Create the standard demo tasks. */\r
242         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
243         vCreateBlockTimeTasks();\r
244         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
245         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
246         vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );\r
247         vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
248         vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );\r
249         vStartQueuePeekTasks();\r
250         vStartRecursiveMutexTasks();\r
251         vStartInterruptQueueTasks();\r
252 \r
253         /* The suicide tasks must be created last as they need to know how many\r
254         tasks were running prior to their creation in order to ascertain whether\r
255         or not the correct/expected number of tasks are running at any given time. */\r
256         vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
257 \r
258         /* Create the software timer that performs the 'check' functionality,\r
259         as described at the top of this file. */\r
260         xCheckTimer = xTimerCreate( "CheckTimer",/* A text name, purely to help debugging. */\r
261                                                                 ( mainCHECK_TIMER_PERIOD_MS ),          /* The timer period, in this case 5000ms (5s). */\r
262                                                                 pdTRUE,                                                         /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */\r
263                                                                 ( void * ) 0,                                           /* The ID is not used, so can be set to anything. */\r
264                                                                 prvCheckTimerCallback                           /* The callback function that inspects the status of all the other tasks. */\r
265                                                           );\r
266                                                           \r
267         configASSERT( xCheckTimer );\r
268         \r
269         /* Start the check timer.  It will actually start when the scheduler is\r
270         started. */\r
271         xTimerStart( xCheckTimer, mainDONT_BLOCK );\r
272 \r
273         /* Start the tasks running. */\r
274         vTaskStartScheduler();\r
275 \r
276         /* If all is well we will never reach here as the scheduler will now be\r
277         running.  If we do reach here then it is likely that there was insufficient\r
278         heap available for the idle task to be created. */\r
279         for( ;; );\r
280 }\r
281 /*-----------------------------------------------------------*/\r
282 \r
283 static void prvCheckTimerCallback( TimerHandle_t xTimer )\r
284 {\r
285 static long lChangedTimerPeriodAlready = pdFALSE, lErrorStatus = pdPASS;\r
286 static volatile unsigned long ulLastRegTest1CycleCount = 0UL, ulLastRegTest2CycleCount = 0UL;\r
287 \r
288         /* Check the standard demo tasks are running without error. */\r
289         if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
290         {\r
291                 lErrorStatus = pdFAIL;\r
292         }\r
293         else if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
294         {\r
295                 lErrorStatus = pdFAIL;\r
296         }\r
297         else if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
298         {\r
299                 lErrorStatus = pdFAIL;\r
300         }\r
301         else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
302         {\r
303                 lErrorStatus = pdFAIL;\r
304         }\r
305         else if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
306         {\r
307                 lErrorStatus = pdFAIL;\r
308         }\r
309         else if( xArePollingQueuesStillRunning() != pdTRUE )\r
310         {\r
311                 lErrorStatus = pdFAIL;\r
312         }\r
313         else if( xIsCreateTaskStillRunning() != pdTRUE )\r
314         {\r
315                 lErrorStatus = pdFAIL;\r
316         }\r
317         else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
318         {\r
319                 lErrorStatus = pdFAIL;\r
320         }\r
321         else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
322         {\r
323                 lErrorStatus = pdFAIL;\r
324         }\r
325         else if( xAreIntQueueTasksStillRunning() != pdPASS )\r
326         {\r
327                 lErrorStatus = pdFAIL;\r
328         }\r
329 \r
330         /* Check the reg test tasks are still cycling.  They will stop incrementing\r
331         their loop counters if they encounter an error. */\r
332         if( ulRegTest1CycleCount == ulLastRegTest1CycleCount )\r
333         {\r
334                 lErrorStatus = pdFAIL;\r
335         }\r
336 \r
337         if( ulRegTest2CycleCount == ulLastRegTest2CycleCount )\r
338         {\r
339                 lErrorStatus = pdFAIL;\r
340         }\r
341 \r
342         ulLastRegTest1CycleCount = ulRegTest1CycleCount;\r
343         ulLastRegTest2CycleCount = ulRegTest2CycleCount;\r
344 \r
345         /* Toggle the check LED to give an indication of the system status.  If\r
346         the LED toggles every 5 seconds then everything is ok.  A faster toggle\r
347         indicates an error. */\r
348         vParTestToggleLED( mainCHECK_LED );\r
349         \r
350         /* Was an error detected this time through the callback execution? */\r
351         if( lErrorStatus != pdPASS )\r
352         {\r
353                 if( lChangedTimerPeriodAlready == pdFALSE )\r
354                 {\r
355                         lChangedTimerPeriodAlready = pdTRUE;\r
356                         \r
357                         /* This call to xTimerChangePeriod() uses a zero block time.  \r
358                         Functions called from inside of a timer callback function must \r
359                         *never* attempt to block. */\r
360                         xTimerChangePeriod( xCheckTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );\r
361                 }\r
362         }\r
363 }\r
364 /*-----------------------------------------------------------*/\r
365 \r
366 /* The RX port uses this callback function to configure its tick interrupt.\r
367 This allows the application to choose the tick interrupt source. */\r
368 void vApplicationSetupTimerInterrupt( void )\r
369 {\r
370         /* Enable compare match timer 0. */\r
371         MSTP( CMT0 ) = 0;\r
372 \r
373         /* Interrupt on compare match. */\r
374         CMT0.CMCR.BIT.CMIE = 1;\r
375 \r
376         /* Set the compare match value. */\r
377         CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );\r
378 \r
379         /* Divide the PCLK by 8. */\r
380         CMT0.CMCR.BIT.CKS = 0;\r
381 \r
382         /* Enable the interrupt... */\r
383         _IEN( _CMT0_CMI0 ) = 1;\r
384 \r
385         /* ...and set its priority to the application defined kernel priority. */\r
386         _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;\r
387 \r
388         /* Start the timer. */\r
389         CMT.CMSTR0.BIT.STR0 = 1;\r
390 }\r
391 /*-----------------------------------------------------------*/\r
392 \r
393 /* This function is explained by the comments above its prototype at the top\r
394 of this file. */\r
395 void vApplicationMallocFailedHook( void )\r
396 {\r
397         for( ;; );\r
398 }\r
399 /*-----------------------------------------------------------*/\r
400 \r
401 /* This function is explained by the comments above its prototype at the top\r
402 of this file. */\r
403 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
404 {\r
405         for( ;; );\r
406 }\r
407 /*-----------------------------------------------------------*/\r
408 \r
409 /* This function is explained by the comments above its prototype at the top\r
410 of this file. */\r
411 void vApplicationIdleHook( void )\r
412 {\r
413         /* If this is being executed then the kernel has been started.  Start the high\r
414         frequency timer test as described at the top of this file.  This is only\r
415         included in the optimised build configuration - otherwise it takes up too much\r
416         CPU time and can disrupt other tests. */\r
417         #ifdef INCLUDE_HIGH_FREQUENCY_TIMER_TEST\r
418         static portBASE_TYPE xTimerTestStarted = pdFALSE;\r
419         extern void vSetupHighFrequencyTimer( void );\r
420                 if( xTimerTestStarted == pdFALSE )\r
421                 {\r
422                         vSetupHighFrequencyTimer();\r
423                         xTimerTestStarted = pdTRUE;\r
424                 }\r
425         #endif\r
426 }\r
427 /*-----------------------------------------------------------*/\r
428 \r
429 /* This function is explained in the comments at the top of this file. */\r
430 static void prvRegTest1Task( void *pvParameters )\r
431 {\r
432         if( ( ( unsigned long ) pvParameters ) != mainREG_TEST_1_PARAMETER )\r
433         {\r
434                 /* The parameter did not contain the expected value. */\r
435                 for( ;; )\r
436                 {\r
437                         /* Stop the tick interrupt so its obvious something has gone wrong. */\r
438                         taskDISABLE_INTERRUPTS();\r
439                 }\r
440         }\r
441 \r
442         /* This is an inline asm function that never returns. */\r
443         prvRegTest1Implementation();\r
444 }\r
445 /*-----------------------------------------------------------*/\r
446 \r
447 /* This function is explained in the comments at the top of this file. */\r
448 static void prvRegTest2Task( void *pvParameters )\r
449 {\r
450         if( ( ( unsigned long ) pvParameters ) != mainREG_TEST_2_PARAMETER )\r
451         {\r
452                 /* The parameter did not contain the expected value. */\r
453                 for( ;; )\r
454                 {\r
455                         /* Stop the tick interrupt so its obvious something has gone wrong. */\r
456                         taskDISABLE_INTERRUPTS();\r
457                 }\r
458         }\r
459 \r
460         /* This is an inline asm function that never returns. */\r
461         prvRegTest2Implementation();\r
462 }\r
463 /*-----------------------------------------------------------*/\r
464 \r
465 /* This function is explained in the comments at the top of this file. */\r
466 #pragma inline_asm prvRegTest1Implementation\r
467 static void prvRegTest1Implementation( void )\r
468 {\r
469         ; Put a known value in each register.\r
470         MOV.L   #1, R1\r
471         MOV.L   #2, R2\r
472         MOV.L   #3, R3\r
473         MOV.L   #4, R4\r
474         MOV.L   #5, R5\r
475         MOV.L   #6, R6\r
476         MOV.L   #7, R7\r
477         MOV.L   #8, R8\r
478         MOV.L   #9, R9\r
479         MOV.L   #10, R10\r
480         MOV.L   #11, R11\r
481         MOV.L   #12, R12\r
482         MOV.L   #13, R13\r
483         MOV.L   #14, R14\r
484         MOV.L   #15, R15\r
485 \r
486         ; Loop, checking each iteration that each register still contains the\r
487         ; expected value.\r
488 TestLoop1:\r
489 \r
490         ; Push the registers that are going to get clobbered.\r
491         PUSHM   R14-R15\r
492 \r
493         ; Increment the loop counter to show this task is still getting CPU time.\r
494         MOV.L   #_ulRegTest1CycleCount, R14\r
495         MOV.L   [ R14 ], R15\r
496         ADD             #1, R15\r
497         MOV.L   R15, [ R14 ]\r
498 \r
499         ; Yield to extend the text coverage.  Set the bit in the ITU SWINTR register.\r
500         MOV.L   #1, R14\r
501         MOV.L   #0872E0H, R15\r
502         MOV.B   R14, [R15]\r
503         NOP\r
504         NOP\r
505 \r
506         ; Restore the clobbered registers.\r
507         POPM    R14-R15\r
508 \r
509         ; Now compare each register to ensure it still contains the value that was\r
510         ; set before this loop was entered.\r
511         CMP             #1, R1\r
512         BNE             RegTest1Error\r
513         CMP             #2, R2\r
514         BNE             RegTest1Error\r
515         CMP             #3, R3\r
516         BNE             RegTest1Error\r
517         CMP             #4, R4\r
518         BNE             RegTest1Error\r
519         CMP             #5, R5\r
520         BNE             RegTest1Error\r
521         CMP             #6, R6\r
522         BNE             RegTest1Error\r
523         CMP             #7, R7\r
524         BNE             RegTest1Error\r
525         CMP             #8, R8\r
526         BNE             RegTest1Error\r
527         CMP             #9, R9\r
528         BNE             RegTest1Error\r
529         CMP             #10, R10\r
530         BNE             RegTest1Error\r
531         CMP             #11, R11\r
532         BNE             RegTest1Error\r
533         CMP             #12, R12\r
534         BNE             RegTest1Error\r
535         CMP             #13, R13\r
536         BNE             RegTest1Error\r
537         CMP             #14, R14\r
538         BNE             RegTest1Error\r
539         CMP             #15, R15\r
540         BNE             RegTest1Error\r
541 \r
542         ; All comparisons passed, start a new itteratio of this loop.\r
543         BRA             TestLoop1\r
544 \r
545 RegTest1Error:\r
546         ; A compare failed, just loop here so the loop counter stops incrementing\r
547         ; causing the check timer to indicate the error.\r
548         BRA RegTest1Error\r
549 }\r
550 /*-----------------------------------------------------------*/\r
551 \r
552 /* This function is explained in the comments at the top of this file. */\r
553 #pragma inline_asm prvRegTest2Implementation\r
554 static void prvRegTest2Implementation( void )\r
555 {\r
556         ; Put a known value in each register.\r
557         MOV.L   #10, R1\r
558         MOV.L   #20, R2\r
559         MOV.L   #30, R3\r
560         MOV.L   #40, R4\r
561         MOV.L   #50, R5\r
562         MOV.L   #60, R6\r
563         MOV.L   #70, R7\r
564         MOV.L   #80, R8\r
565         MOV.L   #90, R9\r
566         MOV.L   #100, R10\r
567         MOV.L   #110, R11\r
568         MOV.L   #120, R12\r
569         MOV.L   #130, R13\r
570         MOV.L   #140, R14\r
571         MOV.L   #150, R15\r
572 \r
573         ; Loop, checking on each iteration that each register still contains the\r
574         ; expected value.\r
575 TestLoop2:\r
576 \r
577         ; Push the registers that are going to get clobbered.\r
578         PUSHM   R14-R15\r
579 \r
580         ; Increment the loop counter to show this task is still getting CPU time.\r
581         MOV.L   #_ulRegTest2CycleCount, R14\r
582         MOV.L   [ R14 ], R15\r
583         ADD             #1, R15\r
584         MOV.L   R15, [ R14 ]\r
585 \r
586         ; Restore the clobbered registers.\r
587         POPM    R14-R15\r
588 \r
589         CMP             #10, R1\r
590         BNE             RegTest2Error\r
591         CMP             #20, R2\r
592         BNE             RegTest2Error\r
593         CMP             #30, R3\r
594         BNE             RegTest2Error\r
595         CMP             #40, R4\r
596         BNE             RegTest2Error\r
597         CMP             #50, R5\r
598         BNE             RegTest2Error\r
599         CMP             #60, R6\r
600         BNE             RegTest2Error\r
601         CMP             #70, R7\r
602         BNE             RegTest2Error\r
603         CMP             #80, R8\r
604         BNE             RegTest2Error\r
605         CMP             #90, R9\r
606         BNE             RegTest2Error\r
607         CMP             #100, R10\r
608         BNE             RegTest2Error\r
609         CMP             #110, R11\r
610         BNE             RegTest2Error\r
611         CMP             #120, R12\r
612         BNE             RegTest2Error\r
613         CMP             #130, R13\r
614         BNE             RegTest2Error\r
615         CMP             #140, R14\r
616         BNE             RegTest2Error\r
617         CMP             #150, R15\r
618         BNE             RegTest2Error\r
619 \r
620         ; All comparisons passed, start a new itteratio of this loop.\r
621         BRA             TestLoop2\r
622 \r
623 RegTest2Error:\r
624         ; A compare failed, just loop here so the loop counter stops incrementing\r
625         ; - causing the check timer to indicate the error.\r
626         BRA RegTest2Error\r
627 }\r
628 /*-----------------------------------------------------------*/\r
629 \r