From a530ab24b02bce971aed98c9bcc1e05c0ccf7899 Mon Sep 17 00:00:00 2001
From: chen <15335560115@163.com>
Date: 星期四, 14 十一月 2024 18:24:36 +0800
Subject: [PATCH] 更改UWB基站配置

---
 keil/uwb_app.c |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 50 insertions(+), 5 deletions(-)

diff --git a/keil/uwb_app.c b/keil/uwb_app.c
index 968c6d6..2be8e51 100644
--- a/keil/uwb_app.c
+++ b/keil/uwb_app.c
@@ -5,6 +5,7 @@
 #include "mk_power.h"
 #include "mk_sleep_timer.h"
 #include "lib_ranging.h"
+#include "lib_aoa.h"
 #include "dw_app_anchor.h"
 #include "global_param.h"
 #include "board.h"
@@ -98,7 +99,17 @@
     uint8_t phy_work_mode; /* PHY_TX / PHY_RX / PHT_TX|PHY_RX */
     struct UWB_CONFIG_T phy_cfg;
 };
-
+/* 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,
+};
 ///* Default communication configuration. */
 //static struct mk_uwb_configure config = {//原来的基站非110k代码
 //    .phy_work_mode = (uint8_t)(PHY_TX | PHY_RX),
@@ -115,6 +126,7 @@
 //    .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                       */
 //};
+#ifndef STS_MODE
 static struct mk_uwb_configure config = {
     .phy_work_mode = (uint8_t)(PHY_TX | PHY_RX),
     .phy_cfg.ch_num = 5,                      /* Channel number.                           */
@@ -130,6 +142,23 @@
     .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                       */
 };
+#else
+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                       */
+};
+#endif
 /* Buffer to store received frame */
 
 /*     Frames used in the ranging process
@@ -376,6 +405,10 @@
 uint16_t uwb_searchcount;
 uint8_t flag_recsuccess;
 uint8_t flag_temp2,flag_temp1;
+ uint8_t valid_sts = 0;
+int16_t elevation = 0;
+int16_t azimuth = 0;
+uint8_t fom = 0;
 extern uint8_t g_start_send_flag,search_open_flag = 1,link_success_flag,flag_secondtask;
 int UwbRange(void)
 {
@@ -504,32 +537,44 @@
 //主函数绑定接受逻辑
 int UwbSearch(void)
 {
-
     uint8_t i;
     uint16_t tempid;
     // The following peripherals will be initialized in the uwb_open function
     // phy/mac/aes/lsp/phy timers initialized
     uwb_open();
+  // Set STS key and IV
+    phy_sts_key_configure(&sts_iv_key);
+	
+	// which RX ports will be used for AoA/PDoA
+    phy_rx_ant_mode_set(RX_ANT_PORTS_COMBINATION);
 
     // Set calibration parameters
     uwb_calibration_params_set(config.phy_cfg.ch_num);
 
-    // set advanced parameters
+   // set advanced parameters
     struct PHY_ADV_CONFIG_T adv_config = {
         .thres_fap_detect = 40,
         .nth_scale_factor = 4,
-        .ranging_performance_mode = 0,
+        .ranging_performance_mode = 3,
         .skip_weakest_port_en = 0,
     };
     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);
-
+		
+		ranging_lib_init();
     ranging_frame_type_set(config.phy_cfg.sts_pkt_cfg);
+		
+		aoa_aux_info_set(AOA_AUX_ANT_IQ_RSSI_PDOA_AOA_FOM);
+    aoa_steering_vector_set((const float *)((uint32_t)((config.phy_cfg.ch_num == 9) ? svec_ch9_ptr : svec_ch5_ptr) | SRAM_BASE));
 
+    aoa_param_config();
+		
+		phy_rx_sts_switch_mode_set(config.phy_cfg.sts_pkt_cfg, STS_SWITCH_EVERY_4SYM, 0, 0);
     // Register rx interrupt callback function
     mac_register_process_handler(tx_int_callback, rx_int_callback);
+		
     receive_flag = 0;
     temp_count3=phy_timer_count_get();
     gpio_pin_set(SCL_PIN);

--
Gitblit v1.9.3