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