2 * FreeRTOS Kernel V10.2.1
\r
3 * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
28 /******************************************************************************
\r
29 * >>>>>> NOTE 1: <<<<<<
\r
31 * main() can be configured to create either a very simple LED flasher demo, or
\r
32 * a more comprehensive test/demo application.
\r
34 * To create a very simple LED flasher example, set the
\r
35 * mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY constant (defined below) to 1. When
\r
36 * this is done, only the standard demo flash tasks are created. The standard
\r
37 * demo flash example creates three tasks, each of which toggle an LED at a
\r
38 * fixed but different frequency.
\r
40 * To create a more comprehensive test and demo application, set
\r
41 * mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY to 0.
\r
43 * >>>>>> NOTE 2: <<<<<<
\r
45 * In addition to the normal set of standard demo tasks, the comprehensive test
\r
46 * makes heavy use of the floating point unit, and forces floating point
\r
47 * instructions to be used from interrupts that nest three deep. The nesting
\r
48 * starts from the tick hook function, resulting is an abnormally long context
\r
49 * switch time. This is done purely to stress test the FPU context switching
\r
50 * implementation, and that part of the test can be removed by setting
\r
51 * configUSE_TICK_HOOK to 0 in FreeRTOSConfig.h.
\r
52 ******************************************************************************
\r
54 * main() creates all the demo application tasks and software timers, then starts
\r
55 * the scheduler. The web documentation provides more details of the standard
\r
56 * demo application tasks, which provide no particular functionality, but do
\r
57 * provide a good example of how to use the FreeRTOS API.
\r
59 * In addition to the standard demo tasks, the following tasks and tests are
\r
60 * defined and/or created within this file:
\r
62 * "Reg test" tasks - These fill both the core and floating point registers with
\r
63 * known values, then check that each register maintains its expected value for
\r
64 * the lifetime of the task. Each task uses a different set of values. The reg
\r
65 * test tasks execute with a very low priority, so get preempted very
\r
66 * frequently. A register containing an unexpected value is indicative of an
\r
67 * error in the context switching mechanism.
\r
69 * "Check" timer - The check software timer period is initially set to three
\r
70 * seconds. The callback function associated with the check software timer
\r
71 * checks that all the standard demo tasks, and the register check tasks, are
\r
72 * not only still executing, but are executing without reporting any errors. If
\r
73 * the check software timer discovers that a task has either stalled, or
\r
74 * reported an error, then it changes its own execution period from the initial
\r
75 * three seconds, to just 200ms. The check software timer callback function
\r
76 * also toggles an LED each time it is called. This provides a visual
\r
77 * indication of the system status: If the LED toggles every three seconds,
\r
78 * then no issues have been discovered. If the LED toggles every 200ms, then
\r
79 * an issue has been discovered with at least one task.
\r
81 * Tick hook - The application tick hook is called from the schedulers tick
\r
82 * interrupt service routine when configUSE_TICK_HOOK is set to 1 in
\r
83 * FreeRTOSConfig.h. In this example, the tick hook is used to test the kernels
\r
84 * handling of the floating point units (FPU) context, both at the task level
\r
85 * and when nesting interrupts access the floating point unit registers. The
\r
86 * tick hook function first fills the FPU registers with a known value, it
\r
87 * then triggers a medium priority interrupt. The medium priority interrupt
\r
88 * fills the FPU registers with a different value, and triggers a high priority
\r
89 * interrupt. The high priority interrupt once again fills the the FPU
\r
90 * registers with a known value before returning to the medium priority
\r
91 * interrupt. The medium priority interrupt checks that the FPU registers
\r
92 * contain the values that it wrote to them, then returns to the tick hook
\r
93 * function. Finally, the tick hook function checks that the FPU registers
\r
94 * contain the values that it wrote to them, before it too returns.
\r
96 * Button interrupt - The button marked "USER" on the starter kit is used to
\r
97 * demonstrate how to write an interrupt service routine, and how to synchronise
\r
98 * a task with an interrupt. A task is created that blocks on a test semaphore.
\r
99 * When the USER button is pressed, the button interrupt handler gives the
\r
100 * semaphore, causing the task to unblock. When the task unblocks, it simply
\r
101 * increments an execution count variable, then returns to block on the
\r
105 /* Kernel includes. */
\r
106 #include "FreeRTOS.h"
\r
108 #include "timers.h"
\r
109 #include "semphr.h"
\r
111 /* Demo application includes. */
\r
112 #include "partest.h"
\r
115 #include "integer.h"
\r
117 #include "semtest.h"
\r
118 #include "dynamic.h"
\r
119 #include "BlockQ.h"
\r
120 #include "blocktim.h"
\r
121 #include "countsem.h"
\r
122 #include "GenQTest.h"
\r
123 #include "recmutex.h"
\r
126 /* Hardware and starter kit includes. */
\r
127 #include "arm_comm.h"
\r
128 #include "iar_stm32f407zg_sk.h"
\r
129 #include "stm32f4xx.h"
\r
130 #include "stm32f4xx_conf.h"
\r
132 /* Priorities for the demo application tasks. */
\r
133 #define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 1UL )
\r
134 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
135 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1UL )
\r
136 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
137 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3UL )
\r
138 #define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
140 /* The LED used by the check timer. */
\r
141 #define mainCHECK_LED ( 3UL )
\r
143 /* A block time of zero simply means "don't block". */
\r
144 #define mainDONT_BLOCK ( 0UL )
\r
146 /* The period after which the check timer will expire, in ms, provided no errors
\r
147 have been reported by any of the standard demo tasks. ms are converted to the
\r
148 equivalent in ticks using the portTICK_PERIOD_MS constant. */
\r
149 #define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_PERIOD_MS )
\r
151 /* The period at which the check timer will expire, in ms, if an error has been
\r
152 reported in one of the standard demo tasks. ms are converted to the equivalent
\r
153 in ticks using the portTICK_PERIOD_MS constant. */
\r
154 #define mainERROR_CHECK_TIMER_PERIOD_MS ( 200UL / portTICK_PERIOD_MS )
\r
156 /* Set mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY to 1 to create a simple demo.
\r
157 Set mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY to 0 to create a much more
\r
158 comprehensive test application. See the comments at the top of this file, and
\r
159 the documentation page on the http://www.FreeRTOS.org web site for more
\r
161 #define mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY 0
\r
163 /*-----------------------------------------------------------*/
\r
166 * Set up the hardware ready to run this demo.
\r
168 static void prvSetupHardware( void );
\r
171 * The check timer callback function, as described at the top of this file.
\r
173 static void prvCheckTimerCallback( TimerHandle_t xTimer );
\r
176 * Configure the interrupts used to test the interrupt nesting depth as
\r
177 * described at the top of this file.
\r
179 static void prvSetupNestedFPUInterruptsTest( void );
\r
182 * Register check tasks, and the tasks used to write over and check the contents
\r
183 * of the FPU registers, as described at the top of this file. The nature of
\r
184 * these files necessitates that they are written in an assembly file.
\r
186 extern void vRegTest1Task( void *pvParameters );
\r
187 extern void vRegTest2Task( void *pvParameters );
\r
188 extern void vRegTestClearFlopRegistersToParameterValue( unsigned long ulValue );
\r
189 extern unsigned long ulRegTestCheckFlopRegistersContainParameterValue( unsigned long ulValue );
\r
192 * The task that is synchronised with the button interrupt. This is done just
\r
193 * to demonstrate how to write interrupt service routines, and how to
\r
194 * synchronise a task with an interrupt.
\r
196 static void prvButtonTestTask( void *pvParameters );
\r
199 * This file can be used to create either a simple LED flasher example, or a
\r
200 * comprehensive test/demo application - depending on the setting of the
\r
201 * mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY constant defined above. If
\r
202 * mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY is set to 1, then the following
\r
203 * function will create a lot of additional tasks and a software timer. If
\r
204 * mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY is set to 0, then the following
\r
205 * function will do nothing.
\r
207 static void prvOptionallyCreateComprehensveTestApplication( void );
\r
209 /*-----------------------------------------------------------*/
\r
211 /* The following two variables are used to communicate the status of the
\r
212 register check tasks to the check software timer. If the variables keep
\r
213 incrementing, then the register check tasks have not discovered any errors. If
\r
214 a variable stops incrementing, then an error has been found. */
\r
215 volatile unsigned long ulRegTest1LoopCounter = 0UL, ulRegTest2LoopCounter = 0UL;
\r
217 /* The following variables are used to verify that the interrupt nesting depth
\r
218 is as intended. ulFPUInterruptNesting is incremented on entry to an interrupt
\r
219 that uses the FPU, and decremented on exit of the same interrupt.
\r
220 ulMaxFPUInterruptNesting latches the highest value reached by
\r
221 ulFPUInterruptNesting. These variables have no other purpose. */
\r
222 volatile unsigned long ulFPUInterruptNesting = 0UL, ulMaxFPUInterruptNesting = 0UL;
\r
224 /* The semaphore used to demonstrate a task being synchronised with an
\r
226 static SemaphoreHandle_t xTestSemaphore = NULL;
\r
228 /* The variable that is incremented by the task synchronised with the button
\r
230 volatile unsigned long ulButtonPressCounts = 0UL;
\r
232 /*-----------------------------------------------------------*/
\r
236 /* Configure the hardware ready to run the test. */
\r
237 prvSetupHardware();
\r
239 /* Start standard demo/test application flash tasks. See the comments at
\r
240 the top of this file. The LED flash tasks are always created. The other
\r
241 tasks are only created if mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY is set to
\r
242 0 (at the top of this file). See the comments at the top of this file for
\r
243 more information. */
\r
244 vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );
\r
246 /* The following function will only create more tasks and timers if
\r
247 mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY is set to 0 (at the top of this
\r
248 file). See the comments at the top of this file for more information. */
\r
249 prvOptionallyCreateComprehensveTestApplication();
\r
251 /* Start the scheduler. */
\r
252 vTaskStartScheduler();
\r
254 /* If all is well, the scheduler will now be running, and the following line
\r
255 will never be reached. If the following line does execute, then there was
\r
256 insufficient FreeRTOS heap memory available for the idle and/or timer tasks
\r
257 to be created. See the memory management section on the FreeRTOS web site
\r
258 for more details. */
\r
261 /*-----------------------------------------------------------*/
\r
263 static void prvCheckTimerCallback( TimerHandle_t xTimer )
\r
265 static long lChangedTimerPeriodAlready = pdFALSE;
\r
266 static unsigned long ulLastRegTest1Value = 0, ulLastRegTest2Value = 0;
\r
267 long lErrorFound = pdFALSE;
\r
269 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
270 that they are all still running, and that none have detected an error. */
\r
272 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
274 lErrorFound = pdTRUE;
\r
277 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
279 lErrorFound = pdTRUE;
\r
282 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
284 lErrorFound = pdTRUE;
\r
287 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
289 lErrorFound = pdTRUE;
\r
292 if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
294 lErrorFound = pdTRUE;
\r
297 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
299 lErrorFound = pdTRUE;
\r
302 if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
304 lErrorFound = pdTRUE;
\r
307 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
309 lErrorFound = pdTRUE;
\r
312 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
314 lErrorFound = pdTRUE;
\r
317 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
319 lErrorFound = pdTRUE;
\r
322 /* Check that the register test 1 task is still running. */
\r
323 if( ulLastRegTest1Value == ulRegTest1LoopCounter )
\r
325 lErrorFound = pdTRUE;
\r
327 ulLastRegTest1Value = ulRegTest1LoopCounter;
\r
329 /* Check that the register test 2 task is still running. */
\r
330 if( ulLastRegTest2Value == ulRegTest2LoopCounter )
\r
332 lErrorFound = pdTRUE;
\r
334 ulLastRegTest2Value = ulRegTest2LoopCounter;
\r
336 /* Toggle the check LED to give an indication of the system status. If
\r
337 the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then
\r
338 everything is ok. A faster toggle indicates an error. */
\r
339 vParTestToggleLED( mainCHECK_LED );
\r
341 /* Have any errors been latch in lErrorFound? If so, shorten the
\r
342 period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.
\r
343 This will result in an increase in the rate at which mainCHECK_LED
\r
345 if( lErrorFound != pdFALSE )
\r
347 if( lChangedTimerPeriodAlready == pdFALSE )
\r
349 lChangedTimerPeriodAlready = pdTRUE;
\r
351 /* This call to xTimerChangePeriod() uses a zero block time.
\r
352 Functions called from inside of a timer callback function must
\r
353 *never* attempt to block. */
\r
354 xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );
\r
358 /*-----------------------------------------------------------*/
\r
360 static void prvButtonTestTask( void *pvParameters )
\r
362 configASSERT( xTestSemaphore );
\r
364 /* This is the task used as an example of how to synchronise a task with
\r
365 an interrupt. Each time the button interrupt gives the semaphore, this task
\r
366 will unblock, increment its execution counter, then return to block
\r
369 /* Take the semaphore before started to ensure it is in the correct
\r
371 xSemaphoreTake( xTestSemaphore, mainDONT_BLOCK );
\r
375 xSemaphoreTake( xTestSemaphore, portMAX_DELAY );
\r
376 ulButtonPressCounts++;
\r
379 /*-----------------------------------------------------------*/
\r
381 static void prvSetupHardware( void )
\r
383 /* Setup STM32 system (clock, PLL and Flash configuration) */
\r
386 /* Ensure all priority bits are assigned as preemption priority bits. */
\r
387 NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );
\r
389 /* Setup the LED outputs. */
\r
390 vParTestInitialise();
\r
392 /* Configure the button input. This configures the interrupt to use the
\r
393 lowest interrupt priority, so it is ok to use the ISR safe FreeRTOS API
\r
394 from the button interrupt handler. */
\r
395 STM_EVAL_PBInit( BUTTON_USER, BUTTON_MODE_EXTI );
\r
397 /*-----------------------------------------------------------*/
\r
399 void vApplicationTickHook( void )
\r
401 #if ( mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY == 0 )
\r
403 /* Just to verify that the interrupt nesting behaves as expected,
\r
404 increment ulFPUInterruptNesting on entry, and decrement it on exit. */
\r
405 ulFPUInterruptNesting++;
\r
407 /* Fill the FPU registers with 0. */
\r
408 vRegTestClearFlopRegistersToParameterValue( 0UL );
\r
410 /* Trigger a timer 2 interrupt, which will fill the registers with a
\r
411 different value and itself trigger a timer 3 interrupt. Note that the
\r
412 timers are not actually used. The timer 2 and 3 interrupt vectors are
\r
413 just used for convenience. */
\r
414 NVIC_SetPendingIRQ( TIM2_IRQn );
\r
416 /* Ensure that, after returning from the nested interrupts, all the FPU
\r
417 registers contain the value to which they were set by the tick hook
\r
419 configASSERT( ulRegTestCheckFlopRegistersContainParameterValue( 0UL ) );
\r
421 ulFPUInterruptNesting--;
\r
425 /*-----------------------------------------------------------*/
\r
427 static void prvSetupNestedFPUInterruptsTest( void )
\r
429 NVIC_InitTypeDef NVIC_InitStructure;
\r
431 /* Enable the TIM2 interrupt in the NVIC. The timer itself is not used,
\r
432 just its interrupt vector to force nesting from software. TIM2 must have
\r
433 a lower priority than TIM3, and both must have priorities above
\r
434 configMAX_SYSCALL_INTERRUPT_PRIORITY. */
\r
435 NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
\r
436 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY - 1;
\r
437 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
\r
438 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
\r
439 NVIC_Init( &NVIC_InitStructure );
\r
441 /* Enable the TIM3 interrupt in the NVIC. The timer itself is not used,
\r
442 just its interrupt vector to force nesting from software. TIM2 must have
\r
443 a lower priority than TIM3, and both must have priorities above
\r
444 configMAX_SYSCALL_INTERRUPT_PRIORITY. */
\r
445 NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
\r
446 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY - 2;
\r
447 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
\r
448 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
\r
449 NVIC_Init( &NVIC_InitStructure );
\r
451 /*-----------------------------------------------------------*/
\r
453 void TIM3_IRQHandler( void )
\r
455 /* Just to verify that the interrupt nesting behaves as expected, increment
\r
456 ulFPUInterruptNesting on entry, and decrement it on exit. */
\r
457 ulFPUInterruptNesting++;
\r
459 /* This is the highest priority interrupt in the chain of forced nesting
\r
460 interrupts, so latch the maximum value reached by ulFPUInterruptNesting.
\r
461 This is done purely to allow verification that the nesting depth reaches
\r
463 if( ulFPUInterruptNesting > ulMaxFPUInterruptNesting )
\r
465 ulMaxFPUInterruptNesting = ulFPUInterruptNesting;
\r
468 /* Fill the FPU registers with 99 to overwrite the values written by
\r
469 TIM2_IRQHandler(). */
\r
470 vRegTestClearFlopRegistersToParameterValue( 99UL );
\r
472 ulFPUInterruptNesting--;
\r
474 /*-----------------------------------------------------------*/
\r
476 void TIM2_IRQHandler( void )
\r
478 /* Just to verify that the interrupt nesting behaves as expected, increment
\r
479 ulFPUInterruptNesting on entry, and decrement it on exit. */
\r
480 ulFPUInterruptNesting++;
\r
482 /* Fill the FPU registers with 1. */
\r
483 vRegTestClearFlopRegistersToParameterValue( 1UL );
\r
485 /* Trigger a timer 3 interrupt, which will fill the registers with a
\r
486 different value. */
\r
487 NVIC_SetPendingIRQ( TIM3_IRQn );
\r
489 /* Ensure that, after returning from the nesting interrupt, all the FPU
\r
490 registers contain the value to which they were set by this interrupt
\r
492 configASSERT( ulRegTestCheckFlopRegistersContainParameterValue( 1UL ) );
\r
494 ulFPUInterruptNesting--;
\r
496 /*-----------------------------------------------------------*/
\r
498 static void prvOptionallyCreateComprehensveTestApplication( void )
\r
500 #if ( mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY == 0 )
\r
502 TimerHandle_t xCheckTimer = NULL;
\r
504 /* Configure the interrupts used to test FPU registers being used from
\r
505 nested interrupts. */
\r
506 prvSetupNestedFPUInterruptsTest();
\r
508 /* Start all the other standard demo/test tasks. */
\r
509 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
510 vStartDynamicPriorityTasks();
\r
511 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
512 vCreateBlockTimeTasks();
\r
513 vStartCountingSemaphoreTasks();
\r
514 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
515 vStartRecursiveMutexTasks();
\r
516 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
517 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
519 /* Most importantly, start the tasks that use the FPU. */
\r
520 vStartMathTasks( mainFLOP_TASK_PRIORITY );
\r
522 /* Create the register check tasks, as described at the top of this
\r
524 xTaskCreate( vRegTest1Task, "Reg1", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );
\r
525 xTaskCreate( vRegTest2Task, "Reg2", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );
\r
527 /* Create the semaphore that is used to demonstrate a task being
\r
528 synchronised with an interrupt. */
\r
529 vSemaphoreCreateBinary( xTestSemaphore );
\r
531 /* Create the task that is unblocked by the demonstration interrupt. */
\r
532 xTaskCreate( prvButtonTestTask, "BtnTest", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );
\r
534 /* Create the software timer that performs the 'check' functionality,
\r
535 as described at the top of this file. */
\r
536 xCheckTimer = xTimerCreate( "CheckTimer", /* A text name, purely to help debugging. */
\r
537 ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */
\r
538 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
539 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
540 prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */
\r
543 if( xCheckTimer != NULL )
\r
545 xTimerStart( xCheckTimer, mainDONT_BLOCK );
\r
548 /* This task has to be created last as it keeps account of the number of
\r
549 tasks it expects to see running. */
\r
550 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
552 #else /* mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY */
\r
554 /* Just to prevent compiler warnings when the configuration options are
\r
555 set such that these static functions are not used. */
\r
556 ( void ) vRegTest1Task;
\r
557 ( void ) vRegTest2Task;
\r
558 ( void ) prvCheckTimerCallback;
\r
559 ( void ) prvSetupNestedFPUInterruptsTest;
\r
561 #endif /* mainCREATE_SIMPLE_LED_FLASHER_DEMO_ONLY */
\r
563 /*-----------------------------------------------------------*/
\r
565 void EXTI9_5_IRQHandler(void)
\r
567 long lHigherPriorityTaskWoken = pdFALSE;
\r
569 /* Only line 6 is enabled, so there is no need to test which line generated
\r
571 EXTI_ClearITPendingBit( EXTI_Line6 );
\r
573 /* This interrupt does nothing more than demonstrate how to synchronise a
\r
574 task with an interrupt. First the handler releases a semaphore.
\r
575 lHigherPriorityTaskWoken has been initialised to zero. */
\r
576 xSemaphoreGiveFromISR( xTestSemaphore, &lHigherPriorityTaskWoken );
\r
578 /* If there was a task that was blocked on the semaphore, and giving the
\r
579 semaphore caused the task to unblock, and the unblocked task has a priority
\r
580 higher than the currently executing task (the task that this interrupt
\r
581 interrupted), then lHigherPriorityTaskWoken will have been set to pdTRUE.
\r
582 Passing pdTRUE into the following macro call will cause this interrupt to
\r
583 return directly to the unblocked, higher priority, task. */
\r
584 portEND_SWITCHING_ISR( lHigherPriorityTaskWoken );
\r
586 /*-----------------------------------------------------------*/
\r
588 void vApplicationMallocFailedHook( void )
\r
590 /* vApplicationMallocFailedHook() will only be called if
\r
591 configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
\r
592 function that will get called if a call to pvPortMalloc() fails.
\r
593 pvPortMalloc() is called internally by the kernel whenever a task, queue,
\r
594 timer or semaphore is created. It is also called by various parts of the
\r
595 demo application. If heap_1.c or heap_2.c are used, then the size of the
\r
596 heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
\r
597 FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
\r
598 to query the size of free heap space that remains (although it does not
\r
599 provide information on how the remaining heap might be fragmented). */
\r
600 taskDISABLE_INTERRUPTS();
\r
603 /*-----------------------------------------------------------*/
\r
605 void vApplicationIdleHook( void )
\r
607 /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
\r
608 to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
\r
609 task. It is essential that code added to this hook function never attempts
\r
610 to block in any way (for example, call xQueueReceive() with a block time
\r
611 specified, or call vTaskDelay()). If the application makes use of the
\r
612 vTaskDelete() API function (as this demo application does) then it is also
\r
613 important that vApplicationIdleHook() is permitted to return to its calling
\r
614 function, because it is the responsibility of the idle task to clean up
\r
615 memory allocated by the kernel to any task that has since been deleted. */
\r
617 /*-----------------------------------------------------------*/
\r
619 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
621 ( void ) pcTaskName;
\r
624 /* Run time stack overflow checking is performed if
\r
625 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
626 function is called if a stack overflow is detected. */
\r
627 taskDISABLE_INTERRUPTS();
\r
630 /*-----------------------------------------------------------*/
\r