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
96 /******************************************************************************
\r
97 * >>>>>> NOTE 1: <<<<<<
\r
99 * main() can be configured to create either a very simple LED flasher demo, or
\r
100 * a more comprehensive test/demo application.
\r
102 * To create a very simple LED flasher example, set the
\r
103 * mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY constant (defined below) to 1. When
\r
104 * this is done, only the standard demo flash tasks are created. The standard
\r
105 * demo flash example creates three tasks, each of which toggle an LED at a
\r
106 * fixed but different frequency.
\r
108 * To create a more comprehensive test and demo application, set
\r
109 * mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY to 0.
\r
111 * >>>>>> NOTE 2: <<<<<<
\r
113 * In addition to the normal set of standard demo tasks, the comprehensive test
\r
114 * makes heavy use of the floating point unit, and forces floating point
\r
115 * instructions to be used from interrupts that nest three deep. The nesting
\r
116 * starts from the tick hook function, resulting is an abnormally long context
\r
117 * switch time. This is done purely to stress test the FPU context switching
\r
118 * implementation, and that part of the test can be removed by setting
\r
119 * configUSE_TICK_HOOK to 0 in FreeRTOSConfig.h.
\r
120 ******************************************************************************
\r
122 * main() creates all the demo application tasks and software timers, then starts
\r
123 * the scheduler. The web documentation provides more details of the standard
\r
124 * demo application tasks, which provide no particular functionality, but do
\r
125 * provide a good example of how to use the FreeRTOS API.
\r
127 * In addition to the standard demo tasks, the following tasks and tests are
\r
128 * defined and/or created within this file:
\r
130 * "Reg test" tasks - These fill both the core and floating point registers with
\r
131 * known values, then check that each register maintains its expected value for
\r
132 * the lifetime of the task. Each task uses a different set of values. The reg
\r
133 * test tasks execute with a very low priority, so get preempted very
\r
134 * frequently. A register containing an unexpected value is indicative of an
\r
135 * error in the context switching mechanism.
\r
137 * "Check" timer - The check software timer period is initially set to three
\r
138 * seconds. The callback function associated with the check software timer
\r
139 * checks that all the standard demo tasks, and the register check tasks, are
\r
140 * not only still executing, but are executing without reporting any errors. If
\r
141 * the check software timer discovers that a task has either stalled, or
\r
142 * reported an error, then it changes its own execution period from the initial
\r
143 * three seconds, to just 200ms. The check software timer callback function
\r
144 * also toggles an LED each time it is called. This provides a visual
\r
145 * indication of the system status: If the LED toggles every three seconds,
\r
146 * then no issues have been discovered. If the LED toggles every 200ms, then
\r
147 * an issue has been discovered with at least one task.
\r
149 * Tick hook - The application tick hook is called from the schedulers tick
\r
150 * interrupt service routine when configUSE_TICK_HOOK is set to 1 in
\r
151 * FreeRTOSConfig.h. In this example, the tick hook is used to test the kernels
\r
152 * handling of the floating point units (FPU) context, both at the task level
\r
153 * and when nesting interrupts access the floating point unit registers. The
\r
154 * tick hook function first fills the FPU registers with a known value, it
\r
155 * then triggers a medium priority interrupt. The medium priority interrupt
\r
156 * fills the FPU registers with a different value, and triggers a high priority
\r
157 * interrupt. The high priority interrupt once again fills the the FPU
\r
158 * registers with a known value before returning to the medium priority
\r
159 * interrupt. The medium priority interrupt checks that the FPU registers
\r
160 * contain the values that it wrote to them, then returns to the tick hook
\r
161 * function. Finally, the tick hook function checks that the FPU registers
\r
162 * contain the values that it wrote to them, before it too returns.
\r
164 * Button interrupt - The button marked "USER" on the starter kit is used to
\r
165 * demonstrate how to write an interrupt service routine, and how to synchronise
\r
166 * a task with an interrupt. A task is created that blocks on a test semaphore.
\r
167 * When the USER button is pressed, the button interrupt handler gives the
\r
168 * semaphore, causing the task to unblock. When the task unblocks, it simply
\r
169 * increments an execution count variable, then returns to block on the
\r
173 /* Kernel includes. */
\r
174 #include "FreeRTOS.h"
\r
176 #include "timers.h"
\r
177 #include "semphr.h"
\r
179 /* Demo application includes. */
\r
180 #include "partest.h"
\r
183 #include "integer.h"
\r
185 #include "semtest.h"
\r
186 #include "dynamic.h"
\r
187 #include "BlockQ.h"
\r
188 #include "blocktim.h"
\r
189 #include "countsem.h"
\r
190 #include "GenQTest.h"
\r
191 #include "recmutex.h"
\r
194 /* Hardware and starter kit includes. */
\r
195 #include "arm_comm.h"
\r
196 #include "iar_stm32f407zg_sk.h"
\r
197 #include "stm32f4xx.h"
\r
198 #include "stm32f4xx_conf.h"
\r
200 /* Priorities for the demo application tasks. */
\r
201 #define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 1UL )
\r
202 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
203 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1UL )
\r
204 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
205 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3UL )
\r
206 #define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
208 /* The LED used by the check timer. */
\r
209 #define mainCHECK_LED ( 3UL )
\r
211 /* A block time of zero simply means "don't block". */
\r
212 #define mainDONT_BLOCK ( 0UL )
\r
214 /* The period after which the check timer will expire, in ms, provided no errors
\r
215 have been reported by any of the standard demo tasks. ms are converted to the
\r
216 equivalent in ticks using the portTICK_PERIOD_MS constant. */
\r
217 #define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_PERIOD_MS )
\r
219 /* The period at which the check timer will expire, in ms, if an error has been
\r
220 reported in one of the standard demo tasks. ms are converted to the equivalent
\r
221 in ticks using the portTICK_PERIOD_MS constant. */
\r
222 #define mainERROR_CHECK_TIMER_PERIOD_MS ( 200UL / portTICK_PERIOD_MS )
\r
224 /* Set mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY to 1 to create a simple demo.
\r
225 Set mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY to 0 to create a much more
\r
226 comprehensive test application. See the comments at the top of this file, and
\r
227 the documentation page on the http://www.FreeRTOS.org web site for more
\r
229 #define mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY 0
\r
231 /*-----------------------------------------------------------*/
\r
234 * Set up the hardware ready to run this demo.
\r
236 static void prvSetupHardware( void );
\r
239 * The check timer callback function, as described at the top of this file.
\r
241 static void prvCheckTimerCallback( TimerHandle_t xTimer );
\r
244 * Configure the interrupts used to test the interrupt nesting depth as
\r
245 * described at the top of this file.
\r
247 static void prvSetupNestedFPUInterruptsTest( void );
\r
250 * Register check tasks, and the tasks used to write over and check the contents
\r
251 * of the FPU registers, as described at the top of this file. The nature of
\r
252 * these files necessitates that they are written in an assembly file.
\r
254 extern void vRegTest1Task( void *pvParameters );
\r
255 extern void vRegTest2Task( void *pvParameters );
\r
256 extern void vRegTestClearFlopRegistersToParameterValue( unsigned long ulValue );
\r
257 extern unsigned long ulRegTestCheckFlopRegistersContainParameterValue( unsigned long ulValue );
\r
260 * The task that is synchronised with the button interrupt. This is done just
\r
261 * to demonstrate how to write interrupt service routines, and how to
\r
262 * synchronise a task with an interrupt.
\r
264 static void prvButtonTestTask( void *pvParameters );
\r
267 * This file can be used to create either a simple LED flasher example, or a
\r
268 * comprehensive test/demo application - depending on the setting of the
\r
269 * mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY constant defined above. If
\r
270 * mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY is set to 1, then the following
\r
271 * function will create a lot of additional tasks and a software timer. If
\r
272 * mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY is set to 0, then the following
\r
273 * function will do nothing.
\r
275 static void prvOptionallyCreateComprehensveTestApplication( void );
\r
277 /*-----------------------------------------------------------*/
\r
279 /* The following two variables are used to communicate the status of the
\r
280 register check tasks to the check software timer. If the variables keep
\r
281 incrementing, then the register check tasks has not discovered any errors. If
\r
282 a variable stops incrementing, then an error has been found. */
\r
283 volatile unsigned long ulRegTest1LoopCounter = 0UL, ulRegTest2LoopCounter = 0UL;
\r
285 /* The following variables are used to verify that the interrupt nesting depth
\r
286 is as intended. ulFPUInterruptNesting is incremented on entry to an interrupt
\r
287 that uses the FPU, and decremented on exit of the same interrupt.
\r
288 ulMaxFPUInterruptNesting latches the highest value reached by
\r
289 ulFPUInterruptNesting. These variables have no other purpose. */
\r
290 volatile unsigned long ulFPUInterruptNesting = 0UL, ulMaxFPUInterruptNesting = 0UL;
\r
292 /* The semaphore used to demonstrate a task being synchronised with an
\r
294 static SemaphoreHandle_t xTestSemaphore = NULL;
\r
296 /* The variable that is incremented by the task synchronised with the button
\r
298 volatile unsigned long ulButtonPressCounts = 0UL;
\r
300 /*-----------------------------------------------------------*/
\r
304 /* Configure the hardware ready to run the test. */
\r
305 prvSetupHardware();
\r
307 /* Start standard demo/test application flash tasks. See the comments at
\r
308 the top of this file. The LED flash tasks are always created. The other
\r
309 tasks are only created if mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY is set to
\r
310 0 (at the top of this file). See the comments at the top of this file for
\r
311 more information. */
\r
312 vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );
\r
314 /* The following function will only create more tasks and timers if
\r
315 mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY is set to 0 (at the top of this
\r
316 file). See the comments at the top of this file for more information. */
\r
317 prvOptionallyCreateComprehensveTestApplication();
\r
319 /* Start the scheduler. */
\r
320 vTaskStartScheduler();
\r
322 /* If all is well, the scheduler will now be running, and the following line
\r
323 will never be reached. If the following line does execute, then there was
\r
324 insufficient FreeRTOS heap memory available for the idle and/or timer tasks
\r
325 to be created. See the memory management section on the FreeRTOS web site
\r
326 for more details. */
\r
329 /*-----------------------------------------------------------*/
\r
331 static void prvCheckTimerCallback( TimerHandle_t xTimer )
\r
333 static long lChangedTimerPeriodAlready = pdFALSE;
\r
334 static unsigned long ulLastRegTest1Value = 0, ulLastRegTest2Value = 0;
\r
335 long lErrorFound = pdFALSE;
\r
337 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
338 that they are all still running, and that none have detected an error. */
\r
340 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
342 lErrorFound = pdTRUE;
\r
345 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
347 lErrorFound = pdTRUE;
\r
350 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
352 lErrorFound = pdTRUE;
\r
355 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
357 lErrorFound = pdTRUE;
\r
360 if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
362 lErrorFound = pdTRUE;
\r
365 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
367 lErrorFound = pdTRUE;
\r
370 if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
372 lErrorFound = pdTRUE;
\r
375 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
377 lErrorFound = pdTRUE;
\r
380 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
382 lErrorFound = pdTRUE;
\r
385 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
387 lErrorFound = pdTRUE;
\r
390 /* Check that the register test 1 task is still running. */
\r
391 if( ulLastRegTest1Value == ulRegTest1LoopCounter )
\r
393 lErrorFound = pdTRUE;
\r
395 ulLastRegTest1Value = ulRegTest1LoopCounter;
\r
397 /* Check that the register test 2 task is still running. */
\r
398 if( ulLastRegTest2Value == ulRegTest2LoopCounter )
\r
400 lErrorFound = pdTRUE;
\r
402 ulLastRegTest2Value = ulRegTest2LoopCounter;
\r
404 /* Toggle the check LED to give an indication of the system status. If
\r
405 the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then
\r
406 everything is ok. A faster toggle indicates an error. */
\r
407 vParTestToggleLED( mainCHECK_LED );
\r
409 /* Have any errors been latch in lErrorFound? If so, shorten the
\r
410 period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.
\r
411 This will result in an increase in the rate at which mainCHECK_LED
\r
413 if( lErrorFound != pdFALSE )
\r
415 if( lChangedTimerPeriodAlready == pdFALSE )
\r
417 lChangedTimerPeriodAlready = pdTRUE;
\r
419 /* This call to xTimerChangePeriod() uses a zero block time.
\r
420 Functions called from inside of a timer callback function must
\r
421 *never* attempt to block. */
\r
422 xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );
\r
426 /*-----------------------------------------------------------*/
\r
428 static void prvButtonTestTask( void *pvParameters )
\r
430 configASSERT( xTestSemaphore );
\r
432 /* This is the task used as an example of how to synchronise a task with
\r
433 an interrupt. Each time the button interrupt gives the semaphore, this task
\r
434 will unblock, increment its execution counter, then return to block
\r
437 /* Take the semaphore before started to ensure it is in the correct
\r
439 xSemaphoreTake( xTestSemaphore, mainDONT_BLOCK );
\r
443 xSemaphoreTake( xTestSemaphore, portMAX_DELAY );
\r
444 ulButtonPressCounts++;
\r
447 /*-----------------------------------------------------------*/
\r
449 static void prvSetupHardware( void )
\r
451 /* Setup STM32 system (clock, PLL and Flash configuration) */
\r
454 /* Ensure all priority bits are assigned as preemption priority bits. */
\r
455 NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );
\r
457 /* Setup the LED outputs. */
\r
458 vParTestInitialise();
\r
460 /* Configure the button input. This configures the interrupt to use the
\r
461 lowest interrupt priority, so it is ok to use the ISR safe FreeRTOS API
\r
462 from the button interrupt handler. */
\r
463 STM_EVAL_PBInit( BUTTON_USER, BUTTON_MODE_EXTI );
\r
465 /*-----------------------------------------------------------*/
\r
467 void vApplicationTickHook( void )
\r
469 #if ( mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY == 0 )
\r
471 /* Just to verify that the interrupt nesting behaves as expected,
\r
472 increment ulFPUInterruptNesting on entry, and decrement it on exit. */
\r
473 ulFPUInterruptNesting++;
\r
475 /* Fill the FPU registers with 0. */
\r
476 vRegTestClearFlopRegistersToParameterValue( 0UL );
\r
478 /* Trigger a timer 2 interrupt, which will fill the registers with a
\r
479 different value and itself trigger a timer 3 interrupt. Note that the
\r
480 timers are not actually used. The timer 2 and 3 interrupt vectors are
\r
481 just used for convenience. */
\r
482 NVIC_SetPendingIRQ( TIM2_IRQn );
\r
484 /* Ensure that, after returning from the nested interrupts, all the FPU
\r
485 registers contain the value to which they were set by the tick hook
\r
487 configASSERT( ulRegTestCheckFlopRegistersContainParameterValue( 0UL ) );
\r
489 ulFPUInterruptNesting--;
\r
493 /*-----------------------------------------------------------*/
\r
495 static void prvSetupNestedFPUInterruptsTest( void )
\r
497 NVIC_InitTypeDef NVIC_InitStructure;
\r
499 /* Enable the TIM2 interrupt in the NVIC. The timer itself is not used,
\r
500 just its interrupt vector to force nesting from software. TIM2 must have
\r
501 a lower priority than TIM3, and both must have priorities above
\r
502 configMAX_SYSCALL_INTERRUPT_PRIORITY. */
\r
503 NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
\r
504 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY - 1;
\r
505 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
\r
506 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
\r
507 NVIC_Init( &NVIC_InitStructure );
\r
509 /* Enable the TIM3 interrupt in the NVIC. The timer itself is not used,
\r
510 just its interrupt vector to force nesting from software. TIM2 must have
\r
511 a lower priority than TIM3, and both must have priorities above
\r
512 configMAX_SYSCALL_INTERRUPT_PRIORITY. */
\r
513 NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
\r
514 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY - 2;
\r
515 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
\r
516 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
\r
517 NVIC_Init( &NVIC_InitStructure );
\r
519 /*-----------------------------------------------------------*/
\r
521 void TIM3_IRQHandler( void )
\r
523 /* Just to verify that the interrupt nesting behaves as expected, increment
\r
524 ulFPUInterruptNesting on entry, and decrement it on exit. */
\r
525 ulFPUInterruptNesting++;
\r
527 /* This is the highest priority interrupt in the chain of forced nesting
\r
528 interrupts, so latch the maximum value reached by ulFPUInterruptNesting.
\r
529 This is done purely to allow verification that the nesting depth reaches
\r
531 if( ulFPUInterruptNesting > ulMaxFPUInterruptNesting )
\r
533 ulMaxFPUInterruptNesting = ulFPUInterruptNesting;
\r
536 /* Fill the FPU registers with 99 to overwrite the values written by
\r
537 TIM2_IRQHandler(). */
\r
538 vRegTestClearFlopRegistersToParameterValue( 99UL );
\r
540 ulFPUInterruptNesting--;
\r
542 /*-----------------------------------------------------------*/
\r
544 void TIM2_IRQHandler( void )
\r
546 /* Just to verify that the interrupt nesting behaves as expected, increment
\r
547 ulFPUInterruptNesting on entry, and decrement it on exit. */
\r
548 ulFPUInterruptNesting++;
\r
550 /* Fill the FPU registers with 1. */
\r
551 vRegTestClearFlopRegistersToParameterValue( 1UL );
\r
553 /* Trigger a timer 3 interrupt, which will fill the registers with a
\r
554 different value. */
\r
555 NVIC_SetPendingIRQ( TIM3_IRQn );
\r
557 /* Ensure that, after returning from the nesting interrupt, all the FPU
\r
558 registers contain the value to which they were set by this interrupt
\r
560 configASSERT( ulRegTestCheckFlopRegistersContainParameterValue( 1UL ) );
\r
562 ulFPUInterruptNesting--;
\r
564 /*-----------------------------------------------------------*/
\r
566 static void prvOptionallyCreateComprehensveTestApplication( void )
\r
568 #if ( mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY == 0 )
\r
570 TimerHandle_t xCheckTimer = NULL;
\r
572 /* Configure the interrupts used to test FPU registers being used from
\r
573 nested interrupts. */
\r
574 prvSetupNestedFPUInterruptsTest();
\r
576 /* Start all the other standard demo/test tasks. */
\r
577 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
578 vStartDynamicPriorityTasks();
\r
579 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
580 vCreateBlockTimeTasks();
\r
581 vStartCountingSemaphoreTasks();
\r
582 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
583 vStartRecursiveMutexTasks();
\r
584 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
585 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
587 /* Most importantly, start the tasks that use the FPU. */
\r
588 vStartMathTasks( mainFLOP_TASK_PRIORITY );
\r
590 /* Create the register check tasks, as described at the top of this
\r
592 xTaskCreate( vRegTest1Task, "Reg1", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );
\r
593 xTaskCreate( vRegTest2Task, "Reg2", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );
\r
595 /* Create the semaphore that is used to demonstrate a task being
\r
596 synchronised with an interrupt. */
\r
597 vSemaphoreCreateBinary( xTestSemaphore );
\r
599 /* Create the task that is unblocked by the demonstration interrupt. */
\r
600 xTaskCreate( prvButtonTestTask, "BtnTest", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );
\r
602 /* Create the software timer that performs the 'check' functionality,
\r
603 as described at the top of this file. */
\r
604 xCheckTimer = xTimerCreate( "CheckTimer", /* A text name, purely to help debugging. */
\r
605 ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */
\r
606 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
607 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
608 prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */
\r
611 if( xCheckTimer != NULL )
\r
613 xTimerStart( xCheckTimer, mainDONT_BLOCK );
\r
616 /* This task has to be created last as it keeps account of the number of
\r
617 tasks it expects to see running. */
\r
618 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
620 #else /* mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY */
\r
622 /* Just to prevent compiler warnings when the configuration options are
\r
623 set such that these static functions are not used. */
\r
624 ( void ) vRegTest1Task;
\r
625 ( void ) vRegTest2Task;
\r
626 ( void ) prvCheckTimerCallback;
\r
627 ( void ) prvSetupNestedFPUInterruptsTest;
\r
629 #endif /* mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY */
\r
631 /*-----------------------------------------------------------*/
\r
633 void EXTI9_5_IRQHandler(void)
\r
635 long lHigherPriorityTaskWoken = pdFALSE;
\r
637 /* Only line 6 is enabled, so there is no need to test which line generated
\r
639 EXTI_ClearITPendingBit( EXTI_Line6 );
\r
641 /* This interrupt does nothing more than demonstrate how to synchronise a
\r
642 task with an interrupt. First the handler releases a semaphore.
\r
643 lHigherPriorityTaskWoken has been initialised to zero. */
\r
644 xSemaphoreGiveFromISR( xTestSemaphore, &lHigherPriorityTaskWoken );
\r
646 /* If there was a task that was blocked on the semaphore, and giving the
\r
647 semaphore caused the task to unblock, and the unblocked task has a priority
\r
648 higher than the currently executing task (the task that this interrupt
\r
649 interrupted), then lHigherPriorityTaskWoken will have been set to pdTRUE.
\r
650 Passing pdTRUE into the following macro call will cause this interrupt to
\r
651 return directly to the unblocked, higher priority, task. */
\r
652 portEND_SWITCHING_ISR( lHigherPriorityTaskWoken );
\r
654 /*-----------------------------------------------------------*/
\r
656 void vApplicationMallocFailedHook( void )
\r
658 /* vApplicationMallocFailedHook() will only be called if
\r
659 configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
\r
660 function that will get called if a call to pvPortMalloc() fails.
\r
661 pvPortMalloc() is called internally by the kernel whenever a task, queue,
\r
662 timer or semaphore is created. It is also called by various parts of the
\r
663 demo application. If heap_1.c or heap_2.c are used, then the size of the
\r
664 heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
\r
665 FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
\r
666 to query the size of free heap space that remains (although it does not
\r
667 provide information on how the remaining heap might be fragmented). */
\r
668 taskDISABLE_INTERRUPTS();
\r
671 /*-----------------------------------------------------------*/
\r
673 void vApplicationIdleHook( void )
\r
675 /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
\r
676 to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
\r
677 task. It is essential that code added to this hook function never attempts
\r
678 to block in any way (for example, call xQueueReceive() with a block time
\r
679 specified, or call vTaskDelay()). If the application makes use of the
\r
680 vTaskDelete() API function (as this demo application does) then it is also
\r
681 important that vApplicationIdleHook() is permitted to return to its calling
\r
682 function, because it is the responsibility of the idle task to clean up
\r
683 memory allocated by the kernel to any task that has since been deleted. */
\r
685 /*-----------------------------------------------------------*/
\r
687 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
689 ( void ) pcTaskName;
\r
692 /* Run time stack overflow checking is performed if
\r
693 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
694 function is called if a stack overflow is detected. */
\r
695 taskDISABLE_INTERRUPTS();
\r
698 /*-----------------------------------------------------------*/
\r