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