/** ##########################################################################
**     Filename  :
**     Project   :
**     Module    :
**     Processor :
**     Version   : 1.0
**     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 "common_cfg.h"
#include "cpu.h"
#include "tim.h"
#include "gpio.h"

#include "logic_timer.h"
#include "random_pseudo.h"
#include "bl_timer.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;
    #ifdef TIM_CFG_DEBUG_DISP_EN
    u16 count[8];
    #endif
}tim_cfg_s;


/*---------------------------------------------------------------------------
- S T A T I C   V A R I A B L E S
----------------------------------------------------------------------------*/
tim_cfg_s g_tim_cfg = {0u};


/*---------------------------------------------------------------------------
* G L O B A L   V A R I A B L E S
----------------------------------------------------------------------------*/


/*---------------------------------------------------------------------------
- C O N S T A N T S
----------------------------------------------------------------------------*/
#ifdef FL_ATIM_ENABLE
const FL_ATIM_InitTypeDef  g_atimer0_Config0 =
{
    (uint32_t)FL_CMU_ATIM_CLK_SOURCE_APBCLK,  /* 时钟源选择APB2 */
    (uint32_t)48u-1u,                          /* 分频系数8000 */ // 479   48MHZ/480=
    (uint32_t)FL_ATIM_COUNTER_DIR_UP,         /* 向上计数 */
    (uint32_t)FL_ATIM_PWM_FREQ-1u,                            /* 自动重装载值1000 */  //  1 / (48MHZ/480) * 100 = 0.001 s
    (uint32_t)FL_ENABLE,          /* 自动重装载禁止preload */
    (uint32_t)FL_ATIM_CLK_DIVISION_DIV1,      /* 死区和滤波设置 */  /*! 定时器分频系数与数字滤波器所使用的采样时钟分频比 */
    (uint32_t)0u, /* 重复计数 */
};

const FL_ATIM_OC_InitTypeDef g_atmer0_ch1_InitStructer =
{
    (uint32_t)FL_ATIM_OC_MODE_PWM1,  /*! OCMode 比较输出模式 */
    (uint32_t)FL_ENABLE, /*! OCState 正向比较通道输出使能 */
    (uint32_t)FL_DISABLE, /*! OCNState 比较互补通道输出使能 */
    (uint32_t)FL_ATIM_OC_POLARITY_NORMAL,  /*! OCPolarity 比较输出极性 */
    (uint32_t)FL_ATIM_OC_POLARITY_NORMAL, /*! OCNPolarity 比较互补输出极性 */
    (uint32_t)FL_DISABLE, /*! OCFastMode 比较输出通道快速模式使能 */
    (uint32_t)FL_DISABLE,   /*! OCPreload 输出比较预装载 */
    (uint32_t)FL_ATIM_PWM_DUTY_INIT,  /*! compareValue 通道比较值 */
    (uint32_t)FL_ATIM_OC_IDLE_STATE_HIGH,  /*! OCIdleState 输出空闲状态电平 */
    (uint32_t)FL_DISABLE,  /*! OCETRFStatus ETR清0使能 */
    (uint32_t)FL_ATIM_OCN_IDLE_STATE_HIGH,  /*! OCNIdleState 互补输出空闲状态电平 */
};

const FL_ATIM_OC_InitTypeDef g_atmer0_ch2_InitStructer =
{
    (uint32_t)FL_ATIM_OC_MODE_PWM1,  /*! OCMode 比较输出模式 */
    (uint32_t)FL_ENABLE, /*! OCState 正向比较通道输出使能 */
    (uint32_t)FL_DISABLE, /*! OCNState 比较互补通道输出使能 */
    (uint32_t)FL_ATIM_OC_POLARITY_NORMAL,  /*! OCPolarity 比较输出极性 */
    (uint32_t)FL_ATIM_OC_POLARITY_NORMAL, /*! OCNPolarity 比较互补输出极性 */
    (uint32_t)FL_DISABLE, /*! OCFastMode 比较输出通道快速模式使能 */
    (uint32_t)FL_DISABLE,   /*! OCPreload 输出比较预装载 */
    (uint32_t)FL_ATIM_PWM_DUTY_INIT,  /*! compareValue 通道比较值 */
    (uint32_t)FL_ATIM_OC_IDLE_STATE_HIGH,  /*! OCIdleState 输出空闲状态电平 */
    (uint32_t)FL_DISABLE,  /*! OCETRFStatus ETR清0使能 */
    (uint32_t)FL_ATIM_OCN_IDLE_STATE_HIGH,  /*! OCNIdleState 互补输出空闲状态电平 */
};

