]> git.sur5r.net Git - freertos/blob - Demo/MB96340_Softune/FreeRTOS_96348hs_SK16FX100PMC/Src/main.c
Add Fujitsu FX definition to portable.h.
[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 \r
175         #if ( INCLUDE_StartIntegerMathTasks == 1 )\r
176                 vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
177         #endif\r
178 \r
179         #if ( INCLUDE_AltStartComTestTasks == 1 )\r
180                 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );\r
181         #endif\r
182 \r
183         #if ( INCLUDE_StartPolledQueueTasks == 1 )\r
184                 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
185         #endif\r
186 \r
187         #if ( INCLUDE_StartSemaphoreTasks == 1 )\r
188                 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
189         #endif\r
190 \r
191         #if ( INCLUDE_StartBlockingQueueTasks == 1 )\r
192                 vStartBlockingQueueTasks( mainQUEUE_BLOCK_PRIORITY );\r
193         #endif\r
194 \r
195         #if ( INCLUDE_StartDynamicPriorityTasks == 1 )\r
196                 vStartDynamicPriorityTasks();\r
197         #endif\r
198 \r
199         #if ( INCLUDE_StartMathTasks == 1 )\r
200                 vStartMathTasks( tskIDLE_PRIORITY );\r
201         #endif\r
202 \r
203         #if ( INCLUDE_StartFlashCoRoutines == 1 )\r
204                 vStartFlashCoRoutines( ledNUMBER_OF_LEDS );\r
205         #endif\r
206 \r
207         #if ( INCLUDE_StartHookCoRoutines == 1 )\r
208                 vStartHookCoRoutines();\r
209         #endif\r
210 \r
211         #if ( INCLUDE_StartGenericQueueTasks == 1 )\r
212                 vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );\r
213         #endif\r
214 \r
215         #if ( INCLUDE_StartQueuePeekTasks == 1 )\r
216                 vStartQueuePeekTasks();\r
217         #endif\r
218 \r
219         #if ( INCLUDE_CreateBlockTimeTasks == 1 )\r
220                 vCreateBlockTimeTasks();\r
221         #endif\r
222 \r
223         #if ( INCLUDE_CreateSuicidalTasks == 1 )\r
224                 vCreateSuicidalTasks( mainDEATH_PRIORITY );\r
225         #endif\r
226 \r
227         #if ( INCLUDE_TraceListTasks == 1 )\r
228                 vTraceListTasks( TASK_UTILITY_PRIORITY );\r
229         #endif\r
230 \r
231         /* Start the 'Check' task which is defined in this file. */\r
232         xTaskCreate( vErrorChecks, (signed portCHAR *) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
233 \r
234         vTaskStartScheduler();\r
235 \r
236         /* Should not reach here */\r
237         while( 1 )\r
238         {\r
239                 __asm( " NOP " );       /*  //  */\r
240         }\r
241 }\r
242 \r
243 /*-----------------------------------------------------------*/\r
244 void vParTestToggleLED( unsigned portBASE_TYPE uxLED )\r
245 {\r
246         if( uxLED < ledNUMBER_OF_LEDS )\r
247         {\r
248                 vTaskSuspendAll();\r
249 \r
250                 /* Toggle the state of the single genuine on board LED. */\r
251                 if( (sState[0] & ((portCHAR) (1 << uxLED))) == 0 )\r
252                 {\r
253                         PDR09 |= ( 1 << uxLED );\r
254                         sState[0] |= ( 1 << uxLED );\r
255                 }\r
256                 else\r
257                 {\r
258                         PDR09 &= ~( 1 << uxLED );\r
259                         sState[0] &= ~( 1 << uxLED );\r
260                 }\r
261 \r
262                 xTaskResumeAll();\r
263         }\r
264         else\r
265         {\r
266                 vTaskSuspendAll();\r
267 \r
268                 uxLED -= ledNUMBER_OF_LEDS;\r
269 \r
270                 if( (sState[1] & ((portCHAR) (1 << uxLED))) == 0 )\r
271                 {\r
272                         PDR00 |= ( 1 << uxLED );\r
273                         sState[1] |= ( 1 << uxLED );\r
274                 }\r
275                 else\r
276                 {\r
277                         PDR00 &= ~( 1 << uxLED );\r
278                         sState[1] &= ~( 1 << uxLED );\r
279                 }\r
280 \r
281                 xTaskResumeAll();\r
282         }\r
283 }\r
284 \r
285 /*-----------------------------------------------------------*/\r
286 void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )\r
287 {\r
288         /* Set or clear the output [in this case show or hide the '*' character. */\r
289         if( uxLED < ledNUMBER_OF_LEDS )\r
290         {\r
291                 vTaskSuspendAll();\r
292                 {\r
293                         if( xValue )\r
294                         {\r
295                                 PDR09 &= ~( 1 << uxLED );\r
296                                 sState[0] &= ~( 1 << uxLED );\r
297                         }\r
298                         else\r
299                         {\r
300                                 PDR09 |= ( 1 << uxLED );\r
301                                 sState[0] |= ( 1 << uxLED );\r
302                         }\r
303                 }\r
304 \r
305                 xTaskResumeAll();\r
306         }\r
307         else\r
308         {\r
309                 vTaskSuspendAll();\r
310                 {\r
311                         if( xValue )\r
312                         {\r
313                                 PDR00 &= ~( 1 << uxLED );\r
314                                 sState[1] &= ~( 1 << uxLED );\r
315                         }\r
316                         else\r
317                         {\r
318                                 PDR00 |= ( 1 << uxLED );\r
319                                 sState[1] |= ( 1 << uxLED );\r
320                         }\r
321                 }\r
322 \r
323                 xTaskResumeAll();\r
324         }\r
325 }\r
326 \r
327 /*-----------------------------------------------------------*/\r
328 static void vErrorChecks( void *pvParameters )\r
329 {\r
330         static volatile unsigned portLONG       ulDummyVariable = 3UL;\r
331         portTickType                                            xDelayPeriod = mainNO_ERROR_CHECK_DELAY;\r
332         ( void ) pvParameters;\r
333 \r
334         /* Cycle for ever, delaying then checking all the other tasks are still\r
335         operating without error. */\r
336         for( ;; )\r
337         {\r
338                 /* Wait until it is time to check again.  The time we wait here depends\r
339                 on whether an error has been detected or not.  When an error is \r
340                 detected the time is shortened resulting in a faster LED flash rate. */\r
341                 vTaskDelay( xDelayPeriod );\r
342 \r
343                 /* Perform a bit of 32bit maths to ensure the registers used by the \r
344                 integer tasks get some exercise outside of the integer tasks \r
345                 themselves. The result here is not important we are just deliberately\r
346                 changing registers used by other tasks to ensure that their context\r
347                 switch is operating as required. - see the demo application \r
348                 documentation for more info. */\r
349                 ulDummyVariable *= 3UL;\r
350 \r
351                 /* See if the other tasks are all ok. */\r
352                 if( prvCheckOtherTasksAreStillRunning() != pdPASS )\r
353                 {\r
354                         /* An error occurred in one of the tasks so shorten the delay \r
355                         period - which has the effect of increasing the frequency of the\r
356                         LED toggle. */\r
357                         xDelayPeriod = mainERROR_CHECK_DELAY;\r
358                 }\r
359 \r
360                 /* Flash! */\r
361                 vParTestToggleLED( mainCHECK_TEST_LED );\r
362         }\r
363 }\r
364 \r
365 /*-----------------------------------------------------------*/\r
366 static portSHORT prvCheckOtherTasksAreStillRunning( void )\r
367 {\r
368         static portSHORT        sNoErrorFound = pdTRUE;\r
369 \r
370         /* The demo tasks maintain a count that increments every cycle of the task\r
371         provided that the task has never encountered an error.  This function \r
372         checks the counts maintained by the tasks to ensure they are still being\r
373         incremented.  A count remaining at the same value between calls therefore\r
374         indicates that an error has been detected.  Only tasks that do not flash\r
375         an LED are checked. */\r
376         #if ( INCLUDE_StartIntegerMathTasks == 1 )\r
377         if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
378         {\r
379                 sNoErrorFound = pdFALSE;\r
380         }\r
381 \r
382         #endif\r
383         #if ( INCLUDE_AltStartComTestTasks == 1 )\r
384         if( xAreComTestTasksStillRunning() != pdTRUE )\r
385         {\r
386                 sNoErrorFound = pdFALSE;\r
387         }\r
388 \r
389         #endif\r
390         #if ( INCLUDE_StartPolledQueueTasks == 1 )\r
391         if( xArePollingQueuesStillRunning() != pdTRUE )\r
392         {\r
393                 sNoErrorFound = pdFALSE;\r
394         }\r
395 \r
396         #endif\r
397         #if ( INCLUDE_StartSemaphoreTasks == 1 )\r
398         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
399         {\r
400                 sNoErrorFound = pdFALSE;\r
401         }\r
402 \r
403         #endif\r
404         #if ( INCLUDE_StartBlockingQueueTasks == 1 )\r
405         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
406         {\r
407                 sNoErrorFound = pdFALSE;\r
408         }\r
409 \r
410         #endif\r
411         #if ( INCLUDE_StartDynamicPriorityTasks == 1 )\r
412         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
413         {\r
414                 sNoErrorFound = pdFALSE;\r
415         }\r
416 \r
417         #endif\r
418         #if ( INCLUDE_StartMathTasks == 1 )\r
419         if( xAreMathsTaskStillRunning() != pdTRUE )\r
420         {\r
421                 sNoErrorFound = pdFALSE;\r
422         }\r
423 \r
424         #endif\r
425         #if ( INCLUDE_StartFlashCoRoutines == 1 )\r
426         if( xAreFlashCoRoutinesStillRunning() != pdTRUE )\r
427         {\r
428                 sNoErrorFound = pdFALSE;\r
429         }\r
430 \r
431         #endif\r
432         #if ( INCLUDE_StartHookCoRoutines == 1 )\r
433         if( xAreHookCoRoutinesStillRunning() != pdTRUE )\r
434         {\r
435                 sNoErrorFound = pdFALSE;\r
436         }\r
437 \r
438         #endif\r
439         #if ( INCLUDE_StartGenericQueueTasks == 1 )\r
440         if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
441         {\r
442                 sNoErrorFound = pdFALSE;\r
443         }\r
444 \r
445         #endif\r
446         #if ( INCLUDE_StartQueuePeekTasks == 1 )\r
447         if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
448         {\r
449                 sNoErrorFound = pdFALSE;\r
450         }\r
451 \r
452         #endif\r
453         #if ( INCLUDE_CreateBlockTimeTasks == 1 )\r
454         if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
455         {\r
456                 sNoErrorFound = pdFALSE;\r
457         }\r
458 \r
459         #endif\r
460         #if ( INCLUDE_CreateSuicidalTasks == 1 )\r
461         if( xIsCreateTaskStillRunning() != pdTRUE )\r
462         {\r
463                 sNoErrorFound = pdFALSE;\r
464         }\r
465 \r
466         #endif\r
467         return sNoErrorFound;\r
468 }\r
469 \r
470 /*---------------------------------------------------------------------------*/\r