Skip to content

Commit

Permalink
Merge branch 'bugfix/ieee802154_deinit_v5.2' into 'release/v5.2'
Browse files Browse the repository at this point in the history
Bugfix/ieee802154 deinit (Backport v5.2)

See merge request espressif/esp-idf!27974
  • Loading branch information
jack0c committed Dec 25, 2023
2 parents 99d10ca + d5076b5 commit 9d2d1e2
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 20 deletions.
11 changes: 9 additions & 2 deletions components/ieee802154/Kconfig
Expand Up @@ -2,7 +2,7 @@ menu "IEEE 802.15.4"
visible if SOC_IEEE802154_SUPPORTED

config IEEE802154_ENABLED
bool
bool "IEEE802154 Enable"
default "y" if SOC_IEEE802154_SUPPORTED

config IEEE802154_RX_BUFFER_SIZE
Expand All @@ -14,6 +14,7 @@ menu "IEEE 802.15.4"
The number of 802.15.4 receive buffers

choice IEEE802154_CCA_MODE
depends on IEEE802154_ENABLED
prompt "Clear Channel Assessment (CCA) mode"
default IEEE802154_CCA_ED
help
Expand Down Expand Up @@ -41,6 +42,7 @@ menu "IEEE 802.15.4"
endchoice

config IEEE802154_CCA_MODE
depends on IEEE802154_ENABLED
int
default 0 if IEEE802154_CCA_CARRIER
default 1 if IEEE802154_CCA_ED
Expand All @@ -49,26 +51,30 @@ menu "IEEE 802.15.4"

config IEEE802154_CCA_THRESHOLD
int "CCA detection threshold"
depends on IEEE802154_ENABLED
range -120 0
default -60
help
set the CCA threshold, in dB

config IEEE802154_PENDING_TABLE_SIZE
int "Pending table size"
depends on IEEE802154_ENABLED
range 1 100
default 20
help
set the pending table size

config IEEE802154_MULTI_PAN_ENABLE
bool "Enable multi-pan feature for frame filter"
depends on IEEE802154_ENABLED
default n
help
Enable IEEE802154 multi-pan

config IEEE802154_TIMING_OPTIMIZATION
bool "Enable throughput optimization"
depends on IEEE802154_ENABLED
default n
help
Enabling this option increases throughput by ~5% at the expense of ~2.1k
Expand All @@ -77,14 +83,15 @@ menu "IEEE 802.15.4"
config IEEE802154_SLEEP_ENABLE
# Todo: Remove when support safe power-down of the power domain (IDF-7317)
bool "Enable IEEE802154 light sleep"
depends on PM_ENABLE
depends on PM_ENABLE && IEEE802154_ENABLED
default n
help
Enabling this option allows the IEEE802.15.4 module to be powered down during automatic light sleep,
which reduces current consumption.

menuconfig IEEE802154_DEBUG
bool "Enable IEEE802154 Debug"
depends on IEEE802154_ENABLED
default n
help
Enabling this option allows different kinds of IEEE802154 debug output.
Expand Down
38 changes: 22 additions & 16 deletions components/ieee802154/driver/esp_ieee802154_dev.c
Expand Up @@ -31,14 +31,14 @@
#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
#define IEEE802154_LINK_OWNER ENTRY(0) | ENTRY(2)
#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);
Expand All @@ -51,9 +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 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)
{
Expand Down Expand Up @@ -660,14 +660,24 @@ 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, NULL);
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");

return ret;
}

esp_err_t ieee802154_mac_deinit(void)
{
esp_err_t ret = ESP_OK;
if (s_ieee802154_isr_handle) {
ret = esp_intr_free(s_ieee802154_isr_handle);
s_ieee802154_isr_handle = NULL;
}
return ret;
}

IEEE802154_STATIC void start_ed(uint32_t duration)
{
ieee802154_ll_enable_events(IEEE802154_EVENT_ED_DONE);
Expand All @@ -693,7 +703,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);

Expand Down Expand Up @@ -721,7 +731,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) {
Expand Down Expand Up @@ -763,7 +773,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();
Expand All @@ -776,7 +786,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();
Expand Down Expand Up @@ -810,24 +820,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)
Expand All @@ -837,14 +843,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();
Expand All @@ -860,7 +866,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();
Expand Down
6 changes: 4 additions & 2 deletions components/ieee802154/esp_ieee802154.c
Expand Up @@ -22,15 +22,17 @@
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();
}

esp_err_t esp_ieee802154_disable(void)
{
esp_btbb_disable();
ieee802154_rf_disable();
ieee802154_disable();
return ESP_OK;
return ieee802154_mac_deinit();
}

uint8_t esp_ieee802154_get_channel(void)
Expand Down
21 changes: 21 additions & 0 deletions components/ieee802154/private_include/esp_ieee802154_dev.h
Expand Up @@ -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.
*
Expand All @@ -65,6 +76,16 @@ void ieee802154_disable(void);
*/
esp_err_t ieee802154_mac_init(void);

/**
* @brief Deinitialize the IEEE 802.15.4 MAC.
*
* @return
* - ESP_OK on success.
* - ESP_FAIL on failure.
*
*/
esp_err_t ieee802154_mac_deinit(void);

/**
* @brief Transmit the given frame.
*
Expand Down
7 changes: 7 additions & 0 deletions components/ieee802154/private_include/esp_ieee802154_util.h
Expand Up @@ -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); \
Expand Down

0 comments on commit 9d2d1e2

Please sign in to comment.