2 FreeRTOS V5.4.1 - Copyright (C) 2009 Real Time Engineers Ltd.
\r
4 This file is part of the FreeRTOS distribution.
\r
6 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
7 the terms of the GNU General Public License (version 2) as published by the
\r
8 Free Software Foundation and modified by the FreeRTOS exception.
\r
9 **NOTE** The exception to the GPL is included to allow you to distribute a
\r
10 combined work that includes FreeRTOS without being obliged to provide the
\r
11 source code for proprietary components outside of the FreeRTOS kernel.
\r
12 Alternative commercial license and support terms are also available upon
\r
13 request. See the licensing section of http://www.FreeRTOS.org for full
\r
16 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
21 You should have received a copy of the GNU General Public License along
\r
22 with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
\r
23 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
26 ***************************************************************************
\r
28 * Looking for a quick start? Then check out the FreeRTOS eBook! *
\r
29 * See http://www.FreeRTOS.org/Documentation for details *
\r
31 ***************************************************************************
\r
35 Please ensure to read the configuration and relevant port sections of the
\r
36 online documentation.
\r
38 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
41 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
44 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
45 licensing and training services.
\r
50 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
51 * documentation provides more details of the demo application tasks.
\r
53 * In addition to the standard demo tasks, the follow demo specific tasks are
\r
56 * The "Check" task. This only executes every three seconds but has the highest
\r
57 * priority so is guaranteed to get processor time. Its main function is to
\r
58 * check that all the other tasks are still operational. Most tasks maintain
\r
59 * a unique count that is incremented each time the task successfully completes
\r
60 * its function. Should any error occur within such a task the count is
\r
61 * permanently halted. The check task inspects the count of each task to ensure
\r
62 * it has changed since the last time the check task executed. If all the count
\r
63 * variables have changed all the tasks are still executing error free, and the
\r
64 * check task toggles the onboard LED. Should any task contain an error at any time
\r
65 * the LED toggle rate will change from 3 seconds to 500ms.
\r
67 * The "Register Check" tasks. These tasks fill the CPU registers with known
\r
68 * values, then check that each register still contains the expected value 0 the
\r
69 * discovery of an unexpected value being indicative of an error in the RTOS
\r
70 * context switch mechanism. The register check tasks operate at low priority
\r
71 * so are switched in and out frequently.
\r
73 * The "Trace Utility" task. This can be used to obtain trace and debug
\r
74 * information via UART5.
\r
78 /* Hardware specific includes. */
\r
79 #include "mb91467d.h"
\r
80 #include "vectors.h"
\r
81 #include "watchdog.h"
\r
83 /* Scheduler includes. */
\r
84 #include "FreeRTOS.h"
\r
87 /* Demo app includes. */
\r
89 #include "integer.h"
\r
90 #include "comtest2.h"
\r
91 #include "semtest.h"
\r
93 #include "dynamic.h"
\r
95 #include "GenQTest.h"
\r
97 #include "blocktim.h"
\r
99 #include "taskutility.h"
\r
100 #include "partest.h"
\r
101 #include "crflash.h"
\r
103 /* Demo task priorities. */
\r
104 #define mainWATCHDOG_TASK_PRIORITY ( tskIDLE_PRIORITY + 5 )
\r
105 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
106 #define mainUTILITY_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
107 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
108 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
109 #define mainQUEUE_BLOCK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
110 #define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
111 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
112 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
114 /* Baud rate used by the COM test tasks. */
\r
115 #define mainCOM_TEST_BAUD_RATE ( ( unsigned portLONG ) 19200 )
\r
117 /* The frequency at which the 'Check' tasks executes. See the comments at the
\r
118 top of the page. When the system is operating error free the 'Check' task
\r
119 toggles an LED every three seconds. If an error is discovered in any task the
\r
120 rate is increased to 500 milliseconds. [in this case the '*' characters on the
\r
121 LCD represent LEDs]*/
\r
122 #define mainNO_ERROR_CHECK_DELAY ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
123 #define mainERROR_CHECK_DELAY ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
125 /* The total number of LEDs available. */
\r
126 #define mainNO_CO_ROUTINE_LEDs ( 8 )
\r
128 /* The first LED used by the comtest tasks. */
\r
129 #define mainCOM_TEST_LED ( 0x05 )
\r
131 /* The LED used by the check task. */
\r
132 #define mainCHECK_TEST_LED ( 0x07 )
\r
134 /* The number of interrupt levels to use. */
\r
135 #define mainINTERRUPT_LEVELS ( 31 )
\r
137 /* The number of 'flash' co-routines to create - each toggles a different LED. */
\r
138 #define mainNUM_FLASH_CO_ROUTINES ( 8 )
\r
140 /*---------------------------------------------------------------------------*/
\r
143 * The function that implements the Check task. See the comments at the head
\r
144 * of the page for implementation details.
\r
146 static void prvErrorChecks( void *pvParameters );
\r
149 * Called by the Check task. Returns pdPASS if all the other tasks are found
\r
150 * to be operating without error - otherwise returns pdFAIL.
\r
152 static portSHORT prvCheckOtherTasksAreStillRunning( void );
\r
155 * Setup the microcontroller as used by this demo.
\r
157 static void prvSetupHardware( void );
\r
160 * Tasks that test the context switch mechanism by filling the CPU registers
\r
161 * with known values then checking that each register contains the value
\r
162 * expected. Each of the two tasks use different values, and as low priority
\r
163 * tasks, get swapped in and out regularly.
\r
165 static void vFirstRegisterTestTask( void *pvParameters );
\r
166 static void vSecondRegisterTestTask( void *pvParameters );
\r
168 /*---------------------------------------------------------------------------*/
\r
170 /* The variable that is set to true should an error be found in one of the
\r
171 register test tasks. */
\r
172 unsigned portLONG ulRegTestError = pdFALSE;
\r
174 /*---------------------------------------------------------------------------*/
\r
176 /* Start all the demo application tasks, then start the scheduler. */
\r
179 /* Initialise the hardware ready for the demo. */
\r
180 prvSetupHardware();
\r
182 /* Start the standard demo application tasks. */
\r
183 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
184 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
185 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );
\r
186 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
187 vStartBlockingQueueTasks ( mainQUEUE_BLOCK_PRIORITY );
\r
188 vStartDynamicPriorityTasks();
\r
189 vStartMathTasks( tskIDLE_PRIORITY );
\r
190 vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
\r
191 vStartQueuePeekTasks();
\r
192 vCreateBlockTimeTasks();
\r
193 vStartFlashCoRoutines( mainNUM_FLASH_CO_ROUTINES );
\r
195 /* Start the 'Check' task which is defined in this file. */
\r
196 xTaskCreate( prvErrorChecks, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
198 /* Start the 'Register Test' tasks as described at the top of this file. */
\r
199 xTaskCreate( vFirstRegisterTestTask, ( signed portCHAR * ) "Reg1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
200 xTaskCreate( vSecondRegisterTestTask, ( signed portCHAR * ) "Reg2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
202 /* Start the task that write trace information to the UART. */
\r
203 vUtilityStartTraceTask( mainUTILITY_TASK_PRIORITY );
\r
205 /* If we are going to service the watchdog from within a task, then create
\r
207 #if WATCHDOG == WTC_IN_TASK
\r
208 vStartWatchdogTask( mainWATCHDOG_TASK_PRIORITY );
\r
211 /* The suicide tasks must be started last as they record the number of other
\r
212 tasks that exist within the system. The value is then used to ensure at run
\r
213 time the number of tasks that exists is within expected bounds. */
\r
214 vCreateSuicidalTasks( mainDEATH_PRIORITY );
\r
216 /* Now start the scheduler. Following this call the created tasks should
\r
218 vTaskStartScheduler( );
\r
220 /* vTaskStartScheduler() will only return if an error occurs while the
\r
221 idle task is being created. */
\r
224 /*-----------------------------------------------------------*/
\r
226 static void prvErrorChecks( void *pvParameters )
\r
228 portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY, xLastExecutionTime;
\r
230 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
231 works correctly. */
\r
232 xLastExecutionTime = xTaskGetTickCount();
\r
234 /* Cycle for ever, delaying then checking all the other tasks are still
\r
235 operating without error. */
\r
238 /* Wait until it is time to check again. The time we wait here depends
\r
239 on whether an error has been detected or not. When an error is
\r
240 detected the time is shortened resulting in a faster LED flash rate. */
\r
241 /* Perform this check every mainCHECK_DELAY milliseconds. */
\r
242 vTaskDelayUntil( &xLastExecutionTime, xDelayPeriod );
\r
244 /* See if the other tasks are all ok. */
\r
245 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
247 /* An error occurred in one of the tasks so shorten the delay
\r
248 period - which has the effect of increasing the frequency of the
\r
250 xDelayPeriod = mainERROR_CHECK_DELAY;
\r
254 vParTestToggleLED( mainCHECK_TEST_LED );
\r
257 /*-----------------------------------------------------------*/
\r
259 static portSHORT prvCheckOtherTasksAreStillRunning( void )
\r
261 portBASE_TYPE lReturn = pdPASS;
\r
263 /* The demo tasks maintain a count that increments every cycle of the task
\r
264 provided that the task has never encountered an error. This function
\r
265 checks the counts maintained by the tasks to ensure they are still being
\r
266 incremented. A count remaining at the same value between calls therefore
\r
267 indicates that an error has been detected. */
\r
269 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
274 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
279 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
284 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
289 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
294 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
299 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
304 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
309 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
314 if ( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
319 /* Have the register test tasks found any errors? */
\r
320 if( ulRegTestError != pdFALSE )
\r
327 /*-----------------------------------------------------------*/
\r
329 static void prvSetupHardware( void )
\r
331 /* Allow all interrupt levels. */
\r
332 __set_il( mainINTERRUPT_LEVELS );
\r
334 /* Initialise interrupts. */
\r
337 /* Initialise the ports used by the LEDs. */
\r
338 vParTestInitialise();
\r
340 /* If we are going to use the watchdog, then initialise it now. */
\r
341 #if WATCHDOG != WTC_NONE
\r
345 /*-----------------------------------------------------------*/
\r
347 /* Idle hook function. */
\r
348 #if configUSE_IDLE_HOOK == 1
\r
349 void vApplicationIdleHook( void )
\r
351 /* Are we using the idle task to kick the watchdog? See watchdog.h
\r
352 for watchdog kicking options. Note this is for demonstration only
\r
353 and is not a suggested method of servicing the watchdog in a real
\r
355 #if WATCHDOG == WTC_IN_IDLE
\r
359 vCoRoutineSchedule();
\r
362 #if WATCHDOG == WTC_IN_IDLE
\r
363 #error configUSE_IDLE_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the idle task hook.
\r
367 /*-----------------------------------------------------------*/
\r
369 /* Tick hook function. */
\r
370 #if configUSE_TICK_HOOK == 1
\r
371 void vApplicationTickHook( void )
\r
373 /* Are we using the tick to kick the watchdog? See watchdog.h
\r
374 for watchdog kicking options. Note this is for demonstration
\r
375 only and is not a suggested method of servicing the watchdog in
\r
376 a real application. */
\r
377 #if WATCHDOG == WTC_IN_TICK
\r
382 #if WATCHDOG == WTC_IN_TICK
\r
383 #error configUSE_TICK_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the tick hook.
\r
386 /*-----------------------------------------------------------*/
\r
388 static void vFirstRegisterTestTask( void *pvParameters )
\r
390 extern volatile unsigned portLONG ulCriticalNesting;
\r
392 /* Fills the registers with known values (different to the values
\r
393 used in vSecondRegisterTestTask()), then checks that the registers still
\r
394 all contain the expected value. This is done to test the context save
\r
395 and restore mechanism as this task is swapped onto and off of the CPU. */
\r
400 ;Load known values into each register.
\r
401 LDI #0x11111111, R0
\r
402 LDI #0x22222222, R1
\r
403 LDI #0x33333333, R2
\r
404 LDI #0x44444444, R3
\r
405 LDI #0x55555555, R4
\r
406 LDI #0x66666666, R5
\r
407 LDI #0x77777777, R6
\r
408 LDI #0x88888888, R7
\r
409 LDI #0x99999999, R8
\r
410 LDI #0xaaaaaaaa, R9
\r
411 LDI #0xbbbbbbbb, R10
\r
412 LDI #0xcccccccc, R11
\r
413 LDI #0xdddddddd, R12
\r
415 ;Check each register still contains the expected value.
\r
416 LDI #0x11111111, R13
\r
418 BNE First_Set_Error
\r
420 LDI #0x22222222, R13
\r
422 BNE First_Set_Error
\r
424 LDI #0x33333333, R13
\r
426 BNE First_Set_Error
\r
428 LDI #0x44444444, R13
\r
430 BNE First_Set_Error
\r
432 LDI #0x55555555, R13
\r
434 BNE First_Set_Error
\r
436 LDI #0x66666666, R13
\r
438 BNE First_Set_Error
\r
440 LDI #0x77777777, R13
\r
442 BNE First_Set_Error
\r
444 LDI #0x88888888, R13
\r
446 BNE First_Set_Error
\r
448 LDI #0x99999999, R13
\r
450 BNE First_Set_Error
\r
452 LDI #0xaaaaaaaa, R13
\r
454 BNE First_Set_Error
\r
456 LDI #0xbbbbbbbb, R13
\r
458 BNE First_Set_Error
\r
460 LDI #0xcccccccc, R13
\r
462 BNE First_Set_Error
\r
464 LDI #0xdddddddd, R13
\r
466 BNE First_Set_Error
\r
468 BRA First_Start_Next_Loop
\r
472 ; Latch that an error has occurred.
\r
473 LDI #_ulRegTestError, R0
\r
474 LDI #0x00000001, R1
\r
478 First_Start_Next_Loop:
\r
484 /*-----------------------------------------------------------*/
\r
486 static void vSecondRegisterTestTask( void *pvParameters )
\r
488 extern volatile unsigned portLONG ulCriticalNesting;
\r
490 /* Fills the registers with known values (different to the values
\r
491 used in vFirstRegisterTestTask()), then checks that the registers still
\r
492 all contain the expected value. This is done to test the context save
\r
493 and restore mechanism as this task is swapped onto and off of the CPU. */
\r
498 ;Load known values into each register.
\r
499 LDI #0x11111111, R1
\r
500 LDI #0x22222222, R2
\r
502 LDI #0x33333333, R3
\r
503 LDI #0x44444444, R4
\r
504 LDI #0x55555555, R5
\r
505 LDI #0x66666666, R6
\r
506 LDI #0x77777777, R7
\r
507 LDI #0x88888888, R8
\r
508 LDI #0x99999999, R9
\r
510 LDI #0xaaaaaaaa, R10
\r
511 LDI #0xbbbbbbbb, R11
\r
512 LDI #0xcccccccc, R12
\r
513 LDI #0xdddddddd, R0
\r
515 ;Check each register still contains the expected value.
\r
516 LDI #0x11111111, R13
\r
518 BNE Second_Set_Error
\r
520 LDI #0x22222222, R13
\r
522 BNE Second_Set_Error
\r
524 LDI #0x33333333, R13
\r
526 BNE Second_Set_Error
\r
528 LDI #0x44444444, R13
\r
530 BNE Second_Set_Error
\r
532 LDI #0x55555555, R13
\r
534 BNE Second_Set_Error
\r
538 LDI #0x66666666, R13
\r
540 BNE Second_Set_Error
\r
542 LDI #0x77777777, R13
\r
544 BNE Second_Set_Error
\r
546 LDI #0x88888888, R13
\r
548 BNE Second_Set_Error
\r
550 LDI #0x99999999, R13
\r
552 BNE Second_Set_Error
\r
556 LDI #0xaaaaaaaa, R13
\r
558 BNE Second_Set_Error
\r
560 LDI #0xbbbbbbbb, R13
\r
562 BNE Second_Set_Error
\r
564 LDI #0xcccccccc, R13
\r
566 BNE Second_Set_Error
\r
568 LDI #0xdddddddd, R13
\r
570 BNE Second_Set_Error
\r
572 BRA Second_Start_Next_Loop
\r
576 ; Latch that an error has occurred.
\r
577 LDI #_ulRegTestError, R0
\r
578 LDI #0x00000001, R1
\r
582 Second_Start_Next_Loop:
\r
588 /*-----------------------------------------------------------*/
\r