From 9969b9c0955599a20d5eff046bcb244fdb0a9afc Mon Sep 17 00:00:00 2001 From: Tan Yan Quan Date: Thu, 24 Apr 2025 16:15:08 +0800 Subject: [PATCH 1/2] feat(openthread): support bus_latency for dual-chip BR solution --- components/openthread/Kconfig | 6 +++++ .../src/port/esp_openthread_radio_spinel.cpp | 24 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/components/openthread/Kconfig b/components/openthread/Kconfig index 428f180c47..59292eeed5 100644 --- a/components/openthread/Kconfig +++ b/components/openthread/Kconfig @@ -379,6 +379,12 @@ menu "OpenThread" help The device's XTAL accuracy, in ppm. + config OPENTHREAD_BUS_LATENCY + int "The bus latency between host and radio chip" + default 4000 + help + The device's bus latency, in us. + config OPENTHREAD_MLE_MAX_CHILDREN int "The size of max MLE children entries" default 10 diff --git a/components/openthread/src/port/esp_openthread_radio_spinel.cpp b/components/openthread/src/port/esp_openthread_radio_spinel.cpp index 17fa36bbe6..36f16b57fb 100644 --- a/components/openthread/src/port/esp_openthread_radio_spinel.cpp +++ b/components/openthread/src/port/esp_openthread_radio_spinel.cpp @@ -516,3 +516,27 @@ uint32_t otPlatRadioGetSupportedChannelMask(otInstance *aInstance) // Refer to `GetRadioChannelMask(bool aPreferred)`: FALSE to get supported channel mask return s_radio.GetRadioChannelMask(false); } + +uint32_t otPlatRadioGetBusSpeed(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + +#if CONFIG_OPENTHREAD_RADIO_SPINEL_UART + return s_esp_openthread_radio_config->radio_uart_config.uart_config.baud_rate; +#elif CONFIG_OPENTHREAD_RADIO_SPINEL_SPI + return s_esp_openthread_radio_config->radio_spi_config.spi_device.clock_speed_hz; +#else + return 0; +#endif +} + +uint32_t otPlatRadioGetBusLatency(otInstance *aInstance) +{ + OT_UNUSED_VARIABLE(aInstance); + +#if CONFIG_OPENTHREAD_RADIO_SPINEL_UART || CONFIG_OPENTHREAD_RADIO_SPINEL_SPI + return CONFIG_OPENTHREAD_BUS_LATENCY; +#else + return 0; +#endif +} From 427084d6671464c56da2669f5f8f3835c8972d76 Mon Sep 17 00:00:00 2001 From: Tan Yan Quan Date: Thu, 24 Apr 2025 16:17:27 +0800 Subject: [PATCH 2/2] fix(openthread): handle SetTimeSyncState when ifconfig up or down --- .../openthread/private_include/esp_openthread_radio.h | 8 ++++++++ .../openthread/src/port/esp_openthread_radio_spinel.cpp | 5 +++++ components/openthread/src/port/esp_openthread_state.c | 6 +++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/components/openthread/private_include/esp_openthread_radio.h b/components/openthread/private_include/esp_openthread_radio.h index 20e4556681..4b9aa4555f 100644 --- a/components/openthread/private_include/esp_openthread_radio.h +++ b/components/openthread/private_include/esp_openthread_radio.h @@ -44,6 +44,14 @@ void esp_openthread_radio_deinit(void); */ void esp_openthread_radio_update(esp_openthread_mainloop_context_t *mainloop); +/** + * @brief This function handles netif change for radio spinel. + * + * @param[in] state The updated netif state. + * + */ +void esp_openthread_handle_netif_state_change(bool state); + /** * @brief This function performs the OpenThread radio process. * diff --git a/components/openthread/src/port/esp_openthread_radio_spinel.cpp b/components/openthread/src/port/esp_openthread_radio_spinel.cpp index 36f16b57fb..d38f435bb7 100644 --- a/components/openthread/src/port/esp_openthread_radio_spinel.cpp +++ b/components/openthread/src/port/esp_openthread_radio_spinel.cpp @@ -202,6 +202,11 @@ void esp_openthread_radio_update(esp_openthread_mainloop_context_t *mainloop) s_spinel_interface.GetSpinelInterface().UpdateFdSet((void *)mainloop); } +void esp_openthread_handle_netif_state_change(bool state) +{ + s_radio.SetTimeSyncState(state); +} + void otPlatRadioGetIeeeEui64(otInstance *instance, uint8_t *ieee_eui64) { SuccessOrDie(s_radio.GetIeeeEui64(ieee_eui64)); diff --git a/components/openthread/src/port/esp_openthread_state.c b/components/openthread/src/port/esp_openthread_state.c index 7dac89c3ef..153d343ea1 100644 --- a/components/openthread/src/port/esp_openthread_state.c +++ b/components/openthread/src/port/esp_openthread_state.c @@ -21,7 +21,7 @@ static void handle_ot_netif_state_change(otInstance* instance) { - if (otLinkIsEnabled(instance)) { + if (otIp6IsEnabled(instance)) { ESP_LOGI(TAG, "netif up"); if (esp_event_post(OPENTHREAD_EVENT, OPENTHREAD_EVENT_IF_UP, NULL, 0, 0) != ESP_OK) { ESP_LOGE(TAG, "Failed to post OpenThread if up event"); @@ -32,6 +32,10 @@ static void handle_ot_netif_state_change(otInstance* instance) ESP_LOGE(TAG, "Failed to post OpenThread if down event"); } } + +#if (CONFIG_OPENTHREAD_RADIO_SPINEL_UART || CONFIG_OPENTHREAD_RADIO_SPINEL_SPI) + esp_openthread_handle_netif_state_change(otIp6IsEnabled(instance)); +#endif } static void handle_ot_netdata_change(void)