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