From 1d826c7a2bbe858b6ffb03fe5ddecbd33bb6a881 Mon Sep 17 00:00:00 2001 From: WanqQixiang Date: Tue, 27 Sep 2022 14:30:46 +0800 Subject: [PATCH] openthread: Add some flash optimization options for openthread component openthread: use a certain version of esp_openthread_cli_extension managed component --- components/ieee802154/lib | 2 +- components/openthread/CMakeLists.txt | 13 ++++-- components/openthread/Kconfig | 45 +++++++++++++++++++ components/openthread/lib | 2 +- components/openthread/openthread | 2 +- .../openthread-core-esp32x-ftd-config.h | 26 ++++++----- .../openthread-core-esp32x-mtd-config.h | 20 +++++---- .../openthread/src/esp_openthread_stubs.c | 31 +++++++++++++ .../openthread/ot_br/main/idf_component.yml | 2 +- examples/openthread/ot_cli/main/esp_ot_cli.c | 10 ++--- .../openthread/ot_cli/main/idf_component.yml | 2 +- 11 files changed, 120 insertions(+), 35 deletions(-) create mode 100644 components/openthread/src/esp_openthread_stubs.c diff --git a/components/ieee802154/lib b/components/ieee802154/lib index a35ccebb0d..2b52a261fe 160000 --- a/components/ieee802154/lib +++ b/components/ieee802154/lib @@ -1 +1 @@ -Subproject commit a35ccebb0d6f30879367a795efca1586ec6bbfc3 +Subproject commit 2b52a261fef2ad7b630e11866dca567d17170401 diff --git a/components/openthread/CMakeLists.txt b/components/openthread/CMakeLists.txt index 1ed80f5dec..0b91fd9b3b 100644 --- a/components/openthread/CMakeLists.txt +++ b/components/openthread/CMakeLists.txt @@ -34,16 +34,20 @@ if(CONFIG_OPENTHREAD_ENABLED) if(CONFIG_OPENTHREAD_FTD OR CONFIG_OPENTHREAD_MTD) list(APPEND src_dirs "src" - "openthread/examples/apps/cli" "openthread/src/core/backbone_router" "openthread/src/core/coap" "openthread/src/core/meshcop" "openthread/src/core/net" - "openthread/src/cli" "openthread/src/lib/platform") - list(APPEND exclude_srcs - "openthread/examples/apps/cli/main.c") + if(CONFIG_OPENTHREAD_CLI) + list(APPEND src_dirs + "openthread/examples/apps/cli" + "openthread/src/cli") + + list(APPEND exclude_srcs + "openthread/examples/apps/cli/main.c") + endif() elseif(CONFIG_OPENTHREAD_RADIO) list(APPEND src_dirs @@ -61,6 +65,7 @@ if(CONFIG_OPENTHREAD_ENABLED) "openthread/src/core/api/ip6_api.cpp" "openthread/src/core/api/link_api.cpp" "openthread/src/core/api/message_api.cpp" + "openthread/src/core/api/nat64_api.cpp" "openthread/src/core/api/netdata_api.cpp" "openthread/src/core/api/random_crypto_api.cpp" "openthread/src/core/api/tcp_api.cpp" diff --git a/components/openthread/Kconfig b/components/openthread/Kconfig index e6e962be94..b5e86b104a 100644 --- a/components/openthread/Kconfig +++ b/components/openthread/Kconfig @@ -6,6 +6,44 @@ menu "OpenThread" help Select this option to enable OpenThread and show the submenu with OpenThread configuration choices. + config OPENTHREAD_LOG_LEVEL_DYNAMIC + bool "Enable dynamic log level control" + depends on OPENTHREAD_ENABLED + default y + help + Select this option to enable dynamic log level control for OpenThread + + choice OPENTHREAD_LOG_LEVEL + prompt "OpenThread log verbosity" + depends on OPENTHREAD_ENABLED && !OPENTHREAD_LOG_LEVEL_DYNAMIC + default OPENTHREAD_LOG_LEVEL_INFO + help + Select OpenThread log level. + + config OPENTHREAD_LOG_LEVEL_NONE + bool "No logs" + config OPENTHREAD_LOG_LEVEL_CRIT + bool "Error logs" + config OPENTHREAD_LOG_LEVEL_WARN + bool "Warning logs" + config OPENTHREAD_LOG_LEVEL_NOTE + bool "Notice logs" + config OPENTHREAD_LOG_LEVEL_INFO + bool "Info logs" + config OPENTHREAD_LOG_LEVEL_DEBG + bool "Debug logs" + endchoice #OPENTHREAD_LOG_LEVEL + + config OPENTHREAD_LOG_LEVEL + int + depends on OPENTHREAD_ENABLED && !OPENTHREAD_LOG_LEVEL_DYNAMIC + default 0 if OPENTHREAD_LOG_LEVEL_NONE + default 1 if OPENTHREAD_LOG_LEVEL_CRIT + default 2 if OPENTHREAD_LOG_LEVEL_WARN + default 3 if OPENTHREAD_LOG_LEVEL_NOTE + default 4 if OPENTHREAD_LOG_LEVEL_INFO + default 5 if OPENTHREAD_LOG_LEVEL_DEBG + choice OPENTHREAD_RADIO_TYPE prompt "Config the Thread radio type" depends on OPENTHREAD_ENABLED @@ -51,6 +89,13 @@ menu "OpenThread" radio only device. endchoice + config OPENTHREAD_CLI + bool "Enable Openthread Command-Line Interface" + depends on OPENTHREAD_ENABLED + default y + help + Select this option to enable Command-Line Interface in OpenThread. + config OPENTHREAD_DIAG bool "Enable diag" depends on OPENTHREAD_ENABLED diff --git a/components/openthread/lib b/components/openthread/lib index 0758f50523..698e8386c3 160000 --- a/components/openthread/lib +++ b/components/openthread/lib @@ -1 +1 @@ -Subproject commit 0758f50523b25f75a4a24f8687946fa4eaf7661e +Subproject commit 698e8386c31f2c34e167b65f72a6b2553e838dd9 diff --git a/components/openthread/openthread b/components/openthread/openthread index 1b5298eb76..e64ba13faa 160000 --- a/components/openthread/openthread +++ b/components/openthread/openthread @@ -1 +1 @@ -Subproject commit 1b5298eb7663a8fb48402e73a17f6e47db89648c +Subproject commit e64ba13faa865aa7febd5cb7dc7eb52ff19a2c5c 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 49be86e632..ad015fba3d 100644 --- a/components/openthread/private_include/openthread-core-esp32x-ftd-config.h +++ b/components/openthread/private_include/openthread-core-esp32x-ftd-config.h @@ -41,6 +41,14 @@ */ #define OPENTHREAD_CONFIG_LOG_OUTPUT OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED +/** + * @def OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE + * + * Configuration option to enable dynamic log level control. + * + */ +#define OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE CONFIG_OPENTHREAD_LOG_LEVEL_DYNAMIC + /** * @def OPENTHREAD_CONFIG_LOG_LEVEL * @@ -48,15 +56,11 @@ * verbose log level possible. See `OPENTHREAD_CONFIG_LOG_LEVEL_INIT` to set the initial log level. * */ +#if OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE #define OPENTHREAD_CONFIG_LOG_LEVEL OT_LOG_LEVEL_DEBG - -/** - * @def OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE - * - * Define as 1 to enable dynamic log level control. - * - */ -#define OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE 1 +#else +#define OPENTHREAD_CONFIG_LOG_LEVEL CONFIG_OPENTHREAD_LOG_LEVEL +#endif #define OPENTHREAD_CONFIG_LOG_CLI 1 #define OPENTHREAD_CONFIG_LOG_PKT_DUMP 1 @@ -150,13 +154,13 @@ #endif /** - * @def OPENTHREAD_CONFIG_BORDER_ROUTING_NAT64_ENABLE + * @def OPENTHREAD_CONFIG_NAT64_BORDER_ROUTING_ENABLE * * Define to 1 to enable Border Routing NAT64 support. * */ -#ifndef OPENTHREAD_CONFIG_BORDER_ROUTING_NAT64_ENABLE -#define OPENTHREAD_CONFIG_BORDER_ROUTING_NAT64_ENABLE 1 +#ifndef OPENTHREAD_CONFIG_NAT64_BORDER_ROUTING_ENABLE +#define OPENTHREAD_CONFIG_NAT64_BORDER_ROUTING_ENABLE 1 #endif /** 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 f2131e46e6..a675e00853 100644 --- a/components/openthread/private_include/openthread-core-esp32x-mtd-config.h +++ b/components/openthread/private_include/openthread-core-esp32x-mtd-config.h @@ -41,6 +41,14 @@ */ #define OPENTHREAD_CONFIG_LOG_OUTPUT OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED +/** + * @def OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE + * + * Configuration option to enable dynamic log level control. + * + */ +#define OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE CONFIG_OPENTHREAD_LOG_LEVEL_DYNAMIC + /** * @def OPENTHREAD_CONFIG_LOG_LEVEL * @@ -48,15 +56,11 @@ * verbose log level possible. See `OPENTHREAD_CONFIG_LOG_LEVEL_INIT` to set the initial log level. * */ +#if OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE #define OPENTHREAD_CONFIG_LOG_LEVEL OT_LOG_LEVEL_DEBG - -/** - * @def OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE - * - * Define as 1 to enable dynamic log level control. - * - */ -#define OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE 1 +#else +#define OPENTHREAD_CONFIG_LOG_LEVEL CONFIG_OPENTHREAD_LOG_LEVEL +#endif #define OPENTHREAD_CONFIG_LOG_CLI 1 #define OPENTHREAD_CONFIG_LOG_PKT_DUMP 1 diff --git a/components/openthread/src/esp_openthread_stubs.c b/components/openthread/src/esp_openthread_stubs.c new file mode 100644 index 0000000000..c129d04e85 --- /dev/null +++ b/components/openthread/src/esp_openthread_stubs.c @@ -0,0 +1,31 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include + +OT_TOOL_WEAK void otPlatUartReceived(const uint8_t *, uint16_t) +{ +} + +OT_TOOL_WEAK void otPlatUartSendDone(void) +{ +} + +OT_TOOL_WEAK void otPlatDiagRadioTransmitDone(otInstance *, otRadioFrame *, otError) +{ +} + +OT_TOOL_WEAK void otPlatDiagRadioReceiveDone(otInstance *, otRadioFrame *, otError) +{ +} + +OT_TOOL_WEAK void otPlatDiagAlarmFired(otInstance *) +{ +} diff --git a/examples/openthread/ot_br/main/idf_component.yml b/examples/openthread/ot_br/main/idf_component.yml index 6bcf90f97a..2f9c0f6440 100644 --- a/examples/openthread/ot_br/main/idf_component.yml +++ b/examples/openthread/ot_br/main/idf_component.yml @@ -1,6 +1,6 @@ ## IDF Component Manager Manifest File dependencies: - espressif/esp_ot_cli_extension: "*" + espressif/esp_ot_cli_extension: "~0.1.0" espressif/mdns: "^1.0.3" ## Required IDF version idf: diff --git a/examples/openthread/ot_cli/main/esp_ot_cli.c b/examples/openthread/ot_cli/main/esp_ot_cli.c index 863664a585..0d4e3ad379 100644 --- a/examples/openthread/ot_cli/main/esp_ot_cli.c +++ b/examples/openthread/ot_cli/main/esp_ot_cli.c @@ -43,7 +43,6 @@ #define TAG "ot_esp_cli" -#if CONFIG_OPENTHREAD_CLI_ESP_EXTENSION static esp_netif_t *init_openthread_netif(const esp_openthread_platform_config_t *config) { esp_netif_config_t cfg = ESP_NETIF_DEFAULT_OPENTHREAD(); @@ -53,7 +52,6 @@ static esp_netif_t *init_openthread_netif(const esp_openthread_platform_config_t return netif; } -#endif // CONFIG_OPENTHREAD_CLI_ESP_EXTENSION static void ot_task_worker(void *aContext) { @@ -66,16 +64,18 @@ static void ot_task_worker(void *aContext) // Initialize the OpenThread stack ESP_ERROR_CHECK(esp_openthread_init(&config)); +#if CONFIG_OPENTHREAD_LOG_LEVEL_DYNAMIC // The OpenThread log level directly matches ESP log level (void)otLoggingSetLevel(CONFIG_LOG_DEFAULT_LEVEL); +#endif // Initialize the OpenThread cli esp_openthread_cli_init(); -#if CONFIG_OPENTHREAD_CLI_ESP_EXTENSION esp_netif_t *openthread_netif; // Initialize the esp_netif bindings openthread_netif = init_openthread_netif(&config); +#if CONFIG_OPENTHREAD_CLI_ESP_EXTENSION esp_cli_custom_command_init(); #endif // CONFIG_OPENTHREAD_CLI_ESP_EXTENSION @@ -84,10 +84,8 @@ static void ot_task_worker(void *aContext) esp_openthread_launch_mainloop(); // Clean up -#if CONFIG_OPENTHREAD_CLI_ESP_EXTENSION esp_netif_destroy(openthread_netif); esp_openthread_netif_glue_deinit(); -#endif // CONFIG_OPENTHREAD_CLI_ESP_EXTENSION esp_vfs_eventfd_unregister(); vTaskDelete(NULL); @@ -104,9 +102,7 @@ void app_main(void) }; ESP_ERROR_CHECK(esp_event_loop_create_default()); -#if CONFIG_OPENTHREAD_CLI_ESP_EXTENSION ESP_ERROR_CHECK(esp_netif_init()); -#endif // CONFIG_OPENTHREAD_CLI_ESP_EXTENSION ESP_ERROR_CHECK(esp_vfs_eventfd_register(&eventfd_config)); xTaskCreate(ot_task_worker, "ot_cli_main", 10240, xTaskGetCurrentTaskHandle(), 5, NULL); } diff --git a/examples/openthread/ot_cli/main/idf_component.yml b/examples/openthread/ot_cli/main/idf_component.yml index 1d7d5f4a23..2246fc9a0e 100644 --- a/examples/openthread/ot_cli/main/idf_component.yml +++ b/examples/openthread/ot_cli/main/idf_component.yml @@ -1,5 +1,5 @@ ## IDF Component Manager Manifest File dependencies: - espressif/esp_ot_cli_extension: "*" + espressif/esp_ot_cli_extension: "~0.1.0" idf: version: ">=4.1.0"