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