Skip to content

Commit

Permalink
Merge branch 'backport/openthread_related_feature_v52_20241112' into …
Browse files Browse the repository at this point in the history
…'release/v5.2'

Backport openthread related features to 5.2

See merge request espressif/esp-idf!34837
  • Loading branch information
Jiang Jiang Jian committed Nov 21, 2024
2 parents c19a00b + e6967ad commit be05f8d
Show file tree
Hide file tree
Showing 21 changed files with 255 additions and 19 deletions.
2 changes: 2 additions & 0 deletions components/esp_coex/include/esp_coex_i154.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ typedef enum {
void esp_coex_ieee802154_txrx_pti_set(ieee802154_coex_event_t event);
void esp_coex_ieee802154_ack_pti_set(ieee802154_coex_event_t event);
void esp_coex_ieee802154_coex_break_notify(void);
void esp_coex_ieee802154_extcoex_tx_stage(void);
void esp_coex_ieee802154_extcoex_rx_stage(void);
#endif

#endif
20 changes: 20 additions & 0 deletions components/ieee802154/driver/esp_ieee802154_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,23 @@ IEEE802154_NOINLINE IEEE802154_STATIC bool stop_current_operation(void)
return true;
}

FORCE_INLINE_ATTR void extcoex_tx_stage_start(void)
{
#if CONFIG_ESP_COEX_EXTERNAL_COEXIST_ENABLE
esp_coex_ieee802154_extcoex_tx_stage();
#endif
}

FORCE_INLINE_ATTR void extcoex_rx_stage_start(void)
{
#if CONFIG_ESP_COEX_EXTERNAL_COEXIST_ENABLE
esp_coex_ieee802154_extcoex_rx_stage();
#endif
}

