| | |
| | | * 1 uus = 512 / 499.2 祍 and 1 祍 = 499.2 * 128 dtu. */ |
| | | #define UUS_TO_DWT_TIME 65536 |
| | | |
| | | /* Delay between frames, in UWB microseconds. See NOTE 4 below. */ |
| | | /* This is the delay from the end of the frame transmission to the enable of the receiver, as programmed for the DW1000's wait for response feature. */ |
| | | #define POLL_TX_TO_RESP_RX_DLY_UUS 150 |
| | | /* This is the delay from Frame RX timestamp to TX reply timestamp used for calculating/setting the DW1000's delayed TX function. This includes the |
| | | * frame length of approximately 2.66 ms with above configuration. */ |
| | | #define RESP_RX_TO_FINAL_TX_DLY_UUS 410 |
| | | ///* Delay between frames, in UWB microseconds. See NOTE 4 below. */ |
| | | ///* This is the delay from the end of the frame transmission to the enable of the receiver, as programmed for the DW1000's wait for response feature. */ |
| | | //#define POLL_TX_TO_RESP_RX_DLY_UUS 150 |
| | | ///* This is the delay from Frame RX timestamp to TX reply timestamp used for calculating/setting the DW1000's delayed TX function. This includes the |
| | | // * frame length of approximately 2.66 ms with above configuration. */ |
| | | //#define RESP_RX_TO_FINAL_TX_DLY_UUS 410 |
| | | |
| | | /* Receive response timeout. See NOTE 5 below. */ |
| | | #define RESP_RX_TIMEOUT_UUS 600 |
| | | ///* Receive response timeout. See NOTE 5 below. */ |
| | | //#define RESP_RX_TIMEOUT_UUS 600 |
| | | |
| | | #define DELAY_BETWEEN_TWO_FRAME_UUS 400 |
| | | //#define DELAY_BETWEEN_TWO_FRAME_UUS 400 |
| | | |
| | | //#define POLL_RX_TO_RESP_TX_DLY_UUS 470 |
| | | /* This is the delay from the end of the frame transmission to the enable of the receiver, as programmed for the DW1000's wait for response feature. */ |
| | | #define RESP_TX_TO_FINAL_RX_DLY_UUS 200 |
| | | /* Receive final timeout. See NOTE 5 below. */ |
| | | #define FINAL_RX_TIMEOUT_UUS 4300 |
| | | ////#define POLL_RX_TO_RESP_TX_DLY_UUS 470 |
| | | ///* This is the delay from the end of the frame transmission to the enable of the receiver, as programmed for the DW1000's wait for response feature. */ |
| | | //#define RESP_TX_TO_FINAL_RX_DLY_UUS 200 |
| | | ///* Receive final timeout. See NOTE 5 below. */ |
| | | //#define FINAL_RX_TIMEOUT_UUS 4300 |
| | | |
| | | |
| | | #define SPEED_OF_LIGHT 299702547 |
| | |
| | | DWT_PHRMODE_STD, /* PHY header mode. */ |
| | | (65 + 8 - 8) /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */ |
| | | }; |
| | | static uint8_t tx_poll_msg[20] = {0}; |
| | | static uint8_t tx_sync_msg[14] = {0}; |
| | | static uint8_t tx_final_msg[60] = {0}; |
| | | static uint8_t tx_resp_msg[22] = {0}; |
| | | uint8_t tx_near_msg[80] = {0}; |
| | | //static uint8_t tx_poll_msg[20] = {0}; |
| | | //static uint8_t tx_sync_msg[14] = {0}; |
| | | //static uint8_t tx_final_msg[60] = {0}; |
| | | //static uint8_t tx_resp_msg[22] = {0}; |
| | | // uint8_t tx_near_msg[80] = {0}; |
| | | |
| | | static uint32_t frame_seq_nb = 0; |
| | | static uint32_t status_reg = 0; |
| | | static uint8_t rx_buffer[100]; |
| | | static uint64_t poll_tx_ts; |
| | | static uint64_t resp_rx_ts; |
| | | static uint64_t final_tx_ts; |
| | | static uint64_t poll_rx_ts; |
| | | static uint64_t resp_tx_ts; |
| | | static uint64_t final_rx_ts; |
| | | int32_t anchor_dist_last_frm[TAG_NUM_IN_SYS],his_dist[TAG_NUM_IN_SYS]; ; |
| | | uint32_t tag_id = 0; |
| | | uint32_t tag_id_recv = 0; |
| | | uint32_t anc_id_recv = 0; |
| | | uint8_t random_delay_tim = 0; |
| | | double distance, dist_no_bias, dist_cm; |
| | | uint32_t g_UWB_com_interval = 0; |
| | | float dis_after_filter; //当前距离值 |
| | | LPFilter_Frac* p_Dis_Filter; //测距用的低通滤波器 |
| | | //static uint32_t frame_seq_nb = 0; |
| | | //static uint32_t status_reg = 0; |
| | | //static uint8_t rx_buffer[100]; |
| | | //static uint64_t poll_tx_ts; |
| | | //static uint64_t resp_rx_ts; |
| | | //static uint64_t final_tx_ts; |
| | | //static uint64_t poll_rx_ts; |
| | | //static uint64_t resp_tx_ts; |
| | | //static uint64_t final_rx_ts; |
| | | //int32_t anchor_dist_last_frm[TAG_NUM_IN_SYS],his_dist[TAG_NUM_IN_SYS]; ; |
| | | //uint32_t tag_id = 0; |
| | | //uint32_t tag_id_recv = 0; |
| | | //uint32_t anc_id_recv = 0; |
| | | //uint8_t random_delay_tim = 0; |
| | | //double distance, dist_no_bias, dist_cm; |
| | | //uint32_t g_UWB_com_interval = 0; |
| | | //float dis_after_filter; //当前距离值 |
| | | //LPFilter_Frac* p_Dis_Filter; //测距用的低通滤波器 |
| | | |
| | | |
| | | |
| | | static uint64_t get_tx_timestamp_u64(void) |
| | | { |
| | | uint8_t ts_tab[5]; |
| | | uint64_t ts = 0; |
| | | int i; |
| | | dwt_readtxtimestamp(ts_tab); |
| | | for (i = 4; i >= 0; i--) |
| | | { |
| | | ts <<= 8; |
| | | ts |= ts_tab[i]; |
| | | } |
| | | return ts; |
| | | } |
| | | //static uint64_t get_tx_timestamp_u64(void) |
| | | //{ |
| | | // uint8_t ts_tab[5]; |
| | | // uint64_t ts = 0; |
| | | // int i; |
| | | // dwt_readtxtimestamp(ts_tab); |
| | | // for (i = 4; i >= 0; i--) |
| | | // { |
| | | // ts <<= 8; |
| | | // ts |= ts_tab[i]; |
| | | // } |
| | | // return ts; |
| | | //} |
| | | |
| | | static uint64_t get_rx_timestamp_u64(void) |
| | | { |
| | | uint8_t ts_tab[5]; |
| | | uint64_t ts = 0; |
| | | int i; |
| | | dwt_readrxtimestamp(ts_tab); |
| | | for (i = 4; i >= 0; i--) |
| | | { |
| | | ts <<= 8; |
| | | ts |= ts_tab[i]; |
| | | } |
| | | return ts; |
| | | } |
| | | //static uint64_t get_rx_timestamp_u64(void) |
| | | //{ |
| | | // uint8_t ts_tab[5]; |
| | | // uint64_t ts = 0; |
| | | // int i; |
| | | // dwt_readrxtimestamp(ts_tab); |
| | | // for (i = 4; i >= 0; i--) |
| | | // { |
| | | // ts <<= 8; |
| | | // ts |= ts_tab[i]; |
| | | // } |
| | | // return ts; |
| | | //} |
| | | |
| | | static void final_msg_set_ts(uint8_t *ts_field, uint64_t ts) |
| | | { |
| | | int i; |
| | | for (i = 0; i < FINAL_MSG_TS_LEN; i++) |
| | | { |
| | | ts_field[i] = (uint8_t) ts; |
| | | ts >>= 8; |
| | | } |
| | | } |
| | | //static void final_msg_set_ts(uint8_t *ts_field, uint64_t ts) |
| | | //{ |
| | | // int i; |
| | | // for (i = 0; i < FINAL_MSG_TS_LEN; i++) |
| | | // { |
| | | // ts_field[i] = (uint8_t) ts; |
| | | // ts >>= 8; |
| | | // } |
| | | //} |
| | | |
| | | static void final_msg_get_ts(const uint8_t *ts_field, uint32_t *ts) |
| | | { |
| | | int i; |
| | | *ts = 0; |
| | | for (i = 0; i < FINAL_MSG_TS_LEN; i++) |
| | | { |
| | | *ts += ts_field[i] << (i * 8); |
| | | } |
| | | } |
| | | //static void final_msg_get_ts(const uint8_t *ts_field, uint32_t *ts) |
| | | //{ |
| | | // int i; |
| | | // *ts = 0; |
| | | // for (i = 0; i < FINAL_MSG_TS_LEN; i++) |
| | | // { |
| | | // *ts += ts_field[i] << (i * 8); |
| | | // } |
| | | //} |
| | | uint32_t uwbid=0; |
| | | void Dw1000_Init(void) |
| | | { |
| | |
| | | { |
| | | //g_com_map[DEV_ID] = 0x0b; |
| | | //tag_state=DISCPOLL; |
| | | tx_poll_msg[MESSAGE_TYPE_IDX]=POLL; |
| | | tx_resp_msg[MESSAGE_TYPE_IDX]=RESPONSE; |
| | | tx_final_msg[MESSAGE_TYPE_IDX]=FINAL; |
| | | tx_sync_msg[MESSAGE_TYPE_IDX]=SYNC; |
| | | // tx_poll_msg[MESSAGE_TYPE_IDX]=POLL; |
| | | // tx_resp_msg[MESSAGE_TYPE_IDX]=RESPONSE; |
| | | // tx_final_msg[MESSAGE_TYPE_IDX]=FINAL; |
| | | // tx_sync_msg[MESSAGE_TYPE_IDX]=SYNC; |
| | | |
| | | memcpy(&tx_poll_msg[TAG_ID_IDX], &dev_id, 2); |
| | | memcpy(&tx_final_msg[TAG_ID_IDX], &dev_id, 2); |
| | | memcpy(&tx_resp_msg[ANCHOR_ID_IDX], &dev_id, 2); |
| | | memcpy(&tx_sync_msg[ANCHOR_ID_IDX], &dev_id, 2); |
| | | memcpy(&tx_near_msg[ANCHOR_ID_IDX], &dev_id, 2); |
| | | memcpy(&tx_near_msg[TAG_ID_IDX], &dev_id, 2); |
| | | // memcpy(&tx_poll_msg[TAG_ID_IDX], &dev_id, 2); |
| | | // memcpy(&tx_final_msg[TAG_ID_IDX], &dev_id, 2); |
| | | // memcpy(&tx_resp_msg[ANCHOR_ID_IDX], &dev_id, 2); |
| | | // memcpy(&tx_sync_msg[ANCHOR_ID_IDX], &dev_id, 2); |
| | | // memcpy(&tx_near_msg[ANCHOR_ID_IDX], &dev_id, 2); |
| | | // memcpy(&tx_near_msg[TAG_ID_IDX], &dev_id, 2); |
| | | } |
| | | uint16_t Checksum_u16(uint8_t* pdata, uint32_t len) |
| | | { |