keil/include/components/app/src/ranging_simple.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_simple.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];
@@ -146,12 +146,8 @@
    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 (ANT_PATTERN == ANT_PATTERN_SQUARE)
    struct AOA_ANGLE_SPAN_T aoa_span;
    angle_span_t aoa_span;
    aoa_span.Ndim = 2;
    aoa_span.el_low = 90;
    aoa_span.el_high = 90;
@@ -163,23 +159,17 @@
#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
@@ -219,14 +209,14 @@
    // uint8_t locak_long_addr[8] = {0xa5,0xc6,0x91,0xcd,};
    // uwbs_local_long_addr_set(locak_long_addr);
    // WsfTimerStartMs(&ranging_cb.daemon_timer, TAG_BLINK_PERIOD_MS * 10, WSF_TIMER_PERIODIC);
    // mk_timer_list_start_timer(&ranging_cb.daemon_timer, TAG_BLINK_PERIOD_MS * 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)
@@ -239,7 +229,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)
@@ -279,19 +269,6 @@
    return ranging_env.responder_num;
}
// 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(enum DEV_ROLE_T role, uint8_t dev_idx)
{
@@ -311,7 +288,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;
}
@@ -335,7 +312,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;
}
@@ -979,8 +956,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;