static void enable_rx(void)
{
extcoex_rx_stage_start();
set_next_rx_buffer();
IEEE802154_SET_TXRX_PTI(IEEE802154_SCENE_RX);

Expand Down Expand Up @@ -403,6 +418,7 @@ static IRAM_ATTR void isr_handle_tx_done(void)
NEEDS_NEXT_OPT(true);
} else if (s_ieee802154_state == IEEE802154_STATE_TX || s_ieee802154_state == IEEE802154_STATE_TX_CCA) {
if (ieee802154_frame_is_ack_required(s_tx_frame) && ieee802154_ll_get_rx_auto_ack()) {
extcoex_rx_stage_start();
ieee802154_set_state(IEEE802154_STATE_RX_ACK);
#if !CONFIG_IEEE802154_TEST
receive_ack_timeout_timer_start(200000); // 200ms for receive ack timeout
Expand All @@ -423,6 +439,7 @@ static IRAM_ATTR void isr_handle_rx_done(void)
if (s_ieee802154_state == IEEE802154_STATE_RX) {
if (ieee802154_frame_is_ack_required(s_rx_frame[s_rx_index]) && ieee802154_frame_get_version(s_rx_frame[s_rx_index]) <= IEEE802154_FRAME_VERSION_1
&& ieee802154_ll_get_tx_auto_ack()) {
extcoex_tx_stage_start();
// auto tx ack only works for the frame with version 0b00 and 0b01
s_rx_frame_info[s_rx_index].pending = ieee802154_ack_config_pending_bit(s_rx_frame[s_rx_index]);
ieee802154_set_state(IEEE802154_STATE_TX_ACK);
Expand All @@ -432,6 +449,7 @@ static IRAM_ATTR void isr_handle_rx_done(void)
s_rx_frame_info[s_rx_index].pending = ieee802154_ack_config_pending_bit(s_rx_frame[s_rx_index]);
// For 2015 enh-ack, SW should generate an enh-ack then send it manually
if (esp_ieee802154_enh_ack_generator(s_rx_frame[s_rx_index], &s_rx_frame_info[s_rx_index], s_enh_ack_frame) == ESP_OK) {
extcoex_tx_stage_start();
#if !CONFIG_IEEE802154_TEST
// Send the Enh-Ack frame if generator succeeds.
ieee802154_ll_set_tx_addr(s_enh_ack_frame);
Expand All @@ -456,6 +474,7 @@ static IRAM_ATTR void isr_handle_rx_done(void)

static IRAM_ATTR void isr_handle_ack_tx_done(void)
{
extcoex_rx_stage_start();
ieee802154_receive_done((uint8_t *)s_rx_frame[s_rx_index], &s_rx_frame_info[s_rx_index]);
NEEDS_NEXT_OPT(true);
}
Expand Down Expand Up @@ -831,6 +850,7 @@ IEEE802154_STATIC void tx_init(const uint8_t *frame)
// set rx pointer for ack frame
set_next_rx_buffer();
}
extcoex_tx_stage_start();
}

static inline esp_err_t ieee802154_transmit_internal(const uint8_t *frame, bool cca)
Expand Down
18 changes: 13 additions & 5 deletions components/openthread/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,20 @@ menu "OpenThread"
help
Select this option to enable border router features in OpenThread.

config OPENTHREAD_PLATFORM_MSGPOOL_MANAGEMENT
bool 'Allocate message pool buffer from PSRAM'
menu "Thread Memory Allocation Config"
depends on OPENTHREAD_ENABLED && (SPIRAM_USE_CAPS_ALLOC || SPIRAM_USE_MALLOC)
default n
help
If enabled, the message pool is managed by platform defined logic.
config OPENTHREAD_MEM_ALLOC_EXTERNAL
bool 'Allocate memory from PSRAM'
default y
help
Select this option to allocate buffer from PSRAM for Thread

config OPENTHREAD_PLATFORM_MSGPOOL_MANAGEMENT
bool 'Allocate message pool buffer from PSRAM'
default n
help
If enabled, the message pool is managed by platform defined logic.
endmenu

config OPENTHREAD_NUM_MESSAGE_BUFFERS
int "The number of openthread message buffers"
Expand Down
10 changes: 10 additions & 0 deletions components/openthread/include/esp_openthread_border_router.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ esp_netif_t *esp_openthread_get_backbone_netif(void);
*/
void esp_openthread_register_rcp_failure_handler(esp_openthread_rcp_failure_handler handler);

/**
* @brief Registers the callback for spinel compatibility error.
*
* @note This function must be called before esp_openthread_init.
*
* @param[in] callback The callback.
*
*/
void esp_openthread_set_compatibility_error_callback(esp_openthread_compatibility_error_callback callback);

/**
* @brief Deinitializes the connection to RCP.
*
Expand Down
2 changes: 2 additions & 0 deletions components/openthread/include/esp_openthread_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ typedef struct {

typedef void (*esp_openthread_rcp_failure_handler)(void);

typedef void (*esp_openthread_compatibility_error_callback)(void);

#ifdef __cplusplus
}
#endif
11 changes: 11 additions & 0 deletions components/openthread/include/esp_radio_spinel.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ typedef struct {
typedef void (*esp_radio_spinel_rcp_failure_handler)(void); /* The handler for rcp failure.*/
typedef esp_err_t (*esp_radio_spinel_uart_init_handler)(const esp_radio_spinel_uart_config_t *uart_config_t, int *uart_fd); /* The handler for UART initialization.*/
typedef esp_err_t (*esp_radio_spinel_uart_deinit_handler)(const esp_radio_spinel_uart_config_t *uart_config_t, int *uart_fd); /* The handler for UART deinitialization.*/
typedef void (*esp_radio_spinel_compatibility_error_callback)(void);

typedef struct
{
Expand Down Expand Up @@ -391,6 +392,16 @@ esp_err_t esp_radio_spinel_rcp_deinit(esp_radio_spinel_idx_t idx);
*/
esp_err_t esp_radio_spinel_rcp_version_get(char *running_rcp_version, esp_radio_spinel_idx_t idx);

/**
* @brief Registers the callback for spinel compatibility error.
*
* @note This function must be called before esp_radio_spinel_init.
*
* @param[in] callback The callback.
*
*/
void esp_radio_spinel_set_compatibility_error_callback(esp_radio_spinel_compatibility_error_callback callback);

#ifdef __cplusplus
}
#endif
28 changes: 28 additions & 0 deletions components/openthread/include/esp_radio_spinel_platform.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include "sdkconfig.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Get frame counter.
*
* @param[in] idx The index of 802.15.4 related protocol stack.
*
* @return
* - The frame counter
*
*/
uint32_t esp_radio_spinel_extern_get_frame_counter(esp_radio_spinel_idx_t idx);

#ifdef __cplusplus
}
#endif
2 changes: 1 addition & 1 deletion components/openthread/openthread
Submodule openthread updated 907 files
21 changes: 21 additions & 0 deletions components/openthread/private_include/esp_openthread_common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include "esp_heap_caps.h"
#include <utility>
#include "common/new.hpp"

template <typename T, typename... Args>
inline T *New(uint32_t alloc_caps, Args &&...args)
{
void *p = heap_caps_calloc(1, sizeof(T), alloc_caps);
if (p != nullptr) {
return new (p) T(std::forward<Args>(args)...);
}
return nullptr;
}
13 changes: 11 additions & 2 deletions components/openthread/private_include/esp_openthread_platform.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -84,7 +84,7 @@ void esp_openthread_platform_workflow_unregister(const char *name);
* @brief Initializes the platform-specific support for the OpenThread stack.
*
* @note This function is not called by and will not call the OpenThread library.
* The user needs to call otInstanceInitSingle to intialize the OpenThread
* The user needs to call otInstanceInitSingle to initialize the OpenThread
* stack after calling this function.
*
* @param[in] init_config The initialization configuration.
Expand Down Expand Up @@ -146,6 +146,15 @@ esp_err_t esp_openthread_platform_process(otInstance *instance, const esp_openth
*
*/
void esp_openthread_set_storage_name(const char *name);

/**
* @brief Gets the caps of memory allocation.
*
* @return
* - The caps of the memory.
*/
uint32_t esp_openthread_get_alloc_caps(void);

#ifdef __cplusplus
} // end of extern "C"
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,16 @@
#define OPENTHREAD_POSIX_CONFIG_RCP_TIME_SYNC_INTERVAL (60 * 1000 * 1000)
#endif

/**
* @def OPENTHREAD_SPINEL_CONFIG_COMPATIBILITY_ERROR_CALLBACK_ENABLE
*
* Enables compatibility error callback in Spinel
*/
#ifndef OPENTHREAD_SPINEL_CONFIG_COMPATIBILITY_ERROR_CALLBACK_ENABLE
#define OPENTHREAD_SPINEL_CONFIG_COMPATIBILITY_ERROR_CALLBACK_ENABLE 1
#endif


#endif

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@
*/
#define OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS CONFIG_OPENTHREAD_NUM_MESSAGE_BUFFERS

/**
* @def OPENTHREAD_CONFIG_COAP_API_ENABLE
*
* Define to 1 to enable the CoAP API.
*
*/
#define OPENTHREAD_CONFIG_COAP_API_ENABLE 1

/**
* @def OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE
*
* Define to 1 to enable platform NETIF support.
*
*/
#ifndef OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE
#define OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE 1
#endif

/**
* @def OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
*
*/
#ifndef OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT
// TZ-567: Set OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT to 3 after adding rcp failure notification mechanism
#define OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT 3
#endif

Expand Down Expand Up @@ -77,3 +76,23 @@
#ifndef OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT
#define OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT CONFIG_OPENTHREAD_MAC_MAX_CSMA_BACKOFFS_DIRECT
#endif


/**
* @def OPENTHREAD_SPINEL_CONFIG_COMPATIBILITY_ERROR_CALLBACK_ENABLE
*
* Enables compatibility error callback in Spinel
*/
#ifndef OPENTHREAD_SPINEL_CONFIG_COMPATIBILITY_ERROR_CALLBACK_ENABLE
#define OPENTHREAD_SPINEL_CONFIG_COMPATIBILITY_ERROR_CALLBACK_ENABLE 1
#endif

/**
* @def OPENTHREAD_SPINEL_CONFIG_MAX_SRC_MATCH_ENTRIES
*
* Defines size of the local source match table used by RadioSpinel
* when OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT is used.
*/
#ifndef OPENTHREAD_SPINEL_CONFIG_MAX_SRC_MATCH_ENTRIES
#define OPENTHREAD_SPINEL_CONFIG_MAX_SRC_MATCH_ENTRIES 12
#endif
2 changes: 1 addition & 1 deletion components/openthread/sbom_openthread.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ supplier: 'Organization: Espressif Systems (Shanghai) CO LTD'
originator: 'Organization: Google LLC'
description: OpenThread released by Google is an open-source implementation of the Thread networking
url: https://github.com/espressif/openthread
hash: f32c18bc0840f400182456e58ae3900fc2fb4af7
hash: 005c5cefc22aaf0396e4327ee7f2e0ad32a7733b
15 changes: 15 additions & 0 deletions components/openthread/src/esp_openthread_netif_glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "esp_log.h"
#include "esp_netif.h"
#include "esp_openthread.h"
#include "esp_openthread_border_router.h"
#include "esp_openthread_common_macro.h"
#include "esp_openthread_lock.h"
#include "esp_openthread_netif_glue_priv.h"
Expand All @@ -33,6 +34,7 @@
#include "openthread/ip6.h"
#include "openthread/link.h"
#include "openthread/message.h"
#include "openthread/platform/infra_if.h"
#include "openthread/thread.h"

typedef struct {
Expand Down Expand Up @@ -381,3 +383,16 @@ esp_netif_t *esp_openthread_get_netif(void)
{
return s_openthread_netif;
}

otError otPlatGetInfraIfLinkLayerAddress(otInstance *aInstance, uint32_t aIfIndex, otPlatInfraIfLinkLayerAddress *aInfraIfLinkLayerAddress)
{
esp_netif_t *backbone_netif = esp_openthread_get_backbone_netif();
if (esp_netif_get_netif_impl_index(backbone_netif) != aIfIndex) {
ESP_LOGE(OT_PLAT_LOG_TAG, "Failed to get LL address, error: Invalid If index");
return OT_ERROR_FAILED;
} else {
esp_netif_get_mac(backbone_netif, aInfraIfLinkLayerAddress->mAddress);
aInfraIfLinkLayerAddress->mLength = 6;
return OT_ERROR_NONE;
}
}
10 changes: 10 additions & 0 deletions components/openthread/src/esp_openthread_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,13 @@ esp_err_t esp_openthread_platform_process(otInstance *instance, const esp_openth
}
return ESP_OK;
}

uint32_t esp_openthread_get_alloc_caps(void)
{
return
#if CONFIG_OPENTHREAD_PLATFORM_MALLOC_CAP_SPIRAM
(MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
#else
(MALLOC_CAP_DEFAULT | MALLOC_CAP_8BIT);
#endif
}
Loading

0 comments on commit be05f8d

Please sign in to comment.