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