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