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