From c3398f33737a56c6e5a55dffd6fa61dd163943a6 Mon Sep 17 00:00:00 2001 From: Xu Si Yu Date: Fri, 29 Mar 2024 12:23:29 +0800 Subject: [PATCH 1/3] fix(vfs): make case eventfd_select_block exit normally --- .../vfs/test_apps/main/test_vfs_eventfd.c | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/components/vfs/test_apps/main/test_vfs_eventfd.c b/components/vfs/test_apps/main/test_vfs_eventfd.c index 11ea46997d..d250b7c33b 100644 --- a/components/vfs/test_apps/main/test_vfs_eventfd.c +++ b/components/vfs/test_apps/main/test_vfs_eventfd.c @@ -351,20 +351,23 @@ TEST_CASE("eventfd multiple selects", "[vfs][eventfd]") } typedef struct { - int *value; + QueueHandle_t queue; int fd; } select_block_task_args_t; static void select_block_task(void *arg) { - int fd = ((select_block_task_args_t *)arg)->fd; + select_block_task_args_t *select_arg = (select_block_task_args_t *)arg; + int fd = select_arg->fd; fd_set read_fds; FD_ZERO(&read_fds); FD_SET(fd, &read_fds); - select(fd + 1, &read_fds, NULL, NULL, NULL); - *(((select_block_task_args_t *)arg)->value) = 1; + int val = select(fd + 1, &read_fds, NULL, NULL, NULL); + assert(val == 1); + bool is_selected = true; + xQueueSend(select_arg->queue, &is_selected, 0); vTaskDelete(NULL); } @@ -376,20 +379,20 @@ TEST_CASE("eventfd select block", "[vfs][eventfd]") select_block_task_args_t args; args.fd = eventfd(0, 0); TEST_ASSERT_GREATER_OR_EQUAL(0, args.fd); - int a = 0; - args.value = &a; + args.queue = xQueueCreate(1, sizeof(bool)); int fd_write = eventfd(0, 0); TEST_ASSERT_GREATER_OR_EQUAL(0, fd_write); xTaskCreate(select_block_task, "select_block_task", 2048, &args, 5, NULL); - vTaskDelay(pdMS_TO_TICKS(2000)); + bool is_selected = false; uint64_t val = 1; TEST_ASSERT_EQUAL(sizeof(val), write(fd_write, &val, sizeof(val))); - vTaskDelay(pdMS_TO_TICKS(2000)); - - TEST_ASSERT_EQUAL(0, *(args.value)); + TEST_ASSERT(!xQueueReceive(args.queue, &is_selected, pdMS_TO_TICKS(2000))); + TEST_ASSERT_EQUAL(sizeof(val), write(args.fd, &val, sizeof(val))); + TEST_ASSERT(xQueueReceive(args.queue, &is_selected, pdMS_TO_TICKS(1000))); + TEST_ASSERT_EQUAL(true, is_selected); TEST_ASSERT_EQUAL(0, close(args.fd)); TEST_ASSERT_EQUAL(0, close(fd_write)); TEST_ESP_OK(esp_vfs_eventfd_unregister()); From cea24c71377a471fff75290366e753aa633cf6a8 Mon Sep 17 00:00:00 2001 From: Xu Si Yu Date: Wed, 20 Mar 2024 18:00:33 +0800 Subject: [PATCH 2/3] feat(openthread): add max csmabackoffs for transmission --- components/openthread/Kconfig | 8 ++++++++ components/openthread/include/esp_radio_spinel.h | 13 +++++++------ .../openthread-core-esp32x-ftd-config.h | 12 ++++++++++++ .../openthread-core-esp32x-mtd-config.h | 12 ++++++++++++ .../openthread-core-esp32x-radio-config.h | 14 +++++++++++++- .../openthread-core-esp32x-spinel-config.h | 12 ++++++++++++ .../openthread/src/spinel/esp_radio_spinel.cpp | 10 ++++++---- 7 files changed, 70 insertions(+), 11 deletions(-) diff --git a/components/openthread/Kconfig b/components/openthread/Kconfig index c291ede131..558f093f6c 100644 --- a/components/openthread/Kconfig +++ b/components/openthread/Kconfig @@ -266,6 +266,14 @@ menu "OpenThread" default 1024 range 512 8192 + config OPENTHREAD_MAC_MAX_CSMA_BACKOFFS_DIRECT + int "Maximum backoffs times before declaring a channel access failure." + depends on OPENTHREAD_ENABLED || OPENTHREAD_SPINEL_ONLY + default 4 + help + The maximum number of backoffs the CSMA-CA algorithm will attempt before declaring a channel access + failure. + config OPENTHREAD_MLE_MAX_CHILDREN int "The size of max MLE children entries" depends on OPENTHREAD_ENABLED diff --git a/components/openthread/include/esp_radio_spinel.h b/components/openthread/include/esp_radio_spinel.h index e8edef1fa6..24c5f1a629 100644 --- a/components/openthread/include/esp_radio_spinel.h +++ b/components/openthread/include/esp_radio_spinel.h @@ -6,15 +6,16 @@ #pragma once -#ifdef __cplusplus -extern "C" { -#endif - +#include "sdkconfig.h" #include #include "esp_ieee802154_types.h" #include "driver/uart.h" #include "soc/gpio_num.h" +#ifdef __cplusplus +extern "C" { +#endif + #define ESP_SPINEL_LOG_TAG "ESP_RADIO_SPINEL" #define SPINEL_PROP_VENDOR_ESP_SET_COORDINATOR (SPINEL_PROP_VENDOR_ESP__BEGIN + 1) /* Vendor command for coordinator.*/ @@ -55,11 +56,11 @@ typedef struct void (*transmit_started)(const uint8_t *frame); /* Callback for Transmit Started.*/ void (*switchover_done)(bool success); /* Callback for Switchover Done.*/ -#if OPENTHREAD_CONFIG_DIAG_ENABLE +#if CONFIG_OPENTHREAD_DIAG void (*diag_receive_done)(const uint8_t *frame, esp_ieee802154_frame_info_t *frame_info); /* Callback for Receive Done (diag).*/ void (*diag_transmit_done)(const uint8_t *frame, esp_ieee802154_frame_info_t *frame_info); /* Callback for Transmit Done (diag).*/ void (*diag_transmit_failed)(esp_ieee802154_tx_error_t error); /* Callback for Transmit Failed (diag).*/ -#endif // OPENTHREAD_CONFIG_DIAG_ENABLE +#endif // CONFIG_OPENTHREAD_DIAG } esp_radio_spinel_callbacks_t; /* ESP Radio Spinel Callbacks.*/ /** 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 6043159bf3..609c01112c 100644 --- a/components/openthread/private_include/openthread-core-esp32x-ftd-config.h +++ b/components/openthread/private_include/openthread-core-esp32x-ftd-config.h @@ -620,4 +620,16 @@ #define OPENTHREAD_CONFIG_TMF_ADDRESS_QUERY_MAX_RETRY_DELAY CONFIG_OPENTHREAD_ADDRESS_QUERY_MAX_RETRY_DELAY #endif +/** + * @def OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT + * + * The maximum number of backoffs the CSMA-CA algorithm will attempt before declaring a channel access failure. + * + * Equivalent to macMaxCSMABackoffs in IEEE 802.15.4-2006, default value is 4. + * + */ +#ifndef OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT +#define OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT CONFIG_OPENTHREAD_MAC_MAX_CSMA_BACKOFFS_DIRECT +#endif + #define OPENTHREAD_FTD 1 diff --git a/components/openthread/private_include/openthread-core-esp32x-mtd-config.h b/components/openthread/private_include/openthread-core-esp32x-mtd-config.h index a008afcca6..e5520f1e5b 100644 --- a/components/openthread/private_include/openthread-core-esp32x-mtd-config.h +++ b/components/openthread/private_include/openthread-core-esp32x-mtd-config.h @@ -304,4 +304,16 @@ #define OPENTHREAD_CONFIG_TMF_ADDRESS_QUERY_MAX_RETRY_DELAY CONFIG_OPENTHREAD_ADDRESS_QUERY_MAX_RETRY_DELAY #endif +/** + * @def OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT + * + * The maximum number of backoffs the CSMA-CA algorithm will attempt before declaring a channel access failure. + * + * Equivalent to macMaxCSMABackoffs in IEEE 802.15.4-2006, default value is 4. + * + */ +#ifndef OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT +#define OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT CONFIG_OPENTHREAD_MAC_MAX_CSMA_BACKOFFS_DIRECT +#endif + #define OPENTHREAD_MTD 1 diff --git a/components/openthread/private_include/openthread-core-esp32x-radio-config.h b/components/openthread/private_include/openthread-core-esp32x-radio-config.h index 2f34b61ef1..cd8ad15909 100644 --- a/components/openthread/private_include/openthread-core-esp32x-radio-config.h +++ b/components/openthread/private_include/openthread-core-esp32x-radio-config.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 */ @@ -230,3 +230,15 @@ #define OPENTHREAD_ENABLE_NCP_VENDOR_HOOK 1 #endif #endif //CONFIG_OPENTHREAD_NCP_VENDOR_HOOK + +/** + * @def OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT + * + * The maximum number of backoffs the CSMA-CA algorithm will attempt before declaring a channel access failure. + * + * Equivalent to macMaxCSMABackoffs in IEEE 802.15.4-2006, default value is 4. + * + */ +#ifndef OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT +#define OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT CONFIG_OPENTHREAD_MAC_MAX_CSMA_BACKOFFS_DIRECT +#endif 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 ab6da83d84..68d5b8240a 100644 --- a/components/openthread/private_include/openthread-core-esp32x-spinel-config.h +++ b/components/openthread/private_include/openthread-core-esp32x-spinel-config.h @@ -46,3 +46,15 @@ * */ #define OPENTHREAD_CONFIG_PLATFORM_RADIO_SPINEL_RX_FRAME_BUFFER_SIZE CONFIG_OPENTHREAD_SPINEL_RX_FRAME_BUFFER_SIZE + +/** + * @def OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT + * + * The maximum number of backoffs the CSMA-CA algorithm will attempt before declaring a channel access failure. + * + * Equivalent to macMaxCSMABackoffs in IEEE 802.15.4-2006, default value is 4. + * + */ +#ifndef OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT +#define OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT CONFIG_OPENTHREAD_MAC_MAX_CSMA_BACKOFFS_DIRECT +#endif diff --git a/components/openthread/src/spinel/esp_radio_spinel.cpp b/components/openthread/src/spinel/esp_radio_spinel.cpp index c9895ff00a..2b7bcfdf16 100644 --- a/components/openthread/src/spinel/esp_radio_spinel.cpp +++ b/components/openthread/src/spinel/esp_radio_spinel.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include "sdkconfig.h" #include "esp_check.h" #include "esp_log.h" #include "platform/exit_code.h" @@ -123,7 +124,7 @@ void SwitchoverDone(otInstance *aInstance, bool aSuccess) s_esp_radio_spinel_callbacks[idx].switchover_done(aSuccess); } -#if OPENTHREAD_CONFIG_DIAG_ENABLE +#if CONFIG_OPENTHREAD_DIAG void DiagReceiveDone(otInstance *aInstance, otRadioFrame *aFrame, otError aError) { esp_radio_spinel_idx_t idx = get_index_from_instance(aInstance); @@ -172,7 +173,7 @@ void DiagTransmitDone(otInstance *aInstance, otRadioFrame *aFrame, otError aErro } } } -#endif // OPENTHREAD_CONFIG_DIAG_ENABLE +#endif // CONFIG_OPENTHREAD_DIAG void esp_radio_spinel_set_callbacks(const esp_radio_spinel_callbacks_t aCallbacks, esp_radio_spinel_idx_t idx) @@ -184,10 +185,10 @@ void esp_radio_spinel_set_callbacks(const esp_radio_spinel_callbacks_t aCallback Callbacks.mEnergyScanDone = EnergyScanDone; Callbacks.mTxStarted = TxStarted; Callbacks.mSwitchoverDone = SwitchoverDone; -#if OPENTHREAD_CONFIG_DIAG_ENABLE +#if CONFIG_OPENTHREAD_DIAG Callbacks.mDiagReceiveDone = DiagReceiveDone; Callbacks.mDiagTransmitDone = DiagTransmitDone; -#endif // OPENTHREAD_CONFIG_DIAG_ENABLE +#endif // CONFIG_OPENTHREAD_DIAG s_radio[idx].SetCallbacks(Callbacks); } @@ -268,6 +269,7 @@ esp_err_t esp_radio_spinel_transmit(uint8_t *frame, uint8_t channel, bool cca, e s_transmit_frame.mLength = frame[0]; s_transmit_frame.mPsdu = frame + 1; s_transmit_frame.mInfo.mTxInfo.mCsmaCaEnabled = cca; + s_transmit_frame.mInfo.mTxInfo.mMaxCsmaBackoffs = CONFIG_OPENTHREAD_MAC_MAX_CSMA_BACKOFFS_DIRECT; s_transmit_frame.mChannel = channel; s_transmit_frame.mInfo.mTxInfo.mRxChannelAfterTxDone = channel; return (s_radio[idx].Transmit(s_transmit_frame) == OT_ERROR_NONE) ? ESP_OK : ESP_FAIL; From fd36f6fcac7a770d8dffba94d10b2f70c4f1ca4d Mon Sep 17 00:00:00 2001 From: Xu Si Yu Date: Thu, 23 Nov 2023 16:48:06 +0800 Subject: [PATCH 3/3] fix(ci): fix wrong path of ot sleep case --- examples/openthread/pytest_otbr.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/openthread/pytest_otbr.py b/examples/openthread/pytest_otbr.py index 487e68ee9b..c307adc1c7 100644 --- a/examples/openthread/pytest_otbr.py +++ b/examples/openthread/pytest_otbr.py @@ -562,11 +562,11 @@ def test_TCP_NAT64(Init_interface:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> N 'config, count, app_path, target', [ ('cli_h2|sleepy_c6', 2, f'{os.path.join(os.path.dirname(__file__), "ot_cli")}' - f'|{os.path.join(os.path.dirname(__file__), "ot_sleepy_device")}', + f'|{os.path.join(os.path.dirname(__file__), "ot_sleepy_device/light_sleep")}', 'esp32h2|esp32c6'), ('cli_c6|sleepy_h2', 2, f'{os.path.join(os.path.dirname(__file__), "ot_cli")}' - f'|{os.path.join(os.path.dirname(__file__), "ot_sleepy_device")}', + f'|{os.path.join(os.path.dirname(__file__), "ot_sleepy_device/light_sleep")}', 'esp32c6|esp32h2'), ], indirect=True,