esp_openthread_platform.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 "esp_err.h"
  8. #include "esp_openthread_types.h"
  9. #include "openthread/error.h"
  10. #include "openthread/instance.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. #define WORKFLOW_MAX_NAMELEN 16
  15. /**
  16. * @brief update function declaration
  17. *
  18. * @param[inout] mainloop The main loop context.
  19. *
  20. */
  21. typedef void (*esp_openthread_update_func)(esp_openthread_mainloop_context_t *mainloop);
  22. /**
  23. * @brief process function declaration
  24. *
  25. * @param[in] instance The OpenThread instance.
  26. * @param[in] mainloop The main loop context.
  27. *
  28. * @return
  29. * - ESP_OK
  30. * - ESP_FAIL
  31. *
  32. */
  33. typedef esp_err_t (*esp_openthread_process_func)(otInstance *instance,
  34. const esp_openthread_mainloop_context_t *mainloop);
  35. /**
  36. * @brief This struct contains a platform update function, a platform process function
  37. * and the workflow name
  38. *
  39. * @note The structs will form a list, and the update functions and process functions in the list
  40. * will be called in esp_openthread_platform_update and esp_openthread_platform_process.
  41. *
  42. */
  43. typedef struct esp_openthread_platform_workflow {
  44. char name[WORKFLOW_MAX_NAMELEN];
  45. esp_openthread_update_func update_func;
  46. esp_openthread_process_func process_func;
  47. struct esp_openthread_platform_workflow *next;
  48. } esp_openthread_platform_workflow_t;
  49. /**
  50. * @brief This function adds a esp_openthread_platform_workflow to the workflow list
  51. *
  52. *
  53. * @param[in] updatefcn The update function of the workflow added to the list.
  54. * @param[in] processfcn The process function of the workflow added to the list.
  55. * @param[in] name The name of the added workflow
  56. *
  57. * @return
  58. * - ESP_OK on success
  59. * - ESP_ERR_NO_MEM on allocation failure
  60. * - ESP_FAIL on other failures
  61. *
  62. */
  63. esp_err_t esp_openthread_platform_workflow_register(esp_openthread_update_func update_func,
  64. esp_openthread_process_func process_func, const char *name);
  65. /**
  66. * @brief This function removes a esp_openthread_platform_workflow according the input name
  67. * from the workflow list
  68. *
  69. * @param[in] name The name of the removed workflow
  70. *
  71. */
  72. void esp_openthread_platform_workflow_unregister(const char *name);
  73. /**
  74. * @brief Initializes the platform-specific support for the OpenThread stack.
  75. *
  76. * @note This function is not called by and will not call the OpenThread library.
  77. * The user needs to call otInstanceInitSingle to intialize the OpenThread
  78. * stack after calling this function.
  79. *
  80. * @param[in] init_config The initialization configuration.
  81. *
  82. * @return
  83. * - ESP_OK on success
  84. * - ESP_ERR_NO_MEM if allocation has failed
  85. * - ESP_ERR_INVALID_ARG if radio or host connection mode not supported
  86. * - ESP_ERR_INVALID_STATE if already initialized
  87. *
  88. */
  89. esp_err_t esp_openthread_platform_init(const esp_openthread_platform_config_t *init_config);
  90. /**
  91. * This function performs all platform-specific deinitialization for OpenThread's drivers.
  92. *
  93. * @note This function is not called by the OpenThread library. Instead, the user should
  94. * call this function when deinitialization of OpenThread's drivers is most appropriate.
  95. *
  96. * @return
  97. * - ESP_OK on success
  98. * - ESP_ERR_INVALID_STATE if not initialized
  99. *
  100. */
  101. esp_err_t esp_openthread_platform_deinit(void);
  102. /**
  103. * @brief This function updates the platform fds and timeouts
  104. *
  105. * @note This function will not update the OpenThread core stack pending events.
  106. * The users need to call `otTaskletsArePending` to check whether there being
  107. * pending OpenThread tasks.
  108. *
  109. * @param[inout] mainloop The main loop context.
  110. *
  111. */
  112. void esp_openthread_platform_update(esp_openthread_mainloop_context_t *mainloop);
  113. /**
  114. * @brief This function performs the OpenThread related platform process (radio, uart, alarm etc.)
  115. *
  116. * @note This function will call the OpenThread core stack process functions.
  117. * The users need to call `otTaskletsProcess` by self.
  118. *
  119. * @param[in] instance The OpenThread instance.
  120. * @param[in] mainloop The main loop context.
  121. *
  122. * @return
  123. * - ESP_OK on success
  124. * - ESP_FAIL on failure
  125. *
  126. */
  127. esp_err_t esp_openthread_platform_process(otInstance *instance, const esp_openthread_mainloop_context_t *mainloop);
  128. /**
  129. * @brief This function set the OpenThread storage name
  130. *
  131. * @param[in] name The OpenThread storage name.
  132. *
  133. */
  134. void esp_openthread_set_storage_name(const char *name);
  135. #ifdef __cplusplus
  136. } // end of extern "C"
  137. #endif