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