1 /* THIS SAMPLE CODE IS PROVIDED AS IS AND IS SUBJECT TO ALTERATIONS. FUJITSU */
\r
2 /* MICROELECTRONICS ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY ERRORS OR */
\r
3 /* ELIGIBILITY FOR ANY PURPOSES. */
\r
4 /* (C) Fujitsu Microelectronics Europe GmbH */
\r
5 /*------------------------------------------------------------------------
\r
8 - See README.TXT for project description and disclaimer.
\r
9 -------------------------------------------------------------------------*/
\r
13 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
14 * documentation provides more details of the demo application tasks.
\r
16 * Main.c also creates a task called "Check". This only executes every three
\r
17 * seconds but has the highest priority so is guaranteed to get processor time.
\r
18 * Its main function is to check that all the other tasks are still operational.
\r
19 * Each task (other than the "flash" tasks) maintains a unique count that is
\r
20 * incremented each time the task successfully completes its function. Should
\r
21 * any error occur within such a task the count is permanently halted. The
\r
22 * check task inspects the count of each task to ensure it has changed since
\r
23 * the last time the check task executed. If all the count variables have
\r
24 * changed all the tasks are still executing error free, and the check task
\r
25 * toggles the onboard LED. Should any task contain an error at any time
\r
26 * the LED toggle rate will change from 3 seconds to 500ms.
\r
31 /* Hardware specific includes. */
\r
32 #include "mb91467d.h"
\r
33 #include "vectors.h"
\r
34 #include "watchdog.h"
\r
36 /* Scheduler includes. */
\r
37 #include "FreeRTOS.h"
\r
40 /* Demo app includes. */
\r
42 #include "integer.h"
\r
43 #include "comtest.h"
\r
45 #include "semtest.h"
\r
47 #include "dynamic.h"
\r
49 #include "crflash.h"
\r
51 #include "GenQTest.h"
\r
53 #include "BlockTim.h"
\r
55 #include "taskutility.h"
\r
57 /* Demo task priorities. */
\r
58 #define mainWATCHDOG_TASK_PRIORITY ( tskIDLE_PRIORITY + 5 )
\r
59 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
60 #define mainUTILITY_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
61 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
62 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
63 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
64 #define mainQUEUE_BLOCK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
65 #define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
66 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
67 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
69 /* Baud rate used by the COM test tasks. */
\r
70 #define mainCOM_TEST_BAUD_RATE ( ( unsigned portLONG ) 19200 )
\r
72 /* The frequency at which the 'Check' tasks executes. See the comments at the
\r
73 top of the page. When the system is operating error free the 'Check' task
\r
74 toggles an LED every three seconds. If an error is discovered in any task the
\r
75 rate is increased to 500 milliseconds. [in this case the '*' characters on the
\r
76 LCD represent LED's]*/
\r
77 #define mainNO_ERROR_CHECK_DELAY ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
78 #define mainERROR_CHECK_DELAY ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
80 /* The total number of LEDs available. */
\r
81 #define ledNUMBER_OF_LEDS ( 8 )
\r
83 /* The first LED used by the comtest tasks. */
\r
84 #define mainCOM_TEST_LED ( 0x05 )
\r
86 /* The LED used by the check task. */
\r
87 #define mainCHECK_TEST_LED ( 0x07 )
\r
89 /* The number of interrupt levels to use. */
\r
90 #define mainINTERRUPT_LEVELS ( 31 )
\r
92 /*---------------------------------------------------------------------------*/
\r
95 * The function that implements the Check task. See the comments at the head
\r
96 * of the page for implementation details.
\r
98 static void vErrorChecks( void *pvParameters );
\r
101 * Called by the Check task. Returns pdPASS if all the other tasks are found
\r
102 * to be operating without error - otherwise returns pdFAIL.
\r
104 static portSHORT prvCheckOtherTasksAreStillRunning( void );
\r
107 * Setup the microcontroller as used by this demo.
\r
109 static void prvSetupHardware( void );
\r
111 /*---------------------------------------------------------------------------*/
\r
113 /* Start all the demo application tasks, then start the scheduler. */
\r
116 /* Initialise the hardware ready for the demo. */
\r
117 prvSetupHardware();
\r
119 /* Start the standard demo application tasks. */
\r
120 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
121 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
122 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );
\r
123 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
124 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
125 vStartBlockingQueueTasks ( mainQUEUE_BLOCK_PRIORITY );
\r
126 vStartDynamicPriorityTasks();
\r
127 vStartMathTasks( tskIDLE_PRIORITY );
\r
128 vStartFlashCoRoutines(ledNUMBER_OF_LEDS);
\r
129 vStartHookCoRoutines();
\r
130 vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
\r
131 vStartQueuePeekTasks();
\r
132 vCreateBlockTimeTasks();
\r
134 /* Start the 'Check' task which is defined in this file. */
\r
135 xTaskCreate( vErrorChecks, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
137 /* Start the task that write trace information to the UART. */
\r
138 vUtilityStartTraceTask( mainUTILITY_TASK_PRIORITY );
\r
140 /* If we are going to service the watchdog from within a task, then create
\r
142 #if WATCHDOG == WTC_IN_TASK
\r
143 vStartWatchdogTask( mainWATCHDOG_TASK_PRIORITY );
\r
146 /* The suicide tasks must be started last as they record the number of other
\r
147 tasks that exist within the system. The value is then used to ensure at run
\r
148 time the number of tasks that exists is within expected bounds. */
\r
149 vCreateSuicidalTasks( mainDEATH_PRIORITY );
\r
151 /* Now start the scheduler. Following this call the created tasks should
\r
153 vTaskStartScheduler( );
\r
155 /* vTaskStartScheduler() will only return if an error occurs while the
\r
156 idle task is being created. */
\r
159 /*-----------------------------------------------------------*/
\r
161 static void vErrorChecks( void *pvParameters )
\r
163 portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY;
\r
165 /* Cycle for ever, delaying then checking all the other tasks are still
\r
166 operating without error. */
\r
169 /* Wait until it is time to check again. The time we wait here depends
\r
170 on whether an error has been detected or not. When an error is
\r
171 detected the time is shortened resulting in a faster LED flash rate. */
\r
172 vTaskDelay( xDelayPeriod );
\r
174 /* See if the other tasks are all ok. */
\r
175 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
177 /* An error occurred in one of the tasks so shorten the delay
\r
178 period - which has the effect of increasing the frequency of the
\r
180 xDelayPeriod = mainERROR_CHECK_DELAY;
\r
184 vParTestToggleLED(mainCHECK_TEST_LED);
\r
187 /*-----------------------------------------------------------*/
\r
189 static portSHORT prvCheckOtherTasksAreStillRunning( void )
\r
191 static portBASE_TYPE xErrorOccurred = pdFALSE;
\r
193 /* The demo tasks maintain a count that increments every cycle of the task
\r
194 provided that the task has never encountered an error. This function
\r
195 checks the counts maintained by the tasks to ensure they are still being
\r
196 incremented. A count remaining at the same value between calls therefore
\r
197 indicates that an error has been detected. */
\r
199 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
201 xErrorOccurred = pdTRUE
\r
204 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
206 xErrorOccurred = pdTRUE
\r
209 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
211 xErrorOccurred = pdTRUE
\r
214 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
216 xErrorOccurred = pdTRUE
\r
219 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
221 xErrorOccurred = pdTRUE
\r
224 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
226 xErrorOccurred = pdTRUE
\r
229 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
231 xErrorOccurred = pdTRUE
\r
234 if( xAreFlashCoRoutinesStillRunning() != pdTRUE )
\r
236 xErrorOccurred = pdTRUE
\r
239 if( xAreHookCoRoutinesStillRunning() != pdTRUE )
\r
241 xErrorOccurred = pdTRUE
\r
244 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
246 xErrorOccurred = pdTRUE
\r
249 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
251 xErrorOccurred = pdTRUE
\r
254 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
256 xErrorOccurred = pdTRUE
\r
259 if ( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
261 xErrorOccurred = pdTRUE
\r
264 return sNoErrorFound;
\r
266 /*-----------------------------------------------------------*/
\r
268 static void prvSetupHardware( void )
\r
270 /* Allow all interrupt levels. */
\r
271 __set_il( mainINTERRUPT_LEVELS );
\r
273 /* Initialise interrupts. */
\r
276 /* Initialise the ports used by the LEDs. */
\r
277 vParTestInitialise();
\r
279 /* If we are going to use the watchdog, then initialise it now. */
\r
280 #if WATCHDOG != WTC_NONE
\r
284 /*-----------------------------------------------------------*/
\r
286 /* The below callback function is called from Tick ISR if configUSE_TICK_HOOK
\r
287 is configured as 1. This function needs to be uncommented if the crhook.c
\r
288 is not used, since the crhook.c has also defined vApplicationTickHook(). */
\r
289 #if configUSE_TICK_HOOK == 1
\r
290 void vApplicationTickHook ( void )
\r
292 /* Are we using the tick interrupt to kick the watchdog? */
\r
293 #if WATCHDOG == WTC_IN_TICK
\r
298 /*-----------------------------------------------------------*/
\r
300 /* The below callback function is called from Delayed ISR if configUSE_IDLE_HOOK
\r
301 is configured as 1. */
\r
302 #if configUSE_IDLE_HOOK == 1
\r
303 void vApplicationIdleHook ( void )
\r
305 /* Are we using the idle task to kick the watchdog? */
\r
306 #if WATCHDOG == WTC_IN_IDLE
\r
310 vCoRoutineSchedule();
\r