]> git.sur5r.net Git - freertos/blob - Demo/MB96340_Softune/FreeRTOS_96348hs_SK16FX100PMC/Src/main.c
Prepare for V5.0.4 release.
[freertos] / Demo / MB96340_Softune / FreeRTOS_96348hs_SK16FX100PMC / Src / main.c
1 /*\r
2         FreeRTOS.org V5.0.4 - Copyright (C) 2003-2008 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS.org distribution.\r
5 \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
10 \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
15 \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
19 \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
24         can be applied.\r
25 \r
26     ***************************************************************************\r
27     ***************************************************************************\r
28     *                                                                         *\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
33     *                                                                         *\r
34     ***************************************************************************\r
35     ***************************************************************************\r
36 \r
37         Please ensure to read the configuration and relevant port sections of the\r
38         online documentation.\r
39 \r
40         http://www.FreeRTOS.org - Documentation, latest information, license and \r
41         contact details.\r
42 \r
43         http://www.SafeRTOS.com - A version that is certified for use in safety \r
44         critical systems.\r
45 \r
46         http://www.OpenRTOS.com - Commercial support, development, porting, \r
47         licensing and training services.\r
48 */\r
49 \r
50 /*\r
51  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
52  * documentation provides more details of the demo application tasks.\r
53  * \r
54  * In addition to the standard demo tasks, the follow demo specific tasks are\r
55  * create:\r
56  *\r
57  * The "Check" task.  This only executes every three seconds but has the highest \r
58  * priority so is guaranteed to get processor time.  Its main function is to \r
59  * check that all the other tasks are still operational.  Most tasks maintain \r
60  * a unique count that is incremented each time the task successfully completes \r
61  * its function.  Should any error occur within such a task the count is \r
62  * permanently halted.  The check task inspects the count of each task to ensure \r
63  * it has changed since the last time the check task executed.  If all the count \r
64  * variables have changed all the tasks are still executing error free, and the \r
65  * check task toggles the onboard LED.  Should any task contain an error at any time \r
66  * the LED toggle rate will change from 3 seconds to 500ms.\r
67  *\r
68  * The "Trace Utility" task.  This can be used to obtain trace and debug \r
69  * information via UART1.\r
70  */\r
71 \r
72 \r
73 /* Scheduler includes. */\r
74 #include "FreeRTOS.h"\r
75 #include "task.h"\r
76 #include "semphr.h"\r
77 \r
78 /* Demo application includes. */\r
79 #include "flash.h"\r
80 #include "integer.h"\r
81 #include "comtest2.h"\r
82 #include "PollQ.h"\r
83 #include "semtest.h"\r
84 #include "BlockQ.h"\r
85 #include "dynamic.h"\r
86 #include "flop.h"\r
87 #include "GenQTest.h"\r
88 #include "QPeek.h"\r
89 #include "blocktim.h"\r
90 #include "death.h"\r
91 #include "taskutility.h"\r
92 #include "partest.h"\r
93 #include "crflash.h"\r
94 #include "watchdog.h"\r
95 \r
96 /* Library includes. */\r
97 #include <watchdog.h>\r
98 \r
99 /*-----------------------------------------------------------*/\r
100 \r
101 /* Demo task priorities. */\r
102 #define WTC_TASK_PRIORITY                       ( tskIDLE_PRIORITY + 5 )\r
103 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )\r
104 #define TASK_UTILITY_PRIORITY           ( tskIDLE_PRIORITY )\r
105 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 3 )\r
106 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
107 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 2 )\r
108 #define mainQUEUE_BLOCK_PRIORITY        ( tskIDLE_PRIORITY + 2 )\r
109 #define mainDEATH_PRIORITY                      ( tskIDLE_PRIORITY + 1 )\r
110 #define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
111 #define mainGENERIC_QUEUE_PRIORITY      ( tskIDLE_PRIORITY )\r
112 \r
113 /* Baud rate used by the COM test tasks. */\r
114 #define mainCOM_TEST_BAUD_RATE  ( ( unsigned portLONG ) 19200 )\r
115 \r
116 /* The frequency at which the 'Check' tasks executes.  See the comments at the \r
117 top of the page.  When the system is operating error free the 'Check' task\r
118 toggles an LED every three seconds.  If an error is discovered in any task the\r
119 rate is increased to 500 milliseconds.  [in this case the '*' characters on the \r
120 LCD represent LED's] */\r
121 #define mainNO_ERROR_CHECK_DELAY        ( (portTickType) 3000 / portTICK_RATE_MS )\r
122 #define mainERROR_CHECK_DELAY           ( (portTickType) 500 / portTICK_RATE_MS )\r
123 \r
124 /* LED assignments for the demo tasks. */\r
125 #define mainNUM_FLASH_CO_ROUTINES       8\r
126 #define mainCOM_TEST_LED                        0x05\r
127 #define mainCHECK_TEST_LED                      0x07\r
128 \r
129 /*-----------------------------------------------------------*/\r
130 \r
131 /* \r
132  * The function that implements the Check task.  See the comments at the head\r
133  * of the page for implementation details.\r
134  */\r
135 static void     vErrorChecks( void *pvParameters );\r
136 \r
137 /*\r
138  * Called by the Check task.  Returns pdPASS if all the other tasks are found\r
139  * to be operating without error - otherwise returns pdFAIL.\r
140  */\r
141 static portSHORT prvCheckOtherTasksAreStillRunning( void );\r
142 \r
143 /*\r
144  * Perform any hardware setup necessary for the demo.\r
145  */\r
146 static void prvSetupHardware( void );\r
147 \r
148 /*-----------------------------------------------------------*/\r
149 \r
150 void main( void )\r
151 {\r
152         InitIrqLevels();                /* Initialize interrupts */\r
153         __set_il( 7 );                  /* Allow all levels      */\r
154 \r
155         prvSetupHardware();\r
156 \r
157         #if WATCHDOG == WTC_IN_TASK\r
158                 vStartWatchdogTask( WTC_TASK_PRIORITY );\r
159         #endif\r
160 \r
161         /* Start the standard demo application tasks. */\r
162         vStartLEDFlashTasks( mainLED_TASK_PRIORITY );\r
163         vStartIntegerMathTasks( tskIDLE_PRIORITY );     \r
164         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
165         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
166         vStartBlockingQueueTasks( mainQUEUE_BLOCK_PRIORITY );\r
167         vStartDynamicPriorityTasks();\r
168         vStartFlashCoRoutines( mainNUM_FLASH_CO_ROUTINES );\r
169         vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );\r
170         vCreateBlockTimeTasks();\r
171 \r
172         /* The definition INCLUDE_TraceListTasks is set within FreeRTOSConfig.h. */\r
173         #if INCLUDE_TraceListTasks == 1\r
174                 vUtilityStartTraceTask( TASK_UTILITY_PRIORITY );\r
175         #else\r
176                 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );\r
177         #endif\r
178 \r
179         /* Start the 'Check' task which is defined in this file. */\r
180         xTaskCreate( vErrorChecks, (signed portCHAR *) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
181 \r
182         /* The suicide tasks must be started last as they record the number of other\r
183         tasks that exist within the system.  The value is then used to ensure at run\r
184         time the number of tasks that exists is within expected bounds. */\r
185         vCreateSuicidalTasks( mainDEATH_PRIORITY );\r
186 \r
187         /* Now start the scheduler.  Following this call the created tasks should\r
188         be executing. */        \r
189         vTaskStartScheduler( );\r
190         \r
191         /* vTaskStartScheduler() will only return if an error occurs while the \r
192         idle task is being created. */\r
193         for( ;; );\r
194 }\r
195 /*-----------------------------------------------------------*/\r
196 \r
197 static void prvSetupHardware( void )\r
198 {\r
199         /* Initialise the port used by the LEDs. */\r
200         vParTestInitialise();\r
201 \r
202         /* See watchdog.h for definitions relating to the watchdog use. */\r
203         #if WATCHDOG != WTC_NONE\r
204                 InitWatchdog();\r
205         #endif\r
206 }\r
207 /*-----------------------------------------------------------*/\r
208 \r
209 static void vErrorChecks( void *pvParameters )\r
210 {\r
211 portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY;\r
212 \r
213         /* Just to remove compiler warnings. */\r
214         ( void ) pvParameters;\r
215 \r
216         /* Cycle for ever, delaying then checking all the other tasks are still\r
217         operating without error. */\r
218         for( ;; )\r
219         {\r
220                 /* Wait until it is time to check again.  The time we wait here depends\r
221                 on whether an error has been detected or not.  When an error is \r
222                 detected the time is shortened resulting in a faster LED flash rate. */\r
223                 vTaskDelay( xDelayPeriod );\r
224 \r
225                 /* See if the other tasks are all ok. */\r
226                 if( prvCheckOtherTasksAreStillRunning() != pdPASS )\r
227                 {\r
228                         /* An error occurred in one of the tasks so shorten the delay \r
229                         period - which has the effect of increasing the frequency of the\r
230                         LED toggle. */\r
231                         xDelayPeriod = mainERROR_CHECK_DELAY;\r
232                 }\r
233 \r
234                 /* Flash! */\r
235                 vParTestToggleLED( mainCHECK_TEST_LED );\r
236         }\r
237 }\r
238 /*-----------------------------------------------------------*/\r
239 \r
240 static portSHORT prvCheckOtherTasksAreStillRunning( void )\r
241 {\r
242         static portSHORT        sNoErrorFound = pdTRUE;\r
243 \r
244         /* The demo tasks maintain a count that increments every cycle of the task\r
245         provided that the task has never encountered an error.  This function \r
246         checks the counts maintained by the tasks to ensure they are still being\r
247         incremented.  A count remaining at the same value between calls therefore\r
248         indicates that an error has been detected.  Only tasks that do not flash\r
249         an LED are checked. */\r
250         if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
251         {\r
252                 sNoErrorFound = pdFALSE;\r
253         }\r
254 \r
255         if( xArePollingQueuesStillRunning() != pdTRUE )\r
256         {\r
257                 sNoErrorFound = pdFALSE;\r
258         }\r
259 \r
260         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
261         {\r
262                 sNoErrorFound = pdFALSE;\r
263         }\r
264 \r
265         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
266         {\r
267                 sNoErrorFound = pdFALSE;\r
268         }\r
269 \r
270         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
271         {\r
272                 sNoErrorFound = pdFALSE;\r
273         }\r
274 \r
275         if( xAreFlashCoRoutinesStillRunning() != pdTRUE )\r
276         {\r
277                 sNoErrorFound = pdFALSE;\r
278         }\r
279 \r
280         if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
281         {\r
282                 sNoErrorFound = pdFALSE;\r
283         }\r
284 \r
285         if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
286         {\r
287                 sNoErrorFound = pdFALSE;\r
288         }\r
289 \r
290         if( xIsCreateTaskStillRunning() != pdTRUE )\r
291         {\r
292                 sNoErrorFound = pdFALSE;\r
293         }\r
294 \r
295         #if INCLUDE_TraceListTasks == 0\r
296         {\r
297                 if( xAreComTestTasksStillRunning() != pdTRUE )\r
298                 {\r
299                         sNoErrorFound = pdFALSE;\r
300                 }\r
301         }\r
302         #endif\r
303 \r
304         return sNoErrorFound;\r
305 }\r
306 /*-----------------------------------------------------------*/\r
307 \r
308 /* Idle hook function. */\r
309 #if configUSE_IDLE_HOOK == 1\r
310         void vApplicationIdleHook( void )\r
311         {\r
312                 /* Are we using the idle task to kick the watchdog?  See watchdog.h\r
313                 for watchdog kicking options. Note this is for demonstration only\r
314                 and is not a suggested method of servicing the watchdog in a real\r
315                 application. */\r
316                 #if WATCHDOG == WTC_IN_IDLE\r
317                         Kick_Watchdog();\r
318                 #endif\r
319 \r
320                 vCoRoutineSchedule();\r
321         }\r
322 #else\r
323         #if WATCHDOG == WTC_IN_IDLE\r
324                 #error configUSE_IDLE_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the idle task hook.\r
325         #endif\r
326 #endif\r
327 \r
328 /*-----------------------------------------------------------*/\r
329 \r
330 /* Tick hook function. */\r
331 #if configUSE_TICK_HOOK == 1\r
332         void vApplicationTickHook( void )\r
333         {\r
334                 /* Are we using the tick to kick the watchdog?  See watchdog.h\r
335                 for watchdog kicking options.  Note this is for demonstration\r
336                 only and is not a suggested method of servicing the watchdog in\r
337                 a real application. */\r
338                 #if WATCHDOG == WTC_IN_TICK\r
339                         Kick_Watchdog();\r
340                 #endif\r
341         }\r
342 #else\r
343         #if WATCHDOG == WTC_IN_TICK\r
344                 #error configUSE_TICK_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the tick hook.\r
345         #endif\r
346 #endif\r
347 /*-----------------------------------------------------------*/\r