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