keil/include/components/app/src/ranging_ss_twr.c
@@ -1,5 +1,5 @@
/*
 * 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.
@@ -49,12 +49,12 @@
#include "ranging_ss_twr.h"
#include "lib_aoa.h"
#include "lib_ranging.h"
#if KF_EN
#if FILTER_EN
#include "lib_kf.h"
#endif
// #include "board.h"
#if KF_EN && FILTER_EN
#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];
@@ -141,28 +141,18 @@
    uwbs_configure(PHY_TX | PHY_RX, uwb_app_config.session_param.tx_power_level);
#if CSI_EN
    ranging_aux_out_opt_set(CH_LEN_DEFAULT, 3);
#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 FILTER_EN
    if (uwb_app_config.filter_en)
    {
#if KF_EN
        loc_post_kf_config(uwb_app_config.session_param.ranging_interval, kf_mac_addr_cache, kf_channel_cache, kf_mat_value_cache, KF_SUPPORT_NUM,
                           KF_TIMEOUT_MS);
#else
        loc_post_filter_config(uwb_app_config.session_param.ranging_interval, 1, uwb_app_config.session_param.aoa_result_req);
#endif
        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
@@ -191,14 +181,14 @@
    ranging_env.count_last = 0;
    ranging_env.lost_cnt = 0;
    WsfTimerStartMs(&ranging_cb.daemon_timer, uwb_app_config.session_param.ranging_interval * 10, WSF_TIMER_PERIODIC);
    mk_timer_list_start_timer(&ranging_cb.daemon_timer, uwb_app_config.session_param.ranging_interval * 10, MK_TIMER_PERIODIC);
    LOG_INFO(TRACE_MODULE_APP, "Ranging start, role %d\r\n", dev_role);
}
void ranging_stop(void)
{
    ranging_env.enable = 0;
    WsfTimerStop(&ranging_cb.daemon_timer);
    mk_timer_list_stop_timer(&ranging_cb.daemon_timer);
}
void ranging_restart(void)
@@ -211,7 +201,7 @@
int8_t ranging_tx_power_get(void)
{
    return uwb_tx_power_get(uwb_app_config.ppdu_params.ch_num, uwb_app_config.session_param.tx_power_level);
    return uwb_tx_power_get(uwb_app_config.ppdu_params->ch_num, uwb_app_config.session_param.tx_power_level);
}
void ranging_local_addr_set(uint16_t short_addr)
@@ -262,19 +252,6 @@
    return (user_response_data_len == data_len) ? 0 : 1;
}
// ts_a - ts_b
int64_t ranging_timestamp_diff(int64_t ts_a, int64_t ts_b)
{
    if (ts_a < ts_b)
    {
        return (0x20000000000 - ts_b + ts_a);
    }
    else
    {
        return (ts_a - ts_b);
    }
}
// unit: 15.6ps
int64_t ranging_tround(void)
{
@@ -284,7 +261,7 @@
    int64_t tround = ranging_timestamp_diff(rx_timestamp, tx_timestamp);
    // correct antenna delay
    tround -= ranging_ant_delays_get(uwb_app_config.ppdu_params.rx_ant_id);
    tround -= ranging_ant_delays_get(uwb_app_config.ppdu_params->rx_main_ant);
    return tround;
}
@@ -298,7 +275,7 @@
    int64_t treply = ranging_timestamp_diff(tx_timestamp, rx_timestamp);
    // correct antenna delay
    treply += ranging_ant_delays_get(uwb_app_config.ppdu_params.rx_ant_id);
    treply += ranging_ant_delays_get(uwb_app_config.ppdu_params->rx_main_ant);
    return treply;
}
@@ -615,8 +592,9 @@
        ind->hdr.event = UWB_PKT_RX_DONE_MSG;
        ind->ranging_stage = (uint8_t)stage;
        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);
        ind->rx_len = rx->pkt_len;
@@ -625,6 +603,8 @@
            memcpy(ind->rx_data, rx->pkt_data, rx->pkt_len);
        }
        g_freq_offset = phy_freq_offset_get();
        // Send the message
        WsfMsgSend(ranging_cb.handle_id, ind);
    }