2020-01-28 16:11:46 +00:00
|
|
|
#include "base_timer.h"
|
|
|
|
|
2021-04-13 15:09:25 +00:00
|
|
|
#define TIMER_REV_INT_CBPF_DEFINE(TIMER, INIT) static TIMER_INT_FP TIMER##_INIT_CALLBACK = (INIT)
|
|
|
|
|
|
|
|
#define TIMER_REV_INT_CFG_DEFINE(TIMER) void TIMER##_ConfigReceiveInterrupt(TIMER_INT_FP pfCallBack, int iPreemptionPriority, int SubPriority)\
|
|
|
|
{\
|
|
|
|
NVIC_InitTypeDef NVIC_InitStructure;\
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannel = TIMER##_IRQn;\
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=iPreemptionPriority;\
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = SubPriority;\
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;\
|
|
|
|
NVIC_Init(&NVIC_InitStructure);\
|
|
|
|
TIMER##_INIT_CALLBACK = pfCallBack;\
|
|
|
|
}
|
|
|
|
|
|
|
|
#define TIMER_REV_INT_SRV_DEFINE(TIMER) void TIMER##_IRQHandler(void)\
|
|
|
|
{\
|
|
|
|
if (TIM_GetITStatus(TIMER, TIM_IT_Update) != RESET)\
|
|
|
|
{\
|
|
|
|
TIM_ClearITPendingBit(TIMER, TIM_IT_Update);\
|
|
|
|
if(NULL != TIMER##_INIT_CALLBACK)\
|
|
|
|
{\
|
|
|
|
TIMER##_INIT_CALLBACK();\
|
|
|
|
}\
|
|
|
|
}\
|
|
|
|
}
|
2020-01-28 16:11:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
TIMER_REV_INT_CBPF_DEFINE(TIM3, NULL);
|
|
|
|
TIMER_REV_INT_CFG_DEFINE(TIM3);
|
|
|
|
TIMER_REV_INT_SRV_DEFINE(TIM3);
|
|
|
|
|
|
|
|
TIMER_REV_INT_CBPF_DEFINE(TIM4, NULL);
|
|
|
|
TIMER_REV_INT_CFG_DEFINE(TIM4);
|
|
|
|
TIMER_REV_INT_SRV_DEFINE(TIM4);
|
|
|
|
|
|
|
|
void BASE_TIMER_Initialize(TIM_TypeDef* pstTimerBase, uint16_t uiReloadValue, uint16_t uiPrescaler)
|
2021-04-13 15:09:25 +00:00
|
|
|
{
|
2020-01-28 16:11:46 +00:00
|
|
|
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
|
2021-04-13 15:09:25 +00:00
|
|
|
/* Configure timer data. */
|
|
|
|
TIM_TimeBaseStructure.TIM_Period = uiReloadValue;
|
|
|
|
TIM_TimeBaseStructure.TIM_Prescaler = uiPrescaler;
|
|
|
|
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
|
|
|
|
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
|
|
|
TIM_TimeBaseInit(pstTimerBase, &TIM_TimeBaseStructure);
|
2020-01-28 16:11:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BASE_TIMER_ActiveInterrupt(TIM_TypeDef* pstTimerBase, bool bEnable)
|
|
|
|
{
|
2021-04-13 15:09:25 +00:00
|
|
|
TIM_Cmd(pstTimerBase, DISABLE);
|
|
|
|
if(true == bEnable)
|
|
|
|
{
|
|
|
|
TIM_ITConfig(pstTimerBase,TIM_IT_Update, ENABLE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TIM_ITConfig(pstTimerBase,TIM_IT_Update, DISABLE);
|
|
|
|
}
|
|
|
|
TIM_Cmd(pstTimerBase, ENABLE);
|
2020-01-28 16:11:46 +00:00
|
|
|
}
|