]> git.sur5r.net Git - freertos/blob - Demo/RX600_RX62N-RDK_Renesas/RTOSDemo/main-full.c
All relating to the RX600 RDK demo - which is still a work in progress:
[freertos] / Demo / RX600_RX62N-RDK_Renesas / RTOSDemo / main-full.c
1 /*\r
2     FreeRTOS V6.0.5 - Copyright (C) 2010 Real Time Engineers Ltd.\r
3 \r
4     ***************************************************************************\r
5     *                                                                         *\r
6     * If you are:                                                             *\r
7     *                                                                         *\r
8     *    + New to FreeRTOS,                                                   *\r
9     *    + Wanting to learn FreeRTOS or multitasking in general quickly       *\r
10     *    + Looking for basic training,                                        *\r
11     *    + Wanting to improve your FreeRTOS skills and productivity           *\r
12     *                                                                         *\r
13     * then take a look at the FreeRTOS eBook                                  *\r
14     *                                                                         *\r
15     *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *\r
16     *                  http://www.FreeRTOS.org/Documentation                  *\r
17     *                                                                         *\r
18     * A pdf reference manual is also available.  Both are usually delivered   *\r
19     * to your inbox within 20 minutes to two hours when purchased between 8am *\r
20     * and 8pm GMT (although please allow up to 24 hours in case of            *\r
21     * exceptional circumstances).  Thank you for your support!                *\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 exception to the GPL is included to allow you to distribute\r
31     a combined work that includes FreeRTOS without being obliged to provide the\r
32     source code for proprietary components outside of the FreeRTOS kernel.\r
33     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT\r
34     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
35     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  * Creates all the demo application tasks, then starts the scheduler.  The web\r
60  * documentation provides more details of the standard demo application tasks,\r
61  * which provide no particular functionality but do provide a good example of\r
62  * how to use the FreeRTOS API.  The tasks defined in flop.c are included in the\r
63  * set of standard demo tasks to ensure the floating point unit gets some\r
64  * exercise.\r
65  *\r
66  * In addition to the standard demo tasks, the following tasks and tests are\r
67  * defined and/or created within this file:\r
68  *\r
69  * "Reg test" tasks - These fill the registers with known values, then check\r
70  * that each register still contains its expected value.  Each task uses\r
71  * different values.  The tasks run with very low priority so get preempted\r
72  * very frequently.  A check variable is incremented on each iteration of the\r
73  * test loop.  A register containing an unexpected value is indicative of an\r
74  * error in the context switching mechanism and will result in a branch to a\r
75  * null loop - which in turn will prevent the check variable from incrementing\r
76  * any further and allow the check task (described below) to determine that an\r
77  * error has occurred.  The nature of the reg test tasks necessitates that they\r
78  * are written in assembly code.\r
79  *\r
80  * "Check" task - This only executes every five seconds but has a high priority\r
81  * to ensure it gets processor time.  Its main function is to check that all the\r
82  * standard demo tasks are still operational.  While no errors have been\r
83  * discovered the check task will toggle LED 5 every 5 seconds - the toggle\r
84  * rate increasing to 200ms being a visual indication that at least one task has\r
85  * reported unexpected behaviour.\r
86  *\r
87  * "High frequency timer test" - A high frequency periodic interrupt is\r
88  * generated using a timer - the interrupt is assigned a priority above\r
89  * configMAX_SYSCALL_INTERRUPT_PRIORITY so should not be effected by anything\r
90  * the kernel is doing.  The interrupt service routine measures the number of\r
91  * counts a separate timer performs between each interrupt to determine the\r
92  * jitter in the interrupt timing.\r
93  *\r
94  * *NOTE 1* If LED5 is toggling every 5 seconds then all the demo application\r
95  * tasks are executing as expected and no errors have been reported in any\r
96  * tasks.  The toggle rate increasing to 200ms indicates that at least one task\r
97  * has reported unexpected behaviour.\r
98  *\r
99  * *NOTE 2* vApplicationSetupTimerInterrupt() is called by the kernel to let\r
100  * the application set up a timer to generate the tick interrupt.  In this\r
101  * example a compare match timer is used for this purpose.\r
102  *\r
103  * *NOTE 3* The CPU must be in Supervisor mode when the scheduler is started.\r
104  * The PowerON_Reset_PC() supplied in resetprg.c with this demo has\r
105  * Change_PSW_PM_to_UserMode() commented out to ensure this is the case.\r
106  *\r
107  * *NOTE 4* The IntQueue common demo tasks test interrupt nesting and make use\r
108  * of all the 8bit timers (as two cascaded 16bit units).\r
109 */\r
110 \r
111 /* Hardware specific includes. */\r
112 #include "iodefine.h"\r
113 \r
114 /* Kernel includes. */\r
115 #include "FreeRTOS.h"\r
116 #include "task.h"\r
117 \r
118 /* Standard demo includes. */\r
119 #include "partest.h"\r
120 #include "flash.h"\r
121 #include "IntQueue.h"\r
122 #include "BlockQ.h"\r
123 #include "death.h"\r
124 #include "integer.h"\r
125 #include "blocktim.h"\r
126 #include "semtest.h"\r
127 #include "PollQ.h"\r
128 #include "GenQTest.h"\r
129 #include "QPeek.h"\r
130 #include "recmutex.h"\r
131 #include "flop.h"\r
132 \r
133 /* Values that are passed into the reg test tasks using the task parameter.  The\r
134 tasks check that the values are passed in correctly. */\r
135 #define mainREG_TEST_1_PARAMETER        ( 0x12121212UL )\r
136 #define mainREG_TEST_2_PARAMETER        ( 0x12345678UL )\r
137 \r
138 /* Priorities at which the tasks are created. */\r
139 #define mainCHECK_TASK_PRIORITY         ( configMAX_PRIORITIES - 1 )\r
140 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 1 )\r
141 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
142 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
143 #define mainCREATOR_TASK_PRIORITY   ( tskIDLE_PRIORITY + 3 )\r
144 #define mainFLASH_TASK_PRIORITY         ( tskIDLE_PRIORITY + 1 )\r
145 #define mainuIP_TASK_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
146 #define mainINTEGER_TASK_PRIORITY   ( tskIDLE_PRIORITY )\r
147 #define mainGEN_QUEUE_TASK_PRIORITY     ( tskIDLE_PRIORITY )\r
148 #define mainFLOP_TASK_PRIORITY          ( tskIDLE_PRIORITY )\r
149 \r
150 /* The WEB server uses string handling functions, which in turn use a bit more\r
151 stack than most of the other tasks. */\r
152 #define mainuIP_STACK_SIZE                      ( configMINIMAL_STACK_SIZE * 3 )\r
153 \r
154 /* The LED toggled by the check task. */\r
155 #define mainCHECK_LED                           ( 5 )\r
156 \r
157 /* The rate at which mainCHECK_LED will toggle when all the tasks are running\r
158 without error.  Controlled by the check task as described at the top of this\r
159 file. */\r
160 #define mainNO_ERROR_CYCLE_TIME         ( 5000 / portTICK_RATE_MS )\r
161 \r
162 /* The rate at which mainCHECK_LED will toggle when an error has been reported\r
163 by at least one task.  Controlled by the check task as described at the top of\r
164 this file. */\r
165 #define mainERROR_CYCLE_TIME            ( 200 / portTICK_RATE_MS )\r
166 \r
167 /* The period of the peripheral clock in nano seconds.  This is used to calculate\r
168 the jitter time in nano seconds as part of the high frequency timer test.  The\r
169 clock driving the timer is divided by 8. */\r
170 #define mainNS_PER_CLOCK                        ( ( unsigned long ) ( ( 1.0 /  ( ( double ) configPERIPHERAL_CLOCK_HZ ) / 8.0 ) * 1000000000.0 ) )\r
171 \r
172 /*\r
173  * vApplicationMallocFailedHook() will only be called if\r
174  * configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook\r
175  * function that will execute if a call to pvPortMalloc() fails.\r
176  * pvPortMalloc() is called internally by the kernel whenever a task, queue or\r
177  * semaphore is created.  It is also called by various parts of the demo\r
178  * application.\r
179  */\r
180 void vApplicationMallocFailedHook( void );\r
181 \r
182 /*\r
183  * vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set to 1\r
184  * in FreeRTOSConfig.h.  It is a hook function that is called on each iteration\r
185  * of the idle task.  It is essential that code added to this hook function\r
186  * never attempts to block in any way (for example, call xQueueReceive() with\r
187  * a block time specified).  If the application makes use of the vTaskDelete()\r
188  * API function (as this demo application does) then it is also important that\r
189  * vApplicationIdleHook() is permitted to return to its calling function because\r
190  * it is the responsibility of the idle task to clean up memory allocated by the\r
191  * kernel to any task that has since been deleted.\r
192  */\r
193 void vApplicationIdleHook( void );\r
194 \r
195 /*\r
196  * vApplicationStackOverflowHook() will only be called if\r
197  * configCHECK_FOR_STACK_OVERFLOW is set to a non-zero value.  The handle and\r
198  * name of the offending task should be passed in the function parameters, but\r
199  * it is possible that the stack overflow will have corrupted these - in which\r
200  * case pxCurrentTCB can be inspected to find the same information.\r
201  */\r
202 void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName );\r
203 \r
204 /*\r
205  * The reg test tasks as described at the top of this file.\r
206  */\r
207 static void prvRegTest1Task( void *pvParameters );\r
208 static void prvRegTest2Task( void *pvParameters );\r
209 \r
210 /*\r
211  * The actual implementation of the reg test functionality, which, because of\r
212  * the direct register access, have to be in assembly.\r
213  */\r
214 static void prvRegTest1Implementation( void );\r
215 static void prvRegTest2Implementation( void );\r
216 \r
217 /*\r
218  * The check task as described at the top of this file.\r
219  */\r
220 static void prvCheckTask( void *pvParameters );\r
221 \r
222 /*\r
223  * Contains the implementation of the WEB server.\r
224  */\r
225 extern void vuIP_Task( void *pvParameters );\r
226 \r
227 /*-----------------------------------------------------------*/\r
228 \r
229 /* Variables that are incremented on each iteration of the reg test tasks -\r
230 provided the tasks have not reported any errors.  The check task inspects these\r
231 variables to ensure they are still incrementing as expected.  If a variable\r
232 stops incrementing then it is likely that its associate task has stalled. */\r
233 unsigned long ulRegTest1CycleCount = 0UL, ulRegTest2CycleCount = 0UL;\r
234 \r
235 /* The status message that is displayed at the bottom of the "task stats" web\r
236 page, which is served by the uIP task. */\r
237 const char *pcStatusMessage = "All tasks executing without error.";\r
238 \r
239 /*-----------------------------------------------------------*/\r
240 \r
241 void main(void)\r
242 {\r
243 extern void HardwareSetup( void );\r
244 \r
245         /* Renesas provided CPU configuration routine.  The clocks are configured in\r
246         here. */\r
247         HardwareSetup();\r
248 \r
249         /* Turn all LEDs off. */\r
250         vParTestInitialise();\r
251 \r
252         /* Start the reg test tasks which test the context switching mechanism. */\r
253         xTaskCreate( prvRegTest1Task, "RegTst1", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_1_PARAMETER, tskIDLE_PRIORITY, NULL );\r
254         xTaskCreate( prvRegTest2Task, "RegTst2", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_2_PARAMETER, tskIDLE_PRIORITY, NULL );\r
255 \r
256         /* The web server task. */\r
257         xTaskCreate( vuIP_Task, "uIP", mainuIP_STACK_SIZE, NULL, mainuIP_TASK_PRIORITY, NULL );\r
258 \r
259         /* Start the check task as described at the top of this file. */\r
260         xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE * 3, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
261 \r
262         /* Create the standard demo tasks. */\r
263         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
264         vCreateBlockTimeTasks();\r
265         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
266         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
267         vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );\r
268         vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
269         vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );\r
270         vStartQueuePeekTasks();\r
271         vStartRecursiveMutexTasks();\r
272         vStartInterruptQueueTasks();\r
273         vStartMathTasks( mainFLOP_TASK_PRIORITY );\r
274 \r
275         /* The suicide tasks must be created last as they need to know how many\r
276         tasks were running prior to their creation in order to ascertain whether\r
277         or not the correct/expected number of tasks are running at any given time. */\r
278         vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
279 \r
280         /* Start the tasks running. */\r
281         vTaskStartScheduler();\r
282 \r
283         /* If all is well we will never reach here as the scheduler will now be\r
284         running.  If we do reach here then it is likely that there was insufficient\r
285         heap available for the idle task to be created. */\r
286         for( ;; );\r
287 }\r
288 /*-----------------------------------------------------------*/\r
289 \r
290 static void prvCheckTask( void *pvParameters )\r
291 {\r
292 static volatile unsigned long ulLastRegTest1CycleCount = 0UL, ulLastRegTest2CycleCount = 0UL;\r
293 portTickType xNextWakeTime, xCycleFrequency = mainNO_ERROR_CYCLE_TIME;\r
294 extern void vSetupHighFrequencyTimer( void );\r
295 extern volatile unsigned short usMaxJitter;\r
296 volatile unsigned long ulActualJitter = 0;\r
297 \r
298         /* If this is being executed then the kernel has been started.  Start the high\r
299         frequency timer test as described at the top of this file.  This is only\r
300         included in the optimised build configuration - otherwise it takes up too much\r
301         CPU time. */\r
302         #ifdef INCLUDE_HIGH_FREQUENCY_TIMER_TEST\r
303                 vSetupHighFrequencyTimer();\r
304         #endif\r
305 \r
306         /* Initialise xNextWakeTime - this only needs to be done once. */\r
307         xNextWakeTime = xTaskGetTickCount();\r
308 \r
309         for( ;; )\r
310         {\r
311                 /* Place this task in the blocked state until it is time to run again. */\r
312                 vTaskDelayUntil( &xNextWakeTime, xCycleFrequency );\r
313 \r
314                 /* Check the standard demo tasks are running without error. */\r
315                 if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
316                 {\r
317                         /* Increase the rate at which this task cycles, which will increase the\r
318                         rate at which mainCHECK_LED flashes to give visual feedback that an error\r
319                         has occurred. */\r
320                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
321                         pcStatusMessage = "Error: GenQueue";\r
322                 }\r
323                 else if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
324                 {\r
325                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
326                         pcStatusMessage = "Error: QueuePeek";\r
327                 }\r
328                 else if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
329                 {\r
330                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
331                         pcStatusMessage = "Error: BlockQueue";\r
332                 }\r
333                 else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
334                 {\r
335                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
336                         pcStatusMessage = "Error: BlockTime";\r
337                 }\r
338                 else if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
339                 {\r
340                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
341                         pcStatusMessage = "Error: SemTest";\r
342                 }\r
343                 else if( xArePollingQueuesStillRunning() != pdTRUE )\r
344                 {\r
345                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
346                         pcStatusMessage = "Error: PollQueue";\r
347                 }\r
348                 else if( xIsCreateTaskStillRunning() != pdTRUE )\r
349                 {\r
350                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
351                         pcStatusMessage = "Error: Death";\r
352                 }\r
353                 else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
354                 {\r
355                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
356                         pcStatusMessage = "Error: IntMath";\r
357                 }\r
358                 else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
359                 {\r
360                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
361                         pcStatusMessage = "Error: RecMutex";\r
362                 }\r
363                 else if( xAreIntQueueTasksStillRunning() != pdPASS )\r
364                 {\r
365                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
366                         pcStatusMessage = "Error: IntQueue";\r
367                 }\r
368                 else if( xAreMathsTaskStillRunning() != pdPASS )\r
369                 {\r
370                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
371                         pcStatusMessage = "Error: Flop";\r
372                 }\r
373 \r
374                 /* Check the reg test tasks are still cycling.  They will stop incrementing\r
375                 their loop counters if they encounter an error. */\r
376                 if( ulRegTest1CycleCount == ulLastRegTest1CycleCount )\r
377                 {\r
378                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
379                         pcStatusMessage = "Error: RegTest1";\r
380                 }\r
381 \r
382                 if( ulRegTest2CycleCount == ulLastRegTest2CycleCount )\r
383                 {\r
384                         xCycleFrequency = mainERROR_CYCLE_TIME;\r
385                         pcStatusMessage = "Error: RegTest2";\r
386                 }\r
387 \r
388                 ulLastRegTest1CycleCount = ulRegTest1CycleCount;\r
389                 ulLastRegTest2CycleCount = ulRegTest2CycleCount;\r
390 \r
391                 /* Toggle the check LED to give an indication of the system status.  If\r
392                 the LED toggles every 5 seconds then everything is ok.  A faster toggle\r
393                 indicates an error. */\r
394                 vParTestToggleLED( mainCHECK_LED );\r
395 \r
396                 /* Calculate the maximum jitter experienced by the high frequency timer\r
397                 test and print it out.  It is ok to use printf without worrying about\r
398                 mutual exclusion as it is not used anywhere else in this demo. */\r
399                 //sprintf( cTempBuf, "%s [%fns]\n", "Max Jitter = ", ( ( float ) usMaxJitter ) * mainNS_PER_CLOCK );\r
400                 ulActualJitter = ( ( unsigned long ) usMaxJitter ) * mainNS_PER_CLOCK;\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 void vTaskGetRunTimeStats( signed char *pcWriteBuffer )\r
657 {\r
658         /* Not implemented yet, so put here to keep the linker happy. */\r
659 }\r
660 /*-----------------------------------------------------------*/\r
661 \r
662 char *pcGetTaskStatusMessage( void )\r
663 {\r
664         /* Not bothered about a critical section here.  This just returns a string\r
665         that is displaed on the "Task Stats" WEB page served by this demo. */\r
666         return pcStatusMessage;\r
667 }\r
668 /*-----------------------------------------------------------*/\r
669 \r
670 \r