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