From e328ebef585cea2351b37117b2d5ac4978ecd3c0 Mon Sep 17 00:00:00 2001
From: WXK <287788329@qq.com>
Date: 星期二, 11 二月 2025 14:57:23 +0800
Subject: [PATCH] 1111111

---
 keil/include/drivers/mk_uwb.c |   47 ++++++++++++++++++++++++++++++++---------------
 1 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/keil/include/drivers/mk_uwb.c b/keil/include/drivers/mk_uwb.c
index e7b82ee..588dbd6 100644
--- a/keil/include/drivers/mk_uwb.c
+++ b/keil/include/drivers/mk_uwb.c
@@ -50,7 +50,7 @@
 #include "board.h"
 
 #ifndef RSSI_EN
-#define RSSI_EN 0
+#define RSSI_EN (0)
 #endif
 
 // single tone power range: -20dBm ~ 10dBm, step: 0.5dB (+/-0.2dB); tx power = -20dBm + 0.5 * power_level (+/- 1.5dB).
@@ -137,42 +137,41 @@
 static const uint8_t (*power_table)[5] = power_table_CH9;
 
 extern int16_t ranging_ant_delays_get(uint8_t ant_idx);
-extern void ranging_ant_delays_set(uint8_t ant_idx, int16_t delay_ps);
-extern int pdoa_ant_delays_get(int16_t *delays, uint8_t rx_ant_num);
-extern int pdoa_ant_delays_set(int16_t *delays, uint8_t rx_ant_num);
-extern int pdoa_ant_space_set(int16_t ant_space);
-extern int pdoa_gain_set(int16_t *gain, uint8_t rx_ant_num);
-extern int pdoa_angle_offset_set(int16_t *angle_offset);
-
 __WEAK int16_t ranging_ant_delays_get(uint8_t ant_idx)
 {
     return 0;
 }
 
+extern void ranging_ant_delays_set(uint8_t ant_idx, int16_t delay_ps);
 __WEAK void ranging_ant_delays_set(uint8_t ant_idx, int16_t delay_ps)
 {
 }
 
+extern int pdoa_ant_delays_get(int16_t *delays, uint8_t rx_ant_num);
 __WEAK int pdoa_ant_delays_get(int16_t *delays, uint8_t rx_ant_num)
 {
     return 0;
 }
 
+extern int pdoa_ant_delays_set(int16_t *delays, uint8_t rx_ant_num);
 __WEAK int pdoa_ant_delays_set(int16_t *delays, uint8_t rx_ant_num)
 {
     return 0;
 }
 
+extern int pdoa_ant_space_set(int16_t ant_space);
 __WEAK int pdoa_ant_space_set(int16_t ant_space)
 {
     return 0;
 }
 
+extern int pdoa_gain_set(int16_t *gain, uint8_t rx_ant_num);
 __WEAK int pdoa_gain_set(int16_t *gain, uint8_t rx_ant_num)
 {
     return 0;
 }
 
+extern int pdoa_angle_offset_set(int16_t *angle_offset);
 __WEAK int pdoa_angle_offset_set(int16_t *angle_offset)
 {
     return 0;
@@ -196,14 +195,18 @@
     mac_init(IRQ_PRIORITY_HIGH, 3, 3, PHY_PAYLOAD_LEN_MAX);
 #endif
 
+#ifdef XIP_EN
+    mac_ifs_set(PHY_LIFS_PERIOD_MACCLK_LONG, PHY_SIFS_PERIOD_MACCLK_LONG);
+#endif
+
 #if RSSI_EN
     mac_rssi_calculation_en(1);
 #endif
 
-    phy_init(IRQ_PRIORITY_NORMAL);
+    phy_init(IRQ_PRIORITY_NONE);
 
     phy_timer_open(1, IRQ_PRIORITY_HIGH);
-
+    
     LOG_INFO(TRACE_MODULE_DRIVER, "uwb_open\r\n");
     return 0;
 }
@@ -234,9 +237,6 @@
     {
         // lna scan dis
         REG_WRITE(0x40000628, (1 << 6) | rx_ant_code[antenna_idx & 0x03]);
-#ifndef RADAR_EN
-        LOG_INFO(TRACE_MODULE_DRIVER, "Open ANT%d\r\n", antenna_idx & 0x03);
-#endif
     }
 }
 
@@ -301,6 +301,19 @@
     {
         // low band
         power_table = power_table_CH2;
+    }
+}
+
+void uwb_pulse_shape_set(uint8_t pulse_shape)
+{
+    uint32_t value = REG_READ(0x40000404) & ~(0x3U << 16);
+    if (pulse_shape)
+    {
+        REG_WRITE(0x40000404, value | (0x01 << 16));
+    }
+    else
+    {
+        REG_WRITE(0x40000404, value);
     }
 }
 
@@ -424,7 +437,11 @@
 {
     // RF config
     uwb_channel_switch(ppdu_params->ch_num);
+    // Pulse shape
+    uwb_pulse_shape_set(ppdu_params->pulse_shape);
+    // Antenna
     uwb_rx_antenna_open((enum UWB_RX_ANT_T)ppdu_params->rx_ant_id);
+    LOG_INFO(TRACE_MODULE_DRIVER, "Open ANT%d\r\n", ppdu_params->rx_ant_id & 0x03);
 
     // Generate PHY configuration
     void *sets_a = phy_params_generate(mode, HIGH_PERFORMANCE_MODE_EN, ppdu_params, NULL);
@@ -529,17 +546,17 @@
     {
     }
 
+    uint32_t lock = int_lock();
     if ((REG_READ(0x40000400) & 0x0f) == 7)
     {
-        uint32_t lock = int_lock();
         uint32_t ts = phy_timer_count_get() + 250; /* 2us timeout */
         REG_WRITE(0x40000408, ts);                 /* cfg the rx timeout */
         if (int_rpt_dis)
         {
             mac_current_rx_report_discard();
         }
-        int_unlock(lock);
     }
+    int_unlock(lock);
 }
 
 void uwb_tx_carrier_only(uint8_t on, uint8_t ch_num, uint8_t tx_power_level)

--
Gitblit v1.9.3