cfw_dispatch.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _CFW_DISPATCH_H_
  13. #define _CFW_DISPATCH_H_
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include <stddef.h>
  17. #include "osi_api.h"
  18. #include "osi_event_hub.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /**
  23. * @brief indicate invalid UTI or UTI unavailable
  24. */
  25. #define CFW_UTI_INVALID (0xffff)
  26. /**
  27. * @brief CFW event dispatch initialization
  28. */
  29. void cfwDispatchInit(void);
  30. /**
  31. * @brief set CFW event dispatch main thread
  32. *
  33. * When the UTI of CFW event is not registered, the event
  34. * will be sent to the *main thread*.
  35. *
  36. * @param thread main thread to be set
  37. */
  38. void cfwDispatchSetMainThread(osiThread_t *thread);
  39. /**
  40. * @brief request a UTI, response to current thread
  41. *
  42. * Request a UTI, and set the CFW event with the specified UTI will be send to
  43. * current thread, that is the caller thread.
  44. *
  45. * @param cb callback to be invoked when UTI matches
  46. * @param cb_ctx callback context
  47. * @return
  48. * - requested UTI
  49. * - CFW_UTI_INVALID if no free UTI
  50. */
  51. uint16_t cfwRequestUTI(osiEventCallback_t cb, void *cb_ctx);
  52. #ifdef CONFIG_QUEC_PROJECT_FEATURE
  53. #define QUCE_REQUEST_UTI_RETRY_CNT_MAX 5
  54. /**
  55. * @brief request a UTI, response to current thread
  56. *
  57. * Request a UTI, and set the CFW event with the specified UTI will be send to
  58. * current thread, that is the caller thread.
  59. *
  60. * @param cb callback to be invoked when UTI matches
  61. * @param cb_ctx callback context
  62. * @return
  63. * - requested UTI
  64. * - CFW_UTI_INVALID if no free UTI
  65. */
  66. uint16_t quec_cfwRequestUTI(osiEventCallback_t cb, void *cb_ctx);
  67. #endif
  68. /**
  69. * @brief request a UTI with more options
  70. *
  71. * The thread for the arriving matched UTI can be specified.
  72. *
  73. * Normally, the UTI registration will be removed automatically when the first
  74. * event is handled in \a cfwInvokeUtiCallback. In case there are more than one
  75. * event with the UTI will arrive, \a auto_remove can be set to false. Then the
  76. * UTI registration won't be removed automatically. Rather, it should be
  77. * released manually.
  78. *
  79. * @param cb callback to be invoked when UTI matches
  80. * @param cb_ctx callback context
  81. * @param thread the thread should receive response event, NULL for current thread
  82. * @param auto_remove auto remove the UTI registration after callback is invoked
  83. * @return
  84. * - requested UTI
  85. * - CFW_UTI_INVALID if no free UTI
  86. */
  87. uint16_t cfwRequestUTIEx(osiEventCallback_t cb, void *cb_ctx, osiThread_t *thread, bool auto_remove);
  88. /**
  89. * @brief request a UTI, and not register response thread
  90. *
  91. * Only when the caller doesn't care about the response event,
  92. * it should be called. When the response arrived, the caller
  93. * thread may not be able to receive the response event.
  94. *
  95. * The requested UTI will be reused automatically. It is not
  96. * needed and not permitted to call \p cfwReleaseUTI.
  97. *
  98. * @return
  99. * - requested UTI
  100. * - CFW_UTI_INVALID if no free UTI
  101. */
  102. uint16_t cfwRequestNoWaitUTI(void);
  103. /**
  104. * @brief request a registered UTI with response to current thread
  105. *
  106. * When it is known that response event won't arrive, for example,
  107. * the call returns error, it *must* be called. Otherwise, the
  108. * UTI resource will be leaked.
  109. *
  110. * When there are registered (UTI, thread) combination can match,
  111. * it will return silently.
  112. *
  113. * @param uti the UTI to be released
  114. */
  115. void cfwReleaseUTI(uint16_t uti);
  116. /**
  117. * @brief dispatch CFW event
  118. *
  119. * When CFW event is about to be sent, this *must* be called.
  120. * And it will ensure the event to be sent to proper thread.
  121. *
  122. * The event *MUST* be CFW event, that is, the third parameter follows
  123. * CFW event convention.
  124. *
  125. * It won't fail to send. When the UTI is registered, it will be
  126. * sent to the registered thread. Otherwise, it will be sent to
  127. * the main thread. And if main thread is not set, it will be
  128. * dropped.
  129. *
  130. * @param event the event to be sent, and must be CFW event
  131. */
  132. void cfwDispatchSendEvent(const osiEvent_t *event);
  133. /**
  134. * @brief check whether the event ID is CFW event
  135. *
  136. * @param id the event ID
  137. * @return
  138. * - true if it is CFW event
  139. * - false if it is not CFW event
  140. */
  141. bool cfwIsCfwEvent(uint32_t id);
  142. /**
  143. * @brief check whether the indicate ID is CFW indicate event
  144. *
  145. * @param id the indicate ID
  146. * @return
  147. * - true if it is CFW indicate event
  148. * - false if it is not CFW indicate event
  149. */
  150. bool cfwIsCfwIndicate(uint32_t id);
  151. /**
  152. * @brief invoke registered callback
  153. *
  154. * When a registered callback is invoked, and the event id matches the registered
  155. * last UTI or the registration doesn't specify event id, it will be unregistered
  156. * automatically
  157. *
  158. * @param event input event, must be \p CFW_EVENT
  159. * @return
  160. * - true if the registered callback is invoked
  161. * - false if \p event is not a CFW_EVENT, or the UTI is not registered
  162. */
  163. bool cfwInvokeUtiCallback(const osiEvent_t *event);
  164. #ifdef __cplusplus
  165. }
  166. #endif
  167. #endif