mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
feat(openthread): reorganize source file structure
This commit is contained in:
@@ -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
|
||||||
@@ -12,8 +12,8 @@
|
|||||||
#include "esp_openthread_common_macro.h"
|
#include "esp_openthread_common_macro.h"
|
||||||
#include "esp_openthread_cli.h"
|
#include "esp_openthread_cli.h"
|
||||||
#include "esp_openthread_dns64.h"
|
#include "esp_openthread_dns64.h"
|
||||||
|
#include "esp_openthread_instance.h"
|
||||||
#include "esp_openthread_lock.h"
|
#include "esp_openthread_lock.h"
|
||||||
#include "esp_openthread_ncp.h"
|
|
||||||
#include "esp_openthread_netif_glue.h"
|
#include "esp_openthread_netif_glue.h"
|
||||||
#include "esp_openthread_platform.h"
|
#include "esp_openthread_platform.h"
|
||||||
#include "esp_openthread_sleep.h"
|
#include "esp_openthread_sleep.h"
|
||||||
@@ -26,7 +26,6 @@
|
|||||||
#include "openthread/instance.h"
|
#include "openthread/instance.h"
|
||||||
#include "openthread/logging.h"
|
#include "openthread/logging.h"
|
||||||
#include "openthread/netdata.h"
|
#include "openthread/netdata.h"
|
||||||
#include "openthread/tasklet.h"
|
|
||||||
#include "openthread/thread.h"
|
#include "openthread/thread.h"
|
||||||
|
|
||||||
#if CONFIG_OPENTHREAD_FTD
|
#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");
|
"Failed to initialize OpenThread platform driver");
|
||||||
esp_openthread_lock_acquire(portMAX_DELAY);
|
esp_openthread_lock_acquire(portMAX_DELAY);
|
||||||
esp_err_t ret = ESP_OK;
|
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");
|
"Failed to initialize OpenThread instance");
|
||||||
#if CONFIG_OPENTHREAD_DNS64_CLIENT
|
#if CONFIG_OPENTHREAD_DNS64_CLIENT
|
||||||
ESP_GOTO_ON_ERROR(esp_openthread_dns64_client_init(), exit, OT_PLAT_LOG_TAG,
|
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_lock_acquire(portMAX_DELAY);
|
||||||
esp_openthread_platform_update(&mainloop);
|
esp_openthread_platform_update(&mainloop);
|
||||||
if (otTaskletsArePending(instance)) {
|
if (esp_openthread_tasklets_are_pending(instance)) {
|
||||||
mainloop.timeout.tv_sec = 0;
|
mainloop.timeout.tv_sec = 0;
|
||||||
mainloop.timeout.tv_usec = 0;
|
mainloop.timeout.tv_usec = 0;
|
||||||
}
|
}
|
||||||
@@ -222,9 +221,7 @@ esp_err_t esp_openthread_launch_mainloop(void)
|
|||||||
if (result >= 0) {
|
if (result >= 0) {
|
||||||
esp_openthread_lock_acquire(portMAX_DELAY);
|
esp_openthread_lock_acquire(portMAX_DELAY);
|
||||||
error = esp_openthread_platform_process(instance, &mainloop);
|
error = esp_openthread_platform_process(instance, &mainloop);
|
||||||
while (otTaskletsArePending(instance)) {
|
esp_openthread_tasklets_process(instance);
|
||||||
otTaskletsProcess(instance);
|
|
||||||
}
|
|
||||||
esp_openthread_lock_release();
|
esp_openthread_lock_release();
|
||||||
if (error != ESP_OK) {
|
if (error != ESP_OK) {
|
||||||
ESP_LOGE(OT_PLAT_LOG_TAG, "esp_openthread_platform_process failed");
|
ESP_LOGE(OT_PLAT_LOG_TAG, "esp_openthread_platform_process failed");
|
||||||
@@ -244,7 +241,7 @@ esp_err_t esp_openthread_launch_mainloop(void)
|
|||||||
|
|
||||||
esp_err_t esp_openthread_deinit(void)
|
esp_err_t esp_openthread_deinit(void)
|
||||||
{
|
{
|
||||||
otInstanceFinalize(esp_openthread_get_instance());
|
esp_openthread_instances_deinit(esp_openthread_get_instance());
|
||||||
return esp_openthread_platform_deinit();
|
return esp_openthread_platform_deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,7 +268,7 @@ static void ot_task_worker(void *aContext)
|
|||||||
#endif // CONFIG_OPENTHREAD_CLI
|
#endif // CONFIG_OPENTHREAD_CLI
|
||||||
|
|
||||||
#if CONFIG_OPENTHREAD_RADIO
|
#if CONFIG_OPENTHREAD_RADIO
|
||||||
otAppNcpInit(esp_openthread_get_instance());
|
esp_openthread_ncp_app_init(esp_openthread_get_instance());
|
||||||
#endif
|
#endif
|
||||||
xSemaphoreGive(s_ot_syn_semaphore);
|
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 "esp_partition.h"
|
||||||
#include "common/code_utils.hpp"
|
#include "common/code_utils.hpp"
|
||||||
#include "common/logging.hpp"
|
#include "common/logging.hpp"
|
||||||
#include "core/instance/instance.hpp"
|
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/queue.h"
|
#include "freertos/queue.h"
|
||||||
#include "openthread/cli.h"
|
#include "openthread/cli.h"
|
||||||
@@ -166,11 +165,6 @@ exit:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
otInstance *esp_openthread_get_instance(void)
|
|
||||||
{
|
|
||||||
return (otInstance *)&ot::Instance::Get();
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_err_t esp_openthread_platform_deinit(void)
|
esp_err_t esp_openthread_platform_deinit(void)
|
||||||
{
|
{
|
||||||
ESP_RETURN_ON_FALSE(s_openthread_platform_initialized, ESP_ERR_INVALID_STATE, OT_PLAT_LOG_TAG,
|
ESP_RETURN_ON_FALSE(s_openthread_platform_initialized, ESP_ERR_INVALID_STATE, OT_PLAT_LOG_TAG,
|
||||||
|
|||||||
Reference in New Issue
Block a user