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