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