]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RX200_RX210-RSK_Renesas/RTOSDemo/main-full.c
Update version numbers in preparation for V8.2.0 release candidate 1.
[freertos] / FreeRTOS / Demo / RX200_RX210-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.\r
107  *\r
108  * In addition to the standard demo tasks, the following tasks and tests are\r
109  * defined and/or created within this file:\r
110  *\r
111  * "Reg test" tasks - These fill the registers with known values, then \r
112  * repeatedly check that each register still contains its expected value for \r
113  * the lifetime of the tasks.  Each task uses different values.  The tasks run \r
114  * with very low priority so get preempted very frequently.  A check variable \r
115  * is incremented on each iteration of the test loop.  A register containing an \r
116  * unexpected value is indicative of an error in the context switching \r
117  * mechanism and will result in a branch to a null loop - which in turn will \r
118  * prevent the check variable from incrementing any further and allow the check \r
119  * timer (described below) to determine that an error has occurred.  The nature \r
120  * of the reg test tasks necessitates that they are written in assembly code.\r
121  *\r
122  * "Check Timer" and Callback Function - The check timer period is initially \r
123  * set to five seconds.  The check timer callback function checks that all the \r
124  * standard demo tasks are not only still executing, but are executing without \r
125  * reporting any errors.  If the check timer discovers that a task has either \r
126  * stalled, or reported an error, then it changes its own period from the \r
127  * initial five seconds, to just 200ms.  The check timer callback function \r
128  * also toggles LED 3 each time it is called.  This provides a visual \r
129  * indication of the system status:  If the LED toggles every five seconds, \r
130  * then no issues have been discovered.  If the LED toggles every 200ms, then \r
131  * an issue has been discovered with at least one task.\r
132  *\r
133  * "High frequency timer test" - A high frequency periodic interrupt is\r
134  * generated using a timer - the interrupt is assigned a priority above\r
135  * configMAX_SYSCALL_INTERRUPT_PRIORITY, so will not be effected by anything\r
136  * the kernel is doing.  The frequency and priority of the interrupt, in\r
137  * combination with other standard tests executed in this demo, will result\r
138  * in interrupts nesting at least 3 and probably 4 deep.  This test is only\r
139  * included in build configurations that have the optimiser switched on.\r
140  *\r
141  * "Button and LCD test" - This creates two tasks.  The first simply scrolls\r
142  * a message back and forth along the top line of the LCD display.  If no\r
143  * buttons are pushed, the second also scrolls a message back and forth, but\r
144  * along the bottom line of the display.  The automatic scrolling of the second\r
145  * line of the display can be started and stopped using button SW2.  Once \r
146  * stopped it can then be manually nudged left using button SW3, and manually\r
147  * nudged right using button SW1.  Button pushes generate an interrupt, and the\r
148  * interrupt communicates with the task using a queue.\r
149  *\r
150  * *NOTE 1* vApplicationSetupTimerInterrupt() is called by the kernel to let\r
151  * the application set up a timer to generate the tick interrupt.  In this\r
152  * example a compare match timer is used for this purpose.\r
153  *\r
154  * *NOTE 2* The CPU must be in Supervisor mode when the scheduler is started.\r
155  * The PowerON_Reset_PC() supplied in resetprg.c with this demo has\r
156  * Change_PSW_PM_to_UserMode() commented out to ensure this is the case.\r
157  *\r
158  * *NOTE 3* The IntQueue common demo tasks test interrupt nesting and make use\r
159  * of all the 8bit timers (as two cascaded 16bit units).\r
160 */\r
161 \r
162 /* Standard includes. */\r
163 #include <string.h>\r
164 \r
165 /* Hardware specific includes. */\r
166 #include "iodefine.h"\r
167 \r
168 /* Kernel includes. */\r
169 #include "FreeRTOS.h"\r
170 #include "task.h"\r
171 #include "timers.h"\r
172 #include "semphr.h"\r
173 \r
174 /* Standard demo includes. */\r
175 #include "partest.h"\r
176 #include "flash.h"\r
177 #include "IntQueue.h"\r
178 #include "BlockQ.h"\r
179 #include "death.h"\r
180 #include "integer.h"\r
181 #include "blocktim.h"\r
182 #include "semtest.h"\r
183 #include "PollQ.h"\r
184 #include "GenQTest.h"\r
185 #include "QPeek.h"\r
186 #include "recmutex.h"\r
187 \r
188 /* Demo specific tasks. */\r
189 #include "ButtonAndLCD.h"\r
190 \r
191 /* Peripheral includes. */\r
192 #include "lcd.h"\r
193 \r
194 /* Values that are passed into the reg test tasks using the task parameter.  \r
195 The tasks check that the values are passed in correctly. */\r
196 #define mainREG_TEST_1_PARAMETER        ( 0x12121212UL )\r
197 #define mainREG_TEST_2_PARAMETER        ( 0x12345678UL )\r
198 \r
199 /* Priorities at which the tasks are created. */\r
200 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 1 )\r
201 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
202 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
203 #define mainCREATOR_TASK_PRIORITY   ( tskIDLE_PRIORITY + 3 )\r
204 #define mainFLASH_TASK_PRIORITY         ( tskIDLE_PRIORITY + 1 )\r
205 #define mainINTEGER_TASK_PRIORITY   ( tskIDLE_PRIORITY )\r
206 #define mainGEN_QUEUE_TASK_PRIORITY     ( tskIDLE_PRIORITY )\r
207 #define mainFLOP_TASK_PRIORITY          ( tskIDLE_PRIORITY )\r
208 \r
209 /* The LED toggled by the check timer. */\r
210 #define mainCHECK_LED                           ( 3 )\r
211 \r
212 /* The period at which the check timer will expire, in ms, provided no errors\r
213 have been reported by any of the standard demo tasks.  ms are converted to the\r
214 equivalent in ticks using the portTICK_PERIOD_MS constant. */\r
215 #define mainCHECK_TIMER_PERIOD_MS                       ( 5000UL / portTICK_PERIOD_MS )\r
216 \r
217 /* The period at which the check timer will expire, in ms, if an error has been\r
218 reported in one of the standard demo tasks.  ms are converted to the equivalent\r
219 in ticks using the portTICK_PERIOD_MS constant. */\r
220 #define mainERROR_CHECK_TIMER_PERIOD_MS         ( 200UL / portTICK_PERIOD_MS )\r
221 \r
222 /* A block time of zero simple means "Don't Block". */\r
223 #define mainDONT_BLOCK                          ( 0UL )\r
224 \r
225 /*\r
226  * vApplicationMallocFailedHook() will only be called if\r
227  * configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook\r
228  * function that will execute if a call to pvPortMalloc() fails.\r
229  * pvPortMalloc() is called internally by the kernel whenever a task, queue or\r
230  * semaphore is created.  It is also called by various parts of the demo\r
231  * application.\r
232  */\r
233 void vApplicationMallocFailedHook( void );\r
234 \r
235 /*\r
236  * vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set to 1\r
237  * in FreeRTOSConfig.h.  It is a hook function that is called on each iteration\r
238  * of the idle task.  It is essential that code added to this hook function\r
239  * never attempts to block in any way (for example, call xQueueReceive() with\r
240  * a block time specified).  If the application makes use of the vTaskDelete()\r
241  * API function (as this demo application does) then it is also important that\r
242  * vApplicationIdleHook() is permitted to return to its calling function because\r
243  * it is the responsibility of the idle task to clean up memory allocated by the\r
244  * kernel to any task that has since been deleted.\r
245  */\r
246 void vApplicationIdleHook( void );\r
247 \r
248 /*\r
249  * vApplicationStackOverflowHook() will only be called if\r
250  * configCHECK_FOR_STACK_OVERFLOW is set to a non-zero value.  The handle and\r
251  * name of the offending task should be passed in the function parameters, but\r
252  * it is possible that the stack overflow will have corrupted these - in which\r
253  * case pxCurrentTCB can be inspected to find the same information.\r
254  */\r
255 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
256 \r
257 /*\r
258  * The reg test tasks as described at the top of this file.\r
259  */\r
260 static void prvRegTest1Task( void *pvParameters );\r
261 static void prvRegTest2Task( void *pvParameters );\r
262 \r
263 /*\r
264  * The actual implementation of the reg test functionality, which, because of\r
265  * the direct register access, have to be in assembly.\r
266  */\r
267 static void prvRegTest1Implementation( void );\r
268 static void prvRegTest2Implementation( void );\r
269 \r
270 /*\r
271  * The check timer callback function, as described at the top of this file.\r
272  */\r
273 static void prvCheckTimerCallback( TimerHandle_t xTimer );\r
274 \r
275 \r
276 /*-----------------------------------------------------------*/\r
277 \r
278 /* Variables that are incremented on each iteration of the reg test tasks -\r
279 provided the tasks have not reported any errors.  The check timer inspects these\r
280 variables to ensure they are still incrementing as expected.  If a variable\r
281 stops incrementing then it is likely that its associate task has stalled. */\r
282 unsigned long ulRegTest1CycleCount = 0UL, ulRegTest2CycleCount = 0UL;\r
283 \r
284 /* The check timer.  This uses prvCheckTimerCallback() as its callback\r
285 function. */\r
286 static TimerHandle_t xCheckTimer = NULL;\r
287 \r
288 /*-----------------------------------------------------------*/\r
289 \r
290 void main(void)\r
291 {\r
292 extern void HardwareSetup( void );\r
293 \r
294         /* Renesas provided CPU configuration routine.  The clocks are configured in\r
295         here. */\r
296         HardwareSetup();        \r
297 \r
298         /* Turn all LEDs off. */\r
299         vParTestInitialise();\r
300 \r
301         /* Start the reg test tasks which test the context switching mechanism. */\r
302         xTaskCreate( prvRegTest1Task, "RegTst1", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_1_PARAMETER, tskIDLE_PRIORITY, NULL );\r
303         xTaskCreate( prvRegTest2Task, "RegTst2", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_2_PARAMETER, tskIDLE_PRIORITY, NULL );\r
304 \r
305         /* The button and LCD tasks, as described at the top of this file. */\r
306         vStartButtonAndLCDDemo();\r
307 \r
308         /* Create the standard demo tasks. */\r
309         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
310         vCreateBlockTimeTasks();\r
311         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
312         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
313         vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );\r
314         vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
315         vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );\r
316         vStartQueuePeekTasks();\r
317         vStartRecursiveMutexTasks();\r
318         vStartInterruptQueueTasks();\r
319 \r
320         /* The suicide tasks must be created last as they need to know how many\r
321         tasks were running prior to their creation in order to ascertain whether\r
322         or not the correct/expected number of tasks are running at any given time. */\r
323         vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
324 \r
325         /* Create the software timer that performs the 'check' functionality,\r
326         as described at the top of this file. */\r
327         xCheckTimer = xTimerCreate( "CheckTimer",/* A text name, purely to help debugging. */\r
328                                                                 ( mainCHECK_TIMER_PERIOD_MS ),          /* The timer period, in this case 5000ms (5s). */\r
329                                                                 pdTRUE,                                                         /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */\r
330                                                                 ( void * ) 0,                                           /* The ID is not used, so can be set to anything. */\r
331                                                                 prvCheckTimerCallback                           /* The callback function that inspects the status of all the other tasks. */\r
332                                                           );\r
333                                                           \r
334         configASSERT( xCheckTimer );\r
335         \r
336         /* Start the check timer.  It will actually start when the scheduler is\r
337         started. */\r
338         xTimerStart( xCheckTimer, mainDONT_BLOCK );\r
339 \r
340         /* Start the tasks running. */\r
341         vTaskStartScheduler();\r
342 \r
343         /* If all is well we will never reach here as the scheduler will now be\r
344         running.  If we do reach here then it is likely that there was insufficient\r
345         heap available for the idle task to be created. */\r
346         for( ;; );\r
347 }\r
348 /*-----------------------------------------------------------*/\r
349 \r
350 static void prvCheckTimerCallback( TimerHandle_t xTimer )\r
351 {\r
352 static long lChangedTimerPeriodAlready = pdFALSE, lErrorStatus = pdPASS;\r
353 static volatile unsigned long ulLastRegTest1CycleCount = 0UL, ulLastRegTest2CycleCount = 0UL;\r
354 \r
355         /* Check the standard demo tasks are running without error. */\r
356         if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
357         {\r
358                 lErrorStatus = pdFAIL;\r
359         }\r
360         else if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
361         {\r
362                 lErrorStatus = pdFAIL;\r
363         }\r
364         else if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
365         {\r
366                 lErrorStatus = pdFAIL;\r
367         }\r
368         else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
369         {\r
370                 lErrorStatus = pdFAIL;\r
371         }\r
372         else if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
373         {\r
374                 lErrorStatus = pdFAIL;\r
375         }\r
376         else if( xArePollingQueuesStillRunning() != pdTRUE )\r
377         {\r
378                 lErrorStatus = pdFAIL;\r
379         }\r
380         else if( xIsCreateTaskStillRunning() != pdTRUE )\r
381         {\r
382                 lErrorStatus = pdFAIL;\r
383         }\r
384         else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
385         {\r
386                 lErrorStatus = pdFAIL;\r
387         }\r
388         else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
389         {\r
390                 lErrorStatus = pdFAIL;\r
391         }\r
392         else if( xAreIntQueueTasksStillRunning() != pdPASS )\r
393         {\r
394                 lErrorStatus = pdFAIL;\r
395         }\r
396 \r
397         /* Check the reg test tasks are still cycling.  They will stop incrementing\r
398         their loop counters if they encounter an error. */\r
399         if( ulRegTest1CycleCount == ulLastRegTest1CycleCount )\r
400         {\r
401                 lErrorStatus = pdFAIL;\r
402         }\r
403 \r
404         if( ulRegTest2CycleCount == ulLastRegTest2CycleCount )\r
405         {\r
406                 lErrorStatus = pdFAIL;\r
407         }\r
408 \r
409         ulLastRegTest1CycleCount = ulRegTest1CycleCount;\r
410         ulLastRegTest2CycleCount = ulRegTest2CycleCount;\r
411 \r
412         /* Toggle the check LED to give an indication of the system status.  If\r
413         the LED toggles every 5 seconds then everything is ok.  A faster toggle\r
414         indicates an error. */\r
415         vParTestToggleLED( mainCHECK_LED );\r
416         \r
417         /* Was an error detected this time through the callback execution? */\r
418         if( lErrorStatus != pdPASS )\r
419         {\r
420                 if( lChangedTimerPeriodAlready == pdFALSE )\r
421                 {\r
422                         lChangedTimerPeriodAlready = pdTRUE;\r
423                         \r
424                         /* This call to xTimerChangePeriod() uses a zero block time.  \r
425                         Functions called from inside of a timer callback function must \r
426                         *never* attempt to block. */\r
427                         xTimerChangePeriod( xCheckTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );\r
428                 }\r
429         }\r
430 }\r
431 /*-----------------------------------------------------------*/\r
432 \r
433 /* The RX port uses this callback function to configure its tick interrupt.\r
434 This allows the application to choose the tick interrupt source. */\r
435 void vApplicationSetupTimerInterrupt( void )\r
436 {\r
437         /* Enable compare match timer 0. */\r
438         MSTP( CMT0 ) = 0;\r
439 \r
440         /* Interrupt on compare match. */\r
441         CMT0.CMCR.BIT.CMIE = 1;\r
442 \r
443         /* Set the compare match value. */\r
444         CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );\r
445 \r
446         /* Divide the PCLK by 8. */\r
447         CMT0.CMCR.BIT.CKS = 0;\r
448 \r
449         /* Enable the interrupt... */\r
450         _IEN( _CMT0_CMI0 ) = 1;\r
451 \r
452         /* ...and set its priority to the application defined kernel priority. */\r
453         _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;\r
454 \r
455         /* Start the timer. */\r
456         CMT.CMSTR0.BIT.STR0 = 1;\r
457 }\r
458 /*-----------------------------------------------------------*/\r
459 \r
460 /* This function is explained by the comments above its prototype at the top\r
461 of this file. */\r
462 void vApplicationMallocFailedHook( void )\r
463 {\r
464         for( ;; );\r
465 }\r
466 /*-----------------------------------------------------------*/\r
467 \r
468 /* This function is explained by the comments above its prototype at the top\r
469 of this file. */\r
470 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
471 {\r
472         for( ;; );\r
473 }\r
474 /*-----------------------------------------------------------*/\r
475 \r
476 /* This function is explained by the comments above its prototype at the top\r
477 of this file. */\r
478 void vApplicationIdleHook( void )\r
479 {\r
480         /* If this is being executed then the kernel has been started.  Start the high\r
481         frequency timer test as described at the top of this file.  This is only\r
482         included in the optimised build configuration - otherwise it takes up too much\r
483         CPU time and can disrupt other tests. */\r
484         #ifdef INCLUDE_HIGH_FREQUENCY_TIMER_TEST\r
485         static portBASE_TYPE xTimerTestStarted = pdFALSE;\r
486         extern void vSetupHighFrequencyTimer( void );\r
487                 if( xTimerTestStarted == pdFALSE )\r
488                 {\r
489                         vSetupHighFrequencyTimer();\r
490                         xTimerTestStarted = pdTRUE;\r
491                 }\r
492         #endif\r
493 }\r
494 /*-----------------------------------------------------------*/\r
495 \r
496 /* This function is explained in the comments at the top of this file. */\r
497 static void prvRegTest1Task( void *pvParameters )\r
498 {\r
499         if( ( ( unsigned long ) pvParameters ) != mainREG_TEST_1_PARAMETER )\r
500         {\r
501                 /* The parameter did not contain the expected value. */\r
502                 for( ;; )\r
503                 {\r
504                         /* Stop the tick interrupt so its obvious something has gone wrong. */\r
505                         taskDISABLE_INTERRUPTS();\r
506                 }\r
507         }\r
508 \r
509         /* This is an inline asm function that never returns. */\r
510         prvRegTest1Implementation();\r
511 }\r
512 /*-----------------------------------------------------------*/\r
513 \r
514 /* This function is explained in the comments at the top of this file. */\r
515 static void prvRegTest2Task( void *pvParameters )\r
516 {\r
517         if( ( ( unsigned long ) pvParameters ) != mainREG_TEST_2_PARAMETER )\r
518         {\r
519                 /* The parameter did not contain the expected value. */\r
520                 for( ;; )\r
521                 {\r
522                         /* Stop the tick interrupt so its obvious something has gone wrong. */\r
523                         taskDISABLE_INTERRUPTS();\r
524                 }\r
525         }\r
526 \r
527         /* This is an inline asm function that never returns. */\r
528         prvRegTest2Implementation();\r
529 }\r
530 /*-----------------------------------------------------------*/\r
531 \r
532 /* This function is explained in the comments at the top of this file. */\r
533 #pragma inline_asm prvRegTest1Implementation\r
534 static void prvRegTest1Implementation( void )\r
535 {\r
536         ; Put a known value in each register.\r
537         MOV.L   #1, R1\r
538         MOV.L   #2, R2\r
539         MOV.L   #3, R3\r
540         MOV.L   #4, R4\r
541         MOV.L   #5, R5\r
542         MOV.L   #6, R6\r
543         MOV.L   #7, R7\r
544         MOV.L   #8, R8\r
545         MOV.L   #9, R9\r
546         MOV.L   #10, R10\r
547         MOV.L   #11, R11\r
548         MOV.L   #12, R12\r
549         MOV.L   #13, R13\r
550         MOV.L   #14, R14\r
551         MOV.L   #15, R15\r
552 \r
553         ; Loop, checking each itteration that each register still contains the\r
554         ; expected value.\r
555 TestLoop1:\r
556 \r
557         ; Push the registers that are going to get clobbered.\r
558         PUSHM   R14-R15\r
559 \r
560         ; Increment the loop counter to show this task is still getting CPU time.\r
561         MOV.L   #_ulRegTest1CycleCount, R14\r
562         MOV.L   [ R14 ], R15\r
563         ADD             #1, R15\r
564         MOV.L   R15, [ R14 ]\r
565 \r
566         ; Yield to extend the text coverage.  Set the bit in the ITU SWINTR register.\r
567         MOV.L   #1, R14\r
568         MOV.L   #0872E0H, R15\r
569         MOV.B   R14, [R15]\r
570         NOP\r
571         NOP\r
572 \r
573         ; Restore the clobbered registers.\r
574         POPM    R14-R15\r
575 \r
576         ; Now compare each register to ensure it still contains the value that was\r
577         ; set before this loop was entered.\r
578         CMP             #1, R1\r
579         BNE             RegTest1Error\r
580         CMP             #2, R2\r
581         BNE             RegTest1Error\r
582         CMP             #3, R3\r
583         BNE             RegTest1Error\r
584         CMP             #4, R4\r
585         BNE             RegTest1Error\r
586         CMP             #5, R5\r
587         BNE             RegTest1Error\r
588         CMP             #6, R6\r
589         BNE             RegTest1Error\r
590         CMP             #7, R7\r
591         BNE             RegTest1Error\r
592         CMP             #8, R8\r
593         BNE             RegTest1Error\r
594         CMP             #9, R9\r
595         BNE             RegTest1Error\r
596         CMP             #10, R10\r
597         BNE             RegTest1Error\r
598         CMP             #11, R11\r
599         BNE             RegTest1Error\r
600         CMP             #12, R12\r
601         BNE             RegTest1Error\r
602         CMP             #13, R13\r
603         BNE             RegTest1Error\r
604         CMP             #14, R14\r
605         BNE             RegTest1Error\r
606         CMP             #15, R15\r
607         BNE             RegTest1Error\r
608 \r
609         ; All comparisons passed, start a new itteratio of this loop.\r
610         BRA             TestLoop1\r
611 \r
612 RegTest1Error:\r
613         ; A compare failed, just loop here so the loop counter stops incrementing\r
614         ; causing the check timer to indicate the error.\r
615         BRA RegTest1Error\r
616 }\r
617 /*-----------------------------------------------------------*/\r
618 \r
619 /* This function is explained in the comments at the top of this file. */\r
620 #pragma inline_asm prvRegTest2Implementation\r
621 static void prvRegTest2Implementation( void )\r
622 {\r
623         ; Put a known value in each register.\r
624         MOV.L   #10, R1\r
625         MOV.L   #20, R2\r
626         MOV.L   #30, R3\r
627         MOV.L   #40, R4\r
628         MOV.L   #50, R5\r
629         MOV.L   #60, R6\r
630         MOV.L   #70, R7\r
631         MOV.L   #80, R8\r
632         MOV.L   #90, R9\r
633         MOV.L   #100, R10\r
634         MOV.L   #110, R11\r
635         MOV.L   #120, R12\r
636         MOV.L   #130, R13\r
637         MOV.L   #140, R14\r
638         MOV.L   #150, R15\r
639 \r
640         ; Loop, checking on each itteration that each register still contains the\r
641         ; expected value.\r
642 TestLoop2:\r
643 \r
644         ; Push the registers that are going to get clobbered.\r
645         PUSHM   R14-R15\r
646 \r
647         ; Increment the loop counter to show this task is still getting CPU time.\r
648         MOV.L   #_ulRegTest2CycleCount, R14\r
649         MOV.L   [ R14 ], R15\r
650         ADD             #1, R15\r
651         MOV.L   R15, [ R14 ]\r
652 \r
653         ; Restore the clobbered registers.\r
654         POPM    R14-R15\r
655 \r
656         CMP             #10, R1\r
657         BNE             RegTest2Error\r
658         CMP             #20, R2\r
659         BNE             RegTest2Error\r
660         CMP             #30, R3\r
661         BNE             RegTest2Error\r
662         CMP             #40, R4\r
663         BNE             RegTest2Error\r
664         CMP             #50, R5\r
665         BNE             RegTest2Error\r
666         CMP             #60, R6\r
667         BNE             RegTest2Error\r
668         CMP             #70, R7\r
669         BNE             RegTest2Error\r
670         CMP             #80, R8\r
671         BNE             RegTest2Error\r
672         CMP             #90, R9\r
673         BNE             RegTest2Error\r
674         CMP             #100, R10\r
675         BNE             RegTest2Error\r
676         CMP             #110, R11\r
677         BNE             RegTest2Error\r
678         CMP             #120, R12\r
679         BNE             RegTest2Error\r
680         CMP             #130, R13\r
681         BNE             RegTest2Error\r
682         CMP             #140, R14\r
683         BNE             RegTest2Error\r
684         CMP             #150, R15\r
685         BNE             RegTest2Error\r
686 \r
687         ; All comparisons passed, start a new itteratio of this loop.\r
688         BRA             TestLoop2\r
689 \r
690 RegTest2Error:\r
691         ; A compare failed, just loop here so the loop counter stops incrementing\r
692         ; - causing the check timer to indicate the error.\r
693         BRA RegTest2Error\r
694 }\r
695 /*-----------------------------------------------------------*/\r
696 \r