From 81ee463f545e0d3fe090775f4d2b36d2e4263647 Mon Sep 17 00:00:00 2001 From: Shu Chen Date: Thu, 18 Jan 2024 19:53:42 +0800 Subject: [PATCH] feat(ieee802154): make the receive done handler feature mandatory --- components/ieee802154/Kconfig | 8 --- .../ieee802154/driver/esp_ieee802154_dev.c | 33 ++---------- components/ieee802154/esp_ieee802154.c | 4 +- .../ieee802154/include/esp_ieee802154.h | 52 +++++++------------ .../private_include/esp_ieee802154_dev.h | 4 +- .../test_ieee802154/main/src/ieee802154_cmd.c | 2 + .../src/port/esp_openthread_radio.c | 6 +-- examples/openthread/ot_cli/sdkconfig.defaults | 7 --- examples/openthread/ot_rcp/sdkconfig.defaults | 6 --- .../esp_zigbee_gateway/sdkconfig.defaults | 6 --- .../esp_zigbee_rcp/main/idf_component.yml | 4 +- .../zigbee/esp_zigbee_rcp/sdkconfig.defaults | 6 --- .../HA_on_off_light/sdkconfig.defaults | 6 --- .../HA_on_off_switch/sdkconfig.defaults | 1 - 14 files changed, 29 insertions(+), 116 deletions(-) diff --git a/components/ieee802154/Kconfig b/components/ieee802154/Kconfig index 305d4f2ecb..9c5d18e237 100644 --- a/components/ieee802154/Kconfig +++ b/components/ieee802154/Kconfig @@ -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 diff --git a/components/ieee802154/driver/esp_ieee802154_dev.c b/components/ieee802154/driver/esp_ieee802154_dev.c index 1e915d4070..42a8f3308c 100644 --- a/components/ieee802154/driver/esp_ieee802154_dev.c +++ b/components/ieee802154/driver/esp_ieee802154_dev.c @@ -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]--------------------| @@ -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]; @@ -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. @@ -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 @@ -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) { @@ -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]; @@ -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); } diff --git a/components/ieee802154/esp_ieee802154.c b/components/ieee802154/esp_ieee802154.c index 2167dbdaa3..796b161a7b 100644 --- a/components/ieee802154/esp_ieee802154.c +++ b/components/ieee802154/esp_ieee802154.c @@ -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) { diff --git a/components/ieee802154/include/esp_ieee802154.h b/components/ieee802154/include/esp_ieee802154.h index a7bb1598ee..27db5ca49b 100644 --- a/components/ieee802154/include/esp_ieee802154.h +++ b/components/ieee802154/include/esp_ieee802154.h @@ -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: * |-----------------------------------------------------------------------| @@ -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); @@ -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); @@ -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); @@ -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. @@ -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); diff --git a/components/ieee802154/private_include/esp_ieee802154_dev.h b/components/ieee802154/private_include/esp_ieee802154_dev.h index 988d6fecb8..6dada29c56 100644 --- a/components/ieee802154/private_include/esp_ieee802154_dev.h +++ b/components/ieee802154/private_include/esp_ieee802154_dev.h @@ -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. * @@ -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. diff --git a/components/ieee802154/test_apps/test_ieee802154/main/src/ieee802154_cmd.c b/components/ieee802154/test_apps/test_ieee802154/main/src/ieee802154_cmd.c index b5a779fe3c..98369e43fd 100644 --- a/components/ieee802154/test_apps/test_ieee802154/main/src/ieee802154_cmd.c +++ b/components/ieee802154/test_apps/test_ieee802154/main/src/ieee802154_cmd.c @@ -875,6 +875,7 @@ void esp_ieee802154_transmit_done(const uint8_t *frame, const uint8_t *ack, esp_ ack[idx], ack[idx+1], ack[idx+2], ack[idx+3], ack[idx+4], ack[idx+5], ack[idx+6], ack[idx+7]); } + esp_ieee802154_receive_handle_done(ack); } } @@ -886,6 +887,7 @@ void esp_ieee802154_receive_done(uint8_t *frame, esp_ieee802154_frame_info_t *fr frame[idx], frame[idx+1], frame[idx+2], frame[idx+3], frame[idx+4], frame[idx+5], frame[idx+6], frame[idx+7]); } + esp_ieee802154_receive_handle_done(frame); } void esp_ieee802154_energy_detect_done(int8_t power) diff --git a/components/openthread/src/port/esp_openthread_radio.c b/components/openthread/src/port/esp_openthread_radio.c index 11d2437a95..c98989e086 100644 --- a/components/openthread/src/port/esp_openthread_radio.c +++ b/components/openthread/src/port/esp_openthread_radio.c @@ -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; } } @@ -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--; diff --git a/examples/openthread/ot_cli/sdkconfig.defaults b/examples/openthread/ot_cli/sdkconfig.defaults index 7a1d93e740..7b724c1c89 100644 --- a/examples/openthread/ot_cli/sdkconfig.defaults +++ b/examples/openthread/ot_cli/sdkconfig.defaults @@ -33,10 +33,3 @@ CONFIG_LWIP_IPV6_NUM_ADDRESSES=8 CONFIG_LWIP_MULTICAST_PING=y CONFIG_LWIP_HOOK_IP6_SELECT_SRC_ADDR_CUSTOM=y # end of lwIP - -# -# IEEE 802.15.4 -# -CONFIG_IEEE802154_ENABLED=y -CONFIG_IEEE802154_RECEIVE_DONE_HANDLER=y -# end of IEEE 802.15.4 diff --git a/examples/openthread/ot_rcp/sdkconfig.defaults b/examples/openthread/ot_rcp/sdkconfig.defaults index 9dea0be01d..002c6f9f30 100644 --- a/examples/openthread/ot_rcp/sdkconfig.defaults +++ b/examples/openthread/ot_rcp/sdkconfig.defaults @@ -30,12 +30,6 @@ CONFIG_LOG_BOOTLOADER_LEVEL_ERROR=y CONFIG_LOG_BOOTLOADER_LEVEL_INFO=n # End of deprecated options -# -# IEEE 802.15.4 -# -CONFIG_IEEE802154_RECEIVE_DONE_HANDLER=y -# end of IEEE 802.15.4 - # # Configurations for optimizing the size of ot_rcp firmware # diff --git a/examples/zigbee/esp_zigbee_gateway/sdkconfig.defaults b/examples/zigbee/esp_zigbee_gateway/sdkconfig.defaults index 0d42a949ae..25d3d36dcc 100644 --- a/examples/zigbee/esp_zigbee_gateway/sdkconfig.defaults +++ b/examples/zigbee/esp_zigbee_gateway/sdkconfig.defaults @@ -31,9 +31,3 @@ CONFIG_ZB_ENABLED=y CONFIG_ZB_ZCZR=y # end of Zboss # end of Component config - -# -# IEEE802154 -# -CONFIG_IEEE802154_RECEIVE_DONE_HANDLER=y -# end of IEEE802154 diff --git a/examples/zigbee/esp_zigbee_rcp/main/idf_component.yml b/examples/zigbee/esp_zigbee_rcp/main/idf_component.yml index 72f9982b83..c186c3c8ca 100644 --- a/examples/zigbee/esp_zigbee_rcp/main/idf_component.yml +++ b/examples/zigbee/esp_zigbee_rcp/main/idf_component.yml @@ -1,7 +1,7 @@ ## IDF Component Manager Manifest File dependencies: - espressif/esp-zboss-lib: "~1.0.9" - espressif/esp-zigbee-lib: "~1.0.9" + espressif/esp-zboss-lib: "1.0.9" + espressif/esp-zigbee-lib: "1.0.9" ## Required IDF version idf: version: ">=5.0.0" diff --git a/examples/zigbee/esp_zigbee_rcp/sdkconfig.defaults b/examples/zigbee/esp_zigbee_rcp/sdkconfig.defaults index ff652ad98b..b337975d5c 100644 --- a/examples/zigbee/esp_zigbee_rcp/sdkconfig.defaults +++ b/examples/zigbee/esp_zigbee_rcp/sdkconfig.defaults @@ -14,10 +14,4 @@ CONFIG_PARTITION_TABLE_MD5=y CONFIG_ZB_ENABLED=y CONFIG_ZB_RCP=y # end of ZBOSS Source - -# -# IEEE802154 -# -CONFIG_IEEE802154_RECEIVE_DONE_HANDLER=y -# end of IEEE802154 # end of Component config diff --git a/examples/zigbee/light_sample/HA_on_off_light/sdkconfig.defaults b/examples/zigbee/light_sample/HA_on_off_light/sdkconfig.defaults index bff542df4f..51a266bdd0 100644 --- a/examples/zigbee/light_sample/HA_on_off_light/sdkconfig.defaults +++ b/examples/zigbee/light_sample/HA_on_off_light/sdkconfig.defaults @@ -28,10 +28,4 @@ CONFIG_MBEDTLS_ECJPAKE_C=y CONFIG_ZB_ENABLED=y CONFIG_ZB_ZED=y # end of Zboss - -# -# IEEE802154 -# -CONFIG_IEEE802154_RECEIVE_DONE_HANDLER=y -# end of IEEE802154 # end of Component config diff --git a/examples/zigbee/light_sample/HA_on_off_switch/sdkconfig.defaults b/examples/zigbee/light_sample/HA_on_off_switch/sdkconfig.defaults index b6077ef439..79fcc61b2c 100644 --- a/examples/zigbee/light_sample/HA_on_off_switch/sdkconfig.defaults +++ b/examples/zigbee/light_sample/HA_on_off_switch/sdkconfig.defaults @@ -27,6 +27,5 @@ CONFIG_MBEDTLS_ECJPAKE_C=y # CONFIG_ZB_ENABLED=y CONFIG_ZB_ZCZR=y -CONFIG_IEEE802154_RECEIVE_DONE_HANDLER=y # end of Zboss # end of Component config