]> git.sur5r.net Git - freertos/blob - Demo/MB96340_Softune/FreeRTOS_96348hs_SK16FX100PMC/Src/main.c
Tidy up 16bit Fujitsu port ready for release.
[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  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
45  * documentation provides more details of the demo application tasks.\r
46  * \r
47  * In addition to the standard demo tasks, the follow demo specific tasks are\r
48  * create:\r
49  *\r
50  * The "Check" task.  This only executes every three seconds but has the highest \r
51  * priority so is guaranteed to get processor time.  Its main function is to \r
52  * check that all the other tasks are still operational.  Most tasks maintain \r
53  * a unique count that is incremented each time the task successfully completes \r
54  * its function.  Should any error occur within such a task the count is \r
55  * permanently halted.  The check task inspects the count of each task to ensure \r
56  * it has changed since the last time the check task executed.  If all the count \r
57  * variables have changed all the tasks are still executing error free, and the \r
58  * check task toggles the onboard LED.  Should any task contain an error at any time \r
59  * the LED toggle rate will change from 3 seconds to 500ms.\r
60  *\r
61  * The "Trace Utility" task.  This can be used to obtain trace and debug \r
62  * information via UART1.\r
63  */\r
64 \r
65 \r
66 /* Scheduler includes. */\r
67 #include "FreeRTOS.h"\r
68 #include "task.h"\r
69 #include "semphr.h"\r
70 \r
71 /* Demo application includes. */\r
72 #include "flash.h"\r
73 #include "integer.h"\r
74 #include "comtest2.h"\r
75 #include "PollQ.h"\r
76 #include "semtest.h"\r
77 #include "BlockQ.h"\r
78 #include "dynamic.h"\r
79 #include "flop.h"\r
80 #include "GenQTest.h"\r
81 #include "QPeek.h"\r
82 #include "BlockTim.h"\r
83 #include "death.h"\r
84 #include "taskutility.h"\r
85 #include "partest.h"\r
86 #include "crflash.h"\r
87 #include "watchdog.h"\r
88 \r
89 /* Library includes. */\r
90 #include <watchdog.h>\r
91 \r
92 /*-----------------------------------------------------------*/\r
93 \r
94 /* Demo task priorities. */\r
95 #define WTC_TASK_PRIORITY                       ( tskIDLE_PRIORITY + 5 )\r
96 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )\r
97 #define TASK_UTILITY_PRIORITY           ( tskIDLE_PRIORITY )\r
98 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 3 )\r
99 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
100 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 2 )\r
101 #define mainQUEUE_BLOCK_PRIORITY        ( tskIDLE_PRIORITY + 2 )\r
102 #define mainDEATH_PRIORITY                      ( tskIDLE_PRIORITY + 1 )\r
103 #define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
104 #define mainGENERIC_QUEUE_PRIORITY      ( tskIDLE_PRIORITY )\r
105 \r
106 /* Baud rate used by the COM test tasks. */\r
107 #define mainCOM_TEST_BAUD_RATE  ( ( unsigned portLONG ) 19200 )\r
108 \r
109 /* The frequency at which the 'Check' tasks executes.  See the comments at the \r
110 top of the page.  When the system is operating error free the 'Check' task\r
111 toggles an LED every three seconds.  If an error is discovered in any task the\r
112 rate is increased to 500 milliseconds.  [in this case the '*' characters on the \r
113 LCD represent LED's] */\r
114 #define mainNO_ERROR_CHECK_DELAY        ( (portTickType) 3000 / portTICK_RATE_MS )\r
115 #define mainERROR_CHECK_DELAY           ( (portTickType) 500 / portTICK_RATE_MS )\r
116 \r
117 /* LED assignments for the demo tasks. */\r
118 #define mainNUM_FLASH_CO_ROUTINES       8\r
119 #define mainCOM_TEST_LED                        0x05\r
120 #define mainCHECK_TEST_LED                      0x07\r
121 \r
122 /*-----------------------------------------------------------*/\r
123 \r
124 /* \r
125  * The function that implements the Check task.  See the comments at the head\r
126  * of the page for implementation details.\r
127  */\r
128 static void     vErrorChecks( void *pvParameters );\r
129 \r
130 /*\r
131  * Called by the Check task.  Returns pdPASS if all the other tasks are found\r
132  * to be operating without error - otherwise returns pdFAIL.\r
133  */\r
134 static portSHORT prvCheckOtherTasksAreStillRunning( void );\r
135 \r
136 /*\r
137  * Perform any hardware setup necessary for the demo.\r
138  */\r
139 static void prvSetupHardware( void );\r
140 \r
141 /*-----------------------------------------------------------*/\r
142 \r
143 void main( void )\r
144 {\r
145         InitIrqLevels();                /* Initialize interrupts */\r
146         __set_il( 7 );                  /* Allow all levels      */\r
147 \r
148         prvSetupHardware();\r
149 \r
150         #if WATCHDOG == WTC_IN_TASK\r
151                 vStartWatchdogTask( WTC_TASK_PRIORITY );\r
152         #endif\r
153 \r
154         /* Start the standard demo application tasks. */\r
155         vStartLEDFlashTasks( mainLED_TASK_PRIORITY );\r
156         vStartIntegerMathTasks( tskIDLE_PRIORITY );     \r
157         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
158         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
159         vStartBlockingQueueTasks( mainQUEUE_BLOCK_PRIORITY );\r
160         vStartDynamicPriorityTasks();\r
161         vStartFlashCoRoutines( mainNUM_FLASH_CO_ROUTINES );\r
162         vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );\r
163         vCreateBlockTimeTasks();\r
164 \r
165         /* The definition INCLUDE_TraceListTasks is set within FreeRTOSConfig.h.\r
166         It should be set to 0 if using the EUROScope debugger. */\r
167         #if INCLUDE_TraceListTasks == 1\r
168                 vUtilityStartTraceTask( TASK_UTILITY_PRIORITY );\r
169         #else\r
170                 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );\r
171         #endif\r
172 \r
173         /* Start the 'Check' task which is defined in this file. */\r
174         xTaskCreate( vErrorChecks, (signed portCHAR *) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
175 \r
176         /* The suicide tasks must be started last as they record the number of other\r
177         tasks that exist within the system.  The value is then used to ensure at run\r
178         time the number of tasks that exists is within expected bounds. */\r
179         vCreateSuicidalTasks( mainDEATH_PRIORITY );\r
180 \r
181         /* Now start the scheduler.  Following this call the created tasks should\r
182         be executing. */        \r
183         vTaskStartScheduler( );\r
184         \r
185         /* vTaskStartScheduler() will only return if an error occurs while the \r
186         idle task is being created. */\r
187         for( ;; );\r
188 }\r
189 /*-----------------------------------------------------------*/\r
190 \r
191 static void prvSetupHardware( void )\r
192 {\r
193         /* Initialise the port used by the LEDs. */\r
194         vParTestInitialise();\r
195 \r
196         /* See watchdog.h for definitions relating to the watchdog use. */\r
197         #if WATCHDOG != WTC_NONE\r
198                 InitWatchdog();\r
199         #endif\r
200 }\r
201 /*-----------------------------------------------------------*/\r
202 \r
203 static void vErrorChecks( void *pvParameters )\r
204 {\r
205 portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY;\r
206 \r
207         /* Just to remove compiler warnings. */\r
208         ( void ) pvParameters;\r
209 \r
210         /* Cycle for ever, delaying then checking all the other tasks are still\r
211         operating without error. */\r
212         for( ;; )\r
213         {\r
214                 /* Wait until it is time to check again.  The time we wait here depends\r
215                 on whether an error has been detected or not.  When an error is \r
216                 detected the time is shortened resulting in a faster LED flash rate. */\r
217                 vTaskDelay( xDelayPeriod );\r
218 \r
219                 /* See if the other tasks are all ok. */\r
220                 if( prvCheckOtherTasksAreStillRunning() != pdPASS )\r
221                 {\r
222                         /* An error occurred in one of the tasks so shorten the delay \r
223                         period - which has the effect of increasing the frequency of the\r
224                         LED toggle. */\r
225                         xDelayPeriod = mainERROR_CHECK_DELAY;\r
226                 }\r
227 \r
228                 /* Flash! */\r
229                 vParTestToggleLED( mainCHECK_TEST_LED );\r
230         }\r
231 }\r
232 /*-----------------------------------------------------------*/\r
233 \r
234 static portSHORT prvCheckOtherTasksAreStillRunning( void )\r
235 {\r
236         static portSHORT        sNoErrorFound = pdTRUE;\r
237 \r
238         /* The demo tasks maintain a count that increments every cycle of the task\r
239         provided that the task has never encountered an error.  This function \r
240         checks the counts maintained by the tasks to ensure they are still being\r
241         incremented.  A count remaining at the same value between calls therefore\r
242         indicates that an error has been detected.  Only tasks that do not flash\r
243         an LED are checked. */\r
244         if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
245         {\r
246                 sNoErrorFound = pdFALSE;\r
247         }\r
248 \r
249         if( xArePollingQueuesStillRunning() != pdTRUE )\r
250         {\r
251                 sNoErrorFound = pdFALSE;\r
252         }\r
253 \r
254         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
255         {\r
256                 sNoErrorFound = pdFALSE;\r
257         }\r
258 \r
259         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
260         {\r
261                 sNoErrorFound = pdFALSE;\r
262         }\r
263 \r
264         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
265         {\r
266                 sNoErrorFound = pdFALSE;\r
267         }\r
268 \r
269         if( xAreFlashCoRoutinesStillRunning() != pdTRUE )\r
270         {\r
271                 sNoErrorFound = pdFALSE;\r
272         }\r
273 \r
274         if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
275         {\r
276                 sNoErrorFound = pdFALSE;\r
277         }\r
278 \r
279         if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
280         {\r
281                 sNoErrorFound = pdFALSE;\r
282         }\r
283 \r
284         if( xIsCreateTaskStillRunning() != pdTRUE )\r
285         {\r
286                 sNoErrorFound = pdFALSE;\r
287         }\r
288 \r
289         #if INCLUDE_TraceListTasks == 0\r
290         {\r
291                 if( xAreComTestTasksStillRunning() != pdTRUE )\r
292                 {\r
293                         sNoErrorFound = pdFALSE;\r
294                 }\r
295         }\r
296         #endif\r
297 \r
298         return sNoErrorFound;\r
299 }\r
300 /*-----------------------------------------------------------*/\r
301 \r
302 /* Idle hook function. */\r
303 #if configUSE_IDLE_HOOK == 1\r
304         void vApplicationIdleHook( void )\r
305         {\r
306                 /* Are we using the idle task to kick the watchdog?  See watchdog.h\r
307                 for watchdog kicking options. Note this is for demonstration only\r
308                 and is not a suggested method of servicing the watchdog in a real\r
309                 application. */\r
310                 #if WATCHDOG == WTC_IN_IDLE\r
311                         Kick_Watchdog();\r
312                 #endif\r
313 \r
314                 vCoRoutineSchedule();\r
315         }\r
316 #else\r
317         #if WATCHDOG == WTC_IN_IDLE\r
318                 #error configUSE_IDLE_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the idle task hook.\r
319         #endif\r
320 #endif\r
321 \r
322 /*-----------------------------------------------------------*/\r
323 \r
324 /* Tick hook function. */\r
325 #if configUSE_TICK_HOOK == 1\r
326         void vApplicationTickHook( void )\r
327         {\r
328                 /* Are we using the tick to kick the watchdog?  See watchdog.h\r
329                 for watchdog kicking options.  Note this is for demonstration\r
330                 only and is not a suggested method of servicing the watchdog in\r
331                 a real application. */\r
332                 #if WATCHDOG == WTC_IN_TICK\r
333                         Kick_Watchdog();\r
334                 #endif\r
335         }\r
336 #else\r
337         #if WATCHDOG == WTC_IN_TICK\r
338                 #error configUSE_TICK_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the tick hook.\r
339         #endif\r
340 #endif\r
341 /*-----------------------------------------------------------*/\r