2 FreeRTOS V8.2.0rc1 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
13 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
14 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
15 >>! obliged to provide the source code for proprietary components !<<
\r
16 >>! outside of the FreeRTOS kernel. !<<
\r
18 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
19 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
20 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
21 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * Having a problem? Start by reading the FAQ "My application does *
\r
28 * not run, what could be wrong?". Have you defined configASSERT()? *
\r
30 * http://www.FreeRTOS.org/FAQHelp.html *
\r
32 ***************************************************************************
\r
34 ***************************************************************************
\r
36 * FreeRTOS provides completely free yet professionally developed, *
\r
37 * robust, strictly quality controlled, supported, and cross *
\r
38 * platform software that is more than just the market leader, it *
\r
39 * is the industry's de facto standard. *
\r
41 * Help yourself get started quickly while simultaneously helping *
\r
42 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
43 * tutorial book, reference manual, or both: *
\r
44 * http://www.FreeRTOS.org/Documentation *
\r
46 ***************************************************************************
\r
48 ***************************************************************************
\r
50 * Investing in training allows your team to be as productive as *
\r
51 * possible as early as possible, lowering your overall development *
\r
52 * cost, and enabling you to bring a more robust product to market *
\r
53 * earlier than would otherwise be possible. Richard Barry is both *
\r
54 * the architect and key author of FreeRTOS, and so also the world's *
\r
55 * leading authority on what is the world's most popular real time *
\r
56 * kernel for deeply embedded MCU designs. Obtaining your training *
\r
57 * from Richard ensures your team will gain directly from his in-depth *
\r
58 * product knowledge and years of usage experience. Contact Real Time *
\r
59 * Engineers Ltd to enquire about the FreeRTOS Masterclass, presented *
\r
60 * by Richard Barry: http://www.FreeRTOS.org/contact
\r
62 ***************************************************************************
\r
64 ***************************************************************************
\r
66 * You are receiving this top quality software for free. Please play *
\r
67 * fair and reciprocate by reporting any suspected issues and *
\r
68 * participating in the community forum: *
\r
69 * http://www.FreeRTOS.org/support *
\r
73 ***************************************************************************
\r
75 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
76 license and Real Time Engineers Ltd. contact details.
\r
78 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
79 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
80 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
82 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
83 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
85 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
86 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
87 licenses offer ticketed support, indemnification and commercial middleware.
\r
89 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
90 engineered and independently SIL3 certified version for use in safety and
\r
91 mission critical applications that require provable dependability.
\r
97 * main-blinky.c is included when the "Blinky" build configuration is used.
\r
98 * main-full.c is included when the "Full" build configuration is used.
\r
100 * main-full.c (this file) defines a comprehensive demo that creates many
\r
101 * tasks, queues, semaphores and timers. It also demonstrates how Cortex-M3
\r
102 * interrupts can interact with FreeRTOS tasks/timers.
\r
104 * This project runs on the SK-FM3-100PMC evaluation board, which is populated
\r
105 * with an MB9BF5006N Cortex-M3 based microcontroller.
\r
107 * The main() Function:
\r
108 * main() creates three demo specific software timers, one demo specific queue,
\r
109 * and two demo specific tasks. It then creates a whole host of 'standard
\r
110 * demo' tasks/queues/semaphores, before starting the scheduler. The demo
\r
111 * specific tasks and timers are described in the comments here. The standard
\r
112 * demo tasks are described on the FreeRTOS.org web site.
\r
114 * The standard demo tasks provide no specific functionality. They are
\r
115 * included to both test the FreeRTOS port, and provide examples of how the
\r
116 * various FreeRTOS API functions can be used.
\r
118 * This demo creates 43 tasks in total. If you want a simpler demo, use the
\r
119 * Blinky build configuration.
\r
121 * The Demo Specific Queue Send Task:
\r
122 * The queue send task is implemented by the prvQueueSendTask() function in
\r
123 * this file. prvQueueSendTask() sits in a loop that causes it to repeatedly
\r
124 * block for 200 milliseconds, before sending the value 100 to the queue that
\r
125 * was created within main(). Once the value is sent, the task loops back
\r
126 * around to block for another 200 milliseconds.
\r
128 * The Demo Specific Queue Receive Task:
\r
129 * The queue receive task is implemented by the prvQueueReceiveTask() function
\r
130 * in this file. prvQueueReceiveTask() sits in a loop that causes it to
\r
131 * repeatedly attempt to read data from the queue that was created within
\r
132 * main(). When data is received, the task checks the value of the data, and
\r
133 * if the value equals the expected 100, toggles an LED in the 7 segment display
\r
134 * (see the documentation page for this demo on the FreeRTOS.org site to see
\r
135 * which LED is used). The 'block time' parameter passed to the queue receive
\r
136 * function specifies that the task should be held in the Blocked state
\r
137 * indefinitely to wait for data to be available on the queue. The queue
\r
138 * receive task will only leave the Blocked state when the queue send task
\r
139 * writes to the queue. As the queue send task writes to the queue every 200
\r
140 * milliseconds, the queue receive task leaves the Blocked state every 200
\r
141 * milliseconds, and therefore toggles the LED every 200 milliseconds.
\r
143 * The Demo Specific LED Software Timer and the Button Interrupt:
\r
144 * The user button SW2 is configured to generate an interrupt each time it is
\r
145 * pressed. The interrupt service routine switches an LED on, and resets the
\r
146 * LED software timer. The LED timer has a 5000 millisecond (5 second) period,
\r
147 * and uses a callback function that is defined to just turn the LED off again.
\r
148 * Therefore, pressing the user button will turn the LED on, and the LED will
\r
149 * remain on until a full five seconds pass without the button being pressed.
\r
150 * See the documentation page for this demo on the FreeRTOS.org web site to see
\r
151 * which LED is used.
\r
153 * The Demo Specific "Check" Callback Function:
\r
154 * This is called each time the 'check' timer expires. The check timer
\r
155 * callback function inspects all the standard demo tasks to see if they are
\r
156 * all executing as expected. The check timer is initially configured to
\r
157 * expire every three seconds, but will shorted this to every 500ms if an error
\r
158 * is ever discovered. The check timer callback toggles the LED defined by
\r
159 * the mainCHECK_LED definition each time it executes. Therefore, if LED
\r
160 * mainCHECK_LED is toggling every three seconds, then no error have been found.
\r
161 * If LED mainCHECK_LED is toggling every 500ms, then at least one errors has
\r
162 * been found. The variable pcStatusMessage is set to a string that indicates
\r
163 * which task reported an error. See the documentation page for this demo on
\r
164 * the FreeRTOS.org web site to see which LED in the 7 segment display is used.
\r
166 * The Demo Specific "Digit Counter" Callback Function:
\r
167 * This is called each time the 'digit counter' timer expires. It causes the
\r
168 * digits 0 to 9 to be displayed in turn as the first character of the two
\r
169 * character display. The LEDs in the other digit of the two character
\r
170 * display are used as general purpose LEDs, as described in this comment block.
\r
172 * The Demo Specific Idle Hook Function:
\r
173 * The idle hook function demonstrates how to query the amount of FreeRTOS heap
\r
174 * space that is remaining (see vApplicationIdleHook() defined in this file).
\r
176 * The Demo Specific Tick Hook Function:
\r
177 * The tick hook function is used to test the interrupt safe software timer
\r
181 /* Kernel includes. */
\r
182 #include "FreeRTOS.h"
\r
185 #include "timers.h"
\r
187 /* Fujitsu drivers/libraries. */
\r
188 #include "mb9bf506n.h"
\r
189 #include "system_mb9bf50x.h"
\r
191 /* Common demo includes. */
\r
192 #include "partest.h"
\r
194 #include "BlockQ.h"
\r
196 #include "blocktim.h"
\r
197 #include "semtest.h"
\r
198 #include "GenQTest.h"
\r
200 #include "recmutex.h"
\r
201 #include "TimerDemo.h"
\r
202 #include "comtest2.h"
\r
204 #include "countsem.h"
\r
205 #include "dynamic.h"
\r
207 /* The rate at which data is sent to the queue, specified in milliseconds, and
\r
208 converted to ticks using the portTICK_PERIOD_MS constant. */
\r
209 #define mainQUEUE_SEND_FREQUENCY_MS ( 200 / portTICK_PERIOD_MS )
\r
211 /* The number of items the queue can hold. This is 1 as the receive task
\r
212 will remove items as they are added, meaning the send task should always find
\r
213 the queue empty. */
\r
214 #define mainQUEUE_LENGTH ( 1 )
\r
216 /* The LED toggled by the check timer callback function. This is an LED in the
\r
217 second digit of the two digit 7 segment display. See the documentation page
\r
218 for this demo on the FreeRTOS.org web site to see which LED this relates to. */
\r
219 #define mainCHECK_LED 0x07UL
\r
221 /* The LED toggle by the queue receive task. This is an LED in the second digit
\r
222 of the two digit 7 segment display. See the documentation page for this demo on
\r
223 the FreeRTOS.org web site to see which LED this relates to. */
\r
224 #define mainTASK_CONTROLLED_LED 0x06UL
\r
226 /* The LED turned on by the button interrupt, and turned off by the LED timer.
\r
227 This is an LED in the second digit of the two digit 7 segment display. See the
\r
228 documentation page for this demo on the FreeRTOS.org web site to see which LED
\r
229 this relates to. */
\r
230 #define mainTIMER_CONTROLLED_LED 0x05UL
\r
232 /* The LED used by the comtest tasks. See the comtest.c file for more
\r
233 information. The LEDs used by the comtest task are in the second digit of the
\r
234 two digit 7 segment display. See the documentation page for this demo on the
\r
235 FreeRTOS.org web site to see which LEDs this relates to. */
\r
236 #define mainCOM_TEST_LED ( 3 )
\r
238 /* Constant used by the standard timer test functions. */
\r
239 #define mainTIMER_TEST_PERIOD ( 50 )
\r
241 /* Priorities used by the various different standard demo tasks. */
\r
242 #define mainCHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
\r
243 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
244 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
245 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
246 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
247 #define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
248 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
249 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
250 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
252 /* Priorities defined in this main-full.c file. */
\r
253 #define mainQUEUE_RECEIVE_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
254 #define mainQUEUE_SEND_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
256 /* The period at which the check timer will expire, in ms, provided no errors
\r
257 have been reported by any of the standard demo tasks. ms are converted to the
\r
258 equivalent in ticks using the portTICK_PERIOD_MS constant. */
\r
259 #define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_PERIOD_MS )
\r
261 /* The period at which the check timer will expire, in ms, if an error has been
\r
262 reported in one of the standard demo tasks. ms are converted to the equivalent
\r
263 in ticks using the portTICK_PERIOD_MS constant. */
\r
264 #define mainERROR_CHECK_TIMER_PERIOD_MS ( 500UL / portTICK_PERIOD_MS )
\r
266 /* The period at which the digit counter timer will expire, in ms, and converted
\r
267 to ticks using the portTICK_PERIOD_MS constant. */
\r
268 #define mainDIGIT_COUNTER_TIMER_PERIOD_MS ( 250UL / portTICK_PERIOD_MS )
\r
270 /* The LED will remain on until the button has not been pushed for a full
\r
272 #define mainLED_TIMER_PERIOD_MS ( 5000UL / portTICK_PERIOD_MS )
\r
274 /* A zero block time. */
\r
275 #define mainDONT_BLOCK ( 0UL )
\r
277 /* Baud rate used by the comtest tasks. */
\r
278 #define mainCOM_TEST_BAUD_RATE ( 115200UL )
\r
280 /*-----------------------------------------------------------*/
\r
283 * Setup the NVIC, LED outputs, and button inputs.
\r
285 static void prvSetupHardware( void );
\r
288 * The application specific (not common demo) tasks as described in the comments
\r
289 * at the top of this file.
\r
291 static void prvQueueReceiveTask( void *pvParameters );
\r
292 static void prvQueueSendTask( void *pvParameters );
\r
295 * The LED timer callback function. This does nothing but switch an LED off.
\r
297 static void prvLEDTimerCallback( TimerHandle_t xTimer );
\r
300 * The check timer callback function, as described at the top of this file.
\r
302 static void prvCheckTimerCallback( TimerHandle_t xTimer );
\r
305 * The digit counter callback function, as described at the top of this file.
\r
307 static void prvDigitCounterTimerCallback( TimerHandle_t xTimer );
\r
310 * This is not a 'standard' partest function, so the prototype is not in
\r
311 * partest.h, and is instead included here.
\r
313 void vParTestSetLEDFromISR( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue );
\r
315 /*-----------------------------------------------------------*/
\r
317 /* The queue used by both application specific demo tasks defined in this file. */
\r
318 static QueueHandle_t xQueue = NULL;
\r
320 /* The LED software timer. This uses prvLEDTimerCallback() as it's callback
\r
322 static TimerHandle_t xLEDTimer = NULL;
\r
324 /* The digit counter software timer. This displays a counting digit on one half
\r
325 of the seven segment displays. */
\r
326 static TimerHandle_t xDigitCounterTimer = NULL;
\r
328 /* The check timer. This uses prvCheckTimerCallback() as its callback
\r
330 static TimerHandle_t xCheckTimer = NULL;
\r
332 /* If an error is detected in a standard demo task, then pcStatusMessage will
\r
333 be set to point to a string that identifies the offending task. This is just
\r
334 to make debugging easier. */
\r
335 static const char *pcStatusMessage = NULL;
\r
337 /*-----------------------------------------------------------*/
\r
341 /* Configure the NVIC, LED outputs and button inputs. */
\r
342 prvSetupHardware();
\r
344 /* Create the queue. */
\r
345 xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );
\r
347 if( xQueue != NULL )
\r
349 /* Start the two application specific demo tasks, as described in the
\r
350 comments at the top of this file. */
\r
351 xTaskCreate( prvQueueReceiveTask, "Rx", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_RECEIVE_TASK_PRIORITY, NULL );
\r
352 xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_SEND_TASK_PRIORITY, NULL );
\r
354 /* Create the software timer that is responsible for turning off the LED
\r
355 if the button is not pushed within 5000ms, as described at the top of
\r
357 xLEDTimer = xTimerCreate( "LEDTimer", /* A text name, purely to help debugging. */
\r
358 ( mainLED_TIMER_PERIOD_MS ),/* The timer period, in this case 5000ms (5s). */
\r
359 pdFALSE, /* This is a one shot timer, so xAutoReload is set to pdFALSE. */
\r
360 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
361 prvLEDTimerCallback /* The callback function that switches the LED off. */
\r
364 /* Create the software timer that performs the 'check' functionality,
\r
365 as described at the top of this file. */
\r
366 xCheckTimer = xTimerCreate( "CheckTimer", /* A text name, purely to help debugging. */
\r
367 ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */
\r
368 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
369 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
370 prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */
\r
373 /* Create the software timer that performs the 'digit counting'
\r
374 functionality, as described at the top of this file. */
\r
375 xDigitCounterTimer = xTimerCreate( "DigitCounter", /* A text name, purely to help debugging. */
\r
376 ( mainDIGIT_COUNTER_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */
\r
377 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
378 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
379 prvDigitCounterTimerCallback /* The callback function that inspects the status of all the other tasks. */
\r
382 /* Create a lot of 'standard demo' tasks. Over 40 tasks are created in
\r
383 this demo. For a much simpler demo, select the 'blinky' build
\r
385 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
386 vCreateBlockTimeTasks();
\r
387 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
388 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
389 vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );
\r
390 vStartQueuePeekTasks();
\r
391 vStartRecursiveMutexTasks();
\r
392 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );
\r
393 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
394 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
395 vStartCountingSemaphoreTasks();
\r
396 vStartDynamicPriorityTasks();
\r
398 /* The suicide tasks must be created last, as they need to know how many
\r
399 tasks were running prior to their creation in order to ascertain whether
\r
400 or not the correct/expected number of tasks are running at any given
\r
402 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
404 /* Start the tasks and timer running. */
\r
405 vTaskStartScheduler();
\r
408 /* If all is well, the scheduler will now be running, and the following line
\r
409 will never be reached. If the following line does execute, then there was
\r
410 insufficient FreeRTOS heap memory available for the idle and/or timer tasks
\r
411 to be created. See the memory management section on the FreeRTOS web site
\r
412 for more details. */
\r
415 /*-----------------------------------------------------------*/
\r
417 static void prvCheckTimerCallback( TimerHandle_t xTimer )
\r
419 /* Check the standard demo tasks are running without error. Latch the
\r
420 latest reported error in the pcStatusMessage character pointer. */
\r
421 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
423 pcStatusMessage = "Error: GenQueue";
\r
426 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
428 pcStatusMessage = "Error: QueuePeek\r\n";
\r
431 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
433 pcStatusMessage = "Error: BlockQueue\r\n";
\r
436 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
438 pcStatusMessage = "Error: BlockTime\r\n";
\r
441 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
443 pcStatusMessage = "Error: SemTest\r\n";
\r
446 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
448 pcStatusMessage = "Error: Death\r\n";
\r
451 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
453 pcStatusMessage = "Error: RecMutex\r\n";
\r
456 if( xAreComTestTasksStillRunning() != pdPASS )
\r
458 pcStatusMessage = "Error: ComTest\r\n";
\r
461 if( xAreTimerDemoTasksStillRunning( ( mainCHECK_TIMER_PERIOD_MS ) ) != pdTRUE )
\r
463 pcStatusMessage = "Error: TimerDemo";
\r
466 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
468 pcStatusMessage = "Error: PollQueue";
\r
471 if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
\r
473 pcStatusMessage = "Error: CountSem";
\r
476 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
478 pcStatusMessage = "Error: DynamicPriority";
\r
481 /* Toggle the check LED to give an indication of the system status. If
\r
482 the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then
\r
483 everything is ok. A faster toggle indicates an error. */
\r
484 vParTestToggleLED( mainCHECK_LED );
\r
486 /* Have any errors been latch in pcStatusMessage? If so, shorten the
\r
487 period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.
\r
488 This will result in an increase in the rate at which mainCHECK_LED
\r
490 if( pcStatusMessage != NULL )
\r
492 /* This call to xTimerChangePeriod() uses a zero block time. Functions
\r
493 called from inside of a timer callback function must *never* attempt
\r
495 xTimerChangePeriod( xCheckTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );
\r
498 /*-----------------------------------------------------------*/
\r
500 static void prvLEDTimerCallback( TimerHandle_t xTimer )
\r
502 /* The timer has expired - so no button pushes have occurred in the last
\r
503 five seconds - turn the LED off. */
\r
504 vParTestSetLED( mainTIMER_CONTROLLED_LED, pdFALSE );
\r
506 /*-----------------------------------------------------------*/
\r
508 static void prvDigitCounterTimerCallback( TimerHandle_t xTimer )
\r
510 /* Define the bit patterns that display numbers on the seven segment display. */
\r
511 static const unsigned short usNumbersPatterns[] = { 0xC000U, 0xF900U, 0xA400U, 0xB000U, 0x9900U, 0x9200U, 0x8200U, 0xF800U, 0x8000U, 0x9000U };
\r
512 static long lCounter = 0L;
\r
513 const long lNumberOfDigits = 10L;
\r
515 /* Display the next number, counting up. */
\r
516 FM3_GPIO->PDOR1 = usNumbersPatterns[ lCounter ];
\r
518 /* Move onto the next digit. */
\r
521 /* Ensure the counter does not go off the end of the array. */
\r
522 if( lCounter >= lNumberOfDigits )
\r
527 /*-----------------------------------------------------------*/
\r
529 /* The ISR executed when the user button is pushed. */
\r
530 void INT0_7_Handler( void )
\r
532 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
534 /* The button was pushed, so ensure the LED is on before resetting the
\r
535 LED timer. The LED timer will turn the LED off if the button is not
\r
536 pushed within 5000ms. */
\r
537 vParTestSetLEDFromISR( mainTIMER_CONTROLLED_LED, pdTRUE );
\r
539 /* This interrupt safe FreeRTOS function can be called from this interrupt
\r
540 because the interrupt priority is below the
\r
541 configMAX_SYSCALL_INTERRUPT_PRIORITY setting in FreeRTOSConfig.h. */
\r
542 xTimerResetFromISR( xLEDTimer, &xHigherPriorityTaskWoken );
\r
544 /* Clear the interrupt before leaving. This just clears all the interrupts
\r
545 for simplicity, as only one is actually used in this simple demo anyway. */
\r
546 FM3_EXTI->EICL = 0x0000;
\r
548 /* If calling xTimerResetFromISR() caused a task (in this case the timer
\r
549 service/daemon task) to unblock, and the unblocked task has a priority
\r
550 higher than or equal to the task that was interrupted, then
\r
551 xHigherPriorityTaskWoken will now be set to pdTRUE, and calling
\r
552 portEND_SWITCHING_ISR() will ensure the unblocked task runs next. */
\r
553 portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
\r
555 /*-----------------------------------------------------------*/
\r
557 static void prvQueueSendTask( void *pvParameters )
\r
559 TickType_t xNextWakeTime;
\r
560 const unsigned long ulValueToSend = 100UL;
\r
562 /* The timer command queue will have been filled when the timer test tasks
\r
563 were created in main() (this is part of the test they perform). Therefore,
\r
564 while the check and digit counter timers can be created in main(), they
\r
565 cannot be started from main(). Once the scheduler has started, the timer
\r
566 service task will drain the command queue, and now the check and digit
\r
567 counter timers can be started successfully. */
\r
568 xTimerStart( xCheckTimer, portMAX_DELAY );
\r
569 xTimerStart( xDigitCounterTimer, portMAX_DELAY );
\r
571 /* Initialise xNextWakeTime - this only needs to be done once. */
\r
572 xNextWakeTime = xTaskGetTickCount();
\r
576 /* Place this task in the blocked state until it is time to run again.
\r
577 The block time is specified in ticks, the constant used converts ticks
\r
578 to ms. While in the Blocked state this task will not consume any CPU
\r
580 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );
\r
582 /* Send to the queue - causing the queue receive task to unblock and
\r
583 toggle an LED. 0 is used as the block time so the sending operation
\r
584 will not block - it shouldn't need to block as the queue should always
\r
585 be empty at this point in the code. */
\r
586 xQueueSend( xQueue, &ulValueToSend, mainDONT_BLOCK );
\r
589 /*-----------------------------------------------------------*/
\r
591 static void prvQueueReceiveTask( void *pvParameters )
\r
593 unsigned long ulReceivedValue;
\r
597 /* Wait until something arrives in the queue - this task will block
\r
598 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in
\r
599 FreeRTOSConfig.h. */
\r
600 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );
\r
602 /* To get here something must have been received from the queue, but
\r
603 is it the expected value? If it is, toggle the LED. */
\r
604 if( ulReceivedValue == 100UL )
\r
606 vParTestToggleLED( mainTASK_CONTROLLED_LED );
\r
610 /*-----------------------------------------------------------*/
\r
612 static void prvSetupHardware( void )
\r
614 const unsigned short usButtonInputBit = 0x01U;
\r
617 SystemCoreClockUpdate();
\r
619 /* Initialise the IO used for the LEDs on the 7 segment displays. */
\r
620 vParTestInitialise();
\r
622 /* Set the switches to input (P18->P1F). */
\r
623 FM3_GPIO->DDR5 = 0x0000;
\r
624 FM3_GPIO->PFR5 = 0x0000;
\r
626 /* Assign the button input as GPIO. */
\r
627 FM3_GPIO->PFR1 |= usButtonInputBit;
\r
629 /* Button interrupt on falling edge. */
\r
630 FM3_EXTI->ELVR = 0x0003;
\r
632 /* Clear all external interrupts. */
\r
633 FM3_EXTI->EICL = 0x0000;
\r
635 /* Enable the button interrupt. */
\r
636 FM3_EXTI->ENIR |= usButtonInputBit;
\r
638 /* Setup the GPIO and the NVIC for the switch used in this simple demo. */
\r
639 NVIC_SetPriority( EXINT0_7_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
\r
640 NVIC_EnableIRQ( EXINT0_7_IRQn );
\r
642 /*-----------------------------------------------------------*/
\r
644 void vApplicationMallocFailedHook( void )
\r
646 /* Called if a call to pvPortMalloc() fails because there is insufficient
\r
647 free memory available in the FreeRTOS heap. pvPortMalloc() is called
\r
648 internally by FreeRTOS API functions that create tasks, queues, software
\r
649 timers, and semaphores. The size of the FreeRTOS heap is set by the
\r
650 configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
\r
653 /*-----------------------------------------------------------*/
\r
655 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
657 ( void ) pcTaskName;
\r
660 /* Run time stack overflow checking is performed if
\r
661 configconfigCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
662 function is called if a stack overflow is detected. */
\r
663 taskDISABLE_INTERRUPTS();
\r
666 /*-----------------------------------------------------------*/
\r
668 void vApplicationIdleHook( void )
\r
670 volatile size_t xFreeStackSpace;
\r
672 /* This function is called on each cycle of the idle task. In this case it
\r
673 does nothing useful, other than report the amount of FreeRTOS heap that
\r
674 remains unallocated. */
\r
675 xFreeStackSpace = xPortGetFreeHeapSize();
\r
677 if( xFreeStackSpace > 100 )
\r
679 /* By now, the kernel has allocated everything it is going to, so
\r
680 if there is a lot of heap remaining unallocated then
\r
681 the value of configTOTAL_HEAP_SIZE in FreeRTOSConfig.h can be
\r
682 reduced accordingly. */
\r
685 /*-----------------------------------------------------------*/
\r
687 void vApplicationTickHook( void )
\r
689 /* Call the periodic timer test, which tests the timer API functions that
\r
690 can be called from an ISR. */
\r
691 vTimerPeriodicISRTests();
\r
693 /*-----------------------------------------------------------*/
\r