From 5631f61d1e227cf40802bcef95b1bf9c053cb04a Mon Sep 17 00:00:00 2001 From: WXK <287788329@qq.com> Date: 星期五, 14 三月 2025 18:46:44 +0800 Subject: [PATCH] 1.10,ch9 --- keil/include/main/main.c | 90 ++++++++++++++++++++++++++++++++++++++------ 1 files changed, 77 insertions(+), 13 deletions(-) diff --git a/keil/include/main/main.c b/keil/include/main/main.c index 123f295..00d4efc 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 60 +#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 + 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,6 +111,12 @@ .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 bat_percent=0,g_start_send_flag=1; @@ -109,12 +124,15 @@ 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); 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); @@ -131,17 +149,56 @@ 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; enable_sleep_count++; if(enable_sleep_count==SLEEP_START_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 +222,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,8 +235,8 @@ 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)|2; +tag_frequency=1000/g_com_map[COM_INTERVAL]; +g_com_map[VERSION] = (1<<8)|10; 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); } @@ -244,13 +302,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 +318,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 +335,20 @@ #endif //Serial0_PutString("进入app测试\r\n"); while (1) - { + { wdt_ping(WDT_ID0);//喂狗 if(g_start_send_flag) { //LOG_INFO(TRACE_MODULE_APP, "测距ing"); 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