]> git.sur5r.net Git - freertos/blob - Demo/CORTEX_Kinetis_K60_Tower_IAR/main-full.c
Ethernet working in the Kinetis K60 demo.
[freertos] / Demo / CORTEX_Kinetis_K60_Tower_IAR / main-full.c
1 /*\r
2     FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.\r
3 \r
4 \r
5         FreeRTOS supports many tools and architectures. V7.0.0 is sponsored by:\r
6         Atollic AB - Atollic provides professional embedded systems development\r
7         tools for C/C++ development, code analysis and test automation.\r
8         See http://www.atollic.com\r
9 \r
10 \r
11     ***************************************************************************\r
12      *                                                                       *\r
13      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
14      *    Complete, revised, and edited pdf reference manuals are also       *\r
15      *    available.                                                         *\r
16      *                                                                       *\r
17      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
18      *    ensuring you get running as quickly as possible and with an        *\r
19      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
20      *    the FreeRTOS project to continue with its mission of providing     *\r
21      *    professional grade, cross platform, de facto standard solutions    *\r
22      *    for microcontrollers - completely free of charge!                  *\r
23      *                                                                       *\r
24      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
25      *                                                                       *\r
26      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
27      *                                                                       *\r
28     ***************************************************************************\r
29 \r
30 \r
31     This file is part of the FreeRTOS distribution.\r
32 \r
33     FreeRTOS is free software; you can redistribute it and/or modify it under\r
34     the terms of the GNU General Public License (version 2) as published by the\r
35     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
36     >>>NOTE<<< The modification to the GPL is included to allow you to\r
37     distribute a combined work that includes FreeRTOS without being obliged to\r
38     provide the source code for proprietary components outside of the FreeRTOS\r
39     kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
40     WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
41     or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
42     more details. You should have received a copy of the GNU General Public\r
43     License and the FreeRTOS license exception along with FreeRTOS; if not it\r
44     can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
45     by writing to Richard Barry, contact details for whom are available on the\r
46     FreeRTOS WEB site.\r
47 \r
48     1 tab == 4 spaces!\r
49 \r
50     http://www.FreeRTOS.org - Documentation, latest information, license and\r
51     contact details.\r
52 \r
53     http://www.SafeRTOS.com - A version that is certified for use in safety\r
54     critical systems.\r
55 \r
56     http://www.OpenRTOS.com - Commercial support, development, porting,\r
57     licensing and training services.\r
58 */\r
59 \r
60 /*\r
61  * main-blinky.c is included when the "Blinky" build configuration is used.\r
62  * main-full.c is included when the "Full" build configuration is used.\r
63  *\r
64  * main-full.c (this file) defines a comprehensive demo that creates many\r
65  * tasks, queues, semaphores and timers.  It also demonstrates how Cortex-M3\r
66  * interrupts can interact with FreeRTOS tasks/timers.\r
67  *\r
68  * This project runs on the SK-FM3-100PMC evaluation board, which is populated\r
69  * with an MB9BF5006N Cortex-M3 based microcontroller.\r
70  *\r
71  * The main() Function:\r
72  * main() creates three demo specific software timers, one demo specific queue,\r
73  * and two demo specific tasks.  It then creates a whole host of 'standard\r
74  * demo' tasks/queues/semaphores, before starting the scheduler.  The demo\r
75  * specific tasks and timers are described in the comments here.  The standard\r
76  * demo tasks are described on the FreeRTOS.org web site.\r
77  *\r
78  * The standard demo tasks provide no specific functionality.  They are\r
79  * included to both test the FreeRTOS port, and provide examples of how the\r
80  * various FreeRTOS API functions can be used.\r
81  *\r
82  * This demo creates 43 tasks in total.  If you want a simpler demo, use the\r
83  * Blinky build configuration.\r
84  *\r
85  * The Demo Specific LED Software Timer and the Button Interrupt:\r
86  * The user button SW2 is configured to generate an interrupt each time it is\r
87  * pressed.  The interrupt service routine switches an LED on, and resets the\r
88  * LED software timer.  The LED timer has a 5000 millisecond (5 second) period,\r
89  * and uses a callback function that is defined to just turn the LED off again.\r
90  * Therefore, pressing the user button will turn the LED on, and the LED will\r
91  * remain on until a full five seconds pass without the button being pressed.\r
92  * See the documentation page for this demo on the FreeRTOS.org web site to see\r
93  * which LED is used.\r
94  *\r
95  * The Demo Specific "Check" Callback Function:\r
96  * This is called each time the 'check' timer expires.  The check timer\r
97  * callback function inspects all the standard demo tasks to see if they are\r
98  * all executing as expected.  The check timer is initially configured to\r
99  * expire every three seconds, but will shorted this to every 500ms if an error\r
100  * is ever discovered.  The check timer callback toggles the LED defined by\r
101  * the mainCHECK_LED definition each time it executes.  Therefore, if LED\r
102  * mainCHECK_LED is toggling every three seconds, then no error have been found.\r
103  * If LED mainCHECK_LED is toggling every 500ms, then at least one errors has\r
104  * been found.  The variable pcStatusMessage is set to a string that indicates\r
105  * which task reported an error.  See the documentation page for this demo on\r
106  * the FreeRTOS.org web site to see which LED in the 7 segment display is used.\r
107  *\r
108  * The Demo Specific Idle Hook Function:\r
109  * The idle hook function demonstrates how to query the amount of FreeRTOS heap\r
110  * space that is remaining (see vApplicationIdleHook() defined in this file).\r
111  *\r
112  * The Demo Specific Tick Hook Function:\r
113  * The tick hook function is used to test the interrupt safe software timer\r
114  * functionality.\r
115  */\r
116 \r
117 /* Kernel includes. */\r
118 #include "FreeRTOS.h"\r
119 #include "task.h"\r
120 #include "queue.h"\r
121 #include "timers.h"\r
122 \r
123 /* Freescale includes. */\r
124 #include "common.h"\r
125 \r
126 /* Common demo includes. */\r
127 #include "partest.h"\r
128 #include "flash.h"\r
129 #include "BlockQ.h"\r
130 #include "death.h"\r
131 #include "blocktim.h"\r
132 #include "semtest.h"\r
133 #include "GenQTest.h"\r
134 #include "QPeek.h"\r
135 #include "recmutex.h"\r
136 #include "TimerDemo.h"\r
137 #include "comtest2.h"\r
138 #include "PollQ.h"\r
139 #include "countsem.h"\r
140 #include "dynamic.h"\r
141 \r
142 /* The rate at which data is sent to the queue, specified in milliseconds, and\r
143 converted to ticks using the portTICK_RATE_MS constant. */\r
144 #define mainQUEUE_SEND_FREQUENCY_MS     ( 200 / portTICK_RATE_MS )\r
145 \r
146 /* The number of items the queue can hold.  This is 1 as the receive task\r
147 will remove items as they are added, meaning the send task should always find\r
148 the queue empty. */\r
149 #define mainQUEUE_LENGTH                        ( 1 )\r
150 \r
151 /* The LED toggled by the check timer callback function.  */\r
152 #define mainCHECK_LED                           3UL\r
153 \r
154 /* The LED turned on by the button interrupt, and turned off by the LED timer. */\r
155 #define mainTIMER_CONTROLLED_LED        2UL\r
156 \r
157 /* The LEDs toggled by the two simple flash LED timers. */\r
158 #define mainLED0                                        0UL\r
159 #define mainLED1                                        1UL\r
160 \r
161 /* The LED used by the comtest tasks. See the comtest.c file for more\r
162 information.  In this case, the LED is deliberatly out of the valid range as\r
163 all the available LEDs are already used by other tasks and timers. */\r
164 #define mainCOM_TEST_LED                        ( 4 )\r
165 \r
166 /* Constant used by the standard timer test functions. */\r
167 #define mainTIMER_TEST_PERIOD           ( 50 )\r
168 \r
169 /* Priorities used by the various different standard demo tasks. */\r
170 #define mainCHECK_TASK_PRIORITY         ( configMAX_PRIORITIES - 1 )\r
171 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 1 )\r
172 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
173 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
174 #define mainCREATOR_TASK_PRIORITY   ( tskIDLE_PRIORITY + 3 )\r
175 #define mainINTEGER_TASK_PRIORITY   ( tskIDLE_PRIORITY )\r
176 #define mainGEN_QUEUE_TASK_PRIORITY     ( tskIDLE_PRIORITY )\r
177 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
178 #define mainuIP_TASK_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
179 \r
180 /* The WEB server uses string handling functions, which in turn use a bit more\r
181 stack than most of the other tasks. */\r
182 #define mainuIP_STACK_SIZE                      ( configMINIMAL_STACK_SIZE * 3 )\r
183 \r
184 /* Priorities defined in this main-full.c file. */\r
185 #define mainQUEUE_RECEIVE_TASK_PRIORITY         ( tskIDLE_PRIORITY + 2 )\r
186 #define mainQUEUE_SEND_TASK_PRIORITY            ( tskIDLE_PRIORITY + 1 )\r
187 \r
188 /* The period at which the check timer will expire, in ms, provided no errors\r
189 have been reported by any of the standard demo tasks.  ms are converted to the\r
190 equivalent in ticks using the portTICK_RATE_MS constant. */\r
191 #define mainCHECK_TIMER_PERIOD_MS                       ( 3000UL / portTICK_RATE_MS )\r
192 \r
193 /* The period at which the check timer will expire, in ms, if an error has been\r
194 reported in one of the standard demo tasks.  ms are converted to the equivalent\r
195 in ticks using the portTICK_RATE_MS constant. */\r
196 #define mainERROR_CHECK_TIMER_PERIOD_MS         ( 500UL / portTICK_RATE_MS )\r
197 \r
198 /* The LED will remain on until the button has not been pushed for a full\r
199 5000ms. */\r
200 #define mainBUTTON_LED_TIMER_PERIOD_MS          ( 5000UL / portTICK_RATE_MS )\r
201 \r
202 /* The period at which the two simple LED flash timers will execute their\r
203 callback functions. */\r
204 #define mainLED1_TIMER_PERIOD_MS                        ( 200 / portTICK_RATE_MS )\r
205 #define mainLED2_TIMER_PERIOD_MS                        ( 600 / portTICK_RATE_MS )\r
206 \r
207 /* A block time of zero simply means "don't block". */\r
208 #define mainDONT_BLOCK                                          ( 0UL )\r
209 \r
210 /* Baud rate used by the comtest tasks. */\r
211 #define mainCOM_TEST_BAUD_RATE                          ( 115200UL )\r
212 \r
213 /* The vector used by the GPIO port E.  Button SW2 is configured to generate\r
214 an interrput on this port. */\r
215 #define mainGPIO_E_VECTOR                                       ( 107 - 16 )\r
216 \r
217 /*-----------------------------------------------------------*/\r
218 \r
219 /*\r
220  * Setup the NVIC, LED outputs, and button inputs.\r
221  */\r
222 static void prvSetupHardware( void );\r
223 \r
224 /*\r
225  * Creates the timers that are specific to this demo - namely, the check timer\r
226  * the button LED timer, and the two simple LED flash timers.\r
227  */\r
228 static void prvCreateDemoSpecificTimers( void );\r
229 \r
230 /*\r
231  * The LED timer callback function.  This does nothing but switch an LED off.\r
232  */\r
233 static void prvButtonLEDTimerCallback( xTimerHandle xTimer );\r
234 \r
235 /*\r
236  * The callback function used by both simple LED flash timers.  Both timers use\r
237  * the same callback, so the function parameter is used to determine which LED\r
238  * should be flashed (effectively to determine which timer has expired.\r
239  */\r
240 static void prvLEDTimerCallback( xTimerHandle xTimer );\r
241 \r
242 /*\r
243  * The check timer callback function, as described at the top of this file.\r
244  */\r
245 static void prvCheckTimerCallback( xTimerHandle xTimer );\r
246 \r
247 /*\r
248  * This is not a 'standard' partest function, so the prototype is not in\r
249  * partest.h, and is instead included here.\r
250  */\r
251 void vParTestSetLEDFromISR( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue );\r
252 \r
253 /*\r
254  * Contains the implementation of the WEB server.\r
255  */\r
256 extern void vuIP_Task( void *pvParameters );\r
257 \r
258 /*-----------------------------------------------------------*/\r
259 \r
260 /* The queue used by both application specific demo tasks defined in this file. */\r
261 static xQueueHandle xQueue = NULL;\r
262 \r
263 /* The LED software timer.  This uses prvButtonLEDTimerCallback() as it's callback\r
264 function. */\r
265 static xTimerHandle xLEDTimer = NULL;\r
266 \r
267 /* The check timer.  This uses prvCheckTimerCallback() as its callback\r
268 function. */\r
269 static xTimerHandle xCheckTimer = NULL;\r
270 \r
271 /* LED timers - these simply flash LEDs, each using a different frequency. */\r
272 static xTimerHandle xLED1Timer = NULL, xLED2Timer = NULL;\r
273 \r
274 /* If an error is detected in a standard demo task, then pcStatusMessage will\r
275 be set to point to a string that identifies the offending task.  This is just\r
276 to make debugging easier. */\r
277 static const char *pcStatusMessage = NULL;\r
278 \r
279 /*-----------------------------------------------------------*/\r
280 \r
281 void main( void )\r
282 {\r
283         /* Configure the NVIC, LED outputs and button inputs. */\r
284         prvSetupHardware();\r
285 \r
286         /* Create the queue. */\r
287         xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );\r
288 \r
289         if( xQueue != NULL )\r
290         {\r
291                 /* Create the timers that are specific to this demo - other timers are\r
292                 created as part of the standard demo within vStartTimerDemoTask. */\r
293                 prvCreateDemoSpecificTimers();\r
294 \r
295                 /* Create a lot of 'standard demo' tasks.  Over 40 tasks are created in\r
296                 this demo.  For a much simpler demo, select the 'blinky' build\r
297                 configuration. */\r
298                 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
299                 vCreateBlockTimeTasks();\r
300                 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
301                 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
302                 vStartQueuePeekTasks();\r
303                 vStartRecursiveMutexTasks();\r
304                 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );\r
305 //_RB_          vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
306                 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
307                 vStartCountingSemaphoreTasks();\r
308                 vStartDynamicPriorityTasks();\r
309                 \r
310                 /* The web server task. */\r
311                 xTaskCreate( vuIP_Task, "uIP", mainuIP_STACK_SIZE, NULL, mainuIP_TASK_PRIORITY, NULL );\r
312 \r
313                 /* The suicide tasks must be created last, as they need to know how many\r
314                 tasks were running prior to their creation in order to ascertain whether\r
315                 or not the correct/expected number of tasks are running at any given\r
316                 time. */\r
317                 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
318 \r
319                 /* Start the tasks and timer running. */\r
320                 vTaskStartScheduler();\r
321         }\r
322 \r
323         /* If all is well, the scheduler will now be running, and the following line\r
324         will never be reached.  If the following line does execute, then there was\r
325         insufficient FreeRTOS heap memory available for the idle and/or timer tasks\r
326         to be created.  See the memory management section on the FreeRTOS web site\r
327         for more details. */\r
328         for( ;; );\r
329 }\r
330 /*-----------------------------------------------------------*/\r
331 \r
332 static void prvCheckTimerCallback( xTimerHandle xTimer )\r
333 {\r
334 static long lChangedTimerPeriodAlready = pdFALSE;\r
335 \r
336         /* Check the standard demo tasks are running without error.   Latch the\r
337         latest reported error in the pcStatusMessage character pointer. */\r
338         if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
339         {\r
340                 pcStatusMessage = "Error: GenQueue";\r
341         }\r
342 \r
343         if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
344         {\r
345                 pcStatusMessage = "Error: QueuePeek\n";\r
346         }\r
347 \r
348         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
349         {\r
350                 pcStatusMessage = "Error: BlockQueue\n";\r
351         }\r
352 \r
353         if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
354         {\r
355                 pcStatusMessage = "Error: BlockTime\n";\r
356         }\r
357 \r
358         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
359         {\r
360                 pcStatusMessage = "Error: SemTest\n";\r
361         }\r
362 \r
363         if( xIsCreateTaskStillRunning() != pdTRUE )\r
364         {\r
365                 pcStatusMessage = "Error: Death\n";\r
366         }\r
367 \r
368         if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
369         {\r
370                 pcStatusMessage = "Error: RecMutex\n";\r
371         }\r
372 \r
373 if( 0 )//_RB_   if( xAreComTestTasksStillRunning() != pdPASS )\r
374         {\r
375                 pcStatusMessage = "Error: ComTest\n";\r
376         }\r
377         \r
378         if( xAreTimerDemoTasksStillRunning( ( mainCHECK_TIMER_PERIOD_MS ) ) != pdTRUE )\r
379         {\r
380                 pcStatusMessage = "Error: TimerDemo\n";\r
381         }\r
382 \r
383         if( xArePollingQueuesStillRunning() != pdTRUE )\r
384         {\r
385                 pcStatusMessage = "Error: PollQueue\n";\r
386         }\r
387 \r
388         if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )\r
389         {\r
390                 pcStatusMessage = "Error: CountSem\n";\r
391         }\r
392         \r
393         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
394         {\r
395                 pcStatusMessage = "Error: DynamicPriority\n";\r
396         }\r
397         \r
398         /* Toggle the check LED to give an indication of the system status.  If\r
399         the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then\r
400         everything is ok.  A faster toggle indicates an error. */\r
401         vParTestToggleLED( mainCHECK_LED );\r
402 \r
403         /* Have any errors been latch in pcStatusMessage?  If so, shorten the\r
404         period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.\r
405         This will result in an increase in the rate at which mainCHECK_LED\r
406         toggles. */\r
407         if( pcStatusMessage != NULL )\r
408         {\r
409                 if( lChangedTimerPeriodAlready == pdFALSE )\r
410                 {\r
411                         lChangedTimerPeriodAlready = pdTRUE;\r
412                         printf( "%s", pcStatusMessage );\r
413                         \r
414                         /* This call to xTimerChangePeriod() uses a zero block time.  Functions\r
415                         called from inside of a timer callback function must *never* attempt\r
416                         to block. */\r
417                         xTimerChangePeriod( xCheckTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );\r
418                 }\r
419         }\r
420 }\r
421 /*-----------------------------------------------------------*/\r
422 \r
423 static void prvButtonLEDTimerCallback( xTimerHandle xTimer )\r
424 {\r
425         /* The timer has expired - so no button pushes have occurred in the last\r
426         five seconds - turn the LED off. */\r
427         vParTestSetLED( mainTIMER_CONTROLLED_LED, pdFALSE );\r
428 }\r
429 /*-----------------------------------------------------------*/\r
430 \r
431 static void prvLEDTimerCallback( xTimerHandle xTimer )\r
432 {\r
433 unsigned long ulLED;\r
434 \r
435         /* This callback is shared by two timers, so the parameter is used to\r
436         determine which LED to toggle.  The LED number is stored in the ID of the\r
437         timer. */\r
438         ulLED = ( unsigned long ) pvTimerGetTimerID( xTimer );\r
439         vParTestToggleLED( ulLED );\r
440 }\r
441 /*-----------------------------------------------------------*/\r
442 \r
443 /* The ISR executed when the user button is pushed. */\r
444 void vPort_E_ISRHandler( void )\r
445 {\r
446 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
447 \r
448         /* The button was pushed, so ensure the LED is on before resetting the\r
449         LED timer.  The LED timer will turn the LED off if the button is not\r
450         pushed within 5000ms. */\r
451         vParTestSetLED( mainTIMER_CONTROLLED_LED, pdTRUE );\r
452 \r
453         /* This interrupt safe FreeRTOS function can be called from this interrupt\r
454         because the interrupt priority is below the\r
455         configMAX_SYSCALL_INTERRUPT_PRIORITY setting in FreeRTOSConfig.h. */\r
456         xTimerResetFromISR( xLEDTimer, &xHigherPriorityTaskWoken );\r
457 \r
458         /* Clear the interrupt before leaving.  This just clears all the interrupts\r
459         for simplicity, as only one is actually used in this simple demo anyway. */\r
460         PORTE_ISFR = 0xFFFFFFFFUL;\r
461 \r
462         /* If calling xTimerResetFromISR() caused a task (in this case the timer\r
463         service/daemon task) to unblock, and the unblocked task has a priority\r
464         higher than or equal to the task that was interrupted, then\r
465         xHigherPriorityTaskWoken will now be set to pdTRUE, and calling\r
466         portEND_SWITCHING_ISR() will ensure the unblocked task runs next. */\r
467         portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );\r
468 }\r
469 /*-----------------------------------------------------------*/\r
470 \r
471 static void prvSetupHardware( void )\r
472 {\r
473         /* Enable the interrupt on SW1. */\r
474         taskDISABLE_INTERRUPTS();\r
475         PORTE_PCR26 = PORT_PCR_MUX( 1 ) | PORT_PCR_IRQC( 0xA ) | PORT_PCR_PE_MASK | PORT_PCR_PS_MASK;\r
476         enable_irq( mainGPIO_E_VECTOR );\r
477         set_irq_priority( mainGPIO_E_VECTOR, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );\r
478         \r
479         /* Configure the LED outputs. */\r
480         vParTestInitialise();\r
481 }\r
482 /*-----------------------------------------------------------*/\r
483 \r
484 static void prvCreateDemoSpecificTimers( void )\r
485 {\r
486         /* This function creates the timers, but does not start them.  This is\r
487         because the standard demo timer test is started after this function is\r
488         called.  The standard demo timer test will deliberatly fill the timer\r
489         command queue - and will fail the test if the command queue already holds\r
490         start commands for the timers created here.  Instead, the timers created in\r
491         this function are started from the idle task, at which time, the timer\r
492         service/daemon task will be running, and will have drained the timer command\r
493         queue. */\r
494         \r
495         /* Create the software timer that is responsible for turning off the LED\r
496         if the button is not pushed within 5000ms, as described at the top of\r
497         this file. */\r
498         xLEDTimer = xTimerCreate(       ( const signed char * ) "ButtonLEDTimer",       /* A text name, purely to help debugging. */\r
499                                                                 ( mainBUTTON_LED_TIMER_PERIOD_MS ),                     /* The timer period, in this case 5000ms (5s). */\r
500                                                                 pdFALSE,                                                                        /* This is a one shot timer, so xAutoReload is set to pdFALSE. */\r
501                                                                 ( void * ) 0,                                                           /* The ID is not used, so can be set to anything. */\r
502                                                                 prvButtonLEDTimerCallback                                       /* The callback function that switches the LED off. */\r
503                                                         );\r
504 \r
505         /* Create the software timer that performs the 'check' functionality,\r
506         as described at the top of this file. */\r
507         xCheckTimer = xTimerCreate( ( const signed char * ) "CheckTimer",/* A text name, purely to help debugging. */\r
508                                                                 ( mainCHECK_TIMER_PERIOD_MS ),          /* The timer period, in this case 3000ms (3s). */\r
509                                                                 pdTRUE,                                                         /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */\r
510                                                                 ( void * ) 0,                                           /* The ID is not used, so can be set to anything. */\r
511                                                                 prvCheckTimerCallback                           /* The callback function that inspects the status of all the other tasks. */\r
512                                                           );\r
513         \r
514         /* Create the software timers used to simply flash LEDs.  These two timers\r
515         share a callback function, so the callback parameter is used to pass in the\r
516         LED that should be toggled. */\r
517         xLED1Timer = xTimerCreate( ( const signed char * ) "LED1Timer",/* A text name, purely to help debugging. */\r
518                                                                 ( mainLED1_TIMER_PERIOD_MS ),           /* The timer period, in this case 3000ms (3s). */\r
519                                                                 pdTRUE,                                                         /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */\r
520                                                                 ( void * ) mainLED0,                            /* The ID is used to pass in the number of the LED to be toggled. */\r
521                                                                 prvLEDTimerCallback                                     /* The callback function simply toggles the LED specified by its parameter. */\r
522                                                           );\r
523 \r
524         xLED2Timer = xTimerCreate( ( const signed char * ) "LED2Timer",/* A text name, purely to help debugging. */\r
525                                                                 ( mainLED2_TIMER_PERIOD_MS ),           /* The timer period, in this case 3000ms (3s). */\r
526                                                                 pdTRUE,                                                         /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */\r
527                                                                 ( void * ) mainLED1,                            /* The ID is used to pass in the number of the LED to be toggled. */\r
528                                                                 prvLEDTimerCallback                                     /* The callback function simply toggles the LED specified by its parameter. */\r
529                                                           );\r
530 }\r
531 /*-----------------------------------------------------------*/\r
532 \r
533 void vApplicationMallocFailedHook( void )\r
534 {\r
535         /* Called if a call to pvPortMalloc() fails because there is insufficient\r
536         free memory available in the FreeRTOS heap.  pvPortMalloc() is called\r
537         internally by FreeRTOS API functions that create tasks, queues, software\r
538         timers, and semaphores.  The size of the FreeRTOS heap is set by the\r
539         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */\r
540         taskDISABLE_INTERRUPTS();\r
541         for( ;; );\r
542 }\r
543 /*-----------------------------------------------------------*/\r
544 \r
545 void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )\r
546 {\r
547         ( void ) pcTaskName;\r
548         ( void ) pxTask;\r
549 \r
550         /* Run time stack overflow checking is performed if\r
551         configconfigCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
552         function is called if a stack overflow is detected. */\r
553         taskDISABLE_INTERRUPTS();\r
554         for( ;; );\r
555 }\r
556 /*-----------------------------------------------------------*/\r
557 \r
558 void vApplicationIdleHook( void )\r
559 {\r
560 static long lPrintedOut = pdFALSE;\r
561 volatile size_t xFreeHeapSpace;\r
562 \r
563         if( lPrintedOut == pdFALSE )\r
564         {\r
565                 lPrintedOut = pdTRUE;\r
566 \r
567                 /* The timer command queue will have been filled when the timer test\r
568                 tasks were created in main() (this is part of the test they perform).\r
569                 Therefore, while the check and LED timers can be created in main(), they\r
570                 cannot be started from main().  Once the scheduler has started, the timer\r
571                 service task will drain the command queue, and now the check and digit\r
572                 counter timers can be started successfully. */\r
573                 xTimerStart( xCheckTimer, portMAX_DELAY );\r
574                 xTimerStart( xLED1Timer, portMAX_DELAY );\r
575                 xTimerStart( xLED2Timer, portMAX_DELAY );\r
576                 \r
577                 xFreeHeapSpace = xPortGetFreeHeapSize();\r
578                 printf( "%d bytes of FreeRTOS heap remain unused\nconfigTOTAL_HEAP_SIZE can be reduced\n", xFreeHeapSpace );\r
579                 \r
580                 if( xFreeHeapSpace > 100 )\r
581                 {\r
582                         /* By now, the kernel has allocated everything it is going to, so\r
583                         if there is a lot of heap remaining unallocated then\r
584                         the value of configTOTAL_HEAP_SIZE in FreeRTOSConfig.h can be\r
585                         reduced accordingly. */\r
586                 }\r
587         }\r
588 }\r
589 /*-----------------------------------------------------------*/\r
590 \r
591 void vApplicationTickHook( void )\r
592 {\r
593         /* Call the periodic timer test, which tests the timer API functions that\r
594         can be called from an ISR. */\r
595         vTimerPeriodicISRTests();\r
596 }       \r
597 /*-----------------------------------------------------------*/\r
598 \r
599 char *pcGetTaskStatusMessage( void )\r
600 {\r
601         /* Not bothered about a critical section here although technically because\r
602         of the task priorities the pointer could change it will be atomic if not\r
603         near atomic and its not critical. */\r
604         if( pcStatusMessage == NULL )\r
605         {\r
606                 return "All tasks running without error";\r
607         }\r
608         else\r
609         {\r
610                 return ( char * ) pcStatusMessage;\r
611         }\r
612 }\r
613 /*-----------------------------------------------------------*/\r