1 // Copyright 2021 Espressif Systems (Shanghai) CO LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License
14 
15 #pragma once
16 
17 #include <stdbool.h>
18 
19 #include "esp_err.h"
20 #include "freertos/FreeRTOS.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 /**
27  * @brief This function initializes the OpenThread API lock.
28  *
29  * @return
30  *      - ESP_OK on success
31  *      - ESP_ERR_NO_MEM if allocation has failed
32  *      - ESP_ERR_INVALID_STATE if already initialized
33  *
34  */
35 esp_err_t esp_openthread_lock_init(void);
36 
37 /**
38  * This function deinitializes the OpenThread API lock.
39  *
40  */
41 void esp_openthread_lock_deinit(void);
42 
43 /**
44  * @brief This functions acquires the OpenThread API lock.
45  *
46  * @note Every OT APIs that takes an otInstance argument MUST be protected with this API lock
47  *       except that the call site is in OT callbacks.
48  *
49  * @param[in] block_ticks   The maxinum number of RTOS ticks to wait for the lock.
50  *
51  * @return
52  *      - True on lock acquired
53  *      - False on failing to acquire the lock with the timeout.
54  *
55  */
56 bool esp_openthread_lock_acquire(TickType_t block_ticks);
57 
58 /**
59  * @brief This function releases the OpenThread API lock.
60  *
61  */
62 void esp_openthread_lock_release(void);
63 
64 
65 #ifdef __cplusplus
66 }
67 #endif
68