]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MB96340_Softune/FreeRTOS_96348hs_SK16FX100PMC/Src/main.c
Update version number ready to release the FAT file system demo.
[freertos] / FreeRTOS / Demo / MB96340_Softune / FreeRTOS_96348hs_SK16FX100PMC / Src / main.c
1 /*\r
2     FreeRTOS V7.4.2 - Copyright (C) 2013 Real Time Engineers Ltd.\r
3 \r
4     FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME.  PLEASE VISIT\r
5     http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
10      *    Complete, revised, and edited pdf reference manuals are also       *\r
11      *    available.                                                         *\r
12      *                                                                       *\r
13      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
14      *    ensuring you get running as quickly as possible and with an        *\r
15      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
16      *    the FreeRTOS project to continue with its mission of providing     *\r
17      *    professional grade, cross platform, de facto standard solutions    *\r
18      *    for microcontrollers - completely free of charge!                  *\r
19      *                                                                       *\r
20      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
21      *                                                                       *\r
22      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
23      *                                                                       *\r
24     ***************************************************************************\r
25 \r
26 \r
27     This file is part of the FreeRTOS distribution.\r
28 \r
29     FreeRTOS is free software; you can redistribute it and/or modify it under\r
30     the terms of the GNU General Public License (version 2) as published by the\r
31     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
32 \r
33     >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to\r
34     distribute a combined work that includes FreeRTOS without being obliged to\r
35     provide the source code for proprietary components outside of the FreeRTOS\r
36     kernel.\r
37 \r
38     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
39     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
40     FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more\r
41     details. You should have received a copy of the GNU General Public License\r
42     and the FreeRTOS license exception along with FreeRTOS; if not it can be\r
43     viewed here: http://www.freertos.org/a00114.html and also obtained by\r
44     writing to Real Time Engineers Ltd., contact details for whom are available\r
45     on the FreeRTOS WEB site.\r
46 \r
47     1 tab == 4 spaces!\r
48 \r
49     ***************************************************************************\r
50      *                                                                       *\r
51      *    Having a problem?  Start by reading the FAQ "My application does   *\r
52      *    not run, what could be wrong?"                                     *\r
53      *                                                                       *\r
54      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
55      *                                                                       *\r
56     ***************************************************************************\r
57 \r
58 \r
59     http://www.FreeRTOS.org - Documentation, books, training, latest versions, \r
60     license and Real Time Engineers Ltd. contact details.\r
61 \r
62     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
63     including FreeRTOS+Trace - an indispensable productivity tool, and our new\r
64     fully thread aware and reentrant UDP/IP stack.\r
65 \r
66     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High \r
67     Integrity Systems, who sell the code with commercial support, \r
68     indemnification and middleware, under the OpenRTOS brand.\r
69     \r
70     http://www.SafeRTOS.com - High Integrity Systems also provide a safety \r
71     engineered and independently SIL3 certified version for use in safety and \r
72     mission critical applications that require provable dependability.\r
73 */\r
74 \r
75 /*\r
76  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
77  * documentation provides more details of the demo application tasks.\r
78  * \r
79  * In addition to the standard demo tasks, the follow demo specific tasks are\r
80  * create:\r
81  *\r
82  * The "Check" task.  This only executes every three seconds but has the highest \r
83  * priority so is guaranteed to get processor time.  Its main function is to \r
84  * check that all the other tasks are still operational.  Most tasks maintain \r
85  * a unique count that is incremented each time the task successfully completes \r
86  * its function.  Should any error occur within such a task the count is \r
87  * permanently halted.  The check task inspects the count of each task to ensure \r
88  * it has changed since the last time the check task executed.  If all the count \r
89  * variables have changed all the tasks are still executing error free, and the \r
90  * check task toggles the onboard LED.  Should any task contain an error at any time \r
91  * the LED toggle rate will change from 3 seconds to 500ms.\r
92  *\r
93  * The "Trace Utility" task.  This can be used to obtain trace and debug \r
94  * information via UART1.\r
95  */\r
96 \r
97 \r
98 /* Scheduler includes. */\r
99 #include "FreeRTOS.h"\r
100 #include "task.h"\r
101 #include "semphr.h"\r
102 \r
103 /* Demo application includes. */\r
104 #include "flash.h"\r
105 #include "integer.h"\r
106 #include "comtest2.h"\r
107 #include "PollQ.h"\r
108 #include "semtest.h"\r
109 #include "BlockQ.h"\r
110 #include "dynamic.h"\r
111 #include "flop.h"\r
112 #include "GenQTest.h"\r
113 #include "QPeek.h"\r
114 #include "blocktim.h"\r
115 #include "death.h"\r
116 #include "taskutility.h"\r
117 #include "partest.h"\r
118 #include "crflash.h"\r
119 #include "watchdog.h"\r
120 \r
121 /* Library includes. */\r
122 #include <watchdog.h>\r
123 \r
124 /*-----------------------------------------------------------*/\r
125 \r
126 /* Demo task priorities. */\r
127 #define WTC_TASK_PRIORITY                       ( tskIDLE_PRIORITY + 5 )\r
128 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )\r
129 #define TASK_UTILITY_PRIORITY           ( tskIDLE_PRIORITY )\r
130 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 3 )\r
131 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
132 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 2 )\r
133 #define mainQUEUE_BLOCK_PRIORITY        ( tskIDLE_PRIORITY + 2 )\r
134 #define mainDEATH_PRIORITY                      ( tskIDLE_PRIORITY + 1 )\r
135 #define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
136 #define mainGENERIC_QUEUE_PRIORITY      ( tskIDLE_PRIORITY )\r
137 \r
138 /* Baud rate used by the COM test tasks. */\r
139 #define mainCOM_TEST_BAUD_RATE  ( ( unsigned long ) 19200 )\r
140 \r
141 /* The frequency at which the 'Check' tasks executes.  See the comments at the \r
142 top of the page.  When the system is operating error free the 'Check' task\r
143 toggles an LED every three seconds.  If an error is discovered in any task the\r
144 rate is increased to 500 milliseconds.  [in this case the '*' characters on the \r
145 LCD represent LED's] */\r
146 #define mainNO_ERROR_CHECK_DELAY        ( (portTickType) 3000 / portTICK_RATE_MS )\r
147 #define mainERROR_CHECK_DELAY           ( (portTickType) 500 / portTICK_RATE_MS )\r
148 \r
149 /* LED assignments for the demo tasks. */\r
150 #define mainNUM_FLASH_CO_ROUTINES       8\r
151 #define mainCOM_TEST_LED                        0x05\r
152 #define mainCHECK_TEST_LED                      0x07\r
153 \r
154 /*-----------------------------------------------------------*/\r
155 \r
156 /* \r
157  * The function that implements the Check task.  See the comments at the head\r
158  * of the page for implementation details.\r
159  */\r
160 static void     vErrorChecks( void *pvParameters );\r
161 \r
162 /*\r
163  * Called by the Check task.  Returns pdPASS if all the other tasks are found\r
164  * to be operating without error - otherwise returns pdFAIL.\r
165  */\r
166 static short prvCheckOtherTasksAreStillRunning( void );\r
167 \r
168 /*\r
169  * Perform any hardware setup necessary for the demo.\r
170  */\r
171 static void prvSetupHardware( void );\r
172 \r
173 /*-----------------------------------------------------------*/\r
174 \r
175 void main( void )\r
176 {\r
177         InitIrqLevels();                /* Initialize interrupts */\r
178         __set_il( 7 );                  /* Allow all levels      */\r
179 \r
180         prvSetupHardware();\r
181 \r
182         #if WATCHDOG == WTC_IN_TASK\r
183                 vStartWatchdogTask( WTC_TASK_PRIORITY );\r
184         #endif\r
185 \r
186         /* Start the standard demo application tasks. */\r
187         vStartLEDFlashTasks( mainLED_TASK_PRIORITY );\r
188         vStartIntegerMathTasks( tskIDLE_PRIORITY );     \r
189         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
190         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
191         vStartBlockingQueueTasks( mainQUEUE_BLOCK_PRIORITY );\r
192         vStartDynamicPriorityTasks();\r
193         vStartFlashCoRoutines( mainNUM_FLASH_CO_ROUTINES );\r
194         vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );\r
195         vCreateBlockTimeTasks();\r
196 \r
197         /* The definition INCLUDE_TraceListTasks is set within FreeRTOSConfig.h. */\r
198         #if INCLUDE_TraceListTasks == 1\r
199                 vUtilityStartTraceTask( TASK_UTILITY_PRIORITY );\r
200         #else\r
201                 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );\r
202         #endif\r
203 \r
204         /* Start the 'Check' task which is defined in this file. */\r
205         xTaskCreate( vErrorChecks, (signed char *) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
206 \r
207         /* The suicide tasks must be started last as they record the number of other\r
208         tasks that exist within the system.  The value is then used to ensure at run\r
209         time the number of tasks that exists is within expected bounds. */\r
210         vCreateSuicidalTasks( mainDEATH_PRIORITY );\r
211 \r
212         /* Now start the scheduler.  Following this call the created tasks should\r
213         be executing. */        \r
214         vTaskStartScheduler( );\r
215         \r
216         /* vTaskStartScheduler() will only return if an error occurs while the \r
217         idle task is being created. */\r
218         for( ;; );\r
219 }\r
220 /*-----------------------------------------------------------*/\r
221 \r
222 static void prvSetupHardware( void )\r
223 {\r
224         /* Initialise the port used by the LEDs. */\r
225         vParTestInitialise();\r
226 \r
227         /* See watchdog.h for definitions relating to the watchdog use. */\r
228         #if WATCHDOG != WTC_NONE\r
229                 InitWatchdog();\r
230         #endif\r
231 }\r
232 /*-----------------------------------------------------------*/\r
233 \r
234 static void vErrorChecks( void *pvParameters )\r
235 {\r
236 portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY;\r
237 \r
238         /* Just to remove compiler warnings. */\r
239         ( void ) pvParameters;\r
240 \r
241         /* Cycle for ever, delaying then checking all the other tasks are still\r
242         operating without error. */\r
243         for( ;; )\r
244         {\r
245                 /* Wait until it is time to check again.  The time we wait here depends\r
246                 on whether an error has been detected or not.  When an error is \r
247                 detected the time is shortened resulting in a faster LED flash rate. */\r
248                 vTaskDelay( xDelayPeriod );\r
249 \r
250                 /* See if the other tasks are all ok. */\r
251                 if( prvCheckOtherTasksAreStillRunning() != pdPASS )\r
252                 {\r
253                         /* An error occurred in one of the tasks so shorten the delay \r
254                         period - which has the effect of increasing the frequency of the\r
255                         LED toggle. */\r
256                         xDelayPeriod = mainERROR_CHECK_DELAY;\r
257                 }\r
258 \r
259                 /* Flash! */\r
260                 vParTestToggleLED( mainCHECK_TEST_LED );\r
261         }\r
262 }\r
263 /*-----------------------------------------------------------*/\r
264 \r
265 static short prvCheckOtherTasksAreStillRunning( void )\r
266 {\r
267         static short    sNoErrorFound = pdTRUE;\r
268 \r
269         /* The demo tasks maintain a count that increments every cycle of the task\r
270         provided that the task has never encountered an error.  This function \r
271         checks the counts maintained by the tasks to ensure they are still being\r
272         incremented.  A count remaining at the same value between calls therefore\r
273         indicates that an error has been detected.  Only tasks that do not flash\r
274         an LED are checked. */\r
275         if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
276         {\r
277                 sNoErrorFound = pdFALSE;\r
278         }\r
279 \r
280         if( xArePollingQueuesStillRunning() != pdTRUE )\r
281         {\r
282                 sNoErrorFound = pdFALSE;\r
283         }\r
284 \r
285         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
286         {\r
287                 sNoErrorFound = pdFALSE;\r
288         }\r
289 \r
290         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
291         {\r
292                 sNoErrorFound = pdFALSE;\r
293         }\r
294 \r
295         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
296         {\r
297                 sNoErrorFound = pdFALSE;\r
298         }\r
299 \r
300         if( xAreFlashCoRoutinesStillRunning() != pdTRUE )\r
301         {\r
302                 sNoErrorFound = pdFALSE;\r
303         }\r
304 \r
305         if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
306         {\r
307                 sNoErrorFound = pdFALSE;\r
308         }\r
309 \r
310         if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
311         {\r
312                 sNoErrorFound = pdFALSE;\r
313         }\r
314 \r
315         if( xIsCreateTaskStillRunning() != pdTRUE )\r
316         {\r
317                 sNoErrorFound = pdFALSE;\r
318         }\r
319 \r
320         #if INCLUDE_TraceListTasks == 0\r
321         {\r
322                 if( xAreComTestTasksStillRunning() != pdTRUE )\r
323                 {\r
324                         sNoErrorFound = pdFALSE;\r
325                 }\r
326         }\r
327         #endif\r
328 \r
329         return sNoErrorFound;\r
330 }\r
331 /*-----------------------------------------------------------*/\r
332 \r
333 /* Idle hook function. */\r
334 #if configUSE_IDLE_HOOK == 1\r
335         void vApplicationIdleHook( void )\r
336         {\r
337                 /* Are we using the idle task to kick the watchdog?  See watchdog.h\r
338                 for watchdog kicking options. Note this is for demonstration only\r
339                 and is not a suggested method of servicing the watchdog in a real\r
340                 application. */\r
341                 #if WATCHDOG == WTC_IN_IDLE\r
342                         Kick_Watchdog();\r
343                 #endif\r
344 \r
345                 vCoRoutineSchedule();\r
346         }\r
347 #else\r
348         #if WATCHDOG == WTC_IN_IDLE\r
349                 #error configUSE_IDLE_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the idle task hook.\r
350         #endif\r
351 #endif\r
352 \r
353 /*-----------------------------------------------------------*/\r
354 \r
355 /* Tick hook function. */\r
356 #if configUSE_TICK_HOOK == 1\r
357         void vApplicationTickHook( void )\r
358         {\r
359                 /* Are we using the tick to kick the watchdog?  See watchdog.h\r
360                 for watchdog kicking options.  Note this is for demonstration\r
361                 only and is not a suggested method of servicing the watchdog in\r
362                 a real application. */\r
363                 #if WATCHDOG == WTC_IN_TICK\r
364                         Kick_Watchdog();\r
365                 #endif\r
366         }\r
367 #else\r
368         #if WATCHDOG == WTC_IN_TICK\r
369                 #error configUSE_TICK_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the tick hook.\r
370         #endif\r
371 #endif\r
372 /*-----------------------------------------------------------*/\r