From 3a1f8ffd9bc151577bbd800e5d0d1e3d646ce5e4 Mon Sep 17 00:00:00 2001 From: Tan Yan Quan Date: Fri, 6 Jun 2025 12:26:44 +0800 Subject: [PATCH 1/3] fix(openthread): disable rx_abort events in next operation --- components/ieee802154/driver/esp_ieee802154_dev.c | 1 + 1 file changed, 1 insertion(+) diff --git a/components/ieee802154/driver/esp_ieee802154_dev.c b/components/ieee802154/driver/esp_ieee802154_dev.c index c6b7868f9c..c40505578a 100644 --- a/components/ieee802154/driver/esp_ieee802154_dev.c +++ b/components/ieee802154/driver/esp_ieee802154_dev.c @@ -385,6 +385,7 @@ static IRAM_ATTR void next_operation(void) #if !CONFIG_IEEE802154_TEST if (s_pending_tx.frame) { // Here the driver needs to recover the setting of rx aborts, see function `ieee802154_transmit`. + ieee802154_ll_disable_rx_abort_events(IEEE802154_RX_ABORT_ALL); ieee802154_ll_enable_rx_abort_events(BIT(IEEE802154_RX_ABORT_BY_TX_ACK_TIMEOUT - 1) | BIT(IEEE802154_RX_ABORT_BY_TX_ACK_COEX_BREAK - 1)); // Clear the RX abort event again for avoiding the risk if there are still some rx abort events created after last isr process. ieee802154_ll_clear_events(IEEE802154_EVENT_RX_ABORT); From 7f94080c3bca36631f1c7f97434b60deb3845882 Mon Sep 17 00:00:00 2001 From: Xu Si Yu Date: Tue, 3 Jun 2025 16:29:46 +0800 Subject: [PATCH 2/3] feat(openthread): add some configurations in Kconfig --- components/openthread/Kconfig | 12 +++- .../openthread-core-esp32x-ftd-config.h | 62 +++++++++++++++++++ 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/components/openthread/Kconfig b/components/openthread/Kconfig index bca02ec1fb..54ecce875a 100644 --- a/components/openthread/Kconfig +++ b/components/openthread/Kconfig @@ -320,8 +320,8 @@ menu "OpenThread" config OPENTHREAD_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 + default y if !ESP_COEX_SW_COEXIST_ENABLE && !ESP_COEX_EXTERNAL_COEXIST_ENABLE + default n if ESP_COEX_SW_COEXIST_ENABLE || ESP_COEX_EXTERNAL_COEXIST_ENABLE help Select this option to enable OpenThread radio capability rx on when idle. Do not support this feature when SW coexistence is enabled. @@ -343,7 +343,7 @@ menu "OpenThread" RSS to its current parent every periodically and starts a parent search process if the average RSS is below OPENTHREAD_PARENT_SEARCH_RSS_THRESHOLD. This feature is always enabled for FTDs. menu "Parent Search Configurations" - depends on OPENTHREAD_PARENT_SEARCH_MTD + depends on OPENTHREAD_PARENT_SEARCH_MTD || OPENTHREAD_FTD config OPENTHREAD_PARENT_SEARCH_CHECK_INTERVAL_MINS int "The interval in minutes for a child to check the trigger condition to perform a parent search" default 9 @@ -353,6 +353,12 @@ menu "OpenThread" config OPENTHREAD_PARENT_SEARCH_RSS_THRESHOLD int "The RSS threshold used to trigger a parent search" default -65 + config OPENTHREAD_PARENT_SEARCH_RESELECT_TIMEOUT_MINS + int "The parent reselect timeout duration in minutes used on FTD child devices" + default 90 + config OPENTHREAD_PARENT_SEARCH_RSS_MARGIN + int "The RSS margin over the current parent RSS used on FTD child devices" + default 7 endmenu menu "Thread Memory Allocation" 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 57e19977d0..6e62ee5f39 100644 --- a/components/openthread/private_include/openthread-core-esp32x-ftd-config.h +++ b/components/openthread/private_include/openthread-core-esp32x-ftd-config.h @@ -382,6 +382,68 @@ #define OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE 0 #endif +/** + * @def OPENTHREAD_CONFIG_PARENT_SEARCH_CHECK_INTERVAL + * + * Specifies the interval in seconds for a child to check the trigger condition to perform a parent search. + * + * Applicable only if periodic parent search feature is enabled (see `OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE`). + */ +#ifdef OPENTHREAD_CONFIG_PARENT_SEARCH_CHECK_INTERVAL +#error `OPENTHREAD_CONFIG_PARENT_SEARCH_CHECK_INTERVAL` is redefined. +#endif +#define OPENTHREAD_CONFIG_PARENT_SEARCH_CHECK_INTERVAL CONFIG_OPENTHREAD_PARENT_SEARCH_CHECK_INTERVAL_MINS * 60 + +/** + * @def OPENTHREAD_CONFIG_PARENT_SEARCH_BACKOFF_INTERVAL + * + * Specifies the backoff interval in seconds for a child to not perform a parent search after triggering one. This is + * used when device is an MTD child. + * + * Applicable only if periodic parent search feature is enabled (see `OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE`). + */ +#ifdef OPENTHREAD_CONFIG_PARENT_SEARCH_BACKOFF_INTERVAL +#error `OPENTHREAD_CONFIG_PARENT_SEARCH_BACKOFF_INTERVAL` is redefined. +#endif +#define OPENTHREAD_CONFIG_PARENT_SEARCH_BACKOFF_INTERVAL CONFIG_OPENTHREAD_PARENT_SEARCH_BACKOFF_INTERVAL_MINS * 60 + +/** + * @def OPENTHREAD_CONFIG_PARENT_SEARCH_RSS_THRESHOLD + * + * Specifies the RSS threshold used to trigger a parent search. + * + * Applicable only if periodic parent search feature is enabled (see `OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE`). + */ +#ifdef OPENTHREAD_CONFIG_PARENT_SEARCH_RSS_THRESHOLD +#error `OPENTHREAD_CONFIG_PARENT_SEARCH_RSS_THRESHOLD` is redefined. +#endif +#define OPENTHREAD_CONFIG_PARENT_SEARCH_RSS_THRESHOLD CONFIG_OPENTHREAD_PARENT_SEARCH_RSS_THRESHOLD + +/** + * @def OPENTHREAD_CONFIG_PARENT_SEARCH_RESELECT_TIMEOUT + * + * Specifies parent reselect timeout duration in seconds used on FTD child devices. When an attach attempt to a + * neighboring router selected as a potential new parent fails, the same router cannot be selected again until this + * timeout expires. + * + * Applicable only if periodic parent search feature is enabled (see `OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE`). + */ +#ifdef OPENTHREAD_CONFIG_PARENT_SEARCH_RESELECT_TIMEOUT +#error `OPENTHREAD_CONFIG_PARENT_SEARCH_RESELECT_TIMEOUT` is redefined. +#endif +#define OPENTHREAD_CONFIG_PARENT_SEARCH_RESELECT_TIMEOUT CONFIG_OPENTHREAD_PARENT_SEARCH_RESELECT_TIMEOUT_MINS * 60 + +/** + * @def OPENTHREAD_CONFIG_PARENT_SEARCH_RSS_MARGIN + * + * Specifies the RSS margin over the current parent RSS for allowing selection of a neighboring router as a potential + * new parent to attach to. Used on FTD child devices. + */ +#ifdef OPENTHREAD_CONFIG_PARENT_SEARCH_RSS_MARGIN +#error `OPENTHREAD_CONFIG_PARENT_SEARCH_RSS_MARGIN` is redefined. +#endif +#define OPENTHREAD_CONFIG_PARENT_SEARCH_RSS_MARGIN CONFIG_OPENTHREAD_PARENT_SEARCH_RSS_MARGIN + /*----The following options set fixed default values but can be overridden by the user header file.----*/ #if CONFIG_OPENTHREAD_BORDER_ROUTER From aa66cb8d1cb20e79f4730c5d368f6392702c096f Mon Sep 17 00:00:00 2001 From: Tan Yan Quan Date: Wed, 11 Jun 2025 16:00:14 +0800 Subject: [PATCH 3/3] feat(openthread): use apb_freq_max mode for esp_openthread_sleep pm lock --- components/openthread/src/port/esp_openthread_sleep.c | 6 ++++-- .../light_sleep/main/esp_ot_sleepy_device.c | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/components/openthread/src/port/esp_openthread_sleep.c b/components/openthread/src/port/esp_openthread_sleep.c index a5381625ca..8ca7504a6f 100644 --- a/components/openthread/src/port/esp_openthread_sleep.c +++ b/components/openthread/src/port/esp_openthread_sleep.c @@ -19,10 +19,12 @@ esp_err_t esp_openthread_sleep_init(void) { esp_err_t err = ESP_OK; - err = esp_pm_lock_create(ESP_PM_CPU_FREQ_MAX, 0, "ieee802154", &s_pm_lock); + // Here we use APB_MAX because modem requires MODEM_REQUIRED_MIN_APB_CLK_FREQ. + // No need for CPU_MAX to reduce current consumption during Rx window. + err = esp_pm_lock_create(ESP_PM_APB_FREQ_MAX, 0, "ot_sleep", &s_pm_lock); if (err == ESP_OK) { esp_pm_lock_acquire(s_pm_lock); - ESP_LOGI(TAG, "Enable ieee802154 light sleep, the wake up source is ESP timer"); + ESP_LOGI(TAG, "Enable OpenThread light sleep, the wake up source is ESP timer"); } else { if (s_pm_lock != NULL) { esp_pm_lock_delete(s_pm_lock); diff --git a/examples/openthread/ot_sleepy_device/light_sleep/main/esp_ot_sleepy_device.c b/examples/openthread/ot_sleepy_device/light_sleep/main/esp_ot_sleepy_device.c index a7600f9c9a..d4e1892273 100644 --- a/examples/openthread/ot_sleepy_device/light_sleep/main/esp_ot_sleepy_device.c +++ b/examples/openthread/ot_sleepy_device/light_sleep/main/esp_ot_sleepy_device.c @@ -25,6 +25,7 @@ #include "esp_openthread_netif_glue.h" #include "esp_ot_sleepy_device_config.h" #include "esp_vfs_eventfd.h" +#include "esp_private/esp_clk.h" #include "driver/uart.h" #include "nvs_flash.h" #include "openthread/logging.h" @@ -192,7 +193,7 @@ static esp_err_t ot_power_save_init(void) esp_pm_config_t pm_config = { .max_freq_mhz = cur_cpu_freq_mhz, - .min_freq_mhz = cur_cpu_freq_mhz, + .min_freq_mhz = esp_clk_xtal_freq() / MHZ, #if CONFIG_FREERTOS_USE_TICKLESS_IDLE .light_sleep_enable = true #endif