Merge branch 'feat/support_multipan_feature_rcp_20260603_v6.1' into 'release/v6.1'

feat(openthread): support multipan feature for RCP (v6.1)

See merge request espressif/esp-idf!51777
This commit is contained in:
Jiang Jiang Jian
2026-08-31 11:40:43 +08:00
41 changed files with 2084 additions and 320 deletions
+22 -7
View File
@@ -323,7 +323,7 @@ menu "OpenThread"
bool "Enable link metrics feature"
default n
select IEEE802154_TIMING_OPTIMIZATION if IEEE802154_ENABLED
select OPENTHREAD_TIMING_OPTIMIZATION
select OPENTHREAD_TIMING_OPTIMIZATION if OPENTHREAD_RADIO_NATIVE
help
Select this option to enable link metrics feature
@@ -427,17 +427,16 @@ menu "OpenThread"
endmenu
menu "Thread Memory Allocation"
depends on (SPIRAM_USE_CAPS_ALLOC || SPIRAM_USE_MALLOC)
config OPENTHREAD_PLATFORM_MALLOC_CAP_SPIRAM
depends on (SPIRAM_USE_CAPS_ALLOC || SPIRAM_USE_MALLOC)
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'
depends on OPENTHREAD_PLATFORM_MALLOC_CAP_SPIRAM
default y
bool 'Allocate message pool buffer from platform'
default n
help
If enabled, the message pool is managed by platform defined logic.
endmenu
@@ -471,8 +470,8 @@ menu "OpenThread"
config OPENTHREAD_NUM_MESSAGE_BUFFERS
int "The number of openthread message buffers"
default 65 if !OPENTHREAD_PLATFORM_MSGPOOL_MANAGEMENT
default 1024 if OPENTHREAD_PLATFORM_MSGPOOL_MANAGEMENT
default 65 if !OPENTHREAD_PLATFORM_MALLOC_CAP_SPIRAM
default 1024 if OPENTHREAD_PLATFORM_MALLOC_CAP_SPIRAM
config OPENTHREAD_XTAL_ACCURACY
int "The accuracy of the XTAL"
@@ -517,6 +516,22 @@ menu "OpenThread"
OpenThread esp_netif, attaches the esp_netif glue, and enables
lwIP-specific DNS/netif handling.
config OPENTHREAD_MULTIPAN_RCP_ENABLE
bool "Enable Multipan RCP"
depends on (OPENTHREAD_RADIO && IEEE802154_MULTI_PAN_ENABLE)
default n
help
Enable MULTI-PAN RCP support. This also enables multiple OpenThread
instances. Currently only radio devices are supported.
config OPENTHREAD_MULTIPLE_INTERFACES_COUNT
int "The number of multiple interfaces"
depends on OPENTHREAD_MULTIPAN_RCP_ENABLE
default 2
range 2 3
help
Number of multiple interfaces.
endmenu
menu "Thread Log"
@@ -42,3 +42,9 @@
#else
#define ESP_OPENTHREAD_ASSERT(a) assert(a)
#endif
#if CONFIG_OPENTHREAD_MULTIPAN_RCP_ENABLE
#define OT_INSTANCE_COUNT CONFIG_OPENTHREAD_MULTIPLE_INTERFACES_COUNT
#else
#define OT_INSTANCE_COUNT 1
#endif
@@ -0,0 +1,56 @@
/*
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdbool.h>
#include "openthread/instance.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Initialize OpenThread instance(s) for the selected build (single or multiple).
*
* @return true on success, false otherwise.
*/
bool esp_openthread_instances_init(void);
/**
* @brief Finalize OpenThread instance(s) for the selected build (single or multiple).
*
* @param[in] instance Instance provided by the caller (may be unused in multi-instance builds).
*/
void esp_openthread_instances_deinit(otInstance *instance);
/**
* @brief Check whether tasklets are pending.
*
* @param[in] instance Instance provided by the caller (may be unused in multi-instance builds).
*/
bool esp_openthread_tasklets_are_pending(otInstance *instance);
/**
* @brief Process pending tasklets.
*
* @param[in] instance Instance provided by the caller (may be unused in multi-instance builds).
*/
void esp_openthread_tasklets_process(otInstance *instance);
/**
* @brief Initialize the NCP/RCP application for the selected instance mode.
*
* @param[in] instance Instance provided by the caller (may be unused in multi-instance builds).
*
* @note Only used when CONFIG_OPENTHREAD_RADIO is enabled.
*/
void esp_openthread_ncp_app_init(otInstance *instance);
#ifdef __cplusplus
}
#endif
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -10,8 +10,21 @@
extern "C" {
#endif
/**
* @brief This function initializes the NCP for a single instance
*
* @param[in] aInstance The OpenThread instance.
*/
void otAppNcpInit(otInstance *aInstance);
/**
* @brief This function initializes the NCP for multiple instances
*
* @param[in] aInstances The array of OpenThread instances.
* @param[in] aCount The number of instances.
*/
void otAppNcpInitMulti(otInstance **aInstances, uint8_t aCount);
#if CONFIG_OPENTHREAD_RCP_SPINEL_CONSOLE
esp_err_t esp_console_redirect_to_otlog(void);
#endif // CONFIG_OPENTHREAD_RCP_SPINEL_CONSOLE
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -155,6 +155,37 @@ void esp_openthread_set_storage_name(const char *name);
*/
uint32_t esp_openthread_get_alloc_caps(void);
/**
* @brief This function gets the index of the instance
*
* @param[in] instance The OpenThread instance.
*
* @note Invalid input is logged and asserted.
*
* @return
* - The index of the instance
*/
int8_t esp_openthread_get_idx_from_instance(otInstance *instance);
/**
* @brief This function gets the instance from the index
*
* @param[in] idx The index of the instance.
*
* @note Invalid index is logged and asserted. A valid index always has an instance.
*
* @return
* - The instance
*/
otInstance *esp_openthread_get_instance_from_idx(int8_t idx);
/**
* @brief This function sets the active instance
*
* @param[in] instance The OpenThread instance.
*/
void esp_openthread_set_active_instance(otInstance *instance);
#ifdef __cplusplus
} // end of extern "C"
#endif
@@ -165,6 +165,62 @@
#define OPENTHREAD_CONFIG_TIME_SYNC_ENABLE 0
#endif
/**
* @def OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE
*
* Define to 1 to enable multiple instance support.
*/
#ifdef OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE
#error `OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE` is redefined.
#endif
#if CONFIG_OPENTHREAD_MULTIPAN_RCP_ENABLE
#define OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE 1
#else
#define OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE 0
#endif
/**
* @def OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
*
* Define to 1 to enable multipan RCP support.
*/
#ifdef OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE
#error `OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE` is redefined.
#endif
#if CONFIG_OPENTHREAD_MULTIPAN_RCP_ENABLE
#define OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE 1
#else
#define OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE 0
#endif
/**
* @def OPENTHREAD_CONFIG_MULTIPLE_STATIC_INSTANCE_ENABLE
*
* Define to 1 to enable multiple static instance support.
*/
#ifdef OPENTHREAD_CONFIG_MULTIPLE_STATIC_INSTANCE_ENABLE
#error `OPENTHREAD_CONFIG_MULTIPLE_STATIC_INSTANCE_ENABLE` is redefined.
#endif
#if CONFIG_OPENTHREAD_MULTIPAN_RCP_ENABLE
#define OPENTHREAD_CONFIG_MULTIPLE_STATIC_INSTANCE_ENABLE 1
#else
#define OPENTHREAD_CONFIG_MULTIPLE_STATIC_INSTANCE_ENABLE 0
#endif
/**
* @def OPENTHREAD_SPINEL_CONFIG_BROADCAST_IID
*
* Define broadcast IID for spinel frames dedicated to all hosts in multipan configuration.
* Host interfaces use IID 0 .. COUNT-1; broadcast takes the next slot.
*
*/
#ifdef OPENTHREAD_SPINEL_CONFIG_BROADCAST_IID
#error `OPENTHREAD_SPINEL_CONFIG_BROADCAST_IID` is redefined.
#endif
#if CONFIG_OPENTHREAD_MULTIPAN_RCP_ENABLE
#define OPENTHREAD_SPINEL_CONFIG_BROADCAST_IID SPINEL_HEADER_IID(CONFIG_OPENTHREAD_MULTIPLE_INTERFACES_COUNT)
#endif
/*----The following options set fixed default values but can be overridden by the user header file.----*/
#if CONFIG_OPENTHREAD_LINK_METRICS
@@ -90,11 +90,11 @@
#endif
/**
* @def OPENTHREAD_CONFIG_MAC_SOFTWARE_RETX_SECURITY_ENABLE
* @def OPENTHREAD_CONFIG_CRYPTO_LIB
*
* Workaround for SPINEL_ONLY build configuration.
* See esp-idf MR !50530 for details.
* See esp-idf MR !49222 for details.
*/
#ifndef OPENTHREAD_CONFIG_MAC_SOFTWARE_RETX_SECURITY_ENABLE
#define OPENTHREAD_CONFIG_MAC_SOFTWARE_RETX_SECURITY_ENABLE 0
#ifndef OPENTHREAD_CONFIG_CRYPTO_LIB
#define OPENTHREAD_CONFIG_CRYPTO_LIB OPENTHREAD_CONFIG_CRYPTO_LIB_PSA
#endif
+1 -1
View File
@@ -5,7 +5,7 @@ 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: b678a4f63b6f9397d1a0fa8f31e5b8e0271a4d00
hash: 43cc05a9bcf780bd758bad53d897e2d88cf8cb75
cve-exclude-list:
- cve: CVE-2026-8369
reason: We use Espressif’s NAT64 implementation and hence this CVE from the upstream NAT64 implementation is not applicable.
+8 -9
View File
@@ -12,8 +12,8 @@
#include "esp_openthread_common_macro.h"
#include "esp_openthread_cli.h"
#include "esp_openthread_dns64.h"
#include "esp_openthread_instance.h"
#include "esp_openthread_lock.h"
#include "esp_openthread_ncp.h"
#include "esp_openthread_netif_glue.h"
#include "esp_openthread_platform.h"
#include "esp_openthread_sleep.h"
@@ -26,7 +26,6 @@
#include "openthread/instance.h"
#include "openthread/logging.h"
#include "openthread/netdata.h"
#include "openthread/tasklet.h"
#include "openthread/thread.h"
#if CONFIG_OPENTHREAD_FTD
@@ -81,7 +80,7 @@ esp_err_t esp_openthread_init(const esp_openthread_platform_config_t *config)
"Failed to initialize OpenThread platform driver");
esp_openthread_lock_acquire(portMAX_DELAY);
esp_err_t ret = ESP_OK;
ESP_GOTO_ON_FALSE(otInstanceInitSingle() != NULL, ESP_FAIL, exit, OT_PLAT_LOG_TAG,
ESP_GOTO_ON_FALSE(esp_openthread_instances_init(), ESP_FAIL, exit, OT_PLAT_LOG_TAG,
"Failed to initialize OpenThread instance");
#if CONFIG_OPENTHREAD_DNS64_CLIENT
ESP_GOTO_ON_ERROR(esp_openthread_dns64_client_init(), exit, OT_PLAT_LOG_TAG,
@@ -203,7 +202,7 @@ esp_err_t esp_openthread_launch_mainloop(void)
esp_openthread_lock_acquire(portMAX_DELAY);
esp_openthread_platform_update(&mainloop);
if (otTaskletsArePending(instance)) {
if (esp_openthread_tasklets_are_pending(instance)) {
mainloop.timeout.tv_sec = 0;
mainloop.timeout.tv_usec = 0;
}
@@ -222,9 +221,7 @@ esp_err_t esp_openthread_launch_mainloop(void)
if (result >= 0) {
esp_openthread_lock_acquire(portMAX_DELAY);
error = esp_openthread_platform_process(instance, &mainloop);
while (otTaskletsArePending(instance)) {
otTaskletsProcess(instance);
}
esp_openthread_tasklets_process(instance);
esp_openthread_lock_release();
if (error != ESP_OK) {
ESP_LOGE(OT_PLAT_LOG_TAG, "esp_openthread_platform_process failed");
@@ -244,7 +241,9 @@ esp_err_t esp_openthread_launch_mainloop(void)
esp_err_t esp_openthread_deinit(void)
{
otInstanceFinalize(esp_openthread_get_instance());
esp_openthread_lock_acquire(portMAX_DELAY);
esp_openthread_instances_deinit(esp_openthread_get_instance());
esp_openthread_lock_release();
return esp_openthread_platform_deinit();
}
@@ -271,7 +270,7 @@ static void ot_task_worker(void *aContext)
#endif // CONFIG_OPENTHREAD_CLI
#if CONFIG_OPENTHREAD_RADIO
otAppNcpInit(esp_openthread_get_instance());
esp_openthread_ncp_app_init(esp_openthread_get_instance());
#endif
xSemaphoreGive(s_ot_syn_semaphore);
@@ -0,0 +1,47 @@
/*
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "sdkconfig.h"
#include "core/instance/instance.hpp"
#include "esp_openthread.h"
#include "esp_openthread_instance.h"
#include "esp_openthread_ncp.h"
#include "openthread/instance.h"
#include "openthread/tasklet.h"
bool esp_openthread_instances_init(void)
{
return otInstanceInitSingle() != NULL;
}
void esp_openthread_instances_deinit(otInstance *instance)
{
otInstanceFinalize(instance);
}
bool esp_openthread_tasklets_are_pending(otInstance *instance)
{
return otTaskletsArePending(instance);
}
void esp_openthread_tasklets_process(otInstance *instance)
{
while (otTaskletsArePending(instance)) {
otTaskletsProcess(instance);
}
}
#if CONFIG_OPENTHREAD_RADIO
void esp_openthread_ncp_app_init(otInstance *instance)
{
otAppNcpInit(instance);
}
#endif
otInstance *esp_openthread_get_instance(void)
{
return (otInstance *)&ot::Instance::Get();
}
@@ -20,7 +20,6 @@
#include "esp_partition.h"
#include "common/code_utils.hpp"
#include "common/logging.hpp"
#include "core/instance/instance.hpp"
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "openthread/cli.h"
@@ -166,11 +165,6 @@ exit:
return ret;
}
otInstance *esp_openthread_get_instance(void)
{
return (otInstance *)&ot::Instance::Get();
}
esp_err_t esp_openthread_platform_deinit(void)
{
ESP_RETURN_ON_FALSE(s_openthread_platform_initialized, ESP_ERR_INVALID_STATE, OT_PLAT_LOG_TAG,
@@ -0,0 +1,116 @@
/*
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "sdkconfig.h"
#include <assert.h>
#include "esp_log.h"
#include "esp_openthread.h"
#include "esp_openthread_common_macro.h"
#include "esp_openthread_instance.h"
#include "esp_openthread_ncp.h"
#include "esp_openthread_platform.h"
#include "openthread/instance.h"
#include "openthread/tasklet.h"
static otInstance *s_active_instance = NULL;
static otInstance *s_instances[OT_INSTANCE_COUNT] = {NULL};
bool esp_openthread_instances_init(void)
{
for (int i = 0; i < OT_INSTANCE_COUNT; i++) {
s_instances[i] = otInstanceInitMultiple(i);
assert(s_instances[i]);
}
esp_openthread_set_active_instance(s_instances[0]);
return true;
}
void esp_openthread_instances_deinit(otInstance *instance)
{
(void)instance;
for (int i = 0; i < OT_INSTANCE_COUNT; i++) {
otInstanceFinalize(s_instances[i]);
}
}
bool esp_openthread_tasklets_are_pending(otInstance *instance)
{
(void)instance;
for (int idx = 0; idx < OT_INSTANCE_COUNT; idx++) {
if (otTaskletsArePending(esp_openthread_get_instance_from_idx(idx))) {
return true;
}
}
return false;
}
void esp_openthread_tasklets_process(otInstance *instance)
{
(void)instance;
for (int idx = 0; idx < OT_INSTANCE_COUNT; idx++) {
otInstance *inst = esp_openthread_get_instance_from_idx(idx);
while (otTaskletsArePending(inst)) {
otTaskletsProcess(inst);
}
}
}
#if CONFIG_OPENTHREAD_RADIO
void esp_openthread_ncp_app_init(otInstance *instance)
{
(void)instance;
otInstance *instances[OT_INSTANCE_COUNT] = {nullptr};
for (int idx = 0; idx < OT_INSTANCE_COUNT; idx++) {
instances[idx] = esp_openthread_get_instance_from_idx(idx);
}
otAppNcpInitMulti(instances, OT_INSTANCE_COUNT);
}
#endif
otInstance *esp_openthread_get_instance(void)
{
return s_active_instance;
}
int8_t esp_openthread_get_idx_from_instance(otInstance *instance)
{
if (instance == nullptr) {
ESP_LOGE(OT_PLAT_LOG_TAG, "Instance is NULL");
assert(instance != nullptr);
}
uint8_t idx = otInstanceGetIndex(instance);
if (idx >= OT_INSTANCE_COUNT) {
ESP_LOGE(OT_PLAT_LOG_TAG, "Index %u is out of range", idx);
assert(idx < OT_INSTANCE_COUNT);
}
return static_cast<int8_t>(idx);
}
otInstance *esp_openthread_get_instance_from_idx(int8_t idx)
{
if (idx < 0 || idx >= OT_INSTANCE_COUNT) {
ESP_LOGE(OT_PLAT_LOG_TAG, "Index %d is out of range", idx);
assert(idx >= 0 && idx < OT_INSTANCE_COUNT);
}
otInstance *instance = otInstanceGetInstance(static_cast<uint8_t>(idx));
if (instance == nullptr) {
ESP_LOGE(OT_PLAT_LOG_TAG, "No instance for index %d", idx);
assert(instance != nullptr);
}
return instance;
}
void esp_openthread_set_active_instance(otInstance *instance)
{
s_active_instance = instance;
}
@@ -0,0 +1,167 @@
/*
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "esp_openthread_alarm.h"
#include <stdbool.h>
#include <stdint.h>
#include <sys/time.h>
#include "esp_log.h"
#include "esp_openthread.h"
#include "esp_openthread_common_macro.h"
#include "esp_openthread_platform.h"
#include "esp_timer.h"
#include "openthread-core-config.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "openthread/platform/alarm-micro.h"
#include "openthread/platform/alarm-milli.h"
#include "openthread/platform/diag.h"
#include "openthread/platform/radio.h"
#include "openthread/platform/time.h"
typedef struct {
uint32_t alarm_ms;
bool is_ms_running;
uint32_t alarm_us;
bool is_us_running;
otInstance *instance;
} esp_openthread_alarm_t;
static esp_openthread_alarm_t s_alarms[OT_INSTANCE_COUNT];
static const char *alarm_workflow = "alarm";
static inline bool is_expired(uint32_t target, uint32_t now)
{
return (((now - target) & (1 << 31)) == 0);
}
static inline uint32_t calculate_duration(uint32_t target, uint32_t now)
{
return is_expired(target, now) ? 0 : target - now;
}
uint64_t otPlatTimeGet(void)
{
return (uint64_t)esp_timer_get_time();
}
void otPlatAlarmMilliStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt)
{
int8_t idx = esp_openthread_get_idx_from_instance(aInstance);
s_alarms[idx].alarm_ms = aT0 + aDt;
s_alarms[idx].is_ms_running = true;
ESP_LOGD(OT_PLAT_LOG_TAG, "Millisecond timer alarm start running, t0=%"PRIu32", dt=%"PRIu32"", aT0, aDt);
}
void otPlatAlarmMilliStop(otInstance *aInstance)
{
int8_t idx = esp_openthread_get_idx_from_instance(aInstance);
s_alarms[idx].is_ms_running = false;
}
uint32_t inline otPlatAlarmMilliGetNow(void)
{
return otPlatTimeGet() / US_PER_MS;
}
void otPlatAlarmMicroStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt)
{
int8_t idx = esp_openthread_get_idx_from_instance(aInstance);
s_alarms[idx].alarm_us = aT0 + aDt;
s_alarms[idx].is_us_running = true;
ESP_LOGD(OT_PLAT_LOG_TAG, "Microsecond timer alarm start running, t0=%"PRIu32", dt=%"PRIu32"", aT0, aDt);
}
void otPlatAlarmMicroStop(otInstance *aInstance)
{
int8_t idx = esp_openthread_get_idx_from_instance(aInstance);
s_alarms[idx].is_us_running = false;
}
uint32_t inline otPlatAlarmMicroGetNow(void)
{
return otPlatTimeGet();
}
esp_err_t esp_openthread_alarm_init(void)
{
for (int idx = 0; idx < OT_INSTANCE_COUNT; idx++) {
memset((void *)(&s_alarms[idx]), 0, sizeof(esp_openthread_alarm_t));
}
return esp_openthread_platform_workflow_register(&esp_openthread_alarm_update, &esp_openthread_alarm_process,
alarm_workflow);
}
void esp_openthread_alarm_deinit(void)
{
esp_openthread_platform_workflow_unregister(alarm_workflow);
}
void esp_openthread_alarm_update(esp_openthread_mainloop_context_t *mainloop)
{
struct timeval *timeout = &mainloop->timeout;
int64_t remain_min_time_us = INT64_MAX;
int64_t remaining_us = 0;
for (int idx = 0; idx < OT_INSTANCE_COUNT; idx++) {
if (s_alarms[idx].is_ms_running) {
remaining_us = calculate_duration(s_alarms[idx].alarm_ms, otPlatAlarmMilliGetNow()) * US_PER_MS;
if (remain_min_time_us > remaining_us) {
remain_min_time_us = remaining_us;
}
}
if (s_alarms[idx].is_us_running) {
remaining_us = calculate_duration(s_alarms[idx].alarm_us, otPlatAlarmMicroGetNow());
if (remain_min_time_us > remaining_us) {
remain_min_time_us = remaining_us;
}
}
}
if (remain_min_time_us != INT64_MAX && remain_min_time_us > 0) {
timeout->tv_sec = remain_min_time_us / US_PER_S;
timeout->tv_usec = remain_min_time_us % US_PER_S;
} else {
timeout->tv_sec = 0;
timeout->tv_usec = 0;
}
}
esp_err_t esp_openthread_alarm_process(otInstance *aInstance, const esp_openthread_mainloop_context_t *mainloop)
{
OT_UNUSED_VARIABLE(aInstance);
OT_UNUSED_VARIABLE(mainloop);
for (int idx = 0; idx < OT_INSTANCE_COUNT; idx++) {
otInstance *instance = esp_openthread_get_instance_from_idx(idx);
if (s_alarms[idx].is_ms_running && is_expired(s_alarms[idx].alarm_ms, otPlatAlarmMilliGetNow())) {
s_alarms[idx].is_ms_running = false;
#if OPENTHREAD_CONFIG_DIAG_ENABLE
if (otPlatDiagModeGet()) {
otPlatDiagAlarmFired(instance);
} else
#endif
{
otPlatAlarmMilliFired(instance);
}
ESP_LOGD(OT_PLAT_LOG_TAG, "Millisecond timer alarm fired");
}
if (s_alarms[idx].is_us_running && is_expired(s_alarms[idx].alarm_us, otPlatAlarmMicroGetNow())) {
s_alarms[idx].is_us_running = false;
otPlatAlarmMicroFired(instance);
ESP_LOGD(OT_PLAT_LOG_TAG, "Microsecond timer alarm fired");
}
}
return ESP_OK;
}
File diff suppressed because it is too large Load Diff
@@ -92,6 +92,31 @@ static esp_err_t init_console_command_worker()
}
#endif // CONFIG_OPENTHREAD_RCP_SPINEL_CONSOLE
static void ncp_init_console(void)
{
#if CONFIG_OPENTHREAD_RCP_SPINEL_CONSOLE
esp_err_t err = esp_console_redirect_to_otlog();
if (err != ESP_OK) {
ESP_LOGE(NO_LOG_TAG, "Failed to redirect console to otPlatLog: %s", esp_err_to_name(err));
}
init_console_command_worker();
#endif
}
#if CONFIG_OPENTHREAD_MULTIPAN_RCP_ENABLE
extern "C" void otAppNcpInitMulti(otInstance **aInstances, uint8_t aCount)
{
#if (CONFIG_OPENTHREAD_RCP_UART || CONFIG_OPENTHREAD_RCP_USB_SERIAL_JTAG || CONFIG_OPENTHREAD_RCP_CUSTOM)
IgnoreError(otPlatUartEnable());
otNcpHdlcInitMulti(aInstances, aCount, NcpSend);
#else
#error "Multiple instances based on SPI are not supported yet"
#endif
ncp_init_console();
}
#else
extern "C" void otAppNcpInit(otInstance *aInstance)
{
#if (CONFIG_OPENTHREAD_RCP_UART || CONFIG_OPENTHREAD_RCP_USB_SERIAL_JTAG)
@@ -101,15 +126,9 @@ extern "C" void otAppNcpInit(otInstance *aInstance)
otNcpSpiInit(aInstance);
#endif
#if CONFIG_OPENTHREAD_RCP_SPINEL_CONSOLE
esp_err_t err = esp_console_redirect_to_otlog();
if (err != ESP_OK) {
ESP_LOGE(NO_LOG_TAG, "Failed to redirect console to otPlatLog: %s", esp_err_to_name(err));
}
init_console_command_worker();
#endif // CONFIG_OPENTHREAD_RCP_SPINEL_CONSOLE
ncp_init_console();
}
#endif
namespace ot {
namespace Ncp {
@@ -1,9 +1,10 @@
/*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "sdkconfig.h"
#include "common/new.hpp"
#include "ncp_hdlc.hpp"
@@ -12,6 +13,30 @@ namespace Ncp {
static OT_DEFINE_ALIGNED_VAR(sNcpRaw, sizeof(NcpHdlc), uint64_t);
#if CONFIG_OPENTHREAD_MULTIPAN_RCP_ENABLE
extern "C" void otNcpHdlcInitMulti(otInstance **aInstances, uint8_t aCount, otNcpHdlcSendCallback aSendCallback)
{
NcpHdlc *ncpHdlc = nullptr;
ot::Instance *instances[SPINEL_HEADER_IID_MAX];
OT_ASSERT(aCount < SPINEL_HEADER_IID_MAX + 1);
OT_ASSERT(aCount > 0);
OT_ASSERT(aInstances[0] != nullptr);
for (int i = 0; i < aCount; i++)
{
OT_ASSERT(aInstances[i] != nullptr);
instances[i] = static_cast<ot::Instance *>(aInstances[i]);
}
ncpHdlc = new (&sNcpRaw) NcpHdlc(instances, aCount, aSendCallback);
if (ncpHdlc == nullptr || ncpHdlc != NcpBase::GetNcpInstance())
{
OT_ASSERT(false);
}
}
#else
extern "C" void otNcpHdlcInit(otInstance *aInstance, otNcpHdlcSendCallback aSendCallback)
{
NcpHdlc *ncpHdlc = nullptr;
@@ -24,6 +49,7 @@ extern "C" void otNcpHdlcInit(otInstance *aInstance, otNcpHdlcSendCallback aSend
OT_ASSERT(false);
}
}
#endif
} // namespace Ncp
} // namespace ot
@@ -28,11 +28,13 @@ void otPlatMessagePoolInit(otInstance *aInstance, uint16_t aMinNumFreeBuffers, s
uint16_t num_buffers = aMinNumFreeBuffers;
#if CONFIG_OPENTHREAD_PLATFORM_MALLOC_CAP_SPIRAM
if (!esp_psram_is_initialized() && num_buffers > OT_MSGPOOL_NUM_BUFFERS_NO_PSRAM) {
ESP_LOGW(OT_PLAT_LOG_TAG, "PSRAM not available, reducing message pool from %u to %u buffers",
num_buffers, OT_MSGPOOL_NUM_BUFFERS_NO_PSRAM);
num_buffers = OT_MSGPOOL_NUM_BUFFERS_NO_PSRAM;
}
#endif
otMessageBuffer *buffer_pool = (otMessageBuffer *)heap_caps_calloc_prefer(num_buffers, aBufferSize, 3, esp_openthread_get_alloc_caps(), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
s_buffer_pool_pointer = (otMessageBuffer **)heap_caps_calloc_prefer(num_buffers, sizeof(otMessageBuffer **), 3, esp_openthread_get_alloc_caps(), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
@@ -10,7 +10,6 @@
#include "sdkconfig.h"
#include "esp_check.h"
#include "esp_ieee802154.h"
#include "esp_ieee802154_types.h"
#include "esp_mac.h"
#include "esp_openthread_common.h"
#include "esp_openthread_common_macro.h"
@@ -37,7 +36,6 @@
#include "esp_coex_i154.h"
#endif
#define ESP_RECEIVE_SENSITIVITY -120
#define ESP_OPENTHREAD_XTAL_ACCURACY CONFIG_OPENTHREAD_XTAL_ACCURACY
#define ESP_OPENTHREAD_CSL_ACCURACY CONFIG_OPENTHREAD_CSL_ACCURACY
#define ESP_OPENTHREAD_CSL_UNCERTAIN CONFIG_OPENTHREAD_CSL_UNCERTAIN
@@ -484,7 +482,7 @@ otError otPlatRadioSetCcaEnergyDetectThreshold(otInstance *aInstance, int8_t aTh
int8_t otPlatRadioGetReceiveSensitivity(otInstance *aInstance)
{
return ESP_RECEIVE_SENSITIVITY;
return esp_ieee802154_get_receive_sensitivity();
}
#if CONFIG_OPENTHREAD_DIAG
+20 -5
View File
@@ -61,18 +61,31 @@ set(rcp_srcs
openthread/src/ncp/ncp_base_dispatcher.cpp
openthread/src/ncp/ncp_base_radio.cpp
openthread/examples/apps/ncp/ncp.c
# ESP port
src/port/esp_openthread_alarm.c
# ESP port (logging/misc/settings stay at the original path)
src/port/esp_openthread_logging.c
src/port/esp_openthread_misc.c
src/port/esp_openthread_radio.c
src/port/esp_openthread_settings.c
# ESP sources
src/esp_openthread.cpp
src/esp_openthread_lock.c
src/esp_openthread_platform.cpp
src/esp_openthread_task_queue.c
# ESP NCP
)
# Single-instance files stay at the original src/ paths. Multipan RCP swaps in
# radio/alarm/instance under src/multiple_instances/. NCP is shared in src/ncp/.
if(CONFIG_OPENTHREAD_MULTIPAN_RCP_ENABLE)
set(OT_PORT_DIR "src/multiple_instances/port")
set(OT_INSTANCE_SRC "src/multiple_instances/esp_openthread_instance.cpp")
else()
set(OT_PORT_DIR "src/port")
set(OT_INSTANCE_SRC "src/esp_openthread_instance.cpp")
endif()
list(APPEND rcp_srcs
${OT_PORT_DIR}/esp_openthread_alarm.c
${OT_PORT_DIR}/esp_openthread_radio.c
${OT_INSTANCE_SRC}
src/ncp/esp_openthread_ncp.cpp
)
@@ -88,7 +101,9 @@ elseif(CONFIG_OPENTHREAD_RCP_SPI)
list(APPEND rcp_srcs
openthread/src/ncp/ncp_spi.cpp
src/port/esp_openthread_spi_slave.c)
if(CONFIG_OPENTHREAD_NCP_VENDOR_HOOK)
# Multipan SPI NCP is not supported; the compile-time check lives in
# src/ncp/esp_openthread_ncp.cpp.
if(CONFIG_OPENTHREAD_NCP_VENDOR_HOOK AND NOT CONFIG_OPENTHREAD_MULTIPAN_RCP_ENABLE)
list(APPEND rcp_srcs src/ncp/esp_openthread_ncp_spi.cpp)
endif()
endif()