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