2 FreeRTOS.org V5.0.0 - Copyright (C) 2003-2008 Richard Barry.
4 This file is part of the FreeRTOS.org distribution.
6 FreeRTOS.org is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 FreeRTOS.org is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with FreeRTOS.org; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 A special exception to the GPL can be applied should you wish to distribute
21 a combined work that includes FreeRTOS.org, without being obliged to provide
22 the source code for any proprietary components. See the licensing section
23 of http://www.FreeRTOS.org for full details of how and when the exception
26 ***************************************************************************
27 ***************************************************************************
29 * SAVE TIME AND MONEY! We can port FreeRTOS.org to your own hardware, *
30 * and even write all or part of your application on your behalf. *
31 * See http://www.OpenRTOS.com for details of the services we provide to *
32 * expedite your project. *
34 ***************************************************************************
35 ***************************************************************************
37 Please ensure to read the configuration and relevant port sections of the
40 http://www.FreeRTOS.org - Documentation, latest information, license and
43 http://www.SafeRTOS.com - A version that is certified for use in safety
46 http://www.OpenRTOS.com - Commercial support, development, porting,
47 licensing and training services.
51 * Creates all the demo application tasks, then starts the scheduler. The WEB
52 * documentation provides more details of the demo application tasks.
54 * In addition to the standard demo tasks, the follow demo specific tasks are
57 * The "Check" task. This only executes every three seconds but has the highest
58 * priority so is guaranteed to get processor time. Its main function is to
59 * check that all the other tasks are still operational. Most tasks maintain
60 * a unique count that is incremented each time the task successfully completes
61 * its function. Should any error occur within such a task the count is
62 * permanently halted. The check task inspects the count of each task to ensure
63 * it has changed since the last time the check task executed. If all the count
64 * variables have changed all the tasks are still executing error free, and the
65 * check task toggles the onboard LED. Should any task contain an error at any time
66 * the LED toggle rate will change from 3 seconds to 500ms.
68 * The "Register Check" tasks. These tasks fill the CPU registers with known
69 * values, then check that each register still contains the expected value, the
70 * discovery of an unexpected value being indicative of an error in the RTOS
71 * context switch mechanism. The register check tasks operate at low priority
72 * so are switched in and out frequently.
76 /* Scheduler includes. */
80 /* Xilinx library includes. */
84 /* Demo application includes. */
99 #include "flop-reg-test.h"
101 /* Priorities assigned to the demo tasks. */
102 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
103 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
104 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
105 #define mainQUEUE_BLOCK_PRIORITY ( tskIDLE_PRIORITY + 1 )
106 #define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 1 )
107 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
108 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
109 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 )
110 #define mainFLOP_PRIORITY ( tskIDLE_PRIORITY )
112 /* The first LED used by the COM test and check tasks respectively. */
113 #define mainCOM_TEST_LED ( 4 )
114 #define mainCHECK_TEST_LED ( 3 )
116 /* The baud rate used by the comtest tasks is set by the hardware, so the
117 baud rate parameters passed into the comtest initialisation has no effect. */
118 #define mainBAUD_SET_IN_HARDWARE ( 0 )
120 /* Delay periods used by the check task. If no errors have been found then
121 the check LED will toggle every mainNO_ERROR_CHECK_DELAY milliseconds. If an
122 error has been found at any time then the toggle rate will increase to
123 mainERROR_CHECK_DELAY milliseconds. */
124 #define mainNO_ERROR_CHECK_DELAY ( ( portTickType ) 3000 / portTICK_RATE_MS )
125 #define mainERROR_CHECK_DELAY ( ( portTickType ) 500 / portTICK_RATE_MS )
129 * The tasks defined within this file - described within the comments at the
132 static void prvRegTestTask1( void *pvParameters );
133 static void prvRegTestTask2( void *pvParameters );
134 static void prvErrorChecks( void *pvParameters );
137 * Called by the 'check' task to inspect all the standard demo tasks within
138 * the system, as described within the comments at the head of this page.
140 static portBASE_TYPE prvCheckOtherTasksAreStillRunning( void );
143 * Perform any hardware initialisation required by the demo application.
145 static void prvSetupHardware( void );
147 /*-----------------------------------------------------------*/
149 /* xRegTestStatus will get set to pdFAIL by the regtest tasks if they
150 discover an unexpected value. */
151 static volatile unsigned portBASE_TYPE xRegTestStatus = pdPASS;
153 /* Counters used to ensure the regtest tasks are still running. */
154 static volatile unsigned portLONG ulRegTest1Counter = 0UL, ulRegTest2Counter = 0UL;
156 /*-----------------------------------------------------------*/
161 /* Must be called prior to installing any interrupt handlers! */
162 vPortSetupInterruptController();
164 /* In this case prvSetupHardware() just enables the caches and and
165 configures the IO ports for the LED outputs. */
168 /* Start the standard demo application tasks. Note that the baud rate used
169 by the comtest tasks is set by the hardware, so the baud rate parameter
170 passed has no effect. */
171 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
172 vStartIntegerMathTasks( tskIDLE_PRIORITY );
173 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainBAUD_SET_IN_HARDWARE, mainCOM_TEST_LED );
174 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
175 vStartBlockingQueueTasks ( mainQUEUE_BLOCK_PRIORITY );
176 vStartDynamicPriorityTasks();
177 vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
178 vStartQueuePeekTasks();
179 vCreateBlockTimeTasks();
180 vStartCountingSemaphoreTasks();
181 vStartRecursiveMutexTasks();
183 #if ( configUSE_FPU == 1 )
\r
185 /* A different project is provided that has configUSE_FPU set to 1
\r
186 in order to demonstrate all the settings required to use the floating
\r
187 point unit. If you wish to use the floating point unit do not start
\r
188 with this project. */
189 vStartMathTasks( mainFLOP_PRIORITY );
190 vStartFlopRegTests();
\r
194 /* Create the tasks defined within this file. */
195 xTaskCreate( prvRegTestTask1, ( signed portCHAR * ) "Regtest1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
196 xTaskCreate( prvRegTestTask2, ( signed portCHAR * ) "Regtest2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
197 xTaskCreate( prvErrorChecks, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
199 /* The suicide tasks must be started last as they record the number of other
200 tasks that exist within the system. The value is then used to ensure at run
201 time the number of tasks that exists is within expected bounds. */
202 vCreateSuicidalTasks( mainDEATH_PRIORITY );
204 /* Now start the scheduler. Following this call the created tasks should
206 vTaskStartScheduler();
208 /* vTaskStartScheduler() will only return if an error occurs while the
209 idle task is being created. */
214 /*-----------------------------------------------------------*/
216 static portBASE_TYPE prvCheckOtherTasksAreStillRunning( void )
218 portBASE_TYPE lReturn = pdPASS;
219 static unsigned portLONG ulLastRegTest1Counter= 0UL, ulLastRegTest2Counter = 0UL;
221 /* The demo tasks maintain a count that increments every cycle of the task
222 provided that the task has never encountered an error. This function
223 checks the counts maintained by the tasks to ensure they are still being
224 incremented. A count remaining at the same value between calls therefore
225 indicates that an error has been detected. */
227 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
232 if( xAreComTestTasksStillRunning() != pdTRUE )
237 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
242 if( xAreBlockingQueuesStillRunning() != pdTRUE )
247 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
252 if( xIsCreateTaskStillRunning() != pdTRUE )
257 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
262 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
267 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
272 if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
277 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
282 #if ( configUSE_FPU == 1 )
283 if( xAreMathsTaskStillRunning() != pdTRUE )
288 if( xAreFlopRegisterTestsStillRunning() != pdTRUE )
294 /* Have the register test tasks found any errors? */
295 if( xRegTestStatus != pdPASS )
300 /* Are the register test tasks still looping? */
301 if( ulLastRegTest1Counter == ulRegTest1Counter )
307 ulLastRegTest1Counter = ulRegTest1Counter;
310 if( ulLastRegTest2Counter == ulRegTest2Counter )
316 ulLastRegTest2Counter = ulRegTest2Counter;
321 /*-----------------------------------------------------------*/
323 static void prvErrorChecks( void *pvParameters )
325 portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY, xLastExecutionTime;
326 volatile unsigned portBASE_TYPE uxFreeStack;
328 /* Just to remove compiler warning. */
329 ( void ) pvParameters;
331 /* This call is just to demonstrate the use of the function - nothing is
332 done with the value. You would expect the stack high water mark to be
333 lower (the function to return a larger value) here at function entry than
334 later following calls to other functions. */
335 uxFreeStack = uxTaskGetStackHighWaterMark( NULL );
337 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
339 xLastExecutionTime = xTaskGetTickCount();
341 /* Cycle for ever, delaying then checking all the other tasks are still
342 operating without error. */
345 /* Again just for demo purposes - uxFreeStack should have a lower value
346 here than following the call to uxTaskGetStackHighWaterMark() on the
348 uxFreeStack = uxTaskGetStackHighWaterMark( NULL );
350 /* Wait until it is time to check again. The time we wait here depends
351 on whether an error has been detected or not. When an error is
352 detected the time is shortened resulting in a faster LED flash rate. */
353 vTaskDelayUntil( &xLastExecutionTime, xDelayPeriod );
355 /* See if the other tasks are all ok. */
356 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
358 /* An error occurred in one of the tasks so shorten the delay
359 period - which has the effect of increasing the frequency of the
361 xDelayPeriod = mainERROR_CHECK_DELAY;
365 vParTestToggleLED( mainCHECK_TEST_LED );
368 /*-----------------------------------------------------------*/
370 static void prvSetupHardware( void )
372 XCache_EnableICache( 0x80000000 );
373 XCache_EnableDCache( 0x80000000 );
375 /* Setup the IO port for use with the LED outputs. */
376 vParTestInitialise();
378 /*-----------------------------------------------------------*/
380 void prvRegTest1Pass( void )
382 /* Called from the inline assembler - this cannot be static
383 otherwise it can get optimised away. */
386 /*-----------------------------------------------------------*/
388 void prvRegTest2Pass( void )
390 /* Called from the inline assembler - this cannot be static
391 otherwise it can get optimised away. */
394 /*-----------------------------------------------------------*/
396 void prvRegTestFail( void )
398 /* Called from the inline assembler - this cannot be static
399 otherwise it can get optimised away. */
400 xRegTestStatus = pdFAIL;
402 /*-----------------------------------------------------------*/
404 static void prvRegTestTask1( void *pvParameters )
406 /* Just to remove compiler warning. */
407 ( void ) pvParameters;
409 /* The first register test task as described at the top of this file. The
410 values used in the registers are different to those use in the second
411 register test task. Also, unlike the second register test task, this task
412 yields between setting the register values and subsequently checking the
416 "RegTest1Start: \n\t" \
419 " mtspr 256, 0 #USPRG0 \n\t" \
421 " mtspr 8, 0 #LR \n\t" \
423 " mtspr 1, 0 #XER \n\t" \
461 " bne RegTest1Fail \n\t" \
463 " bne RegTest1Fail \n\t" \
465 " bne RegTest1Fail \n\t" \
467 " bne RegTest1Fail \n\t" \
469 " bne RegTest1Fail \n\t" \
471 " bne RegTest1Fail \n\t" \
473 " bne RegTest1Fail \n\t" \
475 " bne RegTest1Fail \n\t" \
477 " bne RegTest1Fail \n\t" \
478 " cmpwi 10, 10 \n\t" \
479 " bne RegTest1Fail \n\t" \
480 " cmpwi 11, 11 \n\t" \
481 " bne RegTest1Fail \n\t" \
482 " cmpwi 12, 12 \n\t" \
483 " bne RegTest1Fail \n\t" \
484 " cmpwi 13, 13 \n\t" \
485 " bne RegTest1Fail \n\t" \
486 " cmpwi 14, 14 \n\t" \
487 " bne RegTest1Fail \n\t" \
488 " cmpwi 15, 15 \n\t" \
489 " bne RegTest1Fail \n\t" \
490 " cmpwi 16, 16 \n\t" \
491 " bne RegTest1Fail \n\t" \
492 " cmpwi 17, 17 \n\t" \
493 " bne RegTest1Fail \n\t" \
494 " cmpwi 18, 18 \n\t" \
495 " bne RegTest1Fail \n\t" \
496 " cmpwi 19, 19 \n\t" \
497 " bne RegTest1Fail \n\t" \
498 " cmpwi 20, 20 \n\t" \
499 " bne RegTest1Fail \n\t" \
500 " cmpwi 21, 21 \n\t" \
501 " bne RegTest1Fail \n\t" \
502 " cmpwi 22, 22 \n\t" \
503 " bne RegTest1Fail \n\t" \
504 " cmpwi 23, 23 \n\t" \
505 " bne RegTest1Fail \n\t" \
506 " cmpwi 24, 24 \n\t" \
507 " bne RegTest1Fail \n\t" \
508 " cmpwi 25, 25 \n\t" \
509 " bne RegTest1Fail \n\t" \
510 " cmpwi 26, 26 \n\t" \
511 " bne RegTest1Fail \n\t" \
512 " cmpwi 27, 27 \n\t" \
513 " bne RegTest1Fail \n\t" \
514 " cmpwi 28, 28 \n\t" \
515 " bne RegTest1Fail \n\t" \
516 " cmpwi 29, 29 \n\t" \
517 " bne RegTest1Fail \n\t" \
518 " cmpwi 30, 30 \n\t" \
519 " bne RegTest1Fail \n\t" \
520 " cmpwi 31, 31 \n\t" \
521 " bne RegTest1Fail \n\t" \
523 " mfspr 0, 256 #USPRG0 \n\t" \
524 " cmpwi 0, 301 \n\t" \
525 " bne RegTest1Fail \n\t" \
526 " mfspr 0, 8 #LR \n\t" \
527 " cmpwi 0, 501 \n\t" \
528 " bne RegTest1Fail \n\t" \
529 " mfspr 0, 1 #XER \n\t" \
531 " bne RegTest1Fail \n\t" \
533 " bl prvRegTest1Pass \n\t" \
534 " b RegTest1Start \n\t" \
536 "RegTest1Fail: \n\t" \
539 " bl prvRegTestFail \n\t" \
540 " b RegTest1Start \n\t" \
543 /*-----------------------------------------------------------*/
545 static void prvRegTestTask2( void *pvParameters )
547 /* Just to remove compiler warning. */
548 ( void ) pvParameters;
550 /* The second register test task as described at the top of this file.
551 Note that this task fills the registers with different values to the
552 first register test task. */
555 "RegTest2Start: \n\t" \
558 " mtspr 256, 0 #USPRG0 \n\t" \
560 " mtspr 8, 0 #LR \n\t" \
562 " mtspr 1, 0 #XER \n\t" \
596 " cmpwi 0, 11 \n\t" \
597 " bne RegTest2Fail \n\t" \
598 " cmpwi 2, 12 \n\t" \
599 " bne RegTest2Fail \n\t" \
600 " cmpwi 3, 13 \n\t" \
601 " bne RegTest2Fail \n\t" \
602 " cmpwi 4, 14 \n\t" \
603 " bne RegTest2Fail \n\t" \
604 " cmpwi 5, 15 \n\t" \
605 " bne RegTest2Fail \n\t" \
606 " cmpwi 6, 16 \n\t" \
607 " bne RegTest2Fail \n\t" \
608 " cmpwi 7, 17 \n\t" \
609 " bne RegTest2Fail \n\t" \
610 " cmpwi 8, 18 \n\t" \
611 " bne RegTest2Fail \n\t" \
612 " cmpwi 9, 19 \n\t" \
613 " bne RegTest2Fail \n\t" \
614 " cmpwi 10, 110 \n\t" \
615 " bne RegTest2Fail \n\t" \
616 " cmpwi 11, 111 \n\t" \
617 " bne RegTest2Fail \n\t" \
618 " cmpwi 12, 112 \n\t" \
619 " bne RegTest2Fail \n\t" \
620 " cmpwi 13, 113 \n\t" \
621 " bne RegTest2Fail \n\t" \
622 " cmpwi 14, 114 \n\t" \
623 " bne RegTest2Fail \n\t" \
624 " cmpwi 15, 115 \n\t" \
625 " bne RegTest2Fail \n\t" \
626 " cmpwi 16, 116 \n\t" \
627 " bne RegTest2Fail \n\t" \
628 " cmpwi 17, 117 \n\t" \
629 " bne RegTest2Fail \n\t" \
630 " cmpwi 18, 118 \n\t" \
631 " bne RegTest2Fail \n\t" \
632 " cmpwi 19, 119 \n\t" \
633 " bne RegTest2Fail \n\t" \
634 " cmpwi 20, 120 \n\t" \
635 " bne RegTest2Fail \n\t" \
636 " cmpwi 21, 121 \n\t" \
637 " bne RegTest2Fail \n\t" \
638 " cmpwi 22, 122 \n\t" \
639 " bne RegTest2Fail \n\t" \
640 " cmpwi 23, 123 \n\t" \
641 " bne RegTest2Fail \n\t" \
642 " cmpwi 24, 124 \n\t" \
643 " bne RegTest2Fail \n\t" \
644 " cmpwi 25, 125 \n\t" \
645 " bne RegTest2Fail \n\t" \
646 " cmpwi 26, 126 \n\t" \
647 " bne RegTest2Fail \n\t" \
648 " cmpwi 27, 127 \n\t" \
649 " bne RegTest2Fail \n\t" \
650 " cmpwi 28, 128 \n\t" \
651 " bne RegTest2Fail \n\t" \
652 " cmpwi 29, 129 \n\t" \
653 " bne RegTest2Fail \n\t" \
654 " cmpwi 30, 130 \n\t" \
655 " bne RegTest2Fail \n\t" \
656 " cmpwi 31, 131 \n\t" \
657 " bne RegTest2Fail \n\t" \
659 " mfspr 0, 256 #USPRG0 \n\t" \
660 " cmpwi 0, 300 \n\t" \
661 " bne RegTest2Fail \n\t" \
662 " mfspr 0, 8 #LR \n\t" \
663 " cmpwi 0, 500 \n\t" \
664 " bne RegTest2Fail \n\t" \
665 " mfspr 0, 1 #XER \n\t" \
667 " bne RegTest2Fail \n\t" \
669 " bl prvRegTest2Pass \n\t" \
670 " b RegTest2Start \n\t" \
672 "RegTest2Fail: \n\t" \
675 " bl prvRegTestFail \n\t" \
676 " b RegTest2Start \n\t" \
679 /*-----------------------------------------------------------*/
681 /* This hook function will get called if there is a suspected stack overflow.
682 An overflow can cause the task name to be corrupted, in which case the task
683 handle needs to be used to determine the offending task. */
684 void vApplicationStackOverflowHook( xTaskHandle xTask, signed portCHAR *pcTaskName );
685 void vApplicationStackOverflowHook( xTaskHandle xTask, signed portCHAR *pcTaskName )
687 /* To prevent the optimiser removing the variables. */
688 volatile xTaskHandle xTaskIn = xTask;
689 volatile signed portCHAR *pcTaskNameIn = pcTaskName;
691 /* Remove compiler warnings. */
\r
693 ( void ) pcTaskNameIn;
\r
695 /* The following three calls are simply to stop compiler warnings about the
696 functions not being used - they are called from the inline assembly. */