]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_STM32F7_STM32756G-EVAL/Full_Demo/IntQueueTimer.c
Update version number ready for V8.2.1 release.
[freertos] / FreeRTOS / Demo / CORTEX_M7_STM32F7_STM32756G-EVAL / Full_Demo / IntQueueTimer.c
1 /*\r
2     FreeRTOS V8.2.1 - Copyright (C) 2015 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
12 \r
13     ***************************************************************************\r
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
16     >>!   obliged to provide the source code for proprietary components     !<<\r
17     >>!   outside of the FreeRTOS kernel.                                   !<<\r
18     ***************************************************************************\r
19 \r
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
23     link: http://www.freertos.org/a00114.html\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    FreeRTOS provides completely free yet professionally developed,    *\r
28      *    robust, strictly quality controlled, supported, and cross          *\r
29      *    platform software that is more than just the market leader, it     *\r
30      *    is the industry's de facto standard.                               *\r
31      *                                                                       *\r
32      *    Help yourself get started quickly while simultaneously helping     *\r
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
34      *    tutorial book, reference manual, or both:                          *\r
35      *    http://www.FreeRTOS.org/Documentation                              *\r
36      *                                                                       *\r
37     ***************************************************************************\r
38 \r
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
40     the FAQ page "My application does not run, what could be wrong?".  Have you\r
41     defined configASSERT()?\r
42 \r
43     http://www.FreeRTOS.org/support - In return for receiving this top quality\r
44     embedded software for free we request you assist our global community by\r
45     participating in the support forum.\r
46 \r
47     http://www.FreeRTOS.org/training - Investing in training allows your team to\r
48     be as productive as possible as early as possible.  Now you can receive\r
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
50     Ltd, and the world's leading authority on the world's leading RTOS.\r
51 \r
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
55 \r
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
58 \r
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
61     licenses offer ticketed support, indemnification and commercial middleware.\r
62 \r
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
64     engineered and independently SIL3 certified version for use in safety and\r
65     mission critical applications that require provable dependability.\r
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 \r
70 /*\r
71  * This file initialises three timers as follows:\r
72  *\r
73  * TIM2 and TIM3 provide the interrupts that are used with the IntQ\r
74  * standard demo tasks, which test interrupt nesting and using queues from\r
75  * interrupts.  The timers generate interrupts at slightly different\r
76  * frequencies and use different priorities, resulting in a nesting depth of\r
77  * three (including the tick and PendSV interrupts, which run at lower\r
78  * priorities).\r
79  *\r
80  * TIM4 provides a much higher frequency timer that tests the nesting\r
81  * of interrupts that don't use the FreeRTOS API.  For convenience, the high\r
82  * frequency timer also keeps a count of the number of times it executes, and\r
83  * the count can be used as the time base for the run time stats.\r
84  *\r
85  * All the timers can nest with the tick interrupt - creating a maximum\r
86  * interrupt nesting depth of 4.\r
87  *\r
88  */\r
89 \r
90 /* Scheduler includes. */\r
91 #include "FreeRTOS.h"\r
92 \r
93 /* Demo includes. */\r
94 #include "IntQueueTimer.h"\r
95 #include "IntQueue.h"\r
96 \r
97 /* The frequencies at which the first two timers expire are slightly offset to\r
98 ensure they don't remain synchronised.  The frequency of the highest priority\r
99 interrupt is 20 times faster so really hammers the interrupt entry and exit\r
100 code. */\r
101 #define tmrTIMER_2_FREQUENCY    ( 2000UL )\r
102 #define tmrTIMER_3_FREQUENCY    ( 2003UL )\r
103 #define tmrTIMER_4_FREQUENCY    ( 20000UL )\r
104 \r
105 /* The high frequency interrupt given a priority above the maximum at which\r
106 interrupt safe FreeRTOS calls can be made.  The priority of the lower frequency\r
107 timers must still be above the tick interrupt priority. */\r
108 #define tmrLOWER_PRIORITY               configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY + 1\r
109 #define tmrMEDIUM_PRIORITY              configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY\r
110 #define tmrHIGHER_PRIORITY              configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY - 1\r
111 /*-----------------------------------------------------------*/\r
112 \r
113 /* For convenience the high frequency timer increments a variable that is then\r
114 used as the time base for the run time stats. */\r
115 volatile uint32_t ulHighFrequencyTimerCounts = 0;\r
116 \r
117 /*-----------------------------------------------------------*/\r
118 \r
119 void vInitialiseTimerForIntQueueTest( void )\r
120 {\r
121 TIM_HandleTypeDef    xTimHandle;\r
122 const uint32_t ulPrescale = 0; /* No prescale. */\r
123 \r
124         /* Clock the utilised timers. */\r
125         __TIM2_CLK_ENABLE();\r
126         __TIM3_CLK_ENABLE();\r
127         __TIM4_CLK_ENABLE();\r
128 \r
129         /* Configure TIM2 to generate an interrupt at the required frequency. */\r
130         xTimHandle.Instance = TIM2;\r
131         xTimHandle.Init.Period = ( SystemCoreClock / 2UL ) / ( tmrTIMER_2_FREQUENCY - 1 );\r
132         xTimHandle.Init.Prescaler = ulPrescale;\r
133         xTimHandle.Init.ClockDivision = 0;\r
134         xTimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;\r
135         HAL_TIM_Base_Init( &xTimHandle );\r
136         HAL_TIM_Base_Start_IT( &xTimHandle );\r
137 \r
138     /* Configure and enable TIM2 interrupt. */\r
139         NVIC_SetPriority( TIM2_IRQn, tmrLOWER_PRIORITY );\r
140     NVIC_ClearPendingIRQ( TIM2_IRQn );\r
141     NVIC_EnableIRQ( TIM2_IRQn );\r
142 \r
143         /* Repeat for TIM3 and TIM4. */\r
144         xTimHandle.Instance = TIM3;\r
145         xTimHandle.Init.Period = ( SystemCoreClock / 2UL ) / ( tmrTIMER_3_FREQUENCY - 1 );\r
146         HAL_TIM_Base_Init( &xTimHandle );\r
147         HAL_TIM_Base_Start_IT( &xTimHandle );\r
148         NVIC_SetPriority( TIM3_IRQn, tmrMEDIUM_PRIORITY );\r
149     NVIC_ClearPendingIRQ( TIM3_IRQn );\r
150     NVIC_EnableIRQ( TIM3_IRQn );\r
151 \r
152         xTimHandle.Instance = TIM4;\r
153         xTimHandle.Init.Period = ( SystemCoreClock / 2UL ) / ( tmrTIMER_4_FREQUENCY - 1 );\r
154         HAL_TIM_Base_Init( &xTimHandle );\r
155         HAL_TIM_Base_Start_IT( &xTimHandle );\r
156         NVIC_SetPriority( TIM4_IRQn, tmrHIGHER_PRIORITY );\r
157     NVIC_ClearPendingIRQ( TIM4_IRQn );\r
158     NVIC_EnableIRQ( TIM4_IRQn );\r
159 }\r
160 /*-----------------------------------------------------------*/\r
161 \r
162 void TIM2_IRQHandler( void )\r
163 {\r
164         /* Clear the interrupt and call the IntQTimer test function. */\r
165         TIM2->SR = 0;\r
166         portYIELD_FROM_ISR( xFirstTimerHandler() );\r
167 }\r
168 /*-----------------------------------------------------------*/\r
169 \r
170 void TIM3_IRQHandler( void )\r
171 {\r
172         /* Clear the interrupt and call the IntQTimer test function. */\r
173         TIM3->SR = 0;\r
174         portYIELD_FROM_ISR( xSecondTimerHandler() );\r
175 }\r
176 /*-----------------------------------------------------------*/\r
177 \r
178 void TIM4_IRQHandler( void )\r
179 {\r
180         TIM4->SR = 0;\r
181 \r
182         /* Keep a count of the number of interrupts to use as a time base for the\r
183         run-time stats. */\r
184         ulHighFrequencyTimerCounts++;\r
185 }\r
186 \r