]> git.sur5r.net Git - freertos/blob - Demo/MB96340_Softune/FreeRTOS_96348hs_SK16FX100PMC/Src/main.c
Renamed MAIN.c to main.c.
[freertos] / Demo / MB96340_Softune / FreeRTOS_96348hs_SK16FX100PMC / Src / main.c
1 /*\r
2         FreeRTOS.org V4.7.1 - Copyright (C) 2003-2008 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS.org distribution.\r
5 \r
6         FreeRTOS.org is free software; you can redistribute it and/or modify\r
7         it under the terms of the GNU General Public License as published by\r
8         the Free Software Foundation; either version 2 of the License, or\r
9         (at your option) any later version.\r
10 \r
11         FreeRTOS.org is distributed in the hope that it will be useful,\r
12         but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14         GNU General Public License for more details.\r
15 \r
16         You should have received a copy of the GNU General Public License\r
17         along with FreeRTOS.org; if not, write to the Free Software\r
18         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
19 \r
20         A special exception to the GPL can be applied should you wish to distribute\r
21         a combined work that includes FreeRTOS.org, without being obliged to provide\r
22         the source code for any proprietary components.  See the licensing section\r
23         of http://www.FreeRTOS.org for full details of how and when the exception\r
24         can be applied.\r
25 \r
26         ***************************************************************************\r
27 \r
28         Please ensure to read the configuration and relevant port sections of the \r
29         online documentation.\r
30 \r
31         +++ http://www.FreeRTOS.org +++\r
32         Documentation, latest information, license and contact details.  \r
33 \r
34         +++ http://www.SafeRTOS.com +++\r
35         A version that is certified for use in safety critical systems.\r
36 \r
37         +++ http://www.OpenRTOS.com +++\r
38         Commercial support, development, porting, licensing and training services.\r
39 \r
40         ***************************************************************************\r
41 */\r
42 \r
43 /*---------------------------------------------------------------------------\r
44   MAIN.C\r
45   - description\r
46   - See README.TXT for project description and disclaimer.\r
47 \r
48 /*---------------------------------------------------------------------------*/\r
49 \r
50 /* 16FX includes */\r
51 #include "mb96348hs.h"\r
52 \r
53 /* Scheduler includes. */\r
54 #include "FreeRTOS.h"\r
55 #include "task.h"\r
56 #include "semphr.h"\r
57 #include <watchdog.h>\r
58 #include <config.h>\r
59 \r
60 /*---------------------------------------------------------------------------*/\r
61 \r
62 /* Demo task priorities. */\r
63 #define WTC_TASK_PRIORITY                       ( tskIDLE_PRIORITY + 5 )\r
64 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )\r
65 #define TASK_UTILITY_PRIORITY           ( tskIDLE_PRIORITY + 3 )\r
66 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 3 )\r
67 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
68 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 2 )\r
69 #define mainQUEUE_BLOCK_PRIORITY        ( tskIDLE_PRIORITY + 2 )\r
70 #define mainDEATH_PRIORITY                      ( tskIDLE_PRIORITY + 1 )\r
71 #define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
72 #define mainGENERIC_QUEUE_PRIORITY      ( tskIDLE_PRIORITY )\r
73 \r
74 /* Baud rate used by the COM test tasks. */\r
75 #define mainCOM_TEST_BAUD_RATE  ( ( unsigned portLONG ) 19200 )\r
76 \r
77 /* The frequency at which the 'Check' tasks executes.  See the comments at the \r
78 top of the page.  When the system is operating error free the 'Check' task\r
79 toggles an LED every three seconds.  If an error is discovered in any task the\r
80 rate is increased to 500 milliseconds.  [in this case the '*' characters on the \r
81 LCD represent LED's]*/\r
82 #define mainNO_ERROR_CHECK_DELAY        ( (portTickType) 3000 / portTICK_RATE_MS )\r
83 #define mainERROR_CHECK_DELAY           ( (portTickType) 500 / portTICK_RATE_MS )\r
84 \r
85 /*---------------------------------------------------------------------------*/\r
86 #define ledNUMBER_OF_LEDS       8\r
87 #define mainCOM_TEST_LED        0x05\r
88 #define mainCHECK_TEST_LED      0x07\r
89 \r
90 /*---------------------------------------------------------------------------*/\r
91 \r
92 /* \r
93  * The function that implements the Check task.  See the comments at the head\r
94  * of the page for implementation details.\r
95  */\r
96 static void                                     vErrorChecks( void *pvParameters );\r
97 \r
98 /*\r
99  * Called by the Check task.  Returns pdPASS if all the other tasks are found\r
100  * to be operating without error - otherwise returns pdFAIL.\r
101  */\r
102 static portSHORT                        prvCheckOtherTasksAreStillRunning( void );\r
103 \r
104 /*---------------------------------------------------------------------------*/\r
105 static unsigned portCHAR        sState[2] = { 0xFF, 0xFF };\r
106 \r
107 /*---------------------------------------------------------------------------\r
108  * The below callback function is called from Tick ISR if configUSE_TICK_HOOK \r
109  * is configured as 1.\r
110  *---------------------------------------------------------------------------*/\r
111 \r
112 /*void vApplicationTickHook ( void )\r
113 {\r
114 #if WATCHDOG == WTC_IN_TICK\r
115         Kick_Watchdog();\r
116 #endif\r
117 }*/\r
118 \r
119 /*---------------------------------------------------------------------------\r
120  * The below callback function is called from Delayed ISR if configUSE_IDLE_HOOK \r
121  * is configured as 1.\r
122  *---------------------------------------------------------------------------*/\r
123 void vApplicationIdleHook( void )\r
124 {\r
125         #if WATCHDOG == WTC_IN_IDLE\r
126         Kick_Watchdog();\r
127         #endif\r
128         #if ( INCLUDE_StartFlashCoRoutines == 1 || INCLUDE_StartHookCoRoutines == 1 )\r
129         vCoRoutineSchedule();\r
130         #endif\r
131 }\r
132 \r
133 /*---------------------------------------------------------------------------\r
134  * Initialize Port 00\r
135  *---------------------------------------------------------------------------*/\r
136 static void prvInitPort00( void )\r
137 {\r
138         DDR00 = 0xFF;\r
139         PDR00 = 0xFF;\r
140         DDR09 = 0xFF;\r
141         PDR09 = 0xFF;\r
142 }\r
143 \r
144 /*---------------------------------------------------------------------------\r
145  * Setup the hardware\r
146  *---------------------------------------------------------------------------*/\r
147 static void prvSetupHardware( void )\r
148 {\r
149         prvInitPort00();\r
150 \r
151         #if WATCHDOG != WTC_NONE\r
152         InitWatchdog();\r
153         #endif\r
154 }\r
155 \r
156 /*---------------------------------------------------------------------------\r
157  * main()\r
158  *---------------------------------------------------------------------------*/\r
159 void main( void )\r
160 {\r
161         InitIrqLevels();                /* Initialize interrupts */\r
162         __set_il( 7 );                  /* Allow all levels      */\r
163 \r
164         prvSetupHardware();\r
165 \r
166         #if WATCHDOG == WTC_IN_TASK\r
167         vStartWatchdogTask( WTC_TASK_PRIORITY );\r
168         #endif\r
169 \r
170         /* Start the standard demo application tasks. */\r
171         #if ( INCLUDE_StartLEDFlashTasks == 1 )\r
172         vStartLEDFlashTasks( mainLED_TASK_PRIORITY );\r
173         #endif\r
174         #if ( INCLUDE_StartIntegerMathTasks == 1 )\r
175         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
176         #endif\r
177         #if ( INCLUDE_AltStartComTestTasks == 1 )\r
178         vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );\r
179         #endif\r
180         #if ( INCLUDE_StartPolledQueueTasks == 1 )\r
181         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
182         #endif\r
183         #if ( INCLUDE_StartSemaphoreTasks == 1 )\r
184         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
185         #endif\r
186         #if ( INCLUDE_StartBlockingQueueTasks == 1 )\r
187         vStartBlockingQueueTasks( mainQUEUE_BLOCK_PRIORITY );\r
188         #endif\r
189         #if ( INCLUDE_StartDynamicPriorityTasks == 1 )\r
190         vStartDynamicPriorityTasks();\r
191         #endif\r
192         #if ( INCLUDE_StartMathTasks == 1 )\r
193         vStartMathTasks( tskIDLE_PRIORITY );\r
194         #endif\r
195         #if ( INCLUDE_StartFlashCoRoutines == 1 )\r
196         vStartFlashCoRoutines( ledNUMBER_OF_LEDS );\r
197         #endif\r
198         #if ( INCLUDE_StartHookCoRoutines == 1 )\r
199         vStartHookCoRoutines();\r
200         #endif\r
201         #if ( INCLUDE_StartGenericQueueTasks == 1 )\r
202         vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );\r
203         #endif\r
204         #if ( INCLUDE_StartQueuePeekTasks == 1 )\r
205         vStartQueuePeekTasks();\r
206         #endif\r
207         #if ( INCLUDE_CreateBlockTimeTasks == 1 )\r
208         vCreateBlockTimeTasks();\r
209         #endif\r
210         #if ( INCLUDE_CreateSuicidalTasks == 1 )\r
211         vCreateSuicidalTasks( mainDEATH_PRIORITY );\r
212         #endif\r
213         #if ( INCLUDE_TraceListTasks == 1 )\r
214         vTraceListTasks( TASK_UTILITY_PRIORITY );\r
215         #endif\r
216 \r
217         /* Start the 'Check' task which is defined in this file. */\r
218         xTaskCreate( vErrorChecks, (signed portCHAR *) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
219 \r
220         vTaskStartScheduler();\r
221 \r
222         /* Should not reach here */\r
223         while( 1 )\r
224         {\r
225                 __asm( " NOP " );       /*  //  */\r
226         }\r
227 }\r
228 \r
229 /*-----------------------------------------------------------*/\r
230 void vParTestToggleLED( unsigned portBASE_TYPE uxLED )\r
231 {\r
232         if( uxLED < ledNUMBER_OF_LEDS )\r
233         {\r
234                 vTaskSuspendAll();\r
235 \r
236                 /* Toggle the state of the single genuine on board LED. */\r
237                 if( (sState[0] & ((portCHAR) (1 << uxLED))) == 0 )\r
238                 {\r
239                         PDR09 |= ( 1 << uxLED );\r
240                         sState[0] |= ( 1 << uxLED );\r
241                 }\r
242                 else\r
243                 {\r
244                         PDR09 &= ~( 1 << uxLED );\r
245                         sState[0] &= ~( 1 << uxLED );\r
246                 }\r
247 \r
248                 xTaskResumeAll();\r
249         }\r
250         else\r
251         {\r
252                 vTaskSuspendAll();\r
253 \r
254                 uxLED -= ledNUMBER_OF_LEDS;\r
255 \r
256                 if( (sState[1] & ((portCHAR) (1 << uxLED))) == 0 )\r
257                 {\r
258                         PDR00 |= ( 1 << uxLED );\r
259                         sState[1] |= ( 1 << uxLED );\r
260                 }\r
261                 else\r
262                 {\r
263                         PDR00 &= ~( 1 << uxLED );\r
264                         sState[1] &= ~( 1 << uxLED );\r
265                 }\r
266 \r
267                 xTaskResumeAll();\r
268         }\r
269 }\r
270 \r
271 /*-----------------------------------------------------------*/\r
272 void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )\r
273 {\r
274         /* Set or clear the output [in this case show or hide the '*' character. */\r
275         if( uxLED < ledNUMBER_OF_LEDS )\r
276         {\r
277                 vTaskSuspendAll();\r
278                 {\r
279                         if( xValue )\r
280                         {\r
281                                 PDR09 &= ~( 1 << uxLED );\r
282                                 sState[0] &= ~( 1 << uxLED );\r
283                         }\r
284                         else\r
285                         {\r
286                                 PDR09 |= ( 1 << uxLED );\r
287                                 sState[0] |= ( 1 << uxLED );\r
288                         }\r
289                 }\r
290 \r
291                 xTaskResumeAll();\r
292         }\r
293         else\r
294         {\r
295                 vTaskSuspendAll();\r
296                 {\r
297                         if( xValue )\r
298                         {\r
299                                 PDR00 &= ~( 1 << uxLED );\r
300                                 sState[1] &= ~( 1 << uxLED );\r
301                         }\r
302                         else\r
303                         {\r
304                                 PDR00 |= ( 1 << uxLED );\r
305                                 sState[1] |= ( 1 << uxLED );\r
306                         }\r
307                 }\r
308 \r
309                 xTaskResumeAll();\r
310         }\r
311 }\r
312 \r
313 /*-----------------------------------------------------------*/\r
314 static void vErrorChecks( void *pvParameters )\r
315 {\r
316         static volatile unsigned portLONG       ulDummyVariable = 3UL;\r
317         portTickType                                            xDelayPeriod = mainNO_ERROR_CHECK_DELAY;\r
318         ( void ) pvParameters;\r
319 \r
320         /* Cycle for ever, delaying then checking all the other tasks are still\r
321         operating without error. */\r
322         for( ;; )\r
323         {\r
324                 /* Wait until it is time to check again.  The time we wait here depends\r
325                 on whether an error has been detected or not.  When an error is \r
326                 detected the time is shortened resulting in a faster LED flash rate. */\r
327                 vTaskDelay( xDelayPeriod );\r
328 \r
329                 /* Perform a bit of 32bit maths to ensure the registers used by the \r
330                 integer tasks get some exercise outside of the integer tasks \r
331                 themselves. The result here is not important we are just deliberately\r
332                 changing registers used by other tasks to ensure that their context\r
333                 switch is operating as required. - see the demo application \r
334                 documentation for more info. */\r
335                 ulDummyVariable *= 3UL;\r
336 \r
337                 /* See if the other tasks are all ok. */\r
338                 if( prvCheckOtherTasksAreStillRunning() != pdPASS )\r
339                 {\r
340                         /* An error occurred in one of the tasks so shorten the delay \r
341                         period - which has the effect of increasing the frequency of the\r
342                         LED toggle. */\r
343                         xDelayPeriod = mainERROR_CHECK_DELAY;\r
344                 }\r
345 \r
346                 /* Flash! */\r
347                 vParTestToggleLED( mainCHECK_TEST_LED );\r
348         }\r
349 }\r
350 \r
351 /*-----------------------------------------------------------*/\r
352 static portSHORT prvCheckOtherTasksAreStillRunning( void )\r
353 {\r
354         static portSHORT        sNoErrorFound = pdTRUE;\r
355 \r
356         /* The demo tasks maintain a count that increments every cycle of the task\r
357         provided that the task has never encountered an error.  This function \r
358         checks the counts maintained by the tasks to ensure they are still being\r
359         incremented.  A count remaining at the same value between calls therefore\r
360         indicates that an error has been detected.  Only tasks that do not flash\r
361         an LED are checked. */\r
362         #if ( INCLUDE_StartIntegerMathTasks == 1 )\r
363         if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
364         {\r
365                 sNoErrorFound = pdFALSE;\r
366         }\r
367 \r
368         #endif\r
369         #if ( INCLUDE_AltStartComTestTasks == 1 )\r
370         if( xAreComTestTasksStillRunning() != pdTRUE )\r
371         {\r
372                 sNoErrorFound = pdFALSE;\r
373         }\r
374 \r
375         #endif\r
376         #if ( INCLUDE_StartPolledQueueTasks == 1 )\r
377         if( xArePollingQueuesStillRunning() != pdTRUE )\r
378         {\r
379                 sNoErrorFound = pdFALSE;\r
380         }\r
381 \r
382         #endif\r
383         #if ( INCLUDE_StartSemaphoreTasks == 1 )\r
384         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
385         {\r
386                 sNoErrorFound = pdFALSE;\r
387         }\r
388 \r
389         #endif\r
390         #if ( INCLUDE_StartBlockingQueueTasks == 1 )\r
391         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
392         {\r
393                 sNoErrorFound = pdFALSE;\r
394         }\r
395 \r
396         #endif\r
397         #if ( INCLUDE_StartDynamicPriorityTasks == 1 )\r
398         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
399         {\r
400                 sNoErrorFound = pdFALSE;\r
401         }\r
402 \r
403         #endif\r
404         #if ( INCLUDE_StartMathTasks == 1 )\r
405         if( xAreMathsTaskStillRunning() != pdTRUE )\r
406         {\r
407                 sNoErrorFound = pdFALSE;\r
408         }\r
409 \r
410         #endif\r
411         #if ( INCLUDE_StartFlashCoRoutines == 1 )\r
412         if( xAreFlashCoRoutinesStillRunning() != pdTRUE )\r
413         {\r
414                 sNoErrorFound = pdFALSE;\r
415         }\r
416 \r
417         #endif\r
418         #if ( INCLUDE_StartHookCoRoutines == 1 )\r
419         if( xAreHookCoRoutinesStillRunning() != pdTRUE )\r
420         {\r
421                 sNoErrorFound = pdFALSE;\r
422         }\r
423 \r
424         #endif\r
425         #if ( INCLUDE_StartGenericQueueTasks == 1 )\r
426         if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
427         {\r
428                 sNoErrorFound = pdFALSE;\r
429         }\r
430 \r
431         #endif\r
432         #if ( INCLUDE_StartQueuePeekTasks == 1 )\r
433         if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
434         {\r
435                 sNoErrorFound = pdFALSE;\r
436         }\r
437 \r
438         #endif\r
439         #if ( INCLUDE_CreateBlockTimeTasks == 1 )\r
440         if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
441         {\r
442                 sNoErrorFound = pdFALSE;\r
443         }\r
444 \r
445         #endif\r
446         #if ( INCLUDE_CreateSuicidalTasks == 1 )\r
447         if( xIsCreateTaskStillRunning() != pdTRUE )\r
448         {\r
449                 sNoErrorFound = pdFALSE;\r
450         }\r
451 \r
452         #endif\r
453         return sNoErrorFound;\r
454 }\r
455 \r
456 /*---------------------------------------------------------------------------*/\r