Skip to content

Commit

Permalink
Merge branch 'feat/154_enable_receive_done' into 'master'
Browse files Browse the repository at this point in the history
feat(ieee802154): make the receive done handler feature mandatory

See merge request espressif/esp-idf!28573
  • Loading branch information
chshu committed Jan 26, 2024
2 parents 6aa6403 + 6bc6660 commit b056ac7
Show file tree
Hide file tree
Showing 29 changed files with 87 additions and 131 deletions.
1 change: 0 additions & 1 deletion .gitlab/ci/rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,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
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
33 changes: 3 additions & 30 deletions components/ieee802154/driver/esp_ieee802154_dev.c
Original file line number Diff line number Diff line change
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 @@ -85,7 +80,6 @@ typedef struct {
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 @@ -113,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 @@ -123,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 @@ -179,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 @@ -204,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
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
52 changes: 19 additions & 33 deletions components/ieee802154/include/esp_ieee802154.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,20 @@ esp_err_t esp_ieee802154_sleep(void);
/**
* @brief Set the IEEE 802.15.4 Radio to receive state.
*
* @note Radio will continue receiving until it receives a valid frame.
* Refer to `esp_ieee802154_receive_done()`.
*
* @return
* - ESP_OK on success
* - ESP_FAIL on failure due to invalid state.
*
* Note: Radio will continue receiving until it receives a valid frame.
* Ref to esp_ieee802154_receive_done().
*
*/
esp_err_t esp_ieee802154_receive(void);

/**
* @brief Transmit the given frame.
* The transmit result will be reported via `esp_ieee802154_transmit_done()`
* or `esp_ieee802154_transmit_failed()`.
*
* @param[in] frame The pointer to the frame, the frame format:
* |-----------------------------------------------------------------------|
Expand All @@ -138,9 +140,6 @@ esp_err_t esp_ieee802154_receive(void);
* - ESP_OK on success.
* - ESP_FAIL on failure due to invalid state.
*
* Note: The transmit result will be reported via esp_ieee802154_transmit_done()
* or esp_ieee802154_transmit_failed().
*
*/
esp_err_t esp_ieee802154_transmit(const uint8_t *frame, bool cca);

Expand Down Expand Up @@ -453,35 +452,31 @@ bool esp_ieee802154_get_rx_when_idle(void);
*/
esp_err_t esp_ieee802154_energy_detect(uint32_t duration);

#if CONFIG_IEEE802154_RECEIVE_DONE_HANDLER
/**
* @brief Notify the IEEE 802.15.4 Radio that the frame is handled done by upper layer.
*
* @param[in] frame The pointer to the frame which was passed from the function esp_ieee802154_receive_done.
* or ack frame from esp_ieee802154_transmit_done.
* @param[in] frame The pointer to the frame which was passed from the function `esp_ieee802154_receive_done()`
* or ack frame from `esp_ieee802154_transmit_done()`.
*
* @return
* - ESP_OK on success
* - ESP_FAIL if frame is invalid.
*
*/
esp_err_t esp_ieee802154_receive_handle_done(uint8_t *frame);
#endif
esp_err_t esp_ieee802154_receive_handle_done(const uint8_t *frame);

/** Below are the events generated by IEEE 802.15.4 subsystem, which are in ISR context **/
/**
* @brief A Frame was received.
*
* @note User must call the function `esp_ieee802154_receive_handle_done()` to notify 802.15.4 driver after the received frame is handled.
*
* @param[in] frame The point to the received frame, frame format:
* |-----------------------------------------------------------------------|
* | Len | MHR | MAC Payload (no FCS) |
* |-----------------------------------------------------------------------|
* @param[in] frame_info More information of the received frame, refer to esp_ieee802154_frame_info_t.
*
* Note: If configuration `IEEE802154_RECEIVE_DONE_HANDLER` is enabled, then the user must call the function
* `esp_ieee802154_receive_handle_done()` to inform 802.15.4 driver that the received frame is handled.
* See `esp_ieee802154_receive_handle_done()` for more informations.
*
*/
extern void esp_ieee802154_receive_done(uint8_t *frame, esp_ieee802154_frame_info_t *frame_info);

Expand All @@ -494,27 +489,22 @@ extern void esp_ieee802154_receive_sfd_done(void);
/**
* @brief The Frame Transmission succeeded.
*
* @note If the ack frame is not null, user must call the function `esp_ieee802154_receive_handle_done()` to notify 802.15.4 driver
* after the ack frame is handled.
*
* @param[in] frame The pointer to the transmitted frame.
* @param[in] ack The received ACK frame, it could be NULL if the transmitted frame's AR bit is not set.
* @param[in] ack_frame_info More information of the ACK frame, refer to esp_ieee802154_frame_info_t.
*
* Note: refer to esp_ieee802154_transmit().
*
* If configuration `IEEE802154_RECEIVE_DONE_HANDLER` is enabled and ack frame is not null, then after the upper layer has processed the frame,
* the user must call the function `esp_ieee802154_receive_handle_done()` to inform 802.15.4 driver that the ack frame is handled.
* See `esp_ieee802154_receive_handle_done()` for more informations.
*
*/
extern void esp_ieee802154_transmit_done(const uint8_t *frame, const uint8_t *ack, esp_ieee802154_frame_info_t *ack_frame_info);

/**
* @brief The Frame Transmission failed.
* @brief The Frame Transmission failed. Refer to `esp_ieee802154_transmit()`.
*
* @param[in] frame The pointer to the frame.
* @param[in] error The transmission failure reason, refer to esp_ieee802154_tx_error_t.
*
* Note: refer to esp_ieee802154_transmit().
*
*/
extern void esp_ieee802154_transmit_failed(const uint8_t *frame, esp_ieee802154_tx_error_t error);

Expand All @@ -525,32 +515,31 @@ extern void esp_ieee802154_transmit_failed(const uint8_t *frame, esp_ieee802154_
extern void esp_ieee802154_transmit_sfd_done(uint8_t *frame);

/**
* @brief The energy detection done.
* @brief The energy detection done. Refer to `esp_ieee802154_energy_detect()`.
*
* @param[in] power The detected power level, in dBm.
*
* Note: refer to esp_ieee802154_energy_detect().
*
*/
extern void esp_ieee802154_energy_detect_done(int8_t power);

/**
* @brief Set the IEEE 802.15.4 Radio to receive state at a specific time.
*
* @note Radio will start receiving after the timestamp, and continue receiving until it receives a valid frame.
* Refer to `esp_ieee802154_receive_done()`.
*
* @param[in] time A specific timestamp for starting receiving.
* @return
* - ESP_OK on success
* - ESP_FAIL on failure due to invalid state.
*
* Note: Radio will start receiving after the timestamp, and continue receiving until it receives a valid frame.
* Ref to esp_ieee802154_receive_done().
*
*/
esp_err_t esp_ieee802154_receive_at(uint32_t time);

/**
* @brief Transmit the given frame at a specific time.
* The transmit result will be reported via `esp_ieee802154_transmit_done()`
* or `esp_ieee802154_transmit_failed()`.
*
* @param[in] frame The pointer to the frame. Refer to `esp_ieee802154_transmit()`.
* @param[in] cca Perform CCA before transmission if it's true, otherwise transmit the frame directly.
Expand All @@ -560,9 +549,6 @@ esp_err_t esp_ieee802154_receive_at(uint32_t time);
* - ESP_OK on success.
* - ESP_FAIL on failure due to invalid state.
*
* Note: The transmit result will be reported via esp_ieee802154_transmit_done()
* or esp_ieee802154_transmit_failed().
*
*/
esp_err_t esp_ieee802154_transmit_at(const uint8_t *frame, bool cca, uint32_t time);

Expand Down
1 change: 0 additions & 1 deletion components/ieee802154/lib
Submodule lib deleted from 102b03
4 changes: 1 addition & 3 deletions components/ieee802154/private_include/esp_ieee802154_dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ esp_err_t ieee802154_transmit(const uint8_t *frame, bool cca);
*/
esp_err_t ieee802154_receive(void);

#if CONFIG_IEEE802154_RECEIVE_DONE_HANDLER
/**
* @brief Notify the IEEE 802.15.4 Radio that the frame is handled done by upper layer.
*
Expand All @@ -122,8 +121,7 @@ esp_err_t ieee802154_receive(void);
* - ESP_FAIL if frame is invalid.
*
*/
esp_err_t ieee802154_receive_handle_done(uint8_t* frame);
#endif
esp_err_t ieee802154_receive_handle_done(const uint8_t* frame);

/**
* @brief Transmit the given frame at a specific time.
Expand Down
6 changes: 1 addition & 5 deletions components/openthread/src/port/esp_openthread_radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,7 @@ esp_err_t esp_openthread_radio_process(otInstance *aInstance, const esp_openthre
otPlatRadioTxDone(aInstance, &s_transmit_frame, NULL, OT_ERROR_NONE);
} else {
otPlatRadioTxDone(aInstance, &s_transmit_frame, &s_ack_frame, OT_ERROR_NONE);
#if CONFIG_IEEE802154_RECEIVE_DONE_HANDLER
esp_ieee802154_receive_handle_done(s_ack_frame.mPsdu - 1);
#endif
esp_ieee802154_receive_handle_done(s_ack_frame.mPsdu - 1);
s_ack_frame.mPsdu = NULL;
}
}
Expand Down Expand Up @@ -228,9 +226,7 @@ esp_err_t esp_openthread_radio_process(otInstance *aInstance, const esp_openthre
{
otPlatRadioReceiveDone(aInstance, &s_receive_frame[s_recv_queue.head], OT_ERROR_NONE);
}
#if CONFIG_IEEE802154_RECEIVE_DONE_HANDLER
esp_ieee802154_receive_handle_done(s_receive_frame[s_recv_queue.head].mPsdu - 1);
#endif
s_receive_frame[s_recv_queue.head].mPsdu = NULL;
s_recv_queue.head = (s_recv_queue.head + 1) % CONFIG_IEEE802154_RX_BUFFER_SIZE;
s_recv_queue.used--;
Expand Down
4 changes: 4 additions & 0 deletions docs/conf_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
'api-reference/provisioning/wifi_provisioning.rst',
'migration-guides/release-5.x/5.2/wifi.rst']

IEEE802154_DOCS = ['migration-guides/release-5.x/5.1/ieee802154.rst',
'migration-guides/release-5.x/5.2/ieee802154.rst']

NAN_DOCS = ['api-reference/network/esp_nan.rst']

WIFI_MESH_DOCS = ['api-guides/esp-wifi-mesh.rst',
Expand Down Expand Up @@ -194,6 +197,7 @@
'SOC_BLUFI_SUPPORTED':BLUFI_DOCS,
'SOC_WIFI_SUPPORTED':WIFI_DOCS,
'SOC_BT_CLASSIC_SUPPORTED':CLASSIC_BT_DOCS,
'SOC_IEEE802154_SUPPORTED':IEEE802154_DOCS,
'SOC_SUPPORT_COEXISTENCE':COEXISTENCE_DOCS,
'SOC_PSRAM_DMA_CAPABLE':MM_SYNC_DOCS,
'SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE':MM_SYNC_DOCS,
Expand Down
13 changes: 13 additions & 0 deletions docs/en/migration-guides/release-5.x/5.1/ieee802154.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
IEEE 802.15.4
=============

:link_to_translation:`zh_CN:[中文]`

Receive Handle Done
-------------------

.. note::

It is required since IDF v5.1.3 release.

User must call the function :cpp:func:`esp_ieee802154_receive_handle_done` to notify 802.15.4 driver after the received frame is handled. Otherwise the frame buffer will not be freed for future use.
1 change: 1 addition & 0 deletions docs/en/migration-guides/release-5.x/5.1/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Migration from 5.0 to 5.1
:maxdepth: 1

gcc
:SOC_IEEE802154_SUPPORTED: ieee802154
peripherals
storage
networking
Expand Down
9 changes: 9 additions & 0 deletions docs/en/migration-guides/release-5.x/5.2/ieee802154.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
IEEE 802.15.4
=============

:link_to_translation:`zh_CN:[中文]`

Receive Handle Done
-------------------

User must call the function :cpp:func:`esp_ieee802154_receive_handle_done` to notify 802.15.4 driver after the received frame is handled. Otherwise the frame buffer will not be freed for future use.
1 change: 1 addition & 0 deletions docs/en/migration-guides/release-5.x/5.2/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Migration from 5.1 to 5.2

bluetooth-classic
gcc
:SOC_IEEE802154_SUPPORTED: ieee802154
peripherals
protocols
storage
Expand Down
13 changes: 13 additions & 0 deletions docs/zh_CN/migration-guides/release-5.x/5.1/ieee802154.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
IEEE 802.15.4
=============

:link_to_translation:`en:[English]`

Receive Handle Done
-------------------

.. note::

这个功能仅包括在 IDF v5.1.3 以及之后的发布中。

当收到的数据帧被处理后, 用户需要调用函数 :cpp:func:`esp_ieee802154_receive_handle_done` 通知 802.15.4 驱动层,否则这个数据空间将不会被释放。
Loading

0 comments on commit b056ac7

Please sign in to comment.