const FL_ATIM_OC_InitTypeDef g_atmer0_ch3_InitStructer =
{
    (uint32_t)FL_ATIM_OC_MODE_PWM1,  /*! OCMode 比较输出模式 */
    (uint32_t)FL_ENABLE, /*! OCState 正向比较通道输出使能 */
    (uint32_t)FL_DISABLE, /*! OCNState 比较互补通道输出使能 */
    (uint32_t)FL_ATIM_OC_POLARITY_NORMAL,  /*! OCPolarity 比较输出极性 */
    (uint32_t)FL_ATIM_OC_POLARITY_NORMAL, /*! OCNPolarity 比较互补输出极性 */
    (uint32_t)FL_DISABLE, /*! OCFastMode 比较输出通道快速模式使能 */
    (uint32_t)FL_DISABLE,   /*! OCPreload 输出比较预装载 */
    (uint32_t)FL_ATIM_PWM_DUTY_INIT,  /*! compareValue 通道比较值 */
    (uint32_t)FL_ATIM_OC_IDLE_STATE_HIGH,  /*! OCIdleState 输出空闲状态电平 */
    (uint32_t)FL_DISABLE,  /*! OCETRFStatus ETR清0使能 */
    (uint32_t)FL_ATIM_OCN_IDLE_STATE_HIGH,  /*! OCNIdleState 互补输出空闲状态电平 */
};

const FL_ATIM_OC_InitTypeDef g_atmer0_ch4_InitStructer =
{
    (uint32_t)FL_ATIM_OC_MODE_PWM1,  /*! OCMode 比较输出模式 */
    (uint32_t)FL_ENABLE, /*! OCState 正向比较通道输出使能 */
    (uint32_t)FL_DISABLE, /*! OCNState 比较互补通道输出使能 */
    (uint32_t)FL_ATIM_OC_POLARITY_NORMAL,  /*! OCPolarity 比较输出极性 */
    (uint32_t)FL_ATIM_OC_POLARITY_NORMAL, /*! OCNPolarity 比较互补输出极性 */
    (uint32_t)FL_DISABLE, /*! OCFastMode 比较输出通道快速模式使能 */
    (uint32_t)FL_DISABLE,   /*! OCPreload 输出比较预装载 */
    (uint32_t)FL_ATIM_PWM_DUTY_INIT,  /*! compareValue 通道比较值 */
    (uint32_t)FL_ATIM_OC_IDLE_STATE_HIGH,  /*! OCIdleState 输出空闲状态电平 */
    (uint32_t)FL_DISABLE,  /*! OCETRFStatus ETR清0使能 */
    (uint32_t)FL_ATIM_OCN_IDLE_STATE_HIGH,  /*! OCNIdleState 互补输出空闲状态电平 */
};


const FL_ATIM_BDTR_InitTypeDef g_atimer0_bdtr_config=
{
    (uint32_t)FL_ATIM_OSSR_DISABLE, /*! OSSRState 运行状态下的输出关闭状态 */
    (uint32_t)FL_ATIM_OSSI_DISABLE, /*! OSSIState 空闲状态下的输出关闭状态 */
    (uint32_t)FL_ATIM_LOCK_LEVEL_OFF, /*! lockLevel 寄存器写保护等级 */
    (uint32_t)100u,   /*! deadTime 死区时间 */
    (uint32_t)FL_DISABLE,  /*! breakState 刹车使能 */
    (uint32_t)FL_ATIM_BREAK_FILTER_DIV1,  /*! breakFilter 刹车信号滤波 */
    (uint32_t)FL_ATIM_BREAK_POLARITY_HIGH, /*! breakPolarity 刹车信号极性 */
    (uint32_t)FL_DISABLE, /*! automaticOutput 刹车后计数器重装后自动输出使能*/
    (uint32_t)FL_ATIM_BREAK1_GATE_AUTO, /*! gatedBrakeSignal_1 刹车信号1门控 */
    (uint32_t)FL_ATIM_BREAK2_GATE_AUTO, /*! gatedBrakeSignal_2 刹车信号2门控 */
    (uint32_t)FL_ATIM_BREAK_COMBINATION_OR, /*! brakeSignalCombined  两路刹车信号控制逻辑 */
};
#endif


