Skip to content

Commit

Permalink
Merge branch 'backport5.1/openthread_2024_3_14' into 'release/v5.1'
Browse files Browse the repository at this point in the history
openthread modifications backport to 5.1

See merge request espressif/esp-idf!29653
  • Loading branch information
chshu committed Mar 17, 2024
2 parents 8af8f58 + 88cd813 commit 19dd338
Show file tree
Hide file tree
Showing 12 changed files with 298 additions and 9 deletions.
11 changes: 6 additions & 5 deletions components/openthread/src/port/esp_openthread_radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <stdatomic.h>
#include "esp_openthread_radio.h"

#include "error.h"
Expand Down Expand Up @@ -51,7 +52,7 @@ typedef struct {
typedef struct {
uint8_t head;
uint8_t tail;
uint8_t used;
atomic_uint_fast8_t used;
} esp_openthread_circular_queue_info_t;

static otRadioFrame s_transmit_frame;
Expand Down Expand Up @@ -216,7 +217,7 @@ esp_err_t esp_openthread_radio_process(otInstance *aInstance, const esp_openthre
otPlatRadioEnergyScanDone(aInstance, s_ed_power);
}

while (s_recv_queue.used) {
while (atomic_load(&s_recv_queue.used)) {
if (s_receive_frame[s_recv_queue.head].mPsdu != NULL) {
#if OPENTHREAD_CONFIG_DIAG_ENABLE
if (otPlatDiagModeGet()) {
Expand All @@ -229,7 +230,7 @@ esp_err_t esp_openthread_radio_process(otInstance *aInstance, const esp_openthre
esp_ieee802154_receive_handle_done(s_receive_frame[s_recv_queue.head].mPsdu - 1);
s_receive_frame[s_recv_queue.head].mPsdu = NULL;
s_recv_queue.head = (s_recv_queue.head + 1) % CONFIG_IEEE802154_RX_BUFFER_SIZE;
s_recv_queue.used--;
atomic_fetch_sub(&s_recv_queue.used, 1);
}
}

Expand Down Expand Up @@ -681,7 +682,7 @@ void IRAM_ATTR esp_ieee802154_receive_done(uint8_t *data, esp_ieee802154_frame_i
otRadioFrame ot_frame;
ot_frame.mPsdu = data + 1;

if (s_recv_queue.used == CONFIG_IEEE802154_RX_BUFFER_SIZE) {
if (atomic_load(&s_recv_queue.used) == CONFIG_IEEE802154_RX_BUFFER_SIZE) {
ESP_EARLY_LOGE(OT_PLAT_LOG_TAG, "radio receive buffer full!");
return;
}
Expand All @@ -699,7 +700,7 @@ void IRAM_ATTR esp_ieee802154_receive_done(uint8_t *data, esp_ieee802154_frame_i
s_with_security_enh_ack = false;
#endif // OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2
s_recv_queue.tail = (s_recv_queue.tail + 1) % CONFIG_IEEE802154_RX_BUFFER_SIZE;
s_recv_queue.used++;
atomic_fetch_add(&s_recv_queue.used, 1);
set_event(EVENT_RX_DONE);
}

Expand Down
2 changes: 1 addition & 1 deletion components/vfs/vfs_eventfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static esp_err_t event_start_select(int nfds,

for (int i = 0; i < nfds; i++) {
_lock_acquire_recursive(&s_events[i].lock);
if (s_events[i].fd == i) {
if (s_events[i].fd == i && (FD_ISSET(i, readfds) || FD_ISSET(i, writefds) || FD_ISSET(i, exceptfds))) {
if (s_events[i].support_isr) {
portENTER_CRITICAL(&s_events[i].data_spin_lock);
}
Expand Down
11 changes: 9 additions & 2 deletions examples/openthread/ot_br/main/esp_ot_br.c
Original file line number Diff line number Diff line change
@@ -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: CC0-1.0
*
Expand All @@ -15,6 +15,7 @@
#include <stdio.h>
#include <string.h>

#include "sdkconfig.h"
#include "esp_check.h"
#include "esp_err.h"
#include "esp_event.h"
Expand All @@ -35,7 +36,6 @@
#include "mdns.h"
#include "nvs_flash.h"
#include "protocol_examples_common.h"
#include "sdkconfig.h"
#include "driver/uart.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
Expand All @@ -44,6 +44,10 @@
#include "openthread/logging.h"
#include "openthread/tasklet.h"

#if CONFIG_OPENTHREAD_STATE_INDICATOR_ENABLE
#include "ot_led_strip.h"
#endif

#define TAG "esp_ot_br"

#if CONFIG_EXTERNAL_COEX_ENABLE
Expand Down Expand Up @@ -72,6 +76,9 @@ static void ot_task_worker(void *aContext)

// Initialize border routing features
esp_openthread_lock_acquire(portMAX_DELAY);
#if CONFIG_OPENTHREAD_STATE_INDICATOR_ENABLE
ESP_ERROR_CHECK(esp_openthread_state_indicator_init(esp_openthread_get_instance()));
#endif
ESP_ERROR_CHECK(esp_netif_attach(openthread_netif, esp_openthread_netif_glue_init(&config)));

(void)otLoggingSetLevel(CONFIG_LOG_DEFAULT_LEVEL);
Expand Down
2 changes: 2 additions & 0 deletions examples/openthread/ot_br/main/idf_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ dependencies:
## Required IDF version
idf:
version: ">=5.0"
ot_led:
path: ${IDF_PATH}/examples/openthread/ot_common_components/ot_led
1 change: 1 addition & 0 deletions examples/openthread/ot_br/sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ CONFIG_MBEDTLS_ECJPAKE_C=y
#
CONFIG_OPENTHREAD_ENABLED=y
CONFIG_OPENTHREAD_BORDER_ROUTER=y
CONFIG_OPENTHREAD_RADIO_SPINEL_UART=y
# end of OpenThread

#
Expand Down
11 changes: 10 additions & 1 deletion examples/openthread/ot_cli/main/esp_ot_cli.c
Original file line number Diff line number Diff line change
@@ -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: CC0-1.0
*
Expand All @@ -16,6 +16,7 @@
#include <unistd.h>
#include <string.h>

#include "sdkconfig.h"
#include "esp_err.h"
#include "esp_event.h"
#include "esp_log.h"
Expand All @@ -38,6 +39,10 @@
#include "openthread/logging.h"
#include "openthread/tasklet.h"

#if CONFIG_OPENTHREAD_STATE_INDICATOR_ENABLE
#include "ot_led_strip.h"
#endif

#if CONFIG_OPENTHREAD_CLI_ESP_EXTENSION
#include "esp_ot_cli_extension.h"
#endif // CONFIG_OPENTHREAD_CLI_ESP_EXTENSION
Expand Down Expand Up @@ -65,6 +70,10 @@ static void ot_task_worker(void *aContext)
// Initialize the OpenThread stack
ESP_ERROR_CHECK(esp_openthread_init(&config));

#if CONFIG_OPENTHREAD_STATE_INDICATOR_ENABLE
ESP_ERROR_CHECK(esp_openthread_state_indicator_init(esp_openthread_get_instance()));
#endif

#if CONFIG_OPENTHREAD_LOG_LEVEL_DYNAMIC
// The OpenThread log level directly matches ESP log level
(void)otLoggingSetLevel(CONFIG_LOG_DEFAULT_LEVEL);
Expand Down
2 changes: 2 additions & 0 deletions examples/openthread/ot_cli/main/idf_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ dependencies:
version: "~1.0.0"
idf:
version: ">=4.1.0"
ot_led:
path: ${IDF_PATH}/examples/openthread/ot_common_components/ot_led
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if(CONFIG_OPENTHREAD_STATE_INDICATOR_ENABLE)
set(srcs "ot_led_strip.c")
endif()

idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS "include"
PRIV_REQUIRES led_strip openthread)
128 changes: 128 additions & 0 deletions examples/openthread/ot_common_components/ot_led/Kconfig.projbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
menu "OpenThread Device Role Indicator"

orsource "$IDF_PATH/examples/common_components/env_caps/$IDF_TARGET/Kconfig.env_caps"

config OPENTHREAD_STATE_INDICATOR_ENABLE
depends on SOC_RMT_SUPPORTED
bool 'Enable the LED for openthread deivce'
default False
help
If enabled, the LED of ESP Openthread Device will display different colors based on the current role.

config OPENTHREAD_STATE_INDICATOR_GPIO
depends on OPENTHREAD_STATE_INDICATOR_ENABLE
int "Blink GPIO number"
range ENV_GPIO_RANGE_MIN ENV_GPIO_OUT_RANGE_MAX
default 5 if IDF_TARGET_ESP32
default 18 if IDF_TARGET_ESP32S2
default 48 if IDF_TARGET_ESP32S3
default 8
help
GPIO number (IOxx) to blink on and off the LED.
Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to blink.

menu "Indicator of Leader Device"
config LEADER_INDICATOR_RED
depends on OPENTHREAD_STATE_INDICATOR_ENABLE
int "red config"
range 0 255
default 40
help
Red config of LED for OpenThread leader device

config LEADER_INDICATOR_GREEN
depends on OPENTHREAD_STATE_INDICATOR_ENABLE
int "green config"
range 0 255
default 0
help
Red config of LED for OpenThread leader device

config LEADER_INDICATOR_BLUE
depends on OPENTHREAD_STATE_INDICATOR_ENABLE
int "blue config"
range 0 255
default 0
help
Blue config of LED for OpenThread leader device
endmenu

menu "Indicator of Router Device"
config ROUTER_INDICATOR_RED
depends on OPENTHREAD_STATE_INDICATOR_ENABLE
int "red config"
range 0 255
default 0
help
Red config of LED for OpenThread router device

config ROUTER_INDICATOR_GREEN
depends on OPENTHREAD_STATE_INDICATOR_ENABLE
int "green config"
range 0 255
default 0
help
Green config of LED for OpenThread router device

config ROUTER_INDICATOR_BLUE
depends on OPENTHREAD_STATE_INDICATOR_ENABLE
int "blue config"
range 0 255
default 40
help
Blue config of LED for OpenThread router device
endmenu

menu "Indicator of Child Device"
config CHILD_INDICATOR_RED
depends on OPENTHREAD_STATE_INDICATOR_ENABLE
int "red config"
range 0 255
default 0
help
Red config of LED for OpenThread child device

config CHILD_INDICATOR_GREEN
depends on OPENTHREAD_STATE_INDICATOR_ENABLE
int "green config"
range 0 255
default 40
help
Green config of LED for OpenThread child device

config CHILD_INDICATOR_BLUE
depends on OPENTHREAD_STATE_INDICATOR_ENABLE
int "blue config"
range 0 255
default 0
help
Blue config of LED for OpenThread child device
endmenu

menu "Indicator of Detached Device"
config DETACHED_INDICATOR_RED
depends on OPENTHREAD_STATE_INDICATOR_ENABLE
int "red config"
range 0 255
default 20
help
Red config of LED for OpenThread detached device

config DETACHED_INDICATOR_GREEN
depends on OPENTHREAD_STATE_INDICATOR_ENABLE
int "green config"
range 0 255
default 20
help
Green config of LED for OpenThread detached device

config DETACHED_INDICATOR_BLUE
depends on OPENTHREAD_STATE_INDICATOR_ENABLE
int "blue config"
range 0 255
default 20
help
Blue config of LED for OpenThread detached device
endmenu

endmenu
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dependencies:
espressif/led_strip: "^2.4.1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*
* OpenThread Command Line Example
*
* This example code is in the Public Domain (or CC0 licensed, at your option.)
*
* Unless required by applicable law or agreed to in writing, this
* software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied.
*/

#include "esp_err.h"
#include "esp_openthread.h"

/**
* @brief Initilize the LED of OpenThread device.
*
* @return
* - ESP_OK on success
* - ESP_FAIL on failure
*
*/
esp_err_t esp_openthread_state_indicator_init(otInstance *instance);

/**
* @brief Set the LED color of OpenThread device.
*
* @param[in] index index of pixel to set
* @param[in] red red part of color
* @param[in] green green part of color
* @param[in] blue blue part of color
*
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_ARG: Set LED color failed because of invalid parameters
* - ESP_FAIL on other failure
*
*/
esp_err_t esp_openthread_state_indicator_set(uint32_t index, uint32_t red, uint32_t green, uint32_t blue);

/**
* @brief Clear the LED color of OpenThread device.
*
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_ARG: Clear LED color failed because of invalid parameters
* - ESP_FAIL on other failure
*
*/
esp_err_t esp_openthread_state_indicator_clear(void);
Loading

0 comments on commit 19dd338

Please sign in to comment.