mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-29 18:27:20 +02:00
Merge branch 'feat/and_function_to_exit_ot_mainloop_v5.3' into 'release/v5.3'
feat(openthread): add a function to exit openthread mainloop safely (v5.3) See merge request espressif/esp-idf!39612
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -79,6 +79,15 @@ esp_err_t esp_openthread_deinit(void);
|
||||
*/
|
||||
otInstance *esp_openthread_get_instance(void);
|
||||
|
||||
/**
|
||||
* @brief Signals the OpenThread main loop to exit.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_FAIL on failures
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_openthread_mainloop_exit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // end of extern "C"
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include "openthread/dataset_ftd.h"
|
||||
#endif
|
||||
|
||||
static bool s_ot_mainloop_running = false;
|
||||
|
||||
static int hex_digit_to_int(char hex)
|
||||
{
|
||||
if ('A' <= hex && hex <= 'F') {
|
||||
@ -158,13 +160,24 @@ esp_err_t esp_openthread_auto_start(otOperationalDatasetTlvs *datasetTlvs)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void mainloop_safe_exit(void *ctx)
|
||||
{
|
||||
s_ot_mainloop_running = false;
|
||||
}
|
||||
|
||||
esp_err_t esp_openthread_mainloop_exit(void)
|
||||
{
|
||||
return esp_openthread_task_queue_post(mainloop_safe_exit, NULL);
|
||||
}
|
||||
|
||||
esp_err_t esp_openthread_launch_mainloop(void)
|
||||
{
|
||||
esp_openthread_mainloop_context_t mainloop;
|
||||
otInstance *instance = esp_openthread_get_instance();
|
||||
esp_err_t error = ESP_OK;
|
||||
s_ot_mainloop_running = true;
|
||||
|
||||
while (true) {
|
||||
while (s_ot_mainloop_running) {
|
||||
FD_ZERO(&mainloop.read_fds);
|
||||
FD_ZERO(&mainloop.write_fds);
|
||||
FD_ZERO(&mainloop.error_fds);
|
||||
|
Reference in New Issue
Block a user