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