| | |
| | | /* |
| | | * Copyright (c) 2019-2023 Beijing Hanwei Innovation Technology Ltd. Co. and |
| | | * Copyright (c) 2019-2025 Beijing Hanwei Innovation Technology Ltd. Co. and |
| | | * its subsidiaries and affiliates (collectly called MKSEMI). |
| | | * |
| | | * All rights reserved. |
| | |
| | | |
| | | #include "board.h" |
| | | |
| | | #if FILTER_EN |
| | | #define KF_SUPPORT_NUM 6 |
| | | #define KF_TIMEOUT_MS 2000 |
| | | static struct KF_MAC_ADDR_T kf_mac_addr_cache[KF_SUPPORT_NUM]; |
| | | static struct KF_CHANNEL_CACHE_T kf_channel_cache[KF_SUPPORT_NUM]; |
| | | static struct KF_MAT_VALUE_CACHE_T kf_mat_value_cache[KF_SUPPORT_NUM]; |
| | | #endif |
| | | |
| | | #if PDOA_3D_EN |
| | | #define PDOA_3D_SUPPORT_NUM 100 |
| | | #define PDOA_3D_SUPPORT_NUM 10 |
| | | #define PDOA_3D_TIMEOUT_MS 2000 |
| | | static struct PDOA_3D_MAC_ADDR_T mac_addr_cache[PDOA_3D_SUPPORT_NUM]; |
| | | static struct PDOA_3D_PDOA_DATA_T pdoa_data_cache[PDOA_3D_SUPPORT_NUM]; |
| | |
| | | |
| | | if (uwb_app_config.session_param.device_role == DEV_ROLE_INITIATOR) |
| | | { |
| | | phy_rx_sts_switch_mode_set(uwb_app_config.ppdu_params.sts_pkt_cfg, STS_NEVER_SWITCH, 0, 0); |
| | | phy_rx_sts_switch_mode_set(uwb_app_config.ppdu_params->sts_pkt_cfg, STS_NEVER_SWITCH, 0, 0); |
| | | } |
| | | else |
| | | { |
| | | phy_rx_sts_switch_mode_set(uwb_app_config.ppdu_params.sts_pkt_cfg, STS_SWITCH_EVERY_4SYM, 0, 0); |
| | | phy_rx_sts_switch_mode_set(uwb_app_config.ppdu_params->sts_pkt_cfg, STS_SWITCH_EVERY_4SYM, 0, 0); |
| | | } |
| | | |
| | | #if (ANT_PATTERN == ANT_PATTERN_SQUARE) |
| | | struct AOA_ANGLE_SPAN_T aoa_span; |
| | | angle_span_t aoa_span; |
| | | #if AOA_3D_EN |
| | | aoa_span.Ndim = 2; |
| | | aoa_span.el_low = 0; |
| | |
| | | #endif |
| | | |
| | | #if AOA_EN |
| | | aoa_aux_info_set(AOA_AUX_ANT_IQ_RSSI_PDOA_AOA_FOM); |
| | | aoa_steering_vector_set((const float *)((uint32_t)((uwb_app_config.ppdu_params.ch_num == 9) ? svec_ch9_ptr : svec_ch5_ptr) | SRAM_BASE)); |
| | | sts_param_config(uwb_app_config.ppdu_params->sts_pkt_cfg, STS_AUX_ANT_IQ_RSSI_PDOA_AOA_FOM, STS_BUF_NUM, STS_BUF_SIZE); |
| | | aoa_steering_vector_set((const float *)((uint32_t)((uwb_app_config.ppdu_params->ch_num == 9) ? svec_ch9_ptr : svec_ch5_ptr) | SRAM_BASE)); |
| | | #else |
| | | aoa_aux_info_set(AOA_AUX_ANT_IQ_RSSI); |
| | | sts_param_config(uwb_app_config.ppdu_params->sts_pkt_cfg, STS_AUX_ANT_IQ_RSSI, STS_BUF_NUM, STS_BUF_SIZE); |
| | | #endif |
| | | |
| | | aoa_param_config(); |
| | | |
| | | #if PDOA_3D_EN |
| | | pdoa_3d_param_config(ANT_PATTERN, ANT_LAYOUT, PDOA_3D_AMBIGUITY_LEVEL_HIGH, mac_addr_cache, pdoa_data_cache, PDOA_3D_SUPPORT_NUM, PDOA_3D_TIMEOUT_MS); |
| | | pdoa_3d_param_config(ANT_PATTERN, ANT_LAYOUT, PDOA_3D_AMBIGUITY_LEVEL_NONE, mac_addr_cache, pdoa_data_cache, PDOA_3D_SUPPORT_NUM, PDOA_3D_TIMEOUT_MS); |
| | | #endif |
| | | |
| | | #if FILTER_EN |
| | | if (uwb_app_config.filter_en) |
| | | { |
| | | loc_post_filter_config(uwb_app_config.session_param.ranging_interval, 0, 1); |
| | | uint32_t update_period_ms = uwb_app_config.session_param.ranging_interval; |
| | | loc_post_kf_config(update_period_ms, kf_mac_addr_cache, kf_channel_cache, kf_mat_value_cache, KF_SUPPORT_NUM, KF_TIMEOUT_MS); |
| | | } |
| | | #endif |
| | | } |
| | |
| | | aoa_env.sequence_num++; |
| | | if (uwb_app_config.session_param.device_role == DEV_ROLE_INITIATOR) |
| | | { |
| | | // Power on radio |
| | | power_on_radio(1, 0); |
| | | |
| | | // SP3 payload len = 0 |
| | | mac_tx(EVT_MODE_MAC_ASAP_PHY_FIX, aoa_env.anchor_point, 0, NULL, 0); |
| | | mac_start(); |
| | | uwb_tx(NULL, 0, TX_MODE_DEFER, aoa_env.anchor_point); |
| | | |
| | | LOG_INFO(TRACE_MODULE_APP, "AoA Initiator SEQ NUM %u\r\n", aoa_env.sequence_num); |
| | | } |
| | |
| | | { |
| | | // Change Rx main antenna |
| | | uint8_t main_ant = 3; |
| | | phy_rx_sts_switch_mode_set(uwb_app_config.ppdu_params.sts_pkt_cfg, STS_SWITCH_EVERY_4SYM, 1, main_ant); |
| | | aoa_param_update(main_ant); |
| | | // Power on radio |
| | | power_on_radio(0, 1); |
| | | sts_lsp_store(); |
| | | phy_rx_sts_switch_mode_set(uwb_app_config.ppdu_params->sts_pkt_cfg, STS_SWITCH_EVERY_4SYM, 1, main_ant); |
| | | sts_param_update(main_ant); |
| | | |
| | | if (aoa_env.stage == AOA_SYNC) |
| | | { |
| | | mac_rx(EVT_MODE_MAC_PHY_ASAP, 0, aoa_env.ranging_period); |
| | | uwb_rx(RX_MODE_IMMEDIATE, 0, aoa_env.ranging_period); |
| | | } |
| | | else |
| | | { |
| | | mac_rx(EVT_MODE_MAC_ASAP_PHY_FIX, aoa_env.anchor_point - UWB_RX_OPEN_IN_ADVANCE, UWB_RX_WINDOW); |
| | | uwb_rx(RX_MODE_DEFER, aoa_env.anchor_point - UWB_RX_OPEN_IN_ADVANCE, UWB_RX_WINDOW); |
| | | } |
| | | mac_start(); |
| | | |
| | | LOG_INFO(TRACE_MODULE_APP, "AoA Responder SEQ NUM %u\r\n", aoa_env.sequence_num); |
| | | } |
| | | } |
| | |
| | | |
| | | void aoa_process(const struct MAC_HW_REPORT_T *ind) |
| | | { |
| | | power_off_radio(); |
| | | sts_lsp_store_stop(); |
| | | |
| | | if (uwb_app_config.session_param.device_role == DEV_ROLE_INITIATOR) |
| | | { |
| | | phy_timer_target_set(aoa_env.anchor_point + aoa_env.ranging_period - UWB_EVT_PREFETCH_TIME, aoa_timer_callback); |
| | |
| | | { |
| | | if (ind->err_code == UWB_RX_OK) |
| | | { |
| | | sts_lsp_store_stop(); |
| | | // update anchor point |
| | | aoa_env.anchor_point = ind->timestamp - phy_shr_duration(); |
| | | aoa_env.stage = AOA_POLL; |
| | |
| | | { |
| | | if (aoa_env.stage == AOA_SYNC) |
| | | { |
| | | sts_lsp_store(); |
| | | mac_rx(EVT_MODE_MAC_PHY_ASAP, 0, aoa_env.ranging_period); |
| | | mac_start(); |
| | | uwb_rx(RX_MODE_IMMEDIATE, 0, aoa_env.ranging_period); |
| | | return; |
| | | } |
| | | else |
| | |
| | | } |
| | | phy_timer_target_set(aoa_env.anchor_point + aoa_env.ranging_period - UWB_EVT_PREFETCH_TIME, aoa_timer_callback); |
| | | } |
| | | |
| | | power_off_radio(); |
| | | } |
| | | |
| | | void aoa_done(const struct MAC_HW_REPORT_T *rx) |
| | |
| | | { |
| | | ind->hdr.event = AOA_DONE_MSG; |
| | | ind->status = rx->err_code; |
| | | ind->rssi = rx->rssi; |
| | | ind->snr = rx->snr; |
| | | // ind->rssi = rx->rssi; |
| | | ind->rssi = correct_rssi(rx->rssi); |
| | | ind->snr = correct_snr(rx->snr); |
| | | |
| | | if ((rx->pkt_len) && (rx->pkt_data != NULL)) |
| | | { |