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