| | |
| | | case UWB_PKT_TX_DONE_MSG: |
| | | { |
| | | const struct UWB_PKT_TX_DONE_IND_T *ind = (const struct UWB_PKT_TX_DONE_IND_T *)param; |
| | | |
| | | if (ind->status != UWB_TX_OK) |
| | | { |
| | | LOG_INFO(TRACE_MODULE_APP, "UWB TX fail 0x%04x\r\n", ind->status); |
| | | break; |
| | | } |
| | | |
| | | if (ind->ranging_stage == RANGING_POLL) |
| | | { |
| | | uint16_t seq_num = READ_SHORT(&ind->tx_data[2]); |
| | | ranging_env.range_data.sequence_num = READ_SHORT(&ind->tx_data[2]); |
| | | |
| | | #ifdef SE_DEMO_EN |
| | | if (ind->tx_len > (MSG_HEADER_LEN + MSG_POLL_USER_DATA_IDX)) |
| | |
| | | LOG_INFO(TRACE_MODULE_APP | TRACE_NO_OPTION, "\r\n"); |
| | | if (uwb_app_config.ranging_flow_mode == (uint8_t)RANGING_FLOW_CONTENTION) |
| | | { |
| | | LOG_INFO(TRACE_MODULE_APP, "Custom DS-TWR Contention Initiator SEQ NUM %u\r\n", seq_num); |
| | | LOG_INFO(TRACE_MODULE_APP, "Custom DS-TWR Contention Initiator SEQ NUM %u\r\n", ranging_env.range_data.sequence_num); |
| | | } |
| | | else |
| | | { |
| | | LOG_INFO(TRACE_MODULE_APP, "Custom DS-TWR Initiator SEQ NUM %u\r\n", seq_num); |
| | | LOG_INFO(TRACE_MODULE_APP, "Custom DS-TWR Initiator SEQ NUM %u\r\n", ranging_env.range_data.sequence_num); |
| | | } |
| | | LOG_INFO(TRACE_MODULE_APP, "[TX][%u] Poll %s\r\n", ind->tx_len, ind->status == UWB_TX_OK ? "" : "TX Fail"); |
| | | } |
| | |
| | | { |
| | | LOG_INFO(TRACE_MODULE_APP, "[TX][%u] Final\r\n", ind->tx_len); |
| | | |
| | | // calculate_first_tap_power(1, 1); |
| | | // print_preamble_chest(1, 1); |
| | | // print_sts_ch_taps(1); |
| | | // calculate_first_tap_power(0, 1); |
| | | // print_preamble_chest(ranging_env.range_data.sequence_num, 0, 1); |
| | | // print_sts_ch_taps(0, 1); |
| | | } |
| | | else if (ind->ranging_stage == RANGING_RESULT) |
| | | { |
| | |
| | | LOG_INFO(TRACE_MODULE_APP, "[RX][%u][%d] Poll\r\n", ind->rx_len, ranging_env.main_ant_id); |
| | | // LOG_INFO(TRACE_MODULE_APP, "[RX]Peer Tx Power Level %d\r\n", usr_pkt->msg.poll_msg[MSG_POLL_TX_PWR_IDX]); |
| | | |
| | | int32_t freq_offset = phy_freq_offset_get(); |
| | | int32_t freq_offset_filter = average_filter(freq_offset); |
| | | LOG_INFO(TRACE_MODULE_APP, "CH Freq Offset %d\r\n", freq_offset_filter); |
| | | #if XTAL_AUTO_TUNE_EN |
| | | int32_t ppm = freq_offset_filter / (int32_t)(ch_center_freq_map[uwb_app_config.ppdu_params.ch_num] * 1e-6); |
| | | calib_xtal38m4_load_cap_auto_tune(ppm); |
| | | #endif |
| | | #if USER_DEFINED_DATA_REPORT_EN |
| | | uint8_t user_data_len = (uint8_t)(ind->rx_len - MSG_HEADER_LEN - MSG_POLL_USER_DATA_IDX); |
| | | if (user_data_len) |
| | |
| | | uint32_t distance = (uint32_t)(tof_f * 0.299702547 * VP_VAL - RANGING_CORR); |
| | | |
| | | // update distance result |
| | | struct RANGING_MEASUREMENT_T *range_result = &ranging_env.range_data.measurements[0]; |
| | | struct TWR_MEASUREMENT_T *range_result = &ranging_env.range_data.measurements[0]; |
| | | range_result->status = STATUS_OK; |
| | | range_result->distance = (uint16_t)distance; |
| | | |
| | |
| | | uint8_t gaps_num = usr_pkt->msg.final_msg[MSG_FINAL_GAPS_NUM_IDX(ranging_env.responder_slot_idx)]; |
| | | uint8_t gaps[CIR_LEN / CE_WIN - 1]; |
| | | memcpy(gaps, &usr_pkt->msg.final_msg[MSG_FINAL_GAPS_IDX(ranging_env.responder_slot_idx)], (CIR_LEN / CE_WIN - 1)); |
| | | debug_csi.ranging_fom = ranging_fom_calculate(&debug_csi, fap_valid, gaps, gaps_num); |
| | | debug_csi.ranging_fom = ranging_fom_calculate(&debug_csi, 0, fap_valid, gaps, gaps_num); |
| | | #endif |
| | | |
| | | LOG_INFO(TRACE_MODULE_APP, "Poll-FoM %d, Response-FoM %d Final-FoM %d, Poll-NLoS %d, Response-NLoS %d Final-NLoS %d\r\n", |
| | | ranging_env.frame[0].fom, FoM, ranging_env.frame[1].fom, ranging_env.frame[0].NLoS, NLoS, ranging_env.frame[1].NLoS); |
| | | LOG_INFO(TRACE_MODULE_APP, "FoM %d-%d-%d, NLoS %d-%d-%d\r\n", ranging_env.frame[0].fom, FoM, ranging_env.frame[1].fom, |
| | | ranging_env.frame[0].NLoS, NLoS, ranging_env.frame[1].NLoS); |
| | | |
| | | range_result->NLoS = MAX(NLoS, MAX(ranging_env.frame[0].NLoS, ranging_env.frame[1].NLoS)); |
| | | |
| | |
| | | LOG_INFO(TRACE_MODULE_APP, "RSSI: %ddBm, SNR: %ddB \r\n", ind->rssi, ind->snr); |
| | | #endif |
| | | |
| | | // calculate_first_tap_power(2, 2); |
| | | // print_preamble_chest(2, 2); |
| | | // print_sts_ch_taps(2); |
| | | int32_t freq_offset = phy_freq_offset_get(); |
| | | int32_t freq_offset_filter = average_filter(freq_offset); |
| | | LOG_INFO(TRACE_MODULE_APP, "CH Freq Offset %d\r\n", freq_offset_filter); |
| | | |
| | | #if (X38M4_AUTO_TUNE_EN == 1) |
| | | int32_t ppm = freq_offset_filter / (int32_t)(ch_center_freq_map[uwb_app_config.ppdu_params.ch_num] * 1e-6); |
| | | calib_xtal38m4_load_cap_auto_tune(ppm); |
| | | #endif |
| | | // calculate_first_tap_power(0, 2); |
| | | // print_preamble_chest(ranging_env.range_data.sequence_num, 0, 2); |
| | | // print_sts_ch_taps(0, 2); |
| | | } |
| | | #if RANGING_RESULT_REPORT_EN |
| | | else if (ind->ranging_stage == RANGING_RESULT) |
| | |
| | | if (ranging_env.initiator_result_flag & (1 << responder_idx)) |
| | | { |
| | | uint16_t distance = READ_SHORT(&usr_pkt->msg.result_msg[2]); |
| | | LOG_INFO(TRACE_MODULE_APP, |
| | | "Address %X, Distance %ucm, Poll-FoM %d, Response-FoM %d Final-FoM %d, Poll-NLoS %d, Response-NLoS %d Final-NLoS %d\r\n", |
| | | responder_addr, distance, usr_pkt->msg.result_msg[4], ranging_env.frame[responder_idx].fom, usr_pkt->msg.result_msg[6], |
| | | usr_pkt->msg.result_msg[5], ranging_env.frame[responder_idx].NLoS, usr_pkt->msg.result_msg[7]); |
| | | LOG_INFO(TRACE_MODULE_APP, "Address %X, Distance %ucm, FoM %d-%d-%d, NLoS %d-%d-%d\r\n", responder_addr, distance, |
| | | usr_pkt->msg.result_msg[4], ranging_env.frame[responder_idx].fom, usr_pkt->msg.result_msg[6], usr_pkt->msg.result_msg[5], |
| | | ranging_env.frame[responder_idx].NLoS, usr_pkt->msg.result_msg[7]); |
| | | } |
| | | } |
| | | #endif |
| | |
| | | else |
| | | { |
| | | LOG_INFO(TRACE_MODULE_APP, "UWB RX fail 0x%04x\r\n", ind->status); |
| | | // print_preamble_chest(ranging_env.range_data.sequence_num, 0, 2); |
| | | } |
| | | } |
| | | break; |