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