2025-04-26 16:03:23 +08:00

371 lines
8.9 KiB
C
Raw Permalink 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.

/** ##########################################################################
** Filename :
** Project :
** Module :
** Processor :
** Version :
** Compiler :
** Date/Time :
** Abstract :
** Contents :
** Note :
**
** (c) Copyright dmdz Co.,Ltd
** --------------------------------------------------------------------------
** R E V I S I O N H I S T O R Y
** --------------------------------------------------------------------------
** Date Ver Author Description
** -20230602- --V1.0-- --mingyea--- --修改--
** #########################################################################*/
/*---------------------------------------------------------------------------
- I N C L U D E F I L E S
----------------------------------------------------------------------------*/
#include "tim.h"
#include "cpu.h"
#include "nvic.h"
#include "pwm_manage.h"
/*---------------------------------------------------------------------------
- D E F I N E S / M A C R O S
----------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------
- T Y P E D E F I N I T I O N S
----------------------------------------------------------------------------*/
typedef struct
{
u8 state;
u16 pwm_duty;
}tim_s;
/*---------------------------------------------------------------------------
- S T A T I C V A R I A B L E S
----------------------------------------------------------------------------*/
static tim_s g_tim;
/*---------------------------------------------------------------------------
* G L O B A L V A R I A B L E S
----------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------
- C O N S T A N T S
----------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------
- F U N C T I O N P R O T O T Y P E
----------------------------------------------------------------------------*/
#ifdef FL_ATIM_ENABLE
/*---------------------------------------------------------------------------
|Prototype :
|Called by :
|Preconditions :
|Input parameters :
|Output parameters :
|Return value :
|Description :
----------------------------------------------------------------------------*/
static void atim_init(void)
{
FL_ATIM_Init(ATIM, (FL_ATIM_InitTypeDef*)&g_atimer0_Config0);
FL_ATIM_ClearFlag_Update(ATIM); /* 清除计数器中断标志位 */
//FL_ATIM_EnableIT_Update(ATIM); /* 开启计数器中断 */
pwm_manage_atm_init();
FL_ATIM_Enable(ATIM); /* 使能定时器 */
//FL_ATIM_EnableALLOutput(ATIM);/* 主控输出使能 */
//FL_ATIM_OC_EnableChannel(ATIM,FL_ATIM_CHANNEL_2);
//FL_ATIM_OC_DisableChannel(ATIM,FL_ATIM_CHANNEL_2);
}
#endif
#ifdef FL_BSTIM16_ENABLE
/*---------------------------------------------------------------------------
|Prototype :
|Called by :
|Preconditions :
|Input parameters :
|Output parameters :
|Return value :
|Description :
----------------------------------------------------------------------------*/
static void bstim16_init(void)
{
FL_BSTIM16_Init(BSTIM16, (FL_BSTIM16_InitTypeDef*)&g_TimerBase_InitStruct);
FL_BSTIM16_ClearFlag_Update(BSTIM16); /* 清除计数器中断标志位 */
FL_BSTIM16_EnableIT_Update(BSTIM16); /* 开启计数器中断 */
NVIC_ClearPendingIRQ(BSTIM_IRQn);
NVIC_DisableIRQ(BSTIM_IRQn);
NVIC_SetPriority(BSTIM_IRQn, NVIC_PRIORITY_TIM); //中断优先级配置
NVIC_EnableIRQ(BSTIM_IRQn);
FL_BSTIM16_Enable(BSTIM16); /* 使能定时器 */
}
#endif
#ifdef FL_GPTIM_ENABLE
/*---------------------------------------------------------------------------
|Prototype :初始化
|Called by :
|Preconditions :
|Input parameters :
|Output parameters :
|Return value :
|Description :
----------------------------------------------------------------------------*/
void gptim_init(void)
{
FL_GPTIM_Init(GPTIM0, (FL_GPTIM_InitTypeDef*)&g_gptim_init_cfg);
pwm_manage_gptm0_init();
FL_GPTIM_Enable(GPTIM0); /* 使能定时器 */
}
#endif
#ifdef FL_GPTIM1_ENABLE
/*---------------------------------------------------------------------------
|Prototype :初始化
|Called by :
|Preconditions :
|Input parameters :
|Output parameters :
|Return value :
|Description :
----------------------------------------------------------------------------*/
void gptim1_init(void)
{
FL_GPTIM_Init(GPTIM1, (FL_GPTIM_InitTypeDef*)&g_gptim1_init_cfg);
pwm_manage_gptm1_init();
FL_GPTIM_Enable(GPTIM1); /* 使能定时器 */
}
#endif
#ifdef FL_GPTIM2_ENABLE
/*---------------------------------------------------------------------------
|Prototype :初始化
|Called by :
|Preconditions :
|Input parameters :
|Output parameters :
|Return value :
|Description :
----------------------------------------------------------------------------*/
void gptim2_init(void)
{
FL_GPTIM_Init(GPTIM2, (FL_GPTIM_InitTypeDef*)&g_gptim2_init_cfg);
pwm_manage_gptm2_init();
FL_GPTIM_Enable(GPTIM2); /* 使能定时器 */
}
#endif
#ifdef FL_LPTIM16_ENABLE
/*---------------------------------------------------------------------------
|Prototype : 初始化
|Called by :
|Preconditions :
|Input parameters :
|Output parameters :
|Return value :
|Description :
----------------------------------------------------------------------------*/
void lptim16_init(void)
{
FL_LPTIM16_StructInit((FL_LPTIM16_InitTypeDef*)&g_lptim16_cfg_tab);
FL_LPTIM16_Init(LPTIM16, (FL_LPTIM16_InitTypeDef*)&g_lptim16_cfg_tab);
/*---------------- 中断配置 ----------------*/
/* 清除标志 */
FL_LPTIM16_ClearFlag_Update(LPTIM16);
/* 中断使能 */
FL_LPTIM16_EnableIT_Update(LPTIM16);
/* 使能并配置NVIC */
NVIC_ClearPendingIRQ(LPTIMx_IRQn);
NVIC_DisableIRQ(LPTIMx_IRQn);
NVIC_SetPriority(LPTIMx_IRQn, NVIC_PRIORITY_RTC); //中断优先级配置
NVIC_EnableIRQ(LPTIMx_IRQn);
/*---------------------------------------------*/
/* 使能LPTIM16 */
FL_LPTIM16_Enable(LPTIM16);
}
#endif
#ifdef FL_LPTIM32_ENABLE
/*---------------------------------------------------------------------------
|Prototype : 初始化
|Called by :
|Preconditions :
|Input parameters :
|Output parameters :
|Return value :
|Description :
----------------------------------------------------------------------------*/
void lptim32_init(void)
{
/*---------------- 定时器时间基准配置 ----------------*/
FL_LPTIM32_StructInit((FL_LPTIM32_InitTypeDef*)&g_lptim32_cfg_tab);
FL_LPTIM32_Init(LPTIM32, (FL_LPTIM32_InitTypeDef*)&g_lptim32_cfg_tab);
/*---------------------------------------------*/
/*---------------- 中断配置 ----------------*/
/* 清除标志 */
FL_LPTIM32_ClearFlag_Update(LPTIM32);
pwm_manage_lpt32_init();
/*---------------------------------------------*/
/* 使能LPTIM32 */
FL_LPTIM32_Enable(LPTIM32);
}
#endif
/*---------------------------------------------------------------------------
|Prototype : 初始化
|Called by :
|Preconditions :
|Input parameters :
|Output parameters :
|Return value :
|Description :
----------------------------------------------------------------------------*/
void tim_init(void)
{
g_tim.state =0u;
g_tim.pwm_duty =500u;
#ifdef FL_BSTIM16_ENABLE
bstim16_init();
#endif
#ifdef FL_LPTIM16_ENABLE
//lptim16_init();
#endif
#ifdef FL_LPTIM32_ENABLE
lptim32_init();
#endif
#ifdef FL_ATIM_ENABLE
atim_init();
#endif
#ifdef FL_GPTIM_ENABLE
gptim_init();
#endif
#ifdef FL_GPTIM1_ENABLE
gptim1_init();
#endif
#ifdef FL_GPTIM2_ENABLE
gptim2_init();
#endif
}
/*---------------------------------------------------------------------------
|Prototype : 反初始化
|Called by :
|Preconditions :
|Input parameters :
|Output parameters :
|Return value :
|Description :
----------------------------------------------------------------------------*/
void tim_de_init(void)
{
#ifdef FL_ATIM_ENABLE
FL_ATIM_DeInit(ATIM);
#endif
#ifdef FL_BSTIM16_ENABLE
FL_BSTIM16_DeInit(BSTIM16);
#endif
#ifdef FL_GPTIM0_ENABLE
FL_GPTIM_DeInit(GPTIM0);
#endif
#ifdef FL_GPTIM1_ENABLE
FL_GPTIM_DeInit(GPTIM1);
#endif
#ifdef FL_GPTIM2_ENABLE
FL_GPTIM_DeInit(GPTIM2);
#endif
#ifdef FL_LPTIM32_ENABLE
FL_LPTIM32_DeInit(LPTIM32);
#endif
//留着LPTIM16不反初始是给间歇唤醒用的
}
/*---------------------------------------------------------------------------
|Prototype :
|Called by :
|Preconditions :
|Input parameters :
|Output parameters :
|Return value :
|Description : 任务, 测试用
----------------------------------------------------------------------------*/
void tim_task(void)
{
if(g_tim.state==1u)
{
//#ifdef FL_ATIM_PWM_EN
//FL_ATIM_WriteCompareCH2(ATIM,g_tim.pwm_duty); //B6
//#endif
#ifdef FL_GPTIM_ENABLE
FL_GPTIM_WriteCompareCH2(GPTIM0,g_tim.pwm_duty); //B6
#endif
}
}