| | |
| | | #define RANGING_PERIOD_MS (1000) |
| | | |
| | | /* This is the delay from the end of the poll frame transmission to the enable of the receiver */ |
| | | #define POLL_TX_TO_RESP_RX_DLY_US 750U //yuan700 |
| | | #define POLL_TX_TO_RESP_RX_DLY_US 300U //yuan700 |
| | | |
| | | #define RESP_RX_TO_FINAL_TX_DLY_US 550U |
| | | |
| | |
| | | #define POLL_DELAY 100U //yuan100U |
| | | |
| | | /* Receive response timeout */ |
| | | #define RESP_RX_TIMEOUT_US 2500U //Yuan500 10mssuccess 300jixian |
| | | #define RESP_RX_TIMEOUT_US 1200U //Yuan500 10mssuccess 300jixian |
| | | |
| | | /* Field index in frame */ |
| | | #define MSG_SEQ_NUM_IDX 2 |
| | |
| | | }; |
| | | uint32_t dev_id; |
| | | uint8_t group_id; |
| | | #ifndef STS_MODE |
| | | #ifdef DW1000 |
| | | /* Default communication configuration. */ |
| | | static struct mk_uwb_configure config = {//yuan |
| | | .phy_work_mode = (uint8_t)(PHY_TX | PHY_RX), |
| | |
| | | .phy_cfg.sts_seglen = STS_SEGLEN_BPRF_64, /* Number of symbols in an STS segment */ |
| | | .phy_cfg.rx_ant_id = UWB_RX_ANT_3, /* UWB RX antenna port */ |
| | | }; |
| | | #else |
| | | #elif defined STS_MODE |
| | | static struct mk_uwb_configure config = { |
| | | .phy_work_mode = (uint8_t)(PHY_TX | PHY_RX), |
| | | .phy_cfg.ch_num = 5, /* Channel number. */ |
| | |
| | | .sts_key1 = 0xF86050A8, |
| | | .sts_key2 = 0xD1D336AA, |
| | | .sts_key3 = 0x14148674, |
| | | }; |
| | | #else //MKmode |
| | | /* Default communication configuration. */ |
| | | static struct mk_uwb_configure config = { |
| | | .phy_work_mode = (uint8_t)(PHY_TX | PHY_RX), |
| | | .phy_cfg.ch_num = 9, /* Channel number. */ |
| | | .phy_cfg.code_index = 9, /* TX preamble code. */ |
| | | .phy_cfg.mean_prf = MEAN_PRF_64M, /* Data rate 6.8M */ |
| | | .phy_cfg.data_bit_rate = DATA_BR_6M8, /* data rate 6.8M. */ |
| | | .phy_cfg.sync_sym = PREAM_LEN_128, /* Preamble duration, length of preamble 128 */ |
| | | .phy_cfg.sfd_sym = BPRF_NSFD2_8, /* Identifier for SFD sequence */ |
| | | .phy_cfg.ranging_bit = 1, /* ranging bit set. */ |
| | | .phy_cfg.trx_mode = TRX_MODE_15_4Z_BPRF, /* IEEE802.15.4z - BPRF mode */ |
| | | .phy_cfg.sts_pkt_cfg = STS_PKT_CFG_0, /* SP0 Frame */ |
| | | .phy_cfg.sts_segnum = STS_SEGNUM_BPRF_1, /* Number of STS segments in the frame */ |
| | | .phy_cfg.sts_seglen = STS_SEGLEN_BPRF_64, /* Number of symbols in an STS segment */ |
| | | .phy_cfg.rx_ant_id = UWB_RX_ANT_3, /* UWB RX antenna port */ |
| | | }; |
| | | #endif |
| | | ///* Default communication configuration. */ |
| | |
| | | |
| | | // uwb configure |
| | | uwb_configure(config.phy_work_mode, board_param.tx_power_fcc[CALIB_CH(config.phy_cfg.ch_num)], &config.phy_cfg); |
| | | #ifdef STS_MODE |
| | | #if (defined STS_MODE) || (defined MK_MODE) |
| | | ranging_lib_init(); |
| | | #endif |
| | | ranging_frame_type_set(config.phy_cfg.sts_pkt_cfg); |
| | |
| | | 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());//等待发送完成 |
| | | #ifdef BOXING |
| | | gpio_pin_clr(IO_PIN_5);//测试 |
| | | gpio_pin_set(IO_PIN_5);//测试 |
| | | temp_count2=phy_timer_count_get(); |
| | | #endif |
| | | temp_count2=phy_timer_count_get(); |
| | | resp_rx_en_start_u32 = poll_tx_en_start_u32+ US_TO_PHY_TIMER_COUNT(POLL_TX_TO_RESP_RX_DLY_US);//设置发送多少s后接收按target独立时间起点算+ US_TO_PHY_TIMER_COUNT(POLL_TX_TO_RESP_RX_DLY_US为发送后要多久开启接收时间 |
| | | temp_resp=resp_rx_en_start_u32; |
| | | //tempflag=uwb_rx(1, resp_rx_en_start_u32, RESP_RX_TIMEOUT_US);//开启接受并设置接收超时 |
| | | tempflag=uwb_rx(0,0, RESP_RX_TIMEOUT_US); |
| | | tempflag=uwb_rx(0,resp_rx_en_start_u32, RESP_RX_TIMEOUT_US); |
| | | |
| | | |
| | | start_receive_count=phy_timer_count_get(); |
| | |
| | | // #endif |
| | | }else if(receive_flag==2){//接收出错 |
| | | receive_flag=0; |
| | | sleep_timer_start(__MS_TO_32K_CNT(SLEEP_COUNT-phy_timer_count_get()%30));//测试 |
| | | sleep_time_step=SLEEP_COUNT-phy_timer_count_get()%10; |
| | | // sleep_timer_start(__MS_TO_32K_CNT(SLEEP_COUNT-phy_timer_count_get()%30));//测试 |
| | | // sleep_time_step=SLEEP_COUNT-phy_timer_count_get()%10; |
| | | tempflag=uwb_rx(0, 0, RESP_RX_TIMEOUT_US);//立即开启接受并设置0超时 |
| | | temp_count3=phy_timer_count_get(); |
| | | // while(mac_is_busy()); |