keil/uwb_app.c
@@ -60,7 +60,7 @@
#define RANGING_PERIOD_MS (1000)
/* This is the delay from Frame RX POLL frame to send RESP Frame */
#define POLL_RX_TO_RESP_TX_DLY_US 450U //yuan750 7500Haoyong
#define POLL_RX_TO_RESP_TX_DLY_US 670U //yuan450
#define RESP_TX_TO_FINAL_RX_DLY_US 500U
@@ -79,7 +79,7 @@
/* RX window open in advance */
#define RX_WIN_IN_ADVANCE_US (150)
#define DELAY_BETWEEN_TWO_FRAME_UUS 400
#define DELAY_BETWEEN_TWO_FRAME_UUS 1000
/* Field index in frame */
#define MSG_SEQ_NUM_IDX 2
@@ -341,14 +341,16 @@
    if(rec_nearbase_num == ancrec_nearbasepos)//抢占模式自己为新基站
    {
        random_time = (phy_timer_count_get()%1000);//多基站抢占一个位置时避免一个也收不到的情况就每一个随机错开几十uS
        random_time = (phy_timer_count_get()%100);//多基站抢占一个位置时避免一个也收不到的情况就每一个随机错开几十uS
        //resp_tx_time = (poll_rx_ts+((random_time+rec_nearbase_num*20 + POLL_RX_TO_RESP_TX_DLY_UUS+ancrec_nearbasepos*DELAY_BETWEEN_TWO_FRAME_UUS) * UUS_TO_DWT_TIME)) >> 8;//计算Response发送时间T3。
        // (resp_tx_en_start_u32) is the moment when TX enable
        resp_tx_en_start_u32 = random_time+phy_timer_count_get()+ US_TO_PHY_TIMER_COUNT(POLL_RX_TO_RESP_TX_DLY_US)+rec_nearbase_num*US_TO_PHY_TIMER_COUNT(DELAY_BETWEEN_TWO_FRAME_UUS);//后面的需要根据已有基站数量进行更改,如果是抢占自己最后一个回复,要有底数
    } else {
        resp_tx_en_start_u32 = random_time+poll_rx_en_start_u32+US_TO_PHY_TIMER_COUNT(20*rec_nearbase_num)+US_TO_PHY_TIMER_COUNT(POLL_RX_TO_RESP_TX_DLY_US)+rec_nearbase_num*US_TO_PHY_TIMER_COUNT(DELAY_BETWEEN_TWO_FRAME_UUS);//后面的需要根据已有基站数量进行更改,如果是抢占自己最后一个回复,要有底数
      } else {
        //resp_tx_time = (poll_rx_ts + ((rec_nearbase_num*20+POLL_RX_TO_RESP_TX_DLY_UUS+ancrec_nearbasepos*DELAY_BETWEEN_TWO_FRAME_UUS) * UUS_TO_DWT_TIME)) >> 8;//计算Response发送时间T3。
        resp_tx_en_start_u32 = phy_timer_count_get() + US_TO_PHY_TIMER_COUNT(POLL_RX_TO_RESP_TX_DLY_US)+(ancrec_nearbasepos+1)*US_TO_PHY_TIMER_COUNT(DELAY_BETWEEN_TWO_FRAME_UUS);//后面的需要根据已有基站数量进行更改,自己非抢占
    }//此处设置绝对时间将poll u32改为phy_timer_count_get()
        resp_tx_en_start_u32 = poll_rx_en_start_u32+US_TO_PHY_TIMER_COUNT(20*rec_nearbase_num)+US_TO_PHY_TIMER_COUNT(POLL_RX_TO_RESP_TX_DLY_US)+rec_nearbase_num*US_TO_PHY_TIMER_COUNT(DELAY_BETWEEN_TWO_FRAME_UUS);//后面的需要根据已有基站数量进行更改,自己非抢占
            //这里应该有问题问一下钟工
      }//此处设置绝对时间将poll u32改为phy_timer_count_get()
    resp_tx_ts_i64 = ranging_tx_time_correct(resp_tx_en_start_u32 + phy_shr_duration());//修正时间戳
    /* Write all timestamps in the final message. See NOTE 8 below. */
@@ -362,7 +364,8 @@
    while(mac_is_busy());
    gpio_pin_clr(SCL_PIN);
}
uint16_t uwb_searchcount,range_timeout_us = 5000;
uint32_t range_timeout_us = 5000;
uint16_t uwb_searchcount;
uint8_t flag_recsuccess;
extern uint8_t g_start_send_flag,search_open_flag = 1,link_success_flag;
int UwbRange(void)
@@ -398,7 +401,7 @@
    temp_count3=phy_timer_count_get();
    gpio_pin_set(SCL_PIN);
    uwb_rx(0, 0, range_timeout_us);//开启接收
  //  while(mac_is_busy());
   // while(mac_is_busy());
  //  temp_count2=phy_timer_count_get();
      start_receive_count=phy_timer_count_get();
   poll_timeout=US_TO_PHY_TIMER_COUNT(range_timeout_us);//多一个多0.4ms默认0.4ms计算为0.125*4*100000,默认开启1mss
@@ -418,6 +421,7 @@
                    break;
            }
        }
    if(receive_flag==1)//成功接收
    {
@@ -465,6 +469,8 @@
         uwb_rx(0, 0, range_timeout_us);
    }
   }
      delay_us(1);
      uwb_rx_force_off(1);
      if(!flag_recsuccess)
      {
         sleep_timer_start(__MS_TO_32K_CNT(UWB_DELAY_TIME_US-3));//测试
@@ -477,7 +483,10 @@
            search_open_flag = 1;
        }
         }
    gpio_pin_clr(SCL_PIN);
         return 0;
}
@@ -579,6 +588,8 @@
        uwb_rx(0, 0, RX_SYNC_WIN_US_TEMP);//再次开启接收
    }
      delay_us(1);
      uwb_rx_force_off(1);
    // LOG_INFO(TRACE_MODULE_APP,"超时定时器:%x,%x,%x\r\n",start_receive_count,end_receive_count,current_count);
    gpio_pin_clr(SCL_PIN);//测试
    return 0;//返回绑定失败标志