Skip to content

Commit

Permalink
Merge branch 'backport5.2/openthread_backport' into 'release/v5.2'
Browse files Browse the repository at this point in the history
some openthread changes backport to release/v5.2

See merge request espressif/esp-idf!28637
  • Loading branch information
chshu committed Feb 20, 2024
2 parents cb270ee + fff9980 commit dbbe2cf
Show file tree
Hide file tree
Showing 73 changed files with 2,110 additions and 480 deletions.
1 change: 0 additions & 1 deletion .gitlab/ci/rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@
- "components/esp_phy/lib"
- "components/esp_wifi/lib"
- "components/esp_coex/lib"
- "components/ieee802154/lib"
- "components/json/cJSON"
- "components/lwip/lwip"
- "components/mbedtls/mbedtls"
Expand Down
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@
path = components/openthread/lib
url = ../../espressif/esp-thread-lib.git

[submodule "components/ieee802154/lib"]
path = components/ieee802154/lib
url = ../../espressif/esp-ieee802154-lib.git

[submodule "components/bt/controller/lib_esp32h2/esp32h2-bt-lib"]
path = components/bt/controller/lib_esp32h2/esp32h2-bt-lib
url = ../../espressif/esp32h2-bt-lib.git
Expand Down
11 changes: 10 additions & 1 deletion components/hal/include/hal/ieee802154_common_ll.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -95,6 +95,7 @@ typedef enum {
} ieee802154_ll_rx_abort_reason_t;

typedef uint32_t ieee802154_ll_rx_abort_events;
#define IEEE802154_RX_ABORT_ALL 0x7fffffff