#ifdef FL_BSTIM16_ENABLE
const FL_BSTIM16_InitTypeDef  g_TimerBase_InitStruct =
{
    (uint32_t)479u,
    (uint32_t)99u,   //  1 / (48MHZ/480M) * 100 = 0.001 s
    (uint32_t)FL_ENABLE,
    (uint32_t)FL_CMU_BSTIM16_CLK_SOURCE_APBCLK,
};
#endif

#ifdef FL_GPTIM_ENABLE
/**
 *
 */
const FL_GPTIM_InitTypeDef g_gptim_init_cfg =
{
    (uint32_t)48u - 1u,                     /* 分频系数48000 */
    (uint32_t)FL_GPTIM_COUNTER_DIR_UP,    /* 向上计数 */
    (uint32_t)FL_GPTIM_PWM_FREQ - 1u,                     /* 自动重装载值1000 */
    (uint32_t)FL_ENABLE,                    /* 预装载preload使能 */
    (uint32_t)FL_GPTIM_CLK_DIVISION_DIV1,   /* 死区和滤波分频 */
};

const FL_GPTIM_OC_InitTypeDef g_gptim_ch1_cfg =
{
    (uint32_t)FL_GPTIM_OC_MODE_PWM1,               /* 输出比较模式PWM1 */
    (uint32_t)FL_DISABLE,                          /* 关闭快速使能 */
    (uint32_t)FL_DISABLE,                          /* OC preload 无效 */
    (uint32_t)FL_GPTIM_PWM_DUTY_VALID,                                 /* 比较值500 */
    (uint32_t)FL_GPTIM_OC_POLARITY_NORMAL,         /* OC正常输出 */
    (uint32_t)FL_DISABLE,                          /* OC1REF不受ETR影响 */
};

const FL_GPTIM_OC_InitTypeDef g_gptim_ch2_cfg =
{
    (uint32_t)FL_GPTIM_OC_MODE_PWM1,               /* 输出比较模式PWM1 */
    (uint32_t)FL_DISABLE,                          /* 关闭快速使能 */
    (uint32_t)FL_DISABLE,                          /* OC preload 无效 */
    (uint32_t)FL_GPTIM_PWM_DUTY_VALID,                                 /* 比较值500 */
    (uint32_t)FL_GPTIM_OC_POLARITY_NORMAL,         /* OC正常输出 */
    (uint32_t)FL_DISABLE,                          /* OC1REF不受ETR影响 */
};

const FL_GPTIM_OC_InitTypeDef g_gptim_ch3_cfg =
{
    (uint32_t)FL_GPTIM_OC_MODE_PWM1,               /* 输出比较模式PWM1 */
    (uint32_t)FL_DISABLE,                          /* 关闭快速使能 */
    (uint32_t)FL_DISABLE,                          /* OC preload 无效 */
    (uint32_t)FL_GPTIM_PWM_DUTY_VALID,                                 /* 比较值500 */
    (uint32_t)FL_GPTIM_OC_POLARITY_NORMAL,         /* OC正常输出 */
    (uint32_t)FL_DISABLE,                          /* OC1REF不受ETR影响 */
};

const FL_GPTIM_OC_InitTypeDef g_gptim_ch4_cfg =
{
    (uint32_t)FL_GPTIM_OC_MODE_PWM1,               /* 输出比较模式PWM1 */
    (uint32_t)FL_DISABLE,                          /* 关闭快速使能 */
    (uint32_t)FL_DISABLE,                          /* OC preload 无效 */
    (uint32_t)FL_GPTIM_PWM_DUTY_VALID,                                 /* 比较值500 */
    (uint32_t)FL_GPTIM_OC_POLARITY_NORMAL,         /* OC正常输出 */
    (uint32_t)FL_DISABLE,                          /* OC1REF不受ETR影响 */
};

#endif

#ifdef FL_GPTIM1_ENABLE

const FL_GPTIM_InitTypeDef g_gptim1_init_cfg =
{
    (uint32_t)48u - 1u,                     /* 分频系数48000 */
    (uint32_t)FL_GPTIM_COUNTER_DIR_UP,    /* 向上计数 */
    (uint32_t)FL_GPTIM1_PWM_FREQ - 1u,                     /* 自动重装载值1000 */
    (uint32_t)FL_ENABLE,                    /* 预装载preload使能 */
    (uint32_t)FL_GPTIM_CLK_DIVISION_DIV1,   /* 死区和滤波分频 */
};

