2 FreeRTOS V7.5.1 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
65 /******************************************************************************
\r
66 * >>>>>> NOTE 1: <<<<<<
\r
68 * main() can be configured to create either a very simple LED flasher demo, or
\r
69 * a more comprehensive test/demo application.
\r
71 * To create a very simple LED flasher example, set the
\r
72 * mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY constant (defined below) to 1. When
\r
73 * this is done, only the standard demo flash tasks are created. The standard
\r
74 * demo flash example creates three tasks, each of which toggle an LED at a
\r
75 * fixed but different frequency.
\r
77 * To create a more comprehensive test and demo application, set
\r
78 * mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY to 0.
\r
80 * >>>>>> NOTE 2: <<<<<<
\r
82 * In addition to the normal set of standard demo tasks, the comprehensive test
\r
83 * makes heavy use of the floating point unit, and forces floating point
\r
84 * instructions to be used from interrupts that nest three deep. The nesting
\r
85 * starts from the tick hook function, resulting is an abnormally long context
\r
86 * switch time. This is done purely to stress test the FPU context switching
\r
87 * implementation, and that part of the test can be removed by setting
\r
88 * configUSE_TICK_HOOK to 0 in FreeRTOSConfig.h.
\r
89 ******************************************************************************
\r
91 * main() creates all the demo application tasks and software timers, then starts
\r
92 * the scheduler. The web documentation provides more details of the standard
\r
93 * demo application tasks, which provide no particular functionality, but do
\r
94 * provide a good example of how to use the FreeRTOS API.
\r
96 * In addition to the standard demo tasks, the following tasks and tests are
\r
97 * defined and/or created within this file:
\r
99 * "Reg test" tasks - These fill both the core and floating point registers with
\r
100 * known values, then check that each register maintains its expected value for
\r
101 * the lifetime of the task. Each task uses a different set of values. The reg
\r
102 * test tasks execute with a very low priority, so get preempted very
\r
103 * frequently. A register containing an unexpected value is indicative of an
\r
104 * error in the context switching mechanism.
\r
106 * "Check" timer - The check software timer period is initially set to three
\r
107 * seconds. The callback function associated with the check software timer
\r
108 * checks that all the standard demo tasks, and the register check tasks, are
\r
109 * not only still executing, but are executing without reporting any errors. If
\r
110 * the check software timer discovers that a task has either stalled, or
\r
111 * reported an error, then it changes its own execution period from the initial
\r
112 * three seconds, to just 200ms. The check software timer callback function
\r
113 * also toggles an LED each time it is called. This provides a visual
\r
114 * indication of the system status: If the LED toggles every three seconds,
\r
115 * then no issues have been discovered. If the LED toggles every 200ms, then
\r
116 * an issue has been discovered with at least one task.
\r
118 * Tick hook - The application tick hook is called from the schedulers tick
\r
119 * interrupt service routine when configUSE_TICK_HOOK is set to 1 in
\r
120 * FreeRTOSConfig.h. In this example, the tick hook is used to test the kernels
\r
121 * handling of the floating point units (FPU) context, both at the task level
\r
122 * and when nesting interrupts access the floating point unit registers. The
\r
123 * tick hook function first fills the FPU registers with a known value, it
\r
124 * then triggers a medium priority interrupt. The medium priority interrupt
\r
125 * fills the FPU registers with a different value, and triggers a high priority
\r
126 * interrupt. The high priority interrupt once again fills the the FPU
\r
127 * registers with a known value before returning to the medium priority
\r
128 * interrupt. The medium priority interrupt checks that the FPU registers
\r
129 * contain the values that it wrote to them, then returns to the tick hook
\r
130 * function. Finally, the tick hook function checks that the FPU registers
\r
131 * contain the values that it wrote to them, before it too returns.
\r
133 * Button interrupt - The button marked "USER" on the starter kit is used to
\r
134 * demonstrate how to write an interrupt service routine, and how to synchronise
\r
135 * a task with an interrupt. A task is created that blocks on a test semaphore.
\r
136 * When the USER button is pressed, the button interrupt handler gives the
\r
137 * semaphore, causing the task to unblock. When the task unblocks, it simply
\r
138 * increments an execution count variable, then returns to block on the
\r
142 /* Kernel includes. */
\r
143 #include "FreeRTOS.h"
\r
145 #include "timers.h"
\r
146 #include "semphr.h"
\r
148 /* Demo application includes. */
\r
149 #include "partest.h"
\r
152 #include "integer.h"
\r
154 #include "semtest.h"
\r
155 #include "dynamic.h"
\r
156 #include "BlockQ.h"
\r
157 #include "blocktim.h"
\r
158 #include "countsem.h"
\r
159 #include "GenQTest.h"
\r
160 #include "recmutex.h"
\r
163 /* Hardware and starter kit includes. */
\r
164 #include "arm_comm.h"
\r
165 #include "iar_stm32f407zg_sk.h"
\r
166 #include "stm32f4xx.h"
\r
167 #include "stm32f4xx_conf.h"
\r
169 /* Priorities for the demo application tasks. */
\r
170 #define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 1UL )
\r
171 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
172 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1UL )
\r
173 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
174 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3UL )
\r
175 #define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
177 /* The LED used by the check timer. */
\r
178 #define mainCHECK_LED ( 3UL )
\r
180 /* A block time of zero simply means "don't block". */
\r
181 #define mainDONT_BLOCK ( 0UL )
\r
183 /* The period after which the check timer will expire, in ms, provided no errors
\r
184 have been reported by any of the standard demo tasks. ms are converted to the
\r
185 equivalent in ticks using the portTICK_RATE_MS constant. */
\r
186 #define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_RATE_MS )
\r
188 /* The period at which the check timer will expire, in ms, if an error has been
\r
189 reported in one of the standard demo tasks. ms are converted to the equivalent
\r
190 in ticks using the portTICK_RATE_MS constant. */
\r
191 #define mainERROR_CHECK_TIMER_PERIOD_MS ( 200UL / portTICK_RATE_MS )
\r
193 /* Set mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY to 1 to create a simple demo.
\r
194 Set mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY to 0 to create a much more
\r
195 comprehensive test application. See the comments at the top of this file, and
\r
196 the documentation page on the http://www.FreeRTOS.org web site for more
\r
198 #define mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY 0
\r
200 /*-----------------------------------------------------------*/
\r
203 * Set up the hardware ready to run this demo.
\r
205 static void prvSetupHardware( void );
\r
208 * The check timer callback function, as described at the top of this file.
\r
210 static void prvCheckTimerCallback( xTimerHandle xTimer );
\r
213 * Configure the interrupts used to test the interrupt nesting depth as
\r
214 * described at the top of this file.
\r
216 static void prvSetupNestedFPUInterruptsTest( void );
\r
219 * Register check tasks, and the tasks used to write over and check the contents
\r
220 * of the FPU registers, as described at the top of this file. The nature of
\r
221 * these files necessitates that they are written in an assembly file.
\r
223 extern void vRegTest1Task( void *pvParameters );
\r
224 extern void vRegTest2Task( void *pvParameters );
\r
225 extern void vRegTestClearFlopRegistersToParameterValue( unsigned long ulValue );
\r
226 extern unsigned long ulRegTestCheckFlopRegistersContainParameterValue( unsigned long ulValue );
\r
229 * The task that is synchronised with the button interrupt. This is done just
\r
230 * to demonstrate how to write interrupt service routines, and how to
\r
231 * synchronise a task with an interrupt.
\r
233 static void prvButtonTestTask( void *pvParameters );
\r
236 * This file can be used to create either a simple LED flasher example, or a
\r
237 * comprehensive test/demo application - depending on the setting of the
\r
238 * mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY constant defined above. If
\r
239 * mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY is set to 1, then the following
\r
240 * function will create a lot of additional tasks and a software timer. If
\r
241 * mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY is set to 0, then the following
\r
242 * function will do nothing.
\r
244 static void prvOptionallyCreateComprehensveTestApplication( void );
\r
246 /*-----------------------------------------------------------*/
\r
248 /* The following two variables are used to communicate the status of the
\r
249 register check tasks to the check software timer. If the variables keep
\r
250 incrementing, then the register check tasks has not discovered any errors. If
\r
251 a variable stops incrementing, then an error has been found. */
\r
252 volatile unsigned long ulRegTest1LoopCounter = 0UL, ulRegTest2LoopCounter = 0UL;
\r
254 /* The following variables are used to verify that the interrupt nesting depth
\r
255 is as intended. ulFPUInterruptNesting is incremented on entry to an interrupt
\r
256 that uses the FPU, and decremented on exit of the same interrupt.
\r
257 ulMaxFPUInterruptNesting latches the highest value reached by
\r
258 ulFPUInterruptNesting. These variables have no other purpose. */
\r
259 volatile unsigned long ulFPUInterruptNesting = 0UL, ulMaxFPUInterruptNesting = 0UL;
\r
261 /* The semaphore used to demonstrate a task being synchronised with an
\r
263 static xSemaphoreHandle xTestSemaphore = NULL;
\r
265 /* The variable that is incremented by the task synchronised with the button
\r
267 volatile unsigned long ulButtonPressCounts = 0UL;
\r
269 /*-----------------------------------------------------------*/
\r
273 /* Configure the hardware ready to run the test. */
\r
274 prvSetupHardware();
\r
276 /* Start standard demo/test application flash tasks. See the comments at
\r
277 the top of this file. The LED flash tasks are always created. The other
\r
278 tasks are only created if mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY is set to
\r
279 0 (at the top of this file). See the comments at the top of this file for
\r
280 more information. */
\r
281 vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );
\r
283 /* The following function will only create more tasks and timers if
\r
284 mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY is set to 0 (at the top of this
\r
285 file). See the comments at the top of this file for more information. */
\r
286 prvOptionallyCreateComprehensveTestApplication();
\r
288 /* Start the scheduler. */
\r
289 vTaskStartScheduler();
\r
291 /* If all is well, the scheduler will now be running, and the following line
\r
292 will never be reached. If the following line does execute, then there was
\r
293 insufficient FreeRTOS heap memory available for the idle and/or timer tasks
\r
294 to be created. See the memory management section on the FreeRTOS web site
\r
295 for more details. */
\r
298 /*-----------------------------------------------------------*/
\r
300 static void prvCheckTimerCallback( xTimerHandle xTimer )
\r
302 static long lChangedTimerPeriodAlready = pdFALSE;
\r
303 static unsigned long ulLastRegTest1Value = 0, ulLastRegTest2Value = 0;
\r
304 long lErrorFound = pdFALSE;
\r
306 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
307 that they are all still running, and that none have detected an error. */
\r
309 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
311 lErrorFound = pdTRUE;
\r
314 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
316 lErrorFound = pdTRUE;
\r
319 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
321 lErrorFound = pdTRUE;
\r
324 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
326 lErrorFound = pdTRUE;
\r
329 if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
331 lErrorFound = pdTRUE;
\r
334 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
336 lErrorFound = pdTRUE;
\r
339 if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
341 lErrorFound = pdTRUE;
\r
344 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
346 lErrorFound = pdTRUE;
\r
349 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
351 lErrorFound = pdTRUE;
\r
354 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
356 lErrorFound = pdTRUE;
\r
359 /* Check that the register test 1 task is still running. */
\r
360 if( ulLastRegTest1Value == ulRegTest1LoopCounter )
\r
362 lErrorFound = pdTRUE;
\r
364 ulLastRegTest1Value = ulRegTest1LoopCounter;
\r
366 /* Check that the register test 2 task is still running. */
\r
367 if( ulLastRegTest2Value == ulRegTest2LoopCounter )
\r
369 lErrorFound = pdTRUE;
\r
371 ulLastRegTest2Value = ulRegTest2LoopCounter;
\r
373 /* Toggle the check LED to give an indication of the system status. If
\r
374 the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then
\r
375 everything is ok. A faster toggle indicates an error. */
\r
376 vParTestToggleLED( mainCHECK_LED );
\r
378 /* Have any errors been latch in lErrorFound? If so, shorten the
\r
379 period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.
\r
380 This will result in an increase in the rate at which mainCHECK_LED
\r
382 if( lErrorFound != pdFALSE )
\r
384 if( lChangedTimerPeriodAlready == pdFALSE )
\r
386 lChangedTimerPeriodAlready = pdTRUE;
\r
388 /* This call to xTimerChangePeriod() uses a zero block time.
\r
389 Functions called from inside of a timer callback function must
\r
390 *never* attempt to block. */
\r
391 xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );
\r
395 /*-----------------------------------------------------------*/
\r
397 static void prvButtonTestTask( void *pvParameters )
\r
399 configASSERT( xTestSemaphore );
\r
401 /* This is the task used as an example of how to synchronise a task with
\r
402 an interrupt. Each time the button interrupt gives the semaphore, this task
\r
403 will unblock, increment its execution counter, then return to block
\r
406 /* Take the semaphore before started to ensure it is in the correct
\r
408 xSemaphoreTake( xTestSemaphore, mainDONT_BLOCK );
\r
412 xSemaphoreTake( xTestSemaphore, portMAX_DELAY );
\r
413 ulButtonPressCounts++;
\r
416 /*-----------------------------------------------------------*/
\r
418 static void prvSetupHardware( void )
\r
420 /* Setup STM32 system (clock, PLL and Flash configuration) */
\r
423 /* Ensure all priority bits are assigned as preemption priority bits. */
\r
424 NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );
\r
426 /* Setup the LED outputs. */
\r
427 vParTestInitialise();
\r
429 /* Configure the button input. This configures the interrupt to use the
\r
430 lowest interrupt priority, so it is ok to use the ISR safe FreeRTOS API
\r
431 from the button interrupt handler. */
\r
432 STM_EVAL_PBInit( BUTTON_USER, BUTTON_MODE_EXTI );
\r
434 /*-----------------------------------------------------------*/
\r
436 void vApplicationTickHook( void )
\r
438 #if ( mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY == 0 )
\r
440 /* Just to verify that the interrupt nesting behaves as expected,
\r
441 increment ulFPUInterruptNesting on entry, and decrement it on exit. */
\r
442 ulFPUInterruptNesting++;
\r
444 /* Fill the FPU registers with 0. */
\r
445 vRegTestClearFlopRegistersToParameterValue( 0UL );
\r
447 /* Trigger a timer 2 interrupt, which will fill the registers with a
\r
448 different value and itself trigger a timer 3 interrupt. Note that the
\r
449 timers are not actually used. The timer 2 and 3 interrupt vectors are
\r
450 just used for convenience. */
\r
451 NVIC_SetPendingIRQ( TIM2_IRQn );
\r
453 /* Ensure that, after returning from the nested interrupts, all the FPU
\r
454 registers contain the value to which they were set by the tick hook
\r
456 configASSERT( ulRegTestCheckFlopRegistersContainParameterValue( 0UL ) );
\r
458 ulFPUInterruptNesting--;
\r
462 /*-----------------------------------------------------------*/
\r
464 static void prvSetupNestedFPUInterruptsTest( void )
\r
466 NVIC_InitTypeDef NVIC_InitStructure;
\r
468 /* Enable the TIM2 interrupt in the NVIC. The timer itself is not used,
\r
469 just its interrupt vector to force nesting from software. TIM2 must have
\r
470 a lower priority than TIM3, and both must have priorities above
\r
471 configMAX_SYSCALL_INTERRUPT_PRIORITY. */
\r
472 NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
\r
473 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY - 1;
\r
474 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
\r
475 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
\r
476 NVIC_Init( &NVIC_InitStructure );
\r
478 /* Enable the TIM3 interrupt in the NVIC. The timer itself is not used,
\r
479 just its interrupt vector to force nesting from software. TIM2 must have
\r
480 a lower priority than TIM3, and both must have priorities above
\r
481 configMAX_SYSCALL_INTERRUPT_PRIORITY. */
\r
482 NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
\r
483 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY - 2;
\r
484 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
\r
485 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
\r
486 NVIC_Init( &NVIC_InitStructure );
\r
488 /*-----------------------------------------------------------*/
\r
490 void TIM3_IRQHandler( void )
\r
492 /* Just to verify that the interrupt nesting behaves as expected, increment
\r
493 ulFPUInterruptNesting on entry, and decrement it on exit. */
\r
494 ulFPUInterruptNesting++;
\r
496 /* This is the highest priority interrupt in the chain of forced nesting
\r
497 interrupts, so latch the maximum value reached by ulFPUInterruptNesting.
\r
498 This is done purely to allow verification that the nesting depth reaches
\r
500 if( ulFPUInterruptNesting > ulMaxFPUInterruptNesting )
\r
502 ulMaxFPUInterruptNesting = ulFPUInterruptNesting;
\r
505 /* Fill the FPU registers with 99 to overwrite the values written by
\r
506 TIM2_IRQHandler(). */
\r
507 vRegTestClearFlopRegistersToParameterValue( 99UL );
\r
509 ulFPUInterruptNesting--;
\r
511 /*-----------------------------------------------------------*/
\r
513 void TIM2_IRQHandler( void )
\r
515 /* Just to verify that the interrupt nesting behaves as expected, increment
\r
516 ulFPUInterruptNesting on entry, and decrement it on exit. */
\r
517 ulFPUInterruptNesting++;
\r
519 /* Fill the FPU registers with 1. */
\r
520 vRegTestClearFlopRegistersToParameterValue( 1UL );
\r
522 /* Trigger a timer 3 interrupt, which will fill the registers with a
\r
523 different value. */
\r
524 NVIC_SetPendingIRQ( TIM3_IRQn );
\r
526 /* Ensure that, after returning from the nesting interrupt, all the FPU
\r
527 registers contain the value to which they were set by this interrupt
\r
529 configASSERT( ulRegTestCheckFlopRegistersContainParameterValue( 1UL ) );
\r
531 ulFPUInterruptNesting--;
\r
533 /*-----------------------------------------------------------*/
\r
535 static void prvOptionallyCreateComprehensveTestApplication( void )
\r
537 #if ( mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY == 0 )
\r
539 xTimerHandle xCheckTimer = NULL;
\r
541 /* Configure the interrupts used to test FPU registers being used from
\r
542 nested interrupts. */
\r
543 prvSetupNestedFPUInterruptsTest();
\r
545 /* Start all the other standard demo/test tasks. */
\r
546 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
547 vStartDynamicPriorityTasks();
\r
548 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
549 vCreateBlockTimeTasks();
\r
550 vStartCountingSemaphoreTasks();
\r
551 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
552 vStartRecursiveMutexTasks();
\r
553 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
554 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
556 /* Most importantly, start the tasks that use the FPU. */
\r
557 vStartMathTasks( mainFLOP_TASK_PRIORITY );
\r
559 /* Create the register check tasks, as described at the top of this
\r
561 xTaskCreate( vRegTest1Task, ( signed char * ) "Reg1", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );
\r
562 xTaskCreate( vRegTest2Task, ( signed char * ) "Reg2", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );
\r
564 /* Create the semaphore that is used to demonstrate a task being
\r
565 synchronised with an interrupt. */
\r
566 vSemaphoreCreateBinary( xTestSemaphore );
\r
568 /* Create the task that is unblocked by the demonstration interrupt. */
\r
569 xTaskCreate( prvButtonTestTask, ( signed char * ) "BtnTest", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );
\r
571 /* Create the software timer that performs the 'check' functionality,
\r
572 as described at the top of this file. */
\r
573 xCheckTimer = xTimerCreate( ( const signed char * ) "CheckTimer",/* A text name, purely to help debugging. */
\r
574 ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */
\r
575 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
576 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
577 prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */
\r
580 if( xCheckTimer != NULL )
\r
582 xTimerStart( xCheckTimer, mainDONT_BLOCK );
\r
585 /* This task has to be created last as it keeps account of the number of
\r
586 tasks it expects to see running. */
\r
587 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
589 #else /* mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY */
\r
591 /* Just to prevent compiler warnings when the configuration options are
\r
592 set such that these static functions are not used. */
\r
593 ( void ) vRegTest1Task;
\r
594 ( void ) vRegTest2Task;
\r
595 ( void ) prvCheckTimerCallback;
\r
596 ( void ) prvSetupNestedFPUInterruptsTest;
\r
598 #endif /* mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY */
\r
600 /*-----------------------------------------------------------*/
\r
602 void EXTI9_5_IRQHandler(void)
\r
604 long lHigherPriorityTaskWoken = pdFALSE;
\r
606 /* Only line 6 is enabled, so there is no need to test which line generated
\r
608 EXTI_ClearITPendingBit( EXTI_Line6 );
\r
610 /* This interrupt does nothing more than demonstrate how to synchronise a
\r
611 task with an interrupt. First the handler releases a semaphore.
\r
612 lHigherPriorityTaskWoken has been initialised to zero. */
\r
613 xSemaphoreGiveFromISR( xTestSemaphore, &lHigherPriorityTaskWoken );
\r
615 /* If there was a task that was blocked on the semaphore, and giving the
\r
616 semaphore caused the task to unblock, and the unblocked task has a priority
\r
617 higher than the currently executing task (the task that this interrupt
\r
618 interrupted), then lHigherPriorityTaskWoken will have been set to pdTRUE.
\r
619 Passing pdTRUE into the following macro call will cause this interrupt to
\r
620 return directly to the unblocked, higher priority, task. */
\r
621 portEND_SWITCHING_ISR( lHigherPriorityTaskWoken );
\r
623 /*-----------------------------------------------------------*/
\r
625 void vApplicationMallocFailedHook( void )
\r
627 /* vApplicationMallocFailedHook() will only be called if
\r
628 configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
\r
629 function that will get called if a call to pvPortMalloc() fails.
\r
630 pvPortMalloc() is called internally by the kernel whenever a task, queue,
\r
631 timer or semaphore is created. It is also called by various parts of the
\r
632 demo application. If heap_1.c or heap_2.c are used, then the size of the
\r
633 heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
\r
634 FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
\r
635 to query the size of free heap space that remains (although it does not
\r
636 provide information on how the remaining heap might be fragmented). */
\r
637 taskDISABLE_INTERRUPTS();
\r
640 /*-----------------------------------------------------------*/
\r
642 void vApplicationIdleHook( void )
\r
644 /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
\r
645 to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
\r
646 task. It is essential that code added to this hook function never attempts
\r
647 to block in any way (for example, call xQueueReceive() with a block time
\r
648 specified, or call vTaskDelay()). If the application makes use of the
\r
649 vTaskDelete() API function (as this demo application does) then it is also
\r
650 important that vApplicationIdleHook() is permitted to return to its calling
\r
651 function, because it is the responsibility of the idle task to clean up
\r
652 memory allocated by the kernel to any task that has since been deleted. */
\r
654 /*-----------------------------------------------------------*/
\r
656 void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )
\r
658 ( void ) pcTaskName;
\r
661 /* Run time stack overflow checking is performed if
\r
662 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
663 function is called if a stack overflow is detected. */
\r
664 taskDISABLE_INTERRUPTS();
\r
667 /*-----------------------------------------------------------*/
\r