]> begriffs open source - cmsis-freertos/blob - Demo/TriCore_TC1782_TriBoard_GCC/RTOSDemo/main.c
Updated to FreeRTOS V10.0.1
[cmsis-freertos] / Demo / TriCore_TC1782_TriBoard_GCC / RTOSDemo / main.c
1 /*
2  * FreeRTOS Kernel V10.0.1
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * http://www.FreeRTOS.org
23  * http://aws.amazon.com/freertos
24  *
25  * 1 tab == 4 spaces!
26  */
27
28 /******************************************************************************
29  * >>>>>> NOTE: <<<<<<
30  *
31  * main() can be configured to create either a very simple LED flasher demo, or
32  * a more comprehensive test/demo application.
33  *
34  * To create a very simple LED flasher example, set the
35  * mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY constant (defined below) to 1.  When
36  * this is done, only the standard demo flash tasks are created.  The standard
37  * demo flash example creates three tasks, each toggle an LED at a fixed but
38  * different frequency.
39  *
40  * To create a more comprehensive test and demo application, set
41  * mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY to 0.
42  *
43  * Two build configurations are provided, one that executes from RAM and one
44  * that executes from Flash.  The RAM build uses size optimisation, the Flash
45  * build has optimisation completely turned off.  The documentation page for
46  * this port on the FreeRTOS.org web site provides full information.
47  ******************************************************************************
48  *
49  * main() creates all the demo application tasks and timers, then starts the
50  * scheduler.  The web documentation provides more details of the standard demo
51  * application tasks, which provide no particular functionality, but do provide
52  * a good example of how to use the FreeRTOS API.
53  *
54  * In addition to the standard demo tasks, the following tasks and tests are
55  * defined and/or created within this file:
56  *
57  * "Reg test" tasks - These fill the registers with known values, then check
58  * that each register maintains its expected value for the lifetime of the
59  * task.  Each task uses a different set of values.  The reg test tasks execute
60  * with a very low priority, so get preempted very frequently.  A register
61  * containing an unexpected value is indicative of an error in the context
62  * switching mechanism.
63  *
64  * "Check" task - The check task period is initially set to five seconds.
65  * Each time it executes, the check task checks that all the standard demo
66  * tasks, and the register check tasks, are not only still executing, but are
67  * executing without reporting any errors.  If the check task discovers that a
68  * task has either stalled, or reported an error, then it changes its own
69  * execution period from the initial five seconds, to just 500ms.  The check
70  * task  also toggles an LED each time it is called.  This provides a visual
71  * indication of the system status:  If the LED toggles every five seconds,
72  * then no issues have been discovered.  If the LED toggles every 500ms, then
73  * an issue has been discovered with at least one task.
74  *
75  * ***NOTE*** This demo uses the standard comtest tasks, which has special
76  * hardware requirements as a loopback connector, or UART echo server are
77  * required.  See the documentation page for this demo on the FreeRTOS.org web
78  * site for more information.  Note that the comtest tasks were tested by
79  * placing the UART into loopback mode directly in the serial initialisation
80  * sequence, and as such, the baud rate used has not been verified as actually
81  * being correct.
82  */
83
84 /* Standard includes. */
85 #include <stdlib.h>
86 #include <string.h>
87
88 /* Scheduler includes. */
89 #include "FreeRTOS.h"
90 #include "task.h"
91 #include "croutine.h"
92
93 /* Demo application includes. */
94 #include "partest.h"
95 #include "flash.h"
96 #include "integer.h"
97 #include "PollQ.h"
98 #include "comtest2.h"
99 #include "semtest.h"
100 #include "dynamic.h"
101 #include "BlockQ.h"
102 #include "blocktim.h"
103 #include "countsem.h"
104 #include "GenQTest.h"
105 #include "recmutex.h"
106 #include "serial.h"
107 #include "death.h"
108 #include "TimerDemo.h"
109 #include "InterruptNestTest.h"
110
111 /*-----------------------------------------------------------*/
112
113 /* Constants for the ComTest tasks. */
114 #define mainCOM_TEST_BAUD_RATE          ( ( unsigned long ) 200000 )
115
116 #define mainCOM_TEST_LED                        ( 5 )
117
118 /* Priorities for the demo application tasks. */
119 #define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 1 )
120 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )
121 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 2 )
122 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )
123 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )
124 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )
125 #define mainCREATOR_TASK_PRIORITY       ( tskIDLE_PRIORITY + 3 )
126
127 /* The rate at which the on board LED will toggle when there is/is not an
128 error. */
129 #define mainNO_ERROR_FLASH_PERIOD_MS    ( ( TickType_t ) 5000 / portTICK_PERIOD_MS      )
130 #define mainERROR_FLASH_PERIOD_MS               ( ( TickType_t ) 500 / portTICK_PERIOD_MS  )
131 #define mainON_BOARD_LED_BIT                    ( ( unsigned long ) 7 )
132
133 /* Constant used by the standard timer test functions.  The timers created by
134 the timer test functions will all have a period that is a multiple of this
135 value. */
136 #define mainTIMER_TEST_PERIOD           ( 200 )
137
138 /* Set mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY to 1 to create a simple demo.
139 Set mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY to 0 to create a much more
140 comprehensive test application.  See the comments at the top of this file, and
141 the documentation page on the http://www.FreeRTOS.org web site for more
142 information. */
143 #define mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY         0
144
145 /*-----------------------------------------------------------*/
146
147 /*
148  * Checks that all the demo application tasks are still executing without error
149  * - as described at the top of the file.
150  */
151 static long prvCheckOtherTasksAreStillRunning( void );
152
153 /*
154  * The task that executes at the highest priority and calls
155  * prvCheckOtherTasksAreStillRunning().  See the description at the top
156  * of the file.
157  */
158 static void prvCheckTask( void *pvParameters );
159
160 /*
161  * Configure the processor ready to run this demo.
162  */
163 static void prvSetupHardware( void );
164
165 /*
166  * Writes to and checks the value of each register that is used in the context
167  * of a task.  See the comments at the top of this file.
168  */
169 static void prvRegisterCheckTask1( void *pvParameters );
170 static void prvRegisterCheckTask2( void *pvParameters );
171
172 /*
173  * Specific check to see if the register test functions are still operating
174  * correctly.
175  */
176 static portBASE_TYPE prvAreRegTestTasksStillRunning( void );
177
178 /*
179  * This file can be used to create either a simple LED flasher example, or a
180  * comprehensive test/demo application - depending on the setting of the
181  * mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY constant defined above.  If
182  * mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY is set to 1, then the following
183  * function will create a lot of additional tasks and timers.  If
184  * mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY is set to 0, then the following
185  * function will do nothing.
186  */
187 static void prvOptionallyCreateComprehensveTestApplication( void );
188
189 /*-----------------------------------------------------------*/
190
191 /* Used by the register test tasks to indicated liveness. */
192 static unsigned long ulRegisterTest1Count = 0;
193 static unsigned long ulRegisterTest2Count = 0;
194
195 /*-----------------------------------------------------------*/
196
197 /*
198  * Starts all the tasks, then starts the scheduler.
199  */
200 int main( void )
201 {
202         /* Setup the hardware for use with the TriCore evaluation board. */
203         prvSetupHardware();
204
205         /* Start standard demo/test application flash tasks.  See the comments at
206         the top of this file.  The LED flash tasks are always created.  The other
207         tasks are only created if mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY is set to
208         0 (at the top of this file).  See the comments at the top of this file for
209         more information. */
210         vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
211
212         /* The following function will only create more tasks and timers if
213         mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY is set to 0 (at the top of this
214         file).  See the comments at the top of this file for more information. */
215         prvOptionallyCreateComprehensveTestApplication();
216
217         /* Now all the tasks have been started - start the scheduler. */
218         vTaskStartScheduler();
219
220         /* If all is well then the following line will never be reached.  If
221         execution does reach here, then it is highly probably that the heap size
222         is too small for the idle and/or timer tasks to be created within
223         vTaskStartScheduler(). */
224         for( ;; );
225 }
226 /*-----------------------------------------------------------*/
227
228 static void prvCheckTask( void *pvParameters )
229 {
230 TickType_t xDelayPeriod = mainNO_ERROR_FLASH_PERIOD_MS;
231 TickType_t xLastExecutionTime;
232
233         /* Just to stop compiler warnings. */
234         ( void ) pvParameters;
235
236         /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
237         works correctly. */
238         xLastExecutionTime = xTaskGetTickCount();
239
240         /* Cycle for ever, delaying then checking all the other tasks are still
241         operating without error.  If an error is detected then the delay period
242         is decreased from mainNO_ERROR_FLASH_PERIOD_MS to mainERROR_FLASH_PERIOD_MS so
243         the on board LED flash rate will increase.  NOTE:  This task could easily
244         be replaced by a software timer callback to remove the overhead of having
245         an extra task. */
246
247         for( ;; )
248         {
249                 /* Delay until it is time to execute again. */
250                 vTaskDelayUntil( &xLastExecutionTime, xDelayPeriod );
251
252                 /* Check all the standard demo application tasks are executing without
253                 error.  */
254                 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
255                 {
256                         /* An error has been detected in one of the tasks - flash the LED
257                         at a higher frequency to give visible feedback that something has
258                         gone wrong (it might just be that the loop back connector required
259                         by the comtest tasks has not been fitted). */
260                         xDelayPeriod = mainERROR_FLASH_PERIOD_MS;
261                 }
262
263                 /* The toggle rate of the LED depends on how long this task delays for.
264                 An error reduces the delay period and so increases the toggle rate. */
265                 vParTestToggleLED( mainON_BOARD_LED_BIT );
266         }
267 }
268 /*-----------------------------------------------------------*/
269
270 static long prvCheckOtherTasksAreStillRunning( void )
271 {
272 long lReturn = pdPASS;
273 unsigned long ulHighFrequencyTimerTaskIterations, ulExpectedIncFrequency_ms;
274
275         /* Check all the demo tasks (other than the flash tasks) to ensure
276         that they are all still running, and that none have detected an error. */
277
278         if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
279         {
280                 lReturn = pdFAIL;
281         }
282
283         if( xAreComTestTasksStillRunning() != pdTRUE )
284         {
285                 lReturn = pdFAIL;
286         }
287
288         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
289         {
290                 lReturn = pdFAIL;
291         }
292
293         if( xAreBlockingQueuesStillRunning() != pdTRUE )
294         {
295                 lReturn = pdFAIL;
296         }
297
298         if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
299         {
300                 lReturn = pdFAIL;
301         }
302
303         if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
304         {
305                 lReturn = pdFAIL;
306         }
307
308         if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
309         {
310                 lReturn = pdFAIL;
311         }
312
313         if( prvAreRegTestTasksStillRunning() != pdTRUE )
314         {
315                 lReturn = pdFAIL;
316         }
317
318         if( xIsCreateTaskStillRunning() != pdTRUE )
319         {
320                 lReturn = pdFAIL;
321         }
322
323         if( xAreTimerDemoTasksStillRunning( mainNO_ERROR_FLASH_PERIOD_MS ) != pdTRUE )
324         {
325                 lReturn = pdFAIL;
326         }
327
328         if( xArePollingQueuesStillRunning() != pdTRUE )
329         {
330                 lReturn = pdFAIL;
331         }
332
333         if( xAreSemaphoreTasksStillRunning() != pdTRUE )
334         {
335                 lReturn = pdFAIL;
336         }
337
338         /* Obtain the number of times the task associated with the high frequency
339         (interrupt nesting) timer test has increment since the check task last
340         executed, and the frequency at which it is expected to execute in ms. */
341         ulHighFrequencyTimerTaskIterations = ulInterruptNestingTestGetIterationCount( &ulExpectedIncFrequency_ms );
342         if( ( ulHighFrequencyTimerTaskIterations < ( ( mainNO_ERROR_FLASH_PERIOD_MS / ulExpectedIncFrequency_ms ) - 1 ) )
343                 ||
344                 ( ulHighFrequencyTimerTaskIterations > ( ( mainNO_ERROR_FLASH_PERIOD_MS / ulExpectedIncFrequency_ms ) +5 ) )
345           )
346         {
347                 /* Would have expected the high frequency timer task to have
348                 incremented its execution count more times that reported. */
349                 lReturn = pdFAIL;
350         }
351
352         return lReturn;
353 }
354 /*-----------------------------------------------------------*/
355
356 static void prvSetupHardware( void )
357 {
358 extern void set_cpu_frequency(void);
359
360         /* Set-up the PLL. */
361         set_cpu_frequency();
362
363         /* Initialise LED outputs. */
364         vParTestInitialise();
365 }
366 /*-----------------------------------------------------------*/
367
368 void vApplicationMallocFailedHook( void )
369 {
370         /* vApplicationMallocFailedHook() will only be called if
371         configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook
372         function that will get called if a call to pvPortMalloc() fails.
373         pvPortMalloc() is called internally by the kernel whenever a task, queue,
374         timer or semaphore is created.  It is also called by various parts of the
375         demo application.  If heap_1.c or heap_2.c are used, then the size of the
376         heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
377         FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
378         to query the size of free heap space that remains (although it does not
379         provide information on how the remaining heap might be fragmented). */
380         taskDISABLE_INTERRUPTS();
381         for( ;; );
382 }
383 /*-----------------------------------------------------------*/
384
385 void vApplicationTickHook( void )
386 {
387         #if mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY != 1
388         {
389                 /* vApplicationTickHook() will only be called if configUSE_TICK_HOOK is set
390                 to 1 in FreeRTOSConfig.h.  It is a hook function that will get called during
391                 each FreeRTOS tick interrupt.  Note that vApplicationTickHook() is called
392                 from an interrupt context. */
393
394                 /* Call the periodic timer test, which tests the timer API functions that
395                 can be called from an ISR. */
396                 vTimerPeriodicISRTests();
397         }
398         #endif /* mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY */
399 }
400 /*-----------------------------------------------------------*/
401
402 void vApplicationIdleHook( void )
403 {
404         /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
405         to 1 in FreeRTOSConfig.h.  It will be called on each iteration of the idle
406         task.  It is essential that code added to this hook function never attempts
407         to block in any way (for example, call xQueueReceive() with a block time
408         specified, or call vTaskDelay()).  If the application makes use of the
409         vTaskDelete() API function (as this demo application does) then it is also
410         important that vApplicationIdleHook() is permitted to return to its calling
411         function, because it is the responsibility of the idle task to clean up
412         memory allocated by the kernel to any task that has since been deleted. */
413 }
414 /*-----------------------------------------------------------*/
415
416 static portBASE_TYPE prvAreRegTestTasksStillRunning( void )
417 {
418 static unsigned long ulPreviousRegisterTest1Count = 0;
419 static unsigned long ulPreviousRegisterTest2Count = 0;
420 portBASE_TYPE xReturn = pdPASS;
421
422         /* Check to see if the Counts have changed since the last check. */
423         if( ulRegisterTest1Count == ulPreviousRegisterTest1Count )
424         {
425                 xReturn = pdFAIL;
426         }
427
428         if( ulRegisterTest2Count == ulPreviousRegisterTest2Count )
429         {
430                 xReturn = pdFAIL;
431         }
432
433         /* Remember the current count for the next time this function is called. */
434         ulPreviousRegisterTest1Count = ulRegisterTest1Count;
435         ulPreviousRegisterTest2Count = ulRegisterTest2Count;
436
437         return xReturn;
438 }
439 /*-----------------------------------------------------------*/
440
441 static void prvOptionallyCreateComprehensveTestApplication( void )
442 {
443         #if mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY == 0
444         {
445                 vStartIntegerMathTasks( tskIDLE_PRIORITY );
446                 vStartDynamicPriorityTasks();
447                 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
448                 vCreateBlockTimeTasks();
449                 vStartCountingSemaphoreTasks();
450                 vStartGenericQueueTasks( tskIDLE_PRIORITY );
451                 vStartRecursiveMutexTasks();
452                 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
453                 vSetupInterruptNestingTest();
454                 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );
455                 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
456                 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
457
458                 /* Create the register test tasks, as described at the top of this file. */
459                 xTaskCreate( prvRegisterCheckTask1, "Reg 1", configMINIMAL_STACK_SIZE, &ulRegisterTest1Count, tskIDLE_PRIORITY, NULL );
460                 xTaskCreate( prvRegisterCheckTask2, "Reg 2", configMINIMAL_STACK_SIZE, &ulRegisterTest2Count, tskIDLE_PRIORITY, NULL );
461
462                 /* Start the check task - which is defined in this file. */
463                 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
464
465                 /* This task has to be created last as it keeps account of the number of tasks
466                 it expects to see running. */
467                 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
468         }
469         #else /* mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY */
470         {
471                 /* Just to prevent compiler warnings when the configuration options are
472                 set such that these static functions are not used. */
473                 ( void ) prvCheckTask;
474                 ( void ) prvRegisterCheckTask1;
475                 ( void ) prvRegisterCheckTask2;
476         }
477         #endif /* mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY */
478 }
479 /*-----------------------------------------------------------*/
480
481 static void prvRegisterCheckTask1( void *pvParameters )
482 {
483         /* Make space on the stack for the parameter and a counter. */
484         __asm volatile( " sub.a %sp, 4                  \n"
485                                         " st.a [%sp], %a4               \n"
486                                         " mov %d15, 0                   \n"
487                                         " st.w [%sp]4, %d15             \n" );
488
489         /* Change all of the Context sensitive registers (except SP and RA). */
490         __asm volatile(
491                         " mov %d0, 0            \n"
492                         " mov %d1, 1            \n"
493                         " mov %d2, 2            \n"
494                         " mov %d3, 3            \n"
495                         " mov %d4, 4            \n"
496                         " mov %d5, 5            \n"
497                         " mov %d6, 6            \n"
498                         " mov %d7, 7            \n"
499                         " mov %d8, 8            \n"
500                         " mov %d9, 9            \n"
501                         " mov %d10, 10          \n"
502                         " mov %d11, 11          \n"
503                         " mov %d12, 12          \n"
504                         " mov %d13, 13          \n"
505                         " mov %d14, 14          \n"
506                         " mov %d15, 15          \n"
507                         " mov.a %a2, 2          \n"
508                         " mov.a %a3, 3          \n"
509                         " mov.a %a4, 4          \n"
510                         " mov.a %a5, 5          \n"
511                         " mov.a %a6, 6          \n"
512                         " mov.a %a7, 7          \n"
513                         " mov.a %a12, 12        \n"
514                         " mov.a %a13, 13        \n"
515                         " mov.a %a14, 14        \n" );
516
517         /* Check the values of the registers. */
518         __asm(  " _task1_loop:                                                  \n" \
519                         " eq %d1, %d0, 0                                                \n" \
520                         " jne %d1, 1, _task1_error_loop                 \n" \
521                         " eq %d1, %d1, 1                                                \n" \
522                         " jne %d1, 1, _task1_error_loop                 \n" \
523                         " eq %d1, %d2, 2                                                \n" \
524                         " jne %d1, 1, _task1_error_loop                 \n" \
525                         " eq %d1, %d3, 3                                                \n" \
526                         " jne %d1, 1, _task1_error_loop                 \n" \
527                         " eq %d1, %d4, 4                                                \n" \
528                         " jne %d1, 1, _task1_error_loop                 \n" \
529                         " eq %d1, %d5, 5                                                \n" \
530                         " jne %d1, 1, _task1_error_loop                 \n" \
531                         " eq %d1, %d6, 6                                                \n" \
532                         " jne %d1, 1, _task1_error_loop                 \n" \
533                         " eq %d1, %d7, 7                                                \n" \
534                         " jne %d1, 1, _task1_error_loop                 \n" \
535                         " eq %d1, %d8, 8                                                \n" \
536                         " jne %d1, 1, _task1_error_loop                 \n" \
537                         " eq %d1, %d9, 9                                                \n" \
538                         " jne %d1, 1, _task1_error_loop                 \n" \
539                         " eq %d1, %d10, 10                                              \n" \
540                         " jne %d1, 1, _task1_error_loop                 \n" \
541                         " eq %d1, %d11, 11                                              \n" \
542                         " jne %d1, 1, _task1_error_loop                 \n" \
543                         " eq %d1, %d12, 12                                              \n" \
544                         " jne %d1, 1, _task1_error_loop                 \n" \
545                         " eq %d1, %d13, 13                                              \n" \
546                         " jne %d1, 1, _task1_error_loop                 \n" \
547                         " eq %d1, %d14, 14                                              \n" \
548                         " jne %d1, 1, _task1_error_loop                 \n" \
549                         " eq %d1, %d15, 15                                              \n" \
550                         " jne %d1, 1, _task1_error_loop                 \n" \
551                         " mov.a %a15, 2                                                 \n" \
552                         " jne.a %a15, %a2, _task1_error_loop    \n" \
553                         " mov.a %a15, 3                                                 \n" \
554                         " jne.a %a15, %a3, _task1_error_loop    \n" \
555                         " mov.a %a15, 4                                                 \n" \
556                         " jne.a %a15, %a4, _task1_error_loop    \n" \
557                         " mov.a %a15, 5                                                 \n" \
558                         " jne.a %a15, %a5, _task1_error_loop    \n" \
559                         " mov.a %a15, 6                                                 \n" \
560                         " jne.a %a15, %a6, _task1_error_loop    \n" \
561                         " mov.a %a15, 7                                                 \n" \
562                         " jne.a %a15, %a7, _task1_error_loop    \n" \
563                         " mov.a %a15, 12                                                \n" \
564                         " jne.a %a15, %a12, _task1_error_loop   \n" \
565                         " mov.a %a15, 13                                                \n" \
566                         " jne.a %a15, %a13, _task1_error_loop   \n" \
567                         " mov.a %a15, 14                                                \n" \
568                         " jne.a %a15, %a14, _task1_error_loop   \n" \
569                         " j _task1_skip_error_loop                              \n"     \
570                         "_task1_error_loop:                                             \n"     /* Hitting this error loop will stop the counter incrementing, allowing the check task to recognise an error. */ \
571                         "       debug                                                           \n"     \
572                         " j _task1_error_loop                                   \n"     \
573                         "_task1_skip_error_loop:                                \n" );
574
575         /* Load the parameter address from the stack and modify the value. */
576         __asm volatile(                                                                 \
577                         " ld.w %d1, [%sp]4                                              \n"     \
578                         " add %d1, 1                                                    \n"     \
579                         " st.w [%sp]4, %d1                                              \n"     \
580                         " ld.a %a15, [%sp]                                              \n"     \
581                         " st.w [%a15], %d1                                              \n"     \
582                         " j _task1_loop                                                 \n" );
583
584         /* The parameter is used but in the assembly. */
585         (void)pvParameters;
586 }
587 /*-----------------------------------------------------------*/
588
589 static void prvRegisterCheckTask2( void *pvParameters )
590 {
591         /* Make space on the stack for the parameter and a counter. */
592         __asm volatile( " sub.a %sp, 4          \n" \
593                                         " st.a [%sp], %a4       \n" \
594                                         " mov %d15, 0           \n" \
595                                         " st.w [%sp]4, %d15     \n" );
596
597         /* Change all of the Context sensitive registers (except SP and RA). */
598         __asm volatile( " mov %d0, 7            \n" \
599                                         " mov %d1, 1            \n" \
600                                         " mov %d2, 5            \n" \
601                                         " mov %d3, 4            \n" \
602                                         " mov %d4, 3            \n" \
603                                         " mov %d5, 2            \n" \
604                                         " mov %d6, 1            \n" \
605                                         " mov %d7, 0            \n" \
606                                         " mov %d8, 15           \n" \
607                                         " mov %d9, 14           \n" \
608                                         " mov %d10, 13          \n" \
609                                         " mov %d11, 12          \n" \
610                                         " mov %d12, 11          \n" \
611                                         " mov %d13, 10          \n" \
612                                         " mov %d14, 9           \n" \
613                                         " mov %d15, 8           \n" \
614                                         " mov.a %a2, 14         \n" \
615                                         " mov.a %a3, 13         \n" \
616                                         " mov.a %a4, 12         \n" \
617                                         " mov.a %a5, 7          \n" \
618                                         " mov.a %a6, 6          \n" \
619                                         " mov.a %a7, 5          \n" \
620                                         " mov.a %a12, 4         \n" \
621                                         " mov.a %a13, 3         \n" \
622                                         " mov.a %a14, 2         \n" );
623
624         /* Check the values of the registers. */
625         __asm volatile( " _task2_loop:                                                  \n" \
626                                         " syscall 0                                                             \n" \
627                                         " eq %d1, %d0, 7                                                \n" \
628                                         " jne %d1, 1, _task2_error_loop                 \n" \
629                                         " eq %d1, %d1, 1                                                \n" \
630                                         " jne %d1, 1, _task2_error_loop                 \n" \
631                                         " eq %d1, %d2, 5                                                \n" \
632                                         " jne %d1, 1, _task2_error_loop                 \n" \
633                                         " eq %d1, %d3, 4                                                \n" \
634                                         " jne %d1, 1, _task2_error_loop                 \n" \
635                                         " eq %d1, %d4, 3                                                \n" \
636                                         " jne %d1, 1, _task2_error_loop                 \n" \
637                                         " eq %d1, %d5, 2                                                \n" \
638                                         " jne %d1, 1, _task2_error_loop                 \n" \
639                                         " eq %d1, %d6, 1                                                \n" \
640                                         " jne %d1, 1, _task2_error_loop                 \n" \
641                                         " eq %d1, %d7, 0                                                \n" \
642                                         " jne %d1, 1, _task2_error_loop                 \n" \
643                                         " eq %d1, %d8, 15                                               \n" \
644                                         " jne %d1, 1, _task2_error_loop                 \n" \
645                                         " eq %d1, %d9, 14                                               \n" \
646                                         " jne %d1, 1, _task2_error_loop                 \n" \
647                                         " eq %d1, %d10, 13                                              \n" \
648                                         " jne %d1, 1, _task2_error_loop                 \n" \
649                                         " eq %d1, %d11, 12                                              \n" \
650                                         " jne %d1, 1, _task2_error_loop                 \n" \
651                                         " eq %d1, %d12, 11                                              \n" \
652                                         " jne %d1, 1, _task2_error_loop                 \n" \
653                                         " eq %d1, %d13, 10                                              \n" \
654                                         " jne %d1, 1, _task2_error_loop                 \n" \
655                                         " eq %d1, %d14, 9                                               \n" \
656                                         " jne %d1, 1, _task2_error_loop                 \n" \
657                                         " eq %d1, %d15, 8                                               \n" \
658                                         " jne %d1, 1, _task2_error_loop                 \n" \
659                                         " mov.a %a15, 14                                                \n" \
660                                         " jne.a %a15, %a2, _task2_error_loop    \n" \
661                                         " mov.a %a15, 13                                                \n" \
662                                         " jne.a %a15, %a3, _task2_error_loop    \n" \
663                                         " mov.a %a15, 12                                                \n" \
664                                         " jne.a %a15, %a4, _task2_error_loop    \n" \
665                                         " mov.a %a15, 7                                                 \n" \
666                                         " jne.a %a15, %a5, _task2_error_loop    \n" \
667                                         " mov.a %a15, 6                                                 \n" \
668                                         " jne.a %a15, %a6, _task2_error_loop    \n" \
669                                         " mov.a %a15, 5                                                 \n" \
670                                         " jne.a %a15, %a7, _task2_error_loop    \n" \
671                                         " mov.a %a15, 4                                                 \n" \
672                                         " jne.a %a15, %a12, _task2_error_loop   \n" \
673                                         " mov.a %a15, 3                                                 \n" \
674                                         " jne.a %a15, %a13, _task2_error_loop   \n" \
675                                         " mov.a %a15, 2                                                 \n" \
676                                         " jne.a %a15, %a14, _task2_error_loop   \n" \
677                                         " j _task2_skip_error_loop                              \n"     \
678                                         "_task2_error_loop:                                             \n"     /* Hitting this error loop will stop the counter incrementing, allowing the check task to recognise an error. */ \
679                                         " debug                                                                 \n" \
680                                         " j _task2_error_loop                                   \n"     \
681                                         "_task2_skip_error_loop:                                \n"     );
682
683         /* Load the parameter address from the stack and modify the value. */
684         __asm volatile( " ld.w %d1, [%sp]4                                              \n"     \
685                                         " add %d1, %d1, 1                                               \n"     \
686                                         " st.w [%sp]4, %d1                                              \n"     \
687                                         " ld.a %a15, [%sp]                                              \n"     \
688                                         " st.w [%a15], %d1                                              \n"     \
689                                         " j _task2_loop                                 \n"  );
690
691         /* The parameter is used but in the assembly. */
692         (void)pvParameters;
693 }
694
695 /*-----------------------------------------------------------*/
696