Skip to content

Commit

Permalink
Merge branch 'feature/openthread_flash_optimization' into 'master'
Browse files Browse the repository at this point in the history
openthread: Add some flash optimization options

See merge request espressif/esp-idf!20290
  • Loading branch information
chshu committed Sep 28, 2022
2 parents dbdd8ee + 1d826c7 commit 45fb699
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 33 deletions.
2 changes: 1 addition & 1 deletion components/ieee802154/lib
13 changes: 9 additions & 4 deletions components/openthread/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
45 changes: 45 additions & 0 deletions components/openthread/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion components/openthread/openthread
Submodule openthread updated 313 files
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,25 @@
#define OPENTHREAD_CONFIG_LOG_OUTPUT OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED

/**
* @def OPENTHREAD_CONFIG_LOG_LEVEL
* @def OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE
*
* The log level (used at compile time). If `OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE` is set, this defines the most
* verbose log level possible. See `OPENTHREAD_CONFIG_LOG_LEVEL_INIT` to set the initial log level.
* Configuration option to enable dynamic log level control.
*
*/
#define OPENTHREAD_CONFIG_LOG_LEVEL OT_LOG_LEVEL_DEBG
#define OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE CONFIG_OPENTHREAD_LOG_LEVEL_DYNAMIC

/**
* @def OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE
* @def OPENTHREAD_CONFIG_LOG_LEVEL
*
* Define as 1 to enable dynamic log level control.
* The log level (used at compile time). If `OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE` is set, this defines the most
* verbose log level possible. See `OPENTHREAD_CONFIG_LOG_LEVEL_INIT` to set the initial log level.
*
*/
#define OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE 1
#if OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE
#define OPENTHREAD_CONFIG_LOG_LEVEL OT_LOG_LEVEL_DEBG
#else
#define OPENTHREAD_CONFIG_LOG_LEVEL CONFIG_OPENTHREAD_LOG_LEVEL
#endif

#define OPENTHREAD_CONFIG_LOG_CLI 1
#define OPENTHREAD_CONFIG_LOG_PKT_DUMP 1
Expand Down Expand Up @@ -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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,25 @@
#define OPENTHREAD_CONFIG_LOG_OUTPUT OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED

/**
* @def OPENTHREAD_CONFIG_LOG_LEVEL
* @def OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE
*
* The log level (used at compile time). If `OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE` is set, this defines the most
* verbose log level possible. See `OPENTHREAD_CONFIG_LOG_LEVEL_INIT` to set the initial log level.
* Configuration option to enable dynamic log level control.
*
*/
#define OPENTHREAD_CONFIG_LOG_LEVEL OT_LOG_LEVEL_DEBG
#define OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE CONFIG_OPENTHREAD_LOG_LEVEL_DYNAMIC

/**
* @def OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE
* @def OPENTHREAD_CONFIG_LOG_LEVEL
*
* Define as 1 to enable dynamic log level control.
* The log level (used at compile time). If `OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE` is set, this defines the most
* verbose log level possible. See `OPENTHREAD_CONFIG_LOG_LEVEL_INIT` to set the initial log level.
*
*/
#define OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE 1
#if OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE
#define OPENTHREAD_CONFIG_LOG_LEVEL OT_LOG_LEVEL_DEBG
#else
#define OPENTHREAD_CONFIG_LOG_LEVEL CONFIG_OPENTHREAD_LOG_LEVEL
#endif

#define OPENTHREAD_CONFIG_LOG_CLI 1
#define OPENTHREAD_CONFIG_LOG_PKT_DUMP 1
Expand Down
31 changes: 31 additions & 0 deletions components/openthread/src/esp_openthread_stubs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <esp_openthread.h>
#include <openthread/platform/radio.h>
#include <openthread/platform/toolchain.h>
#include <stdint.h>
#include <utils/uart.h>

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 *)
{
}
2 changes: 1 addition & 1 deletion examples/openthread/ot_br/main/idf_component.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
10 changes: 3 additions & 7 deletions examples/openthread/ot_cli/main/esp_ot_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)
{
Expand All @@ -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

Expand All @@ -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);
Expand All @@ -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);
}
2 changes: 1 addition & 1 deletion examples/openthread/ot_cli/main/idf_component.yml
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 45fb699

Please sign in to comment.