/**
* @brief IEEE802154 transmission failed reason.
Expand All @@ -118,6 +119,7 @@ typedef enum {
} ieee802154_ll_tx_abort_reason_t;

typedef uint32_t ieee802154_ll_tx_abort_events;
#define IEEE802154_TX_ABORT_ALL 0x7fffffff

/**
* @brief IEEE802154 CCA mode.
Expand Down Expand Up @@ -168,6 +170,8 @@ typedef enum {
IEEE802154_ED_SAMPLE_AVG = 0x01,
} ieee802154_ll_ed_sample_mode_t;

#define IEEE802154_RX_STATUS_RECEIVE_SFD 0x1

FORCE_INLINE_ATTR void ieee802154_ll_set_cmd(ieee802154_ll_cmd_t cmd)
{
IEEE802154.cmd.cmd = cmd;
Expand All @@ -193,6 +197,11 @@ FORCE_INLINE_ATTR ieee802154_ll_events ieee802154_ll_get_events(void)
return (ieee802154_ll_events)(IEEE802154.event_status.events);
}

FORCE_INLINE_ATTR bool ieee802154_ll_is_current_rx_frame(void)
{
return (IEEE802154.rx_status.rx_state > IEEE802154_RX_STATUS_RECEIVE_SFD);
}

static inline void ieee802154_ll_enable_rx_abort_events(ieee802154_ll_rx_abort_events events)
{
IEEE802154.rx_abort_event_en.rx_abort_en |= events;
Expand Down
8 changes: 0 additions & 8 deletions components/ieee802154/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ menu "IEEE 802.15.4"
configure the CCA mode to Carrier sense AND energy above threshold
endchoice

config IEEE802154_RECEIVE_DONE_HANDLER
bool "Enable the receive done handler feature"
default n
help
configure the receive done handler feature, when enabled, the user must call the
function `esp_ieee802154_receive_handle_done` to inform the 802.15.4 driver that
the received frame has been processed, so the frame space could be freed.

config IEEE802154_CCA_MODE
depends on IEEE802154_ENABLED
int
Expand Down
17 changes: 16 additions & 1 deletion components/ieee802154/driver/esp_ieee802154_debug.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -289,6 +289,11 @@ void ieee802154_tx_nums_update(void)
s_ieee802154_txrx_statistic.tx.nums++;
}

void ieee802154_tx_deferred_nums_update(void)
{
s_ieee802154_txrx_statistic.tx.deferred_nums++;
}

void ieee802154_tx_break_coex_nums_update(void)
{
s_ieee802154_txrx_statistic.tx.abort.tx_coex_break_nums++;
Expand All @@ -302,9 +307,15 @@ void ieee802154_txrx_statistic_print(void)
s_ieee802154_txrx_statistic.tx.abort.cca_failed_nums + s_ieee802154_txrx_statistic.tx.abort.cca_busy_nums;

uint64_t tx_nums = s_ieee802154_txrx_statistic.tx.nums;
uint64_t tx_direct_num = tx_nums - s_ieee802154_txrx_statistic.tx.deferred_nums;

float tx_success_ratio = (tx_nums > 0 ? ((float)tx_success_nums / tx_nums) : 0);
float tx_done_ratio = (tx_nums > 0 ? ((float)s_ieee802154_txrx_statistic.tx.done_nums / tx_nums) : 0);
float tx_abort_ratio = (tx_nums > 0 ? ((float)tx_abort_nums / tx_nums) : 0);

float tx_direct_num_ratio = (tx_nums > 0 ? ((float)tx_direct_num / tx_nums) : 0);
float tx_deferred_num_ratio = (tx_nums > 0 ? ((float)s_ieee802154_txrx_statistic.tx.deferred_nums / tx_nums) : 0);

float tx_abort_rx_ack_coex_break_ratio = (tx_nums > 0 ? ((float)s_ieee802154_txrx_statistic.tx.abort.rx_ack_coex_break_nums / tx_nums) : 0);
float tx_abort_rx_ack_timeout_ratio = (tx_nums > 0 ? ((float)s_ieee802154_txrx_statistic.tx.abort.rx_ack_timeout_nums / tx_nums) : 0);
float tx_abort_tx_coex_break_ratio = (tx_nums > 0 ? ((float)s_ieee802154_txrx_statistic.tx.abort.tx_coex_break_nums / tx_nums) : 0);
Expand All @@ -321,6 +332,10 @@ void ieee802154_txrx_statistic_print(void)

ESP_LOGW(TAG, "+--------------------+-----------------------------------+--------------------------------------------------+");
ESP_LOGW(TAG, "|%-20s|%-10s%-15llu%9.2f%%|%-25s%-15llu%9.2f%%|", "", "Done:", s_ieee802154_txrx_statistic.tx.done_nums, tx_done_ratio*100, "Success:", tx_success_nums, tx_success_ratio*100);
ESP_LOGW(TAG, "+ + +--------------------------------------------------+");
ESP_LOGW(TAG, "|%-20s|%-35s|%-25s%-15llu%9.2f%%|", "", "", "tx_direct_num:", tx_direct_num, tx_direct_num_ratio*100);
ESP_LOGW(TAG, "+ + +--------------------------------------------------+");
ESP_LOGW(TAG, "|%-20s|%-35s|%-25s%-15llu%9.2f%%|", "", "", "tx_deferred_num:", s_ieee802154_txrx_statistic.tx.deferred_nums, tx_deferred_num_ratio*100);
ESP_LOGW(TAG, "+ +-----------------------------------+--------------------------------------------------+");
ESP_LOGW(TAG, "|%-20s|%-35s|%-25s%-15llu%9.2f%%|", "", "", "rx_ack_coex_break:", s_ieee802154_txrx_statistic.tx.abort.rx_ack_coex_break_nums, tx_abort_rx_ack_coex_break_ratio*100);
ESP_LOGW(TAG, "+ + +--------------------------------------------------+");
Expand Down
96 changes: 55 additions & 41 deletions components/ieee802154/driver/esp_ieee802154_dev.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -47,7 +47,6 @@ IEEE802154_STATIC volatile ieee802154_state_t s_ieee802154_state;
static uint8_t *s_tx_frame = NULL;
#define IEEE802154_RX_FRAME_SIZE (127 + 1 + 1) // +1: len, +1: for dma test

#if CONFIG_IEEE802154_RECEIVE_DONE_HANDLER
// +1: for the stub buffer when the valid buffers are full.
//
// |--------------------VB[0]--------------------|
Expand All @@ -62,10 +61,6 @@ static uint8_t *s_tx_frame = NULL;
// STUB : Stub buffer, used when all valid buffers are under processing, the received frame will be dropped.
static uint8_t s_rx_frame[CONFIG_IEEE802154_RX_BUFFER_SIZE + 1][IEEE802154_RX_FRAME_SIZE];
static esp_ieee802154_frame_info_t s_rx_frame_info[CONFIG_IEEE802154_RX_BUFFER_SIZE + 1];
#else
static uint8_t s_rx_frame[CONFIG_IEEE802154_RX_BUFFER_SIZE][IEEE802154_RX_FRAME_SIZE];
static esp_ieee802154_frame_info_t s_rx_frame_info[CONFIG_IEEE802154_RX_BUFFER_SIZE];
#endif

static uint8_t s_rx_index = 0;
static uint8_t s_enh_ack_frame[128];
Expand All @@ -75,8 +70,16 @@ static intr_handle_t s_ieee802154_isr_handle = NULL;

static esp_err_t ieee802154_sleep_init(void);
static void next_operation(void);
static esp_err_t ieee802154_transmit_internal(const uint8_t *frame, bool cca);

#if !CONFIG_IEEE802154_TEST
typedef struct {
const uint8_t *frame;
bool cca;
} pending_tx_t;
static pending_tx_t s_pending_tx = { 0 };
#endif

#if CONFIG_IEEE802154_RECEIVE_DONE_HANDLER
static void ieee802154_receive_done(uint8_t *data, esp_ieee802154_frame_info_t *frame_info)
{
// If the RX done packet is written in the stub buffer, drop it silently.
Expand Down Expand Up @@ -104,7 +107,7 @@ static void ieee802154_transmit_done(const uint8_t *frame, const uint8_t *ack, e
}
}

esp_err_t ieee802154_receive_handle_done(uint8_t *data)
esp_err_t ieee802154_receive_handle_done(const uint8_t *data)
{
uint16_t size = data - &s_rx_frame[0][0];
if ((size % IEEE802154_RX_FRAME_SIZE) != 0
Expand All @@ -114,18 +117,6 @@ esp_err_t ieee802154_receive_handle_done(uint8_t *data)
s_rx_frame_info[size / IEEE802154_RX_FRAME_SIZE].process = false;
return ESP_OK;
}
#else
static void ieee802154_receive_done(uint8_t *data, esp_ieee802154_frame_info_t *frame_info)
{
esp_ieee802154_receive_done(data, frame_info);
}

static void ieee802154_transmit_done(const uint8_t *frame, const uint8_t *ack, esp_ieee802154_frame_info_t *ack_frame_info)
{
esp_ieee802154_transmit_done(frame, ack, ack_frame_info);
}

#endif

static IRAM_ATTR void event_end_process(void)
{
Expand Down Expand Up @@ -170,8 +161,8 @@ uint8_t ieee802154_get_recent_lqi(void)
IEEE802154_STATIC void set_next_rx_buffer(void)
{
uint8_t* next_rx_buffer = NULL;
#if CONFIG_IEEE802154_RECEIVE_DONE_HANDLER
uint8_t index = 0;

if (s_rx_index != CONFIG_IEEE802154_RX_BUFFER_SIZE && s_rx_frame_info[s_rx_index].process == false) {
// If buffer is not full, and current index is empty, set it to hardware.
next_rx_buffer = s_rx_frame[s_rx_index];
Expand All @@ -195,16 +186,7 @@ IEEE802154_STATIC void set_next_rx_buffer(void)
s_rx_index = CONFIG_IEEE802154_RX_BUFFER_SIZE;
next_rx_buffer = s_rx_frame[CONFIG_IEEE802154_RX_BUFFER_SIZE];
}
#else
if (s_rx_frame[s_rx_index][0] != 0) {
s_rx_index++;
if (s_rx_index == CONFIG_IEEE802154_RX_BUFFER_SIZE) {
s_rx_index = 0;
memset(s_rx_frame[s_rx_index], 0, sizeof(s_rx_frame[s_rx_index]));
}
}
next_rx_buffer = (uint8_t *)&s_rx_frame[s_rx_index];
#endif

ieee802154_ll_set_rx_addr(next_rx_buffer);
}

Expand Down Expand Up @@ -367,10 +349,21 @@ static void enable_rx(void)

static IRAM_ATTR void next_operation(void)
{
if (ieee802154_pib_get_rx_when_idle()) {
enable_rx();
} else {
ieee802154_set_state(IEEE802154_STATE_IDLE);
#if !CONFIG_IEEE802154_TEST
if (s_pending_tx.frame) {
// Here the driver needs to recover the setting of rx aborts, see function `ieee802154_transmit`.
ieee802154_ll_enable_rx_abort_events(BIT(IEEE802154_RX_ABORT_BY_TX_ACK_TIMEOUT - 1) | BIT(IEEE802154_RX_ABORT_BY_TX_ACK_COEX_BREAK - 1));
ieee802154_transmit_internal(s_pending_tx.frame, s_pending_tx.cca);
s_pending_tx.frame = NULL;
} else
#endif
{
if (ieee802154_pib_get_rx_when_idle()) {
enable_rx();
} else {
ieee802154_set_state(IEEE802154_STATE_IDLE);
ieee802154_sleep();
}
}
}

Expand Down Expand Up @@ -491,25 +484,24 @@ static IRAM_ATTR void isr_handle_rx_abort(void)
IEEE802154_ASSERT(s_ieee802154_state == IEEE802154_STATE_RX);
#if CONFIG_IEEE802154_TEST
esp_ieee802154_receive_failed(rx_status);
next_operation();
#endif
break;
case IEEE802154_RX_ABORT_BY_COEX_BREAK:
IEEE802154_ASSERT(s_ieee802154_state == IEEE802154_STATE_RX);
#if CONFIG_IEEE802154_TEST
esp_ieee802154_receive_failed(rx_status);
#endif
break;
case IEEE802154_RX_ABORT_BY_ED_ABORT:
case IEEE802154_RX_ABORT_BY_ED_COEX_REJECT:
IEEE802154_ASSERT(s_ieee802154_state == IEEE802154_STATE_ED || s_ieee802154_state == IEEE802154_STATE_CCA);
esp_ieee802154_ed_failed(rx_status);
next_operation();
break;
case IEEE802154_RX_ABORT_BY_TX_ACK_TIMEOUT:
case IEEE802154_RX_ABORT_BY_TX_ACK_COEX_BREAK:
IEEE802154_ASSERT(s_ieee802154_state == IEEE802154_STATE_TX_ACK || s_ieee802154_state == IEEE802154_STATE_TX_ENH_ACK);
#if !CONFIG_IEEE802154_TEST
ieee802154_receive_done((uint8_t *)s_rx_frame[s_rx_index], &s_rx_frame_info[s_rx_index]);
next_operation();
#else
esp_ieee802154_receive_failed(rx_status);
#endif
Expand All @@ -518,14 +510,14 @@ static IRAM_ATTR void isr_handle_rx_abort(void)
IEEE802154_ASSERT(s_ieee802154_state == IEEE802154_STATE_TX_ENH_ACK);
#if !CONFIG_IEEE802154_TEST
ieee802154_receive_done((uint8_t *)s_rx_frame[s_rx_index], &s_rx_frame_info[s_rx_index]);
next_operation();
#else
esp_ieee802154_receive_failed(rx_status);
#endif
break;
default:
IEEE802154_ASSERT(false);
}
next_operation();
}

static IRAM_ATTR void isr_handle_tx_abort(void)
Expand Down Expand Up @@ -802,7 +794,7 @@ IEEE802154_STATIC void tx_init(const uint8_t *frame)
}
}

esp_err_t ieee802154_transmit(const uint8_t *frame, bool cca)
static inline esp_err_t ieee802154_transmit_internal(const uint8_t *frame, bool cca)
{
IEEE802154_RF_ENABLE();
ieee802154_enter_critical();
Expand All @@ -819,10 +811,32 @@ esp_err_t ieee802154_transmit(const uint8_t *frame, bool cca)
}

ieee802154_exit_critical();

return ESP_OK;
}

esp_err_t ieee802154_transmit(const uint8_t *frame, bool cca)
{
#if !CONFIG_IEEE802154_TEST
ieee802154_enter_critical();
if ((s_ieee802154_state == IEEE802154_STATE_RX && ieee802154_ll_is_current_rx_frame())
|| s_ieee802154_state == IEEE802154_STATE_TX_ACK || s_ieee802154_state == IEEE802154_STATE_TX_ENH_ACK) {
// If the current radio is processing an RX frame or sending an ACK, do not shut down the ongoing process.
// Instead, defer the transmission of the pending TX frame.
// Once the current process is completed, the pending transmit frame will be initiated.
s_pending_tx.frame = frame;
s_pending_tx.cca = cca;
IEEE802154_TX_DEFERRED_NUMS_UPDATE();
// Here we enable all rx interrupts due to the driver needs to know when the current RX has finished.
// Will recover the setting of rx abort in function `next_operation`.
ieee802154_ll_enable_rx_abort_events(IEEE802154_RX_ABORT_ALL);
ieee802154_exit_critical();
return ESP_OK;
}
ieee802154_exit_critical();
#endif
return ieee802154_transmit_internal(frame, cca);
}

static inline bool is_target_time_expired(uint32_t target, uint32_t now)
{
return (((now - target) & (1 << 31)) == 0);
Expand Down
4 changes: 1 addition & 3 deletions components/ieee802154/esp_ieee802154.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,10 @@ uint8_t esp_ieee802154_get_recent_lqi(void)
return ieee802154_get_recent_lqi();
}

#if CONFIG_IEEE802154_RECEIVE_DONE_HANDLER
esp_err_t esp_ieee802154_receive_handle_done(uint8_t *frame)
esp_err_t esp_ieee802154_receive_handle_done(const uint8_t *frame)
{
return ieee802154_receive_handle_done(frame);
}
#endif

__attribute__((weak)) void esp_ieee802154_receive_done(uint8_t *data, esp_ieee802154_frame_info_t *frame_info)
{
Expand Down
Loading

0 comments on commit dbbe2cf

Please sign in to comment.