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