]> begriffs open source - freertos/blob - Demo/RX600_RX62N-MDK_Renesas/RTOSDemo/main-full.c
Continue development, plus add Blinky build configuration.
[freertos] / Demo / RX600_RX62N-MDK_Renesas / RTOSDemo / main-full.c
1 /*\r
2     FreeRTOS V6.0.5 - Copyright (C) 2010 Real Time Engineers Ltd.\r
3 \r
4     ***************************************************************************\r
5     *                                                                         *\r
6     * If you are:                                                             *\r
7     *                                                                         *\r
8     *    + New to FreeRTOS,                                                   *\r
9     *    + Wanting to learn FreeRTOS or multitasking in general quickly       *\r
10     *    + Looking for basic training,                                        *\r
11     *    + Wanting to improve your FreeRTOS skills and productivity           *\r
12     *                                                                         *\r
13     * then take a look at the FreeRTOS eBook                                  *\r
14     *                                                                         *\r
15     *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *\r
16     *                  http://www.FreeRTOS.org/Documentation                  *\r
17     *                                                                         *\r
18     * A pdf reference manual is also available.  Both are usually delivered   *\r
19     * to your inbox within 20 minutes to two hours when purchased between 8am *\r
20     * and 8pm GMT (although please allow up to 24 hours in case of            *\r
21     * exceptional circumstances).  Thank you for your support!                *\r
22     *                                                                         *\r
23     ***************************************************************************\r
24 \r
25     This file is part of the FreeRTOS distribution.\r
26 \r
27     FreeRTOS is free software; you can redistribute it and/or modify it under\r
28     the terms of the GNU General Public License (version 2) as published by the\r
29     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
30     ***NOTE*** The exception to the GPL is included to allow you to distribute\r
31     a combined work that includes FreeRTOS without being obliged to provide the\r
32     source code for proprietary components outside of the FreeRTOS kernel.\r
33     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT\r
34     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
35     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
36     more details. You should have received a copy of the GNU General Public \r
37     License and the FreeRTOS license exception along with FreeRTOS; if not it \r
38     can be viewed here: http://www.freertos.org/a00114.html and also obtained \r
39     by writing to Richard Barry, contact details for whom are available on the\r
40     FreeRTOS WEB site.\r
41 \r
42     1 tab == 4 spaces!\r
43 \r
44     http://www.FreeRTOS.org - Documentation, latest information, license and\r
45     contact details.\r
46 \r
47     http://www.SafeRTOS.com - A version that is certified for use in safety\r
48     critical systems.\r
49 \r
50     http://www.OpenRTOS.com - Commercial support, development, porting,\r
51     licensing and training services.\r
52 */\r
53 \r
54 /* \r
55  * This project includes a lot of tasks and tests and is therefore complex.\r
56  * If you would prefer a much simpler project to get started with then select\r
57  * the 'Blinky' build configuration within the HEW IDE.\r
58  *\r
59  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
60  * documentation provides more details of the standard demo application tasks,\r
61  * which provide no particular functionality but do provide a good example of\r
62  * how to use the FreeRTOS API.  The tasks defined in flop.c are included in the\r
63  * set of standard demo tasks to ensure the floating point unit gets some\r
64  * exercise. \r
65  *\r
66  * In addition to the standard demo tasks, the following tasks and tests are \r
67  * defined and/or created within this file:\r
68  *\r
69  * "Reg test" tasks - These fill the registers with known values, then check\r
70  * that each register still contains its expected value.  Each task uses\r
71  * different values.  The tasks run with very low priority so get preempted very\r
72  * frequently.  A register containing an unexpected value is indicative of an\r
73  * error in the context switching mechanism and will result in interrupts being\r
74  * disabled and a branch to a null loop.  This has the effect of stopping \r
75  * execution of all the tests and tasks, which in turn results in all LED\r
76  * activity stopping too.  The nature of the reg test tasks necessitates that \r
77  * they are written in assembly code.  The check task (described below) checks \r
78  * that the reg test tasks are still executing and will indicate an error if\r
79  * either reg test task is found to have stalled.\r
80  *\r
81  * "Check" task - This only executes every five seconds but has a high priority\r
82  * to ensure it gets processor time.  Its main function is to check that all the\r
83  * standard demo tasks are still operational.  While no errors have been\r
84  * discovered the check task will toggle LED 5 every 5 seconds - the toggle\r
85  * rate increasing to 200ms being a visual indication that at least one task has\r
86  * reported unexpected behaviour.\r
87  *\r
88  * "High frequency timer test" - A high frequency periodic interrupt is \r
89  * generated using a timer - the interrupt is assigned a priority above \r
90  * configMAX_SYSCALL_INTERRUPT_PRIORITY so should not be effected by anything\r
91  * the kernel is doing.  The interrupt service routine measures the number of \r
92  * counts a separate timer performs between each interrupt to determine the \r
93  * jitter in the interrupt timing.\r
94  *\r
95  * *NOTE 1* If LED5 is toggling every 5 seconds then all the demo application\r
96  * tasks are executing as expected and no errors have been reported in any \r
97  * tasks.  The toggle rate increasing to 200ms indicates that at least one task\r
98  * has reported unexpected behaviour.\r
99  * \r
100  * *NOTE 2* vApplicationSetupTimerInterrupt() is called by the kernel to let\r
101  * the application set up a timer to generate the tick interrupt.  In this\r
102  * example a compare match timer is used for this purpose.  \r
103  *\r
104  * *NOTE 3* The CPU must be in Supervisor mode when the scheduler is started.\r
105  * The PowerON_Reset_PC() supplied in resetprg.c with this demo has \r
106  * Change_PSW_PM_to_UserMode() commented out to ensure this is the case.\r
107  *\r
108  * *NOTE 4* The IntQueue common demo tasks test interrupt nesting and make use\r
109  * of all the 8bit timers (as two cascaded 16bit units).\r
110 */\r
111 \r
112 /* Hardware specific includes. */\r
113 #include "iodefine.h"\r
114 \r
115 /* Kernel includes. */\r
116 #include "FreeRTOS.h"\r
117 #include "task.h"\r
118 \r
119 /* Standard demo includes. */\r
120 #include "partest.h"\r
121 #include "flash.h"\r
122 #include "IntQueue.h"\r
123 #include "BlockQ.h"\r
124 #include "death.h"\r
125 #include "integer.h"\r
126 #include "blocktim.h"\r
127 #include "semtest.h"\r
128 #include "PollQ.h"\r
129 #include "GenQTest.h"\r
130 #include "QPeek.h"\r
131 #include "recmutex.h"\r
132 #include "flop.h"\r
133 \r
134 /* Values that are passed into the reg test tasks using the task parameter.  The \r
135 tasks check that the values are passed in correctly. */\r
136 #define mainREG_TEST_1_PARAMETER        ( 0x12121212UL )\r
137 #define mainREG_TEST_2_PARAMETER        ( 0x12345678UL )\r
138 \r
139 /* Priorities at which the tasks are created. */\r
140 #define mainCHECK_TASK_PRIORITY         ( configMAX_PRIORITIES - 1 )\r
141 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 1 )\r
142 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
143 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
144 #define mainCREATOR_TASK_PRIORITY   ( tskIDLE_PRIORITY + 3 )\r
145 #define mainFLASH_TASK_PRIORITY         ( tskIDLE_PRIORITY + 1 )\r
146 #define mainuIP_TASK_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
147 #define mainINTEGER_TASK_PRIORITY   ( tskIDLE_PRIORITY )\r
148 #define mainGEN_QUEUE_TASK_PRIORITY     ( tskIDLE_PRIORITY )\r
149 #define mainFLOP_TASK_PRIORITY          ( tskIDLE_PRIORITY )\r
150 \r
151 /* The LED toggled by the check task. */\r
152 #define mainCHECK_LED                                           ( 5 )\r
153 \r
154 /* The rate at which mainCHECK_LED will toggle when all the tasks are running\r
155 without error.  Controlled by the check task as described at the top of this\r
156 file. */\r
157 #define mainNO_ERROR_CYCLE_TIME                         ( 5000 / portTICK_RATE_MS )\r
158 \r
159 /* The rate at which mainCHECK_LED will toggle when an error has been reported\r
160 by at least one task.  Controlled by the check task as described at the top of \r
161 this file. */\r
162 #define mainERROR_CYCLE_TIME                            ( 200 / portTICK_RATE_MS )\r
163 \r
164 /* The period of the peripheral clock in nano seconds.  This is used to calculate\r
165 the jitter time in nano seconds as part of the high frequency timer test.  The\r
166 clock driving the timer is divided by 8. */\r
167 #define mainNS_PER_CLOCK                                        ( ( unsigned long ) ( ( 1.0 /  ( ( double ) configPERIPHERAL_CLOCK_HZ ) / 8.0 ) * 1000000000.0 ) )\r
168 \r
169 /*\r
170  * vApplicationMallocFailedHook() will only be called if\r
171  * configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook\r
172  * function that will execute if a call to pvPortMalloc() fails.\r
173  * pvPortMalloc() is called internally by the kernel whenever a task, queue or\r
174  * semaphore is created.  It is also called by various parts of the demo\r
175  * application.  \r
176  */\r
177 void vApplicationMallocFailedHook( void );\r
178 \r
179 /*\r
180  * vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set to 1\r
181  * in FreeRTOSConfig.h.  It is a hook function that is called on each iteration\r
182  * of the idle task.  It is essential that code added to this hook function\r
183  * never attempts to block in any way (for example, call xQueueReceive() with\r
184  * a block time specified).  If the application makes use of the vTaskDelete()\r
185  * API function (as this demo application does) then it is also important that\r
186  * vApplicationIdleHook() is permitted to return to its calling function because\r
187  * it is the responsibility of the idle task to clean up memory allocated by the\r
188  * kernel to any task that has since been deleted.\r
189  */\r
190 void vApplicationIdleHook( void );\r
191 \r
192 /*\r
193  * vApplicationStackOverflowHook() will only be called if \r
194  * configCHECK_FOR_STACK_OVERFLOW is set to a non-zero value.  The handle and \r
195  * name of the offending task should be passed in the function parameters, but\r
196  * it is possible that the stack overflow will have corrupted these - in which\r
197  * case pxCurrentTCB can be inspected to find the same information.\r
198  */\r
199 void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName );\r
200 \r
201 /*\r
202  * The reg test tasks as described at the top of this file.\r
203  */\r
204 static void prvRegTest1Task( void *pvParameters );\r
205 static void prvRegTest2Task( void *pvParameters );\r
206 \r
207 /*\r
208  * The actual implementation of the reg test functionality, which, because of\r
209  * the direct register access, have to be in assembly.\r
210  */\r
211 static void prvRegTest1Implementation( void );\r
212 static void prvRegTest2Implementation( void );\r
213 \r
214 /*\r
215  * The check task as described at the top of this file.\r
216  */\r
217 static void prvCheckTask( void *pvParameters );\r
218 \r
219 /* Variables that are incremented on each iteration of the reg test tasks - \r
220 provided the tasks have not reported any errors.  The check task inspects these\r
221 variables to ensure they are still incrementing as expected.  If a variable \r
222 stops incrementing then it is likely that its associate task has stalled. */\r
223 unsigned long ulRegTest1CycleCount = 0UL, ulRegTest2CycleCount = 0UL;\r
224 \r
225 /*-----------------------------------------------------------*/\r
226 \r
227 void main(void)\r
228 {\r
229 extern void HardwareSetup( void );\r
230 \r
231         /* Renesas provided CPU configuration routine.  The clocks are configured in\r
232         here. */\r
233         HardwareSetup();\r
234         \r
235         /* Turn all LEDs off. */\r
236         vParTestInitialise();\r
237         \r
238         /* Start the reg test tasks which test the context switching mechanism. */\r
239         xTaskCreate( prvRegTest1Task, "RegTst1", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_1_PARAMETER, tskIDLE_PRIORITY, NULL );\r
240         xTaskCreate( prvRegTest2Task, "RegTst2", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_2_PARAMETER, tskIDLE_PRIORITY, NULL );\r
241 \r
242         /* Start the check task as described at the top of this file. */\r
243         xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE * 3, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
244 \r
245         /* Create the standard demo tasks. */\r
246         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
247         vCreateBlockTimeTasks();\r
248     vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
249     vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
250     vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );\r
251     vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
252         vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );\r
253     vStartQueuePeekTasks();\r
254         vStartRecursiveMutexTasks();\r
255         vStartInterruptQueueTasks();\r
256         vStartMathTasks( mainFLOP_TASK_PRIORITY );\r
257 \r
258         /* The suicide tasks must be created last as they need to know how many\r
259         tasks were running prior to their creation in order to ascertain whether\r
260         or not the correct/expected number of tasks are running at any given time. */\r
261     vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
262 \r
263         /* Start the tasks running. */\r
264         vTaskStartScheduler();\r
265         \r
266         /* If all is well we will never reach here as the scheduler will now be\r
267         running.  If we do reach here then it is likely that there was insufficient\r
268         heap available for the idle task to be created. */\r
269         for( ;; );\r
270 }\r
271 /*-----------------------------------------------------------*/\r
272 \r
273 static void prvCheckTask( void *pvParameters )\r
274 {\r
275 static volatile unsigned long ulLastRegTest1CycleCount = 0UL, ulLastRegTest2CycleCount = 0UL;\r
276 portTickType xNextWakeTime, xCycleFrequency = mainNO_ERROR_CYCLE_TIME;\r
277 extern void vSetupHighFrequencyTimer( void );\r
278 extern volatile unsigned short usMaxJitter;\r
279 volatile unsigned long ulActualJitter = 0;\r
280 \r
281         /* If this is being executed then the kernel has been started.  Start the high\r
282         frequency timer test as described at the top of this file.  This is only \r
283         included in the optimised build configuration - otherwise it takes up too much\r
284         CPU time. */\r
285         #ifdef INCLUDE_HIGH_FREQUENCY_TIMER_TEST\r
286                 vSetupHighFrequencyTimer();\r
287         #endif\r
288 \r
289         /* Initialise xNextWakeTime - this only needs to be done once. */\r
290         xNextWakeTime = xTaskGetTickCount();\r
291 \r
292         for( ;; )\r
293         {\r
294                 /* Place this task in the blocked state until it is time to run again. */\r
295                 vTaskDelayUntil( &xNextWakeTime, xCycleFrequency );\r
296 \r
297                 /* Check the standard demo tasks are running without error. */\r
298                 if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
299                 {\r
300                         /* Increase the rate at which this task cycles, which will increase the\r
301                         rate at which mainCHECK_LED flashes to give visual feedback that an error\r
302                         has occurred. */\r
303                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
304                 }\r
305                 else if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
306                 {\r
307                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
308                 }\r
309                 else if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
310                 {\r
311                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
312                 }\r
313                 else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
314                 {\r
315                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
316                 }\r
317             else if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
318             {\r
319                 xCycleFrequency = mainERROR_CYCLE_TIME;\r
320             }\r
321             else if( xArePollingQueuesStillRunning() != pdTRUE )\r
322             {\r
323                 xCycleFrequency = mainERROR_CYCLE_TIME;\r
324             }\r
325             else if( xIsCreateTaskStillRunning() != pdTRUE )\r
326             {\r
327                 xCycleFrequency = mainERROR_CYCLE_TIME;\r
328             }\r
329             else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
330             {\r
331                 xCycleFrequency = mainERROR_CYCLE_TIME;\r
332             }\r
333             else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
334             {\r
335                 xCycleFrequency = mainERROR_CYCLE_TIME;\r
336             }\r
337                 else if( xAreIntQueueTasksStillRunning() != pdPASS )\r
338                 {\r
339                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
340                 }\r
341                 else if( xAreMathsTaskStillRunning() != pdPASS )\r
342                 {\r
343                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
344                 }\r
345 \r
346                 /* Check the reg test tasks are still cycling.  They will stop incrementing\r
347                 their loop counters if they encounter an error. */\r
348                 if( ulRegTest1CycleCount == ulLastRegTest1CycleCount )\r
349                 {\r
350                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
351                 }\r
352 \r
353                 if( ulRegTest2CycleCount == ulLastRegTest2CycleCount )\r
354                 {\r
355                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
356                 }\r
357                 \r
358                 ulLastRegTest1CycleCount = ulRegTest1CycleCount;\r
359                 ulLastRegTest2CycleCount = ulRegTest2CycleCount;\r
360                 \r
361                 /* Toggle the check LED to give an indication of the system status.  If \r
362                 the LED toggles every 5 seconds then everything is ok.  A faster toggle \r
363                 indicates an error. */\r
364                 vParTestToggleLED( mainCHECK_LED );\r
365                 \r
366                 /* Calculate the maximum jitter experienced by the high frequency timer \r
367                 test and print it out.  It is ok to use printf without worrying about \r
368                 mutual exclusion as it is not used anywhere else in this demo. */\r
369                 //sprintf( cTempBuf, "%s [%fns]\n", "Max Jitter = ", ( ( float ) usMaxJitter ) * mainNS_PER_CLOCK );\r
370                 ulActualJitter = ( ( unsigned long ) usMaxJitter ) * mainNS_PER_CLOCK;\r
371         }\r
372 }\r
373 /*-----------------------------------------------------------*/\r
374 \r
375 /* The RX port uses this callback function to configure its tick interrupt.  \r
376 This allows the application to choose the tick interrupt source. */\r
377 void vApplicationSetupTimerInterrupt( void )\r
378 {\r
379         /* Enable compare match timer 0. */\r
380         MSTP( CMT0 ) = 0;\r
381         \r
382         /* Interrupt on compare match. */\r
383         CMT0.CMCR.BIT.CMIE = 1;\r
384         \r
385         /* Set the compare match value. */\r
386         CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );\r
387         \r
388         /* Divide the PCLK by 8. */\r
389         CMT0.CMCR.BIT.CKS = 0;\r
390         \r
391         /* Enable the interrupt... */\r
392         _IEN( _CMT0_CMI0 ) = 1;\r
393         \r
394         /* ...and set its priority to the application defined kernel priority. */\r
395         _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;\r
396         \r
397         /* Start the timer. */\r
398         CMT.CMSTR0.BIT.STR0 = 1;\r
399 }\r
400 /*-----------------------------------------------------------*/\r
401 \r
402 /* This function is explained by the comments above its prototype at the top\r
403 of this file. */\r
404 void vApplicationMallocFailedHook( void )\r
405 {\r
406         for( ;; );\r
407 }\r
408 /*-----------------------------------------------------------*/\r
409 \r
410 /* This function is explained by the comments above its prototype at the top\r
411 of this file. */\r
412 void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )\r
413 {\r
414         for( ;; );\r
415 }\r
416 /*-----------------------------------------------------------*/\r
417 \r
418 /* This function is explained by the comments above its prototype at the top\r
419 of this file. */\r
420 void vApplicationIdleHook( void )\r
421 {\r
422 }\r
423 /*-----------------------------------------------------------*/\r
424 \r
425 /* This function is explained in the comments at the top of this file. */\r
426 static void prvRegTest1Task( void *pvParameters )\r
427 {\r
428         if( ( ( unsigned long ) pvParameters ) != mainREG_TEST_1_PARAMETER )\r
429         {\r
430                 /* The parameter did not contain the expected value. */\r
431                 for( ;; )\r
432                 {\r
433                         /* Stop the tick interrupt so its obvious something has gone wrong. */\r
434                         taskDISABLE_INTERRUPTS();\r
435                 }\r
436         }\r
437         \r
438         /* This is an inline asm function that never returns. */\r
439         prvRegTest1Implementation();            \r
440 }\r
441 /*-----------------------------------------------------------*/\r
442 \r
443 /* This function is explained in the comments at the top of this file. */\r
444 static void prvRegTest2Task( void *pvParameters )\r
445 {\r
446         if( ( ( unsigned long ) pvParameters ) != mainREG_TEST_2_PARAMETER )\r
447         {\r
448                 /* The parameter did not contain the expected value. */\r
449                 for( ;; )\r
450                 {\r
451                         /* Stop the tick interrupt so its obvious something has gone wrong. */\r
452                         taskDISABLE_INTERRUPTS();\r
453                 }\r
454         }\r
455         \r
456         /* This is an inline asm function that never returns. */\r
457         prvRegTest2Implementation();            \r
458 }\r
459 /*-----------------------------------------------------------*/\r
460 \r
461 /* This function is explained in the comments at the top of this file. */\r
462 #pragma inline_asm prvRegTest1Implementation\r
463 static void prvRegTest1Implementation( void )\r
464 {\r
465         ; Put a known value in each register.\r
466         MOV.L   #1, R1\r
467         MOV.L   #2, R2\r
468         MOV.L   #3, R3\r
469         MOV.L   #4, R4\r
470         MOV.L   #5, R5\r
471         MOV.L   #6, R6\r
472         MOV.L   #7, R7\r
473         MOV.L   #8, R8\r
474         MOV.L   #9, R9\r
475         MOV.L   #10, R10\r
476         MOV.L   #11, R11\r
477         MOV.L   #12, R12\r
478         MOV.L   #13, R13\r
479         MOV.L   #14, R14\r
480         MOV.L   #15, R15\r
481         \r
482         ; Loop, checking each itteration that each register still contains the\r
483         ; expected value.\r
484 TestLoop1:      \r
485 \r
486         ; Push the registers that are going to get clobbered.\r
487         PUSHM   R14-R15\r
488         \r
489         ; Increment the loop counter to show this task is still getting CPU time.\r
490         MOV.L   #_ulRegTest1CycleCount, R14\r
491         MOV.L   [ R14 ], R15\r
492         ADD             #1, R15\r
493         MOV.L   R15, [ R14 ]\r
494         \r
495         ; Yield to extend the text coverage.  Set the bit in the ITU SWINTR register.\r
496         MOV.L   #1, R14\r
497         MOV.L   #0872E0H, R15\r
498         MOV.B   R14, [R15]\r
499         NOP\r
500         NOP\r
501         \r
502         ; Restore the clobbered registers.\r
503         POPM    R14-R15\r
504         \r
505         ; Now compare each register to ensure it still contains the value that was\r
506         ; set before this loop was entered.\r
507         CMP             #1, R1\r
508         BNE             RegTest2Error\r
509         CMP             #2, R2\r
510         BNE             RegTest2Error\r
511         CMP             #3, R3\r
512         BNE             RegTest2Error\r
513         CMP             #4, R4\r
514         BNE             RegTest2Error\r
515         CMP             #5, R5\r
516         BNE             RegTest2Error\r
517         CMP             #6, R6\r
518         BNE             RegTest2Error\r
519         CMP             #7, R7\r
520         BNE             RegTest2Error\r
521         CMP             #8, R8\r
522         BNE             RegTest2Error\r
523         CMP             #9, R9\r
524         BNE             RegTest2Error\r
525         CMP             #10, R10\r
526         BNE             RegTest2Error\r
527         CMP             #11, R11\r
528         BNE             RegTest2Error\r
529         CMP             #12, R12\r
530         BNE             RegTest2Error\r
531         CMP             #13, R13\r
532         BNE             RegTest2Error\r
533         CMP             #14, R14\r
534         BNE             RegTest2Error\r
535         CMP             #15, R15\r
536         BNE             RegTest2Error\r
537 \r
538         ; All comparisons passed, start a new itteratio of this loop.\r
539         BRA             TestLoop1\r
540         \r
541 RegTest1Error:\r
542         ; A compare failed, something has gone wrong.  Stop the tick and any other \r
543         ; interrupts to make it obvious that things have halted.\r
544         CLRPSW  I\r
545         BRA RegTest1Error\r
546 }\r
547 /*-----------------------------------------------------------*/\r
548 \r
549 /* This function is explained in the comments at the top of this file. */\r
550 #pragma inline_asm prvRegTest2Implementation\r
551 static void prvRegTest2Implementation( void )\r
552 {\r
553         ; Put a known value in each register.\r
554         MOV.L   #10, R1\r
555         MOV.L   #20, R2\r
556         MOV.L   #30, R3\r
557         MOV.L   #40, R4\r
558         MOV.L   #50, R5\r
559         MOV.L   #60, R6\r
560         MOV.L   #70, R7\r
561         MOV.L   #80, R8\r
562         MOV.L   #90, R9\r
563         MOV.L   #100, R10\r
564         MOV.L   #110, R11\r
565         MOV.L   #120, R12\r
566         MOV.L   #130, R13\r
567         MOV.L   #140, R14\r
568         MOV.L   #150, R15\r
569         \r
570         ; Loop, checking on each itteration that each register still contains the\r
571         ; expected value.\r
572 TestLoop2:      \r
573         \r
574         ; Push the registers that are going to get clobbered.\r
575         PUSHM   R14-R15\r
576         \r
577         ; Increment the loop counter to show this task is still getting CPU time.\r
578         MOV.L   #_ulRegTest2CycleCount, R14\r
579         MOV.L   [ R14 ], R15\r
580         ADD             #1, R15\r
581         MOV.L   R15, [ R14 ]\r
582         \r
583         ; Restore the clobbered registers.\r
584         POPM    R14-R15 \r
585         \r
586         CMP             #10, R1\r
587         BNE             RegTest2Error\r
588         CMP             #20, R2\r
589         BNE             RegTest2Error\r
590         CMP             #30, R3\r
591         BNE             RegTest2Error\r
592         CMP             #40, R4\r
593         BNE             RegTest2Error\r
594         CMP             #50, R5\r
595         BNE             RegTest2Error\r
596         CMP             #60, R6\r
597         BNE             RegTest2Error\r
598         CMP             #70, R7\r
599         BNE             RegTest2Error\r
600         CMP             #80, R8\r
601         BNE             RegTest2Error\r
602         CMP             #90, R9\r
603         BNE             RegTest2Error\r
604         CMP             #100, R10\r
605         BNE             RegTest2Error\r
606         CMP             #110, R11\r
607         BNE             RegTest2Error\r
608         CMP             #120, R12\r
609         BNE             RegTest2Error\r
610         CMP             #130, R13\r
611         BNE             RegTest2Error\r
612         CMP             #140, R14\r
613         BNE             RegTest2Error\r
614         CMP             #150, R15\r
615         BNE             RegTest2Error\r
616 \r
617         ; All comparisons passed, start a new itteratio of this loop.\r
618         BRA             TestLoop2\r
619         \r
620 RegTest2Error:\r
621         ; A compare failed, something went wrong.  Stop the tick and any other \r
622         ; interrupts to make it obvious that things have halted.\r
623         CLRPSW  I\r
624         BRA RegTest2Error\r
625 }\r
626 \r
627 \r
628 \r
629 \r
630 \r