From 67ca69985af9109a0603a1cde71f21b940c059ff Mon Sep 17 00:00:00 2001 From: chen <15335560115@163.com> Date: 星期四, 15 五月 2025 09:12:53 +0800 Subject: [PATCH] 完全将免布线标签代码移植过来版本 --- keil/include/components/app/src/ranging_fira.c | 155 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 154 insertions(+), 1 deletions(-) diff --git a/keil/include/components/app/src/ranging_fira.c b/keil/include/components/app/src/ranging_fira.c index 0502ed5..004015d 100644 --- a/keil/include/components/app/src/ranging_fira.c +++ b/keil/include/components/app/src/ranging_fira.c @@ -105,6 +105,10 @@ static void ranging_tx_process(struct MAC_HW_REPORT_T *tx_report); static void ranging_rx_process(struct MAC_HW_REPORT_T *rx_report); +void normal_uwb_change_to_fira(void); +void fira_uwb_change_to_normal(void); +void uwb_normal_init(void); +void uwb_fira_init(void); void app_session_init(void); //------------------------------------------------------------------------------ @@ -140,7 +144,8 @@ } void ranging_configure(void) -{ +{ + normal_uwb_change_to_fira();//变为fira配置的uwb fira_keys_generate(); aes_update_key(AES_ID0, &fira_key.devPayKey.ukey.keyByte[0]); @@ -236,7 +241,154 @@ LOG_INFO(TRACE_NO_REPORT_HOST | TRACE_MODULE_FIRA, "slot duration %d slots per round %d ranging interval %d\r\n", uwb_app_config.session_param.slot_duration, uwb_app_config.session_param.slots_per_round, uwb_app_config.session_param.ranging_interval); } +struct mk_uwb_configure +{ + uint8_t phy_work_mode; /* PHY_TX / PHY_RX / PHT_TX|PHY_RX */ + struct UWB_CONFIG_T phy_cfg; +}; +#ifdef DW1000 +/* Default communication configuration. */ +static struct mk_uwb_configure config = {//yuan + .phy_work_mode = (uint8_t)(PHY_TX | PHY_RX), + .phy_cfg.ch_num = UWB_CH_NUM, /* Channel number. */ + .phy_cfg.code_index = 9, /* TRX preamble code */ + .phy_cfg.mean_prf = MEAN_PRF_64M, /* Mean prf 64/128/256M */ + .phy_cfg.data_bit_rate = DATA_BR_6M8, /* Data rate 6.8M */ + .phy_cfg.sync_sym = PREAM_LEN_128, /* Preamble duration, length of preamble 128 */ + .phy_cfg.sfd_sym = NON_STD_NSFD5_8, /* Identifier for SFD sequence */ + .phy_cfg.ranging_bit = 1, /* ranging bit set 1 */ + .phy_cfg.trx_mode = TRX_MODE_15_4A, /* IEEE802.15.4z - BPRF mode */ + .phy_cfg.sts_pkt_cfg = STS_PKT_CFG_0, /* SP0 Frame */ + .phy_cfg.sts_segnum = STS_SEGNUM_BPRF_1, /* Number of STS segments in the frame */ + .phy_cfg.sts_seglen = STS_SEGLEN_BPRF_64, /* Number of symbols in an STS segment */ + .phy_cfg.rx_ant_id = UWB_RX_ANT_3, /* UWB RX antenna port */ +}; +#elif defined STS_MODE +static struct mk_uwb_configure config = { + .phy_work_mode = (uint8_t)(PHY_TX | PHY_RX), + .phy_cfg.ch_num = 5, /* Channel number. */ + .phy_cfg.code_index = 9, /* TRX preamble code */ + .phy_cfg.mean_prf = MEAN_PRF_64M, /* Mean prf 64/128/256M */ + .phy_cfg.data_bit_rate = DATA_BR_6M8, /* Data rate 6.8M */ + .phy_cfg.sync_sym = PREAM_LEN_128, /* Preamble duration, length of preamble 128 */ + .phy_cfg.sfd_sym = BPRF_NSFD2_8, /* Identifier for SFD sequence */ + .phy_cfg.ranging_bit = 1, /* ranging bit set 1 */ + .phy_cfg.trx_mode = TRX_MODE_15_4Z_BPRF, /* IEEE802.15.4z - BPRF mode */ + .phy_cfg.sts_pkt_cfg = STS_PKT_CFG_1, /* SP1 Frame */ + .phy_cfg.sts_segnum = STS_SEGNUM_BPRF_1, /* Number of STS segments in the frame */ + .phy_cfg.sts_seglen = STS_SEGLEN_BPRF_64, /* Number of symbols in an STS segment */ + .phy_cfg.rx_ant_id = UWB_RX_ANT_3, /* UWB RX antenna port */ +}; +/* Use the default key and IV specified in the IEEE 802.15.4z attachment */ +static struct UWB_STS_KEY_CONFIG_T sts_iv_key = { + .sts_vcounter = 0x1F9A3DE4, + .sts_vupper0 = 0xD37EC3CA, + .sts_vupper1 = 0xC44FA8FB, + .sts_vupper2 = 0x362EEB34, + .sts_key0 = 0x14EB220F, + .sts_key1 = 0xF86050A8, + .sts_key2 = 0xD1D336AA, + .sts_key3 = 0x14148674, +}; +#else //MKmode +/* Default communication configuration. */ +static struct mk_uwb_configure config = { + .phy_work_mode = (uint8_t)(PHY_TX | PHY_RX), + .phy_cfg.ch_num = 9, /* Channel number. */ + .phy_cfg.code_index = 9, /* TX preamble code. */ + .phy_cfg.mean_prf = MEAN_PRF_64M, /* Data rate 6.8M */ + .phy_cfg.data_bit_rate = DATA_BR_6M8, /* data rate 6.8M. */ + .phy_cfg.sync_sym = PREAM_LEN_128, /* Preamble duration, length of preamble 128 */ + .phy_cfg.sfd_sym = BPRF_NSFD2_8, /* Identifier for SFD sequence */ + .phy_cfg.ranging_bit = 1, /* ranging bit set. */ + .phy_cfg.trx_mode = TRX_MODE_15_4Z_BPRF, /* IEEE802.15.4z - BPRF mode */ + .phy_cfg.sts_pkt_cfg = STS_PKT_CFG_0, /* SP0 Frame */ + .phy_cfg.sts_segnum = STS_SEGNUM_BPRF_1, /* Number of STS segments in the frame */ + .phy_cfg.sts_seglen = STS_SEGLEN_BPRF_64, /* Number of symbols in an STS segment */ + .phy_cfg.rx_ant_id = UWB_RX_ANT_3, /* UWB RX antenna port */ +}; +#endif +uint8_t normal_flag; +void uwb_fira_init(void) +{ + uwb_open(); + // set advanced parameters + struct PHY_ADV_CONFIG_T adv_config = + { + // RPM0: 40, RPM3: 60 + .thres_fap_detect = 60, + // RPM0: 4, RPM3: 8 + .nth_scale_factor = 8, + // RFrame SP0: 0/1, Others: 0/1/2/3 + .ranging_performance_mode = 3, +#if RX_ANT_PORTS_NUM == 4 + .skip_weakest_port_en = 1, +#else + .skip_weakest_port_en = 0, +#endif + }; + phy_adv_params_configure(&adv_config); + + // which RX ports will be used for AoA/PDoA + phy_rx_ant_mode_set(RX_ANT_PORTS_COMBINATION); + + uwbs_init(); + uwb_app_config.ranging_flow_mode = (uint8_t)(RANGING_FLOW_FIRA); + uwb_app_config.filter_en = (uint8_t)(FILTER_EN); + uwb_app_config.session_param.tx_power_level = board_param.tx_power_fcc[CALIB_CH(uwb_app_config.ppdu_params.ch_num)]; + uwb_app_config.ppdu_params.rx_ant_id = (uint8_t)(RX_MAIN_ANT_PORT); +} +void uwb_normal_init(void) +{ + // The following peripherals will be initialized in the uwb_open function + // phy/mac/aes/lsp/phy timers initialized + uwb_open(); +#ifdef STS_MODE + // Set STS key and IV + phy_sts_key_configure(&sts_iv_key); +#endif + // Set calibration parameters + uwb_calibration_params_set(config.phy_cfg.ch_num); +#ifdef STS_MODE + + // set advanced parameters + struct PHY_ADV_CONFIG_T adv_config = { + .thres_fap_detect = 40, + .nth_scale_factor = 4, + .ranging_performance_mode = 3, + .skip_weakest_port_en = 0, + }; +#else + // set advanced parameters + struct PHY_ADV_CONFIG_T adv_config = { + .thres_fap_detect = 40, + .nth_scale_factor = 4, + .ranging_performance_mode = 0, + .skip_weakest_port_en = 0, + }; +#endif + phy_adv_params_configure(&adv_config); + + // uwb configure + uwb_configure(config.phy_work_mode, board_param.tx_power_fcc[CALIB_CH(config.phy_cfg.ch_num)], &config.phy_cfg); +#if (defined STS_MODE) || (defined MK_MODE) + ranging_lib_init(); +#endif + ranging_frame_type_set(config.phy_cfg.sts_pkt_cfg); +} +void fira_uwb_change_to_normal(void) +{ +uwb_close(); +uwb_normal_init(); +normal_flag=1; +} +void normal_uwb_change_to_fira(void) +{ +uwb_close(); +uwb_fira_init(); +normal_flag=0; +} void ranging_start(void) { ranging_env.enable = 1; @@ -281,6 +433,7 @@ void ranging_stop(void) { ranging_env.enable = 0; + fira_uwb_change_to_normal();//变为normal配置的uwb ranging_monitor_stop(); LOG_INFO(TRACE_NO_REPORT_HOST | TRACE_MODULE_APP, "Ranging stop\r\n"); } -- Gitblit v1.9.3