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