hpm_ffa_drv.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. * Copyright (c) 2022 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_FFA_DRV_H
  8. #define HPM_FFA_DRV_H
  9. #include "hpm_common.h"
  10. #include "hpm_ffa_regs.h"
  11. #include "hpm_soc_ip_feature.h"
  12. /**
  13. * @brief FFA driver APIs
  14. * @defgroup ffa_interface FFA driver APIs
  15. * @ingroup ffa_interfaces
  16. * @{
  17. *
  18. */
  19. /***********************************************************************************************************************
  20. *
  21. * Definitions
  22. *
  23. **********************************************************************************************************************/
  24. /**
  25. * @brief Operation commands supported by FFA
  26. */
  27. #define FFA_OPCMD_FIR (0U) /* !< FIR operation command index */
  28. #define FFA_OPCMD_FFT (2U) /* !< FFT operation command index */
  29. /**
  30. * @brief Data type supported by FFA
  31. */
  32. #define FFA_DATA_TYPE_REAL_Q31 (0U) /* !< FFA Data type: Real Q31 */
  33. #define FFA_DATA_TYPE_REAL_Q15 (1U) /* !< FFA Data type: Real Q15 */
  34. #define FFA_DATA_TYPE_COMPLEX_Q31 (2U) /* !< FFA Data type: Complex Q31 */
  35. #define FFA_DATA_TYPE_COMPLEX_Q15 (3U) /* !< FFA Data type: Complex Q15 */
  36. #if defined(HPM_IP_FEATURE_FFA_FP32) && HPM_IP_FEATURE_FFA_FP32
  37. #define FFA_DATA_TYPE_COMPLEX_FP32 (4U) /* !< FFA Data type: Complex Q15 */
  38. #define FFA_DATA_TYPE_REAL_FP32 (5U) /* !< FFA Data type: Complex Q15 */
  39. #endif
  40. /**
  41. * @brief FFA Q31 data type definition
  42. */
  43. typedef int32_t ffa_q31_t;
  44. /**
  45. * @brief FFA Q15 data type definition
  46. */
  47. typedef int16_t ffa_q15_t;
  48. /**
  49. * @brief FFA complex Q31 data type definition
  50. */
  51. typedef struct {
  52. ffa_q31_t real;
  53. ffa_q31_t image;
  54. } ffa_complex_q31_t;
  55. /**
  56. * @brief FFA complex Q15 data type definition
  57. */
  58. typedef struct {
  59. ffa_q15_t real;
  60. ffa_q15_t image;
  61. } ffa_complex_q15_t;
  62. /**
  63. * @brief FFT transform context
  64. */
  65. typedef struct {
  66. uint16_t is_ifft; /* !< Is Inverse FFT transform */
  67. uint8_t src_data_type; /* !< Source data type */
  68. uint8_t dst_data_type; /* !< Destination date type */
  69. uint32_t num_points; /* !< Number of points */
  70. const void *src; /* !< Source data buffer */
  71. void *dst; /* !< Destination Data buffer */
  72. uint32_t interrupt_mask; /* !< Interrupt mask */
  73. } fft_xfer_t;
  74. /**
  75. * @brief FIR transform context
  76. */
  77. typedef struct {
  78. uint16_t data_type; /* !< Data type */
  79. uint16_t coef_taps; /* !< Coefficient taps */
  80. uint32_t input_taps; /* !< Input data taps */
  81. const void *src; /* !< Source data buffer */
  82. const void *coeff; /* !< Coefficient data buffer */
  83. void *dst; /* !< Destination data buffer */
  84. uint32_t interrupt_mask; /* !< Interrupt mask */
  85. } fir_xfer_t;
  86. /**
  87. * @brief FFA error codes
  88. */
  89. enum {
  90. status_ffa_fir_overflow = MAKE_STATUS(status_group_ffa, 0), /* !< FIR overflow */
  91. status_ffa_fft_overflow = MAKE_STATUS(status_group_ffa, 1), /* !< FFR overflow */
  92. status_ffa_write_error = MAKE_STATUS(status_group_ffa, 2), /* !< FFA write error */
  93. status_ffa_read_next_error = MAKE_STATUS(status_group_ffa, 3), /* !< FFA read next data error */
  94. status_ffa_read_error = MAKE_STATUS(status_group_ffa, 4), /*!< FFA read error */
  95. };
  96. #if defined(HPM_IP_FEATURE_FFA_FP32) && HPM_IP_FEATURE_FFA_FP32
  97. typedef enum {
  98. input_data = 0,
  99. output_data = 1,
  100. coeff_data = 2
  101. } ffa_fp32_status_source_t;
  102. #endif
  103. #ifdef __cplusplus
  104. extern "C" {
  105. #endif
  106. /**
  107. * @brief Enable FFA module and start an specified FFA operation
  108. *
  109. * @param [in] ptr FFA base address
  110. */
  111. static inline void ffa_enable(FFA_Type *ptr)
  112. {
  113. ptr->CTRL = (ptr->CTRL & ~FFA_CTRL_SFTRST_MASK) | FFA_CTRL_EN_MASK;
  114. }
  115. /**
  116. * @brief Stop FFA module
  117. *
  118. * @param [in] ptr FFA base address
  119. */
  120. static inline void ffa_disable(FFA_Type *ptr)
  121. {
  122. ptr->CTRL = (ptr->CTRL & ~FFA_CTRL_EN_MASK) | FFA_CTRL_SFTRST_MASK;
  123. }
  124. /**
  125. * @brief Get FFA status
  126. *
  127. * @param [in] ptr FFA base address
  128. * @return FFA status register value
  129. */
  130. static inline uint32_t ffa_get_status(FFA_Type *ptr)
  131. {
  132. return ptr->STATUS;
  133. }
  134. /**
  135. * @brief Enable FFA Interrupt
  136. *
  137. * @param [in] ptr FFA base address
  138. * @param [in] mask FFA interrupt mask
  139. */
  140. static inline void ffa_enable_interrupt(FFA_Type *ptr, uint32_t mask)
  141. {
  142. ptr->INT_EN |= mask;
  143. }
  144. /**
  145. * @brief Disable FFA interrupt
  146. *
  147. * @param [in] ptr FFA base address
  148. * @param [in] mask FFA interrupt mask
  149. */
  150. static inline void ffa_disable_interrupt(FFA_Type *ptr, uint32_t mask)
  151. {
  152. ptr->INT_EN &= ~mask;
  153. }
  154. #if defined(HPM_IP_FEATURE_FFA_FP32) && HPM_IP_FEATURE_FFA_FP32
  155. static inline void ffa_enable_fp32_interrupt(FFA_Type *ptr, uint32_t mask)
  156. {
  157. ptr->FP_CTRL |= mask;
  158. }
  159. static inline void ffa_disable_fp32_interrupt(FFA_Type *ptr, uint32_t mask)
  160. {
  161. ptr->FP_CTRL &= ~mask;
  162. }
  163. static inline void ffa_set_fp_status_source(FFA_Type *ptr, ffa_fp32_status_source_t source)
  164. {
  165. ptr->FP_CTRL = FFA_FP_CTRL_EXP_ST_SEL_SET(source);
  166. }
  167. static inline void ffa_enable_fp_bias(FFA_Type *ptr)
  168. {
  169. ptr->FP_CTRL |= FFA_FP_CTRL_OPT_BIAS_EXP_MASK;
  170. }
  171. static inline void ffa_disable_fp_bias(FFA_Type *ptr)
  172. {
  173. ptr->FP_CTRL &= ~FFA_FP_CTRL_OPT_BIAS_EXP_MASK;
  174. }
  175. static inline void ffa_set_coef_max_index(FFA_Type *ptr, uint8_t max)
  176. {
  177. ptr->FP_CTRL = (ptr->FP_CTRL & ~FFA_FP_CTRL_COEF_MAX_MASK) | FFA_FP_CTRL_COEF_MAX_SET(max);
  178. }
  179. static inline void ffa_set_output_max_index(FFA_Type *ptr, uint8_t max)
  180. {
  181. ptr->FP_CTRL = (ptr->FP_CTRL & ~FFA_FP_CTRL_OUT_MAX_MASK) | FFA_FP_CTRL_OUT_MAX_SET(max);
  182. }
  183. static inline void ffa_set_input_max_index(FFA_Type *ptr, uint8_t max)
  184. {
  185. ptr->FP_CTRL = (ptr->FP_CTRL & ~FFA_FP_CTRL_IN_MAX_MASK) | FFA_FP_CTRL_IN_MAX_SET(max);
  186. }
  187. static inline uint32_t ffa_get_fp_status(FFA_Type *ptr)
  188. {
  189. return ptr->FP_ST;
  190. }
  191. #endif
  192. /**
  193. * @brief Start an FFT operation
  194. *
  195. * @param [in] ptr FFA base address
  196. * @param [in] fft_xfer FFT transform context
  197. */
  198. void ffa_start_fft(FFA_Type *ptr, fft_xfer_t *fft_xfer);
  199. /**
  200. * @brief Start an FIR operation
  201. *
  202. * @param [in] ptr FFA base address
  203. * @param [in] fir_xfer FIR transform context
  204. */
  205. void ffa_start_fir(FFA_Type *ptr, fir_xfer_t *fir_xfer);
  206. /**
  207. * @brief Perform FFT transformation in blocking mode
  208. *
  209. * @param [in] ptr FFA base address
  210. * @param [in, out] fft_xfer FFT transform context
  211. * @return FFT operation result
  212. */
  213. hpm_stat_t ffa_calculate_fft_blocking(FFA_Type *ptr, fft_xfer_t *fft_xfer);
  214. /**
  215. * @brief Perform FIR transform in blocking mode
  216. *
  217. * @param [in] ptr FFA base address
  218. * @param [in, out] fir_xfer FIR transform context
  219. * @return FIR operation result
  220. */
  221. hpm_stat_t ffa_calculate_fir_blocking(FFA_Type *ptr, fir_xfer_t *fir_xfer);
  222. #ifdef __cplusplus
  223. }
  224. #endif
  225. /**
  226. * @}
  227. *
  228. */
  229. #endif /* HPM_FFA_DRV_H */