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