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