feat(ieee802154): rf enable and disable refactor

This commit is contained in:
zwx 2023-12-11 19:26:06 +08:00 committed by xiaqilin
parent 00cbc1fad2
commit 2f49042b07
4 changed files with 36 additions and 21 deletions

View File

@ -31,7 +31,6 @@
#include "esp_private/esp_clk.h"
#include "esp_private/sleep_retention.h"
#include "esp_private/sleep_modem.h"
static bool s_rf_closed = false;
#if SOC_PM_RETENTION_HAS_CLOCK_BUG
#define IEEE802154_LINK_OWNER ENTRY(3)
#else
@ -39,6 +38,7 @@ static bool s_rf_closed = false;
#endif // SOC_PM_RETENTION_HAS_CLOCK_BUG
#endif // SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE
static bool s_rf_closed = true;
#define CCA_DETECTION_TIME 8
extern void bt_bb_set_zb_tx_on_delay(uint16_t time);
@ -51,10 +51,9 @@ static uint8_t s_rx_index = 0;
static uint8_t s_enh_ack_frame[128];
static uint8_t s_recent_rx_frame_info_index;
static portMUX_TYPE s_ieee802154_spinlock = portMUX_INITIALIZER_UNLOCKED;
static intr_handle_t ieee802154_isr_handle = NULL;
static intr_handle_t s_ieee802154_isr_handle = NULL;
static esp_err_t ieee802154_sleep_init(void);
static void ieee802154_rf_enable(void);
static IRAM_ATTR void event_end_process(void)
{
@ -656,7 +655,7 @@ esp_err_t ieee802154_mac_init(void)
ieee802154_set_state(IEEE802154_STATE_IDLE);
// TODO: Add flags for IEEE802154 ISR allocating. TZ-102
ret = esp_intr_alloc(ieee802154_periph.irq_id, 0, ieee802154_isr, NULL, &ieee802154_isr_handle);
ret = esp_intr_alloc(ieee802154_periph.irq_id, 0, ieee802154_isr, NULL, &s_ieee802154_isr_handle);
ESP_RETURN_ON_FALSE(ret == ESP_OK, ESP_FAIL, IEEE802154_TAG, "IEEE802154 MAC init failed");
ESP_RETURN_ON_FALSE(ieee802154_sleep_init() == ESP_OK, ESP_FAIL, IEEE802154_TAG, "IEEE802154 MAC sleep init failed");
@ -667,8 +666,10 @@ esp_err_t ieee802154_mac_init(void)
esp_err_t ieee802154_mac_deinit(void)
{
esp_err_t ret = ESP_OK;
ret = esp_intr_free(ieee802154_isr_handle);
ieee802154_isr_handle = NULL;
if (s_ieee802154_isr_handle) {
ret = esp_intr_free(s_ieee802154_isr_handle);
s_ieee802154_isr_handle = NULL;
}
return ret;
}
@ -696,7 +697,7 @@ IEEE802154_STATIC void tx_init(const uint8_t *frame)
esp_err_t ieee802154_transmit(const uint8_t *frame, bool cca)
{
ieee802154_rf_enable();
IEEE802154_RF_ENABLE();
ieee802154_enter_critical();
tx_init(frame);
@ -724,7 +725,7 @@ esp_err_t ieee802154_transmit_at(const uint8_t *frame, bool cca, uint32_t time)
{
uint32_t tx_target_time;
uint32_t current_time;
ieee802154_rf_enable();
IEEE802154_RF_ENABLE();
tx_init(frame);
IEEE802154_SET_TXRX_PTI(IEEE802154_SCENE_TX_AT);
if (cca) {
@ -766,7 +767,7 @@ esp_err_t ieee802154_receive(void)
// already in rx state, don't abort current rx operation
return ESP_OK;
}
ieee802154_rf_enable();
IEEE802154_RF_ENABLE();
ieee802154_enter_critical();
rx_init();
@ -779,7 +780,7 @@ esp_err_t ieee802154_receive_at(uint32_t time)
{
uint32_t rx_target_time = time - IEEE802154_RX_RAMPUP_TIME_US;
uint32_t current_time;
ieee802154_rf_enable();
IEEE802154_RF_ENABLE();
rx_init();
IEEE802154_SET_TXRX_PTI(IEEE802154_SCENE_RX_AT);
set_next_rx_buffer();
@ -813,24 +814,20 @@ static esp_err_t ieee802154_sleep_init(void)
return err;
}
IRAM_ATTR static void ieee802154_rf_disable(void)
IRAM_ATTR void ieee802154_rf_disable(void)
{
#if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE
if (s_rf_closed == false) {
esp_phy_disable(PHY_MODEM_IEEE802154);
s_rf_closed = true;
}
#endif // SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE
}
IRAM_ATTR static void ieee802154_rf_enable(void)
IRAM_ATTR void ieee802154_rf_enable(void)
{
#if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE
if (s_rf_closed) {
esp_phy_enable(PHY_MODEM_IEEE802154);
s_rf_closed = false;
}
#endif // SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE
}
esp_err_t ieee802154_sleep(void)
@ -840,14 +837,14 @@ esp_err_t ieee802154_sleep(void)
stop_current_operation();
ieee802154_set_state(IEEE802154_STATE_SLEEP);
ieee802154_exit_critical();
ieee802154_rf_disable(); // colse rf
IEEE802154_RF_DISABLE();
}
return ESP_OK;
}
esp_err_t ieee802154_energy_detect(uint32_t duration)
{
ieee802154_rf_enable();
IEEE802154_RF_ENABLE();
ieee802154_enter_critical();
stop_current_operation();
@ -863,7 +860,7 @@ esp_err_t ieee802154_energy_detect(uint32_t duration)
esp_err_t ieee802154_cca(void)
{
ieee802154_rf_enable();
IEEE802154_RF_ENABLE();
ieee802154_enter_critical();
stop_current_operation();

View File

@ -22,7 +22,7 @@
esp_err_t esp_ieee802154_enable(void)
{
ieee802154_enable();
esp_phy_enable(PHY_MODEM_IEEE802154);
ieee802154_rf_enable();
esp_btbb_enable();
return ieee802154_mac_init();
}
@ -30,7 +30,7 @@ esp_err_t esp_ieee802154_enable(void)
esp_err_t esp_ieee802154_disable(void)
{
esp_btbb_disable();
esp_phy_disable(PHY_MODEM_IEEE802154);
ieee802154_rf_disable();
ieee802154_disable();
return ieee802154_mac_deinit();
}

View File

@ -55,6 +55,17 @@ void ieee802154_enable(void);
*/
void ieee802154_disable(void);
/**
* @brief Enable the RF.
*
*/
void ieee802154_rf_enable(void);
/**
* @brief Disable the RF.
*
*/
void ieee802154_rf_disable(void);
/**
* @brief Initialize the IEEE 802.15.4 MAC.
*

View File

@ -15,6 +15,13 @@
extern "C" {
#endif
#if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE
#define IEEE802154_RF_ENABLE() ieee802154_rf_enable()
#define IEEE802154_RF_DISABLE() ieee802154_rf_disable()
#else
#define IEEE802154_RF_ENABLE()
#define IEEE802154_RF_DISABLE()
#endif // SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE
#define IEEE802154_PROBE(a) do { \
IEEE802154_RECORD_EVENT(a); \
ieee802154_record_abort(a); \