第一次上传E3boot
This commit is contained in:
104
btm_init.c
Normal file
104
btm_init.c
Normal file
@@ -0,0 +1,104 @@
|
||||
#include "regs_base.h"
|
||||
#include "irq_num.h"
|
||||
#include "btm_init.h"
|
||||
|
||||
|
||||
static sdrv_btm_t gstsdrv_btm_timer0;
|
||||
sdrv_btm_t gstsdrv_btm_timer1;
|
||||
|
||||
volatile uint8_t Btm10ms = 0;
|
||||
volatile uint8_t Btm1ms = 0;
|
||||
|
||||
|
||||
#define DEVICE_BASE(dev) _DEVICE_BASE(dev)
|
||||
#define _DEVICE_BASE(dev) APB_##dev##_BASE
|
||||
|
||||
#define DEVICE_INTR(dev) _DEVICE_INTR(dev)
|
||||
#define _DEVICE_INTR(dev) dev##_INTR_NUM
|
||||
|
||||
|
||||
|
||||
/*SDRV_BTM_G0时钟来源于APB clock, APB clock等于150MHz*/
|
||||
/*SDRV_BTM_G0分频之后,clock等于1M*/
|
||||
static sdrv_btm_cfg_t timer0_config = {
|
||||
.base = DEVICE_BASE(BTM2),
|
||||
.irq = DEVICE_INTR(BTM2_O_BTM),
|
||||
.tmr_id = SDRV_BTM_G0,
|
||||
.tmr_cfg = {
|
||||
.si_val = 74, /*输入时钟每(si_val + 1)cycle, G0计数器增加inc_val个*/
|
||||
.inc_val = 1,
|
||||
.frc_rld_rst_cnt_en = true, /*默认是true,表示初始化时是否对counter清零。*/
|
||||
.term_use_mode = SDRV_BTM_DIRECT, /*设置overflow值立即生效,而不是等到下一周期生效。*/
|
||||
.cmp_use_mode = SDRV_BTM_DIRECT, /*设置compare值立即生效,而不是等到下一周期生效。*/
|
||||
.cnt_dir = SDRV_BTM_CNT_UP, /*设置计数器的值是向上增长*/
|
||||
.cnt_mode = SDRV_BTM_CONTINOUS_MODE, /*设置计数器是连续模式*/
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*SDRV_BTM_G1时钟来源于外部晶振,等于24MHz*/
|
||||
/*SDRV_BTM_G1分频之后,clock等于1M*/
|
||||
static sdrv_btm_cfg_t timer1_config = {
|
||||
.base = DEVICE_BASE(BTM2),
|
||||
.irq = DEVICE_INTR(BTM2_O_BTM),
|
||||
.tmr_id = SDRV_BTM_G1,
|
||||
.tmr_cfg = {
|
||||
.si_val = 23,
|
||||
.inc_val = 1,
|
||||
.frc_rld_rst_cnt_en = true,
|
||||
.term_use_mode = SDRV_BTM_DIRECT,
|
||||
.cmp_use_mode = SDRV_BTM_DIRECT,
|
||||
.cnt_dir = SDRV_BTM_CNT_UP,
|
||||
.cnt_mode = SDRV_BTM_CONTINOUS_MODE,
|
||||
}
|
||||
};
|
||||
|
||||
//回调处理,10ms定时标志
|
||||
static void timer1_handle(void *arg)
|
||||
{
|
||||
static int timer1_count = 0;
|
||||
timer1_count++;
|
||||
|
||||
Btm1ms = 1;
|
||||
|
||||
if(timer1_count >= 10)
|
||||
{
|
||||
timer1_count = 0;
|
||||
Btm10ms = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*启用g1计数器*/
|
||||
int btm_init(void)
|
||||
{
|
||||
sdrv_btm_init(&gstsdrv_btm_timer1, &timer0_config);//定时器1初始化
|
||||
sdrv_btm_set_callback(&gstsdrv_btm_timer1, timer1_handle, &gstsdrv_btm_timer1);//设定回调函数
|
||||
sdrv_btm_start(&gstsdrv_btm_timer1, BTM_TYPE_PERIOD, BTM_TIME_US, 1000);//设定1000us定时
|
||||
|
||||
sdrv_btm_init(&gstsdrv_btm_timer0, &timer1_config);//定时器0初始化
|
||||
sdrv_btm_start(&gstsdrv_btm_timer0, BTM_TYPE_PERIOD, BTM_TIME_MS, ~0);//设定1ms定时
|
||||
return 0;
|
||||
}
|
||||
|
||||
//获取当前计数器时间,lwip用
|
||||
uint32_t current_time(void)
|
||||
{
|
||||
return sdrv_btm_get_current_time(&gstsdrv_btm_timer0) / 1000;
|
||||
}
|
||||
|
||||
//获取当前计数器时间us
|
||||
uint32_t getCurrentTime(void)
|
||||
{
|
||||
return sdrv_btm_get_current_time(&gstsdrv_btm_timer0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user