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