esp_openthread_lock.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stdbool.h>
  8. #include "esp_err.h"
  9. #include "freertos/FreeRTOS.h"
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /**
  14. * @brief This function initializes the OpenThread API lock.
  15. *
  16. * @return
  17. * - ESP_OK on success
  18. * - ESP_ERR_NO_MEM if allocation has failed
  19. * - ESP_ERR_INVALID_STATE if already initialized
  20. *
  21. */
  22. esp_err_t esp_openthread_lock_init(void);
  23. /**
  24. * This function deinitializes the OpenThread API lock.
  25. *
  26. */
  27. void esp_openthread_lock_deinit(void);
  28. /**
  29. * @brief This function acquires the OpenThread API lock.
  30. *
  31. * @note Every OT APIs that takes an otInstance argument MUST be protected with this API lock
  32. * except that the call site is in OT callbacks.
  33. *
  34. * @param[in] block_ticks The maxinum number of RTOS ticks to wait for the lock.
  35. *
  36. * @return
  37. * - True on lock acquired
  38. * - False on failing to acquire the lock with the timeout.
  39. *
  40. */
  41. bool esp_openthread_lock_acquire(TickType_t block_ticks);
  42. /**
  43. * @brief This function releases the OpenThread API lock.
  44. *
  45. */
  46. void esp_openthread_lock_release(void);
  47. /**
  48. * @brief This function acquires the OpenThread API task switching lock.
  49. *
  50. * @note In OpenThread API context, it waits for some actions to be done in other tasks (like lwip),
  51. * after task switching, it needs to call OpenThread API again. Normally it's not allowed,
  52. * since the previous OpenThread API lock is not released yet. This task_switching lock allows
  53. * the OpenThread API can be called in this case.
  54. *
  55. * @note Please use esp_openthread_lock_acquire() for normal cases.
  56. *
  57. * @param[in] block_ticks The maxinum number of RTOS ticks to wait for the lock.
  58. *
  59. * @return
  60. * - True on lock acquired
  61. * - False on failing to acquire the lock with the timeout.
  62. *
  63. */
  64. bool esp_openthread_task_switching_lock_acquire(TickType_t block_ticks);
  65. /**
  66. * @brief This function releases the OpenThread API task switching lock.
  67. *
  68. */
  69. void esp_openthread_task_switching_lock_release(void);
  70. #ifdef __cplusplus
  71. }
  72. #endif