hpm_plb_drv.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*
  2. * Copyright (c) 2023 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_PLB_DRV_H
  8. #define HPM_PLB_DRV_H
  9. #include "hpm_common.h"
  10. #include "hpm_plb_regs.h"
  11. /**
  12. * @brief PLB driver APIs
  13. * @defgroup plb_interface PLB driver APIs
  14. * @ingroup io_interfaces
  15. * @{
  16. */
  17. #define PLB_SLICE_MASK (0xf)
  18. #define PLB_SLICE_HIGH_BIT_MASK_SET(slice) (PLB_SLICE_MASK << ((slice - plb_type_b_slice_8) << 2))
  19. #define PLB_SLICE_HIGH_BIT_SHIFT(slice) ((slice - plb_type_b_slice_8) << 2)
  20. #define PLB_SLICE_LOW_BIT_MASK_SET(slice) (PLB_SLICE_MASK << (slice << 2))
  21. #define PLB_SLICE_LOW_BIT_SHIFT(slice) (slice << 2)
  22. /**
  23. * @brief plb channels
  24. *
  25. */
  26. typedef enum plb_chn {
  27. #ifdef PLB_TYPE_B_0
  28. plb_chn0 = PLB_TYPE_B_0,
  29. #endif
  30. #ifdef PLB_TYPE_B_1
  31. plb_chn1 = PLB_TYPE_B_1,
  32. #endif
  33. #ifdef PLB_TYPE_B_2
  34. plb_chn2 = PLB_TYPE_B_2,
  35. #endif
  36. #ifdef PLB_TYPE_B_3
  37. plb_chn3 = PLB_TYPE_B_3,
  38. #endif
  39. #ifdef PLB_TYPE_B_4
  40. plb_chn4 = PLB_TYPE_B_4,
  41. #endif
  42. #ifdef PLB_TYPE_B_5
  43. plb_chn5 = PLB_TYPE_B_5,
  44. #endif
  45. #ifdef PLB_TYPE_B_6
  46. plb_chn6 = PLB_TYPE_B_6,
  47. #endif
  48. #ifdef PLB_TYPE_B_7
  49. plb_chn7 = PLB_TYPE_B_7,
  50. #endif
  51. } plb_chn_t;
  52. /**
  53. * @brief PLB look-up table unit
  54. *
  55. */
  56. typedef enum plb_type_a_lut_num {
  57. #ifdef PLB_TYPE_A_0
  58. plb_type_a_table0 = PLB_TYPE_A_0,
  59. #endif
  60. #ifdef PLB_TYPE_A_1
  61. plb_type_a_table1 = PLB_TYPE_A_1,
  62. #endif
  63. #ifdef PLB_TYPE_A_2
  64. plb_type_a_table2 = PLB_TYPE_A_2,
  65. #endif
  66. #ifdef PLB_TYPE_A_3
  67. plb_type_a_table3 = PLB_TYPE_A_3,
  68. #endif
  69. #ifdef PLB_TYPE_A_4
  70. plb_type_a_table4 = PLB_TYPE_A_4,
  71. #endif
  72. #ifdef PLB_TYPE_A_5
  73. plb_type_a_table5 = PLB_TYPE_A_5,
  74. #endif
  75. #ifdef PLB_TYPE_A_6
  76. plb_type_a_table6 = PLB_TYPE_A_6,
  77. #endif
  78. #ifdef PLB_TYPE_A_7
  79. plb_type_a_table7 = PLB_TYPE_A_7,
  80. #endif
  81. } plb_type_a_lut_num_t;
  82. /**
  83. * @brief PLB truth table configuration unit
  84. *
  85. */
  86. typedef union {
  87. struct {
  88. uint16_t index0_1bit_out: 1;
  89. uint16_t index1_1bit_out: 1;
  90. uint16_t index2_1bit_out: 1;
  91. uint16_t index3_1bit_out: 1;
  92. uint16_t index4_1bit_out: 1;
  93. uint16_t index5_1bit_out: 1;
  94. uint16_t index6_1bit_out: 1;
  95. uint16_t index7_1bit_out: 1;
  96. uint16_t index8_1bit_out: 1;
  97. uint16_t index9_1bit_out: 1;
  98. uint16_t index10_1bit_out: 1;
  99. uint16_t index11_1bit_out: 1;
  100. uint16_t index12_1bit_out: 1;
  101. uint16_t index13_1bit_out: 1;
  102. uint16_t index14_1bit_out: 1;
  103. uint16_t index15_1bit_out: 1;
  104. };
  105. uint16_t val;
  106. } plb_type_a_truth_t;
  107. /**
  108. * @brief Index of slice
  109. *
  110. */
  111. typedef enum plb_type_b_lut_slice {
  112. plb_type_b_slice_0 = 0,
  113. plb_type_b_slice_1 = 1,
  114. plb_type_b_slice_2 = 2,
  115. plb_type_b_slice_3 = 3,
  116. plb_type_b_slice_4 = 4,
  117. plb_type_b_slice_5 = 5,
  118. plb_type_b_slice_6 = 6,
  119. plb_type_b_slice_7 = 7,
  120. plb_type_b_slice_8 = 8,
  121. plb_type_b_slice_9 = 9,
  122. plb_type_b_slice_10 = 10,
  123. plb_type_b_slice_11 = 11,
  124. plb_type_b_slice_12 = 12,
  125. plb_type_b_slice_13 = 13,
  126. plb_type_b_slice_14 = 14,
  127. plb_type_b_slice_15 = 15,
  128. } plb_type_b_lut_slice_t;
  129. /**
  130. * @brief Configuration of slice
  131. *
  132. */
  133. typedef enum plb_type_b_slice_opt {
  134. plb_slice_opt_keep = 0, /**< The data unit keeps the value of the previous cycle */
  135. plb_slice_opt_get_cmp0_val = 1, /**< The data unit will take the value of the cmp0 register as the value for the next cycle */
  136. plb_slice_opt_get_cmp1_val = 2, /**< The data unit will take the value of the cmp1 register as the value for the next cycle */
  137. plb_slice_opt_get_cmp2_val = 3, /**< The data unit will take the value of the cmp2 register as the value for the next cycle */
  138. plb_slice_opt_add_one = 4, /**< The next cycle value of the data cell is the current value plus 1 */
  139. plb_slice_opt_add_two = 5, /**< The next cycle value of the data cell is the current value plus 2 */
  140. plb_slice_opt_sub_one = 6, /**< The next cycle value of the data cell is the current value minus 1 */
  141. plb_slice_opt_sub_two = 7, /**< The next cycle value of the data cell is the current value minus 2 */
  142. plb_slice_opt_shift_left = 4 << 8, /**< The value of the next cycle of the data cell is shifted one place to the left of the current value */
  143. plb_slice_opt_shift_left_add_one = 5 << 8, /**< The next cycle value of the data cell is the current value shifted one place to the left, with the lower bit complemented by one */
  144. plb_slice_opt_shift_right = 6 << 8, /**< The value of the next cycle of the data cell is shifted one place to the right of the current value */
  145. plb_slice_opt_shift_right_add_one = 7 << 8, /**< The next cycle value of the data cell is the current value shifted one place to the right, with the lower bit complemented by one */
  146. } plb_type_b_slice_opt_t;
  147. /**
  148. * @brief Comparator index
  149. *
  150. */
  151. typedef enum plb_type_b_cmp {
  152. plb_type_b_cmp0 = PLB_TYPE_B_CMP_0,
  153. plb_type_b_cmp1 = PLB_TYPE_B_CMP_1,
  154. plb_type_b_cmp2 = PLB_TYPE_B_CMP_2,
  155. plb_type_b_cmp3 = PLB_TYPE_B_CMP_3,
  156. } plb_type_b_cmp_t;
  157. /**
  158. * @brief Comparator operation
  159. *
  160. */
  161. typedef enum plb_type_b_cmp_mode {
  162. plb_cmp_mode_out_zero = 0, /**< output zero */
  163. plb_cmp_mode_out_one = 1, /**< output one */
  164. plb_cmp_mode_gt = 2, /**< Data unit greater than cmp output one, otherwise output zero */
  165. plb_cmp_mode_lt = 3, /**< Data unit less than cmp output one, otherwise output zero */
  166. plb_cmp_mode_eq = 4, /**< Data unit equal to cmp output one, otherwise output zero */
  167. plb_cmp_mode_ne = 5, /**< Data unit not equal to cmp output one, otherwise output zero */
  168. plb_cmp_mode_ge = 6, /**< Data unit greater than or equal to cmp output one, otherwise output zero */
  169. plb_cmp_mode_le = 7, /**< Data unit less than or equal to cmp output one, otherwise output zero */
  170. plb_cmp_mode_and_mask = 10, /**< The data cell corresponding to the bit set to one by cmp is and */
  171. plb_cmp_mode_or_mask = 11, /**< The data cell corresponding to the bit set to one by cmp is or */
  172. plb_cmp_mode_xor_mask = 12, /**< The data cell corresponding to the bit set to one by cmp is xor */
  173. plb_cmp_mode_nand_mask = 13, /**< The data cell corresponding to the bit set to one by cmp is nand */
  174. plb_cmp_mode_nor_mask = 14, /**< The data cell corresponding to the bit set to one by cmp is nor */
  175. plb_cmp_mode_xnor_mask = 15, /**< The data cell corresponding to the bit set to one by cmp is xnor */
  176. } plb_type_b_cmp_mode_t;
  177. #ifdef __cplusplus
  178. extern "C" {
  179. #endif
  180. /**
  181. * @brief Configuring the truth table for lookup tables
  182. *
  183. * @param plb @ref PLB_Type plb base
  184. * @param chn @ref plb_chn_t
  185. * @param lut_num @ref plb_type_a_lut_num_t
  186. * @param truth @ref plb_type_a_truth_t
  187. */
  188. static inline void plb_type_a_set_lut(PLB_Type *plb, plb_chn_t chn, plb_type_a_lut_num_t lut_num, plb_type_a_truth_t *truth)
  189. {
  190. plb->TYPE_A[chn].LOOKUP_TABLE[lut_num] = PLB_TYPE_A_LOOKUP_TABLE_LOOKUP_TABLE_SET(truth->val);
  191. }
  192. /**
  193. * @brief The software injects a cycle value into the TYPE A channel.
  194. *
  195. * @param plb @ref PLB_Type plb base
  196. * @param chn @ref plb_chn_t
  197. * @param inject_val Injected values
  198. */
  199. static inline void plb_type_a_inject_by_sw(PLB_Type *plb, plb_chn_t chn, uint8_t inject_val)
  200. {
  201. plb->TYPE_A[chn].SW_INJECT = PLB_TYPE_A_SW_INJECT_SW_INJECT_SET(inject_val);
  202. }
  203. /**
  204. * @brief Configure the value of the CMP
  205. *
  206. * @param plb @ref PLB_Type plb base
  207. * @param chn @ref plb_chn_t
  208. * @param cmp_index @ref plb_type_b_cmp_t
  209. * @param val CMP value
  210. */
  211. static inline void plb_type_b_set_cmp_val(PLB_Type *plb, plb_chn_t chn, plb_type_b_cmp_t cmp_index, uint32_t val)
  212. {
  213. plb->TYPE_B[chn].CMP[cmp_index] = PLB_TYPE_B_CMP_CMP_VALUE_SET(val);
  214. }
  215. /**
  216. * @brief Setting the mode of the CMP
  217. *
  218. * @param plb @ref PLB_Type plb base
  219. * @param chn @ref plb_chn_t
  220. * @param cmp_index @ref plb_type_b_cmp_t
  221. * @param cmp_mode @ref plb_type_b_cmp_mode_t
  222. */
  223. static inline void plb_type_b_set_cmp_mode(PLB_Type *plb, plb_chn_t chn, plb_type_b_cmp_t cmp_index, plb_type_b_cmp_mode_t cmp_mode)
  224. {
  225. plb->TYPE_B[chn].MODE = (plb->TYPE_B[chn].MODE & (~(PLB_TYPE_B_MODE_OUT0_SEL_MASK << (cmp_index << 2)))) |
  226. ((PLB_TYPE_B_MODE_OUT0_SEL_MASK & cmp_mode) << (cmp_index << 2));
  227. }
  228. /**
  229. * @brief Software injection values
  230. *
  231. * @param plb @ref PLB_Type plb base
  232. * @param chn @ref plb_chn_t
  233. * @param val value
  234. */
  235. static inline void plb_type_b_inject_by_sw(PLB_Type *plb, plb_chn_t chn, uint32_t val)
  236. {
  237. plb->TYPE_B[chn].SW_INJECT = val;
  238. }
  239. /**
  240. * @brief Configuring the PLB type_b's lookup table
  241. *
  242. * @param plb @ref PLB_Type plb base
  243. * @param chn @ref plb_chn_t
  244. * @param slice @ref plb_type_b_lut_slice_t
  245. * @param opt @ref plb_type_b_slice_opt_t
  246. */
  247. void plb_type_b_set_lut(PLB_Type *plb, plb_chn_t chn, plb_type_b_lut_slice_t slice, plb_type_b_slice_opt_t opt);
  248. #ifdef __cplusplus
  249. }
  250. #endif
  251. /**
  252. * @}
  253. */
  254. #endif /* HPM_PLB_DRV_H */