From 6c841ad18a86f1f075340577c0e43ea433bce427 Mon Sep 17 00:00:00 2001
From: WXK <287788329@qq.com>
Date: 星期五, 01 十一月 2024 19:16:27 +0800
Subject: [PATCH] 1.20,等待现场测试一下

---
 Src/application/dw_mbx_tag.c |   70 ++++++++++++++++++----------------
 1 files changed, 37 insertions(+), 33 deletions(-)

diff --git a/Src/application/dw_mbx_tag.c b/Src/application/dw_mbx_tag.c
index e077358..398d257 100644
--- a/Src/application/dw_mbx_tag.c
+++ b/Src/application/dw_mbx_tag.c
@@ -1,7 +1,7 @@
 #include "dw_mbx_tag.h"
 #include "dps310.h"
 #define DELAY_BETWEEN_TWO_FRAME_UUS 400
-#define POLL_RX_TO_RESP_TX_DLY_UUS 470
+#define POLL_RX_TO_RESP_TX_DLY_UUS 670
 #define UUS_TO_DWT_TIME 65536
 
 static uint64_t get_rx_timestamp_u64(void)
@@ -79,19 +79,19 @@
     dwt_writetxfctrl(38, 0);//设定发送长度
     result = dwt_starttx(DWT_START_TX_DELAYED);
 
-    start_time=HAL_LPTIM_ReadCounter(&hlptim1);
-    timeout=100; //单位0.1ms
-    end_time=start_time+(timeout<<2);
-    if(end_time>=32768)
-    {
-        end_time-=32768;
-    }
-    current_time=HAL_LPTIM_ReadCounter(&hlptim1);
+//    start_time=HAL_LPTIM_ReadCounter(&hlptim1);
+//    timeout=100; //单位0.1ms
+//    end_time=start_time+(timeout<<2);
+//    if(end_time>=32768)
+//    {
+//        end_time-=32768;
+//    }
+//    current_time=HAL_LPTIM_ReadCounter(&hlptim1);
     while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & SYS_STATUS_TXFRS ))///不断查询芯片状态直到接收成功或者出现错误
     {
-        current_time=HAL_LPTIM_ReadCounter(&hlptim1);
-        if(current_time>=end_time&&current_time<end_time+15000)
-            break;
+//        current_time=HAL_LPTIM_ReadCounter(&hlptim1);
+//        if(current_time>=end_time&&current_time<end_time+15000)
+//            break;
     };
     tagofflinetime[taglist_pos] = 0;
 //            printf("测距成功,序号%d,距离%d\r\n",frame_seq_nb2,tagdist_list[taglist_pos]);
@@ -138,26 +138,27 @@
     uint16_t checksum;
     uint8_t kk;
 
-    dwt_setrxtimeout(3000);//设定接收超时时间,0位没有超时时间
-    dwt_rxenable(0);//打开接收
-    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET);
-    temp231 =  dwt_read32bitreg(CHAN_CTRL_ID) ;
-    start_time=HAL_LPTIM_ReadCounter(&hlptim1);
-    timeout=100; //单位0.1ms
-    end_time=start_time+(timeout<<2);
-    if(end_time>=32768)
-    {
-        end_time-=32768;
-    }
-    current_time=HAL_LPTIM_ReadCounter(&hlptim1);
+//    dwt_setrxtimeout(3000);//设定接收超时时间,0位没有超时时间
+//    dwt_rxenable(0);//打开接收
+//    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET);
+//    temp231 =  dwt_read32bitreg(CHAN_CTRL_ID) ;
+//    start_time=HAL_LPTIM_ReadCounter(&hlptim1);
+//    timeout=100; //单位0.1ms
+//    end_time=start_time+(timeout<<2);
+//    if(end_time>=32768)
+//    {
+//        end_time-=32768;
+//    }
+//    current_time=HAL_LPTIM_ReadCounter(&hlptim1);
 
-    while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR)))//不断查询芯片状态直到接收成功或者出现错误
-    {
-        current_time=HAL_LPTIM_ReadCounter(&hlptim1);
-        if(current_time>=end_time&&current_time<end_time+15000)
-            break;
-    };
-
+//    while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR)))//不断查询芯片状态直到接收成功或者出现错误
+//    {
+//        current_time=HAL_LPTIM_ReadCounter(&hlptim1);
+//        if(current_time>=end_time&&current_time<end_time+15000)
+//            break;
+//    };
+	status_reg  = dwt_read32bitreg(SYS_STATUS_ID);
+    dwt_setinterrupt(  DWT_INT_RFCG | (DWT_INT_ARFE | DWT_INT_RFSL | DWT_INT_SFDT | DWT_INT_RPHE | DWT_INT_RFCE | DWT_INT_RFTO | DWT_INT_RXPTO), 0);
     if (status_reg & SYS_STATUS_RXFCG && status_reg!=0xffffffff)//成功接收
     {
         uint16_t tag_recv_interval;
@@ -228,8 +229,10 @@
         //  dwt_rxenable(0);
     }
 
-    dwt_forcetrxoff();
-    dwt_entersleep();
+        dwt_forcetrxoff();
+        dwt_setinterrupt(  DWT_INT_RFCG | (DWT_INT_ARFE | DWT_INT_RFSL | DWT_INT_SFDT | DWT_INT_RPHE | DWT_INT_RFCE | DWT_INT_RFTO | DWT_INT_RXPTO), 1);
+		dwt_setrxtimeout(0);//设定接收超时时间,0位没有超时时间
+        dwt_rxenable(0);
 
 }
 wg_state_enum wg_state = WG_Lost;
@@ -355,6 +358,7 @@
     memcpy(&lora_sendbuffer[ANCID_IDX+report_ancnum*2],report_ancdist,report_ancnum*2);
     checksum = Checksum_u16(lora_sendbuffer,4*report_ancnum+ANCID_IDX);
     memcpy(&lora_sendbuffer[ANCID_IDX+report_ancnum*4],&checksum,2);
+    HAL_NVIC_DisableIRQ(EXTI4_15_IRQn);
     Radio.Send(lora_sendbuffer,ANCID_IDX+report_ancnum*4+2);
     LED_TB_ON;
     bat_percent=Get_Battary();

--
Gitblit v1.9.3