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