From ca9caf1fee471e8f4a0f736e4a3958d5d837a78f Mon Sep 17 00:00:00 2001 From: Xu Si Yu Date: Tue, 24 Sep 2024 10:35:54 +0800 Subject: [PATCH] feat(openthread): support vendor hook for rcp spi --- components/openthread/CMakeLists.txt | 7 ++++ .../openthread/src/ncp/esp_openthread_ncp.cpp | 5 +-- .../src/ncp/esp_openthread_ncp_hdlc.cpp | 6 +--- .../src/ncp/esp_openthread_ncp_spi.cpp | 29 +++++++++++++++ examples/openthread/.build-test-rules.yml | 5 ++- examples/openthread/ot_br/sdkconfig.ci.br_spi | 1 + examples/openthread/ot_cli/sdkconfig.ci.cli | 0 .../openthread/ot_cli/sdkconfig.ci.cli_c6 | 2 -- .../openthread/ot_cli/sdkconfig.ci.cli_h2 | 2 -- .../ot_cli/sdkconfig.ci.disable_cli | 2 -- .../openthread/ot_rcp/sdkconfig.ci.rcp_spi | 1 + ...sdkconfig.ci.rcp => sdkconfig.ci.rcp_uart} | 0 ...onfig.ci.sleepy_c6 => sdkconfig.ci.sleepy} | 2 -- .../light_sleep/sdkconfig.ci.sleepy_h2 | 7 ---- .../light_sleep/sdkconfig.defaults.esp32c6 | 2 -- .../light_sleep/sdkconfig.defaults.esp32h2 | 1 - examples/openthread/pytest_otbr.py | 35 +++++++++++-------- 17 files changed, 62 insertions(+), 45 deletions(-) create mode 100644 components/openthread/src/ncp/esp_openthread_ncp_spi.cpp create mode 100644 examples/openthread/ot_br/sdkconfig.ci.br_spi create mode 100644 examples/openthread/ot_cli/sdkconfig.ci.cli delete mode 100644 examples/openthread/ot_cli/sdkconfig.ci.cli_c6 delete mode 100644 examples/openthread/ot_cli/sdkconfig.ci.cli_h2 create mode 100644 examples/openthread/ot_rcp/sdkconfig.ci.rcp_spi rename examples/openthread/ot_rcp/{sdkconfig.ci.rcp => sdkconfig.ci.rcp_uart} (100%) rename examples/openthread/ot_sleepy_device/light_sleep/{sdkconfig.ci.sleepy_c6 => sdkconfig.ci.sleepy} (78%) delete mode 100644 examples/openthread/ot_sleepy_device/light_sleep/sdkconfig.ci.sleepy_h2 delete mode 100644 examples/openthread/ot_sleepy_device/light_sleep/sdkconfig.defaults.esp32h2 diff --git a/components/openthread/CMakeLists.txt b/components/openthread/CMakeLists.txt index 308e5aed4a..17717b80d3 100644 --- a/components/openthread/CMakeLists.txt +++ b/components/openthread/CMakeLists.txt @@ -156,6 +156,13 @@ if(CONFIG_OPENTHREAD_ENABLED) if(CONFIG_OPENTHREAD_NCP_VENDOR_HOOK) list(APPEND src_dirs "src/ncp") + if(CONFIG_OPENTHREAD_RCP_UART) + list(APPEND exclude_srcs + "src/ncp/esp_openthread_ncp_spi.cpp") + elseif(CONFIG_OPENTHREAD_RCP_SPI) + list(APPEND exclude_srcs + "src/ncp/esp_openthread_ncp_hdlc.cpp") + endif() endif() if(NOT CONFIG_OPENTHREAD_DNS64_CLIENT) diff --git a/components/openthread/src/ncp/esp_openthread_ncp.cpp b/components/openthread/src/ncp/esp_openthread_ncp.cpp index 7e5127f869..eefeda5017 100644 --- a/components/openthread/src/ncp/esp_openthread_ncp.cpp +++ b/components/openthread/src/ncp/esp_openthread_ncp.cpp @@ -4,12 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include "sdkconfig.h" #include "esp_ieee802154.h" #include "esp_openthread_ncp.h" #include "ncp_base.hpp" -#if OPENTHREAD_ENABLE_NCP_VENDOR_HOOK - #if CONFIG_OPENTHREAD_RCP_UART #include "utils/uart.h" #endif @@ -107,5 +106,3 @@ otError NcpBase::VendorSetPropertyHandler(spinel_prop_key_t aPropKey) } // namespace Ncp } // namespace ot - -#endif // #if OPENTHREAD_ENABLE_NCP_VENDOR_HOOK diff --git a/components/openthread/src/ncp/esp_openthread_ncp_hdlc.cpp b/components/openthread/src/ncp/esp_openthread_ncp_hdlc.cpp index 0e8a3dbb88..6b86b6d935 100644 --- a/components/openthread/src/ncp/esp_openthread_ncp_hdlc.cpp +++ b/components/openthread/src/ncp/esp_openthread_ncp_hdlc.cpp @@ -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 */ @@ -7,8 +7,6 @@ #include "common/new.hpp" #include "ncp_hdlc.hpp" -#if OPENTHREAD_ENABLE_NCP_VENDOR_HOOK - namespace ot { namespace Ncp { @@ -29,5 +27,3 @@ extern "C" void otNcpHdlcInit(otInstance *aInstance, otNcpHdlcSendCallback aSend } // namespace Ncp } // namespace ot - -#endif // #if OPENTHREAD_ENABLE_NCP_VENDOR_HOOK diff --git a/components/openthread/src/ncp/esp_openthread_ncp_spi.cpp b/components/openthread/src/ncp/esp_openthread_ncp_spi.cpp new file mode 100644 index 0000000000..d85c918aad --- /dev/null +++ b/components/openthread/src/ncp/esp_openthread_ncp_spi.cpp @@ -0,0 +1,29 @@ +/* + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "common/new.hpp" +#include "ncp_spi.hpp" + +namespace ot { +namespace Ncp { + +static OT_DEFINE_ALIGNED_VAR(sNcpRaw, sizeof(NcpSpi), uint64_t); + +extern "C" void otNcpSpiInit(otInstance *aInstance) +{ + NcpSpi *ncpSpi = nullptr; + Instance *instance = static_cast(aInstance); + + ncpSpi = new (&sNcpRaw) NcpSpi(instance); + + if (ncpSpi == nullptr || ncpSpi != NcpBase::GetNcpInstance()) + { + OT_ASSERT(false); + } +} + +} // namespace Ncp +} // namespace ot diff --git a/examples/openthread/.build-test-rules.yml b/examples/openthread/.build-test-rules.yml index 0ad7d9b1a8..9e51727920 100644 --- a/examples/openthread/.build-test-rules.yml +++ b/examples/openthread/.build-test-rules.yml @@ -40,9 +40,8 @@ examples/openthread/ot_rcp: enable: - if: SOC_IEEE802154_SUPPORTED == 1 disable_test: - - if: IDF_TARGET == "esp32h2" - temporary: true - reason: only test on esp32c6 + - if: IDF_TARGET not in ["esp32h2", "esp32c6"] + reason: only test on esp32h2 and esp32c6 <<: *openthread_dependencies examples/openthread/ot_sleepy_device/deep_sleep: diff --git a/examples/openthread/ot_br/sdkconfig.ci.br_spi b/examples/openthread/ot_br/sdkconfig.ci.br_spi new file mode 100644 index 0000000000..1778799eb7 --- /dev/null +++ b/examples/openthread/ot_br/sdkconfig.ci.br_spi @@ -0,0 +1 @@ +CONFIG_OPENTHREAD_RADIO_SPINEL_SPI=y diff --git a/examples/openthread/ot_cli/sdkconfig.ci.cli b/examples/openthread/ot_cli/sdkconfig.ci.cli new file mode 100644 index 0000000000..e69de29bb2 diff --git a/examples/openthread/ot_cli/sdkconfig.ci.cli_c6 b/examples/openthread/ot_cli/sdkconfig.ci.cli_c6 deleted file mode 100644 index a7f4dfb822..0000000000 --- a/examples/openthread/ot_cli/sdkconfig.ci.cli_c6 +++ /dev/null @@ -1,2 +0,0 @@ -CONFIG_IDF_TARGET="esp32c6" -CONFIG_IDF_TARGET_ESP32C6=y diff --git a/examples/openthread/ot_cli/sdkconfig.ci.cli_h2 b/examples/openthread/ot_cli/sdkconfig.ci.cli_h2 deleted file mode 100644 index 485c06eac5..0000000000 --- a/examples/openthread/ot_cli/sdkconfig.ci.cli_h2 +++ /dev/null @@ -1,2 +0,0 @@ -CONFIG_IDF_TARGET="esp32h2" -CONFIG_IDF_TARGET_ESP32H2=y diff --git a/examples/openthread/ot_cli/sdkconfig.ci.disable_cli b/examples/openthread/ot_cli/sdkconfig.ci.disable_cli index 51c321da5e..a281edc22b 100644 --- a/examples/openthread/ot_cli/sdkconfig.ci.disable_cli +++ b/examples/openthread/ot_cli/sdkconfig.ci.disable_cli @@ -1,4 +1,2 @@ -CONFIG_IDF_TARGET="esp32h2" -CONFIG_IDF_TARGET_ESP32H2=y CONFIG_OPENTHREAD_CLI=n CONFIG_OPENTHREAD_CLI_ESP_EXTENSION=n diff --git a/examples/openthread/ot_rcp/sdkconfig.ci.rcp_spi b/examples/openthread/ot_rcp/sdkconfig.ci.rcp_spi new file mode 100644 index 0000000000..87b895575b --- /dev/null +++ b/examples/openthread/ot_rcp/sdkconfig.ci.rcp_spi @@ -0,0 +1 @@ +CONFIG_OPENTHREAD_RCP_SPI=y diff --git a/examples/openthread/ot_rcp/sdkconfig.ci.rcp b/examples/openthread/ot_rcp/sdkconfig.ci.rcp_uart similarity index 100% rename from examples/openthread/ot_rcp/sdkconfig.ci.rcp rename to examples/openthread/ot_rcp/sdkconfig.ci.rcp_uart diff --git a/examples/openthread/ot_sleepy_device/light_sleep/sdkconfig.ci.sleepy_c6 b/examples/openthread/ot_sleepy_device/light_sleep/sdkconfig.ci.sleepy similarity index 78% rename from examples/openthread/ot_sleepy_device/light_sleep/sdkconfig.ci.sleepy_c6 rename to examples/openthread/ot_sleepy_device/light_sleep/sdkconfig.ci.sleepy index c4abd6d670..9f3ddc2c93 100644 --- a/examples/openthread/ot_sleepy_device/light_sleep/sdkconfig.ci.sleepy_c6 +++ b/examples/openthread/ot_sleepy_device/light_sleep/sdkconfig.ci.sleepy @@ -1,5 +1,3 @@ -CONFIG_IDF_TARGET="esp32c6" -CONFIG_IDF_TARGET_ESP32C6=y CONFIG_OPENTHREAD_NETWORK_CHANNEL=12 CONFIG_OPENTHREAD_NETWORK_MASTERKEY="aabbccddeeff00112233445566778899" CONFIG_ESP_SLEEP_DEBUG=y diff --git a/examples/openthread/ot_sleepy_device/light_sleep/sdkconfig.ci.sleepy_h2 b/examples/openthread/ot_sleepy_device/light_sleep/sdkconfig.ci.sleepy_h2 deleted file mode 100644 index b7fa32376f..0000000000 --- a/examples/openthread/ot_sleepy_device/light_sleep/sdkconfig.ci.sleepy_h2 +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG_IDF_TARGET="esp32h2" -CONFIG_IDF_TARGET_ESP32H2=y -CONFIG_OPENTHREAD_NETWORK_CHANNEL=12 -CONFIG_OPENTHREAD_NETWORK_MASTERKEY="aabbccddeeff00112233445566778899" -CONFIG_ESP_SLEEP_DEBUG=y -CONFIG_LOG_MAXIMUM_LEVEL_DEBUG=y -CONFIG_ESP_SLEEP_CACHE_SAFE_ASSERTION=y diff --git a/examples/openthread/ot_sleepy_device/light_sleep/sdkconfig.defaults.esp32c6 b/examples/openthread/ot_sleepy_device/light_sleep/sdkconfig.defaults.esp32c6 index 2c90c3e7ee..229cb8cc6b 100644 --- a/examples/openthread/ot_sleepy_device/light_sleep/sdkconfig.defaults.esp32c6 +++ b/examples/openthread/ot_sleepy_device/light_sleep/sdkconfig.defaults.esp32c6 @@ -1,5 +1,3 @@ -CONFIG_IDF_TARGET="esp32c6" - # # Sleep Config # diff --git a/examples/openthread/ot_sleepy_device/light_sleep/sdkconfig.defaults.esp32h2 b/examples/openthread/ot_sleepy_device/light_sleep/sdkconfig.defaults.esp32h2 deleted file mode 100644 index ba2980822c..0000000000 --- a/examples/openthread/ot_sleepy_device/light_sleep/sdkconfig.defaults.esp32h2 +++ /dev/null @@ -1 +0,0 @@ -CONFIG_IDF_TARGET="esp32h2" diff --git a/examples/openthread/pytest_otbr.py b/examples/openthread/pytest_otbr.py index ea9dc3353d..604862d8d3 100644 --- a/examples/openthread/pytest_otbr.py +++ b/examples/openthread/pytest_otbr.py @@ -91,11 +91,16 @@ default_cli_ot_para = ocf.thread_parameter('router', '', '', '', False) @pytest.mark.flaky(reruns=1, reruns_delay=1) @pytest.mark.parametrize( 'config, count, app_path, target', [ - ('rcp|cli_h2|br', 3, + ('rcp_uart|cli|br', 3, f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}' f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}' f'|{os.path.join(os.path.dirname(__file__), "ot_br")}', 'esp32c6|esp32h2|esp32s3'), + ('rcp_spi|cli|br_spi', 3, + f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}' + f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}' + f'|{os.path.join(os.path.dirname(__file__), "ot_br")}', + 'esp32h2|esp32c6|esp32s3'), ], indirect=True, ) @@ -161,7 +166,7 @@ def formBasicWiFiThreadNetwork(br:IdfDut, cli:IdfDut) -> None: @pytest.mark.flaky(reruns=1, reruns_delay=1) @pytest.mark.parametrize( 'config, count, app_path, target', [ - ('rcp|cli_h2|br', 3, + ('rcp_uart|cli|br', 3, f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}' f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}' f'|{os.path.join(os.path.dirname(__file__), "ot_br")}', @@ -210,7 +215,7 @@ def test_Bidirectional_IPv6_connectivity(Init_interface:bool, dut: Tuple[IdfDut, @pytest.mark.flaky(reruns=1, reruns_delay=1) @pytest.mark.parametrize( 'config, count, app_path, target', [ - ('rcp|cli_h2|br', 3, + ('rcp_uart|cli|br', 3, f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}' f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}' f'|{os.path.join(os.path.dirname(__file__), "ot_br")}', @@ -260,7 +265,7 @@ def test_multicast_forwarding_A(Init_interface:bool, dut: Tuple[IdfDut, IdfDut, @pytest.mark.flaky(reruns=1, reruns_delay=1) @pytest.mark.parametrize( 'config, count, app_path, target', [ - ('rcp|cli_h2|br', 3, + ('rcp_uart|cli|br', 3, f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}' f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}' f'|{os.path.join(os.path.dirname(__file__), "ot_br")}', @@ -311,7 +316,7 @@ def test_multicast_forwarding_B(Init_interface:bool, dut: Tuple[IdfDut, IdfDut, @pytest.mark.flaky(reruns=1, reruns_delay=1) @pytest.mark.parametrize( 'config, count, app_path, target', [ - ('rcp|cli_h2|br', 3, + ('rcp_uart|cli|br', 3, f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}' f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}' f'|{os.path.join(os.path.dirname(__file__), "ot_br")}', @@ -367,7 +372,7 @@ def test_service_discovery_of_Thread_device(Init_interface:bool, Init_avahi:bool @pytest.mark.flaky(reruns=1, reruns_delay=1) @pytest.mark.parametrize( 'config, count, app_path, target', [ - ('rcp|cli_h2|br', 3, + ('rcp_uart|cli|br', 3, f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}' f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}' f'|{os.path.join(os.path.dirname(__file__), "ot_br")}', @@ -430,7 +435,7 @@ def test_service_discovery_of_WiFi_device(Init_interface:bool, Init_avahi:bool, @pytest.mark.flaky(reruns=1, reruns_delay=1) @pytest.mark.parametrize( 'config, count, app_path, target', [ - ('rcp|cli_h2|br', 3, + ('rcp_uart|cli|br', 3, f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}' f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}' f'|{os.path.join(os.path.dirname(__file__), "ot_br")}', @@ -465,7 +470,7 @@ def test_ICMP_NAT64(Init_interface:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> @pytest.mark.flaky(reruns=1, reruns_delay=1) @pytest.mark.parametrize( 'config, count, app_path, target', [ - ('rcp|cli_h2|br', 3, + ('rcp_uart|cli|br', 3, f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}' f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}' f'|{os.path.join(os.path.dirname(__file__), "ot_br")}', @@ -518,7 +523,7 @@ def test_UDP_NAT64(Init_interface:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> N @pytest.mark.flaky(reruns=1, reruns_delay=1) @pytest.mark.parametrize( 'config, count, app_path, target', [ - ('rcp|cli_h2|br', 3, + ('rcp_uart|cli|br', 3, f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}' f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}' f'|{os.path.join(os.path.dirname(__file__), "ot_br")}', @@ -575,11 +580,11 @@ def test_TCP_NAT64(Init_interface:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> N @pytest.mark.openthread_sleep @pytest.mark.parametrize( 'config, count, app_path, target', [ - ('cli_h2|sleepy_c6', 2, + ('cli|sleepy', 2, f'{os.path.join(os.path.dirname(__file__), "ot_cli")}' f'|{os.path.join(os.path.dirname(__file__), "ot_sleepy_device/light_sleep")}', 'esp32h2|esp32c6'), - ('cli_c6|sleepy_h2', 2, + ('cli|sleepy', 2, f'{os.path.join(os.path.dirname(__file__), "ot_cli")}' f'|{os.path.join(os.path.dirname(__file__), "ot_sleepy_device/light_sleep")}', 'esp32c6|esp32h2'), @@ -627,7 +632,7 @@ def test_ot_sleepy_device(dut: Tuple[IdfDut, IdfDut]) -> None: @pytest.mark.flaky(reruns=1, reruns_delay=1) @pytest.mark.parametrize( 'config, count, app_path, target', [ - ('rcp|br', 2, + ('rcp_uart|br', 2, f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}' f'|{os.path.join(os.path.dirname(__file__), "ot_br")}', 'esp32c6|esp32s3'), @@ -666,7 +671,7 @@ def test_basic_startup(dut: Tuple[IdfDut, IdfDut]) -> None: @pytest.mark.flaky(reruns=1, reruns_delay=1) @pytest.mark.parametrize( 'config, count, app_path, target', [ - ('rcp|cli_h2|br', 3, + ('rcp_uart|cli|br', 3, f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}' f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}' f'|{os.path.join(os.path.dirname(__file__), "ot_br")}', @@ -703,7 +708,7 @@ def test_NAT64_DNS(Init_interface:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> N @pytest.mark.flaky(reruns=1, reruns_delay=1) @pytest.mark.parametrize( 'config, count, app_path, target', [ - ('rcp|br', 2, + ('rcp_uart|br', 2, f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}' f'|{os.path.join(os.path.dirname(__file__), "ot_br")}', 'esp32c6|esp32s3'), @@ -761,7 +766,7 @@ def test_br_meshcop(Init_interface:bool, Init_avahi:bool, dut: Tuple[IdfDut, Idf @pytest.mark.flaky(reruns=1, reruns_delay=1) @pytest.mark.parametrize( 'config, count, app_path, target', [ - ('rcp|cli_h2|br', 3, + ('rcp_uart|cli|br', 3, f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}' f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}' f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',