zhangbo
2025-03-14 4ac8869c86534136e97ed4bf738a83e65cdefafa
keil/include/drivers/mk_phy.h
@@ -52,7 +52,7 @@
#define PHY_PAYLOAD_LEN_MAX 1023
#endif
/** us to PHY timer count converter, x <= 3,441,480 us */
/** us to PHY timer count converter, x <= 34,414,802 us */
#define US_TO_PHY_TIMER_COUNT(x) ((x)*1248U / 10U)
/** ms to PHY timer count converter x <= 34,414 ms */
#define MS_TO_PHY_TIMER_COUNT(x) ((x)*124800U)
@@ -66,11 +66,13 @@
/** PHY timer count to MAC timer count converter */
#define PHY_TIMER_COUNT_TO_MAC_TIMER_COUNT(x) ((x) >> 1)
/** ms to MAC timer count converter x <= 68,829 ms */
#define MS_TO_MAC_TIMER_COUNT(x) ((x)*62400U)
/** RSTU to PHY timer count converter, x <= 41,297,762 RSTU */
#define RSTU_TO_PHY_TIMER_COUNT(x) ((x)*104U)
/** RSTU to us converter, x <= 429,496,729 RSTU */
/** RSTU to us converter */
#define RSTU_TO_US(x) ((x)*10U / 12U)
/** RSTU to ms converter */
#define RSTU_TO_MS(x) ((x) / 1200U)
@@ -86,11 +88,8 @@
/** sleep count to PHY timer count converter */
#define SLEEP_COUNT_TO_PHY_TIMER_COUNT(x) ((uint32_t)((float)(x) * (124800000.0f / 32768.0f)))
/** The maximum sleep time of PHY, 10s */
#define PHY_SLEEP_TIME_MS_MAX (10000U)
/** The minimum sleep time of PHY, 2000us */
#define PHY_SLEEP_TIME_US_MIN (2000U)
/** PHY timer count to sleep count converter */
#define PHY_TIMER_COUNT_TO_SLEEP_COUNT(x) ((uint32_t)((float)(x) * (32768.0f / 124800000.0f)))
/// Low power mode clock drift compensation for phy timer count, p = ppm, t = interval(ms)
#define LPM_PPM_COMPENSATION(p, t) ((p)*2 * (t)*1248 / 10000)
@@ -199,6 +198,7 @@
    PHY_IDLE = 0,
    PHY_TX = 1,
    PHY_RX = 2,
    PHY_TRX = 3,
};
/** PHY protocol data unit parameters */
@@ -219,6 +219,7 @@
    uint8_t sts_seglen;
    uint8_t rx_ant_id;
    uint8_t fcs_type;
    uint8_t pulse_shape;
};
/** STS key configuration*/
@@ -318,6 +319,12 @@
 * @return 0 represent intialization successful
 */
int phy_init(enum IRQ_PRIORITY_LEVEL_T priority);
/**
 * @brief De-initialize PHY, disable PHY interrupt.
 * @return 0 represent de-intialization successful
 */
int phy_deinit(void);
/**
 * @brief Register PHY interrupt callback function.
@@ -458,8 +465,15 @@
int phy_timer_close(void);
/**
 * @brief Calculate time duation from start to end.
 * @param[in] start             Start time (124.8MHz clock)
 * @param[in] end               End time (124.8MHz clock)
 */
uint32_t phy_time_gap(uint32_t start, uint32_t end);
/**
 * @brief Set a target time for the PHY timer.
 * @param[in] target            Target time (124.8MHz clock).
 * @param[in] target            Target time (124.8MHz clock)
 * @param[in] callback          Callback function for the target time
 */
void phy_timer_target_set(uint32_t target, drv_callback_t callback);
@@ -482,6 +496,7 @@
 */
uint32_t phy_timer_count_left(void);
uint32_t phy_timer_lp_tick_left(void);
/**
 * @brief Pause the PHY timer.
 */
@@ -561,6 +576,39 @@
 */
void enter_debug_mode(void);
/**
 * @brief Enable antenna port switching based on AGC gain
 * @param[in] en                    Enable or disable
 * @param[in] rf_gain               LNA gain
 * @param[in] bb_gain               Filter gain
 * @return Rx antenna ID
 */
uint8_t phy_rx_ant_sw(uint8_t en, uint8_t rf_gain, uint8_t bb_gain);
/**
 * @brief Set AGC threshold
 * @param[in] high_th               AGC high threshold
 * @param[in] low_th                AGC low threshold
 */
void phy_agc_th_set(uint8_t high_th, uint8_t low_th);
/**
 * @brief Set CE configuration
 * @param[in] sym_per_blk           symbol per block
 * @param[in] bd_th                 preamble detection threshold
 * @param[in] ce_avg                CE average index
 * @param[in] ce_start              CE start symbol
 */
void phy_preamble_ce_set(uint16_t sym_per_blk, uint32_t bd_th, uint8_t ce_avg, uint8_t ce_start);
/**
 * @brief Set preamble code index
 * @param[in] work_mode             PHY_TX mode or PHY_RX mode
 * @param[in] code_idx              Preamble code index
 * @return 0: sucess, -1: error
 */
int phy_preamble_code_idx_set(enum PHY_WORK_MODE_T work_mode, uint8_t code_idx);
#ifdef __cplusplus
}
#endif