const FL_GPTIM_OC_InitTypeDef g_gptim1_ch1_cfg =
{
    (uint32_t)FL_GPTIM_OC_MODE_PWM1,               /* 输出比较模式PWM1 */
    (uint32_t)FL_DISABLE,                          /* 关闭快速使能 */
    (uint32_t)FL_DISABLE,                          /* OC preload 无效 */
    (uint32_t)FL_GPTIM1_PWM_DUTY_VALID,                                 /* 比较值500 */
    (uint32_t)FL_GPTIM_OC_POLARITY_NORMAL,         /* OC正常输出 */
    (uint32_t)FL_DISABLE,                          /* OC1REF不受ETR影响 */
};

const FL_GPTIM_OC_InitTypeDef g_gptim1_ch2_cfg =
{
    (uint32_t)FL_GPTIM_OC_MODE_PWM1,               /* 输出比较模式PWM1 */
    (uint32_t)FL_DISABLE,                          /* 关闭快速使能 */
    (uint32_t)FL_DISABLE,                          /* OC preload 无效 */
    (uint32_t)FL_GPTIM1_PWM_DUTY_VALID,                                 /* 比较值500 */
    (uint32_t)FL_GPTIM_OC_POLARITY_NORMAL,         /* OC正常输出 */
    (uint32_t)FL_DISABLE,                          /* OC1REF不受ETR影响 */
};

const FL_GPTIM_OC_InitTypeDef g_gptim1_ch3_cfg =
{
    (uint32_t)FL_GPTIM_OC_MODE_PWM1,               /* 输出比较模式PWM1 */
    (uint32_t)FL_DISABLE,                          /* 关闭快速使能 */
    (uint32_t)FL_DISABLE,                          /* OC preload 无效 */
    (uint32_t)FL_GPTIM1_PWM_DUTY_VALID,                                 /* 比较值500 */
    (uint32_t)FL_GPTIM_OC_POLARITY_NORMAL,         /* OC正常输出 */
    (uint32_t)FL_DISABLE,                          /* OC1REF不受ETR影响 */
};

const FL_GPTIM_OC_InitTypeDef g_gptim1_ch4_cfg =
{
    (uint32_t)FL_GPTIM_OC_MODE_PWM1,               /* 输出比较模式PWM1 */
    (uint32_t)FL_DISABLE,                          /* 关闭快速使能 */
    (uint32_t)FL_DISABLE,                          /* OC preload 无效 */
    (uint32_t)FL_GPTIM1_PWM_DUTY_VALID,                                 /* 比较值500 */
    (uint32_t)FL_GPTIM_OC_POLARITY_NORMAL,         /* OC正常输出 */
    (uint32_t)FL_DISABLE,                          /* OC1REF不受ETR影响 */
};

#endif




const FL_GPTIM_InitTypeDef g_gptim2_init_cfg =
{
    (uint32_t)48u - 1u,                     /* 分频系数48000 */
    (uint32_t)FL_GPTIM_COUNTER_DIR_UP,    /* 向上计数 */
    (uint32_t)FL_GPTIM2_PWM_FREQ - 1u,                     /* 自动重装载值1000 */
    (uint32_t)FL_ENABLE,                    /* 预装载preload使能 */
    (uint32_t)FL_GPTIM_CLK_DIVISION_DIV1,   /* 死区和滤波分频 */
};

const FL_GPTIM_OC_InitTypeDef g_gptim2_ch1_cfg =
{
    (uint32_t)FL_GPTIM_OC_MODE_PWM1,               /* 输出比较模式PWM1 */
    (uint32_t)FL_DISABLE,                          /* 关闭快速使能 */
    (uint32_t)FL_DISABLE,                          /* OC preload 无效 */
    (uint32_t)FL_GPTIM2_PWM_DUTY_VALID,                                 /* 比较值500 */
    (uint32_t)FL_GPTIM_OC_POLARITY_NORMAL,         /* OC正常输出 */
    (uint32_t)FL_DISABLE,                          /* OC1REF不受ETR影响 */
};

