esp_openthread_lock.h 1.7 KB

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