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