fm_ccjy/bsp/tims.h

85 lines
3.6 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @file tims.h
* @author xxx
* @date 2024-01-16 22:23:43
* @brief
* @copyright Copyright (c) 2024 by xxx, All Rights Reserved.
*/
#ifndef __TIMS_H__
#define __TIMS_H__
/**
* 定时器溢出时间计算公式
Tout = ((ARR + 1)*(PSC + 1)) / Tclk
已知 Tclk 为 84MHz , 我们需要 Tout 为 200ms 即 200000us , 不妨先让PSC为 839, 带入上述公式可得 ARR = 19999.
这样算出来之后ARR和PSC都在0~65535的范围, 则可以使用这组参数
*/
/***
* @brief 启用定时器时钟。
* @param {TIMx} TIMx定时器外设寄存器地址。
* @return {void}
* @note: 此函数应在定时器相关初始化函数之后调用,以启用定时器的时钟。
*/
#define ENABLE_TIM(TIMx) \
do \
{ \
LL_TIM_EnableCounter(TIMx); \
LL_TIM_EnableIT_UPDATE(TIMx); \
} while (__LINE__ == -1);
#define IS_ENABLE_TIM(TIMx) LL_TIM_IsEnabledIT_UPDATE(TIMx)
#define DISABLE_TIM(TIMx) \
do \
{ \
LL_TIM_DisableCounter(TIMx); \
LL_TIM_DisableIT_UPDATE(TIMx); \
} while (__LINE__ == -1);
// 判断定时器的中断是否发生为了方便使用这里直接使用LL库的宏定义
#define IS_TIM_IT_FLAG(TIMx) (LL_TIM_IsActiveFlag_UPDATE(TIMx) == 1)
// 定时器中断处理
#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 (0)
#endif // __TIMS_H__