Mercurial > public > ostc4
comparison Common/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_timebase_tim_template.c @ 128:c78bcbd5deda FlipDisplay
Added current STM32 standandard libraries in version independend folder structure
author | Ideenmodellierer |
---|---|
date | Sun, 17 Feb 2019 21:12:22 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
127:1369f8660eaa | 128:c78bcbd5deda |
---|---|
1 /** | |
2 ****************************************************************************** | |
3 * @file stm32f4xx_hal_timebase_tim_template.c | |
4 * @author MCD Application Team | |
5 * @brief HAL time base based on the hardware TIM Template. | |
6 * | |
7 * This file overrides the native HAL time base functions (defined as weak) | |
8 * the TIM time base: | |
9 * + Intializes the TIM peripheral generate a Period elapsed Event each 1ms | |
10 * + HAL_IncTick is called inside HAL_TIM_PeriodElapsedCallback ie each 1ms | |
11 * | |
12 ****************************************************************************** | |
13 * @attention | |
14 * | |
15 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> | |
16 * | |
17 * Redistribution and use in source and binary forms, with or without modification, | |
18 * are permitted provided that the following conditions are met: | |
19 * 1. Redistributions of source code must retain the above copyright notice, | |
20 * this list of conditions and the following disclaimer. | |
21 * 2. Redistributions in binary form must reproduce the above copyright notice, | |
22 * this list of conditions and the following disclaimer in the documentation | |
23 * and/or other materials provided with the distribution. | |
24 * 3. Neither the name of STMicroelectronics nor the names of its contributors | |
25 * may be used to endorse or promote products derived from this software | |
26 * without specific prior written permission. | |
27 * | |
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
31 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
38 * | |
39 ****************************************************************************** | |
40 */ | |
41 | |
42 /* Includes ------------------------------------------------------------------*/ | |
43 #include "stm32f4xx_hal.h" | |
44 | |
45 /** @addtogroup STM32F4xx_HAL_Driver | |
46 * @{ | |
47 */ | |
48 | |
49 /** @addtogroup HAL_TimeBase_TIM | |
50 * @{ | |
51 */ | |
52 | |
53 /* Private typedef -----------------------------------------------------------*/ | |
54 /* Private define ------------------------------------------------------------*/ | |
55 /* Private macro -------------------------------------------------------------*/ | |
56 /* Private variables ---------------------------------------------------------*/ | |
57 TIM_HandleTypeDef TimHandle; | |
58 /* Private function prototypes -----------------------------------------------*/ | |
59 void TIM6_DAC_IRQHandler(void); | |
60 /* Private functions ---------------------------------------------------------*/ | |
61 | |
62 /** | |
63 * @brief This function configures the TIM6 as a time base source. | |
64 * The time source is configured to have 1ms time base with a dedicated | |
65 * Tick interrupt priority. | |
66 * @note This function is called automatically at the beginning of program after | |
67 * reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig(). | |
68 * @param TickPriority Tick interrupt priority. | |
69 * @retval HAL status | |
70 */ | |
71 HAL_StatusTypeDef HAL_InitTick (uint32_t TickPriority) | |
72 { | |
73 RCC_ClkInitTypeDef clkconfig; | |
74 uint32_t uwTimclock, uwAPB1Prescaler = 0U; | |
75 uint32_t uwPrescalerValue = 0U; | |
76 uint32_t pFLatency; | |
77 | |
78 /*Configure the TIM6 IRQ priority */ | |
79 HAL_NVIC_SetPriority(TIM6_DAC_IRQn, TickPriority ,0U); | |
80 | |
81 /* Enable the TIM6 global Interrupt */ | |
82 HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn); | |
83 | |
84 /* Enable TIM6 clock */ | |
85 __HAL_RCC_TIM6_CLK_ENABLE(); | |
86 | |
87 /* Get clock configuration */ | |
88 HAL_RCC_GetClockConfig(&clkconfig, &pFLatency); | |
89 | |
90 /* Get APB1 prescaler */ | |
91 uwAPB1Prescaler = clkconfig.APB1CLKDivider; | |
92 | |
93 /* Compute TIM6 clock */ | |
94 if (uwAPB1Prescaler == RCC_HCLK_DIV1) | |
95 { | |
96 uwTimclock = HAL_RCC_GetPCLK1Freq(); | |
97 } | |
98 else | |
99 { | |
100 uwTimclock = 2*HAL_RCC_GetPCLK1Freq(); | |
101 } | |
102 | |
103 /* Compute the prescaler value to have TIM6 counter clock equal to 1MHz */ | |
104 uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U); | |
105 | |
106 /* Initialize TIM6 */ | |
107 TimHandle.Instance = TIM6; | |
108 | |
109 /* Initialize TIMx peripheral as follow: | |
110 + Period = [(TIM6CLK/1000) - 1]. to have a (1/1000) s time base. | |
111 + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock. | |
112 + ClockDivision = 0 | |
113 + Counter direction = Up | |
114 */ | |
115 TimHandle.Init.Period = (1000000U / 1000U) - 1U; | |
116 TimHandle.Init.Prescaler = uwPrescalerValue; | |
117 TimHandle.Init.ClockDivision = 0U; | |
118 TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP; | |
119 if(HAL_TIM_Base_Init(&TimHandle) == HAL_OK) | |
120 { | |
121 /* Start the TIM time Base generation in interrupt mode */ | |
122 return HAL_TIM_Base_Start_IT(&TimHandle); | |
123 } | |
124 | |
125 /* Return function status */ | |
126 return HAL_ERROR; | |
127 } | |
128 | |
129 /** | |
130 * @brief Suspend Tick increment. | |
131 * @note Disable the tick increment by disabling TIM6 update interrupt. | |
132 * @retval None | |
133 */ | |
134 void HAL_SuspendTick(void) | |
135 { | |
136 /* Disable TIM6 update Interrupt */ | |
137 __HAL_TIM_DISABLE_IT(&TimHandle, TIM_IT_UPDATE); | |
138 } | |
139 | |
140 /** | |
141 * @brief Resume Tick increment. | |
142 * @note Enable the tick increment by Enabling TIM6 update interrupt. | |
143 * @retval None | |
144 */ | |
145 void HAL_ResumeTick(void) | |
146 { | |
147 /* Enable TIM6 Update interrupt */ | |
148 __HAL_TIM_ENABLE_IT(&TimHandle, TIM_IT_UPDATE); | |
149 } | |
150 | |
151 /** | |
152 * @brief Period elapsed callback in non blocking mode | |
153 * @note This function is called when TIM6 interrupt took place, inside | |
154 * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment | |
155 * a global variable "uwTick" used as application time base. | |
156 * @param htim TIM handle | |
157 * @retval None | |
158 */ | |
159 void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) | |
160 { | |
161 HAL_IncTick(); | |
162 } | |
163 | |
164 /** | |
165 * @brief This function handles TIM interrupt request. | |
166 * @retval None | |
167 */ | |
168 void TIM6_DAC_IRQHandler(void) | |
169 { | |
170 HAL_TIM_IRQHandler(&TimHandle); | |
171 } | |
172 | |
173 /** | |
174 * @} | |
175 */ | |
176 | |
177 /** | |
178 * @} | |
179 */ | |
180 | |
181 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |