]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RX600_RX62N-RDK_Renesas/RTOSDemo/main-full.c
4dc4aaeeeccd06dd305e2f1bebb71b2b1298be1f
[freertos] / FreeRTOS / Demo / RX600_RX62N-RDK_Renesas / RTOSDemo / main-full.c
1 /*\r
2  * FreeRTOS Kernel V10.0.0\r
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software. If you wish to use our Amazon\r
14  * FreeRTOS name, please do so in a fair use way that does not cause confusion.\r
15  *\r
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22  *\r
23  * http://www.FreeRTOS.org\r
24  * http://aws.amazon.com/freertos\r
25  *\r
26  * 1 tab == 4 spaces!\r
27  */\r
28 \r
29 /* ****************************************************************************\r
30  * This project includes a lot of tasks and tests and is therefore complex.\r
31  * If you would prefer a much simpler project to get started with then select\r
32  * the 'Blinky' build configuration within the HEW IDE.\r
33  * ****************************************************************************\r
34  *\r
35  * Creates all the demo application tasks, then starts the scheduler.  The web\r
36  * documentation provides more details of the standard demo application tasks,\r
37  * which provide no particular functionality but do provide a good example of\r
38  * how to use the FreeRTOS API.  The tasks defined in flop.c are included in the\r
39  * set of standard demo tasks to ensure the floating point unit gets some\r
40  * exercise.\r
41  *\r
42  * In addition to the standard demo tasks, the following tasks and tests are\r
43  * defined and/or created within this file:\r
44  *\r
45  * Webserver ("uIP") task - This serves a number of dynamically generated WEB\r
46  * pages to a standard WEB browser.  The IP and MAC addresses are configured by\r
47  * constants defined at the bottom of FreeRTOSConfig.h.  Use either a standard\r
48  * Ethernet cable to connect through a hug, or a cross over (point to point)\r
49  * cable to connect directly.  Ensure the IP address used is compatible with the\r
50  * IP address of the machine running the browser - the easiest way to achieve\r
51  * this is to ensure the first three octets of the IP addresses are the same.\r
52  *\r
53  * "Reg test" tasks - These fill the registers with known values, then check\r
54  * that each register still contains its expected value.  Each task uses\r
55  * different values.  The tasks run with very low priority so get preempted\r
56  * very frequently.  A check variable is incremented on each iteration of the\r
57  * test loop.  A register containing an unexpected value is indicative of an\r
58  * error in the context switching mechanism and will result in a branch to a\r
59  * null loop - which in turn will prevent the check variable from incrementing\r
60  * any further and allow the check task (described below) to determine that an\r
61  * error has occurred.  The nature of the reg test tasks necessitates that they\r
62  * are written in assembly code.\r
63  *\r
64  * "Check" task - This only executes every five seconds but has a high priority\r
65  * to ensure it gets processor time.  Its main function is to check that all the\r
66  * standard demo tasks are still operational.  While no errors have been\r
67  * discovered the check task will toggle LED 5 (marked LED 9 on the silk \r
68  * screen!) every 5 seconds - the toggle rate increasing to 200ms being a visual \r
69  * indication that at least one task has reported unexpected behaviour.\r
70  *\r
71  * "High frequency timer test" - A high frequency periodic interrupt is\r
72  * generated using a timer - the interrupt is assigned a priority above\r
73  * configMAX_SYSCALL_INTERRUPT_PRIORITY so should not be effected by anything\r
74  * the kernel is doing.  The frequency and priority of the interrupt, in\r
75  * combination with other standard tests executed in this demo, should result\r
76  * in interrupts nesting at least 3 and probably 4 deep.  This test is only\r
77  * included in build configurations that have the optimiser switched on.  In\r
78  * optimised builds the count of high frequency ticks is used as the time base\r
79  * for the run time stats.\r
80  *\r
81  * *NOTE 1* If LED5 is toggling every 5 seconds then all the demo application\r
82  * tasks are executing as expected and no errors have been reported in any\r
83  * tasks.  The toggle rate increasing to 200ms indicates that at least one task\r
84  * has reported unexpected behaviour.\r
85  *\r
86  * *NOTE 2* vApplicationSetupTimerInterrupt() is called by the kernel to let\r
87  * the application set up a timer to generate the tick interrupt.  In this\r
88  * example a compare match timer is used for this purpose.\r
89  *\r
90  * *NOTE 3* The CPU must be in Supervisor mode when the scheduler is started.\r
91  * The PowerON_Reset_PC() supplied in resetprg.c with this demo has\r
92  * Change_PSW_PM_to_UserMode() commented out to ensure this is the case.\r
93  *\r
94  * *NOTE 4* The IntQueue common demo tasks test interrupt nesting and make use\r
95  * of all the 8bit timers (as two cascaded 16bit units).\r
96 */\r
97 \r
98 /* Hardware specific includes. */\r
99 #include "iodefine.h"\r
100 \r
101 /* Kernel includes. */\r
102 #include "FreeRTOS.h"\r
103 #include "task.h"\r
104 \r
105 /* Standard demo includes. */\r
106 #include "partest.h"\r
107 #include "flash.h"\r
108 #include "IntQueue.h"\r
109 #include "BlockQ.h"\r
110 #include "death.h"\r
111 #include "integer.h"\r
112 #include "blocktim.h"\r
113 #include "semtest.h"\r
114 #include "PollQ.h"\r
115 #include "GenQTest.h"\r
116 #include "QPeek.h"\r
117 #include "recmutex.h"\r
118 #include "flop.h"\r
119 \r
120 /* Values that are passed into the reg test tasks using the task parameter.  The\r
121 tasks check that the values are passed in correctly. */\r
122 #define mainREG_TEST_1_PARAMETER        ( 0x12121212UL )\r
123 #define mainREG_TEST_2_PARAMETER        ( 0x12345678UL )\r
124 \r
125 /* Priorities at which the tasks are created. */\r
126 #define mainCHECK_TASK_PRIORITY         ( configMAX_PRIORITIES - 1 )\r
127 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 1 )\r
128 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
129 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
130 #define mainCREATOR_TASK_PRIORITY   ( tskIDLE_PRIORITY + 3 )\r
131 #define mainFLASH_TASK_PRIORITY         ( tskIDLE_PRIORITY + 1 )\r
132 #define mainuIP_TASK_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
133 #define mainINTEGER_TASK_PRIORITY   ( tskIDLE_PRIORITY )\r
134 #define mainGEN_QUEUE_TASK_PRIORITY     ( tskIDLE_PRIORITY )\r
135 #define mainFLOP_TASK_PRIORITY          ( tskIDLE_PRIORITY )\r
136 \r
137 /* The WEB server uses string handling functions, which in turn use a bit more\r
138 stack than most of the other tasks. */\r
139 #define mainuIP_STACK_SIZE                      ( configMINIMAL_STACK_SIZE * 3 )\r
140 \r
141 /* The LED toggled by the check task. */\r
142 #define mainCHECK_LED                           ( 5 ) /* Marked LED 9 on the RDK silk screen. */\r
143 \r
144 /* The rate at which mainCHECK_LED will toggle when all the tasks are running\r
145 without error.  Controlled by the check task as described at the top of this\r
146 file. */\r
147 #define mainNO_ERROR_CYCLE_TIME         ( 5000 / portTICK_PERIOD_MS )\r
148 \r
149 /* The rate at which mainCHECK_LED will toggle when an error has been reported\r
150 by at least one task.  Controlled by the check task as described at the top of\r
151 this file. */\r
152 #define mainERROR_CYCLE_TIME            ( 200 / portTICK_PERIOD_MS )\r
153 \r
154 /*\r
155  * vApplicationMallocFailedHook() will only be called if\r
156  * configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook\r
157  * function that will execute if a call to pvPortMalloc() fails.\r
158  * pvPortMalloc() is called internally by the kernel whenever a task, queue or\r
159  * semaphore is created.  It is also called by various parts of the demo\r
160  * application.\r
161  */\r
162 void vApplicationMallocFailedHook( void );\r
163 \r
164 /*\r
165  * vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set to 1\r
166  * in FreeRTOSConfig.h.  It is a hook function that is called on each iteration\r
167  * of the idle task.  It is essential that code added to this hook function\r
168  * never attempts to block in any way (for example, call xQueueReceive() with\r
169  * a block time specified).  If the application makes use of the vTaskDelete()\r
170  * API function (as this demo application does) then it is also important that\r
171  * vApplicationIdleHook() is permitted to return to its calling function because\r
172  * it is the responsibility of the idle task to clean up memory allocated by the\r
173  * kernel to any task that has since been deleted.\r
174  */\r
175 void vApplicationIdleHook( void );\r
176 \r
177 /*\r
178  * vApplicationStackOverflowHook() will only be called if\r
179  * configCHECK_FOR_STACK_OVERFLOW is set to a non-zero value.  The handle and\r
180  * name of the offending task should be passed in the function parameters, but\r
181  * it is possible that the stack overflow will have corrupted these - in which\r
182  * case pxCurrentTCB can be inspected to find the same information.\r
183  */\r
184 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
185 \r
186 /*\r
187  * The reg test tasks as described at the top of this file.\r
188  */\r
189 static void prvRegTest1Task( void *pvParameters );\r
190 static void prvRegTest2Task( void *pvParameters );\r
191 \r
192 /*\r
193  * The actual implementation of the reg test functionality, which, because of\r
194  * the direct register access, have to be in assembly.\r
195  */\r
196 static void prvRegTest1Implementation( void );\r
197 static void prvRegTest2Implementation( void );\r
198 \r
199 /*\r
200  * The check task as described at the top of this file.\r
201  */\r
202 static void prvCheckTask( void *pvParameters );\r
203 \r
204 /*\r
205  * Contains the implementation of the WEB server.\r
206  */\r
207 extern void vuIP_Task( void *pvParameters );\r
208 \r
209 /*-----------------------------------------------------------*/\r
210 \r
211 /* Variables that are incremented on each iteration of the reg test tasks -\r
212 provided the tasks have not reported any errors.  The check task inspects these\r
213 variables to ensure they are still incrementing as expected.  If a variable\r
214 stops incrementing then it is likely that its associate task has stalled. */\r
215 unsigned long ulRegTest1CycleCount = 0UL, ulRegTest2CycleCount = 0UL;\r
216 \r
217 /* The status message that is displayed at the bottom of the "task stats" web\r
218 page, which is served by the uIP task.  This will report any errors picked up\r
219 by the reg test task. */\r
220 const char *pcStatusMessage = "All tasks executing without error.";\r
221 \r
222 /*-----------------------------------------------------------*/\r
223 \r
224 void main(void)\r
225 {\r
226 extern void HardwareSetup( void );\r
227 \r
228         /* Renesas provided CPU configuration routine.  The clocks are configured in\r
229         here. */\r
230         HardwareSetup();\r
231 \r
232         /* Turn all LEDs off. */\r
233         vParTestInitialise();\r
234 \r
235         /* Start the reg test tasks which test the context switching mechanism. */\r
236         xTaskCreate( prvRegTest1Task, "RegTst1", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_1_PARAMETER, tskIDLE_PRIORITY, NULL );\r
237         xTaskCreate( prvRegTest2Task, "RegTst2", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_2_PARAMETER, tskIDLE_PRIORITY, NULL );\r
238 \r
239         /* The web server task. */\r
240         xTaskCreate( vuIP_Task, "uIP", mainuIP_STACK_SIZE, NULL, mainuIP_TASK_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 TickType_t xNextWakeTime, xCycleFrequency = mainNO_ERROR_CYCLE_TIME;\r
277 extern void vSetupHighFrequencyTimer( void );\r
278 \r
279         /* If this is being executed then the kernel has been started.  Start the high\r
280         frequency timer test as described at the top of this file.  This is only\r
281         included in the optimised build configuration - otherwise it takes up too much\r
282         CPU time and can disrupt other tests. */\r
283         #ifdef INCLUDE_HIGH_FREQUENCY_TIMER_TEST\r
284                 vSetupHighFrequencyTimer();\r
285         #endif\r
286 \r
287         /* Initialise xNextWakeTime - this only needs to be done once. */\r
288         xNextWakeTime = xTaskGetTickCount();\r
289 \r
290         for( ;; )\r
291         {\r
292                 /* Place this task in the blocked state until it is time to run again. */\r
293                 vTaskDelayUntil( &xNextWakeTime, xCycleFrequency );\r
294 \r
295                 /* Check the standard demo tasks are running without error. */\r
296                 if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
297                 {\r
298                         /* Increase the rate at which this task cycles, which will increase the\r
299                         rate at which mainCHECK_LED flashes to give visual feedback that an error\r
300                         has occurred. */\r
301                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
302                         pcStatusMessage = "Error: GenQueue";\r
303                 }\r
304                 else if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
305                 {\r
306                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
307                         pcStatusMessage = "Error: QueuePeek";\r
308                 }\r
309                 else if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
310                 {\r
311                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
312                         pcStatusMessage = "Error: BlockQueue";\r
313                 }\r
314                 else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
315                 {\r
316                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
317                         pcStatusMessage = "Error: BlockTime";\r
318                 }\r
319                 else if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
320                 {\r
321                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
322                         pcStatusMessage = "Error: SemTest";\r
323                 }\r
324                 else if( xArePollingQueuesStillRunning() != pdTRUE )\r
325                 {\r
326                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
327                         pcStatusMessage = "Error: PollQueue";\r
328                 }\r
329                 else if( xIsCreateTaskStillRunning() != pdTRUE )\r
330                 {\r
331                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
332                         pcStatusMessage = "Error: Death";\r
333                 }\r
334                 else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
335                 {\r
336                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
337                         pcStatusMessage = "Error: IntMath";\r
338                 }\r
339                 else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
340                 {\r
341                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
342                         pcStatusMessage = "Error: RecMutex";\r
343                 }\r
344                 else if( xAreIntQueueTasksStillRunning() != pdPASS )\r
345                 {\r
346                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
347                         pcStatusMessage = "Error: IntQueue";\r
348                 }\r
349                 else if( xAreMathsTaskStillRunning() != pdPASS )\r
350                 {\r
351                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
352                         pcStatusMessage = "Error: Flop";\r
353                 }\r
354 \r
355                 /* Check the reg test tasks are still cycling.  They will stop incrementing\r
356                 their loop counters if they encounter an error. */\r
357                 if( ulRegTest1CycleCount == ulLastRegTest1CycleCount )\r
358                 {\r
359                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
360                         pcStatusMessage = "Error: RegTest1";\r
361                 }\r
362 \r
363                 if( ulRegTest2CycleCount == ulLastRegTest2CycleCount )\r
364                 {\r
365                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
366                         pcStatusMessage = "Error: RegTest2";\r
367                 }\r
368 \r
369                 ulLastRegTest1CycleCount = ulRegTest1CycleCount;\r
370                 ulLastRegTest2CycleCount = ulRegTest2CycleCount;\r
371 \r
372                 /* Toggle the check LED to give an indication of the system status.  If\r
373                 the LED toggles every 5 seconds then everything is ok.  A faster toggle\r
374                 indicates an error. */\r
375                 vParTestToggleLED( mainCHECK_LED );\r
376         }\r
377 }\r
378 /*-----------------------------------------------------------*/\r
379 \r
380 /* The RX port uses this callback function to configure its tick interrupt.\r
381 This allows the application to choose the tick interrupt source. */\r
382 void vApplicationSetupTimerInterrupt( void )\r
383 {\r
384         /* Enable compare match timer 0. */\r
385         MSTP( CMT0 ) = 0;\r
386 \r
387         /* Interrupt on compare match. */\r
388         CMT0.CMCR.BIT.CMIE = 1;\r
389 \r
390         /* Set the compare match value. */\r
391         CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );\r
392 \r
393         /* Divide the PCLK by 8. */\r
394         CMT0.CMCR.BIT.CKS = 0;\r
395 \r
396         /* Enable the interrupt... */\r
397         _IEN( _CMT0_CMI0 ) = 1;\r
398 \r
399         /* ...and set its priority to the application defined kernel priority. */\r
400         _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;\r
401 \r
402         /* Start the timer. */\r
403         CMT.CMSTR0.BIT.STR0 = 1;\r
404 }\r
405 /*-----------------------------------------------------------*/\r
406 \r
407 /* This function is explained by the comments above its prototype at the top\r
408 of this file. */\r
409 void vApplicationMallocFailedHook( void )\r
410 {\r
411         for( ;; );\r
412 }\r
413 /*-----------------------------------------------------------*/\r
414 \r
415 /* This function is explained by the comments above its prototype at the top\r
416 of this file. */\r
417 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
418 {\r
419         for( ;; );\r
420 }\r
421 /*-----------------------------------------------------------*/\r
422 \r
423 /* This function is explained by the comments above its prototype at the top\r
424 of this file. */\r
425 void vApplicationIdleHook( void )\r
426 {\r
427 }\r
428 /*-----------------------------------------------------------*/\r
429 \r
430 /* This function is explained in the comments at the top of this file. */\r
431 static void prvRegTest1Task( void *pvParameters )\r
432 {\r
433         if( ( ( unsigned long ) pvParameters ) != mainREG_TEST_1_PARAMETER )\r
434         {\r
435                 /* The parameter did not contain the expected value. */\r
436                 for( ;; )\r
437                 {\r
438                         /* Stop the tick interrupt so its obvious something has gone wrong. */\r
439                         taskDISABLE_INTERRUPTS();\r
440                 }\r
441         }\r
442 \r
443         /* This is an inline asm function that never returns. */\r
444         prvRegTest1Implementation();\r
445 }\r
446 /*-----------------------------------------------------------*/\r
447 \r
448 /* This function is explained in the comments at the top of this file. */\r
449 static void prvRegTest2Task( void *pvParameters )\r
450 {\r
451         if( ( ( unsigned long ) pvParameters ) != mainREG_TEST_2_PARAMETER )\r
452         {\r
453                 /* The parameter did not contain the expected value. */\r
454                 for( ;; )\r
455                 {\r
456                         /* Stop the tick interrupt so its obvious something has gone wrong. */\r
457                         taskDISABLE_INTERRUPTS();\r
458                 }\r
459         }\r
460 \r
461         /* This is an inline asm function that never returns. */\r
462         prvRegTest2Implementation();\r
463 }\r
464 /*-----------------------------------------------------------*/\r
465 \r
466 /* This function is explained in the comments at the top of this file. */\r
467 #pragma inline_asm prvRegTest1Implementation\r
468 static void prvRegTest1Implementation( void )\r
469 {\r
470         ; Put a known value in each register.\r
471         MOV.L   #1, R1\r
472         MOV.L   #2, R2\r
473         MOV.L   #3, R3\r
474         MOV.L   #4, R4\r
475         MOV.L   #5, R5\r
476         MOV.L   #6, R6\r
477         MOV.L   #7, R7\r
478         MOV.L   #8, R8\r
479         MOV.L   #9, R9\r
480         MOV.L   #10, R10\r
481         MOV.L   #11, R11\r
482         MOV.L   #12, R12\r
483         MOV.L   #13, R13\r
484         MOV.L   #14, R14\r
485         MOV.L   #15, R15\r
486 \r
487         ; Loop, checking each iteration that each register still contains the\r
488         ; expected value.\r
489 TestLoop1:\r
490 \r
491         ; Push the registers that are going to get clobbered.\r
492         PUSHM   R14-R15\r
493 \r
494         ; Increment the loop counter to show this task is still getting CPU time.\r
495         MOV.L   #_ulRegTest1CycleCount, R14\r
496         MOV.L   [ R14 ], R15\r
497         ADD             #1, R15\r
498         MOV.L   R15, [ R14 ]\r
499 \r
500         ; Yield to extend the text coverage.  Set the bit in the ITU SWINTR register.\r
501         MOV.L   #1, R14\r
502         MOV.L   #0872E0H, R15\r
503         MOV.B   R14, [R15]\r
504         NOP\r
505         NOP\r
506 \r
507         ; Restore the clobbered registers.\r
508         POPM    R14-R15\r
509 \r
510         ; Now compare each register to ensure it still contains the value that was\r
511         ; set before this loop was entered.\r
512         CMP             #1, R1\r
513         BNE             RegTest1Error\r
514         CMP             #2, R2\r
515         BNE             RegTest1Error\r
516         CMP             #3, R3\r
517         BNE             RegTest1Error\r
518         CMP             #4, R4\r
519         BNE             RegTest1Error\r
520         CMP             #5, R5\r
521         BNE             RegTest1Error\r
522         CMP             #6, R6\r
523         BNE             RegTest1Error\r
524         CMP             #7, R7\r
525         BNE             RegTest1Error\r
526         CMP             #8, R8\r
527         BNE             RegTest1Error\r
528         CMP             #9, R9\r
529         BNE             RegTest1Error\r
530         CMP             #10, R10\r
531         BNE             RegTest1Error\r
532         CMP             #11, R11\r
533         BNE             RegTest1Error\r
534         CMP             #12, R12\r
535         BNE             RegTest1Error\r
536         CMP             #13, R13\r
537         BNE             RegTest1Error\r
538         CMP             #14, R14\r
539         BNE             RegTest1Error\r
540         CMP             #15, R15\r
541         BNE             RegTest1Error\r
542 \r
543         ; All comparisons passed, start a new itteratio of this loop.\r
544         BRA             TestLoop1\r
545 \r
546 RegTest1Error:\r
547         ; A compare failed, just loop here so the loop counter stops incrementing\r
548         ; causing the check task to indicate the error.\r
549         BRA RegTest1Error\r
550 }\r
551 /*-----------------------------------------------------------*/\r
552 \r
553 /* This function is explained in the comments at the top of this file. */\r
554 #pragma inline_asm prvRegTest2Implementation\r
555 static void prvRegTest2Implementation( void )\r
556 {\r
557         ; Put a known value in each register.\r
558         MOV.L   #10, R1\r
559         MOV.L   #20, R2\r
560         MOV.L   #30, R3\r
561         MOV.L   #40, R4\r
562         MOV.L   #50, R5\r
563         MOV.L   #60, R6\r
564         MOV.L   #70, R7\r
565         MOV.L   #80, R8\r
566         MOV.L   #90, R9\r
567         MOV.L   #100, R10\r
568         MOV.L   #110, R11\r
569         MOV.L   #120, R12\r
570         MOV.L   #130, R13\r
571         MOV.L   #140, R14\r
572         MOV.L   #150, R15\r
573 \r
574         ; Loop, checking on each iteration that each register still contains the\r
575         ; expected value.\r
576 TestLoop2:\r
577 \r
578         ; Push the registers that are going to get clobbered.\r
579         PUSHM   R14-R15\r
580 \r
581         ; Increment the loop counter to show this task is still getting CPU time.\r
582         MOV.L   #_ulRegTest2CycleCount, R14\r
583         MOV.L   [ R14 ], R15\r
584         ADD             #1, R15\r
585         MOV.L   R15, [ R14 ]\r
586 \r
587         ; Restore the clobbered registers.\r
588         POPM    R14-R15\r
589 \r
590         CMP             #10, R1\r
591         BNE             RegTest2Error\r
592         CMP             #20, R2\r
593         BNE             RegTest2Error\r
594         CMP             #30, R3\r
595         BNE             RegTest2Error\r
596         CMP             #40, R4\r
597         BNE             RegTest2Error\r
598         CMP             #50, R5\r
599         BNE             RegTest2Error\r
600         CMP             #60, R6\r
601         BNE             RegTest2Error\r
602         CMP             #70, R7\r
603         BNE             RegTest2Error\r
604         CMP             #80, R8\r
605         BNE             RegTest2Error\r
606         CMP             #90, R9\r
607         BNE             RegTest2Error\r
608         CMP             #100, R10\r
609         BNE             RegTest2Error\r
610         CMP             #110, R11\r
611         BNE             RegTest2Error\r
612         CMP             #120, R12\r
613         BNE             RegTest2Error\r
614         CMP             #130, R13\r
615         BNE             RegTest2Error\r
616         CMP             #140, R14\r
617         BNE             RegTest2Error\r
618         CMP             #150, R15\r
619         BNE             RegTest2Error\r
620 \r
621         ; All comparisons passed, start a new itteratio of this loop.\r
622         BRA             TestLoop2\r
623 \r
624 RegTest2Error:\r
625         ; A compare failed, just loop here so the loop counter stops incrementing\r
626         ; - causing the check task to indicate the error.\r
627         BRA RegTest2Error\r
628 }\r
629 /*-----------------------------------------------------------*/\r
630 \r
631 char *pcGetTaskStatusMessage( void )\r
632 {\r
633         /* Not bothered about a critical section here although technically because of\r
634         the task priorities the pointer could change it will be atomic if not near\r
635         atomic and its not critical. */\r
636         return ( char * ) pcStatusMessage;\r
637 }\r
638 /*-----------------------------------------------------------*/\r
639 \r
640 \r