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