pam_worker.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. #ifndef _PAM_WORKER_H_
  2. #define _PAM_WORKER_H_
  3. #include <stdint.h>
  4. #include <stdbool.h>
  5. #include "osi_api.h"
  6. #include "osi_event_hub.h"
  7. #include "osi_mem_recycler.h"
  8. #include "pam_config.h"
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. #ifdef CONFIG_PAM_LTE_GNSS_WIFISCAN_SUPPORT
  13. #define RETURN_IF_NULL(VarPointer) OSI_DO_WHILE0(if (pamVarIsNullPointer(VarPointer)) return; else break;)
  14. typedef enum
  15. {
  16. IGNORE_VALUE = 0,
  17. AUTO_GNSS_ON,
  18. USER_GNSS_ON,
  19. AUTO_GNSS_OFF,
  20. USER_GNSS_OFF,
  21. _PAM_END
  22. } PAM_GNSS_SWITCH_CTRL;
  23. typedef enum
  24. {
  25. PAM_NO_WORK,
  26. PAM_GNSS_WORK,
  27. PAM_WIFISCAN_WORK,
  28. PAM_LTE_WORK,
  29. } PAM_WORK_TYPE;
  30. typedef struct
  31. {
  32. uint32_t ev_id;
  33. bool auto_remove;
  34. osiThread_t *thread;
  35. osiEventCallback_t cb;
  36. void *cb_ctx;
  37. } pamEvidRegistry_t;
  38. #define CONFIG_PAM_PENDING_EVID_COUNT 64
  39. typedef struct
  40. {
  41. osiMutex_t *lock;
  42. osiThread_t *main_thread;
  43. pamEvidRegistry_t pending_evid_regs[CONFIG_PAM_PENDING_EVID_COUNT];
  44. uint16_t pending_evid_count;
  45. } pamGnssContext_t;
  46. typedef struct
  47. {
  48. osiThread_t *pamThread;
  49. osiThread_t *pamDelayThread;
  50. osiEventDispatch_t *id_man; // register by event ID
  51. osiEventHub_t *event_hub; // static dispatch
  52. osiMemRecycler_t *mem_recycler;
  53. } pamEngine_t;
  54. typedef struct
  55. {
  56. uint8_t state; //machine state
  57. uint8_t gnssCtrlSwitch; //user stop or sys stop
  58. PAM_WORK_TYPE workType; // 1:gnss, 2:wifiscan, 3:lte, others:reserve
  59. } pamSetting_t;
  60. extern pamSetting_t pamInfo;
  61. /**
  62. * @brief create binding event callback handler.
  63. */
  64. void pamEngineInit(void);
  65. /**
  66. * @brief set user ctrl on/off or auto ctrl on/off gnss.
  67. * @param onType:AUTO_GNSS_ON, USER_GNSS_ON
  68. * offType:AUTO_GNSS_OFF, USER_GNSS_OFF
  69. */
  70. void pamSetGnssSwitchCtrl(PAM_GNSS_SWITCH_CTRL onType, PAM_GNSS_SWITCH_CTRL offType);
  71. /**
  72. * @brief get gnss on/off switch ctrl value.
  73. * @return: gnssCtrlSwitch&0x0F:onType user or auto
  74. * gnssCtrlSwitch&0xF0:offType user or auto
  75. * enum PAM_GNSS_SWITCH_CTRL
  76. */
  77. uint8_t pamGetGnssSwitchCtrl(void);
  78. /**
  79. * @brief set pam module work type.
  80. * @param type value from PAM_WORK_TYPE
  81. */
  82. void pamSetModuleWorkType(uint8_t type);
  83. /**
  84. * @brief get pam module work type.
  85. * @return workType
  86. * PAM_NO_WORK,
  87. * PAM_GNSS_WORK,
  88. * PAM_WIFISCAN_WORK,
  89. * PAM_LTE_WORK,
  90. */
  91. uint8_t pamGetModuleWorkType(void);
  92. /**
  93. * @brief send event to others task,
  94. * taskid from pamCreateAsyncReg func
  95. */
  96. void pamWorkerSendEvent(const osiEvent_t *event);
  97. /**
  98. * @brief reveive event is distributed to the
  99. * callback function correspondif to the event
  100. */
  101. bool pamInvokeEvidCallback(const osiEvent_t *event);
  102. /**
  103. * @brief release event id
  104. */
  105. void pamReleaseEvid(uint32_t ev_id_cnf);
  106. /**
  107. * @brief pam worker init config gPamGnssCtx.
  108. */
  109. void pamWorkerInit(void);
  110. /**
  111. * @brief get event name
  112. * @return event name
  113. */
  114. const char *pamEventName(uint32_t id);
  115. /**
  116. * @brief Register event handler.
  117. */
  118. bool pamEventsRegister(uint32_t id, ...);
  119. /**
  120. * @brief urc display text.
  121. */
  122. void pamRespSimUrcText(uint8_t nSim, const char *text);
  123. /**
  124. * @brief if VarPointer is null, return.
  125. */
  126. bool pamVarIsNullPointer(void *VarPointer);
  127. /**
  128. * @brief entry pam thread callback.
  129. */
  130. void pamThreadCallback(osiCallback_t cb, void *ctx);
  131. /**
  132. * @brief mapping the id of the reveived and sent event.
  133. * @param ID of the event to send.
  134. * @return ID of the event to be received.
  135. */
  136. uint32_t pamMapEventId(uint32_t eventId);
  137. /**
  138. * @brief get pam thread id.
  139. */
  140. osiThread_t *pamGetTaskID(void);
  141. /**
  142. * @brief get pam_delay thread id.
  143. */
  144. osiThread_t *pamGetDelayTaskID(void);
  145. /**
  146. * @brief Entry pam_delay task callback.
  147. */
  148. void pamDelayThreadCallback(osiCallback_t cb, void *ctx);
  149. /**
  150. * @brief create a callback function for asynchronous events.
  151. * @param cb: callback function
  152. * @param cb_ctx: config value
  153. * @param thread: task id
  154. * @param auto_remove: auto release received id.
  155. * @param event_id: ID of the event to send
  156. */
  157. uint32_t pamCreateAsyncReg(osiEventCallback_t cb, void *cb_ctx, osiThread_t *thread, bool auto_remove, uint32_t event_id);
  158. /**
  159. * @brief gnss and cfw event distribution control.
  160. */
  161. bool pamIsHandleCfwOrGnssCB(const osiEvent_t *event);
  162. /**
  163. * @brief Determine whether there it's an indicator event .
  164. */
  165. bool pamIsCfwOrGnssIndicate(uint32_t nEventId);
  166. /**
  167. * @brief Determine whether there it's a pam event .
  168. */
  169. bool pamIsPamEvent(uint32_t nEventId);
  170. /**
  171. * @brief send event data to others task.
  172. * @param event: event data.
  173. * @param hsl_gnss_flag: gnss event or cfw event flage.
  174. */
  175. void pamSendEvent(osiEvent_t *event, uint8_t hsl_gnss_flag);
  176. /**
  177. * @brief init pam engine and worker
  178. * create pamThread and pamDelayThread task.
  179. */
  180. void pamStart(void);
  181. // ===========================from mal handle==========================================
  182. #define PAM_THREAD_STACK_SIZE (2048)
  183. #define PAM_THREAD_EVENT_COUNT (50)
  184. typedef void (*pamContextDelete_t)(void *ctx);
  185. typedef enum
  186. {
  187. PAM_BINDER_UNKNOWN = 0,
  188. PAM_BINDER_UTI,
  189. } pamBinderType_t;
  190. typedef struct
  191. {
  192. pamBinderType_t type;
  193. uint16_t uti;
  194. uint32_t event_id_cnf;
  195. void *ctx;
  196. pamContextDelete_t ctx_delete;
  197. osiSemaphore_t *wait_sema;
  198. } pamBinderaction_t;
  199. typedef struct
  200. {
  201. pamGnssContext_t gPamGnssCtx;
  202. pamBinderaction_t gPamBinderCtx;
  203. } pamContext_t;
  204. /**
  205. * \brief transaction event callback function prototype
  206. *
  207. * The callback will be invoked in separated thread.
  208. */
  209. typedef void (*pamBinderCallback_t)(pamBinderaction_t *binder, const osiEvent_t *event);
  210. /**
  211. * \brief macro to terminate transaction and return error code
  212. */
  213. #define PAM_BINDER_RETURN_ERR(binder, err) OSI_DO_WHILE0(pamTerminateBinder(binder); return (err);)
  214. void pamSetBinderContext(pamBinderaction_t *binder, void *ctx, pamContextDelete_t destroy);
  215. pamBinderaction_t *pamCreateBinder(void);
  216. void pamStartAsyncBinder(pamBinderaction_t *binder, pamBinderCallback_t cb, uint32_t nEventId, bool auto_remove);
  217. uint16_t pamStartNoWaitUtiBinder(void);
  218. void pamAbortBinder(pamBinderaction_t *binder);
  219. void pamTerminateBinder(pamBinderaction_t *binder);
  220. uint16_t pamBinderUti(pamBinderaction_t *binder);
  221. void pamBinderFinished(pamBinderaction_t *binder);
  222. bool pamBinderWait(pamBinderaction_t *binder, unsigned timeout);
  223. void pamContextFree(void *ctx);
  224. void *pamBinderContext(pamBinderaction_t *binder);
  225. #endif //CONFIG_PAM_LTE_GNSS_WIFISCAN_SUPPORT
  226. #endif //_PAM_DISPATCH_H_