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