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