2022-12-18 21:50:08 -05:00
|
|
|
/*
|
2024-05-21 23:28:24 -04:00
|
|
|
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
2022-12-18 21:50:08 -05:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2021-04-02 02:49:49 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include "esp_err.h"
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This function initializes the OpenThread API lock.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK on success
|
|
|
|
* - ESP_ERR_NO_MEM if allocation has failed
|
|
|
|
* - ESP_ERR_INVALID_STATE if already initialized
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
esp_err_t esp_openthread_lock_init(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function deinitializes the OpenThread API lock.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void esp_openthread_lock_deinit(void);
|
|
|
|
|
|
|
|
/**
|
2022-12-18 21:50:08 -05:00
|
|
|
* @brief This function acquires the OpenThread API lock.
|
2021-04-02 02:49:49 -04:00
|
|
|
*
|
2024-05-21 23:28:24 -04:00
|
|
|
* @note Every Openthread APIs that takes an otInstance argument MUST be protected with this API lock
|
|
|
|
* except that the call site is in Openthread callbacks.
|
2021-04-02 02:49:49 -04:00
|
|
|
*
|
2024-05-21 23:28:24 -04:00
|
|
|
* @param[in] block_ticks The maximum number of RTOS ticks to wait for the lock.
|
2021-04-02 02:49:49 -04:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - True on lock acquired
|
|
|
|
* - False on failing to acquire the lock with the timeout.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
bool esp_openthread_lock_acquire(TickType_t block_ticks);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This function releases the OpenThread API lock.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void esp_openthread_lock_release(void);
|
|
|
|
|
2022-12-18 21:50:08 -05:00
|
|
|
/**
|
|
|
|
* @brief This function acquires the OpenThread API task switching lock.
|
|
|
|
*
|
|
|
|
* @note In OpenThread API context, it waits for some actions to be done in other tasks (like lwip),
|
|
|
|
* after task switching, it needs to call OpenThread API again. Normally it's not allowed,
|
2022-12-26 06:05:19 -05:00
|
|
|
* since the previous OpenThread API lock is not released yet. This task_switching lock allows
|
2022-12-18 21:50:08 -05:00
|
|
|
* the OpenThread API can be called in this case.
|
|
|
|
*
|
2022-12-26 06:05:19 -05:00
|
|
|
* @note Please use esp_openthread_lock_acquire() for normal cases.
|
2022-12-26 02:48:07 -05:00
|
|
|
*
|
2024-05-21 23:28:24 -04:00
|
|
|
* @param[in] block_ticks The maximum number of RTOS ticks to wait for the lock.
|
2022-12-18 21:50:08 -05:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - True on lock acquired
|
|
|
|
* - False on failing to acquire the lock with the timeout.
|
|
|
|
*
|
|
|
|
*/
|
2022-12-26 02:48:07 -05:00
|
|
|
bool esp_openthread_task_switching_lock_acquire(TickType_t block_ticks);
|
2022-12-18 21:50:08 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This function releases the OpenThread API task switching lock.
|
|
|
|
*
|
2024-05-21 23:28:24 -04:00
|
|
|
* @note This API must be called after `esp_openthread_task_switching_lock_acquire` or
|
|
|
|
* `esp_openthread_lock_acquire` and will cause a crash if the current task is not the task switching lock holder.
|
|
|
|
* This error could be caused by calling OpenThread APIs without locking OpenThread stack.
|
2022-12-18 21:50:08 -05:00
|
|
|
*/
|
|
|
|
void esp_openthread_task_switching_lock_release(void);
|
2021-04-02 02:49:49 -04:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|