/** * @file tims.h * @brief Header file for TIMS module. * * This file contains the declarations and definitions for the TIMS module. * TIMS stands for Timer System and provides functionality related to timers. * * @author xxx * @date 2024-01-16 22:23:43 * @copyright Copyright (c) 2024 by xxx, All Rights Reserved. */ #ifndef __TIMS_H__ #define __TIMS_H__ #include "lib.h" /** Timer overflow time calculation formula Tout = ((ARR + 1)*(PSC + 1)) / Tclk Given Tclk as 84MHz, we need Tout to be 200ms or 200000us. Let's assume PSC is 839, substituting it into the formula gives ARR = 19999. With these calculated values, both ARR and PSC are within the range of 0 to 65535, so we can use this parameter set. */ /** * @brief Enables the specified TIMx. * @param TIMx TIM instance. */ #define ENABLE_TIM(TIMx) \ do \ { \ LL_TIM_EnableCounter(TIMx); \ LL_TIM_EnableIT_UPDATE(TIMx); \ } while (__LINE__ == -1); /** * @brief Checks if the specified TIMx is enabled. * @param TIMx TIM instance. * @retval The new state of TIMx (1 or 0). */ #define IS_ENABLE_TIM(TIMx) LL_TIM_IsEnabledIT_UPDATE(TIMx) /** * @brief Disables the specified TIMx. * @param TIMx TIM instance. */ #define DISABLE_TIM(TIMx) \ do \ { \ LL_TIM_DisableCounter(TIMx); \ LL_TIM_DisableIT_UPDATE(TIMx); \ } while (__LINE__ == -1); #define ENABLE_TIM_ARR_RELOAD(TIMx) LL_TIM_EnableARRPreload(TIMx) #define DISABLE_TIM_ARR_RELOAD(TIMx) LL_TIM_DisableARRPreload(TIMx) /** * @brief Checks if the specified TIMx interrupt flag is set. * @param TIMx TIM instance. * @retval The new state of the specified TIMx interrupt flag (1 or 0). */ #define IS_TIM_IT_FLAG(TIMx) (LL_TIM_IsActiveFlag_UPDATE(TIMx) == 1) /** * @brief TIM interrupt handler. * @param TIMx TIM instance. */ #define TIM_IRQ_HANDLER(TIMx) \ do \ { \ if (LL_TIM_IsActiveFlag_CC1(TIMx) == SET) \ { \ if (LL_TIM_IsEnabledIT_CC1(TIMx) == SET) \ { \ LL_TIM_ClearFlag_CC1(TIMx); \ } \ } \ if (LL_TIM_IsActiveFlag_CC2(TIMx) == SET) \ { \ if (LL_TIM_IsEnabledIT_CC2(TIMx) == SET) \ { \ LL_TIM_ClearFlag_CC2(TIMx); \ } \ } \ if (LL_TIM_IsActiveFlag_CC3(TIMx) == SET) \ { \ if (LL_TIM_IsEnabledIT_CC3(TIMx) == SET) \ { \ LL_TIM_ClearFlag_CC3(TIMx); \ } \ } \ if (LL_TIM_IsActiveFlag_CC4(TIMx) == SET) \ { \ if (LL_TIM_IsEnabledIT_CC4(TIMx) == SET) \ { \ LL_TIM_ClearFlag_CC4(TIMx); \ } \ } \ if (LL_TIM_IsActiveFlag_UPDATE(TIMx) == SET) \ { \ if (LL_TIM_IsEnabledIT_UPDATE(TIMx) == SET) \ { \ LL_TIM_ClearFlag_UPDATE(TIMx); \ } \ } \ } while (__LINE__ == -1) /** * @brief 获取定时器周期时间(单位:毫秒) * * 获取指定定时器TIMx的周期时间,以秒为单位。 * * @param TIMx 定时器指针,指向需要查询的定时器 * * @return 返回定时器周期时间(单位:毫秒) */ #define TIM_CYCLE(TIMx) ((LL_TIM_GetAutoReload(TIMx) + 1) * 0.1) #endif ///< __TIMS_H__