diff --git a/components/esp_coex/include/esp_coex_i154.h b/components/esp_coex/include/esp_coex_i154.h index b8cb8171e6..d601205ebe 100644 --- a/components/esp_coex/include/esp_coex_i154.h +++ b/components/esp_coex/include/esp_coex_i154.h @@ -1,12 +1,11 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #ifndef __COEXIST_I154_H__ #define __COEXIST_I154_H__ -#ifdef CONFIG_SOC_IEEE802154_SUPPORTED typedef enum { IEEE802154_HIGH = 1, IEEE802154_MIDDLE, @@ -15,11 +14,16 @@ typedef enum { IEEE802154_EVENT_MAX, } ieee802154_coex_event_t; +typedef struct { + ieee802154_coex_event_t idle; + ieee802154_coex_event_t txrx; + ieee802154_coex_event_t txrx_at; +} esp_ieee802154_coex_config_t; + void esp_coex_ieee802154_txrx_pti_set(ieee802154_coex_event_t event); void esp_coex_ieee802154_ack_pti_set(ieee802154_coex_event_t event); void esp_coex_ieee802154_coex_break_notify(void); void esp_coex_ieee802154_extcoex_tx_stage(void); void esp_coex_ieee802154_extcoex_rx_stage(void); -#endif #endif diff --git a/components/esp_coex/include/esp_coexist.h b/components/esp_coex/include/esp_coexist.h index 8a865879dc..5354d741fa 100644 --- a/components/esp_coex/include/esp_coexist.h +++ b/components/esp_coex/include/esp_coexist.h @@ -164,7 +164,7 @@ esp_err_t esp_enable_extern_coex_gpio_pin(external_coex_wire_t wire_type, * @brief Disable external coex. * @return : ESP_OK - success, other - failed */ -esp_err_t esp_disable_extern_coex_gpio_pin(); +esp_err_t esp_disable_extern_coex_gpio_pin(void); #if SOC_EXTERNAL_COEX_ADVANCE /** diff --git a/components/esp_coex/lib b/components/esp_coex/lib index ad30777643..7b588f2dbb 160000 --- a/components/esp_coex/lib +++ b/components/esp_coex/lib @@ -1 +1 @@ -Subproject commit ad30777643ca4c97fbce790f01aebd474ae4946f +Subproject commit 7b588f2dbb12ddcd46c075dcd041f4d03a59154f diff --git a/components/esp_coex/src/coexist.c b/components/esp_coex/src/coexist.c index 89c18d4f9e..a723fd5a73 100644 --- a/components/esp_coex/src/coexist.c +++ b/components/esp_coex/src/coexist.c @@ -275,7 +275,7 @@ esp_err_t esp_enable_extern_coex_gpio_pin(external_coex_wire_t wire_type, esp_ex return ESP_OK; } -esp_err_t esp_disable_extern_coex_gpio_pin() +esp_err_t esp_disable_extern_coex_gpio_pin(void) { esp_coex_external_stop(); diff --git a/components/ieee802154/CMakeLists.txt b/components/ieee802154/CMakeLists.txt index e3e98bac2b..d3fee24de2 100644 --- a/components/ieee802154/CMakeLists.txt +++ b/components/ieee802154/CMakeLists.txt @@ -35,5 +35,6 @@ idf_component_register( INCLUDE_DIRS "${include}" PRIV_INCLUDE_DIRS "${private_include}" LDFRAGMENTS linker.lf - PRIV_REQUIRES esp_phy driver esp_timer esp_coex soc hal + REQUIRES esp_coex + PRIV_REQUIRES esp_phy driver esp_timer soc hal ) diff --git a/components/ieee802154/driver/esp_ieee802154_util.c b/components/ieee802154/driver/esp_ieee802154_util.c index c3ffed0a94..4f151ca85f 100644 --- a/components/ieee802154/driver/esp_ieee802154_util.c +++ b/components/ieee802154/driver/esp_ieee802154_util.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -22,20 +22,39 @@ uint8_t ieee802154_channel_to_freq(uint8_t channel) } #if !CONFIG_IEEE802154_TEST && (CONFIG_ESP_COEX_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE) + +esp_ieee802154_coex_config_t s_coex_config = { + .idle = IEEE802154_IDLE, + .txrx = IEEE802154_LOW, + .txrx_at = IEEE802154_MIDDLE, +}; + +void ieee802154_set_coex_config(esp_ieee802154_coex_config_t config) +{ + s_coex_config.idle = config.idle; + s_coex_config.txrx = config.txrx; + s_coex_config.txrx_at = config.txrx_at; +} + +esp_ieee802154_coex_config_t ieee802154_get_coex_config(void) +{ + return s_coex_config; +} + void ieee802154_set_txrx_pti(ieee802154_txrx_scene_t txrx_scene) { switch (txrx_scene) { case IEEE802154_SCENE_IDLE: - esp_coex_ieee802154_txrx_pti_set(IEEE802154_IDLE); + esp_coex_ieee802154_txrx_pti_set(s_coex_config.idle); break; case IEEE802154_SCENE_TX: case IEEE802154_SCENE_RX: - esp_coex_ieee802154_txrx_pti_set(IEEE802154_LOW); + esp_coex_ieee802154_txrx_pti_set(s_coex_config.txrx); break; case IEEE802154_SCENE_TX_AT: case IEEE802154_SCENE_RX_AT: - esp_coex_ieee802154_txrx_pti_set(IEEE802154_MIDDLE); + esp_coex_ieee802154_txrx_pti_set(s_coex_config.txrx_at); break; default: assert(false); diff --git a/components/ieee802154/esp_ieee802154.c b/components/ieee802154/esp_ieee802154.c index 7cbee090bb..a6d5d303ee 100644 --- a/components/ieee802154/esp_ieee802154.c +++ b/components/ieee802154/esp_ieee802154.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -451,3 +451,15 @@ void esp_ieee802154_record_print(void) ieee802154_record_print(); } #endif // CONFIG_IEEE802154_RECORD + +#if !CONFIG_IEEE802154_TEST && (CONFIG_ESP_COEX_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE) +void esp_ieee802154_set_coex_config(esp_ieee802154_coex_config_t config) +{ + ieee802154_set_coex_config(config); +} + +esp_ieee802154_coex_config_t esp_ieee802154_get_coex_config(void) +{ + return ieee802154_get_coex_config(); +} +#endif diff --git a/components/ieee802154/include/esp_ieee802154.h b/components/ieee802154/include/esp_ieee802154.h index 21529f00e9..f91ebfffd8 100644 --- a/components/ieee802154/include/esp_ieee802154.h +++ b/components/ieee802154/include/esp_ieee802154.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -12,6 +12,10 @@ #include "esp_err.h" #include "esp_ieee802154_types.h" +#if !CONFIG_IEEE802154_TEST && (CONFIG_ESP_COEX_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE) +#include "esp_coex_i154.h" +#endif + #ifdef __cplusplus extern "C" { #endif @@ -653,6 +657,27 @@ void esp_ieee802154_rx_buffer_statistic_print(void); */ void esp_ieee802154_record_print(void); #endif // CONFIG_IEEE802154_RECORD + +#if !CONFIG_IEEE802154_TEST && (CONFIG_ESP_COEX_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE) + +/** + * @brief Set the IEEE802.15.4 coexist config. + * + * @param[in] config The config of IEEE802.15.4 coexist. + * + */ +void esp_ieee802154_set_coex_config(esp_ieee802154_coex_config_t config); + +/** + * @brief Get the IEEE802.15.4 coexist config. + * + * @return + * - The config of IEEE802.15.4 coexist. + * + */ +esp_ieee802154_coex_config_t esp_ieee802154_get_coex_config(void); +#endif + #ifdef __cplusplus } #endif diff --git a/components/ieee802154/private_include/esp_ieee802154_util.h b/components/ieee802154/private_include/esp_ieee802154_util.h index f33fc5823c..13f7f5e757 100644 --- a/components/ieee802154/private_include/esp_ieee802154_util.h +++ b/components/ieee802154/private_include/esp_ieee802154_util.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -360,6 +360,26 @@ void ieee802154_etm_set_event_task(uint32_t channel, uint32_t event, uint32_t ta */ void ieee802154_etm_channel_clear(uint32_t channel); +#if !CONFIG_IEEE802154_TEST && (CONFIG_ESP_COEX_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE) + +/** + * @brief Set the IEEE802.15.4 coexist config. + * + * @param[in] config The config of IEEE802.15.4 coexist. + * + */ +void ieee802154_set_coex_config(esp_ieee802154_coex_config_t config); + +/** + * @brief Get the IEEE802.15.4 coexist config. + * + * @return + * - The config of IEEE802.15.4 coexist. + * + */ +esp_ieee802154_coex_config_t ieee802154_get_coex_config(void); +#endif + #ifdef __cplusplus } #endif diff --git a/components/openthread/CMakeLists.txt b/components/openthread/CMakeLists.txt index 37c92ce9cc..944e77eb60 100644 --- a/components/openthread/CMakeLists.txt +++ b/components/openthread/CMakeLists.txt @@ -274,7 +274,7 @@ idf_component_register(SRC_DIRS "${src_dirs}" PRIV_INCLUDE_DIRS "${private_include_dirs}" REQUIRES esp_netif lwip esp_driver_uart driver LDFRAGMENTS linker.lf - PRIV_REQUIRES console esp_event esp_partition esp_timer + PRIV_REQUIRES console esp_coex esp_event esp_partition esp_timer ieee802154 mbedtls nvs_flash) if(CONFIG_OPENTHREAD_RADIO_TREL) diff --git a/components/openthread/Kconfig b/components/openthread/Kconfig index 9217d55c39..f34a3a0228 100644 --- a/components/openthread/Kconfig +++ b/components/openthread/Kconfig @@ -328,7 +328,7 @@ menu "OpenThread" menu "Thread Memory Allocation" depends on (SPIRAM_USE_CAPS_ALLOC || SPIRAM_USE_MALLOC) - config OPENTHREAD_MEM_ALLOC_EXTERNAL + config OPENTHREAD_PLATFORM_MALLOC_CAP_SPIRAM bool 'Allocate memory from PSRAM' default y help diff --git a/components/openthread/private_include/esp_openthread_ncp.h b/components/openthread/private_include/esp_openthread_ncp.h index 39f9e9532d..507d305daa 100644 --- a/components/openthread/private_include/esp_openthread_ncp.h +++ b/components/openthread/private_include/esp_openthread_ncp.h @@ -12,4 +12,6 @@ #define SPINEL_PROP_VENDOR_ESP_SET_PENDINGMODE (SPINEL_PROP_VENDOR_ESP__BEGIN + 2) +#define SPINEL_PROP_VENDOR_ESP_COEX_EVENT (SPINEL_PROP_VENDOR_ESP__BEGIN + 3) + #endif diff --git a/components/openthread/private_include/esp_openthread_radio.h b/components/openthread/private_include/esp_openthread_radio.h index d3fa70aa2c..98eaec8367 100644 --- a/components/openthread/private_include/esp_openthread_radio.h +++ b/components/openthread/private_include/esp_openthread_radio.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -12,6 +12,10 @@ #include "esp_openthread_types.h" #include "openthread/instance.h" +#if !CONFIG_IEEE802154_TEST && (CONFIG_ESP_COEX_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE) +#include "esp_coex_i154.h" +#endif + #ifdef __cplusplus extern "C" { #endif @@ -53,6 +57,27 @@ void esp_openthread_radio_update(esp_openthread_mainloop_context_t *mainloop); */ esp_err_t esp_openthread_radio_process(otInstance *instance, const esp_openthread_mainloop_context_t *mainloop); + +#if !CONFIG_IEEE802154_TEST && (CONFIG_ESP_COEX_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE) + +/** + * @brief Set the coexist config. + * + * @param[in] config The config of coexist. + * + */ +void esp_openthread_set_coex_config(esp_ieee802154_coex_config_t config); + +/** + * @brief Get the coexist config. + * + * @return + * - The config of coexist. + * + */ +esp_ieee802154_coex_config_t esp_openthread_get_coex_config(void); +#endif + #ifdef __cplusplus } #endif 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 8a2012dc33..65f3289381 100644 --- a/components/openthread/private_include/openthread-core-esp32x-ftd-config.h +++ b/components/openthread/private_include/openthread-core-esp32x-ftd-config.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -493,6 +493,17 @@ #ifndef OPENTHREAD_POSIX_CONFIG_RCP_TIME_SYNC_INTERVAL #define OPENTHREAD_POSIX_CONFIG_RCP_TIME_SYNC_INTERVAL (60 * 1000 * 1000) #endif + +#if !CONFIG_IEEE802154_TEST && (CONFIG_ESP_COEX_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE) +/** + * @def OPENTHREAD_SPINEL_CONFIG_VENDOR_HOOK_ENABLE + * + * Enables compilation of vendor specific code for Spinel + */ +#ifndef OPENTHREAD_SPINEL_CONFIG_VENDOR_HOOK_ENABLE +#define OPENTHREAD_SPINEL_CONFIG_VENDOR_HOOK_ENABLE 1 +#endif +#endif #endif // !CONFIG_OPENTHREAD_RADIO_NATIVE #if CONFIG_OPENTHREAD_LINK_METRICS diff --git a/components/openthread/private_include/openthread-core-esp32x-spinel-config.h b/components/openthread/private_include/openthread-core-esp32x-spinel-config.h index a2562f3faf..350a21c6dc 100644 --- a/components/openthread/private_include/openthread-core-esp32x-spinel-config.h +++ b/components/openthread/private_include/openthread-core-esp32x-spinel-config.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -50,11 +50,15 @@ #define OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT 3 #endif +/** + * @def OPENTHREAD_SPINEL_CONFIG_VENDOR_HOOK_ENABLE + * + * Enables compilation of vendor specific code for Spinel + */ #ifndef OPENTHREAD_SPINEL_CONFIG_VENDOR_HOOK_ENABLE #define OPENTHREAD_SPINEL_CONFIG_VENDOR_HOOK_ENABLE 1 #endif - /** * @def OPENTHREAD_SPINEL_CONFIG_COMPATIBILITY_ERROR_CALLBACK_ENABLE * diff --git a/components/openthread/src/ncp/esp_openthread_ncp.cpp b/components/openthread/src/ncp/esp_openthread_ncp.cpp index eefeda5017..69fc387c9c 100644 --- a/components/openthread/src/ncp/esp_openthread_ncp.cpp +++ b/components/openthread/src/ncp/esp_openthread_ncp.cpp @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -9,6 +9,10 @@ #include "esp_openthread_ncp.h" #include "ncp_base.hpp" +#if !CONFIG_IEEE802154_TEST && (CONFIG_ESP_COEX_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE) +#include "esp_coex_i154.h" +#endif + #if CONFIG_OPENTHREAD_RCP_UART #include "utils/uart.h" #endif @@ -65,6 +69,16 @@ otError NcpBase::VendorGetPropertyHandler(spinel_prop_key_t aPropKey) switch (aPropKey) { + case SPINEL_PROP_VENDOR_ESP_COEX_EVENT: { +#if !CONFIG_IEEE802154_TEST && (CONFIG_ESP_COEX_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE) + esp_ieee802154_coex_config_t config = esp_ieee802154_get_coex_config(); + const uint8_t *args = reinterpret_cast(&config); + error = mEncoder.WriteDataWithLen(args, sizeof(esp_ieee802154_coex_config_t)); +#else + error = OT_ERROR_NOT_IMPLEMENTED; +#endif + break; + } default: error = OT_ERROR_NOT_FOUND; @@ -95,6 +109,23 @@ otError NcpBase::VendorSetPropertyHandler(spinel_prop_key_t aPropKey) esp_ieee802154_set_pending_mode(static_cast(pending_mode)); break; } + case SPINEL_PROP_VENDOR_ESP_COEX_EVENT: { +#if !CONFIG_IEEE802154_TEST && (CONFIG_ESP_COEX_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE) + const uint8_t *args = nullptr; + uint16_t len = 0; + mDecoder.ReadDataWithLen(args, len); + if (len == sizeof(esp_ieee802154_coex_config_t)) { + esp_ieee802154_coex_config_t config; + memcpy(&config, args, len); + esp_ieee802154_set_coex_config(config); + } else { + error = OT_ERROR_INVALID_ARGS; + } +#else + error = OT_ERROR_NOT_IMPLEMENTED; +#endif + break; + } default: error = OT_ERROR_NOT_FOUND; diff --git a/components/openthread/src/port/esp_openthread_radio.c b/components/openthread/src/port/esp_openthread_radio.c index f87cb68291..c9ce9032ba 100644 --- a/components/openthread/src/port/esp_openthread_radio.c +++ b/components/openthread/src/port/esp_openthread_radio.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -32,6 +32,10 @@ #include "utils/link_metrics.h" #include "utils/mac_frame.h" +#if !CONFIG_IEEE802154_TEST && (CONFIG_ESP_COEX_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE) +#include "esp_coex_i154.h" +#endif + #define ESP_RECEIVE_SENSITIVITY -120 #define ESP_OPENTHREAD_XTAL_ACCURACY CONFIG_OPENTHREAD_XTAL_ACCURACY #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE @@ -798,3 +802,15 @@ void otPlatRadioSetRxOnWhenIdle(otInstance *aInstance, bool aEnable) esp_ieee802154_set_rx_when_idle(aEnable); } #endif + +#if !CONFIG_IEEE802154_TEST && (CONFIG_ESP_COEX_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE) +void esp_openthread_set_coex_config(esp_ieee802154_coex_config_t config) +{ + esp_ieee802154_set_coex_config(config); +} + +esp_ieee802154_coex_config_t esp_openthread_get_coex_config(void) +{ + return esp_ieee802154_get_coex_config(); +} +#endif diff --git a/components/openthread/src/port/esp_openthread_radio_spinel.cpp b/components/openthread/src/port/esp_openthread_radio_spinel.cpp index 67cb2bb66a..b3e3a5bdd2 100644 --- a/components/openthread/src/port/esp_openthread_radio_spinel.cpp +++ b/components/openthread/src/port/esp_openthread_radio_spinel.cpp @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -56,6 +56,35 @@ static const esp_openthread_radio_config_t *s_esp_openthread_radio_config = NULL static esp_openthread_compatibility_error_callback s_compatibility_error_callback = NULL; +#if !CONFIG_IEEE802154_TEST && (CONFIG_ESP_COEX_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE) + +#define SPINEL_PROP_VENDOR_ESP_COEX_EVENT (SPINEL_PROP_VENDOR_ESP__BEGIN + 3) + +static esp_ieee802154_coex_config_t s_coex_config = { + .idle = IEEE802154_IDLE, + .txrx = IEEE802154_LOW, + .txrx_at = IEEE802154_MIDDLE, +}; + +static void esp_openthread_restore_coex_config(void *context) +{ + esp_openthread_set_coex_config(s_coex_config); +} + +static esp_err_t esp_openthread_radio_spinel_coex_config_init(void) +{ + s_radio.SetVendorRestorePropertiesCallback(esp_openthread_restore_coex_config, esp_openthread_get_instance()); + esp_ieee802154_coex_config_t coex_config; + uint16_t coex_config_len = 0; + ESP_RETURN_ON_ERROR(s_radio.Get(SPINEL_PROP_VENDOR_ESP_COEX_EVENT, SPINEL_DATATYPE_DATA_WLEN_S, &coex_config, &coex_config_len), + OT_PLAT_LOG_TAG, "Fail to get coex config"); + ESP_RETURN_ON_FALSE(coex_config_len == sizeof(esp_ieee802154_coex_config_t), ESP_FAIL, OT_PLAT_LOG_TAG, + "Fail to get coex config"); + s_coex_config = coex_config; + return ESP_OK; +} +#endif + static void esp_openthread_radio_config_set(const esp_openthread_radio_config_t *config) { s_esp_openthread_radio_config = config; @@ -109,6 +138,9 @@ esp_err_t esp_openthread_radio_init(const esp_openthread_platform_config_t *conf s_spinel_driver.Init(s_spinel_interface.GetSpinelInterface(), true, iidList, ot::Spinel::kSpinelHeaderMaxNumIid); s_radio.SetCompatibilityErrorCallback(ot_spinel_compatibility_error_callback, esp_openthread_get_instance()); s_radio.Init(/*skip_rcp_compatibility_check=*/false, /*reset_radio=*/true, &s_spinel_driver, s_radio_caps, /*RCP_time_sync=*/true); +#if !CONFIG_IEEE802154_TEST && (CONFIG_ESP_COEX_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE) + ESP_RETURN_ON_ERROR(esp_openthread_radio_spinel_coex_config_init(), OT_PLAT_LOG_TAG, "Coex config init failed"); +#endif #if CONFIG_OPENTHREAD_RADIO_SPINEL_SPI // CONFIG_OPENTHREAD_RADIO_SPINEL_SPI ESP_RETURN_ON_ERROR(s_spinel_interface.GetSpinelInterface().AfterRadioInit(), OT_PLAT_LOG_TAG, "Spinel interface init failed"); #endif @@ -156,6 +188,8 @@ esp_err_t esp_openthread_rcp_init(void) void esp_openthread_radio_deinit(void) { s_radio.Deinit(); + s_spinel_driver.Deinit(); + s_spinel_interface.GetSpinelInterface().Disable(); esp_openthread_platform_workflow_unregister(radiospinel_workflow); } @@ -467,3 +501,39 @@ uint16_t otPlatTimeGetXtalAccuracy(void) { return CONFIG_OPENTHREAD_XTAL_ACCURACY; } + +#if !CONFIG_IEEE802154_TEST && (CONFIG_ESP_COEX_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE) + +void esp_openthread_set_coex_config(esp_ieee802154_coex_config_t config) +{ + otError err = s_radio.Set(SPINEL_PROP_VENDOR_ESP_COEX_EVENT, SPINEL_DATATYPE_DATA_WLEN_S, &s_coex_config, sizeof(esp_ieee802154_coex_config_t)); + ESP_RETURN_ON_FALSE(err == OT_ERROR_NONE, , OT_PLAT_LOG_TAG, "Fail to set coex config"); + s_coex_config = config; +} + +esp_ieee802154_coex_config_t esp_openthread_get_coex_config(void) +{ + return s_coex_config; +} + +namespace ot { +namespace Spinel { + +otError RadioSpinel::VendorHandleValueIs(spinel_prop_key_t aPropKey) +{ + otError error = OT_ERROR_NONE; + + switch (aPropKey) + { + default: + ESP_LOGW(OT_PLAT_LOG_TAG, "Not Implemented!"); + error = OT_ERROR_NOT_FOUND; + break; + } + return error; +} + +} // namespace Spinel +} // namespace ot + +#endif diff --git a/components/openthread/src/port/esp_openthread_state.c b/components/openthread/src/port/esp_openthread_state.c index 33d1c70ad4..676c6d1133 100644 --- a/components/openthread/src/port/esp_openthread_state.c +++ b/components/openthread/src/port/esp_openthread_state.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -62,6 +63,12 @@ static void handle_ot_netdata_change(void) static void handle_ot_role_change(otInstance* instance) { +#if !CONFIG_IEEE802154_TEST && (CONFIG_ESP_COEX_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE) + otLinkModeConfig linkmode = otThreadGetLinkMode(instance); + esp_ieee802154_coex_config_t config = esp_openthread_get_coex_config(); + config.txrx = (linkmode.mRxOnWhenIdle) ? IEEE802154_LOW : IEEE802154_MIDDLE; + esp_openthread_set_coex_config(config); +#endif static otDeviceRole s_previous_role = OT_DEVICE_ROLE_DISABLED; otDeviceRole role = otThreadGetDeviceRole(instance); esp_err_t ret = ESP_OK; diff --git a/examples/openthread/.build-test-rules.yml b/examples/openthread/.build-test-rules.yml index 78cbde9eff..94eae8f5e8 100644 --- a/examples/openthread/.build-test-rules.yml +++ b/examples/openthread/.build-test-rules.yml @@ -22,7 +22,8 @@ examples/openthread/ot_br: enable: - - if: SOC_WIFI_SUPPORTED == 1 and IDF_TARGET != "esp32c61" + - if: (SOC_WIFI_SUPPORTED == 1 and IDF_TARGET != "esp32c61") and CONFIG_NAME != "native_radio" + - if: (SOC_WIFI_SUPPORTED == 1 and IDF_TARGET != "esp32c61") and (SOC_IEEE802154_SUPPORTED == 1 and CONFIG_NAME == "native_radio") disable_test: - if: IDF_TARGET not in ["esp32s3"] reason: only test on esp32s3 diff --git a/examples/openthread/ot_br/sdkconfig.ci.ext_coex b/examples/openthread/ot_br/sdkconfig.ci.ext_coex new file mode 100644 index 0000000000..10e03f180e --- /dev/null +++ b/examples/openthread/ot_br/sdkconfig.ci.ext_coex @@ -0,0 +1,2 @@ +CONFIG_EXTERNAL_COEX_ENABLE=y +CONFIG_ESP_COEX_SW_COEXIST_ENABLE=n diff --git a/examples/openthread/ot_br/sdkconfig.ci.native_radio b/examples/openthread/ot_br/sdkconfig.ci.native_radio new file mode 100644 index 0000000000..4adc4205ab --- /dev/null +++ b/examples/openthread/ot_br/sdkconfig.ci.native_radio @@ -0,0 +1,2 @@ +CONFIG_OPENTHREAD_RADIO_NATIVE=y +CONFIG_ESP_COEX_SW_COEXIST_ENABLE=y diff --git a/examples/openthread/ot_br/sdkconfig.ci.spiram b/examples/openthread/ot_br/sdkconfig.ci.spiram new file mode 100644 index 0000000000..f4b071ddb0 --- /dev/null +++ b/examples/openthread/ot_br/sdkconfig.ci.spiram @@ -0,0 +1,6 @@ +CONFIG_IDF_TARGET="esp32s3" +CONFIG_IDF_TARGET_ESP32S3=y +CONFIG_SPIRAM=y +CONFIG_SPIRAM_USE_MALLOC=y +CONFIG_OPENTHREAD_PLATFORM_MALLOC_CAP_SPIRAM=y +CONFIG_OPENTHREAD_PLATFORM_MSGPOOL_MANAGEMENT=y diff --git a/examples/openthread/ot_cli/sdkconfig.ci.ext_coex b/examples/openthread/ot_cli/sdkconfig.ci.ext_coex new file mode 100644 index 0000000000..55c9b2374f --- /dev/null +++ b/examples/openthread/ot_cli/sdkconfig.ci.ext_coex @@ -0,0 +1 @@ +CONFIG_EXTERNAL_COEX_ENABLE=y diff --git a/examples/openthread/ot_rcp/sdkconfig.ci.ext_coex b/examples/openthread/ot_rcp/sdkconfig.ci.ext_coex new file mode 100644 index 0000000000..10e03f180e --- /dev/null +++ b/examples/openthread/ot_rcp/sdkconfig.ci.ext_coex @@ -0,0 +1,2 @@ +CONFIG_EXTERNAL_COEX_ENABLE=y +CONFIG_ESP_COEX_SW_COEXIST_ENABLE=n diff --git a/examples/openthread/ot_trel/CMakeLists.txt b/examples/openthread/ot_trel/CMakeLists.txt index b12d49bfa3..af5dad3d3c 100644 --- a/examples/openthread/ot_trel/CMakeLists.txt +++ b/examples/openthread/ot_trel/CMakeLists.txt @@ -3,4 +3,4 @@ cmake_minimum_required(VERSION 3.16) include($ENV{IDF_PATH}/tools/cmake/project.cmake) -project(esp_ot_cli) +project(esp_ot_trel) diff --git a/examples/openthread/ot_trel/sdkconfig.defaults b/examples/openthread/ot_trel/sdkconfig.defaults index 07de5fdbf9..0e5eb34891 100644 --- a/examples/openthread/ot_trel/sdkconfig.defaults +++ b/examples/openthread/ot_trel/sdkconfig.defaults @@ -44,3 +44,9 @@ CONFIG_COMPILER_OPTIMIZATION_SIZE=y # Example connect CONFIG_EXAMPLE_CONNECT_THREAD=n + +# +# Wireless Coexistence +# +CONFIG_ESP_COEX_SW_COEXIST_ENABLE=n +CONFIG_EXTERNAL_COEX_ENABLE=n