From 784abd1ae0fd36a9ed2884a84aeae953d58f01d3 Mon Sep 17 00:00:00 2001 From: zwx Date: Wed, 24 Apr 2024 15:45:10 +0800 Subject: [PATCH 1/9] feat(openthread): move iperf dependency into cli extension --- examples/openthread/ot_br/main/idf_component.yml | 4 +--- examples/openthread/ot_cli/main/idf_component.yml | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/examples/openthread/ot_br/main/idf_component.yml b/examples/openthread/ot_br/main/idf_component.yml index 10a25935ff8..519cf7f89d2 100644 --- a/examples/openthread/ot_br/main/idf_component.yml +++ b/examples/openthread/ot_br/main/idf_component.yml @@ -1,7 +1,7 @@ ## IDF Component Manager Manifest File dependencies: espressif/esp_ot_cli_extension: - version: "~1.0.0" + version: "~1.1.0" espressif/mdns: "^1.0.3" ## Required IDF version idf: @@ -10,5 +10,3 @@ dependencies: path: ${IDF_PATH}/examples/common_components/protocol_examples_common ot_led: path: ${IDF_PATH}/examples/openthread/ot_common_components/ot_led - espressif/iperf: - version: "~0.1.1" diff --git a/examples/openthread/ot_cli/main/idf_component.yml b/examples/openthread/ot_cli/main/idf_component.yml index 6b1234251fb..3f1f6778d27 100644 --- a/examples/openthread/ot_cli/main/idf_component.yml +++ b/examples/openthread/ot_cli/main/idf_component.yml @@ -1,10 +1,8 @@ ## IDF Component Manager Manifest File dependencies: espressif/esp_ot_cli_extension: - version: "~1.0.0" + version: "~1.1.0" idf: version: ">=4.1.0" ot_led: path: ${IDF_PATH}/examples/openthread/ot_common_components/ot_led - espressif/iperf: - version: "~0.1.1" From d6a3ed06372537aaf606bcd79d6fe4f6a15cec6a Mon Sep 17 00:00:00 2001 From: zwx Date: Fri, 10 May 2024 15:20:11 +0800 Subject: [PATCH 2/9] feat(openthread): remove the range for some configurations --- components/openthread/Kconfig | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/components/openthread/Kconfig b/components/openthread/Kconfig index 558f093f6cf..740479a940a 100644 --- a/components/openthread/Kconfig +++ b/components/openthread/Kconfig @@ -206,7 +206,6 @@ menu "OpenThread" int "The size of max commissioning joiner entries" depends on OPENTHREAD_COMMISSIONER default 2 - range 2 50 config OPENTHREAD_JOINER bool "Enable Joiner" @@ -228,7 +227,6 @@ menu "OpenThread" int "Specifies number of service entries in the SRP client service pool" depends on OPENTHREAD_SRP_CLIENT default 5 - range 2 20 help Set the max buffer size of service entries in the SRP client service pool. @@ -257,14 +255,11 @@ menu "OpenThread" int "The number of openthread message buffers" depends on OPENTHREAD_ENABLED default 65 - range 10 100 if !OPENTHREAD_PLATFORM_MSGPOOL_MANAGEMENT - range 10 8191 if OPENTHREAD_PLATFORM_MSGPOOL_MANAGEMENT config OPENTHREAD_SPINEL_RX_FRAME_BUFFER_SIZE int "The size of openthread spinel rx frame buffer" depends on OPENTHREAD_ENABLED || OPENTHREAD_SPINEL_ONLY - default 1024 - range 512 8192 + default 2048 config OPENTHREAD_MAC_MAX_CSMA_BACKOFFS_DIRECT int "Maximum backoffs times before declaring a channel access failure." @@ -278,13 +273,11 @@ menu "OpenThread" int "The size of max MLE children entries" depends on OPENTHREAD_ENABLED default 10 - range 5 50 config OPENTHREAD_TMF_ADDR_CACHE_ENTRIES int "The size of max TMF address cache entries" depends on OPENTHREAD_ENABLED default 20 - range 5 50 config OPENTHREAD_DNS64_CLIENT bool "Use dns64 client" @@ -303,8 +296,7 @@ menu "OpenThread" config OPENTHREAD_UART_BUFFER_SIZE int "The uart received buffer size of openthread" depends on OPENTHREAD_ENABLED - default 768 - range 128 1024 + default 2048 help Set the OpenThread UART buffer size. @@ -377,7 +369,7 @@ menu "OpenThread" default n help Select this option to enable the radio statistics feature, you can use radio command to print some radio - Statistics informations. + Statistics information. config OPENTHREAD_SPINEL_ONLY bool "Enable OpenThread External Radio Spinel feature" @@ -386,11 +378,11 @@ menu "OpenThread" Select this option to enable the OpenThread Radio Spinel for external protocol stack, such as Zigbee. config OPENTHREAD_RX_ON_WHEN_IDLE - bool "Enable OpenThread radio capibility rx on when idle" + bool "Enable OpenThread radio capability rx on when idle" default y if !ESP_COEX_SW_COEXIST_ENABLE default n if ESP_COEX_SW_COEXIST_ENABLE help - Select this option to enable OpenThread radio capibility rx on when idle. Do not support this feature when + Select this option to enable OpenThread radio capability rx on when idle. Do not support this feature when SW coexistence is enabled. menu "Thread Address Query Config" @@ -398,19 +390,16 @@ menu "OpenThread" int "Timeout value (in seconds) for a address notification response after sending an address query." depends on OPENTHREAD_FTD || OPENTHREAD_MTD default 3 - range 1 10 config OPENTHREAD_ADDRESS_QUERY_RETRY_DELAY int "Initial retry delay for address query (in seconds)." depends on OPENTHREAD_FTD || OPENTHREAD_MTD default 15 - range 1 120 config OPENTHREAD_ADDRESS_QUERY_MAX_RETRY_DELAY int "Maximum retry delay for address query (in seconds)." depends on OPENTHREAD_FTD || OPENTHREAD_MTD default 120 - range OPENTHREAD_ADDRESS_QUERY_RETRY_DELAY 960 endmenu endmenu From 01e02aec6c7a117520ada349639f49b391a7dc62 Mon Sep 17 00:00:00 2001 From: zwx Date: Wed, 15 May 2024 10:57:08 +0800 Subject: [PATCH 3/9] fix(802.15.4): fix a risk for receive_at and ignore bit8 for the frame length --- components/ieee802154/driver/esp_ieee802154_dev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/ieee802154/driver/esp_ieee802154_dev.c b/components/ieee802154/driver/esp_ieee802154_dev.c index 9d18f7ea6d1..131d963c59a 100644 --- a/components/ieee802154/driver/esp_ieee802154_dev.c +++ b/components/ieee802154/driver/esp_ieee802154_dev.c @@ -88,6 +88,8 @@ static void ieee802154_receive_done(uint8_t *data, esp_ieee802154_frame_info_t * esp_rom_printf("receive buffer full, drop the current frame.\n"); } else { // Otherwise, post it to the upper layer. + // Ignore bit8 for the frame length, due to the max frame length is 127 based 802.15.4 spec. + data[0] = data[0] & 0x7f; frame_info->process = true; esp_ieee802154_receive_done(data, frame_info); } @@ -901,11 +903,11 @@ 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_enter_critical(); rx_init(); IEEE802154_SET_TXRX_PTI(IEEE802154_SCENE_RX_AT); set_next_rx_buffer(); ieee802154_set_state(IEEE802154_STATE_RX); - ieee802154_enter_critical(); ieee802154_etm_set_event_task(IEEE802154_ETM_CHANNEL1, ETM_EVENT_TIMER0_OVERFLOW, ETM_TASK_RX_START); current_time = (uint32_t)esp_timer_get_time(); ieee802154_timer0_set_threshold((is_target_time_expired(rx_target_time, current_time) ? 0 : (rx_target_time - current_time))); //uint: 1us From 3efe49f26a4008ad0ca5a73f7a1859bb6c0868f2 Mon Sep 17 00:00:00 2001 From: Xu Si Yu Date: Wed, 10 Apr 2024 17:49:25 +0800 Subject: [PATCH 4/9] feat(openthread): support openthread ephemeral key --- .../include/esp_openthread_netif_glue.h | 13 ++++++- .../openthread/include/esp_openthread_types.h | 2 + components/openthread/lib | 2 +- components/openthread/openthread | 2 +- .../openthread-core-esp32x-ftd-config.h | 4 ++ components/openthread/sbom_openthread.yml | 2 +- .../src/esp_openthread_netif_glue.c | 37 ++++++++++++++++++- examples/openthread/pytest_otbr.py | 8 ++-- 8 files changed, 60 insertions(+), 10 deletions(-) diff --git a/components/openthread/include/esp_openthread_netif_glue.h b/components/openthread/include/esp_openthread_netif_glue.h index 404e9f1f5c7..3d70c8a7f74 100644 --- a/components/openthread/include/esp_openthread_netif_glue.h +++ b/components/openthread/include/esp_openthread_netif_glue.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -16,7 +16,7 @@ extern "C" { #endif /** -* @brief Default configuration reference of OT esp-netif +* @brief Default configuration reference of OpenThread esp-netif */ #define ESP_NETIF_INHERENT_DEFAULT_OPENTHREAD() \ { \ @@ -67,6 +67,15 @@ void esp_openthread_netif_glue_deinit(void); */ esp_netif_t *esp_openthread_get_netif(void); +/** + * @brief This function register a handler for meshcop-e service publish event and remove event. + * + * @param[in] handler The handler. + * @param[in] for_publish The usage of handler, true for publish event and false for remove event. + * + */ +void esp_openthread_register_meshcop_e_handler(esp_event_handler_t handler, bool for_publish); + #ifdef __cplusplus } #endif diff --git a/components/openthread/include/esp_openthread_types.h b/components/openthread/include/esp_openthread_types.h index 28595d3fa00..03095940194 100644 --- a/components/openthread/include/esp_openthread_types.h +++ b/components/openthread/include/esp_openthread_types.h @@ -44,6 +44,8 @@ typedef enum { OPENTHREAD_EVENT_TREL_REMOVE_IP6, /*!< OpenThread stack removed TREL IPv6 address */ OPENTHREAD_EVENT_TREL_MULTICAST_GROUP_JOIN, /*!< OpenThread stack joined TREL IPv6 multicast group */ OPENTHREAD_EVENT_SET_DNS_SERVER, /*!< OpenThread stack set DNS server >*/ + OPENTHREAD_EVENT_PUBLISH_MESHCOP_E, /*!< OpenThread stack start to publish meshcop-e service >*/ + OPENTHREAD_EVENT_REMOVE_MESHCOP_E, /*!< OpenThread stack start to remove meshcop-e service >*/ } esp_openthread_event_t; /** diff --git a/components/openthread/lib b/components/openthread/lib index fcee30db4b7..a0f6a77960b 160000 --- a/components/openthread/lib +++ b/components/openthread/lib @@ -1 +1 @@ -Subproject commit fcee30db4b7342de4df9105bdd049a09d2d63187 +Subproject commit a0f6a77960b36ebe357cc4bee280034f8c7120f1 diff --git a/components/openthread/openthread b/components/openthread/openthread index 456c4482844..be7d36e4ff9 160000 --- a/components/openthread/openthread +++ b/components/openthread/openthread @@ -1 +1 @@ -Subproject commit 456c448284486abe2a9118a9fdaa468fe2383fcd +Subproject commit be7d36e4ff9cf7df6dfce54e58a31163c87b93f7 diff --git a/components/openthread/private_include/openthread-core-esp32x-ftd-config.h b/components/openthread/private_include/openthread-core-esp32x-ftd-config.h index 609c01112c4..bf61bc9094c 100644 --- a/components/openthread/private_include/openthread-core-esp32x-ftd-config.h +++ b/components/openthread/private_include/openthread-core-esp32x-ftd-config.h @@ -632,4 +632,8 @@ #define OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT CONFIG_OPENTHREAD_MAC_MAX_CSMA_BACKOFFS_DIRECT #endif +#ifndef OPENTHREAD_CONFIG_THREAD_VERSION +#define OPENTHREAD_CONFIG_THREAD_VERSION OT_THREAD_VERSION_1_4 +#endif + #define OPENTHREAD_FTD 1 diff --git a/components/openthread/sbom_openthread.yml b/components/openthread/sbom_openthread.yml index 0748bffc639..ae0203670fb 100644 --- a/components/openthread/sbom_openthread.yml +++ b/components/openthread/sbom_openthread.yml @@ -5,4 +5,4 @@ supplier: 'Organization: Espressif Systems (Shanghai) CO LTD' originator: 'Organization: Google LLC' description: OpenThread released by Google is an open-source implementation of the Thread networking url: https://github.com/espressif/openthread -hash: 456c448284486abe2a9118a9fdaa468fe2383fcd +hash: be7d36e4ff9cf7df6dfce54e58a31163c87b93f7 diff --git a/components/openthread/src/esp_openthread_netif_glue.c b/components/openthread/src/esp_openthread_netif_glue.c index 608a3218fa3..8e0ff030855 100644 --- a/components/openthread/src/esp_openthread_netif_glue.c +++ b/components/openthread/src/esp_openthread_netif_glue.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -203,6 +203,33 @@ static esp_err_t openthread_netif_transmit(void *handle, void *buffer, size_t le return error; } +static esp_event_handler_t meshcop_e_publish_handler = NULL; +static void esp_openthread_meshcop_e_publish_handler(void *args, esp_event_base_t base, int32_t event_id, void *data) +{ + if (meshcop_e_publish_handler) { + meshcop_e_publish_handler(args, base, event_id, data); + } +} + +static esp_event_handler_t meshcop_e_remove_handler = NULL; +static void esp_openthread_meshcop_e_remove_handler(void *args, esp_event_base_t base, int32_t event_id, void *data) +{ + if (meshcop_e_remove_handler) { + meshcop_e_remove_handler(args, base, event_id, data); + } +} + +void esp_openthread_register_meshcop_e_handler(esp_event_handler_t handler, bool for_publish) +{ + if (for_publish) { + meshcop_e_publish_handler = handler; + } else if (!for_publish) { + meshcop_e_remove_handler = handler; + } else { + ESP_ERROR_CHECK(ESP_FAIL); + } +} + static esp_err_t register_openthread_event_handlers(esp_netif_t *esp_netif) { ESP_RETURN_ON_ERROR( @@ -229,6 +256,12 @@ static esp_err_t register_openthread_event_handlers(esp_netif_t *esp_netif) ESP_RETURN_ON_ERROR(esp_event_handler_register(OPENTHREAD_EVENT, OPENTHREAD_EVENT_MULTICAST_GROUP_LEAVE, esp_netif_action_leave_ip6_multicast_group, esp_netif), OT_PLAT_LOG_TAG, "OpenThread interface leave ip6 multicast group event register failed"); + ESP_RETURN_ON_ERROR(esp_event_handler_register(OPENTHREAD_EVENT, OPENTHREAD_EVENT_PUBLISH_MESHCOP_E, + esp_openthread_meshcop_e_publish_handler, NULL), + OT_PLAT_LOG_TAG, "OpenThread publish meshcop-e service event register failed"); + ESP_RETURN_ON_ERROR(esp_event_handler_register(OPENTHREAD_EVENT, OPENTHREAD_EVENT_REMOVE_MESHCOP_E, + esp_openthread_meshcop_e_remove_handler, NULL), + OT_PLAT_LOG_TAG, "OpenThread remove meshcop-e service event register failed"); return ESP_OK; } @@ -244,6 +277,8 @@ static void unregister_openthread_event_handlers(void) esp_netif_action_join_ip6_multicast_group); esp_event_handler_unregister(OPENTHREAD_EVENT, OPENTHREAD_EVENT_MULTICAST_GROUP_LEAVE, esp_netif_action_leave_ip6_multicast_group); + esp_event_handler_unregister(OPENTHREAD_EVENT, OPENTHREAD_EVENT_PUBLISH_MESHCOP_E, esp_openthread_meshcop_e_publish_handler); + esp_event_handler_unregister(OPENTHREAD_EVENT, OPENTHREAD_EVENT_REMOVE_MESHCOP_E, esp_openthread_meshcop_e_remove_handler); } static esp_err_t openthread_netif_post_attach(esp_netif_t *esp_netif, void *args) diff --git a/examples/openthread/pytest_otbr.py b/examples/openthread/pytest_otbr.py index c307adc1c71..fbadbf684be 100644 --- a/examples/openthread/pytest_otbr.py +++ b/examples/openthread/pytest_otbr.py @@ -18,7 +18,7 @@ # This file contains the test scripts for Thread: # Case 1: Thread network formation and attaching -# A Thread Border Router forms a Thread network, Thread devices attache to it, then test ping connection between them. +# A Thread Border Router forms a Thread network, Thread devices attach to it, then test ping connection between them. # Case 2: Bidirectional IPv6 connectivity # Test IPv6 ping connection between Thread device and Linux Host (via Thread Border Router). @@ -29,10 +29,10 @@ # Case 4: Multicast forwarding from Thread to Wi-Fi network # Linux Host joins the multicast group, test group communication from Thread to Wi-Fi network. -# Case 5: discover Serice published by Thread device +# Case 5: discover Service published by Thread device # Thread device publishes the service, Linux Host discovers the service on Wi-Fi network. -# Case 6: discover Serice published by W-Fi device +# Case 6: discover Service published by W-Fi device # Linux Host device publishes the service on Wi-Fi network, Thread device discovers the service. # Case 7: ICMP communication via NAT64 @@ -728,7 +728,7 @@ def test_br_meshcop(Init_interface:bool, Init_avahi:bool, dut: Tuple[IdfDut, Idf assert 'hostname = [esp-ot-br.local]' in str(output_str) assert ('address = [' + ipv4_address + ']') in str(output_str) assert 'dn=DefaultDomain' in str(output_str) - assert 'tv=1.3.0' in str(output_str) + assert 'tv=1.4.0' in str(output_str) assert ('nn=' + networkname) in str(output_str) assert 'mn=BorderRouter' in str(output_str) assert 'vn=OpenThread' in str(output_str) From 3860cc8dac31be4faccf0adce6f99bdcadb1825e Mon Sep 17 00:00:00 2001 From: Xu Si Yu Date: Sun, 28 Apr 2024 19:41:35 +0800 Subject: [PATCH 5/9] feat(openthread): update openthread br lib --- components/openthread/CMakeLists.txt | 2 ++ .../include/esp_openthread_border_router.h | 21 ++++++++++++++++--- components/openthread/lib | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/components/openthread/CMakeLists.txt b/components/openthread/CMakeLists.txt index eb3d3dc3394..39cc5b78b81 100644 --- a/components/openthread/CMakeLists.txt +++ b/components/openthread/CMakeLists.txt @@ -111,7 +111,9 @@ if(CONFIG_OPENTHREAD_ENABLED) "openthread/src/core/thread/mesh_forwarder_ftd.cpp" "openthread/src/core/thread/mesh_forwarder_mtd.cpp" "openthread/src/core/thread/mle.cpp" + "openthread/src/core/thread/mle_router.cpp" "openthread/src/core/thread/mle_types.cpp" + "openthread/src/core/thread/neighbor.cpp" "openthread/src/core/thread/neighbor_table.cpp" "openthread/src/core/thread/network_data.cpp" "openthread/src/core/thread/network_data_leader.cpp" diff --git a/components/openthread/include/esp_openthread_border_router.h b/components/openthread/include/esp_openthread_border_router.h index 3a6c6e96387..de4b8ee6048 100644 --- a/components/openthread/include/esp_openthread_border_router.h +++ b/components/openthread/include/esp_openthread_border_router.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -67,7 +67,7 @@ esp_netif_t *esp_openthread_get_backbone_netif(void); void esp_openthread_register_rcp_failure_handler(esp_openthread_rcp_failure_handler handler); /** - * @brief Deinitializes the conneciton to RCP. + * @brief Deinitializes the connection to RCP. * * @return * - ESP_OK on success @@ -77,7 +77,7 @@ void esp_openthread_register_rcp_failure_handler(esp_openthread_rcp_failure_hand esp_err_t esp_openthread_rcp_deinit(void); /** - * @brief Initializes the conneciton to RCP. + * @brief Initializes the connection to RCP. * * @return * - ESP_OK on success @@ -86,6 +86,21 @@ esp_err_t esp_openthread_rcp_deinit(void); */ esp_err_t esp_openthread_rcp_init(void); +/** + * @brief Sets the meshcop(e) instance name. + * + * @note This function can only be called before `esp_openthread_border_router_init`. + * If `instance_name` is NULL, then the service will use the hostname as instance name. + * + * @param[in] instance_name The instance name, can be `NULL`. + * + * @return + * - ESP_OK on success + * - ESP_FAIL if fail to initialize RCP + * + */ +esp_err_t esp_openthread_set_meshcop_instance_name(const char *instance_name); + #ifdef __cplusplus } #endif diff --git a/components/openthread/lib b/components/openthread/lib index a0f6a77960b..5ae57e156e4 160000 --- a/components/openthread/lib +++ b/components/openthread/lib @@ -1 +1 @@ -Subproject commit a0f6a77960b36ebe357cc4bee280034f8c7120f1 +Subproject commit 5ae57e156e4cd2ccd8dc51e90266b16b284e64de From 5887426badcc4fb23e6b3b5b80d9357a470d45fe Mon Sep 17 00:00:00 2001 From: zwx Date: Mon, 27 May 2024 14:43:00 +0800 Subject: [PATCH 6/9] feat(802154): log `buffer full` message in debug mode only --- .../ieee802154/driver/esp_ieee802154_debug.c | 101 +++++++++--------- .../ieee802154/driver/esp_ieee802154_dev.c | 11 +- .../ieee802154/driver/esp_ieee802154_frame.c | 25 +++-- .../ieee802154/driver/esp_ieee802154_timer.c | 9 +- .../private_include/esp_ieee802154_dev.h | 2 - .../private_include/esp_ieee802154_util.h | 2 + 6 files changed, 73 insertions(+), 77 deletions(-) diff --git a/components/ieee802154/driver/esp_ieee802154_debug.c b/components/ieee802154/driver/esp_ieee802154_debug.c index c8472c83159..0dbfd4bc590 100644 --- a/components/ieee802154/driver/esp_ieee802154_debug.c +++ b/components/ieee802154/driver/esp_ieee802154_debug.c @@ -12,7 +12,6 @@ #if CONFIG_IEEE802154_DEBUG ieee802154_probe_info_t g_ieee802154_probe; -#define TAG "ieee802154_debug" #if CONFIG_IEEE802154_RECORD_EVENT static char *ieee802154_get_event_string(ieee802154_ll_event_t events) @@ -176,7 +175,7 @@ static char *ieee80154_tx_abort_reason_string[] = { void ieee802154_assert_print(void) { #if CONFIG_IEEE802154_RECORD_EVENT - ESP_EARLY_LOGW(TAG, "Print the record event, current event index: %d", g_ieee802154_probe.event_index); + ESP_EARLY_LOGW(IEEE802154_TAG, "Print the record event, current event index: %d", g_ieee802154_probe.event_index); for (uint8_t i = 0; i < IEEE802154_ASSERT_RECORD_EVENT_SIZE; i++) { char event_log[200] = { 0 }; char abort_log[100] = { 0 }; @@ -191,49 +190,49 @@ void ieee802154_assert_print(void) snprintf(abort_log, 100, "tx abort reason: %4x, %20s", g_ieee802154_probe.event[i].abort_reason.tx, ieee80154_tx_abort_reason_string[g_ieee802154_probe.event[i].abort_reason.tx]); } - ESP_EARLY_LOGW(TAG, "%s %s", event_log, abort_log); + ESP_EARLY_LOGW(IEEE802154_TAG, "%s %s", event_log, abort_log); } - ESP_EARLY_LOGW(TAG,"Print the record event done.\n"); + ESP_EARLY_LOGW(IEEE802154_TAG,"Print the record event done."); #endif // CONFIG_IEEE802154_RECORD_EVENT #if CONFIG_IEEE802154_RECORD_STATE - ESP_EARLY_LOGW(TAG, "Print the record state, current state index: %d", g_ieee802154_probe.state_index); + ESP_EARLY_LOGW(IEEE802154_TAG, "Print the record state, current state index: %d", g_ieee802154_probe.state_index); for (uint8_t i = 0; i < IEEE802154_ASSERT_RECORD_STATE_SIZE; i++) { - ESP_EARLY_LOGW(TAG, "index %2d: line:%5s, state:%10s, timestamp: %lld", + ESP_EARLY_LOGW(IEEE802154_TAG, "index %2d: line:%5s, state:%10s, timestamp: %lld", i, g_ieee802154_probe.state[i].line_str, ieee802154_state_string[g_ieee802154_probe.state[i].state], g_ieee802154_probe.state[i].timestamp); } - ESP_EARLY_LOGW(TAG,"Print the record state done.\n"); + ESP_EARLY_LOGW(IEEE802154_TAG,"Print the record state done."); #endif // CONFIG_IEEE802154_RECORD_STATE #if CONFIG_IEEE802154_RECORD_CMD - ESP_EARLY_LOGW(TAG, "Print the record cmd, current cmd index: %d", g_ieee802154_probe.cmd_index); + ESP_EARLY_LOGW(IEEE802154_TAG, "Print the record cmd, current cmd index: %d", g_ieee802154_probe.cmd_index); for (uint8_t i = 0; i < IEEE802154_ASSERT_RECORD_CMD_SIZE; i++) { - ESP_EARLY_LOGW(TAG, "index %2d: line:%5s, cmd:%10s, timestamp: %lld", + ESP_EARLY_LOGW(IEEE802154_TAG, "index %2d: line:%5s, cmd:%10s, timestamp: %lld", i, g_ieee802154_probe.cmd[i].line_str, ieee802154_get_cmd_string(g_ieee802154_probe.cmd[i].cmd), g_ieee802154_probe.cmd[i].timestamp); } - ESP_EARLY_LOGW(TAG,"Print the record cmd done.\n"); + ESP_EARLY_LOGW(IEEE802154_TAG,"Print the record cmd done."); #endif // CONFIG_IEEE802154_RECORD_CMD #if CONFIG_IEEE802154_RECORD_ABORT - ESP_EARLY_LOGW(TAG, "Print the record abort, current abort index: %d", g_ieee802154_probe.abort_index); + ESP_EARLY_LOGW(IEEE802154_TAG, "Print the record abort, current abort index: %d", g_ieee802154_probe.abort_index); for (uint8_t i = 0; i < IEEE802154_ASSERT_RECORD_ABORT_SIZE; i++) { if (g_ieee802154_probe.abort[i].is_tx_abort) { - ESP_EARLY_LOGW(TAG, "index %2d: tx abort: %4x, %15s, timestamp: %lld", + ESP_EARLY_LOGW(IEEE802154_TAG, "index %2d: tx abort: %4x, %15s, timestamp: %lld", i, g_ieee802154_probe.abort[i].abort_reason.tx, ieee80154_tx_abort_reason_string[g_ieee802154_probe.abort[i].abort_reason.tx], g_ieee802154_probe.abort[i].timestamp); } else { - ESP_EARLY_LOGW(TAG, "index %2d: rx abort: %4x, %15s, timestamp: %lld", + ESP_EARLY_LOGW(IEEE802154_TAG, "index %2d: rx abort: %4x, %15s, timestamp: %lld", i, g_ieee802154_probe.abort[i].abort_reason.rx, ieee80154_rx_abort_reason_string[g_ieee802154_probe.abort[i].abort_reason.rx], g_ieee802154_probe.abort[i].timestamp); } } - ESP_EARLY_LOGW(TAG,"Print the record abort done.\n"); + ESP_EARLY_LOGW(IEEE802154_TAG,"Print the record abort done."); #endif // CONFIG_IEEE802154_RECORD_ABORT } #endif // CONFIG_IEEE802154_ASSERT @@ -330,43 +329,43 @@ void ieee802154_txrx_statistic_print(void) uint64_t rx_success_nums = s_ieee802154_txrx_statistic.rx.done_nums - s_ieee802154_txrx_statistic.rx.abort.tx_ack_coex_break_nums; - 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, "+ + +--------------------------------------------------+"); - ESP_LOGW(TAG, "|%-20s|%-35s|%-25s%-15llu%9.2f%%|", "", "", "rx_ack_timeout:", s_ieee802154_txrx_statistic.tx.abort.rx_ack_timeout_nums, tx_abort_rx_ack_timeout_ratio*100); - ESP_LOGW(TAG, "+ + +--------------------------------------------------+"); - ESP_LOGW(TAG, "|%-5s%-15llu|%-10s%-15llu%9.2f%%|%-25s%-15llu%9.2f%%|", "TX:", s_ieee802154_txrx_statistic.tx.nums, "Abort", tx_abort_nums, tx_abort_ratio*100, "tx_coex_break:", s_ieee802154_txrx_statistic.tx.abort.tx_coex_break_nums, tx_abort_tx_coex_break_ratio*100); - ESP_LOGW(TAG, "+ + +--------------------------------------------------+"); - ESP_LOGW(TAG, "|%-20s|%-35s|%-25s%-15llu%9.2f%%|", "", "", "tx_security_error:", s_ieee802154_txrx_statistic.tx.abort.tx_security_error_nums, tx_abort_tx_security_error_ratio*100); - ESP_LOGW(TAG, "+ + +--------------------------------------------------+"); - ESP_LOGW(TAG, "|%-20s|%-35s|%-25s%-15llu%9.2f%%|", "", "", "cca_failed:", s_ieee802154_txrx_statistic.tx.abort.cca_failed_nums, tx_abort_cca_failed_ratio*100); - ESP_LOGW(TAG, "+ + +--------------------------------------------------+"); - ESP_LOGW(TAG, "|%-20s|%-35s|%-25s%-15llu%9.2f%%|", "", "", "cca_busy:", s_ieee802154_txrx_statistic.tx.abort.cca_busy_nums, tx_abort_cca_busy_ratio*100); - ESP_LOGW(TAG, "+--------------------+-----------------------------------+--------------------------------------------------+"); - ESP_LOGW(TAG, "|%-20s|%-10s%-25llu|%-25s%-25llu|", "", "Done:", s_ieee802154_txrx_statistic.rx.done_nums, "Success:", rx_success_nums); - ESP_LOGW(TAG, "+ +-----------------------------------+--------------------------------------------------+"); - ESP_LOGW(TAG, "|%-20s|%-35s|%-25s%-25llu|", "", "", "tx_ack_coex_break:", s_ieee802154_txrx_statistic.rx.abort.tx_ack_coex_break_nums); - ESP_LOGW(TAG, "+ + +--------------------------------------------------+"); - ESP_LOGW(TAG, "|%-20s|%-35s|%-25s%-25llu|", "", "", "sfd_timeout:", s_ieee802154_txrx_statistic.rx.abort.sfd_timeout_nums); - ESP_LOGW(TAG, "+ + +--------------------------------------------------+"); - ESP_LOGW(TAG, "|%-20s|%-35s|%-25s%-25llu|", "", "", "crc_error:", s_ieee802154_txrx_statistic.rx.abort.crc_error_nums); - ESP_LOGW(TAG, "+ + +--------------------------------------------------+"); - ESP_LOGW(TAG, "|%-20s|%-10s%-25llu|%-25s%-25llu|", "RX", "Abort", rx_abort_nums, "filter_fail:", s_ieee802154_txrx_statistic.rx.abort.filter_fail_nums); - ESP_LOGW(TAG, "+ + +--------------------------------------------------+"); - ESP_LOGW(TAG, "|%-20s|%-35s|%-25s%-25llu|", "", "", "no_rss:", s_ieee802154_txrx_statistic.rx.abort.no_rss_nums); - ESP_LOGW(TAG, "+ + +--------------------------------------------------+"); - ESP_LOGW(TAG, "|%-20s|%-35s|%-25s%-25llu|", "", "", "rx_coex_break:", s_ieee802154_txrx_statistic.rx.abort.rx_coex_break_nums); - ESP_LOGW(TAG, "+ + +--------------------------------------------------+"); - ESP_LOGW(TAG, "|%-20s|%-35s|%-25s%-25llu|", "", "", "rx_restart:", s_ieee802154_txrx_statistic.rx.abort.rx_restart_nums); - ESP_LOGW(TAG, "+ + +--------------------------------------------------+"); - ESP_LOGW(TAG, "|%-20s|%-35s|%-25s%-25llu|", "", "", "ed_abort:", s_ieee802154_txrx_statistic.rx.abort.ed_abort_nums); - ESP_LOGW(TAG, "+--------------------+-----------------------------------+--------------------------------------------------+"); + ESP_LOGW(IEEE802154_TAG, "+--------------------+-----------------------------------+--------------------------------------------------+"); + ESP_LOGW(IEEE802154_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(IEEE802154_TAG, "+ + +--------------------------------------------------+"); + ESP_LOGW(IEEE802154_TAG, "|%-20s|%-35s|%-25s%-15llu%9.2f%%|", "", "", "tx_direct_num:", tx_direct_num, tx_direct_num_ratio*100); + ESP_LOGW(IEEE802154_TAG, "+ + +--------------------------------------------------+"); + ESP_LOGW(IEEE802154_TAG, "|%-20s|%-35s|%-25s%-15llu%9.2f%%|", "", "", "tx_deferred_num:", s_ieee802154_txrx_statistic.tx.deferred_nums, tx_deferred_num_ratio*100); + ESP_LOGW(IEEE802154_TAG, "+ +-----------------------------------+--------------------------------------------------+"); + ESP_LOGW(IEEE802154_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(IEEE802154_TAG, "+ + +--------------------------------------------------+"); + ESP_LOGW(IEEE802154_TAG, "|%-20s|%-35s|%-25s%-15llu%9.2f%%|", "", "", "rx_ack_timeout:", s_ieee802154_txrx_statistic.tx.abort.rx_ack_timeout_nums, tx_abort_rx_ack_timeout_ratio*100); + ESP_LOGW(IEEE802154_TAG, "+ + +--------------------------------------------------+"); + ESP_LOGW(IEEE802154_TAG, "|%-5s%-15llu|%-10s%-15llu%9.2f%%|%-25s%-15llu%9.2f%%|", "TX:", s_ieee802154_txrx_statistic.tx.nums, "Abort", tx_abort_nums, tx_abort_ratio*100, "tx_coex_break:", s_ieee802154_txrx_statistic.tx.abort.tx_coex_break_nums, tx_abort_tx_coex_break_ratio*100); + ESP_LOGW(IEEE802154_TAG, "+ + +--------------------------------------------------+"); + ESP_LOGW(IEEE802154_TAG, "|%-20s|%-35s|%-25s%-15llu%9.2f%%|", "", "", "tx_security_error:", s_ieee802154_txrx_statistic.tx.abort.tx_security_error_nums, tx_abort_tx_security_error_ratio*100); + ESP_LOGW(IEEE802154_TAG, "+ + +--------------------------------------------------+"); + ESP_LOGW(IEEE802154_TAG, "|%-20s|%-35s|%-25s%-15llu%9.2f%%|", "", "", "cca_failed:", s_ieee802154_txrx_statistic.tx.abort.cca_failed_nums, tx_abort_cca_failed_ratio*100); + ESP_LOGW(IEEE802154_TAG, "+ + +--------------------------------------------------+"); + ESP_LOGW(IEEE802154_TAG, "|%-20s|%-35s|%-25s%-15llu%9.2f%%|", "", "", "cca_busy:", s_ieee802154_txrx_statistic.tx.abort.cca_busy_nums, tx_abort_cca_busy_ratio*100); + ESP_LOGW(IEEE802154_TAG, "+--------------------+-----------------------------------+--------------------------------------------------+"); + ESP_LOGW(IEEE802154_TAG, "|%-20s|%-10s%-25llu|%-25s%-25llu|", "", "Done:", s_ieee802154_txrx_statistic.rx.done_nums, "Success:", rx_success_nums); + ESP_LOGW(IEEE802154_TAG, "+ +-----------------------------------+--------------------------------------------------+"); + ESP_LOGW(IEEE802154_TAG, "|%-20s|%-35s|%-25s%-25llu|", "", "", "tx_ack_coex_break:", s_ieee802154_txrx_statistic.rx.abort.tx_ack_coex_break_nums); + ESP_LOGW(IEEE802154_TAG, "+ + +--------------------------------------------------+"); + ESP_LOGW(IEEE802154_TAG, "|%-20s|%-35s|%-25s%-25llu|", "", "", "sfd_timeout:", s_ieee802154_txrx_statistic.rx.abort.sfd_timeout_nums); + ESP_LOGW(IEEE802154_TAG, "+ + +--------------------------------------------------+"); + ESP_LOGW(IEEE802154_TAG, "|%-20s|%-35s|%-25s%-25llu|", "", "", "crc_error:", s_ieee802154_txrx_statistic.rx.abort.crc_error_nums); + ESP_LOGW(IEEE802154_TAG, "+ + +--------------------------------------------------+"); + ESP_LOGW(IEEE802154_TAG, "|%-20s|%-10s%-25llu|%-25s%-25llu|", "RX", "Abort", rx_abort_nums, "filter_fail:", s_ieee802154_txrx_statistic.rx.abort.filter_fail_nums); + ESP_LOGW(IEEE802154_TAG, "+ + +--------------------------------------------------+"); + ESP_LOGW(IEEE802154_TAG, "|%-20s|%-35s|%-25s%-25llu|", "", "", "no_rss:", s_ieee802154_txrx_statistic.rx.abort.no_rss_nums); + ESP_LOGW(IEEE802154_TAG, "+ + +--------------------------------------------------+"); + ESP_LOGW(IEEE802154_TAG, "|%-20s|%-35s|%-25s%-25llu|", "", "", "rx_coex_break:", s_ieee802154_txrx_statistic.rx.abort.rx_coex_break_nums); + ESP_LOGW(IEEE802154_TAG, "+ + +--------------------------------------------------+"); + ESP_LOGW(IEEE802154_TAG, "|%-20s|%-35s|%-25s%-25llu|", "", "", "rx_restart:", s_ieee802154_txrx_statistic.rx.abort.rx_restart_nums); + ESP_LOGW(IEEE802154_TAG, "+ + +--------------------------------------------------+"); + ESP_LOGW(IEEE802154_TAG, "|%-20s|%-35s|%-25s%-25llu|", "", "", "ed_abort:", s_ieee802154_txrx_statistic.rx.abort.ed_abort_nums); + ESP_LOGW(IEEE802154_TAG, "+--------------------+-----------------------------------+--------------------------------------------------+"); } #endif // CONFIG_IEEE802154_TXRX_STATISTIC diff --git a/components/ieee802154/driver/esp_ieee802154_dev.c b/components/ieee802154/driver/esp_ieee802154_dev.c index 131d963c59a..f94f15d6c98 100644 --- a/components/ieee802154/driver/esp_ieee802154_dev.c +++ b/components/ieee802154/driver/esp_ieee802154_dev.c @@ -5,6 +5,7 @@ */ #include +#include "sdkconfig.h" #include "freertos/portmacro.h" #include "soc/periph_defs.h" #include "soc/soc.h" @@ -84,9 +85,7 @@ static pending_tx_t s_pending_tx = { 0 }; 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. - if (s_rx_index == CONFIG_IEEE802154_RX_BUFFER_SIZE) { - esp_rom_printf("receive buffer full, drop the current frame.\n"); - } else { + if (s_rx_index != CONFIG_IEEE802154_RX_BUFFER_SIZE) { // Otherwise, post it to the upper layer. // Ignore bit8 for the frame length, due to the max frame length is 127 based 802.15.4 spec. data[0] = data[0] & 0x7f; @@ -99,7 +98,6 @@ static void ieee802154_transmit_done(const uint8_t *frame, const uint8_t *ack, e { if (ack && ack_frame_info) { if (s_rx_index == CONFIG_IEEE802154_RX_BUFFER_SIZE) { - esp_rom_printf("receive buffer full, drop the current ack frame.\n"); esp_ieee802154_transmit_failed(frame, ESP_IEEE802154_TX_ERR_NO_ACK); } else { ack_frame_info->process = true; @@ -165,7 +163,6 @@ IEEE802154_STATIC void set_next_rx_buffer(void) { uint8_t* next_rx_buffer = NULL; 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]; @@ -188,8 +185,10 @@ IEEE802154_STATIC void set_next_rx_buffer(void) if (!next_rx_buffer) { s_rx_index = CONFIG_IEEE802154_RX_BUFFER_SIZE; next_rx_buffer = s_rx_frame[CONFIG_IEEE802154_RX_BUFFER_SIZE]; +#if CONFIG_IEEE802154_DEBUG + ESP_EARLY_LOGW(IEEE802154_TAG, "Rx buffer full."); +#endif } - ieee802154_ll_set_rx_addr(next_rx_buffer); } diff --git a/components/ieee802154/driver/esp_ieee802154_frame.c b/components/ieee802154/driver/esp_ieee802154_frame.c index 8a6468be65b..e32e338ae0e 100644 --- a/components/ieee802154/driver/esp_ieee802154_frame.c +++ b/components/ieee802154/driver/esp_ieee802154_frame.c @@ -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 */ @@ -9,8 +9,7 @@ #include "esp_attr.h" #include "esp_ieee802154_dev.h" #include "esp_ieee802154_frame.h" - -static const char *TAG = "ieee802154 frame"; +#include "esp_ieee802154_util.h" IEEE802154_STATIC IEEE802154_INLINE bool is_security_enabled(const uint8_t *frame) { @@ -59,7 +58,7 @@ IEEE802154_STATIC bool is_dst_panid_present(const uint8_t *frame) uint8_t src_mode = src_addr_mode(frame); bool panid_compression = is_panid_compression(frame); - if (dst_mode != IEEE802154_FRAME_DST_MODE_NONE) { // dest address is present/short/extented + if (dst_mode != IEEE802154_FRAME_DST_MODE_NONE) { // dest address is present/short/extended if ((src_mode == IEEE802154_FRAME_SRC_MODE_NONE && panid_compression) || (dst_mode == IEEE802154_FRAME_DST_MODE_EXT && src_mode == IEEE802154_FRAME_SRC_MODE_EXT && panid_compression)) { dst_panid_present = false; @@ -163,12 +162,12 @@ IEEE802154_STATIC IRAM_ATTR uint8_t ieee802154_frame_address_size(const uint8_t IEEE802154_STATIC uint8_t ieee802154_frame_security_header_offset(const uint8_t *frame) { - ESP_RETURN_ON_FALSE_ISR(is_suported_frame_type(ieee802154_frame_get_type(frame)), IEEE802154_FRAME_INVALID_ADDR_MODE, TAG, "invalid frame type"); + ESP_RETURN_ON_FALSE_ISR(is_suported_frame_type(ieee802154_frame_get_type(frame)), IEEE802154_FRAME_INVALID_ADDR_MODE, IEEE802154_TAG, "invalid frame type"); uint8_t offset = ieee802154_frame_address_offset(frame); uint8_t address_size = ieee802154_frame_address_size(frame); - ESP_RETURN_ON_FALSE_ISR(offset != IEEE802154_FRAME_INVALID_OFFSET, IEEE802154_FRAME_INVALID_OFFSET, TAG, "invalid offset"); - ESP_RETURN_ON_FALSE_ISR(address_size != IEEE802154_FRAME_INVALID_OFFSET, IEEE802154_FRAME_INVALID_OFFSET, TAG, "invalid offset"); + ESP_RETURN_ON_FALSE_ISR(offset != IEEE802154_FRAME_INVALID_OFFSET, IEEE802154_FRAME_INVALID_OFFSET, IEEE802154_TAG, "invalid offset"); + ESP_RETURN_ON_FALSE_ISR(address_size != IEEE802154_FRAME_INVALID_OFFSET, IEEE802154_FRAME_INVALID_OFFSET, IEEE802154_TAG, "invalid offset"); offset += address_size; @@ -177,12 +176,12 @@ IEEE802154_STATIC uint8_t ieee802154_frame_security_header_offset(const uint8_t IEEE802154_STATIC uint8_t ieee802154_frame_get_security_field_len(const uint8_t *frame) { - ESP_RETURN_ON_FALSE_ISR(is_suported_frame_type(ieee802154_frame_get_type(frame)), IEEE802154_FRAME_INVALID_OFFSET, TAG, "invalid frame type"); + ESP_RETURN_ON_FALSE_ISR(is_suported_frame_type(ieee802154_frame_get_type(frame)), IEEE802154_FRAME_INVALID_OFFSET, IEEE802154_TAG, "invalid frame type"); uint8_t security_field_len = 0; uint8_t offset = ieee802154_frame_security_header_offset(frame); - ESP_RETURN_ON_FALSE_ISR(offset != IEEE802154_FRAME_INVALID_OFFSET, IEEE802154_FRAME_INVALID_OFFSET, TAG, "invalid offset"); + ESP_RETURN_ON_FALSE_ISR(offset != IEEE802154_FRAME_INVALID_OFFSET, IEEE802154_FRAME_INVALID_OFFSET, IEEE802154_TAG, "invalid offset"); security_field_len += IEEE802154_FRAME_SE_HEAD_SIZE; uint8_t security_header = frame[offset]; @@ -315,13 +314,13 @@ bool IEEE802154_INLINE ieee802154_frame_is_ack_required(const uint8_t *frame) uint8_t ieee802154_frame_get_dst_addr(const uint8_t *frame, uint8_t *addr) { - ESP_RETURN_ON_FALSE_ISR(is_suported_frame_type(ieee802154_frame_get_type(frame)), IEEE802154_FRAME_INVALID_ADDR_MODE, TAG, "invalid frame type"); + ESP_RETURN_ON_FALSE_ISR(is_suported_frame_type(ieee802154_frame_get_type(frame)), IEEE802154_FRAME_INVALID_ADDR_MODE, IEEE802154_TAG, "invalid frame type"); uint8_t offset = ieee802154_frame_address_offset(frame); uint8_t dst_mode = dst_addr_mode(frame); uint8_t addr_size; - ESP_RETURN_ON_FALSE_ISR(dst_mode == IEEE802154_FRAME_DST_MODE_SHORT || dst_mode == IEEE802154_FRAME_DST_MODE_EXT, dst_mode, TAG, "invalid address mode"); + ESP_RETURN_ON_FALSE_ISR(dst_mode == IEEE802154_FRAME_DST_MODE_SHORT || dst_mode == IEEE802154_FRAME_DST_MODE_EXT, dst_mode, IEEE802154_TAG, "invalid address mode"); addr_size = (dst_mode == IEEE802154_FRAME_DST_MODE_SHORT) ? IEEE802154_FRAME_SHORT_ADDR_SIZE : IEEE802154_FRAME_EXT_ADDR_SIZE; @@ -336,14 +335,14 @@ uint8_t ieee802154_frame_get_dst_addr(const uint8_t *frame, uint8_t *addr) uint8_t ieee802154_frame_get_src_addr(const uint8_t *frame, uint8_t *addr) { - ESP_RETURN_ON_FALSE_ISR(is_suported_frame_type(ieee802154_frame_get_type(frame)), IEEE802154_FRAME_INVALID_ADDR_MODE, TAG, "invalid frame type"); + ESP_RETURN_ON_FALSE_ISR(is_suported_frame_type(ieee802154_frame_get_type(frame)), IEEE802154_FRAME_INVALID_ADDR_MODE, IEEE802154_TAG, "invalid frame type"); uint8_t offset = ieee802154_frame_address_offset(frame); uint8_t dst_mode = dst_addr_mode(frame); uint8_t src_mode = src_addr_mode(frame); uint8_t addr_size; - ESP_RETURN_ON_FALSE_ISR(src_mode == IEEE802154_FRAME_SRC_MODE_SHORT || src_mode == IEEE802154_FRAME_SRC_MODE_EXT, src_mode, TAG, "invalid address mode"); + ESP_RETURN_ON_FALSE_ISR(src_mode == IEEE802154_FRAME_SRC_MODE_SHORT || src_mode == IEEE802154_FRAME_SRC_MODE_EXT, src_mode, IEEE802154_TAG, "invalid address mode"); addr_size = (src_mode == IEEE802154_FRAME_SRC_MODE_SHORT) ? IEEE802154_FRAME_SHORT_ADDR_SIZE : IEEE802154_FRAME_EXT_ADDR_SIZE; diff --git a/components/ieee802154/driver/esp_ieee802154_timer.c b/components/ieee802154/driver/esp_ieee802154_timer.c index fb564cbcb58..e2bff1a59be 100644 --- a/components/ieee802154/driver/esp_ieee802154_timer.c +++ b/components/ieee802154/driver/esp_ieee802154_timer.c @@ -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 */ @@ -8,8 +8,7 @@ #include "hal/ieee802154_ll.h" #include "esp_check.h" #include "esp_ieee802154_timer.h" - -static const char *TAG = "ieee802154_timer"; +#include "esp_ieee802154_util.h" void ieee802154_timer0_start(void) { @@ -23,7 +22,7 @@ void ieee802154_timer0_stop(void) esp_err_t ieee802154_timer0_set_threshold(uint32_t value) { - ESP_RETURN_ON_FALSE((value < IEEE802154_TIMER0_THRESHOLD), ESP_ERR_INVALID_ARG, TAG, "invalid timer0 threshold\r\n"); + ESP_RETURN_ON_FALSE((value < IEEE802154_TIMER0_THRESHOLD), ESP_ERR_INVALID_ARG, IEEE802154_TAG, "invalid timer0 threshold"); ieee802154_ll_timer0_set_threshold(value); @@ -47,7 +46,7 @@ void ieee802154_timer1_stop(void) esp_err_t ieee802154_timer1_set_threshold(uint32_t value) { - ESP_RETURN_ON_FALSE((value < IEEE802154_TIMER1_THRESHOLD), ESP_ERR_INVALID_ARG, TAG, "invalid timer1 threshold\r\n"); + ESP_RETURN_ON_FALSE((value < IEEE802154_TIMER1_THRESHOLD), ESP_ERR_INVALID_ARG, IEEE802154_TAG, "invalid timer1 threshold"); ieee802154_ll_timer1_set_threshold(value); diff --git a/components/ieee802154/private_include/esp_ieee802154_dev.h b/components/ieee802154/private_include/esp_ieee802154_dev.h index 6dada29c56c..ace28cd5f78 100644 --- a/components/ieee802154/private_include/esp_ieee802154_dev.h +++ b/components/ieee802154/private_include/esp_ieee802154_dev.h @@ -19,8 +19,6 @@ extern "C" { #endif -#define IEEE802154_TAG "ieee802154" - // These three macros are in microseconds, used for transmit_at #define IEEE802154_ED_TRIG_TX_RAMPUP_TIME_US 256 #define IEEE802154_TX_RAMPUP_TIME_US 98 diff --git a/components/ieee802154/private_include/esp_ieee802154_util.h b/components/ieee802154/private_include/esp_ieee802154_util.h index 44ca5980619..7949e5286da 100644 --- a/components/ieee802154/private_include/esp_ieee802154_util.h +++ b/components/ieee802154/private_include/esp_ieee802154_util.h @@ -17,6 +17,8 @@ extern "C" { #endif +#define IEEE802154_TAG "ieee802154" + #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() From fd0ea434963bb6672fba9d26ed8cc715059e0fd5 Mon Sep 17 00:00:00 2001 From: zwx Date: Mon, 3 Jun 2024 19:53:08 +0800 Subject: [PATCH 7/9] fix(802.15.4): fixed ieee802154 will sleep when only pm enabled --- .../ieee802154/driver/esp_ieee802154_dev.c | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/components/ieee802154/driver/esp_ieee802154_dev.c b/components/ieee802154/driver/esp_ieee802154_dev.c index f94f15d6c98..c5371814796 100644 --- a/components/ieee802154/driver/esp_ieee802154_dev.c +++ b/components/ieee802154/driver/esp_ieee802154_dev.c @@ -27,7 +27,7 @@ #include "esp_attr.h" #include "esp_phy_init.h" -#if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE +#if CONFIG_PM_ENABLE #include "esp_pm.h" #include "esp_private/esp_clk.h" #include "esp_private/sleep_retention.h" @@ -37,7 +37,7 @@ #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 +#endif // CONFIG_PM_ENABLE static bool s_rf_closed = true; #define CCA_DETECTION_TIME 8 @@ -915,24 +915,27 @@ esp_err_t ieee802154_receive_at(uint32_t time) return ESP_OK; } -#if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE +#if CONFIG_PM_ENABLE static esp_err_t ieee802154_sleep_retention_init(void *arg) { + esp_err_t err = ESP_OK; +#if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE #define N_REGS_IEEE802154() (((IEEE802154_MAC_DATE_REG - IEEE802154_REG_BASE) / 4) + 1) const static sleep_retention_entries_config_t ieee802154_mac_regs_retention[] = { [0] = { .config = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_MODEM_IEEE802154_LINK(0x00), IEEE802154_REG_BASE, IEEE802154_REG_BASE, N_REGS_IEEE802154(), 0, 0), .owner = IEEE802154_LINK_OWNER }, }; - esp_err_t err = sleep_retention_entries_create(ieee802154_mac_regs_retention, ARRAY_SIZE(ieee802154_mac_regs_retention), REGDMA_LINK_PRI_IEEE802154, SLEEP_RETENTION_MODULE_802154_MAC); + err = sleep_retention_entries_create(ieee802154_mac_regs_retention, ARRAY_SIZE(ieee802154_mac_regs_retention), REGDMA_LINK_PRI_IEEE802154, SLEEP_RETENTION_MODULE_802154_MAC); ESP_RETURN_ON_ERROR(err, IEEE802154_TAG, "failed to allocate memory for ieee802154 mac retention"); ESP_LOGD(IEEE802154_TAG, "ieee802154 mac sleep retention initialization"); +#endif return err; } -#endif +#endif // CONFIG_PM_ENABLE static esp_err_t ieee802154_sleep_init(void) { esp_err_t err = ESP_OK; -#if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE +#if CONFIG_PM_ENABLE sleep_retention_module_init_param_t init_param = { .cbs = { .create = { .handle = ieee802154_sleep_retention_init, .arg = NULL } }, .depends = BIT(SLEEP_RETENTION_MODULE_BT_BB) | BIT(SLEEP_RETENTION_MODULE_CLOCK_MODEM) @@ -946,14 +949,14 @@ static esp_err_t ieee802154_sleep_init(void) sleep_modem_register_mac_bb_module_prepare_callback(sleep_modem_mac_bb_power_down_prepare, sleep_modem_mac_bb_power_up_prepare); #endif // SOC_PM_RETENTION_HAS_CLOCK_BUG && CONFIG_MAC_BB_PD -#endif // SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE +#endif // CONFIG_PM_ENABLE return err; } static esp_err_t ieee802154_sleep_deinit(void) { esp_err_t err = ESP_OK; -#if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE +#if CONFIG_PM_ENABLE err = sleep_retention_module_free(SLEEP_RETENTION_MODULE_802154_MAC); if (err == ESP_OK) { err = sleep_retention_module_deinit(SLEEP_RETENTION_MODULE_802154_MAC); @@ -962,7 +965,7 @@ static esp_err_t ieee802154_sleep_deinit(void) sleep_modem_unregister_mac_bb_module_prepare_callback(sleep_modem_mac_bb_power_down_prepare, sleep_modem_mac_bb_power_up_prepare); #endif // SOC_PM_RETENTION_HAS_CLOCK_BUG && CONFIG_MAC_BB_PD -#endif // SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE +#endif // CONFIG_PM_ENABLE return err; } From 15512f4170ba2ffb638cc012f017989515075435 Mon Sep 17 00:00:00 2001 From: Xu Si Yu Date: Wed, 29 May 2024 20:52:10 +0800 Subject: [PATCH 8/9] fix(openthread): remove the empty task for openthread tasklets --- .codespellrc | 2 +- components/openthread/src/esp_openthread.cpp | 14 +-- .../src/esp_openthread_platform.cpp | 5 +- .../src/esp_openthread_task_queue.c | 11 ++- .../openthread/src/port/esp_openthread_udp.c | 90 +++++++++---------- .../src/port/esp_spi_spinel_interface.cpp | 4 +- .../src/port/esp_uart_spinel_interface.cpp | 4 +- .../esp_radio_spinel_uart_interface.cpp | 4 +- 8 files changed, 65 insertions(+), 69 deletions(-) diff --git a/.codespellrc b/.codespellrc index 389e346d2a1..b664425f9c7 100644 --- a/.codespellrc +++ b/.codespellrc @@ -1,4 +1,4 @@ [codespell] skip = build,*.yuv,components/fatfs/src/*,alice.txt,*.rgb,components/wpa_supplicant/*,components/esp_wifi/* -ignore-words-list = ser,dout,rsource,fram,inout,shs,ans,aci,unstall,unstalling,hart,wheight +ignore-words-list = ser,dout,rsource,fram,inout,shs,ans,aci,unstall,unstalling,hart,wheight,ot write-changes = true diff --git a/components/openthread/src/esp_openthread.cpp b/components/openthread/src/esp_openthread.cpp index 60eba6153df..87c7b4986ec 100644 --- a/components/openthread/src/esp_openthread.cpp +++ b/components/openthread/src/esp_openthread.cpp @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -129,7 +129,7 @@ esp_err_t esp_openthread_auto_start(otOperationalDatasetTlvs *datasetTlvs) memcpy(dataset.mMeshLocalPrefix.m8, prefix.mPrefix.mFields.m8, sizeof(dataset.mMeshLocalPrefix.m8)); dataset.mComponents.mIsMeshLocalPrefixPresent = true; } else { - ESP_LOGE("Falied to parse mesh local prefix", CONFIG_OPENTHREAD_MESH_LOCAL_PREFIX); + ESP_LOGE("Failed to parse mesh local prefix", CONFIG_OPENTHREAD_MESH_LOCAL_PREFIX); } // Network Key @@ -213,13 +213,3 @@ esp_err_t esp_openthread_deinit(void) otInstanceFinalize(esp_openthread_get_instance()); return esp_openthread_platform_deinit(); } - -static void stub_task(void *context) -{ - // this is a empty function used for ot-task signal pending -} - -void otTaskletsSignalPending(otInstance *aInstance) -{ - esp_openthread_task_queue_post(stub_task, NULL); -} diff --git a/components/openthread/src/esp_openthread_platform.cpp b/components/openthread/src/esp_openthread_platform.cpp index f6f29e278e5..3e73ef362a5 100644 --- a/components/openthread/src/esp_openthread_platform.cpp +++ b/components/openthread/src/esp_openthread_platform.cpp @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -34,7 +34,7 @@ static esp_openthread_platform_workflow_t *s_workflow_list = NULL; esp_err_t esp_openthread_platform_workflow_register(esp_openthread_update_func update_func, esp_openthread_process_func process_func, const char *name) { - uint8_t name_len = strnlen(name, WORKFLOW_MAX_NAMELEN); + uint8_t name_len = strnlen(name, WORKFLOW_MAX_NAMELEN - 1); esp_openthread_platform_workflow_t *current_workflow = s_workflow_list; esp_openthread_platform_workflow_t *before_workflow = NULL; esp_openthread_platform_workflow_t *add_workflow = @@ -42,6 +42,7 @@ esp_err_t esp_openthread_platform_workflow_register(esp_openthread_update_func u ESP_RETURN_ON_FALSE(add_workflow != NULL, ESP_ERR_NO_MEM, OT_PLAT_LOG_TAG, "Failed to alloc memory for esp_openthread_workflow"); strncpy(add_workflow->name, name, name_len); + add_workflow->name[name_len] = '\0'; add_workflow->update_func = update_func; add_workflow->process_func = process_func; add_workflow->next = NULL; diff --git a/components/openthread/src/esp_openthread_task_queue.c b/components/openthread/src/esp_openthread_task_queue.c index 4acfaad722b..32bb4f20020 100644 --- a/components/openthread/src/esp_openthread_task_queue.c +++ b/components/openthread/src/esp_openthread_task_queue.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -15,6 +15,7 @@ #include "freertos/FreeRTOS.h" #include "freertos/portmacro.h" #include "freertos/queue.h" +#include "openthread/tasklet.h" static QueueHandle_t s_task_queue = NULL; static int s_task_queue_event_fd = -1; @@ -37,6 +38,14 @@ esp_err_t esp_openthread_task_queue_init(const esp_openthread_platform_config_t &esp_openthread_task_queue_process, task_queue_workflow); } +void otTaskletsSignalPending(otInstance *aInstance) +{ + uint64_t val = 1; + ssize_t ret; + ret = write(s_task_queue_event_fd, &val, sizeof(val)); + assert(ret == sizeof(val)); +} + esp_err_t IRAM_ATTR esp_openthread_task_queue_post(esp_openthread_task_t task, void *arg) { task_storage_t task_storage = { diff --git a/components/openthread/src/port/esp_openthread_udp.c b/components/openthread/src/port/esp_openthread_udp.c index 852c0a920a0..fd118b2a0f7 100644 --- a/components/openthread/src/port/esp_openthread_udp.c +++ b/components/openthread/src/port/esp_openthread_udp.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -20,6 +20,7 @@ #include "esp_openthread_task_queue.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" +#include "lwip/err.h" #include "lwip/ip6.h" #include "lwip/ip6_addr.h" #include "lwip/ip_addr.h" @@ -40,24 +41,19 @@ typedef struct { } udp_recv_task_t; typedef struct { - TaskHandle_t source_task; otUdpSocket *socket; struct udp_pcb *pcb_ret; } udp_new_task_t; typedef struct { - TaskHandle_t source_task; struct udp_pcb *pcb; ip_addr_t addr; uint16_t port; - err_t ret; } udp_bind_connect_task_t; typedef struct { - TaskHandle_t source_task; struct udp_pcb *pcb; uint8_t netif_index; - esp_err_t err; } udp_bind_netif_task_t; typedef struct { @@ -78,13 +74,6 @@ typedef struct { ip6_addr_t addr; } udp_multicast_join_leave_task_t; -static void wait_for_task_notification(void) -{ - esp_openthread_task_switching_lock_release(); - ulTaskNotifyTake(pdTRUE, portMAX_DELAY); - esp_openthread_task_switching_lock_acquire(portMAX_DELAY); -} - static ip_addr_t map_openthread_addr_to_lwip_addr(const otIp6Address *address) { ip_addr_t addr; @@ -185,23 +174,25 @@ static void handle_udp_recv(void *ctx, struct udp_pcb *pcb, struct pbuf *p, cons } } -static void udp_new_task(void *ctx) +static esp_err_t udp_new_task(void *ctx) { udp_new_task_t *task = (udp_new_task_t *)ctx; - task->pcb_ret = udp_new(); + ESP_RETURN_ON_FALSE(task->pcb_ret != NULL, ESP_ERR_NO_MEM, OT_PLAT_LOG_TAG, "Failed to create a new UDP pcb"); udp_recv(task->pcb_ret, handle_udp_recv, task->socket); - xTaskNotifyGive(task->source_task); + return ESP_OK; } otError otPlatUdpSocket(otUdpSocket *udp_socket) { otError error = OT_ERROR_NONE; + esp_err_t err = ESP_OK; - udp_new_task_t task = { .source_task = xTaskGetCurrentTaskHandle(), .socket = udp_socket }; - tcpip_callback(udp_new_task, &task); - wait_for_task_notification(); - VerifyOrExit(task.pcb_ret != NULL, error = OT_ERROR_FAILED); + udp_new_task_t task = {.socket = udp_socket }; + esp_openthread_task_switching_lock_release(); + err = esp_netif_tcpip_exec(udp_new_task, &task); + esp_openthread_task_switching_lock_acquire(portMAX_DELAY); + VerifyOrExit(err == ESP_OK, error = OT_ERROR_FAILED); udp_socket->mHandle = task.pcb_ret; exit: @@ -220,24 +211,25 @@ otError otPlatUdpClose(otUdpSocket *udp_socket) struct udp_pcb *pcb = (struct udp_pcb *)udp_socket->mHandle; if (pcb) { + esp_openthread_task_switching_lock_release(); tcpip_callback(udp_close_task, pcb); + esp_openthread_task_switching_lock_acquire(portMAX_DELAY); } return OT_ERROR_NONE; } -static void udp_bind_task(void *ctx) +static esp_err_t udp_bind_task(void *ctx) { udp_bind_connect_task_t *task = (udp_bind_connect_task_t *)ctx; - - task->ret = udp_bind(task->pcb, &task->addr, task->port); - xTaskNotifyGive(task->source_task); + err_t ret = udp_bind(task->pcb, &task->addr, task->port); + return (ret == ERR_OK) ? ESP_OK : ESP_FAIL; } otError otPlatUdpBind(otUdpSocket *udp_socket) { + esp_err_t err = ESP_OK; udp_bind_connect_task_t task = { - .source_task = xTaskGetCurrentTaskHandle(), .pcb = (struct udp_pcb *)udp_socket->mHandle, .port = udp_socket->mSockName.mPort, }; @@ -247,17 +239,18 @@ otError otPlatUdpBind(otUdpSocket *udp_socket) task.addr.type = IPADDR_TYPE_ANY; #endif memcpy(ip_2_ip6(&task.addr)->addr, udp_socket->mSockName.mAddress.mFields.m8, sizeof(ip_2_ip6(&task.addr)->addr)); - tcpip_callback(udp_bind_task, &task); - wait_for_task_notification(); + esp_openthread_task_switching_lock_release(); + err = esp_netif_tcpip_exec(udp_bind_task, &task); + esp_openthread_task_switching_lock_acquire(portMAX_DELAY); - return task.ret == ERR_OK ? OT_ERROR_NONE : OT_ERROR_FAILED; + return err == ESP_OK ? OT_ERROR_NONE : OT_ERROR_FAILED; } -static void udp_bind_netif_task(void *ctx) +static esp_err_t udp_bind_netif_task(void *ctx) { udp_bind_netif_task_t *task = (udp_bind_netif_task_t *)ctx; udp_bind_netif(task->pcb, netif_get_by_index(task->netif_index)); - xTaskNotifyGive(task->source_task); + return ESP_OK; } static uint8_t get_netif_index(otNetifIdentifier netif_identifier) @@ -276,34 +269,30 @@ static uint8_t get_netif_index(otNetifIdentifier netif_identifier) otError otPlatUdpBindToNetif(otUdpSocket *udp_socket, otNetifIdentifier netif_identifier) { - otError err = OT_ERROR_NONE; + esp_err_t err = ESP_OK; udp_bind_netif_task_t task = { - .source_task = xTaskGetCurrentTaskHandle(), .pcb = (struct udp_pcb *)udp_socket->mHandle, .netif_index = get_netif_index(netif_identifier), - .err = ESP_OK, }; - tcpip_callback(udp_bind_netif_task, &task); - wait_for_task_notification(); - if (task.err != ESP_OK) { - err = OT_ERROR_FAILED; - } - return err; + esp_openthread_task_switching_lock_release(); + err = esp_netif_tcpip_exec(udp_bind_netif_task, &task); + esp_openthread_task_switching_lock_acquire(portMAX_DELAY); + + return err == ESP_OK ? OT_ERROR_NONE : OT_ERROR_FAILED; } -static void udp_connect_task(void *ctx) +static esp_err_t udp_connect_task(void *ctx) { udp_bind_connect_task_t *task = (udp_bind_connect_task_t *)ctx; - - task->ret = udp_connect(task->pcb, &task->addr, task->port); - xTaskNotifyGive(task->source_task); + err_t ret = udp_connect(task->pcb, &task->addr, task->port); + return (ret == ERR_OK) ? ESP_OK : ESP_FAIL; } otError otPlatUdpConnect(otUdpSocket *udp_socket) { + esp_err_t err = ESP_OK; udp_bind_connect_task_t task = { - .source_task = xTaskGetCurrentTaskHandle(), .pcb = (struct udp_pcb *)udp_socket->mHandle, .port = udp_socket->mPeerName.mPort, }; @@ -312,10 +301,11 @@ otError otPlatUdpConnect(otUdpSocket *udp_socket) if (ip_addr_isany_val(task.addr) && task.port == 0) { return OT_ERROR_NONE; } - tcpip_callback(udp_connect_task, &task); - wait_for_task_notification(); + esp_openthread_task_switching_lock_release(); + err = esp_netif_tcpip_exec(udp_connect_task, &task); + esp_openthread_task_switching_lock_acquire(portMAX_DELAY); - return task.ret == ERR_OK ? OT_ERROR_NONE : OT_ERROR_FAILED; + return err == ESP_OK ? OT_ERROR_NONE : OT_ERROR_FAILED; } static bool is_link_local(const otIp6Address *address) @@ -419,7 +409,9 @@ otError otPlatUdpSend(otUdpSocket *udp_socket, otMessage *message, const otMessa // If the destination address is a openthread mesh local address, set the netif OT. task->netif_index = get_netif_index(OT_NETIF_THREAD); } + esp_openthread_task_switching_lock_release(); tcpip_callback(udp_send_task, task); + esp_openthread_task_switching_lock_acquire(portMAX_DELAY); exit: return error; @@ -458,7 +450,9 @@ otError otPlatUdpJoinMulticastGroup(otUdpSocket *socket, otNetifIdentifier netif task->netif_index = get_netif_index(netif_id); task->addr.zone = task->netif_index; memcpy(task->addr.addr, addr->mFields.m8, sizeof(task->addr.addr)); + esp_openthread_task_switching_lock_release(); tcpip_callback(udp_multicast_join_leave_task, task); + esp_openthread_task_switching_lock_acquire(portMAX_DELAY); exit: return error; @@ -475,7 +469,9 @@ otError otPlatUdpLeaveMulticastGroup(otUdpSocket *socket, otNetifIdentifier neti task->netif_index = get_netif_index(netif_id); task->addr.zone = task->netif_index; memcpy(task->addr.addr, addr->mFields.m8, sizeof(task->addr.addr)); + esp_openthread_task_switching_lock_release(); tcpip_callback(udp_multicast_join_leave_task, task); + esp_openthread_task_switching_lock_acquire(portMAX_DELAY); exit: return error; diff --git a/components/openthread/src/port/esp_spi_spinel_interface.cpp b/components/openthread/src/port/esp_spi_spinel_interface.cpp index b89eff6779f..e19acd91527 100644 --- a/components/openthread/src/port/esp_spi_spinel_interface.cpp +++ b/components/openthread/src/port/esp_spi_spinel_interface.cpp @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -266,8 +266,8 @@ otError SpiSpinelInterface::WaitForFrame(uint64_t timeout_us) otError SpiSpinelInterface::HardwareReset(void) { if (mRcpFailureHandler) { - mRcpFailureHandler(); ConductSPITransaction(true, 0, 0); // clear + mRcpFailureHandler(); } return OT_ERROR_NONE; } diff --git a/components/openthread/src/port/esp_uart_spinel_interface.cpp b/components/openthread/src/port/esp_uart_spinel_interface.cpp index 2cfa42d5e42..6f683fdee4a 100644 --- a/components/openthread/src/port/esp_uart_spinel_interface.cpp +++ b/components/openthread/src/port/esp_uart_spinel_interface.cpp @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -295,8 +295,8 @@ esp_err_t UartSpinelInterface::TryRecoverUart(void) otError UartSpinelInterface::HardwareReset(void) { if (mRcpFailureHandler) { - mRcpFailureHandler(); TryRecoverUart(); + mRcpFailureHandler(); } return OT_ERROR_NONE; } diff --git a/components/openthread/src/spinel/esp_radio_spinel_uart_interface.cpp b/components/openthread/src/spinel/esp_radio_spinel_uart_interface.cpp index d07a67065b1..56806500590 100644 --- a/components/openthread/src/spinel/esp_radio_spinel_uart_interface.cpp +++ b/components/openthread/src/spinel/esp_radio_spinel_uart_interface.cpp @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -276,8 +276,8 @@ esp_err_t UartSpinelInterface::TryRecoverUart(void) otError UartSpinelInterface::HardwareReset(void) { if (mRcpFailureHandler) { - mRcpFailureHandler(); TryRecoverUart(); + mRcpFailureHandler(); } return OT_ERROR_NONE; } From 1de232fb98fc5a3d12d691afa5934f4412662b4a Mon Sep 17 00:00:00 2001 From: zwx Date: Tue, 4 Jun 2024 12:18:13 +0800 Subject: [PATCH 9/9] feat(openthread): update BR lib --- components/openthread/lib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/openthread/lib b/components/openthread/lib index 5ae57e156e4..34d698a2749 160000 --- a/components/openthread/lib +++ b/components/openthread/lib @@ -1 +1 @@ -Subproject commit 5ae57e156e4cd2ccd8dc51e90266b16b284e64de +Subproject commit 34d698a274940730901b934caa023a3281aca53e