2 FreeRTOS.org V5.1.2 - Copyright (C) 2003-2009 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 * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *
\r
31 * This is a concise, step by step, 'hands on' guide that describes both *
\r
32 * general multitasking concepts and FreeRTOS specifics. It presents and *
\r
33 * explains numerous examples that are written using the FreeRTOS API. *
\r
34 * Full source code for all the examples is provided in an accompanying *
\r
37 ***************************************************************************
\r
38 ***************************************************************************
\r
40 Please ensure to read the configuration and relevant port sections of the
\r
41 online documentation.
\r
43 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
46 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
49 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
50 licensing and training services.
\r
55 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
56 * documentation provides more details of the demo application tasks.
\r
58 * In addition to the standard demo tasks, the follow demo specific tasks are
\r
61 * The "Check" task. This only executes every three seconds but has the highest
\r
62 * priority so is guaranteed to get processor time. Its main function is to
\r
63 * check that all the other tasks are still operational. Most tasks maintain
\r
64 * a unique count that is incremented each time the task successfully completes
\r
65 * its function. Should any error occur within such a task the count is
\r
66 * permanently halted. The check task inspects the count of each task to ensure
\r
67 * it has changed since the last time the check task executed. If all the count
\r
68 * variables have changed all the tasks are still executing error free, and the
\r
69 * check task toggles the onboard LED. Should any task contain an error at any time
\r
70 * the LED toggle rate will change from 3 seconds to 500ms.
\r
72 * The "Register Check" tasks. These tasks fill the CPU registers with known
\r
73 * values, then check that each register still contains the expected value 0 the
\r
74 * discovery of an unexpected value being indicative of an error in the RTOS
\r
75 * context switch mechanism. The register check tasks operate at low priority
\r
76 * so are switched in and out frequently.
\r
78 * The "Trace Utility" task. This can be used to obtain trace and debug
\r
79 * information via UART5.
\r
83 /* Hardware specific includes. */
\r
84 #include "mb91467d.h"
\r
85 #include "vectors.h"
\r
86 #include "watchdog.h"
\r
88 /* Scheduler includes. */
\r
89 #include "FreeRTOS.h"
\r
92 /* Demo app includes. */
\r
94 #include "integer.h"
\r
95 #include "comtest2.h"
\r
96 #include "semtest.h"
\r
98 #include "dynamic.h"
\r
100 #include "GenQTest.h"
\r
102 #include "blocktim.h"
\r
104 #include "taskutility.h"
\r
105 #include "partest.h"
\r
106 #include "crflash.h"
\r
108 /* Demo task priorities. */
\r
109 #define mainWATCHDOG_TASK_PRIORITY ( tskIDLE_PRIORITY + 5 )
\r
110 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
111 #define mainUTILITY_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
112 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
113 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
114 #define mainQUEUE_BLOCK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
115 #define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
116 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
117 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
119 /* Baud rate used by the COM test tasks. */
\r
120 #define mainCOM_TEST_BAUD_RATE ( ( unsigned portLONG ) 19200 )
\r
122 /* The frequency at which the 'Check' tasks executes. See the comments at the
\r
123 top of the page. When the system is operating error free the 'Check' task
\r
124 toggles an LED every three seconds. If an error is discovered in any task the
\r
125 rate is increased to 500 milliseconds. [in this case the '*' characters on the
\r
126 LCD represent LEDs]*/
\r
127 #define mainNO_ERROR_CHECK_DELAY ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
128 #define mainERROR_CHECK_DELAY ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
130 /* The total number of LEDs available. */
\r
131 #define mainNO_CO_ROUTINE_LEDs ( 8 )
\r
133 /* The first LED used by the comtest tasks. */
\r
134 #define mainCOM_TEST_LED ( 0x05 )
\r
136 /* The LED used by the check task. */
\r
137 #define mainCHECK_TEST_LED ( 0x07 )
\r
139 /* The number of interrupt levels to use. */
\r
140 #define mainINTERRUPT_LEVELS ( 31 )
\r
142 /* The number of 'flash' co-routines to create - each toggles a different LED. */
\r
143 #define mainNUM_FLASH_CO_ROUTINES ( 8 )
\r
145 /*---------------------------------------------------------------------------*/
\r
148 * The function that implements the Check task. See the comments at the head
\r
149 * of the page for implementation details.
\r
151 static void prvErrorChecks( void *pvParameters );
\r
154 * Called by the Check task. Returns pdPASS if all the other tasks are found
\r
155 * to be operating without error - otherwise returns pdFAIL.
\r
157 static portSHORT prvCheckOtherTasksAreStillRunning( void );
\r
160 * Setup the microcontroller as used by this demo.
\r
162 static void prvSetupHardware( void );
\r
165 * Tasks that test the context switch mechanism by filling the CPU registers
\r
166 * with known values then checking that each register contains the value
\r
167 * expected. Each of the two tasks use different values, and as low priority
\r
168 * tasks, get swapped in and out regularly.
\r
170 static void vFirstRegisterTestTask( void *pvParameters );
\r
171 static void vSecondRegisterTestTask( void *pvParameters );
\r
173 /*---------------------------------------------------------------------------*/
\r
175 /* The variable that is set to true should an error be found in one of the
\r
176 register test tasks. */
\r
177 unsigned portLONG ulRegTestError = pdFALSE;
\r
179 /*---------------------------------------------------------------------------*/
\r
181 /* Start all the demo application tasks, then start the scheduler. */
\r
184 /* Initialise the hardware ready for the demo. */
\r
185 prvSetupHardware();
\r
187 /* Start the standard demo application tasks. */
\r
188 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
189 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
190 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );
\r
191 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
192 vStartBlockingQueueTasks ( mainQUEUE_BLOCK_PRIORITY );
\r
193 vStartDynamicPriorityTasks();
\r
194 vStartMathTasks( tskIDLE_PRIORITY );
\r
195 vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
\r
196 vStartQueuePeekTasks();
\r
197 vCreateBlockTimeTasks();
\r
198 vStartFlashCoRoutines( mainNUM_FLASH_CO_ROUTINES );
\r
200 /* Start the 'Check' task which is defined in this file. */
\r
201 xTaskCreate( prvErrorChecks, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
203 /* Start the 'Register Test' tasks as described at the top of this file. */
\r
204 xTaskCreate( vFirstRegisterTestTask, ( signed portCHAR * ) "Reg1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
205 xTaskCreate( vSecondRegisterTestTask, ( signed portCHAR * ) "Reg2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
207 /* Start the task that write trace information to the UART. */
\r
208 vUtilityStartTraceTask( mainUTILITY_TASK_PRIORITY );
\r
210 /* If we are going to service the watchdog from within a task, then create
\r
212 #if WATCHDOG == WTC_IN_TASK
\r
213 vStartWatchdogTask( mainWATCHDOG_TASK_PRIORITY );
\r
216 /* The suicide tasks must be started last as they record the number of other
\r
217 tasks that exist within the system. The value is then used to ensure at run
\r
218 time the number of tasks that exists is within expected bounds. */
\r
219 vCreateSuicidalTasks( mainDEATH_PRIORITY );
\r
221 /* Now start the scheduler. Following this call the created tasks should
\r
223 vTaskStartScheduler( );
\r
225 /* vTaskStartScheduler() will only return if an error occurs while the
\r
226 idle task is being created. */
\r
229 /*-----------------------------------------------------------*/
\r
231 static void prvErrorChecks( void *pvParameters )
\r
233 portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY, xLastExecutionTime;
\r
235 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
236 works correctly. */
\r
237 xLastExecutionTime = xTaskGetTickCount();
\r
239 /* Cycle for ever, delaying then checking all the other tasks are still
\r
240 operating without error. */
\r
243 /* Wait until it is time to check again. The time we wait here depends
\r
244 on whether an error has been detected or not. When an error is
\r
245 detected the time is shortened resulting in a faster LED flash rate. */
\r
246 /* Perform this check every mainCHECK_DELAY milliseconds. */
\r
247 vTaskDelayUntil( &xLastExecutionTime, xDelayPeriod );
\r
249 /* See if the other tasks are all ok. */
\r
250 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
252 /* An error occurred in one of the tasks so shorten the delay
\r
253 period - which has the effect of increasing the frequency of the
\r
255 xDelayPeriod = mainERROR_CHECK_DELAY;
\r
259 vParTestToggleLED( mainCHECK_TEST_LED );
\r
262 /*-----------------------------------------------------------*/
\r
264 static portSHORT prvCheckOtherTasksAreStillRunning( void )
\r
266 portBASE_TYPE lReturn = pdPASS;
\r
268 /* The demo tasks maintain a count that increments every cycle of the task
\r
269 provided that the task has never encountered an error. This function
\r
270 checks the counts maintained by the tasks to ensure they are still being
\r
271 incremented. A count remaining at the same value between calls therefore
\r
272 indicates that an error has been detected. */
\r
274 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
279 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
284 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
289 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
294 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
299 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
304 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
309 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
314 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
319 if ( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
324 /* Have the register test tasks found any errors? */
\r
325 if( ulRegTestError != pdFALSE )
\r
332 /*-----------------------------------------------------------*/
\r
334 static void prvSetupHardware( void )
\r
336 /* Allow all interrupt levels. */
\r
337 __set_il( mainINTERRUPT_LEVELS );
\r
339 /* Initialise interrupts. */
\r
342 /* Initialise the ports used by the LEDs. */
\r
343 vParTestInitialise();
\r
345 /* If we are going to use the watchdog, then initialise it now. */
\r
346 #if WATCHDOG != WTC_NONE
\r
350 /*-----------------------------------------------------------*/
\r
352 /* Idle hook function. */
\r
353 #if configUSE_IDLE_HOOK == 1
\r
354 void vApplicationIdleHook( void )
\r
356 /* Are we using the idle task to kick the watchdog? See watchdog.h
\r
357 for watchdog kicking options. Note this is for demonstration only
\r
358 and is not a suggested method of servicing the watchdog in a real
\r
360 #if WATCHDOG == WTC_IN_IDLE
\r
364 vCoRoutineSchedule();
\r
367 #if WATCHDOG == WTC_IN_IDLE
\r
368 #error configUSE_IDLE_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the idle task hook.
\r
372 /*-----------------------------------------------------------*/
\r
374 /* Tick hook function. */
\r
375 #if configUSE_TICK_HOOK == 1
\r
376 void vApplicationTickHook( void )
\r
378 /* Are we using the tick to kick the watchdog? See watchdog.h
\r
379 for watchdog kicking options. Note this is for demonstration
\r
380 only and is not a suggested method of servicing the watchdog in
\r
381 a real application. */
\r
382 #if WATCHDOG == WTC_IN_TICK
\r
387 #if WATCHDOG == WTC_IN_TICK
\r
388 #error configUSE_TICK_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the tick hook.
\r
391 /*-----------------------------------------------------------*/
\r
393 static void vFirstRegisterTestTask( void *pvParameters )
\r
395 extern volatile unsigned portLONG ulCriticalNesting;
\r
397 /* Fills the registers with known values (different to the values
\r
398 used in vSecondRegisterTestTask()), then checks that the registers still
\r
399 all contain the expected value. This is done to test the context save
\r
400 and restore mechanism as this task is swapped onto and off of the CPU. */
\r
405 ;Load known values into each register.
\r
406 LDI #0x11111111, R0
\r
407 LDI #0x22222222, R1
\r
408 LDI #0x33333333, R2
\r
409 LDI #0x44444444, R3
\r
410 LDI #0x55555555, R4
\r
411 LDI #0x66666666, R5
\r
412 LDI #0x77777777, R6
\r
413 LDI #0x88888888, R7
\r
414 LDI #0x99999999, R8
\r
415 LDI #0xaaaaaaaa, R9
\r
416 LDI #0xbbbbbbbb, R10
\r
417 LDI #0xcccccccc, R11
\r
418 LDI #0xdddddddd, R12
\r
420 ;Check each register still contains the expected value.
\r
421 LDI #0x11111111, R13
\r
423 BNE First_Set_Error
\r
425 LDI #0x22222222, R13
\r
427 BNE First_Set_Error
\r
429 LDI #0x33333333, R13
\r
431 BNE First_Set_Error
\r
433 LDI #0x44444444, R13
\r
435 BNE First_Set_Error
\r
437 LDI #0x55555555, R13
\r
439 BNE First_Set_Error
\r
441 LDI #0x66666666, R13
\r
443 BNE First_Set_Error
\r
445 LDI #0x77777777, R13
\r
447 BNE First_Set_Error
\r
449 LDI #0x88888888, R13
\r
451 BNE First_Set_Error
\r
453 LDI #0x99999999, R13
\r
455 BNE First_Set_Error
\r
457 LDI #0xaaaaaaaa, R13
\r
459 BNE First_Set_Error
\r
461 LDI #0xbbbbbbbb, R13
\r
463 BNE First_Set_Error
\r
465 LDI #0xcccccccc, R13
\r
467 BNE First_Set_Error
\r
469 LDI #0xdddddddd, R13
\r
471 BNE First_Set_Error
\r
473 BRA First_Start_Next_Loop
\r
477 ; Latch that an error has occurred.
\r
478 LDI #_ulRegTestError, R0
\r
479 LDI #0x00000001, R1
\r
483 First_Start_Next_Loop:
\r
489 /*-----------------------------------------------------------*/
\r
491 static void vSecondRegisterTestTask( void *pvParameters )
\r
493 extern volatile unsigned portLONG ulCriticalNesting;
\r
495 /* Fills the registers with known values (different to the values
\r
496 used in vFirstRegisterTestTask()), then checks that the registers still
\r
497 all contain the expected value. This is done to test the context save
\r
498 and restore mechanism as this task is swapped onto and off of the CPU. */
\r
503 ;Load known values into each register.
\r
504 LDI #0x11111111, R1
\r
505 LDI #0x22222222, R2
\r
507 LDI #0x33333333, R3
\r
508 LDI #0x44444444, R4
\r
509 LDI #0x55555555, R5
\r
510 LDI #0x66666666, R6
\r
511 LDI #0x77777777, R7
\r
512 LDI #0x88888888, R8
\r
513 LDI #0x99999999, R9
\r
515 LDI #0xaaaaaaaa, R10
\r
516 LDI #0xbbbbbbbb, R11
\r
517 LDI #0xcccccccc, R12
\r
518 LDI #0xdddddddd, R0
\r
520 ;Check each register still contains the expected value.
\r
521 LDI #0x11111111, R13
\r
523 BNE Second_Set_Error
\r
525 LDI #0x22222222, R13
\r
527 BNE Second_Set_Error
\r
529 LDI #0x33333333, R13
\r
531 BNE Second_Set_Error
\r
533 LDI #0x44444444, R13
\r
535 BNE Second_Set_Error
\r
537 LDI #0x55555555, R13
\r
539 BNE Second_Set_Error
\r
543 LDI #0x66666666, R13
\r
545 BNE Second_Set_Error
\r
547 LDI #0x77777777, R13
\r
549 BNE Second_Set_Error
\r
551 LDI #0x88888888, R13
\r
553 BNE Second_Set_Error
\r
555 LDI #0x99999999, R13
\r
557 BNE Second_Set_Error
\r
561 LDI #0xaaaaaaaa, R13
\r
563 BNE Second_Set_Error
\r
565 LDI #0xbbbbbbbb, R13
\r
567 BNE Second_Set_Error
\r
569 LDI #0xcccccccc, R13
\r
571 BNE Second_Set_Error
\r
573 LDI #0xdddddddd, R13
\r
575 BNE Second_Set_Error
\r
577 BRA Second_Start_Next_Loop
\r
581 ; Latch that an error has occurred.
\r
582 LDI #_ulRegTestError, R0
\r
583 LDI #0x00000001, R1
\r
587 Second_Start_Next_Loop:
\r
593 /*-----------------------------------------------------------*/
\r