From 15b206e26c18916b34578ae1521cc13274fb8340 Mon Sep 17 00:00:00 2001
From: chen <15335560115@163.com>
Date: 星期五, 27 六月 2025 18:49:04 +0800
Subject: [PATCH] 加入delay去掉进入休眠打印(会导致无法休眠),lora加mk进入休眠功耗16ua左右

---
 keil/include/components/app/src/ranging_fira.c |  134 +++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 131 insertions(+), 3 deletions(-)

diff --git a/keil/include/components/app/src/ranging_fira.c b/keil/include/components/app/src/ranging_fira.c
index 0502ed5..beb9436 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);
 
 //------------------------------------------------------------------------------
@@ -132,15 +136,19 @@
 
 // This function will be called by uwbapi_session_init()
 void app_session_init(void)
-{
+{			
+	#ifdef MY_MODE
+			normal_uwb_change_to_fira();
+	#endif
     // register process handler for MAC TX done and RX done
     mac_register_process_handler(ranging_tx_process, ranging_rx_process);
+		uwbs_handler_init(&op);
 
-    uwbs_handler_init(&op);
 }
 
 void ranging_configure(void)
-{
+{		
+		
     fira_keys_generate();
 
     aes_update_key(AES_ID0, &fira_key.devPayKey.ukey.keyByte[0]);
@@ -236,7 +244,124 @@
     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
 
+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);
+}
+uint8_t normal_flag=0;
+void uwb_normal_init(void)
+{
+Uwb_init();	
+}
+void fira_uwb_change_to_normal(void)
+{
+//uwb_close();
+	CloseUWB();
+uwb_normal_init();
+	OpenUWB();
+normal_flag=1;	
+}
+void normal_uwb_change_to_fira(void)//少个回调设置
+{
+//uwb_close();
+	CloseUWB();
+uwb_fira_init();
+normal_flag=0;
+}
 void ranging_start(void)
 {
     ranging_env.enable = 1;
@@ -281,6 +406,9 @@
 void ranging_stop(void)
 {
     ranging_env.enable = 0;
+	#ifdef MY_MODE
+		fira_uwb_change_to_normal();//变为normal配置的uwb
+	#endif
     ranging_monitor_stop();
     LOG_INFO(TRACE_NO_REPORT_HOST | TRACE_MODULE_APP, "Ranging stop\r\n");
 }

--
Gitblit v1.9.3