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