const FL_GPTIM_OC_InitTypeDef g_gptim2_ch2_cfg =
{
    (uint32_t)FL_GPTIM_OC_MODE_PWM1,               /* 输出比较模式PWM1 */
    (uint32_t)FL_DISABLE,                          /* 关闭快速使能 */
    (uint32_t)FL_DISABLE,                          /* OC preload 无效 */
    (uint32_t)FL_GPTIM2_PWM_DUTY_VALID,                                 /* 比较值500 */
    (uint32_t)FL_GPTIM_OC_POLARITY_NORMAL,         /* OC正常输出 */
    (uint32_t)FL_DISABLE,                          /* OC1REF不受ETR影响 */
};

const FL_GPTIM_OC_InitTypeDef g_gptim2_ch3_cfg =
{
    (uint32_t)FL_GPTIM_OC_MODE_PWM1,               /* 输出比较模式PWM1 */
    (uint32_t)FL_DISABLE,                          /* 关闭快速使能 */
    (uint32_t)FL_DISABLE,                          /* OC preload 无效 */
    (uint32_t)FL_GPTIM2_PWM_DUTY_VALID,                                 /* 比较值500 */
    (uint32_t)FL_GPTIM_OC_POLARITY_NORMAL,         /* OC正常输出 */
    (uint32_t)FL_DISABLE,                          /* OC1REF不受ETR影响 */
};

const FL_GPTIM_OC_InitTypeDef g_gptim2_ch4_cfg =
{
    (uint32_t)FL_GPTIM_OC_MODE_PWM1,               /* 输出比较模式PWM1 */
    (uint32_t)FL_DISABLE,                          /* 关闭快速使能 */
    (uint32_t)FL_DISABLE,                          /* OC preload 无效 */
    (uint32_t)FL_GPTIM2_PWM_DUTY_VALID,                                 /* 比较值500 */
    (uint32_t)FL_GPTIM_OC_POLARITY_NORMAL,         /* OC正常输出 */
    (uint32_t)FL_DISABLE,                          /* OC1REF不受ETR影响 */
};




#ifdef FL_LPTIM16_ENABLE
const FL_LPTIM16_InitTypeDef g_lptim16_cfg_tab =
{
    (uint32_t)FL_CMU_LPTIM16_CLK_SOURCE_RCLP,  /* 内部时钟源 */
    (uint32_t)FL_LPTIM16_CLK_SOURCE_INTERNAL,  /* 预分频器的时钟源 可选择内部时钟, 也可选择外部时钟 */
    (uint32_t)FL_LPTIM16_PSC_DIV32,   /* 预分频系数 */
    (uint32_t)200 - 1,  /* 重装值 */  //200ms 做为间隙唤醒
    (uint32_t)FL_LPTIM16_OPERATION_MODE_NORMAL,  /* 定时器工作模式选择 */
    (uint32_t)FL_LPTIM16_ENCODER_MODE_DISABLE, /* 定时器编码器模式 */
    (uint32_t)FL_LPTIM16_ONE_PULSE_MODE_CONTINUOUS,  /* 单次计数使能 */
    (uint32_t)FL_LPTIM16_ETR_COUNT_EDGE_RISING,  /* ETR异步计数边沿 */
    (uint32_t)FL_LPTIM16_ETR_TRIGGER_EDGE_RISING, /* ETR触发计数边沿 */
};
#endif


const FL_LPTIM32_InitTypeDef g_lptim32_cfg_tab =
{
    (uint32_t)FL_CMU_LPTIM32_CLK_SOURCE_APBCLK,  /* 内部时钟源 */
    (uint32_t)FL_LPTIM32_CLK_SOURCE_INTERNAL,  /* 预分频器的时钟源 可选择内部时钟, 也可选择外部时钟 */
    (uint32_t)FL_LPTIM32_PSC_DIV16,   /* 预分频系数 */
    (uint32_t)FL_LPT32_PWM_FREQ - 1,  /* 重装值 */  //3000*200 - 1  是 200ms
    (uint32_t)FL_LPTIM32_OPERATION_MODE_NORMAL,  /* 定时器工作模式选择 */
    (uint32_t)FL_LPTIM32_ONE_PULSE_MODE_CONTINUOUS,  /* 单次计数使能 */
    (uint32_t)FL_LPTIM32_ETR_COUNT_EDGE_RISING,  /* ETR异步计数边沿 */
    (uint32_t)FL_LPTIM32_ETR_TRIGGER_EDGE_RISING, /* ETR触发计数边沿 */
};

