| | |
| | | #define POLL_DELAY 100U //yuan100U |
| | | |
| | | /* Receive response timeout */ |
| | | #define RESP_RX_TIMEOUT_US 5000U //Yuan500 10mssuccess 300jixian |
| | | #define RESP_RX_TIMEOUT_US 6000U //Yuan500 10mssuccess 300jixian |
| | | |
| | | /* Field index in frame */ |
| | | #define MSG_SEQ_NUM_IDX 2 |
| | |
| | | #define FINAL_MSG_RESP_RX_TS_IDX 14 |
| | | #define FINAL_MSG_FINAL_TX_TS_IDX 18 |
| | | #define DELAY_DEFAULT 50000 |
| | | #define DELAY_BETWEEN_TWO_FRAME_UUS 1400 |
| | | #define DELAY_BETWEEN_TWO_FRAME_UUS 600 //yuan1400 |
| | | #define HALF_SECOND_TIME 62400000 |
| | | |
| | | uint16_t CmpTagInList(uint16_t tagid); |
| | |
| | | }; |
| | | uint32_t dev_id; |
| | | uint8_t group_id; |
| | | /* Default communication configuration. */ |
| | | static struct mk_uwb_configure config = {//yuan |
| | | .phy_work_mode = (uint8_t)(PHY_TX | PHY_RX), |
| | | .phy_cfg.ch_num = 5, /* Channel number. */ |
| | | .phy_cfg.code_index = 9, /* TRX preamble code */ |
| | | .phy_cfg.mean_prf = MEAN_PRF_64M, /* Mean prf 64/128/256M */ |
| | | .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 = NON_STD_NSFD5_8, /* Identifier for SFD sequence */ |
| | | .phy_cfg.ranging_bit = 1, /* ranging bit set 1 */ |
| | | .phy_cfg.trx_mode = TRX_MODE_15_4A, /* 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 */ |
| | | }; |
| | | ///* Default communication configuration. */ |
| | | //static struct mk_uwb_configure config = { |
| | | //static struct mk_uwb_configure config = {//yuan |
| | | // .phy_work_mode = (uint8_t)(PHY_TX | PHY_RX), |
| | | // .phy_cfg.ch_num = 5, /* Channel number. */ |
| | | // .phy_cfg.code_index = 3, /* TX preamble code. */ |
| | | // .phy_cfg.mean_prf = MEAN_PRF_16M, /* Data rate 6.8M */ |
| | | // .phy_cfg.data_bit_rate = DATA_BR_110K, /* data rate 6.8M. */ |
| | | // .phy_cfg.sync_sym = PREAM_LEN_1024, /* Preamble duration, length of preamble 128 */ |
| | | // .phy_cfg.sfd_sym = NSFD_64, /* Identifier for SFD sequence */ |
| | | // .phy_cfg.ranging_bit = 1, /* ranging bit set. */ |
| | | // .phy_cfg.code_index = 9, /* TRX preamble code */ |
| | | // .phy_cfg.mean_prf = MEAN_PRF_64M, /* Mean prf 64/128/256M */ |
| | | // .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 = NON_STD_NSFD5_8, /* Identifier for SFD sequence */ |
| | | // .phy_cfg.ranging_bit = 1, /* ranging bit set 1 */ |
| | | // .phy_cfg.trx_mode = TRX_MODE_15_4A, /* 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 */ |
| | | //}; |
| | | /* Default communication configuration. */ |
| | | static struct mk_uwb_configure config = { |
| | | .phy_work_mode = (uint8_t)(PHY_TX | PHY_RX), |
| | | .phy_cfg.ch_num = 5, /* Channel number. */ |
| | | .phy_cfg.code_index = 3, /* TX preamble code. */ |
| | | .phy_cfg.mean_prf = MEAN_PRF_16M, /* Data rate 6.8M */ |
| | | .phy_cfg.data_bit_rate = DATA_BR_110K, /* data rate 6.8M. */ |
| | | .phy_cfg.sync_sym = PREAM_LEN_1024, /* Preamble duration, length of preamble 128 */ |
| | | .phy_cfg.sfd_sym = NSFD_64, /* Identifier for SFD sequence */ |
| | | .phy_cfg.ranging_bit = 1, /* ranging bit set. */ |
| | | .phy_cfg.trx_mode = TRX_MODE_15_4A, /* 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 */ |
| | | }; |
| | | /* Buffer to store received frame */ |
| | | static uint8_t rx_buf[150]; |
| | | static uint8_t uwb_sendbuffer[150]; |
| | |
| | | } |
| | | uint32_t count_index; |
| | | int tt=1; |
| | | int TagRange(void) |
| | | void uwb_tag_init(void) |
| | | { |
| | | // The following peripherals will be initialized in the uwb_open function |
| | | // The following peripherals will be initialized in the uwb_open function |
| | | // phy/mac/aes/lsp/phy timers initialized |
| | | uwb_open(); |
| | | |
| | |
| | | |
| | | ranging_frame_type_set(config.phy_cfg.sts_pkt_cfg); |
| | | |
| | | // Register rx interrupt callback function |
| | | mac_register_process_handler(tx_int_callback, rx_int_callback); |
| | | |
| | | |
| | | } |
| | | int TagRange(void) |
| | | { |
| | | |
| | | phy_timer_open(1, IRQ_PRIORITY_HIGH); |
| | | //#if LOW_POWER_EN |
| | | // // Initialize low power mode |
| | | // power_init(); |
| | | // // Enable sleep timer |
| | | // sleep_timer_open(true, SLEEP_TIMER_MODE_ONESHOT, NULL); |
| | | //#endif |
| | | // Register rx interrupt callback function |
| | | |
| | | mac_register_process_handler(tx_int_callback, rx_int_callback); |
| | | 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);//发送必须要延时发送才可以用于测距否则立即发送会获取时间戳不对,需要计算程序运行时间,避免设置过去时间 |
| | |
| | | // if(tt){ |
| | | while(current_count<end_receive_count||current_count>end_receive_count+HALF_SECOND_TIME)//循环接受包体,若为124.8K则是+62400000 |
| | | { |
| | | |
| | | current_count=phy_timer_count_get();//不断刷新当前计数器值 |
| | | temp_count2=phy_timer_count_get(); |
| | | while(mac_is_busy());//等待接收完成 |