2 FreeRTOS V7.5.3 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\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
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
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\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
27 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
28 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
29 >>! the source code for proprietary components outside of the FreeRTOS
\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
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\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
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
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
68 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
69 * documentation provides more details of the demo application tasks.
\r
71 * In addition to the standard demo tasks, the follow demo specific tasks are
\r
74 * The "Check" task. This only executes every three seconds but has the highest
\r
75 * priority so is guaranteed to get processor time. Its main function is to
\r
76 * check that all the other tasks are still operational. Most tasks maintain
\r
77 * a unique count that is incremented each time the task successfully completes
\r
78 * its function. Should any error occur within such a task the count is
\r
79 * permanently halted. The check task inspects the count of each task to ensure
\r
80 * it has changed since the last time the check task executed. If all the count
\r
81 * variables have changed all the tasks are still executing error free, and the
\r
82 * check task toggles the onboard LED. Should any task contain an error at any time
\r
83 * the LED toggle rate will change from 3 seconds to 500ms.
\r
85 * The "Register Check" tasks. These tasks fill the CPU registers with known
\r
86 * values, then check that each register still contains the expected value 0 the
\r
87 * discovery of an unexpected value being indicative of an error in the RTOS
\r
88 * context switch mechanism. The register check tasks operate at low priority
\r
89 * so are switched in and out frequently.
\r
91 * The "Trace Utility" task. This can be used to obtain trace and debug
\r
92 * information via UART5.
\r
96 /* Hardware specific includes. */
\r
97 #include "mb91467d.h"
\r
98 #include "vectors.h"
\r
99 #include "watchdog.h"
\r
101 /* Scheduler includes. */
\r
102 #include "FreeRTOS.h"
\r
105 /* Demo app includes. */
\r
107 #include "integer.h"
\r
108 #include "comtest2.h"
\r
109 #include "semtest.h"
\r
110 #include "BlockQ.h"
\r
111 #include "dynamic.h"
\r
113 #include "GenQTest.h"
\r
115 #include "blocktim.h"
\r
117 #include "taskutility.h"
\r
118 #include "partest.h"
\r
119 #include "crflash.h"
\r
121 /* Demo task priorities. */
\r
122 #define mainWATCHDOG_TASK_PRIORITY ( tskIDLE_PRIORITY + 5 )
\r
123 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
124 #define mainUTILITY_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
125 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
126 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
127 #define mainQUEUE_BLOCK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
128 #define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
129 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
130 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
132 /* Baud rate used by the COM test tasks. */
\r
133 #define mainCOM_TEST_BAUD_RATE ( ( unsigned portLONG ) 19200 )
\r
135 /* The frequency at which the 'Check' tasks executes. See the comments at the
\r
136 top of the page. When the system is operating error free the 'Check' task
\r
137 toggles an LED every three seconds. If an error is discovered in any task the
\r
138 rate is increased to 500 milliseconds. [in this case the '*' characters on the
\r
139 LCD represent LEDs]*/
\r
140 #define mainNO_ERROR_CHECK_DELAY ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
141 #define mainERROR_CHECK_DELAY ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
143 /* The total number of LEDs available. */
\r
144 #define mainNO_CO_ROUTINE_LEDs ( 8 )
\r
146 /* The first LED used by the comtest tasks. */
\r
147 #define mainCOM_TEST_LED ( 0x05 )
\r
149 /* The LED used by the check task. */
\r
150 #define mainCHECK_TEST_LED ( 0x07 )
\r
152 /* The number of interrupt levels to use. */
\r
153 #define mainINTERRUPT_LEVELS ( 31 )
\r
155 /* The number of 'flash' co-routines to create - each toggles a different LED. */
\r
156 #define mainNUM_FLASH_CO_ROUTINES ( 8 )
\r
158 /*---------------------------------------------------------------------------*/
\r
161 * The function that implements the Check task. See the comments at the head
\r
162 * of the page for implementation details.
\r
164 static void prvErrorChecks( void *pvParameters );
\r
167 * Called by the Check task. Returns pdPASS if all the other tasks are found
\r
168 * to be operating without error - otherwise returns pdFAIL.
\r
170 static portSHORT prvCheckOtherTasksAreStillRunning( void );
\r
173 * Setup the microcontroller as used by this demo.
\r
175 static void prvSetupHardware( void );
\r
178 * Tasks that test the context switch mechanism by filling the CPU registers
\r
179 * with known values then checking that each register contains the value
\r
180 * expected. Each of the two tasks use different values, and as low priority
\r
181 * tasks, get swapped in and out regularly.
\r
183 static void vFirstRegisterTestTask( void *pvParameters );
\r
184 static void vSecondRegisterTestTask( void *pvParameters );
\r
186 /*---------------------------------------------------------------------------*/
\r
188 /* The variable that is set to true should an error be found in one of the
\r
189 register test tasks. */
\r
190 unsigned portLONG ulRegTestError = pdFALSE;
\r
192 /*---------------------------------------------------------------------------*/
\r
194 /* Start all the demo application tasks, then start the scheduler. */
\r
197 /* Initialise the hardware ready for the demo. */
\r
198 prvSetupHardware();
\r
200 /* Start the standard demo application tasks. */
\r
201 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
202 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
203 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );
\r
204 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
205 vStartBlockingQueueTasks ( mainQUEUE_BLOCK_PRIORITY );
\r
206 vStartDynamicPriorityTasks();
\r
207 vStartMathTasks( tskIDLE_PRIORITY );
\r
208 vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
\r
209 vStartQueuePeekTasks();
\r
210 vCreateBlockTimeTasks();
\r
211 vStartFlashCoRoutines( mainNUM_FLASH_CO_ROUTINES );
\r
213 /* Start the 'Check' task which is defined in this file. */
\r
214 xTaskCreate( prvErrorChecks, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
216 /* Start the 'Register Test' tasks as described at the top of this file. */
\r
217 xTaskCreate( vFirstRegisterTestTask, ( signed portCHAR * ) "Reg1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
218 xTaskCreate( vSecondRegisterTestTask, ( signed portCHAR * ) "Reg2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
220 /* Start the task that write trace information to the UART. */
\r
221 vUtilityStartTraceTask( mainUTILITY_TASK_PRIORITY );
\r
223 /* If we are going to service the watchdog from within a task, then create
\r
225 #if WATCHDOG == WTC_IN_TASK
\r
226 vStartWatchdogTask( mainWATCHDOG_TASK_PRIORITY );
\r
229 /* The suicide tasks must be started last as they record the number of other
\r
230 tasks that exist within the system. The value is then used to ensure at run
\r
231 time the number of tasks that exists is within expected bounds. */
\r
232 vCreateSuicidalTasks( mainDEATH_PRIORITY );
\r
234 /* Now start the scheduler. Following this call the created tasks should
\r
236 vTaskStartScheduler( );
\r
238 /* vTaskStartScheduler() will only return if an error occurs while the
\r
239 idle task is being created. */
\r
242 /*-----------------------------------------------------------*/
\r
244 static void prvErrorChecks( void *pvParameters )
\r
246 portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY, xLastExecutionTime;
\r
248 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
249 works correctly. */
\r
250 xLastExecutionTime = xTaskGetTickCount();
\r
252 /* Cycle for ever, delaying then checking all the other tasks are still
\r
253 operating without error. */
\r
256 /* Wait until it is time to check again. The time we wait here depends
\r
257 on whether an error has been detected or not. When an error is
\r
258 detected the time is shortened resulting in a faster LED flash rate. */
\r
259 /* Perform this check every mainCHECK_DELAY milliseconds. */
\r
260 vTaskDelayUntil( &xLastExecutionTime, xDelayPeriod );
\r
262 /* See if the other tasks are all ok. */
\r
263 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
265 /* An error occurred in one of the tasks so shorten the delay
\r
266 period - which has the effect of increasing the frequency of the
\r
268 xDelayPeriod = mainERROR_CHECK_DELAY;
\r
272 vParTestToggleLED( mainCHECK_TEST_LED );
\r
275 /*-----------------------------------------------------------*/
\r
277 static portSHORT prvCheckOtherTasksAreStillRunning( void )
\r
279 portBASE_TYPE lReturn = pdPASS;
\r
281 /* The demo tasks maintain a count that increments every cycle of the task
\r
282 provided that the task has never encountered an error. This function
\r
283 checks the counts maintained by the tasks to ensure they are still being
\r
284 incremented. A count remaining at the same value between calls therefore
\r
285 indicates that an error has been detected. */
\r
287 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
292 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
297 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
302 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
307 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
312 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
317 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
322 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
327 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
332 if ( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
337 /* Have the register test tasks found any errors? */
\r
338 if( ulRegTestError != pdFALSE )
\r
345 /*-----------------------------------------------------------*/
\r
347 static void prvSetupHardware( void )
\r
349 /* Allow all interrupt levels. */
\r
350 __set_il( mainINTERRUPT_LEVELS );
\r
352 /* Initialise interrupts. */
\r
355 /* Initialise the ports used by the LEDs. */
\r
356 vParTestInitialise();
\r
358 /* If we are going to use the watchdog, then initialise it now. */
\r
359 #if WATCHDOG != WTC_NONE
\r
363 /*-----------------------------------------------------------*/
\r
365 /* Idle hook function. */
\r
366 #if configUSE_IDLE_HOOK == 1
\r
367 void vApplicationIdleHook( void )
\r
369 /* Are we using the idle task to kick the watchdog? See watchdog.h
\r
370 for watchdog kicking options. Note this is for demonstration only
\r
371 and is not a suggested method of servicing the watchdog in a real
\r
373 #if WATCHDOG == WTC_IN_IDLE
\r
377 vCoRoutineSchedule();
\r
380 #if WATCHDOG == WTC_IN_IDLE
\r
381 #error configUSE_IDLE_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the idle task hook.
\r
385 /*-----------------------------------------------------------*/
\r
387 /* Tick hook function. */
\r
388 #if configUSE_TICK_HOOK == 1
\r
389 void vApplicationTickHook( void )
\r
391 /* Are we using the tick to kick the watchdog? See watchdog.h
\r
392 for watchdog kicking options. Note this is for demonstration
\r
393 only and is not a suggested method of servicing the watchdog in
\r
394 a real application. */
\r
395 #if WATCHDOG == WTC_IN_TICK
\r
400 #if WATCHDOG == WTC_IN_TICK
\r
401 #error configUSE_TICK_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the tick hook.
\r
404 /*-----------------------------------------------------------*/
\r
406 static void vFirstRegisterTestTask( void *pvParameters )
\r
408 extern volatile unsigned portLONG ulCriticalNesting;
\r
410 /* Fills the registers with known values (different to the values
\r
411 used in vSecondRegisterTestTask()), then checks that the registers still
\r
412 all contain the expected value. This is done to test the context save
\r
413 and restore mechanism as this task is swapped onto and off of the CPU. */
\r
418 ;Load known values into each register.
\r
419 LDI #0x11111111, R0
\r
420 LDI #0x22222222, R1
\r
421 LDI #0x33333333, R2
\r
422 LDI #0x44444444, R3
\r
423 LDI #0x55555555, R4
\r
424 LDI #0x66666666, R5
\r
425 LDI #0x77777777, R6
\r
426 LDI #0x88888888, R7
\r
427 LDI #0x99999999, R8
\r
428 LDI #0xaaaaaaaa, R9
\r
429 LDI #0xbbbbbbbb, R10
\r
430 LDI #0xcccccccc, R11
\r
431 LDI #0xdddddddd, R12
\r
433 ;Check each register still contains the expected value.
\r
434 LDI #0x11111111, R13
\r
436 BNE First_Set_Error
\r
438 LDI #0x22222222, R13
\r
440 BNE First_Set_Error
\r
442 LDI #0x33333333, R13
\r
444 BNE First_Set_Error
\r
446 LDI #0x44444444, R13
\r
448 BNE First_Set_Error
\r
450 LDI #0x55555555, R13
\r
452 BNE First_Set_Error
\r
454 LDI #0x66666666, R13
\r
456 BNE First_Set_Error
\r
458 LDI #0x77777777, R13
\r
460 BNE First_Set_Error
\r
462 LDI #0x88888888, R13
\r
464 BNE First_Set_Error
\r
466 LDI #0x99999999, R13
\r
468 BNE First_Set_Error
\r
470 LDI #0xaaaaaaaa, R13
\r
472 BNE First_Set_Error
\r
474 LDI #0xbbbbbbbb, R13
\r
476 BNE First_Set_Error
\r
478 LDI #0xcccccccc, R13
\r
480 BNE First_Set_Error
\r
482 LDI #0xdddddddd, R13
\r
484 BNE First_Set_Error
\r
486 BRA First_Start_Next_Loop
\r
490 ; Latch that an error has occurred.
\r
491 LDI #_ulRegTestError, R0
\r
492 LDI #0x00000001, R1
\r
496 First_Start_Next_Loop:
\r
502 /*-----------------------------------------------------------*/
\r
504 static void vSecondRegisterTestTask( void *pvParameters )
\r
506 extern volatile unsigned portLONG ulCriticalNesting;
\r
508 /* Fills the registers with known values (different to the values
\r
509 used in vFirstRegisterTestTask()), then checks that the registers still
\r
510 all contain the expected value. This is done to test the context save
\r
511 and restore mechanism as this task is swapped onto and off of the CPU. */
\r
516 ;Load known values into each register.
\r
517 LDI #0x11111111, R1
\r
518 LDI #0x22222222, R2
\r
520 LDI #0x33333333, R3
\r
521 LDI #0x44444444, R4
\r
522 LDI #0x55555555, R5
\r
523 LDI #0x66666666, R6
\r
524 LDI #0x77777777, R7
\r
525 LDI #0x88888888, R8
\r
526 LDI #0x99999999, R9
\r
528 LDI #0xaaaaaaaa, R10
\r
529 LDI #0xbbbbbbbb, R11
\r
530 LDI #0xcccccccc, R12
\r
531 LDI #0xdddddddd, R0
\r
533 ;Check each register still contains the expected value.
\r
534 LDI #0x11111111, R13
\r
536 BNE Second_Set_Error
\r
538 LDI #0x22222222, R13
\r
540 BNE Second_Set_Error
\r
542 LDI #0x33333333, R13
\r
544 BNE Second_Set_Error
\r
546 LDI #0x44444444, R13
\r
548 BNE Second_Set_Error
\r
550 LDI #0x55555555, R13
\r
552 BNE Second_Set_Error
\r
556 LDI #0x66666666, R13
\r
558 BNE Second_Set_Error
\r
560 LDI #0x77777777, R13
\r
562 BNE Second_Set_Error
\r
564 LDI #0x88888888, R13
\r
566 BNE Second_Set_Error
\r
568 LDI #0x99999999, R13
\r
570 BNE Second_Set_Error
\r
574 LDI #0xaaaaaaaa, R13
\r
576 BNE Second_Set_Error
\r
578 LDI #0xbbbbbbbb, R13
\r
580 BNE Second_Set_Error
\r
582 LDI #0xcccccccc, R13
\r
584 BNE Second_Set_Error
\r
586 LDI #0xdddddddd, R13
\r
588 BNE Second_Set_Error
\r
590 BRA Second_Start_Next_Loop
\r
594 ; Latch that an error has occurred.
\r
595 LDI #_ulRegTestError, R0
\r
596 LDI #0x00000001, R1
\r
600 Second_Start_Next_Loop:
\r
606 /*-----------------------------------------------------------*/
\r