keil/include/components/app/src/ranging_simple_task.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.
@@ -46,7 +46,7 @@
#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"
@@ -62,7 +62,6 @@
        return;
    }
#if KF_EN
    float post_range, post_azimuth, post_elevation;
    float azimuth_meas = mk_q7_to_f32(*azimuth);
    float elevation_meas = mk_q7_to_f32(*elevation);
@@ -92,19 +91,6 @@
    // LOG_INFO(TRACE_MODULE_APP, "$%u %u %d %d %d %d;\r\n", (uint16_t)(range_meas*100),(uint16_t)(post_range*100),(int16_t)azimuth_meas,(int16_t)post_azimuth,
    // (int16_t)elevation_meas, (int16_t)post_elevation);
#else
    float post_range, post_azimuth;
    int azimuth_meas = mk_q7_to_s16(*azimuth);
    float range_meas = (float)*distance;
    // call filter
    loc_post_filter(0, range_meas, azimuth_meas, &post_range, &post_azimuth);
    // update distance
    *distance = (uint16_t)(post_range);
    // update angle
    *azimuth = mk_f32_to_q7(post_azimuth);
    // LOG_INFO(TRACE_MODULE_APP, "$%u %u %d %d;\r\n", (uint16_t)(range_meas*100), (uint16_t)(post_range*100),(int16_t)azimuth_meas, (int16_t)post_azimuth);
#endif
}
#endif
@@ -146,6 +132,12 @@
            {
                const struct UWB_PKT_TX_DONE_IND_T *ind = (const struct UWB_PKT_TX_DONE_IND_T *)param;
                uint8_t flag_print = 1;
                if (ind->status != UWB_TX_OK)
                {
                    LOG_INFO(TRACE_MODULE_APP, "UWB TX fail  0x%04x\r\n", ind->status);
                    break;
                }
                switch (ind->ranging_stage)
                {
@@ -268,15 +260,7 @@
                    if (ind->ranging_stage == RANGING_POLL)
                    {
                        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
                        struct RANGING_MEASUREMENT_T *range_result = &ranging_env.range_data.measurements[0];
                        struct TWR_MEASUREMENT_T *range_result = &ranging_env.range_data.measurements[0];
                        uint8_t NLoS, FoM;
                        ranging_fom_get(&NLoS, &FoM);
                        range_result->NLoS = NLoS;
@@ -328,16 +312,20 @@
                            double tof_f = (double)TIMESTAMP_UNIT_TO_NS(ranging_env.tof);
                            struct RANGING_MEASUREMENT_T *range_result = &ranging_env.range_data.measurements[0];
                            struct TWR_MEASUREMENT_T *range_result = &ranging_env.range_data.measurements[0];
                            // update distance result
                            range_result->distance = (uint16_t)(tof_f * 0.299702547 * VP_VAL - RANGING_CORR);
                            range_result->status = STATUS_OK;
                            if (ranging_frame_type_get() == SP1)
                            if (uwb_app_config.ppdu_params->sts_pkt_cfg != SP0)
                            {
                                range_result->status = sts_valid_check() ? STATUS_OK : STATUS_FAILED;
                            }
                            else
                            {
                                range_result->status = STATUS_OK;
                            }
                            // STS valid
                            if (range_result->status == STATUS_OK)
                            {
@@ -348,9 +336,9 @@
#if PDOA_PRINT_EN
                                float pdoa[3];
                                pdoa[0] = pdoa_select_get(0, 3);
                                pdoa[1] = pdoa_select_get(1, 3);
                                pdoa[2] = pdoa_select_get(2, 3);
                                pdoa[0] = pdoa_result_get(0, 3);
                                pdoa[1] = pdoa_result_get(1, 3);
                                pdoa[2] = pdoa_result_get(2, 3);
                                LOG_INFO(TRACE_MODULE_APP, "PDOA: %f %f %f\r\n", pdoa[0], pdoa[1], pdoa[2]);
                                // float *sts_rssi = sts_rssi_output_get();
@@ -401,14 +389,6 @@
                                    range_result->NLoS = NLoS;
                                }
                                // LOG_INFO(TRACE_MODULE_APP, "NLoS: %u, FoM: %u\r\n", NLoS, FoM);
#if CSI_EN
                                struct RANGING_TAPS_INF_T taps_inf;
                                ranging_taps_inf_get(&taps_inf);
                                LOG_INFO(TRACE_MODULE_APP, "fap: %d, %f\r\n", taps_inf.fap_loc, taps_inf.fap_pow);
                                LOG_INFO(TRACE_MODULE_APP, "tap1: %d, %f\r\n", taps_inf.tap1_loc, taps_inf.tap1_pow);
                                LOG_INFO(TRACE_MODULE_APP, "tap2: %d, %f\r\n", taps_inf.tap2_loc, taps_inf.tap2_pow);
                                LOG_INFO(TRACE_MODULE_APP, "tap3: %d, %f\r\n", taps_inf.tap3_loc, taps_inf.tap3_pow);
#endif
                                // output result
                                uwbapi_report_ranging_data(range_data);
@@ -422,6 +402,14 @@
                        {
                            LOG_INFO(TRACE_MODULE_APP, "Timestamp error\r\n");
                        }
                        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
                        int32_t ppm = freq_offset_filter / (int32_t)(uwb_ch_freq_table[uwb_app_config.ppdu_params->ch_num] * 1e-6);
                        calib_xtal38m4_load_cap_auto_tune(ppm);
#endif
                    }
                }
                else