2 FreeRTOS V7.5.1 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
67 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
68 * documentation provides more details of the demo application tasks.
\r
70 * In addition to the standard demo tasks, the follow demo specific tasks are
\r
73 * The "Check" task. This only executes every three seconds but has the highest
\r
74 * priority so is guaranteed to get processor time. Its main function is to
\r
75 * check that all the other tasks are still operational. Most tasks maintain
\r
76 * a unique count that is incremented each time the task successfully completes
\r
77 * its function. Should any error occur within such a task the count is
\r
78 * permanently halted. The check task inspects the count of each task to ensure
\r
79 * it has changed since the last time the check task executed. If all the count
\r
80 * variables have changed all the tasks are still executing error free, and the
\r
81 * check task toggles the onboard LED. Should any task contain an error at any time
\r
82 * the LED toggle rate will change from 3 seconds to 500ms.
\r
84 * The "Register Check" tasks. These tasks fill the CPU registers with known
\r
85 * values, then check that each register still contains the expected value 0 the
\r
86 * discovery of an unexpected value being indicative of an error in the RTOS
\r
87 * context switch mechanism. The register check tasks operate at low priority
\r
88 * so are switched in and out frequently.
\r
90 * The "Trace Utility" task. This can be used to obtain trace and debug
\r
91 * information via UART5.
\r
95 /* Hardware specific includes. */
\r
96 #include "mb91467d.h"
\r
97 #include "vectors.h"
\r
98 #include "watchdog.h"
\r
100 /* Scheduler includes. */
\r
101 #include "FreeRTOS.h"
\r
104 /* Demo app includes. */
\r
106 #include "integer.h"
\r
107 #include "comtest2.h"
\r
108 #include "semtest.h"
\r
109 #include "BlockQ.h"
\r
110 #include "dynamic.h"
\r
112 #include "GenQTest.h"
\r
114 #include "blocktim.h"
\r
116 #include "taskutility.h"
\r
117 #include "partest.h"
\r
118 #include "crflash.h"
\r
120 /* Demo task priorities. */
\r
121 #define mainWATCHDOG_TASK_PRIORITY ( tskIDLE_PRIORITY + 5 )
\r
122 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
123 #define mainUTILITY_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
124 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
125 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
126 #define mainQUEUE_BLOCK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
127 #define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
128 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
129 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
131 /* Baud rate used by the COM test tasks. */
\r
132 #define mainCOM_TEST_BAUD_RATE ( ( unsigned portLONG ) 19200 )
\r
134 /* The frequency at which the 'Check' tasks executes. See the comments at the
\r
135 top of the page. When the system is operating error free the 'Check' task
\r
136 toggles an LED every three seconds. If an error is discovered in any task the
\r
137 rate is increased to 500 milliseconds. [in this case the '*' characters on the
\r
138 LCD represent LEDs]*/
\r
139 #define mainNO_ERROR_CHECK_DELAY ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
140 #define mainERROR_CHECK_DELAY ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
142 /* The total number of LEDs available. */
\r
143 #define mainNO_CO_ROUTINE_LEDs ( 8 )
\r
145 /* The first LED used by the comtest tasks. */
\r
146 #define mainCOM_TEST_LED ( 0x05 )
\r
148 /* The LED used by the check task. */
\r
149 #define mainCHECK_TEST_LED ( 0x07 )
\r
151 /* The number of interrupt levels to use. */
\r
152 #define mainINTERRUPT_LEVELS ( 31 )
\r
154 /* The number of 'flash' co-routines to create - each toggles a different LED. */
\r
155 #define mainNUM_FLASH_CO_ROUTINES ( 8 )
\r
157 /*---------------------------------------------------------------------------*/
\r
160 * The function that implements the Check task. See the comments at the head
\r
161 * of the page for implementation details.
\r
163 static void prvErrorChecks( void *pvParameters );
\r
166 * Called by the Check task. Returns pdPASS if all the other tasks are found
\r
167 * to be operating without error - otherwise returns pdFAIL.
\r
169 static portSHORT prvCheckOtherTasksAreStillRunning( void );
\r
172 * Setup the microcontroller as used by this demo.
\r
174 static void prvSetupHardware( void );
\r
177 * Tasks that test the context switch mechanism by filling the CPU registers
\r
178 * with known values then checking that each register contains the value
\r
179 * expected. Each of the two tasks use different values, and as low priority
\r
180 * tasks, get swapped in and out regularly.
\r
182 static void vFirstRegisterTestTask( void *pvParameters );
\r
183 static void vSecondRegisterTestTask( void *pvParameters );
\r
185 /*---------------------------------------------------------------------------*/
\r
187 /* The variable that is set to true should an error be found in one of the
\r
188 register test tasks. */
\r
189 unsigned portLONG ulRegTestError = pdFALSE;
\r
191 /*---------------------------------------------------------------------------*/
\r
193 /* Start all the demo application tasks, then start the scheduler. */
\r
196 /* Initialise the hardware ready for the demo. */
\r
197 prvSetupHardware();
\r
199 /* Start the standard demo application tasks. */
\r
200 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
201 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
202 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );
\r
203 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
204 vStartBlockingQueueTasks ( mainQUEUE_BLOCK_PRIORITY );
\r
205 vStartDynamicPriorityTasks();
\r
206 vStartMathTasks( tskIDLE_PRIORITY );
\r
207 vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
\r
208 vStartQueuePeekTasks();
\r
209 vCreateBlockTimeTasks();
\r
210 vStartFlashCoRoutines( mainNUM_FLASH_CO_ROUTINES );
\r
212 /* Start the 'Check' task which is defined in this file. */
\r
213 xTaskCreate( prvErrorChecks, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
215 /* Start the 'Register Test' tasks as described at the top of this file. */
\r
216 xTaskCreate( vFirstRegisterTestTask, ( signed portCHAR * ) "Reg1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
217 xTaskCreate( vSecondRegisterTestTask, ( signed portCHAR * ) "Reg2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
219 /* Start the task that write trace information to the UART. */
\r
220 vUtilityStartTraceTask( mainUTILITY_TASK_PRIORITY );
\r
222 /* If we are going to service the watchdog from within a task, then create
\r
224 #if WATCHDOG == WTC_IN_TASK
\r
225 vStartWatchdogTask( mainWATCHDOG_TASK_PRIORITY );
\r
228 /* The suicide tasks must be started last as they record the number of other
\r
229 tasks that exist within the system. The value is then used to ensure at run
\r
230 time the number of tasks that exists is within expected bounds. */
\r
231 vCreateSuicidalTasks( mainDEATH_PRIORITY );
\r
233 /* Now start the scheduler. Following this call the created tasks should
\r
235 vTaskStartScheduler( );
\r
237 /* vTaskStartScheduler() will only return if an error occurs while the
\r
238 idle task is being created. */
\r
241 /*-----------------------------------------------------------*/
\r
243 static void prvErrorChecks( void *pvParameters )
\r
245 portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY, xLastExecutionTime;
\r
247 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
248 works correctly. */
\r
249 xLastExecutionTime = xTaskGetTickCount();
\r
251 /* Cycle for ever, delaying then checking all the other tasks are still
\r
252 operating without error. */
\r
255 /* Wait until it is time to check again. The time we wait here depends
\r
256 on whether an error has been detected or not. When an error is
\r
257 detected the time is shortened resulting in a faster LED flash rate. */
\r
258 /* Perform this check every mainCHECK_DELAY milliseconds. */
\r
259 vTaskDelayUntil( &xLastExecutionTime, xDelayPeriod );
\r
261 /* See if the other tasks are all ok. */
\r
262 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
264 /* An error occurred in one of the tasks so shorten the delay
\r
265 period - which has the effect of increasing the frequency of the
\r
267 xDelayPeriod = mainERROR_CHECK_DELAY;
\r
271 vParTestToggleLED( mainCHECK_TEST_LED );
\r
274 /*-----------------------------------------------------------*/
\r
276 static portSHORT prvCheckOtherTasksAreStillRunning( void )
\r
278 portBASE_TYPE lReturn = pdPASS;
\r
280 /* The demo tasks maintain a count that increments every cycle of the task
\r
281 provided that the task has never encountered an error. This function
\r
282 checks the counts maintained by the tasks to ensure they are still being
\r
283 incremented. A count remaining at the same value between calls therefore
\r
284 indicates that an error has been detected. */
\r
286 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
291 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
296 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
301 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
306 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
311 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
316 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
321 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
326 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
331 if ( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
336 /* Have the register test tasks found any errors? */
\r
337 if( ulRegTestError != pdFALSE )
\r
344 /*-----------------------------------------------------------*/
\r
346 static void prvSetupHardware( void )
\r
348 /* Allow all interrupt levels. */
\r
349 __set_il( mainINTERRUPT_LEVELS );
\r
351 /* Initialise interrupts. */
\r
354 /* Initialise the ports used by the LEDs. */
\r
355 vParTestInitialise();
\r
357 /* If we are going to use the watchdog, then initialise it now. */
\r
358 #if WATCHDOG != WTC_NONE
\r
362 /*-----------------------------------------------------------*/
\r
364 /* Idle hook function. */
\r
365 #if configUSE_IDLE_HOOK == 1
\r
366 void vApplicationIdleHook( void )
\r
368 /* Are we using the idle task to kick the watchdog? See watchdog.h
\r
369 for watchdog kicking options. Note this is for demonstration only
\r
370 and is not a suggested method of servicing the watchdog in a real
\r
372 #if WATCHDOG == WTC_IN_IDLE
\r
376 vCoRoutineSchedule();
\r
379 #if WATCHDOG == WTC_IN_IDLE
\r
380 #error configUSE_IDLE_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the idle task hook.
\r
384 /*-----------------------------------------------------------*/
\r
386 /* Tick hook function. */
\r
387 #if configUSE_TICK_HOOK == 1
\r
388 void vApplicationTickHook( void )
\r
390 /* Are we using the tick to kick the watchdog? See watchdog.h
\r
391 for watchdog kicking options. Note this is for demonstration
\r
392 only and is not a suggested method of servicing the watchdog in
\r
393 a real application. */
\r
394 #if WATCHDOG == WTC_IN_TICK
\r
399 #if WATCHDOG == WTC_IN_TICK
\r
400 #error configUSE_TICK_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the tick hook.
\r
403 /*-----------------------------------------------------------*/
\r
405 static void vFirstRegisterTestTask( void *pvParameters )
\r
407 extern volatile unsigned portLONG ulCriticalNesting;
\r
409 /* Fills the registers with known values (different to the values
\r
410 used in vSecondRegisterTestTask()), then checks that the registers still
\r
411 all contain the expected value. This is done to test the context save
\r
412 and restore mechanism as this task is swapped onto and off of the CPU. */
\r
417 ;Load known values into each register.
\r
418 LDI #0x11111111, R0
\r
419 LDI #0x22222222, R1
\r
420 LDI #0x33333333, R2
\r
421 LDI #0x44444444, R3
\r
422 LDI #0x55555555, R4
\r
423 LDI #0x66666666, R5
\r
424 LDI #0x77777777, R6
\r
425 LDI #0x88888888, R7
\r
426 LDI #0x99999999, R8
\r
427 LDI #0xaaaaaaaa, R9
\r
428 LDI #0xbbbbbbbb, R10
\r
429 LDI #0xcccccccc, R11
\r
430 LDI #0xdddddddd, R12
\r
432 ;Check each register still contains the expected value.
\r
433 LDI #0x11111111, R13
\r
435 BNE First_Set_Error
\r
437 LDI #0x22222222, R13
\r
439 BNE First_Set_Error
\r
441 LDI #0x33333333, R13
\r
443 BNE First_Set_Error
\r
445 LDI #0x44444444, R13
\r
447 BNE First_Set_Error
\r
449 LDI #0x55555555, R13
\r
451 BNE First_Set_Error
\r
453 LDI #0x66666666, R13
\r
455 BNE First_Set_Error
\r
457 LDI #0x77777777, R13
\r
459 BNE First_Set_Error
\r
461 LDI #0x88888888, R13
\r
463 BNE First_Set_Error
\r
465 LDI #0x99999999, R13
\r
467 BNE First_Set_Error
\r
469 LDI #0xaaaaaaaa, R13
\r
471 BNE First_Set_Error
\r
473 LDI #0xbbbbbbbb, R13
\r
475 BNE First_Set_Error
\r
477 LDI #0xcccccccc, R13
\r
479 BNE First_Set_Error
\r
481 LDI #0xdddddddd, R13
\r
483 BNE First_Set_Error
\r
485 BRA First_Start_Next_Loop
\r
489 ; Latch that an error has occurred.
\r
490 LDI #_ulRegTestError, R0
\r
491 LDI #0x00000001, R1
\r
495 First_Start_Next_Loop:
\r
501 /*-----------------------------------------------------------*/
\r
503 static void vSecondRegisterTestTask( void *pvParameters )
\r
505 extern volatile unsigned portLONG ulCriticalNesting;
\r
507 /* Fills the registers with known values (different to the values
\r
508 used in vFirstRegisterTestTask()), then checks that the registers still
\r
509 all contain the expected value. This is done to test the context save
\r
510 and restore mechanism as this task is swapped onto and off of the CPU. */
\r
515 ;Load known values into each register.
\r
516 LDI #0x11111111, R1
\r
517 LDI #0x22222222, R2
\r
519 LDI #0x33333333, R3
\r
520 LDI #0x44444444, R4
\r
521 LDI #0x55555555, R5
\r
522 LDI #0x66666666, R6
\r
523 LDI #0x77777777, R7
\r
524 LDI #0x88888888, R8
\r
525 LDI #0x99999999, R9
\r
527 LDI #0xaaaaaaaa, R10
\r
528 LDI #0xbbbbbbbb, R11
\r
529 LDI #0xcccccccc, R12
\r
530 LDI #0xdddddddd, R0
\r
532 ;Check each register still contains the expected value.
\r
533 LDI #0x11111111, R13
\r
535 BNE Second_Set_Error
\r
537 LDI #0x22222222, R13
\r
539 BNE Second_Set_Error
\r
541 LDI #0x33333333, R13
\r
543 BNE Second_Set_Error
\r
545 LDI #0x44444444, R13
\r
547 BNE Second_Set_Error
\r
549 LDI #0x55555555, R13
\r
551 BNE Second_Set_Error
\r
555 LDI #0x66666666, R13
\r
557 BNE Second_Set_Error
\r
559 LDI #0x77777777, R13
\r
561 BNE Second_Set_Error
\r
563 LDI #0x88888888, R13
\r
565 BNE Second_Set_Error
\r
567 LDI #0x99999999, R13
\r
569 BNE Second_Set_Error
\r
573 LDI #0xaaaaaaaa, R13
\r
575 BNE Second_Set_Error
\r
577 LDI #0xbbbbbbbb, R13
\r
579 BNE Second_Set_Error
\r
581 LDI #0xcccccccc, R13
\r
583 BNE Second_Set_Error
\r
585 LDI #0xdddddddd, R13
\r
587 BNE Second_Set_Error
\r
589 BRA Second_Start_Next_Loop
\r
593 ; Latch that an error has occurred.
\r
594 LDI #_ulRegTestError, R0
\r
595 LDI #0x00000001, R1
\r
599 Second_Start_Next_Loop:
\r
605 /*-----------------------------------------------------------*/
\r