2 FreeRTOS V8.1.1 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
28 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
29 >>! obliged to provide the source code for proprietary components !<<
\r
30 >>! outside of the FreeRTOS kernel. !<<
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
66 /******************************************************************************
\r
67 * >>>>>> NOTE 1: <<<<<<
\r
69 * main() can be configured to create either a very simple LED flasher demo, or
\r
70 * a more comprehensive test/demo application.
\r
72 * To create a very simple LED flasher example, set the
\r
73 * mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY constant (defined below) to 1. When
\r
74 * this is done, only the standard demo flash tasks are created. The standard
\r
75 * demo flash example creates three tasks, each of which toggle an LED at a
\r
76 * fixed but different frequency.
\r
78 * To create a more comprehensive test and demo application, set
\r
79 * mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY to 0.
\r
81 * >>>>>> NOTE 2: <<<<<<
\r
83 * In addition to the normal set of standard demo tasks, the comprehensive test
\r
84 * makes heavy use of the floating point unit, and forces floating point
\r
85 * instructions to be used from interrupts that nest three deep. The nesting
\r
86 * starts from the tick hook function, resulting is an abnormally long context
\r
87 * switch time. This is done purely to stress test the FPU context switching
\r
88 * implementation, and that part of the test can be removed by setting
\r
89 * configUSE_TICK_HOOK to 0 in FreeRTOSConfig.h.
\r
90 ******************************************************************************
\r
92 * main() creates all the demo application tasks and software timers, then starts
\r
93 * the scheduler. The web documentation provides more details of the standard
\r
94 * demo application tasks, which provide no particular functionality, but do
\r
95 * provide a good example of how to use the FreeRTOS API.
\r
97 * In addition to the standard demo tasks, the following tasks and tests are
\r
98 * defined and/or created within this file:
\r
100 * "Reg test" tasks - These fill both the core and floating point registers with
\r
101 * known values, then check that each register maintains its expected value for
\r
102 * the lifetime of the task. Each task uses a different set of values. The reg
\r
103 * test tasks execute with a very low priority, so get preempted very
\r
104 * frequently. A register containing an unexpected value is indicative of an
\r
105 * error in the context switching mechanism.
\r
107 * "Check" timer - The check software timer period is initially set to three
\r
108 * seconds. The callback function associated with the check software timer
\r
109 * checks that all the standard demo tasks, and the register check tasks, are
\r
110 * not only still executing, but are executing without reporting any errors. If
\r
111 * the check software timer discovers that a task has either stalled, or
\r
112 * reported an error, then it changes its own execution period from the initial
\r
113 * three seconds, to just 200ms. The check software timer callback function
\r
114 * also toggles an LED each time it is called. This provides a visual
\r
115 * indication of the system status: If the LED toggles every three seconds,
\r
116 * then no issues have been discovered. If the LED toggles every 200ms, then
\r
117 * an issue has been discovered with at least one task.
\r
119 * Tick hook - The application tick hook is called from the schedulers tick
\r
120 * interrupt service routine when configUSE_TICK_HOOK is set to 1 in
\r
121 * FreeRTOSConfig.h. In this example, the tick hook is used to test the kernels
\r
122 * handling of the floating point units (FPU) context, both at the task level
\r
123 * and when nesting interrupts access the floating point unit registers. The
\r
124 * tick hook function first fills the FPU registers with a known value, it
\r
125 * then triggers a medium priority interrupt. The medium priority interrupt
\r
126 * fills the FPU registers with a different value, and triggers a high priority
\r
127 * interrupt. The high priority interrupt once again fills the the FPU
\r
128 * registers with a known value before returning to the medium priority
\r
129 * interrupt. The medium priority interrupt checks that the FPU registers
\r
130 * contain the values that it wrote to them, then returns to the tick hook
\r
131 * function. Finally, the tick hook function checks that the FPU registers
\r
132 * contain the values that it wrote to them, before it too returns.
\r
134 * Button interrupt - The button marked "USER" on the starter kit is used to
\r
135 * demonstrate how to write an interrupt service routine, and how to synchronise
\r
136 * a task with an interrupt. A task is created that blocks on a test semaphore.
\r
137 * When the USER button is pressed, the button interrupt handler gives the
\r
138 * semaphore, causing the task to unblock. When the task unblocks, it simply
\r
139 * increments an execution count variable, then returns to block on the
\r
143 /* Kernel includes. */
\r
144 #include "FreeRTOS.h"
\r
146 #include "timers.h"
\r
147 #include "semphr.h"
\r
149 /* Demo application includes. */
\r
150 #include "partest.h"
\r
153 #include "integer.h"
\r
155 #include "semtest.h"
\r
156 #include "dynamic.h"
\r
157 #include "BlockQ.h"
\r
158 #include "blocktim.h"
\r
159 #include "countsem.h"
\r
160 #include "GenQTest.h"
\r
161 #include "recmutex.h"
\r
164 /* Hardware and starter kit includes. */
\r
165 #include "arm_comm.h"
\r
166 #include "iar_stm32f407zg_sk.h"
\r
167 #include "stm32f4xx.h"
\r
168 #include "stm32f4xx_conf.h"
\r
170 /* Priorities for the demo application tasks. */
\r
171 #define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 1UL )
\r
172 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
173 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1UL )
\r
174 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
175 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3UL )
\r
176 #define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
178 /* The LED used by the check timer. */
\r
179 #define mainCHECK_LED ( 3UL )
\r
181 /* A block time of zero simply means "don't block". */
\r
182 #define mainDONT_BLOCK ( 0UL )
\r
184 /* The period after which the check timer will expire, in ms, provided no errors
\r
185 have been reported by any of the standard demo tasks. ms are converted to the
\r
186 equivalent in ticks using the portTICK_PERIOD_MS constant. */
\r
187 #define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_PERIOD_MS )
\r
189 /* The period at which the check timer will expire, in ms, if an error has been
\r
190 reported in one of the standard demo tasks. ms are converted to the equivalent
\r
191 in ticks using the portTICK_PERIOD_MS constant. */
\r
192 #define mainERROR_CHECK_TIMER_PERIOD_MS ( 200UL / portTICK_PERIOD_MS )
\r
194 /* Set mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY to 1 to create a simple demo.
\r
195 Set mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY to 0 to create a much more
\r
196 comprehensive test application. See the comments at the top of this file, and
\r
197 the documentation page on the http://www.FreeRTOS.org web site for more
\r
199 #define mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY 0
\r
201 /*-----------------------------------------------------------*/
\r
204 * Set up the hardware ready to run this demo.
\r
206 static void prvSetupHardware( void );
\r
209 * The check timer callback function, as described at the top of this file.
\r
211 static void prvCheckTimerCallback( TimerHandle_t xTimer );
\r
214 * Configure the interrupts used to test the interrupt nesting depth as
\r
215 * described at the top of this file.
\r
217 static void prvSetupNestedFPUInterruptsTest( void );
\r
220 * Register check tasks, and the tasks used to write over and check the contents
\r
221 * of the FPU registers, as described at the top of this file. The nature of
\r
222 * these files necessitates that they are written in an assembly file.
\r
224 extern void vRegTest1Task( void *pvParameters );
\r
225 extern void vRegTest2Task( void *pvParameters );
\r
226 extern void vRegTestClearFlopRegistersToParameterValue( unsigned long ulValue );
\r
227 extern unsigned long ulRegTestCheckFlopRegistersContainParameterValue( unsigned long ulValue );
\r
230 * The task that is synchronised with the button interrupt. This is done just
\r
231 * to demonstrate how to write interrupt service routines, and how to
\r
232 * synchronise a task with an interrupt.
\r
234 static void prvButtonTestTask( void *pvParameters );
\r
237 * This file can be used to create either a simple LED flasher example, or a
\r
238 * comprehensive test/demo application - depending on the setting of the
\r
239 * mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY constant defined above. If
\r
240 * mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY is set to 1, then the following
\r
241 * function will create a lot of additional tasks and a software timer. If
\r
242 * mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY is set to 0, then the following
\r
243 * function will do nothing.
\r
245 static void prvOptionallyCreateComprehensveTestApplication( void );
\r
247 /*-----------------------------------------------------------*/
\r
249 /* The following two variables are used to communicate the status of the
\r
250 register check tasks to the check software timer. If the variables keep
\r
251 incrementing, then the register check tasks has not discovered any errors. If
\r
252 a variable stops incrementing, then an error has been found. */
\r
253 volatile unsigned long ulRegTest1LoopCounter = 0UL, ulRegTest2LoopCounter = 0UL;
\r
255 /* The following variables are used to verify that the interrupt nesting depth
\r
256 is as intended. ulFPUInterruptNesting is incremented on entry to an interrupt
\r
257 that uses the FPU, and decremented on exit of the same interrupt.
\r
258 ulMaxFPUInterruptNesting latches the highest value reached by
\r
259 ulFPUInterruptNesting. These variables have no other purpose. */
\r
260 volatile unsigned long ulFPUInterruptNesting = 0UL, ulMaxFPUInterruptNesting = 0UL;
\r
262 /* The semaphore used to demonstrate a task being synchronised with an
\r
264 static SemaphoreHandle_t xTestSemaphore = NULL;
\r
266 /* The variable that is incremented by the task synchronised with the button
\r
268 volatile unsigned long ulButtonPressCounts = 0UL;
\r
270 /*-----------------------------------------------------------*/
\r
274 /* Configure the hardware ready to run the test. */
\r
275 prvSetupHardware();
\r
277 /* Start standard demo/test application flash tasks. See the comments at
\r
278 the top of this file. The LED flash tasks are always created. The other
\r
279 tasks are only created if mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY is set to
\r
280 0 (at the top of this file). See the comments at the top of this file for
\r
281 more information. */
\r
282 vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );
\r
284 /* The following function will only create more tasks and timers if
\r
285 mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY is set to 0 (at the top of this
\r
286 file). See the comments at the top of this file for more information. */
\r
287 prvOptionallyCreateComprehensveTestApplication();
\r
289 /* Start the scheduler. */
\r
290 vTaskStartScheduler();
\r
292 /* If all is well, the scheduler will now be running, and the following line
\r
293 will never be reached. If the following line does execute, then there was
\r
294 insufficient FreeRTOS heap memory available for the idle and/or timer tasks
\r
295 to be created. See the memory management section on the FreeRTOS web site
\r
296 for more details. */
\r
299 /*-----------------------------------------------------------*/
\r
301 static void prvCheckTimerCallback( TimerHandle_t xTimer )
\r
303 static long lChangedTimerPeriodAlready = pdFALSE;
\r
304 static unsigned long ulLastRegTest1Value = 0, ulLastRegTest2Value = 0;
\r
305 long lErrorFound = pdFALSE;
\r
307 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
308 that they are all still running, and that none have detected an error. */
\r
310 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
312 lErrorFound = pdTRUE;
\r
315 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
317 lErrorFound = pdTRUE;
\r
320 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
322 lErrorFound = pdTRUE;
\r
325 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
327 lErrorFound = pdTRUE;
\r
330 if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
332 lErrorFound = pdTRUE;
\r
335 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
337 lErrorFound = pdTRUE;
\r
340 if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
342 lErrorFound = pdTRUE;
\r
345 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
347 lErrorFound = pdTRUE;
\r
350 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
352 lErrorFound = pdTRUE;
\r
355 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
357 lErrorFound = pdTRUE;
\r
360 /* Check that the register test 1 task is still running. */
\r
361 if( ulLastRegTest1Value == ulRegTest1LoopCounter )
\r
363 lErrorFound = pdTRUE;
\r
365 ulLastRegTest1Value = ulRegTest1LoopCounter;
\r
367 /* Check that the register test 2 task is still running. */
\r
368 if( ulLastRegTest2Value == ulRegTest2LoopCounter )
\r
370 lErrorFound = pdTRUE;
\r
372 ulLastRegTest2Value = ulRegTest2LoopCounter;
\r
374 /* Toggle the check LED to give an indication of the system status. If
\r
375 the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then
\r
376 everything is ok. A faster toggle indicates an error. */
\r
377 vParTestToggleLED( mainCHECK_LED );
\r
379 /* Have any errors been latch in lErrorFound? If so, shorten the
\r
380 period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.
\r
381 This will result in an increase in the rate at which mainCHECK_LED
\r
383 if( lErrorFound != pdFALSE )
\r
385 if( lChangedTimerPeriodAlready == pdFALSE )
\r
387 lChangedTimerPeriodAlready = pdTRUE;
\r
389 /* This call to xTimerChangePeriod() uses a zero block time.
\r
390 Functions called from inside of a timer callback function must
\r
391 *never* attempt to block. */
\r
392 xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );
\r
396 /*-----------------------------------------------------------*/
\r
398 static void prvButtonTestTask( void *pvParameters )
\r
400 configASSERT( xTestSemaphore );
\r
402 /* This is the task used as an example of how to synchronise a task with
\r
403 an interrupt. Each time the button interrupt gives the semaphore, this task
\r
404 will unblock, increment its execution counter, then return to block
\r
407 /* Take the semaphore before started to ensure it is in the correct
\r
409 xSemaphoreTake( xTestSemaphore, mainDONT_BLOCK );
\r
413 xSemaphoreTake( xTestSemaphore, portMAX_DELAY );
\r
414 ulButtonPressCounts++;
\r
417 /*-----------------------------------------------------------*/
\r
419 static void prvSetupHardware( void )
\r
421 /* Setup STM32 system (clock, PLL and Flash configuration) */
\r
424 /* Ensure all priority bits are assigned as preemption priority bits. */
\r
425 NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );
\r
427 /* Setup the LED outputs. */
\r
428 vParTestInitialise();
\r
430 /* Configure the button input. This configures the interrupt to use the
\r
431 lowest interrupt priority, so it is ok to use the ISR safe FreeRTOS API
\r
432 from the button interrupt handler. */
\r
433 STM_EVAL_PBInit( BUTTON_USER, BUTTON_MODE_EXTI );
\r
435 /*-----------------------------------------------------------*/
\r
437 void vApplicationTickHook( void )
\r
439 #if ( mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY == 0 )
\r
441 /* Just to verify that the interrupt nesting behaves as expected,
\r
442 increment ulFPUInterruptNesting on entry, and decrement it on exit. */
\r
443 ulFPUInterruptNesting++;
\r
445 /* Fill the FPU registers with 0. */
\r
446 vRegTestClearFlopRegistersToParameterValue( 0UL );
\r
448 /* Trigger a timer 2 interrupt, which will fill the registers with a
\r
449 different value and itself trigger a timer 3 interrupt. Note that the
\r
450 timers are not actually used. The timer 2 and 3 interrupt vectors are
\r
451 just used for convenience. */
\r
452 NVIC_SetPendingIRQ( TIM2_IRQn );
\r
454 /* Ensure that, after returning from the nested interrupts, all the FPU
\r
455 registers contain the value to which they were set by the tick hook
\r
457 configASSERT( ulRegTestCheckFlopRegistersContainParameterValue( 0UL ) );
\r
459 ulFPUInterruptNesting--;
\r
463 /*-----------------------------------------------------------*/
\r
465 static void prvSetupNestedFPUInterruptsTest( void )
\r
467 NVIC_InitTypeDef NVIC_InitStructure;
\r
469 /* Enable the TIM2 interrupt in the NVIC. The timer itself is not used,
\r
470 just its interrupt vector to force nesting from software. TIM2 must have
\r
471 a lower priority than TIM3, and both must have priorities above
\r
472 configMAX_SYSCALL_INTERRUPT_PRIORITY. */
\r
473 NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
\r
474 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY - 1;
\r
475 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
\r
476 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
\r
477 NVIC_Init( &NVIC_InitStructure );
\r
479 /* Enable the TIM3 interrupt in the NVIC. The timer itself is not used,
\r
480 just its interrupt vector to force nesting from software. TIM2 must have
\r
481 a lower priority than TIM3, and both must have priorities above
\r
482 configMAX_SYSCALL_INTERRUPT_PRIORITY. */
\r
483 NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
\r
484 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY - 2;
\r
485 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
\r
486 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
\r
487 NVIC_Init( &NVIC_InitStructure );
\r
489 /*-----------------------------------------------------------*/
\r
491 void TIM3_IRQHandler( void )
\r
493 /* Just to verify that the interrupt nesting behaves as expected, increment
\r
494 ulFPUInterruptNesting on entry, and decrement it on exit. */
\r
495 ulFPUInterruptNesting++;
\r
497 /* This is the highest priority interrupt in the chain of forced nesting
\r
498 interrupts, so latch the maximum value reached by ulFPUInterruptNesting.
\r
499 This is done purely to allow verification that the nesting depth reaches
\r
501 if( ulFPUInterruptNesting > ulMaxFPUInterruptNesting )
\r
503 ulMaxFPUInterruptNesting = ulFPUInterruptNesting;
\r
506 /* Fill the FPU registers with 99 to overwrite the values written by
\r
507 TIM2_IRQHandler(). */
\r
508 vRegTestClearFlopRegistersToParameterValue( 99UL );
\r
510 ulFPUInterruptNesting--;
\r
512 /*-----------------------------------------------------------*/
\r
514 void TIM2_IRQHandler( void )
\r
516 /* Just to verify that the interrupt nesting behaves as expected, increment
\r
517 ulFPUInterruptNesting on entry, and decrement it on exit. */
\r
518 ulFPUInterruptNesting++;
\r
520 /* Fill the FPU registers with 1. */
\r
521 vRegTestClearFlopRegistersToParameterValue( 1UL );
\r
523 /* Trigger a timer 3 interrupt, which will fill the registers with a
\r
524 different value. */
\r
525 NVIC_SetPendingIRQ( TIM3_IRQn );
\r
527 /* Ensure that, after returning from the nesting interrupt, all the FPU
\r
528 registers contain the value to which they were set by this interrupt
\r
530 configASSERT( ulRegTestCheckFlopRegistersContainParameterValue( 1UL ) );
\r
532 ulFPUInterruptNesting--;
\r
534 /*-----------------------------------------------------------*/
\r
536 static void prvOptionallyCreateComprehensveTestApplication( void )
\r
538 #if ( mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY == 0 )
\r
540 TimerHandle_t xCheckTimer = NULL;
\r
542 /* Configure the interrupts used to test FPU registers being used from
\r
543 nested interrupts. */
\r
544 prvSetupNestedFPUInterruptsTest();
\r
546 /* Start all the other standard demo/test tasks. */
\r
547 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
548 vStartDynamicPriorityTasks();
\r
549 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
550 vCreateBlockTimeTasks();
\r
551 vStartCountingSemaphoreTasks();
\r
552 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
553 vStartRecursiveMutexTasks();
\r
554 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
555 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
557 /* Most importantly, start the tasks that use the FPU. */
\r
558 vStartMathTasks( mainFLOP_TASK_PRIORITY );
\r
560 /* Create the register check tasks, as described at the top of this
\r
562 xTaskCreate( vRegTest1Task, "Reg1", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );
\r
563 xTaskCreate( vRegTest2Task, "Reg2", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );
\r
565 /* Create the semaphore that is used to demonstrate a task being
\r
566 synchronised with an interrupt. */
\r
567 vSemaphoreCreateBinary( xTestSemaphore );
\r
569 /* Create the task that is unblocked by the demonstration interrupt. */
\r
570 xTaskCreate( prvButtonTestTask, "BtnTest", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );
\r
572 /* Create the software timer that performs the 'check' functionality,
\r
573 as described at the top of this file. */
\r
574 xCheckTimer = xTimerCreate( "CheckTimer", /* A text name, purely to help debugging. */
\r
575 ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */
\r
576 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
577 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
578 prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */
\r
581 if( xCheckTimer != NULL )
\r
583 xTimerStart( xCheckTimer, mainDONT_BLOCK );
\r
586 /* This task has to be created last as it keeps account of the number of
\r
587 tasks it expects to see running. */
\r
588 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
590 #else /* mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY */
\r
592 /* Just to prevent compiler warnings when the configuration options are
\r
593 set such that these static functions are not used. */
\r
594 ( void ) vRegTest1Task;
\r
595 ( void ) vRegTest2Task;
\r
596 ( void ) prvCheckTimerCallback;
\r
597 ( void ) prvSetupNestedFPUInterruptsTest;
\r
599 #endif /* mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY */
\r
601 /*-----------------------------------------------------------*/
\r
603 void EXTI9_5_IRQHandler(void)
\r
605 long lHigherPriorityTaskWoken = pdFALSE;
\r
607 /* Only line 6 is enabled, so there is no need to test which line generated
\r
609 EXTI_ClearITPendingBit( EXTI_Line6 );
\r
611 /* This interrupt does nothing more than demonstrate how to synchronise a
\r
612 task with an interrupt. First the handler releases a semaphore.
\r
613 lHigherPriorityTaskWoken has been initialised to zero. */
\r
614 xSemaphoreGiveFromISR( xTestSemaphore, &lHigherPriorityTaskWoken );
\r
616 /* If there was a task that was blocked on the semaphore, and giving the
\r
617 semaphore caused the task to unblock, and the unblocked task has a priority
\r
618 higher than the currently executing task (the task that this interrupt
\r
619 interrupted), then lHigherPriorityTaskWoken will have been set to pdTRUE.
\r
620 Passing pdTRUE into the following macro call will cause this interrupt to
\r
621 return directly to the unblocked, higher priority, task. */
\r
622 portEND_SWITCHING_ISR( lHigherPriorityTaskWoken );
\r
624 /*-----------------------------------------------------------*/
\r
626 void vApplicationMallocFailedHook( void )
\r
628 /* vApplicationMallocFailedHook() will only be called if
\r
629 configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
\r
630 function that will get called if a call to pvPortMalloc() fails.
\r
631 pvPortMalloc() is called internally by the kernel whenever a task, queue,
\r
632 timer or semaphore is created. It is also called by various parts of the
\r
633 demo application. If heap_1.c or heap_2.c are used, then the size of the
\r
634 heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
\r
635 FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
\r
636 to query the size of free heap space that remains (although it does not
\r
637 provide information on how the remaining heap might be fragmented). */
\r
638 taskDISABLE_INTERRUPTS();
\r
641 /*-----------------------------------------------------------*/
\r
643 void vApplicationIdleHook( void )
\r
645 /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
\r
646 to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
\r
647 task. It is essential that code added to this hook function never attempts
\r
648 to block in any way (for example, call xQueueReceive() with a block time
\r
649 specified, or call vTaskDelay()). If the application makes use of the
\r
650 vTaskDelete() API function (as this demo application does) then it is also
\r
651 important that vApplicationIdleHook() is permitted to return to its calling
\r
652 function, because it is the responsibility of the idle task to clean up
\r
653 memory allocated by the kernel to any task that has since been deleted. */
\r
655 /*-----------------------------------------------------------*/
\r
657 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
659 ( void ) pcTaskName;
\r
662 /* Run time stack overflow checking is performed if
\r
663 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
664 function is called if a stack overflow is detected. */
\r
665 taskDISABLE_INTERRUPTS();
\r
668 /*-----------------------------------------------------------*/
\r