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