From e54c70b2c45ca652ddd2808a95a057cb797eab58 Mon Sep 17 00:00:00 2001 From: chen <15335560115@163.com> Date: 星期六, 05 七月 2025 14:16:11 +0800 Subject: [PATCH] square天线NVM初始化问题解决调到和官方效果一致,初步移植完STS并能稳定一对一测距板本 --- keil/uwb_tag_.c | 45 ++++++++++++++++++++++++++++----------------- 1 files changed, 28 insertions(+), 17 deletions(-) diff --git a/keil/uwb_tag_.c b/keil/uwb_tag_.c index 6f31235..325f90f 100644 --- a/keil/uwb_tag_.c +++ b/keil/uwb_tag_.c @@ -299,30 +299,28 @@ } uint32_t temp_rx_first_stamp,temp_rx_second_stamp; uint16_t temp_rx_first_id,temp_rx_second_id; +uint8_t mac_error; /* RX done process handler. */ static void rx_int_callback(struct MAC_HW_REPORT_T *rx_report) { // Power off radio power_off_radio(); + sts_lsp_store_stop(); //tempflag=uwb_rx(0, 0, RESP_RX_TIMEOUT_US); rx_state = rx_report->err_code; /** UWB RX success */ if (rx_state == UWB_RX_OK) { - /* Received data does not contain FCS */ + if(sts_valid_check()) + { + //mac_error=0; + /* Received data does not contain FCS */ rx_length = rx_report->pkt_len; memcpy(rx_buf, rx_report->pkt_data, rx_length); /* Calculate rx timestamp */ resp_rx_ts_i64 = ranging_rx_time_correct(rx_report); -// if(temp_rx_first_stamp==0) -// { -// temp_rx_first_stamp=(uint32_t)resp_rx_ts_i64; -// memcpy(&temp_rx_first_id,&rx_buf[1],2); -// }else{ -// memcpy(&temp_rx_second_id,&rx_buf[1],2); -// temp_rx_second_stamp=(uint32_t)resp_rx_ts_i64; -// } + temp_count1=phy_timer_count_get(); //获取发射端时钟偏差 resp_rx_num++; @@ -333,7 +331,10 @@ //calib_xtal38m4_load_cap_auto_tune(ppm);//利用电容调整晶振适配频偏应在完整的一包之后调整,需要关闭XTAL_AUTO_TUNE_EN 宏定义避免收包中途校准导致测距错误 //LOG_INFO(TRACE_MODULE_APP, "poll_tx_num is %d,resp_rx_num is %d,distance is %lf\r\n",poll_tx_num,resp_rx_num,distance); receive_flag=1; - + }else{ + //mac_error=1; + rx_state |= UWB_STS_ERR; + } } else { @@ -347,7 +348,7 @@ rx_length = 0; receive_flag=2; temp_count2=phy_timer_count_get(); - + // mac_error=1; } //tempflag=uwb_rx(0, 0, RESP_RX_TIMEOUT_US);//立即开启接受并设置0超时 } @@ -361,6 +362,7 @@ /** UWB TX success */ if (tx_report->err_code == UWB_TX_OK) { + //mac_error=0; poll_tx_num++; temp_count4=phy_timer_count_get();//测试 if(temp_flag){ @@ -370,7 +372,9 @@ } count1=temp_count1; temp_flag=1; - } + }else{ + mac_error=1; + } } @@ -531,7 +535,7 @@ ranging_lib_init(config.phy_cfg.sts_pkt_cfg, CE_AUX_CH_PWR_NLOS_FOM); } void Anchor_uwb_aoa_square_init(void) -{ +{ uwb_open(); // Set calibration parameters uwb_calibration_params_set(config.phy_cfg.ch_num); @@ -674,8 +678,9 @@ uwb_poll_buffer_construct(); temp_tag_num=0;//临时数量为0 poll_tx_en_start_u32 = phy_timer_count_get()+US_TO_PHY_TIMER_COUNT(POLL_DELAY);//发送必须要延时发送才可以用于测距否则立即发送会获取时间戳不对,需要计算程序运行时间,避免设置过去时间 - //tempflag=uwb_tx(uwb_sendbuffer,13+4*tag_num_tosend,1,poll_tx_en_start_u32);//立即发送 - tempflag=uwb_tx(uwb_sendbuffer,sizeof(uwb_sendbuffer),1,poll_tx_en_start_u32);//立即发送 + tempflag=uwb_tx(uwb_sendbuffer,13+4*tag_num_tosend,1,poll_tx_en_start_u32);//立即发送 + + //tempflag=uwb_tx(uwb_sendbuffer,sizeof(uwb_sendbuffer),1,poll_tx_en_start_u32);//立即发送 #ifdef BOXING gpio_pin_set(IO_PIN_5);//测试 #endif @@ -683,6 +688,12 @@ poll_tx_ts_i64 = ranging_tx_time_correct(poll_tx_en_start_u32 + phy_shr_duration());//修正时间戳 temp_count1=phy_timer_count_get(); while(mac_is_busy());//等待发送完成 +// if(!mac_error) +// phy_update_sts_iv_counter(0x01, 0x00);//新增sts发送成功后开启 +// else{ +// mac_error=0; +// return 0;//发送失败 +// } #ifdef BOXING gpio_pin_clr(IO_PIN_5);//测试 gpio_pin_set(IO_PIN_5);//测试 @@ -723,7 +734,7 @@ if(receive_flag==1)//成功接收数据 { receive_flag=0; - phy_update_sts_iv_counter(0x01, 0x00);//新增sts + //phy_update_sts_iv_counter(0x01, 0x00);//新增sts发送成功后开启 tempflag=uwb_rx(0, 0, RESP_RX_TIMEOUT_US);//立即开启接受并设置0超时 //接收成功则判断是否为同一组 if(rx_buf[MESSAGE_TYPE_IDX] == MBX_POLL)//收到是其他的基站的POLL包 @@ -773,7 +784,7 @@ gpio_pin_clr(IO_PIN_5);//测试 gpio_pin_set(IO_PIN_5);//测试 #endif - phy_update_sts_iv_counter(0x00, sts_iv_key.sts_vcounter);//sts + //phy_update_sts_iv_counter(0x00, sts_iv_key.sts_vcounter);//sts } // } #ifdef BOXING -- Gitblit v1.9.3