]> git.sur5r.net Git - freertos/blob - Demo/MB91460_Softune/SRC/main.c
git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@156 1d2547de-c912-0410...
[freertos] / Demo / MB91460_Softune / SRC / main.c
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
6   MAIN.C\r
7   - description\r
8   - See README.TXT for project description and disclaimer.\r
9 -------------------------------------------------------------------------*/\r
10 \r
11 \r
12 /*\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
15  * \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
27  *\r
28  */\r
29 \r
30 \r
31 /* Hardware specific includes. */\r
32 #include "mb91467d.h"\r
33 #include "vectors.h"\r
34 #include "watchdog.h"\r
35 \r
36 /* Scheduler includes. */\r
37 #include "FreeRTOS.h"\r
38 #include "task.h"\r
39 \r
40 /* Demo app includes. */\r
41 #include "flash.h"\r
42 #include "integer.h"\r
43 #include "comtest.h"\r
44 #include "PollQ.h"\r
45 #include "semtest.h"\r
46 #include "BlockQ.h"\r
47 #include "dynamic.h"\r
48 #include "flop.h"\r
49 #include "crflash.h"\r
50 #include "crhook.h"\r
51 #include "GenQTest.h"\r
52 #include "QPeek.h"\r
53 #include "BlockTim.h"\r
54 #include "death.h"\r
55 #include "taskutility.h"\r
56         \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
68 \r
69 /* Baud rate used by the COM test tasks. */\r
70 #define mainCOM_TEST_BAUD_RATE                  ( ( unsigned portLONG ) 19200 )\r
71 \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
79 \r
80 /* The total number of LEDs available. */\r
81 #define ledNUMBER_OF_LEDS               ( 8 )\r
82 \r
83 /* The first LED used by the comtest tasks. */\r
84 #define mainCOM_TEST_LED                ( 0x05 )\r
85 \r
86 /* The LED used by the check task. */\r
87 #define mainCHECK_TEST_LED              ( 0x07 )\r
88 \r
89 /* The number of interrupt levels to use. */\r
90 #define mainINTERRUPT_LEVELS    ( 31 )\r
91 \r
92 /*---------------------------------------------------------------------------*/\r
93 \r
94 /* \r
95  * The function that implements the Check task.  See the comments at the head\r
96  * of the page for implementation details.\r
97  */ \r
98 static void vErrorChecks( void *pvParameters );\r
99 \r
100 /*\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
103  */\r
104 static portSHORT prvCheckOtherTasksAreStillRunning( void );\r
105 \r
106 /* \r
107  * Setup the microcontroller as used by this demo. \r
108  */\r
109 static void prvSetupHardware( void );\r
110 \r
111 /*---------------------------------------------------------------------------*/\r
112 \r
113 /* Start all the demo application tasks, then start the scheduler. */\r
114 void main(void)\r
115 {\r
116         /* Initialise the hardware ready for the demo. */       \r
117         prvSetupHardware();\r
118         \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
133         \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
136 \r
137         /* Start the task that write trace information to the UART. */  \r
138         vUtilityStartTraceTask( mainUTILITY_TASK_PRIORITY );\r
139 \r
140         /* If we are going to service the watchdog from within a task, then create\r
141         the task here. */       \r
142         #if WATCHDOG == WTC_IN_TASK     \r
143                 vStartWatchdogTask( mainWATCHDOG_TASK_PRIORITY );\r
144         #endif          \r
145         \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
150 \r
151         /* Now start the scheduler.  Following this call the created tasks should\r
152         be executing. */        \r
153         vTaskStartScheduler( );\r
154         \r
155         /* vTaskStartScheduler() will only return if an error occurs while the \r
156         idle task is being created. */\r
157         for( ;; );\r
158 }\r
159 /*-----------------------------------------------------------*/\r
160 \r
161 static void vErrorChecks( void *pvParameters )\r
162 {\r
163 portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY;\r
164 \r
165         /* Cycle for ever, delaying then checking all the other tasks are still\r
166         operating without error. */\r
167         for( ;; )\r
168         {\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
173 \r
174                 /* See if the other tasks are all ok. */\r
175                 if( prvCheckOtherTasksAreStillRunning() != pdPASS )\r
176                 {\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
179                         LED toggle. */\r
180                         xDelayPeriod = mainERROR_CHECK_DELAY;\r
181                 }\r
182 \r
183                 /* Flash! */\r
184                 vParTestToggleLED(mainCHECK_TEST_LED);\r
185         }\r
186 }\r
187 /*-----------------------------------------------------------*/\r
188 \r
189 static portSHORT prvCheckOtherTasksAreStillRunning( void )\r
190 {\r
191 static portBASE_TYPE xErrorOccurred = pdFALSE;\r
192 \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
198 \r
199         if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
200         {\r
201                 xErrorOccurred = pdTRUE\r
202         }\r
203 \r
204         if( xArePollingQueuesStillRunning() != pdTRUE )\r
205         {\r
206                 xErrorOccurred = pdTRUE\r
207         }\r
208 \r
209         if( xAreComTestTasksStillRunning() != pdTRUE )\r
210         {\r
211                 xErrorOccurred = pdTRUE\r
212         }\r
213         \r
214         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
215         {\r
216                 xErrorOccurred = pdTRUE\r
217         }\r
218         \r
219         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
220         {\r
221                 xErrorOccurred = pdTRUE\r
222         }\r
223         \r
224         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
225         {\r
226                 xErrorOccurred = pdTRUE\r
227         }\r
228         \r
229         if( xAreMathsTaskStillRunning() != pdTRUE )\r
230         {\r
231                 xErrorOccurred = pdTRUE\r
232         }\r
233         \r
234         if( xAreFlashCoRoutinesStillRunning() != pdTRUE ) \r
235         {\r
236                 xErrorOccurred = pdTRUE\r
237         }\r
238         \r
239         if( xAreHookCoRoutinesStillRunning() != pdTRUE )\r
240         {\r
241                 xErrorOccurred = pdTRUE\r
242         }\r
243         \r
244         if( xIsCreateTaskStillRunning() != pdTRUE )\r
245         {\r
246                 xErrorOccurred = pdTRUE\r
247         }\r
248         \r
249         if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
250         {\r
251                 xErrorOccurred = pdTRUE\r
252         }\r
253         \r
254         if ( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
255         {\r
256                 xErrorOccurred = pdTRUE\r
257         }\r
258         \r
259         if ( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
260         {\r
261                 xErrorOccurred = pdTRUE\r
262         }\r
263         \r
264         return sNoErrorFound;\r
265 }\r
266 /*-----------------------------------------------------------*/\r
267 \r
268 static void prvSetupHardware( void )\r
269 {\r
270         /* Allow all interrupt levels. */\r
271         __set_il( mainINTERRUPT_LEVELS );\r
272 \r
273         /* Initialise interrupts. */\r
274         InitIrqLevels();\r
275 \r
276         /* Initialise the ports used by the LEDs. */\r
277         vParTestInitialise();\r
278 \r
279         /* If we are going to use the watchdog, then initialise it now. */\r
280         #if WATCHDOG != WTC_NONE        \r
281                 InitWatchdog();\r
282         #endif\r
283 }\r
284 /*-----------------------------------------------------------*/\r
285 \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
291         {\r
292                 /* Are we using the tick interrupt to kick the watchdog? */\r
293                 #if WATCHDOG == WTC_IN_TICK\r
294                         Kick_Watchdog();\r
295                 #endif\r
296         }\r
297 #endif\r
298 /*-----------------------------------------------------------*/\r
299 \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
304         {\r
305                 /* Are we using the idle task to kick the watchdog? */\r
306                 #if WATCHDOG == WTC_IN_IDLE\r
307                         Kick_Watchdog();\r
308                 #endif\r
309                 \r
310                 vCoRoutineSchedule();\r
311         }\r
312 #endif\r