From dcbd0e93b5cc05ea9f1e1152c7951a37e12d177f Mon Sep 17 00:00:00 2001 From: chen <15335560115@163.com> Date: 星期二, 03 六月 2025 15:23:36 +0800 Subject: [PATCH] V1.13版本修改接收时间和帧间隔和延迟接收时间参数,适配铁鞋稳定一对多测距版本 --- keil/include/main/main.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 92 insertions(+), 21 deletions(-) diff --git a/keil/include/main/main.c b/keil/include/main/main.c index 6c11a48..5d0bbf9 100644 --- a/keil/include/main/main.c +++ b/keil/include/main/main.c @@ -61,9 +61,14 @@ #define TEST_UART_MODE TEST_UART_DMA_MODE #define NUM_SAMPLES 1 -#define SLEEP_START_TIME 120 +#define SLEEP_START_TIME 10 +#define FREQ_LOST_TIME 5 +#define NOTAG_FREQ 1 +#define BATTERY_GET_TIME 3600 uint8_t enable_sleep_count,sleep_flag; -#define DEBUG_MODE +uint32_t battery_get_count; +//#define DEBUG_MODE +uint32_t reboot_num; struct UART_CFG_T test_uart_cfg = { .parity = UART_PARITY_NONE, @@ -87,7 +92,11 @@ .int_tx = false, #endif }; - +static void app_wdt_callback(void *dev, uint32_t status) +{ + ASSERT(status, "WDT TIMEOUT,程序复位"); + //LOG_INFO(TRACE_MODULE_APP, "程序卡死,看门狗复位"); +} static uint32_t sample[NUM_SAMPLES] = {0}; static struct ADC_CFG_T usr_adc_cfg = { .mode = ADC_MODE_CONTINUE, /* Selected single conversion mode */ @@ -102,22 +111,32 @@ .high_pulse_time = 4, .settle_time = 1, }; + struct WDT_CFG_T app_wdt_cfg = { + .timeout = 32768 * 30, + .rst_en = true, + .int_en = true, + .callback = app_wdt_callback, + }; -uint8_t state5v = 1; +uint8_t state5v = 0; uint8_t bat_percent=0,g_start_send_flag=1; int16_t fVoltage_mv; uint8_t bat_percent; extern uint32_t dev_id; extern uint8_t group_id; -uint8_t tag_frequence; +extern float freqlost_count; +uint8_t tag_frequency; void UartDeinit(void); void UartInit(void); void Program_Init(void); void IdleTask(void); void boot_deinit(void); +void Get_batterty_Voltage(void); +void Calculate_battery_percent(void); +uint8_t sleep_limit_time=1; static void uart_receive_callback(void *dev, uint32_t err_code) { -uart_receive(UART_ID1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE,uart_receive_callback); +uart_receive(UART_ID0,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE,uart_receive_callback); } void UartInit(void) { @@ -131,17 +150,59 @@ uart_close(UART_ID0); uart_close(UART_ID1); } +void Get_batterty_Voltage(void) +{ + battery_monitor_open(); + fVoltage_mv=battery_monitor_get(); + battery_monitor_close(); + Calculate_battery_percent(); +} +void Calculate_battery_percent(void) +{ + if(fVoltage_mv < 3000) + { + bat_percent = 0; + } + else if(fVoltage_mv > 3500) + { + bat_percent = 100; + } + else + { + bat_percent = ((fVoltage_mv - 3000) /8); + } + //LOG_INFO(TRACE_MODULE_APP, "The voltage is %d ,percent is %%%d \r\n",fVoltage_mv,bat_percent); +} static void sleep_timer_callback(void *dev, uint32_t time) { //sleep_timer_start(__MS_TO_32K_CNT(1000)); + static uint8_t lost_jumpcount=0; + reboot_num++; + if(reboot_num>=3600) + NVIC_SystemReset(); //软复位回到bootloader enable_sleep_count++; - if(enable_sleep_count==SLEEP_START_TIME){ - + + if(enable_sleep_count==sleep_limit_time){ enable_sleep_count=0; sleep_flag=1; } - g_start_send_flag=1; - //LOG_INFO(TRACE_MODULE_APP, "Sleep timer interrupt callback\r\n"); + if(battery_get_count++>=BATTERY_GET_TIME) + { + Get_batterty_Voltage(); + battery_get_count=0; + } +// if(freqlost_count++>FREQ_LOST_TIME) +// { +// tag_frequency = NOTAG_FREQ; +// if(lost_jumpcount++>=4) //无测距情况下,每5秒发一次; +// { +// lost_jumpcount = 0; +// g_start_send_flag=1; +// } +// }else{ +// g_start_send_flag=1; +// } + g_start_send_flag=1; } static void adc_callback(void *data, uint32_t number) { @@ -165,8 +226,9 @@ bat_percent = ((fVoltage_mv - 3300) /8); } } - LOG_INFO(TRACE_MODULE_APP, "The voltage is %%%d \r\n",bat_percent); + //LOG_INFO(TRACE_MODULE_APP, "The voltage is %%%d \r\n",bat_percent); } + static void voltage_input_handler(enum IO_PIN_T pin) { //LOG_INFO(TRACE_MODULE_APP, "中断唤醒\r\n"); @@ -177,22 +239,25 @@ parameter_init();//g_com_map表初始化 group_id=g_com_map[GROUP_ID]; memcpy(&dev_id ,&g_com_map[DEV_ID],2); -tag_frequence=1000/g_com_map[COM_INTERVAL]; -g_com_map[VERSION] = (1<<8)|7; +tag_frequency=1000/g_com_map[COM_INTERVAL]; +g_com_map[VERSION] = (1<<8)|13; LOG_INFO(TRACE_MODULE_APP,"设备ID: %x .\r\n",dev_id); -LOG_INFO(TRACE_MODULE_APP,"固件版本:UWB-标签 V%d.%d. \r\n",g_com_map[VERSION]>>8,g_com_map[VERSION]&0xff); +LOG_INFO(TRACE_MODULE_APP,"固件版本:UWB-免布线信标 V%d.%d. \r\n",g_com_map[VERSION]>>8,g_com_map[VERSION]&0xff); } +uint8_t test1; void IdleTask(void) { UART0_CheckReceive(); + test1=gpio_pin_get_val(INPUT_5V_Pin); if(gpio_pin_get_val(INPUT_5V_Pin)) { - - //UART_CheckSend(); // bat_percent=Get_Battary(); if(state5v==0) { state5v=1; + sleep_flag=0; + sleep_limit_time=30;//新增插入串口后30s不休眠 + enable_sleep_count=0;//重新插拔可以重置时间 } }else{ if(state5v==1) @@ -244,13 +309,14 @@ // Disable watchdog timer wdt_close(WDT_ID0); + wdt_open(WDT_ID0,&app_wdt_cfg);//30s最大上限检测喂狗 //LOG_INFO(TRACE_MODULE_APP, "UWB qiang test example\r\n"); // open system timer //sys_timer_open(); gpio_open(); - //board_led_init(); + board_led_init(); //uart_open(UART_ID0, &test_uart_cfg); @@ -259,12 +325,15 @@ uart_receive(UART_ID0,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE,uart_receive_callback); // Initialize low power mode power_init(); + Get_batterty_Voltage();//获取当前内部电压 + //Calculate_battery_percent(); //adc_open(&usr_adc_cfg); //adc_get(&sample[0], NUM_SAMPLES, adc_callback);//adc采样 // Enable sleep timer + Tag_uwb_init(); sleep_timer_open(true, SLEEP_TIMER_MODE_RELOAD, sleep_timer_callback); //sleep_timer_start(__MS_TO_32K_CNT(g_com_map[COM_INTERVAL]));//测试 - sleep_timer_start(__MS_TO_32K_CNT(500));//测试 + sleep_timer_start(__MS_TO_32K_CNT(SLEEP_COUNT));//测试 //board_5V_input_init(voltage_input_handler);//有修改3.3V会一直高电平导致无法进入休眠 #ifdef BOXING io_pin_mux_set(IO_PIN_5, IO_FUNC0);//波形测试 @@ -273,18 +342,20 @@ #endif //Serial0_PutString("进入app测试\r\n"); while (1) - { + { if(g_start_send_flag) { //LOG_INFO(TRACE_MODULE_APP, "测距ing"); - + wdt_ping(WDT_ID0);//喂狗 g_start_send_flag = 0; - + gpio_pin_set(LED_PIN);//亮 TagRange(); + gpio_pin_clr(LED_PIN);//灭 IdleTask(); }else{ IdleTask(); } + LoraUp_Poll(); #ifndef DEBUG_MODE if(sleep_flag){//开始一段时间无休眠 trace_flush(); -- Gitblit v1.9.3