esp_openthread.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 "esp_err.h"
  15. #include "esp_openthread_types.h"
  16. #include "openthread/error.h"
  17. #include "openthread/instance.h"
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /**
  22. * @brief Initializes the platform-specific support for the OpenThread stack.
  23. *
  24. * @note This function is not called by and will not call the OpenThread library.
  25. * The user needs to call otInstanceInitSingle to intialize the OpenThread
  26. * stack after calling this fucntion.
  27. *
  28. * @param[in] init_config The initialization configuration.
  29. *
  30. * @return
  31. * - ESP_OK on success
  32. * - ESP_ERR_NO_MEM if allocation has failed
  33. * - ESP_ERR_INVALID_ARG if radio or host connection mode not supported
  34. * - ESP_ERR_INVALID_STATE if already initialized
  35. *
  36. */
  37. esp_err_t esp_openthread_platform_init(const esp_openthread_platform_config_t *init_config);
  38. /**
  39. * This function performs all platform-specific deinitialization for OpenThread's drivers.
  40. *
  41. * @note This function is not called by the OpenThread library. Instead, the user should
  42. * call this function when deinitialization of OpenThread's drivers is most appropriate.
  43. *
  44. * @return
  45. * - ESP_OK on success
  46. * - ESP_ERR_INVALID_STATE if not initialized
  47. *
  48. */
  49. esp_err_t esp_openthread_platform_deinit(void);
  50. /**
  51. * @brief This function acquires the underlying OpenThread instance.
  52. *
  53. * @note This function can be called on other tasks without lock.
  54. *
  55. * @return The OpenThread instance pointer
  56. *
  57. */
  58. otInstance *esp_openthread_get_instance(void);
  59. /**
  60. * @brief This function updates the platform fds and timeouts
  61. *
  62. * @note This function will not update the OpenThread core stack pending events.
  63. * The users need to call `otTaskletsArePending` to check whether there being
  64. * pending OpenThread tasks.
  65. *
  66. * @param[inout] mainloop The main loop context.
  67. *
  68. */
  69. void esp_openthread_platform_update(esp_openthread_mainloop_context_t *mainloop);
  70. /**
  71. * @brief This function performs the OpenThread related platform process (radio, uart, alarm etc.)
  72. *
  73. * @note This function will call the OpenThread core stack process functions.
  74. * The users need to call `otTaskletsProcess` by self.
  75. *
  76. * @param[in] instance The OpenThread instance.
  77. * @param[in] mainloop The main loop context.
  78. *
  79. * @return
  80. * - ESP_OK on success
  81. * - ESP_FAIL on failure
  82. *
  83. */
  84. esp_err_t esp_openthread_platform_process(otInstance *instance, const esp_openthread_mainloop_context_t *mainloop);
  85. #ifdef __cplusplus
  86. } // end of extern "C"
  87. #endif