Skip to content

Commit

Permalink
ESP32: Add functions to delete OpenThread task and deinit OpenThread …
Browse files Browse the repository at this point in the history
…stack (#36168)
  • Loading branch information
wqx6 authored Nov 5, 2024
1 parent 5158c55 commit 2a7106f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
49 changes: 42 additions & 7 deletions src/platform/ESP32/OpenthreadLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@
#include <esp_openthread_border_router.h>
#endif

static esp_netif_t * openthread_netif = NULL;
static esp_openthread_platform_config_t * s_platform_config = NULL;
static TaskHandle_t cli_transmit_task = NULL;
static QueueHandle_t cli_transmit_task_queue = NULL;
static esp_netif_t * openthread_netif = nullptr;
static esp_openthread_platform_config_t * s_platform_config = nullptr;
static TaskHandle_t cli_transmit_task = nullptr;
static QueueHandle_t cli_transmit_task_queue = nullptr;
static TaskHandle_t openthread_task = nullptr;
static constexpr uint16_t OTCLI_TRANSMIT_TASK_STACK_SIZE = 1024;
static constexpr UBaseType_t OTCLI_TRANSMIT_TASK_PRIORITY = 5;
static const char * TAG = "OpenThread";

CHIP_ERROR cli_transmit_task_post(std::unique_ptr<char[]> && cli_str)
{
Expand Down Expand Up @@ -116,6 +118,14 @@ static esp_err_t cli_command_transmit_task(void)
return ESP_OK;
}

static void cli_command_transmit_task_delete(void)
{
if (cli_transmit_task)
{
vTaskDelete(cli_transmit_task);
}
}

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 @@ -141,7 +151,6 @@ static void ot_task_worker(void * context)
#if defined(CONFIG_OPENTHREAD_BORDER_ROUTER) && defined(CONFIG_AUTO_UPDATE_RCP)

static constexpr size_t kRcpVersionMaxSize = 100;
static const char * TAG = "RCP_UPDATE";

static void update_rcp(void)
{
Expand Down Expand Up @@ -230,7 +239,15 @@ esp_err_t openthread_init_stack(void)
};

ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_vfs_eventfd_register(&eventfd_config));
esp_err_t err = esp_vfs_eventfd_register(&eventfd_config);
if (err == ESP_ERR_INVALID_STATE)
{
ESP_LOGW(TAG, "eventfd is already registered");
}
else if (err != ESP_OK)
{
return err;
}
assert(s_platform_config);
// Initialize the OpenThread stack
ESP_ERROR_CHECK(esp_openthread_init(s_platform_config));
Expand All @@ -248,6 +265,24 @@ esp_err_t openthread_init_stack(void)

esp_err_t openthread_launch_task(void)
{
xTaskCreate(ot_task_worker, "ot_task", CONFIG_THREAD_TASK_STACK_SIZE, xTaskGetCurrentTaskHandle(), 5, NULL);
xTaskCreate(ot_task_worker, "ot_task", CONFIG_THREAD_TASK_STACK_SIZE, xTaskGetCurrentTaskHandle(), 5, &openthread_task);
return ESP_OK;
}

esp_err_t openthread_deinit_stack(void)
{
esp_openthread_netif_glue_deinit();
esp_netif_destroy(openthread_netif);
#ifdef CONFIG_OPENTHREAD_CLI
cli_command_transmit_task_delete();
#endif
return esp_openthread_deinit();
}

void openthread_delete_task(void)
{
if (openthread_task)
{
vTaskDelete(openthread_task);
}
}
2 changes: 2 additions & 0 deletions src/platform/ESP32/OpenthreadLauncher.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ esp_err_t openthread_init_br_rcp(const esp_rcp_update_config_t * update_config);
esp_err_t set_openthread_platform_config(esp_openthread_platform_config_t * config);
esp_err_t openthread_init_stack(void);
esp_err_t openthread_launch_task(void);
esp_err_t openthread_deinit_stack(void);
void openthread_delete_task(void);
CHIP_ERROR cli_transmit_task_post(std::unique_ptr<char[]> && cli_str);

0 comments on commit 2a7106f

Please sign in to comment.