//
const FL_LPTIM32_OC_InitTypeDef g_lpt32_ch1_cfg =
{
    (uint32_t)0u,                      /* 比较值 */
    (uint32_t)FL_LPTIM32_OC_POLARITY_INVERT,   //输出极性
};

//
const FL_LPTIM32_OC_InitTypeDef g_lpt32_ch2_cfg =
{
    (uint32_t)0u,                      /* 比较值 */
    (uint32_t)FL_LPTIM32_OC_POLARITY_INVERT,   //输出极性
};

//
const FL_LPTIM32_OC_InitTypeDef g_lpt32_ch3_cfg =
{
    (uint32_t)0u,                      /* 比较值 */
    (uint32_t)FL_LPTIM32_OC_POLARITY_INVERT,   //输出极性
};

//
const FL_LPTIM32_OC_InitTypeDef g_lpt32_ch4_cfg =
{
    (uint32_t)0u,                      /* 比较值 */
    (uint32_t)FL_LPTIM32_OC_POLARITY_INVERT,   //输出极性
};




/*---------------------------------------------------------------------------
- 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        : ATIM中断函数
----------------------------------------------------------------------------*/
void ATIM_IRQHandler()
{
    if(FL_ATIM_IsEnabledIT_Update(ATIM) && FL_ATIM_IsActiveFlag_Update(ATIM))
    {
        FL_ATIM_ClearFlag_Update(ATIM);

        /* 处理更新事件 */
        //logic_time_tick_count();
        #ifdef TIM_CFG_DEBUG_DISP_EN
        g_tim_cfg.count[0]++;
        if(g_tim_cfg.count[0]>=1000u)
        {
            g_tim_cfg.count[0]=0u;
            g_tim_cfg.count[1]++;
        }
        #endif
        //random_input_count();
        //TEST1_TOGGLE();
    }
}
#endif

#ifdef FL_BSTIM16_ENABLE

/*---------------------------------------------------------------------------
|Prototype          :
|Called by          :
|Preconditions      :
|Input parameters   :
|Output parameters  :
|Return value       :
|Description        : BSTIM中断服务函数
----------------------------------------------------------------------------*/
void BSTIM_IRQHandler(void)
{
    if(FL_BSTIM16_IsEnabledIT_Update(BSTIM16) && FL_BSTIM16_IsActiveFlag_Update(BSTIM16))
    {
        FL_BSTIM16_ClearFlag_Update(BSTIM16);

        /* 处理更新事件 */
        Tim_tick_count();
        //logic_timer_tick_count();
        #ifdef TIM_CFG_DEBUG_DISP_EN
        g_tim_cfg.count[2]++;
        if(g_tim_cfg.count[2]>=1000u)
        {
            g_tim_cfg.count[2]=0u;
            g_tim_cfg.count[3]++;
        }
        #endif
        //random_input_count();
        //TEST1_TOGGLE();
    }
}

#endif


/*---------------------------------------------------------------------------
|Prototype          :
|Called by          :
|Preconditions      :
|Input parameters   :
|Output parameters  :
|Return value       :
|Description        : LPTIM中断函数
----------------------------------------------------------------------------*/
void LPTIM_IRQHandler(void)
{
    #ifdef FL_LPTIM16_ENABLE

    /* 定时器溢出时翻转LED0 */
    if(FL_LPTIM16_IsActiveFlag_Update(LPTIM16))
    {
        FL_LPTIM16_ClearFlag_Update(LPTIM16);
        /* LED0_TOG(); */
        #ifdef TIM_CFG_DEBUG_DISP_EN
        g_tim_cfg.count[4]++;
        if(g_tim_cfg.count[4]>=5u)
        {
            g_tim_cfg.count[4]=0u;
            g_tim_cfg.count[5]++;
        }
        #endif
    }
    #endif
    #ifdef FL_LPTIM32_ENABLE
    /* 定时器溢出时翻转LED */
    if(FL_LPTIM32_IsEnabledIT_Update(LPTIM32) && FL_LPTIM32_IsActiveFlag_Update(LPTIM32))
    {
        /* LED0_TOG(); */
        FL_LPTIM32_ClearFlag_Update(LPTIM32);
        #ifdef TIM_CFG_DEBUG_DISP_EN
        g_tim_cfg.count[6]++;
        if(g_tim_cfg.count[6]>=1000u)
        {
            g_tim_cfg.count[6]=0u;
            g_tim_cfg.count[7]++;
        }
        #endif
    }
    #endif
}



