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