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