hpm_lobs_drv.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /*
  2. * Copyright (c) 2024 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_LOBS_DRV_H
  8. #define HPM_LOBS_DRV_H
  9. #include "hpm_common.h"
  10. #include "hpm_soc_ip_feature.h"
  11. #include "hpm_lobs_regs.h"
  12. /**
  13. * @brief LOBS driver APIs
  14. * @defgroup lobs_interface LOBS driver APIs
  15. * @ingroup lobs_interfaces
  16. * @{
  17. */
  18. #define LOBS_UNLOCK_KEY 0xc5acce55u
  19. #define LOBS_PIN_DO(x) (x * 3)
  20. #define LOBS_PIN_OE(x) (x * 3 + 1)
  21. #define LOBS_PIN_DI(x) (x * 3 + 2)
  22. /**
  23. * @brief group mode selection
  24. *
  25. */
  26. typedef enum {
  27. lobs_one_group_128_bits = 0,
  28. lobs_two_group_8_bits
  29. } lobs_group_mode_t; /**< lobs_group_mode_t */
  30. /**
  31. * @brief sample rate selection
  32. *
  33. */
  34. typedef enum {
  35. lobs_sample_1_per_5 = 4,
  36. lobs_sample_1_per_6 = 5,
  37. lobs_sample_1_per_7 = 6,
  38. } lobs_sample_rate_t; /**< lobs_sample_rate_t */
  39. /**
  40. * @brief burst selection
  41. *
  42. */
  43. typedef enum {
  44. lobs_burst_4 = 3,
  45. lobs_burst_8 = 5,
  46. lobs_burst_16 = 7,
  47. } lobs_burst_t; /**< lobs_burst_t */
  48. /**
  49. * @brief two group selection
  50. *
  51. */
  52. typedef enum {
  53. lobs_two_group_1 = 0,
  54. lobs_two_group_2,
  55. } lobs_two_group_sel_t; /**< lobs_two_group_sel_t */
  56. /**
  57. * @brief state selection
  58. *
  59. */
  60. typedef enum {
  61. lobs_state_0 = 0,
  62. lobs_state_1,
  63. lobs_state_2,
  64. lobs_state_3,
  65. lobs_state_4,
  66. } lobs_state_sel_t; /**< lobs_state_sel_t */
  67. /**
  68. * @brief compare mode
  69. *
  70. */
  71. typedef enum {
  72. lobs_sig_cmp_mode = 0,
  73. lobs_cnt_cmp_mode,
  74. } lobs_cmp_mode_t; /**< lobs_cmp_mode_t */
  75. /**
  76. * @brief compare condition
  77. *
  78. */
  79. typedef enum {
  80. lobs_cnt_matched = 0,
  81. lobs_sig_equal_golden,
  82. lobs_sig_greater_golden,
  83. lobs_sig_greater_equal_golden,
  84. lobs_sig_not_equal_golden,
  85. lobs_sig_less_golden,
  86. lobs_sig_less_equal_golden,
  87. } lobs_state_chg_condition_t; /**< lobs_state_chg_condition_t */
  88. /**
  89. * @brief next state
  90. *
  91. */
  92. typedef enum {
  93. lobs_next_state_finish = 0x00,
  94. lobs_next_state_0 = 0x01,
  95. lobs_next_state_1 = 0x02,
  96. lobs_next_state_2 = 0x04,
  97. lobs_next_state_3 = 0x08,
  98. lobs_next_state_4 = 0x10,
  99. } lobs_next_state_t; /**< lobs_next_state_t */
  100. /**
  101. * @brief ctrl config structure
  102. *
  103. */
  104. typedef struct {
  105. lobs_group_mode_t group_mode;
  106. lobs_sample_rate_t sample_rate;
  107. uint32_t start_addr;
  108. uint32_t end_addr;
  109. } lobs_ctrl_config_t; /**< lobs_ctrl_config_t */
  110. /**
  111. * @brief two group mode config structure
  112. *
  113. */
  114. typedef struct {
  115. bool group_enable;
  116. uint8_t sig_group_num;
  117. uint8_t sample_sig_bit[4];
  118. bool sample_sig_en[4];
  119. } lobs_two_group_mode_config_t; /**< lobs_two_group_mode_config_t */
  120. /**
  121. * @brief two group mode config structure
  122. *
  123. */
  124. typedef struct {
  125. uint8_t sig_group_num;
  126. lobs_cmp_mode_t cmp_mode;
  127. lobs_state_chg_condition_t state_chg_condition;
  128. lobs_next_state_t next_state;
  129. uint32_t cmp_counter;
  130. uint8_t cmp_sig_bit[4];
  131. bool cmp_sig_en[4];
  132. bool cmp_golden_value[4];
  133. } lobs_state_config_t; /**< lobs_state_config_t */
  134. #ifdef __cplusplus
  135. extern "C" {
  136. #endif
  137. /**
  138. * @brief set lobs unlock
  139. *
  140. * @param[in] lobs LOBS base address
  141. */
  142. static inline void lobs_unlock(LOBS_Type *lobs)
  143. {
  144. lobs->LAR = LOBS_UNLOCK_KEY;
  145. }
  146. /**
  147. * @brief set lobs lock
  148. *
  149. * @param[in] lobs LOBS base address
  150. */
  151. static inline void lobs_lock(LOBS_Type *lobs)
  152. {
  153. lobs->LAR = 0;
  154. }
  155. /**
  156. * @brief set lobs enable or disable
  157. *
  158. * @param[in] lobs LOBS base address
  159. * @param[in] enable true - enable; false - disable.
  160. */
  161. static inline void lobs_set_enable(LOBS_Type *lobs, bool enable)
  162. {
  163. lobs->CTRL = (lobs->CTRL & ~LOBS_CTRL_RUN_MASK) | LOBS_CTRL_RUN_SET(enable);
  164. }
  165. /**
  166. * @brief set lobs pre-trig enable or disable
  167. *
  168. * @param[in] lobs LOBS base address
  169. * @param[in] enable true - enable; false - disable.
  170. */
  171. static inline void lobs_set_pre_trig_enable(LOBS_Type *lobs, bool enable)
  172. {
  173. lobs->PTACTION = (lobs->PTACTION & ~LOBS_PTACTION_TRACE_MASK) | LOBS_PTACTION_TRACE_SET(enable);
  174. }
  175. /**
  176. * @brief set lobs state enable or disable
  177. *
  178. * @param[in] lobs LOBS base address
  179. * @param[in] state one of state, @ref lobs_state_sel_t
  180. * @param[in] enable true - enable; false - disable.
  181. */
  182. static inline void lobs_set_state_enable(LOBS_Type *lobs, lobs_state_sel_t state, bool enable)
  183. {
  184. lobs->STATE[state].ACTION = (lobs->STATE[state].ACTION & ~LOBS_STATE_ACTION_TRACE_MASK) | LOBS_STATE_ACTION_TRACE_SET(enable);
  185. }
  186. /**
  187. * @brief get lobs final address
  188. *
  189. * @param[in] lobs LOBS base address
  190. *
  191. * @return uint32_t trace final address
  192. */
  193. static inline uint32_t lobs_get_final_address(LOBS_Type *lobs)
  194. {
  195. return lobs->FINALADDR;
  196. }
  197. /**
  198. * @brief check lobs trace finish
  199. *
  200. * @param[in] lobs LOBS base address
  201. *
  202. * @return bool true - trace finish; false - trace not finish
  203. */
  204. static inline bool lobs_is_trace_finish(LOBS_Type *lobs)
  205. {
  206. return (LOBS_CTSR_FINALSTATE_GET(lobs->CTSR) != 0) ? true : false;
  207. }
  208. /**
  209. * @brief clear lobs fifo overflow flag
  210. *
  211. * @param[in] lobs LOBS base address
  212. *
  213. */
  214. static inline void lobs_clear_fifo_overflow_flag(LOBS_Type *lobs)
  215. {
  216. lobs->STREAMCTRL |= LOBS_STREAMCTRL_FULL_CLEAR_MASK;
  217. }
  218. /**
  219. * @brief lobs deinit
  220. *
  221. * @param[in] lobs LOBS base address
  222. */
  223. void lobs_deinit(LOBS_Type *lobs);
  224. /**
  225. * @brief lobs control config
  226. *
  227. * @param[in] lobs LOBS base address
  228. * @param[in] config control config structure pointer
  229. */
  230. void lobs_ctrl_config(LOBS_Type *lobs, lobs_ctrl_config_t *config);
  231. /**
  232. * @brief lobs two group mode config
  233. *
  234. * @param[in] lobs LOBS base address
  235. * @param[in] group one of the two group, @ref lobs_two_group_sel_t
  236. * @param[in] config two group mode config structure pointer
  237. */
  238. void lobs_two_group_mode_config(LOBS_Type *lobs, lobs_two_group_sel_t group, lobs_two_group_mode_config_t *config);
  239. /**
  240. * @brief lobs state config
  241. *
  242. * @param[in] lobs LOBS base address
  243. * @param[in] state one of state, @ref lobs_state_sel_t
  244. * @param[in] config state config structure pointer
  245. */
  246. void lobs_state_config(LOBS_Type *lobs, lobs_state_sel_t state, lobs_state_config_t *config);
  247. #ifdef __cplusplus
  248. }
  249. #endif
  250. /**
  251. * @}
  252. */
  253. #endif /* HPM_LOBS_DRV_H */