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