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