2 FreeRTOS.org V5.0.0 - Copyright (C) 2003-2008 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
27 ***************************************************************************
\r
29 * SAVE TIME AND MONEY! We can port FreeRTOS.org to your own hardware, *
\r
30 * and even write all or part of your application on your behalf. *
\r
31 * See http://www.OpenRTOS.com for details of the services we provide to *
\r
32 * expedite your project. *
\r
34 ***************************************************************************
\r
35 ***************************************************************************
\r
37 Please ensure to read the configuration and relevant port sections of the
\r
38 online documentation.
\r
40 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
43 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
46 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
47 licensing and training services.
\r
52 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
53 * documentation provides more details of the demo application tasks.
\r
55 * In addition to the standard demo tasks, the follow demo specific tasks are
\r
58 * The "Check" task. This only executes every three seconds but has the highest
\r
59 * priority so is guaranteed to get processor time. Its main function is to
\r
60 * check that all the other tasks are still operational. Most tasks maintain
\r
61 * a unique count that is incremented each time the task successfully completes
\r
62 * its function. Should any error occur within such a task the count is
\r
63 * permanently halted. The check task inspects the count of each task to ensure
\r
64 * it has changed since the last time the check task executed. If all the count
\r
65 * variables have changed all the tasks are still executing error free, and the
\r
66 * check task toggles the onboard LED. Should any task contain an error at any time
\r
67 * the LED toggle rate will change from 3 seconds to 500ms.
\r
69 * The "Register Check" tasks. These tasks fill the CPU registers with known
\r
70 * values, then check that each register still contains the expected value 0 the
\r
71 * discovery of an unexpected value being indicative of an error in the RTOS
\r
72 * context switch mechanism. The register check tasks operate at low priority
\r
73 * so are switched in and out frequently.
\r
75 * The "Trace Utility" task. This can be used to obtain trace and debug
\r
76 * information via UART5.
\r
80 /* Hardware specific includes. */
\r
81 #include "mb91467d.h"
\r
82 #include "vectors.h"
\r
83 #include "watchdog.h"
\r
85 /* Scheduler includes. */
\r
86 #include "FreeRTOS.h"
\r
89 /* Demo app includes. */
\r
91 #include "integer.h"
\r
92 #include "comtest2.h"
\r
93 #include "semtest.h"
\r
95 #include "dynamic.h"
\r
97 #include "GenQTest.h"
\r
99 #include "blocktim.h"
\r
101 #include "taskutility.h"
\r
102 #include "partest.h"
\r
103 #include "crflash.h"
\r
105 /* Demo task priorities. */
\r
106 #define mainWATCHDOG_TASK_PRIORITY ( tskIDLE_PRIORITY + 5 )
\r
107 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
108 #define mainUTILITY_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
109 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
110 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
111 #define mainQUEUE_BLOCK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
112 #define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
113 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
114 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
116 /* Baud rate used by the COM test tasks. */
\r
117 #define mainCOM_TEST_BAUD_RATE ( ( unsigned portLONG ) 19200 )
\r
119 /* The frequency at which the 'Check' tasks executes. See the comments at the
\r
120 top of the page. When the system is operating error free the 'Check' task
\r
121 toggles an LED every three seconds. If an error is discovered in any task the
\r
122 rate is increased to 500 milliseconds. [in this case the '*' characters on the
\r
123 LCD represent LEDs]*/
\r
124 #define mainNO_ERROR_CHECK_DELAY ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
125 #define mainERROR_CHECK_DELAY ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
127 /* The total number of LEDs available. */
\r
128 #define mainNO_CO_ROUTINE_LEDs ( 8 )
\r
130 /* The first LED used by the comtest tasks. */
\r
131 #define mainCOM_TEST_LED ( 0x05 )
\r
133 /* The LED used by the check task. */
\r
134 #define mainCHECK_TEST_LED ( 0x07 )
\r
136 /* The number of interrupt levels to use. */
\r
137 #define mainINTERRUPT_LEVELS ( 31 )
\r
139 /* The number of 'flash' co-routines to create - each toggles a different LED. */
\r
140 #define mainNUM_FLASH_CO_ROUTINES ( 8 )
\r
142 /*---------------------------------------------------------------------------*/
\r
145 * The function that implements the Check task. See the comments at the head
\r
146 * of the page for implementation details.
\r
148 static void prvErrorChecks( void *pvParameters );
\r
151 * Called by the Check task. Returns pdPASS if all the other tasks are found
\r
152 * to be operating without error - otherwise returns pdFAIL.
\r
154 static portSHORT prvCheckOtherTasksAreStillRunning( void );
\r
157 * Setup the microcontroller as used by this demo.
\r
159 static void prvSetupHardware( void );
\r
162 * Tasks that test the context switch mechanism by filling the CPU registers
\r
163 * with known values then checking that each register contains the value
\r
164 * expected. Each of the two tasks use different values, and as low priority
\r
165 * tasks, get swapped in and out regularly.
\r
167 static void vFirstRegisterTestTask( void *pvParameters );
\r
168 static void vSecondRegisterTestTask( void *pvParameters );
\r
170 /*---------------------------------------------------------------------------*/
\r
172 /* The variable that is set to true should an error be found in one of the
\r
173 register test tasks. */
\r
174 unsigned portLONG ulRegTestError = pdFALSE;
\r
176 /*---------------------------------------------------------------------------*/
\r
178 /* Start all the demo application tasks, then start the scheduler. */
\r
181 /* Initialise the hardware ready for the demo. */
\r
182 prvSetupHardware();
\r
184 /* Start the standard demo application tasks. */
\r
185 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
186 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
187 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );
\r
188 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
189 vStartBlockingQueueTasks ( mainQUEUE_BLOCK_PRIORITY );
\r
190 vStartDynamicPriorityTasks();
\r
191 vStartMathTasks( tskIDLE_PRIORITY );
\r
192 vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
\r
193 vStartQueuePeekTasks();
\r
194 vCreateBlockTimeTasks();
\r
195 vStartFlashCoRoutines( mainNUM_FLASH_CO_ROUTINES );
\r
197 /* Start the 'Check' task which is defined in this file. */
\r
198 xTaskCreate( prvErrorChecks, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
200 /* Start the 'Register Test' tasks as described at the top of this file. */
\r
201 xTaskCreate( vFirstRegisterTestTask, ( signed portCHAR * ) "Reg1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
202 xTaskCreate( vSecondRegisterTestTask, ( signed portCHAR * ) "Reg2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
204 /* Start the task that write trace information to the UART. */
\r
205 vUtilityStartTraceTask( mainUTILITY_TASK_PRIORITY );
\r
207 /* If we are going to service the watchdog from within a task, then create
\r
209 #if WATCHDOG == WTC_IN_TASK
\r
210 vStartWatchdogTask( mainWATCHDOG_TASK_PRIORITY );
\r
213 /* The suicide tasks must be started last as they record the number of other
\r
214 tasks that exist within the system. The value is then used to ensure at run
\r
215 time the number of tasks that exists is within expected bounds. */
\r
216 vCreateSuicidalTasks( mainDEATH_PRIORITY );
\r
218 /* Now start the scheduler. Following this call the created tasks should
\r
220 vTaskStartScheduler( );
\r
222 /* vTaskStartScheduler() will only return if an error occurs while the
\r
223 idle task is being created. */
\r
226 /*-----------------------------------------------------------*/
\r
228 static void prvErrorChecks( void *pvParameters )
\r
230 portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY, xLastExecutionTime;
\r
232 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
233 works correctly. */
\r
234 xLastExecutionTime = xTaskGetTickCount();
\r
236 /* Cycle for ever, delaying then checking all the other tasks are still
\r
237 operating without error. */
\r
240 /* Wait until it is time to check again. The time we wait here depends
\r
241 on whether an error has been detected or not. When an error is
\r
242 detected the time is shortened resulting in a faster LED flash rate. */
\r
243 /* Perform this check every mainCHECK_DELAY milliseconds. */
\r
244 vTaskDelayUntil( &xLastExecutionTime, xDelayPeriod );
\r
246 /* See if the other tasks are all ok. */
\r
247 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
249 /* An error occurred in one of the tasks so shorten the delay
\r
250 period - which has the effect of increasing the frequency of the
\r
252 xDelayPeriod = mainERROR_CHECK_DELAY;
\r
256 vParTestToggleLED( mainCHECK_TEST_LED );
\r
259 /*-----------------------------------------------------------*/
\r
261 static portSHORT prvCheckOtherTasksAreStillRunning( void )
\r
263 portBASE_TYPE lReturn = pdPASS;
\r
265 /* The demo tasks maintain a count that increments every cycle of the task
\r
266 provided that the task has never encountered an error. This function
\r
267 checks the counts maintained by the tasks to ensure they are still being
\r
268 incremented. A count remaining at the same value between calls therefore
\r
269 indicates that an error has been detected. */
\r
271 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
276 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
281 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
286 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
291 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
296 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
301 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
306 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
311 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
316 if ( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
321 /* Have the register test tasks found any errors? */
\r
322 if( ulRegTestError != pdFALSE )
\r
329 /*-----------------------------------------------------------*/
\r
331 static void prvSetupHardware( void )
\r
333 /* Allow all interrupt levels. */
\r
334 __set_il( mainINTERRUPT_LEVELS );
\r
336 /* Initialise interrupts. */
\r
339 /* Initialise the ports used by the LEDs. */
\r
340 vParTestInitialise();
\r
342 /* If we are going to use the watchdog, then initialise it now. */
\r
343 #if WATCHDOG != WTC_NONE
\r
347 /*-----------------------------------------------------------*/
\r
349 /* Idle hook function. */
\r
350 #if configUSE_IDLE_HOOK == 1
\r
351 void vApplicationIdleHook( void )
\r
353 /* Are we using the idle task to kick the watchdog? See watchdog.h
\r
354 for watchdog kicking options. Note this is for demonstration only
\r
355 and is not a suggested method of servicing the watchdog in a real
\r
357 #if WATCHDOG == WTC_IN_IDLE
\r
361 vCoRoutineSchedule();
\r
364 #if WATCHDOG == WTC_IN_IDLE
\r
365 #error configUSE_IDLE_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the idle task hook.
\r
369 /*-----------------------------------------------------------*/
\r
371 /* Tick hook function. */
\r
372 #if configUSE_TICK_HOOK == 1
\r
373 void vApplicationTickHook( void )
\r
375 /* Are we using the tick to kick the watchdog? See watchdog.h
\r
376 for watchdog kicking options. Note this is for demonstration
\r
377 only and is not a suggested method of servicing the watchdog in
\r
378 a real application. */
\r
379 #if WATCHDOG == WTC_IN_TICK
\r
384 #if WATCHDOG == WTC_IN_TICK
\r
385 #error configUSE_TICK_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the tick hook.
\r
388 /*-----------------------------------------------------------*/
\r
390 static void vFirstRegisterTestTask( void *pvParameters )
\r
392 extern volatile unsigned portLONG ulCriticalNesting;
\r
394 /* Fills the registers with known values (different to the values
\r
395 used in vSecondRegisterTestTask()), then checks that the registers still
\r
396 all contain the expected value. This is done to test the context save
\r
397 and restore mechanism as this task is swapped onto and off of the CPU. */
\r
402 ;Load known values into each register.
\r
403 LDI #0x11111111, R0
\r
404 LDI #0x22222222, R1
\r
405 LDI #0x33333333, R2
\r
406 LDI #0x44444444, R3
\r
407 LDI #0x55555555, R4
\r
408 LDI #0x66666666, R5
\r
409 LDI #0x77777777, R6
\r
410 LDI #0x88888888, R7
\r
411 LDI #0x99999999, R8
\r
412 LDI #0xaaaaaaaa, R9
\r
413 LDI #0xbbbbbbbb, R10
\r
414 LDI #0xcccccccc, R11
\r
415 LDI #0xdddddddd, R12
\r
417 ;Check each register still contains the expected value.
\r
418 LDI #0x11111111, R13
\r
420 BNE First_Set_Error
\r
422 LDI #0x22222222, R13
\r
424 BNE First_Set_Error
\r
426 LDI #0x33333333, R13
\r
428 BNE First_Set_Error
\r
430 LDI #0x44444444, R13
\r
432 BNE First_Set_Error
\r
434 LDI #0x55555555, R13
\r
436 BNE First_Set_Error
\r
438 LDI #0x66666666, R13
\r
440 BNE First_Set_Error
\r
442 LDI #0x77777777, R13
\r
444 BNE First_Set_Error
\r
446 LDI #0x88888888, R13
\r
448 BNE First_Set_Error
\r
450 LDI #0x99999999, R13
\r
452 BNE First_Set_Error
\r
454 LDI #0xaaaaaaaa, R13
\r
456 BNE First_Set_Error
\r
458 LDI #0xbbbbbbbb, R13
\r
460 BNE First_Set_Error
\r
462 LDI #0xcccccccc, R13
\r
464 BNE First_Set_Error
\r
466 LDI #0xdddddddd, R13
\r
468 BNE First_Set_Error
\r
470 BRA First_Start_Next_Loop
\r
474 ; Latch that an error has occurred.
\r
475 LDI #_ulRegTestError, R0
\r
476 LDI #0x00000001, R1
\r
480 First_Start_Next_Loop:
\r
486 /*-----------------------------------------------------------*/
\r
488 static void vSecondRegisterTestTask( void *pvParameters )
\r
490 extern volatile unsigned portLONG ulCriticalNesting;
\r
492 /* Fills the registers with known values (different to the values
\r
493 used in vFirstRegisterTestTask()), then checks that the registers still
\r
494 all contain the expected value. This is done to test the context save
\r
495 and restore mechanism as this task is swapped onto and off of the CPU. */
\r
500 ;Load known values into each register.
\r
501 LDI #0x11111111, R1
\r
502 LDI #0x22222222, R2
\r
504 LDI #0x33333333, R3
\r
505 LDI #0x44444444, R4
\r
506 LDI #0x55555555, R5
\r
507 LDI #0x66666666, R6
\r
508 LDI #0x77777777, R7
\r
509 LDI #0x88888888, R8
\r
510 LDI #0x99999999, R9
\r
512 LDI #0xaaaaaaaa, R10
\r
513 LDI #0xbbbbbbbb, R11
\r
514 LDI #0xcccccccc, R12
\r
515 LDI #0xdddddddd, R0
\r
517 ;Check each register still contains the expected value.
\r
518 LDI #0x11111111, R13
\r
520 BNE Second_Set_Error
\r
522 LDI #0x22222222, R13
\r
524 BNE Second_Set_Error
\r
526 LDI #0x33333333, R13
\r
528 BNE Second_Set_Error
\r
530 LDI #0x44444444, R13
\r
532 BNE Second_Set_Error
\r
534 LDI #0x55555555, R13
\r
536 BNE Second_Set_Error
\r
540 LDI #0x66666666, R13
\r
542 BNE Second_Set_Error
\r
544 LDI #0x77777777, R13
\r
546 BNE Second_Set_Error
\r
548 LDI #0x88888888, R13
\r
550 BNE Second_Set_Error
\r
552 LDI #0x99999999, R13
\r
554 BNE Second_Set_Error
\r
558 LDI #0xaaaaaaaa, R13
\r
560 BNE Second_Set_Error
\r
562 LDI #0xbbbbbbbb, R13
\r
564 BNE Second_Set_Error
\r
566 LDI #0xcccccccc, R13
\r
568 BNE Second_Set_Error
\r
570 LDI #0xdddddddd, R13
\r
572 BNE Second_Set_Error
\r
574 BRA Second_Start_Next_Loop
\r
578 ; Latch that an error has occurred.
\r
579 LDI #_ulRegTestError, R0
\r
580 LDI #0x00000001, R1
\r
584 Second_Start_Next_Loop:
\r
590 /*-----------------------------------------------------------*/
\r