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