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