2 FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 ***************************************************************************
\r
46 * Having a problem? Start by reading the FAQ "My application does *
\r
47 * not run, what could be wrong? *
\r
49 * http://www.FreeRTOS.org/FAQHelp.html *
\r
51 ***************************************************************************
\r
54 http://www.FreeRTOS.org - Documentation, training, latest information,
\r
55 license and contact details.
\r
57 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
58 including FreeRTOS+Trace - an indispensable productivity tool.
\r
60 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
61 the code with commercial support, indemnification, and middleware, under
\r
62 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
63 provide a safety engineered and independently SIL3 certified version under
\r
64 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
68 * main-blinky.c is included when the "Blinky" build configuration is used.
\r
69 * main-full.c is included when the "Full" build configuration is used.
\r
71 * main-full.c (this file) defines a comprehensive demo that creates many
\r
72 * tasks, queues, semaphores and timers. It also demonstrates how Cortex-M3
\r
73 * interrupts can interact with FreeRTOS tasks/timers.
\r
75 * This project runs on the SK-FM3-100PMC evaluation board, which is populated
\r
76 * with an MB9BF5006N Cortex-M3 based microcontroller.
\r
78 * The main() Function:
\r
79 * main() creates three demo specific software timers, one demo specific queue,
\r
80 * and two demo specific tasks. It then creates a whole host of 'standard
\r
81 * demo' tasks/queues/semaphores, before starting the scheduler. The demo
\r
82 * specific tasks and timers are described in the comments here. The standard
\r
83 * demo tasks are described on the FreeRTOS.org web site.
\r
85 * The standard demo tasks provide no specific functionality. They are
\r
86 * included to both test the FreeRTOS port, and provide examples of how the
\r
87 * various FreeRTOS API functions can be used.
\r
89 * This demo creates 43 tasks in total. If you want a simpler demo, use the
\r
90 * Blinky build configuration.
\r
92 * The Demo Specific Queue Send Task:
\r
93 * The queue send task is implemented by the prvQueueSendTask() function in
\r
94 * this file. prvQueueSendTask() sits in a loop that causes it to repeatedly
\r
95 * block for 200 milliseconds, before sending the value 100 to the queue that
\r
96 * was created within main(). Once the value is sent, the task loops back
\r
97 * around to block for another 200 milliseconds.
\r
99 * The Demo Specific Queue Receive Task:
\r
100 * The queue receive task is implemented by the prvQueueReceiveTask() function
\r
101 * in this file. prvQueueReceiveTask() sits in a loop that causes it to
\r
102 * repeatedly attempt to read data from the queue that was created within
\r
103 * main(). When data is received, the task checks the value of the data, and
\r
104 * if the value equals the expected 100, toggles an LED in the 7 segment display
\r
105 * (see the documentation page for this demo on the FreeRTOS.org site to see
\r
106 * which LED is used). The 'block time' parameter passed to the queue receive
\r
107 * function specifies that the task should be held in the Blocked state
\r
108 * indefinitely to wait for data to be available on the queue. The queue
\r
109 * receive task will only leave the Blocked state when the queue send task
\r
110 * writes to the queue. As the queue send task writes to the queue every 200
\r
111 * milliseconds, the queue receive task leaves the Blocked state every 200
\r
112 * milliseconds, and therefore toggles the LED every 200 milliseconds.
\r
114 * The Demo Specific LED Software Timer and the Button Interrupt:
\r
115 * The user button SW2 is configured to generate an interrupt each time it is
\r
116 * pressed. The interrupt service routine switches an LED on, and resets the
\r
117 * LED software timer. The LED timer has a 5000 millisecond (5 second) period,
\r
118 * and uses a callback function that is defined to just turn the LED off again.
\r
119 * Therefore, pressing the user button will turn the LED on, and the LED will
\r
120 * remain on until a full five seconds pass without the button being pressed.
\r
121 * See the documentation page for this demo on the FreeRTOS.org web site to see
\r
122 * which LED is used.
\r
124 * The Demo Specific "Check" Callback Function:
\r
125 * This is called each time the 'check' timer expires. The check timer
\r
126 * callback function inspects all the standard demo tasks to see if they are
\r
127 * all executing as expected. The check timer is initially configured to
\r
128 * expire every three seconds, but will shorted this to every 500ms if an error
\r
129 * is ever discovered. The check timer callback toggles the LED defined by
\r
130 * the mainCHECK_LED definition each time it executes. Therefore, if LED
\r
131 * mainCHECK_LED is toggling every three seconds, then no error have been found.
\r
132 * If LED mainCHECK_LED is toggling every 500ms, then at least one errors has
\r
133 * been found. The variable pcStatusMessage is set to a string that indicates
\r
134 * which task reported an error. See the documentation page for this demo on
\r
135 * the FreeRTOS.org web site to see which LED in the 7 segment display is used.
\r
137 * The Demo Specific "Digit Counter" Callback Function:
\r
138 * This is called each time the 'digit counter' timer expires. It causes the
\r
139 * digits 0 to 9 to be displayed in turn as the first character of the two
\r
140 * character display. The LEDs in the other digit of the two character
\r
141 * display are used as general purpose LEDs, as described in this comment block.
\r
143 * The Demo Specific Idle Hook Function:
\r
144 * The idle hook function demonstrates how to query the amount of FreeRTOS heap
\r
145 * space that is remaining (see vApplicationIdleHook() defined in this file).
\r
147 * The Demo Specific Tick Hook Function:
\r
148 * The tick hook function is used to test the interrupt safe software timer
\r
152 /* Kernel includes. */
\r
153 #include "FreeRTOS.h"
\r
156 #include "timers.h"
\r
158 /* Fujitsu drivers/libraries. */
\r
159 #include "mb9bf506n.h"
\r
160 #include "system_mb9bf50x.h"
\r
162 /* Common demo includes. */
\r
163 #include "partest.h"
\r
165 #include "BlockQ.h"
\r
167 #include "blocktim.h"
\r
168 #include "semtest.h"
\r
169 #include "GenQTest.h"
\r
171 #include "recmutex.h"
\r
172 #include "TimerDemo.h"
\r
173 #include "comtest2.h"
\r
175 #include "countsem.h"
\r
176 #include "dynamic.h"
\r
178 /* The rate at which data is sent to the queue, specified in milliseconds, and
\r
179 converted to ticks using the portTICK_RATE_MS constant. */
\r
180 #define mainQUEUE_SEND_FREQUENCY_MS ( 200 / portTICK_RATE_MS )
\r
182 /* The number of items the queue can hold. This is 1 as the receive task
\r
183 will remove items as they are added, meaning the send task should always find
\r
184 the queue empty. */
\r
185 #define mainQUEUE_LENGTH ( 1 )
\r
187 /* The LED toggled by the check timer callback function. This is an LED in the
\r
188 second digit of the two digit 7 segment display. See the documentation page
\r
189 for this demo on the FreeRTOS.org web site to see which LED this relates to. */
\r
190 #define mainCHECK_LED 0x07UL
\r
192 /* The LED toggle by the queue receive task. This is an LED in the second digit
\r
193 of the two digit 7 segment display. See the documentation page for this demo on
\r
194 the FreeRTOS.org web site to see which LED this relates to. */
\r
195 #define mainTASK_CONTROLLED_LED 0x06UL
\r
197 /* The LED turned on by the button interrupt, and turned off by the LED timer.
\r
198 This is an LED in the second digit of the two digit 7 segment display. See the
\r
199 documentation page for this demo on the FreeRTOS.org web site to see which LED
\r
200 this relates to. */
\r
201 #define mainTIMER_CONTROLLED_LED 0x05UL
\r
203 /* The LED used by the comtest tasks. See the comtest.c file for more
\r
204 information. The LEDs used by the comtest task are in the second digit of the
\r
205 two digit 7 segment display. See the documentation page for this demo on the
\r
206 FreeRTOS.org web site to see which LEDs this relates to. */
\r
207 #define mainCOM_TEST_LED ( 3 )
\r
209 /* Constant used by the standard timer test functions. */
\r
210 #define mainTIMER_TEST_PERIOD ( 50 )
\r
212 /* Priorities used by the various different standard demo tasks. */
\r
213 #define mainCHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
\r
214 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
215 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
216 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
217 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
218 #define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
219 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
220 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
221 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
223 /* Priorities defined in this main-full.c file. */
\r
224 #define mainQUEUE_RECEIVE_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
225 #define mainQUEUE_SEND_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
227 /* The period at which the check timer will expire, in ms, provided no errors
\r
228 have been reported by any of the standard demo tasks. ms are converted to the
\r
229 equivalent in ticks using the portTICK_RATE_MS constant. */
\r
230 #define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_RATE_MS )
\r
232 /* The period at which the check timer will expire, in ms, if an error has been
\r
233 reported in one of the standard demo tasks. ms are converted to the equivalent
\r
234 in ticks using the portTICK_RATE_MS constant. */
\r
235 #define mainERROR_CHECK_TIMER_PERIOD_MS ( 500UL / portTICK_RATE_MS )
\r
237 /* The period at which the digit counter timer will expire, in ms, and converted
\r
238 to ticks using the portTICK_RATE_MS constant. */
\r
239 #define mainDIGIT_COUNTER_TIMER_PERIOD_MS ( 250UL / portTICK_RATE_MS )
\r
241 /* The LED will remain on until the button has not been pushed for a full
\r
243 #define mainLED_TIMER_PERIOD_MS ( 5000UL / portTICK_RATE_MS )
\r
245 /* A zero block time. */
\r
246 #define mainDONT_BLOCK ( 0UL )
\r
248 /* Baud rate used by the comtest tasks. */
\r
249 #define mainCOM_TEST_BAUD_RATE ( 115200UL )
\r
251 /*-----------------------------------------------------------*/
\r
254 * Setup the NVIC, LED outputs, and button inputs.
\r
256 static void prvSetupHardware( void );
\r
259 * The application specific (not common demo) tasks as described in the comments
\r
260 * at the top of this file.
\r
262 static void prvQueueReceiveTask( void *pvParameters );
\r
263 static void prvQueueSendTask( void *pvParameters );
\r
266 * The LED timer callback function. This does nothing but switch an LED off.
\r
268 static void prvLEDTimerCallback( xTimerHandle xTimer );
\r
271 * The check timer callback function, as described at the top of this file.
\r
273 static void prvCheckTimerCallback( xTimerHandle xTimer );
\r
276 * The digit counter callback function, as described at the top of this file.
\r
278 static void prvDigitCounterTimerCallback( xTimerHandle xTimer );
\r
281 * This is not a 'standard' partest function, so the prototype is not in
\r
282 * partest.h, and is instead included here.
\r
284 void vParTestSetLEDFromISR( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue );
\r
286 /*-----------------------------------------------------------*/
\r
288 /* The queue used by both application specific demo tasks defined in this file. */
\r
289 static xQueueHandle xQueue = NULL;
\r
291 /* The LED software timer. This uses prvLEDTimerCallback() as it's callback
\r
293 static xTimerHandle xLEDTimer = NULL;
\r
295 /* The digit counter software timer. This displays a counting digit on one half
\r
296 of the seven segment displays. */
\r
297 static xTimerHandle xDigitCounterTimer = NULL;
\r
299 /* The check timer. This uses prvCheckTimerCallback() as its callback
\r
301 static xTimerHandle xCheckTimer = NULL;
\r
303 /* If an error is detected in a standard demo task, then pcStatusMessage will
\r
304 be set to point to a string that identifies the offending task. This is just
\r
305 to make debugging easier. */
\r
306 static const char *pcStatusMessage = NULL;
\r
308 /*-----------------------------------------------------------*/
\r
312 /* Configure the NVIC, LED outputs and button inputs. */
\r
313 prvSetupHardware();
\r
315 /* Create the queue. */
\r
316 xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );
\r
318 if( xQueue != NULL )
\r
320 /* Start the two application specific demo tasks, as described in the
\r
321 comments at the top of this file. */
\r
322 xTaskCreate( prvQueueReceiveTask, ( signed char * ) "Rx", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_RECEIVE_TASK_PRIORITY, NULL );
\r
323 xTaskCreate( prvQueueSendTask, ( signed char * ) "TX", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_SEND_TASK_PRIORITY, NULL );
\r
325 /* Create the software timer that is responsible for turning off the LED
\r
326 if the button is not pushed within 5000ms, as described at the top of
\r
328 xLEDTimer = xTimerCreate( ( const signed char * ) "LEDTimer", /* A text name, purely to help debugging. */
\r
329 ( mainLED_TIMER_PERIOD_MS ), /* The timer period, in this case 5000ms (5s). */
\r
330 pdFALSE, /* This is a one shot timer, so xAutoReload is set to pdFALSE. */
\r
331 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
332 prvLEDTimerCallback /* The callback function that switches the LED off. */
\r
335 /* Create the software timer that performs the 'check' functionality,
\r
336 as described at the top of this file. */
\r
337 xCheckTimer = xTimerCreate( ( const signed char * ) "CheckTimer",/* A text name, purely to help debugging. */
\r
338 ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */
\r
339 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
340 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
341 prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */
\r
344 /* Create the software timer that performs the 'digit counting'
\r
345 functionality, as described at the top of this file. */
\r
346 xDigitCounterTimer = xTimerCreate( ( const signed char * ) "DigitCounter", /* A text name, purely to help debugging. */
\r
347 ( mainDIGIT_COUNTER_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */
\r
348 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
349 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
350 prvDigitCounterTimerCallback /* The callback function that inspects the status of all the other tasks. */
\r
353 /* Create a lot of 'standard demo' tasks. Over 40 tasks are created in
\r
354 this demo. For a much simpler demo, select the 'blinky' build
\r
356 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
357 vCreateBlockTimeTasks();
\r
358 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
359 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
360 vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );
\r
361 vStartQueuePeekTasks();
\r
362 vStartRecursiveMutexTasks();
\r
363 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );
\r
364 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
365 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
366 vStartCountingSemaphoreTasks();
\r
367 vStartDynamicPriorityTasks();
\r
369 /* The suicide tasks must be created last, as they need to know how many
\r
370 tasks were running prior to their creation in order to ascertain whether
\r
371 or not the correct/expected number of tasks are running at any given
\r
373 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
375 /* Start the tasks and timer running. */
\r
376 vTaskStartScheduler();
\r
379 /* If all is well, the scheduler will now be running, and the following line
\r
380 will never be reached. If the following line does execute, then there was
\r
381 insufficient FreeRTOS heap memory available for the idle and/or timer tasks
\r
382 to be created. See the memory management section on the FreeRTOS web site
\r
383 for more details. */
\r
386 /*-----------------------------------------------------------*/
\r
388 static void prvCheckTimerCallback( xTimerHandle xTimer )
\r
390 /* Check the standard demo tasks are running without error. Latch the
\r
391 latest reported error in the pcStatusMessage character pointer. */
\r
392 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
394 pcStatusMessage = "Error: GenQueue";
\r
397 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
399 pcStatusMessage = "Error: QueuePeek\r\n";
\r
402 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
404 pcStatusMessage = "Error: BlockQueue\r\n";
\r
407 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
409 pcStatusMessage = "Error: BlockTime\r\n";
\r
412 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
414 pcStatusMessage = "Error: SemTest\r\n";
\r
417 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
419 pcStatusMessage = "Error: Death\r\n";
\r
422 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
424 pcStatusMessage = "Error: RecMutex\r\n";
\r
427 if( xAreComTestTasksStillRunning() != pdPASS )
\r
429 pcStatusMessage = "Error: ComTest\r\n";
\r
432 if( xAreTimerDemoTasksStillRunning( ( mainCHECK_TIMER_PERIOD_MS ) ) != pdTRUE )
\r
434 pcStatusMessage = "Error: TimerDemo";
\r
437 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
439 pcStatusMessage = "Error: PollQueue";
\r
442 if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
\r
444 pcStatusMessage = "Error: CountSem";
\r
447 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
449 pcStatusMessage = "Error: DynamicPriority";
\r
452 /* Toggle the check LED to give an indication of the system status. If
\r
453 the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then
\r
454 everything is ok. A faster toggle indicates an error. */
\r
455 vParTestToggleLED( mainCHECK_LED );
\r
457 /* Have any errors been latch in pcStatusMessage? If so, shorten the
\r
458 period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.
\r
459 This will result in an increase in the rate at which mainCHECK_LED
\r
461 if( pcStatusMessage != NULL )
\r
463 /* This call to xTimerChangePeriod() uses a zero block time. Functions
\r
464 called from inside of a timer callback function must *never* attempt
\r
466 xTimerChangePeriod( xCheckTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );
\r
469 /*-----------------------------------------------------------*/
\r
471 static void prvLEDTimerCallback( xTimerHandle xTimer )
\r
473 /* The timer has expired - so no button pushes have occurred in the last
\r
474 five seconds - turn the LED off. */
\r
475 vParTestSetLED( mainTIMER_CONTROLLED_LED, pdFALSE );
\r
477 /*-----------------------------------------------------------*/
\r
479 static void prvDigitCounterTimerCallback( xTimerHandle xTimer )
\r
481 /* Define the bit patterns that display numbers on the seven segment display. */
\r
482 static const unsigned short usNumbersPatterns[] = { 0xC000U, 0xF900U, 0xA400U, 0xB000U, 0x9900U, 0x9200U, 0x8200U, 0xF800U, 0x8000U, 0x9000U };
\r
483 static long lCounter = 0L;
\r
484 const long lNumberOfDigits = 10L;
\r
486 /* Display the next number, counting up. */
\r
487 FM3_GPIO->PDOR1 = usNumbersPatterns[ lCounter ];
\r
489 /* Move onto the next digit. */
\r
492 /* Ensure the counter does not go off the end of the array. */
\r
493 if( lCounter >= lNumberOfDigits )
\r
498 /*-----------------------------------------------------------*/
\r
500 /* The ISR executed when the user button is pushed. */
\r
501 void INT0_7_Handler( void )
\r
503 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
505 /* The button was pushed, so ensure the LED is on before resetting the
\r
506 LED timer. The LED timer will turn the LED off if the button is not
\r
507 pushed within 5000ms. */
\r
508 vParTestSetLEDFromISR( mainTIMER_CONTROLLED_LED, pdTRUE );
\r
510 /* This interrupt safe FreeRTOS function can be called from this interrupt
\r
511 because the interrupt priority is below the
\r
512 configMAX_SYSCALL_INTERRUPT_PRIORITY setting in FreeRTOSConfig.h. */
\r
513 xTimerResetFromISR( xLEDTimer, &xHigherPriorityTaskWoken );
\r
515 /* Clear the interrupt before leaving. This just clears all the interrupts
\r
516 for simplicity, as only one is actually used in this simple demo anyway. */
\r
517 FM3_EXTI->EICL = 0x0000;
\r
519 /* If calling xTimerResetFromISR() caused a task (in this case the timer
\r
520 service/daemon task) to unblock, and the unblocked task has a priority
\r
521 higher than or equal to the task that was interrupted, then
\r
522 xHigherPriorityTaskWoken will now be set to pdTRUE, and calling
\r
523 portEND_SWITCHING_ISR() will ensure the unblocked task runs next. */
\r
524 portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
\r
526 /*-----------------------------------------------------------*/
\r
528 static void prvQueueSendTask( void *pvParameters )
\r
530 portTickType xNextWakeTime;
\r
531 const unsigned long ulValueToSend = 100UL;
\r
533 /* The timer command queue will have been filled when the timer test tasks
\r
534 were created in main() (this is part of the test they perform). Therefore,
\r
535 while the check and digit counter timers can be created in main(), they
\r
536 cannot be started from main(). Once the scheduler has started, the timer
\r
537 service task will drain the command queue, and now the check and digit
\r
538 counter timers can be started successfully. */
\r
539 xTimerStart( xCheckTimer, portMAX_DELAY );
\r
540 xTimerStart( xDigitCounterTimer, portMAX_DELAY );
\r
542 /* Initialise xNextWakeTime - this only needs to be done once. */
\r
543 xNextWakeTime = xTaskGetTickCount();
\r
547 /* Place this task in the blocked state until it is time to run again.
\r
548 The block time is specified in ticks, the constant used converts ticks
\r
549 to ms. While in the Blocked state this task will not consume any CPU
\r
551 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );
\r
553 /* Send to the queue - causing the queue receive task to unblock and
\r
554 toggle an LED. 0 is used as the block time so the sending operation
\r
555 will not block - it shouldn't need to block as the queue should always
\r
556 be empty at this point in the code. */
\r
557 xQueueSend( xQueue, &ulValueToSend, mainDONT_BLOCK );
\r
560 /*-----------------------------------------------------------*/
\r
562 static void prvQueueReceiveTask( void *pvParameters )
\r
564 unsigned long ulReceivedValue;
\r
568 /* Wait until something arrives in the queue - this task will block
\r
569 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in
\r
570 FreeRTOSConfig.h. */
\r
571 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );
\r
573 /* To get here something must have been received from the queue, but
\r
574 is it the expected value? If it is, toggle the LED. */
\r
575 if( ulReceivedValue == 100UL )
\r
577 vParTestToggleLED( mainTASK_CONTROLLED_LED );
\r
581 /*-----------------------------------------------------------*/
\r
583 static void prvSetupHardware( void )
\r
585 const unsigned short usButtonInputBit = 0x01U;
\r
588 SystemCoreClockUpdate();
\r
590 /* Initialise the IO used for the LEDs on the 7 segment displays. */
\r
591 vParTestInitialise();
\r
593 /* Set the switches to input (P18->P1F). */
\r
594 FM3_GPIO->DDR5 = 0x0000;
\r
595 FM3_GPIO->PFR5 = 0x0000;
\r
597 /* Assign the button input as GPIO. */
\r
598 FM3_GPIO->PFR1 |= usButtonInputBit;
\r
600 /* Button interrupt on falling edge. */
\r
601 FM3_EXTI->ELVR = 0x0003;
\r
603 /* Clear all external interrupts. */
\r
604 FM3_EXTI->EICL = 0x0000;
\r
606 /* Enable the button interrupt. */
\r
607 FM3_EXTI->ENIR |= usButtonInputBit;
\r
609 /* Setup the GPIO and the NVIC for the switch used in this simple demo. */
\r
610 NVIC_SetPriority( EXINT0_7_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
\r
611 NVIC_EnableIRQ( EXINT0_7_IRQn );
\r
613 /*-----------------------------------------------------------*/
\r
615 void vApplicationMallocFailedHook( void )
\r
617 /* Called if a call to pvPortMalloc() fails because there is insufficient
\r
618 free memory available in the FreeRTOS heap. pvPortMalloc() is called
\r
619 internally by FreeRTOS API functions that create tasks, queues, software
\r
620 timers, and semaphores. The size of the FreeRTOS heap is set by the
\r
621 configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
\r
624 /*-----------------------------------------------------------*/
\r
626 void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )
\r
628 ( void ) pcTaskName;
\r
631 /* Run time stack overflow checking is performed if
\r
632 configconfigCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
633 function is called if a stack overflow is detected. */
\r
634 taskDISABLE_INTERRUPTS();
\r
637 /*-----------------------------------------------------------*/
\r
639 void vApplicationIdleHook( void )
\r
641 volatile size_t xFreeStackSpace;
\r
643 /* This function is called on each cycle of the idle task. In this case it
\r
644 does nothing useful, other than report the amount of FreeRTOS heap that
\r
645 remains unallocated. */
\r
646 xFreeStackSpace = xPortGetFreeHeapSize();
\r
648 if( xFreeStackSpace > 100 )
\r
650 /* By now, the kernel has allocated everything it is going to, so
\r
651 if there is a lot of heap remaining unallocated then
\r
652 the value of configTOTAL_HEAP_SIZE in FreeRTOSConfig.h can be
\r
653 reduced accordingly. */
\r
656 /*-----------------------------------------------------------*/
\r
658 void vApplicationTickHook( void )
\r
660 /* Call the periodic timer test, which tests the timer API functions that
\r
661 can be called from an ISR. */
\r
662 vTimerPeriodicISRTests();
\r
664 /*-----------------------------------------------------------*/
\r