fsl_asrc_edma.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. * Copyright 2019-2020 NXP
  3. * All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #ifndef _FSL_ASRC_P2P_EDMA_H_
  8. #define _FSL_ASRC_P2P_EDMA_H_
  9. #include "fsl_edma.h"
  10. #include "fsl_asrc.h"
  11. /*!
  12. * @addtogroup asrc_edma_driver
  13. * @{
  14. */
  15. /*******************************************************************************
  16. * Definitions
  17. ******************************************************************************/
  18. /*! @name Driver version */
  19. /*@{*/
  20. #define FSL_ASRC_EDMA_DRIVER_VERSION (MAKE_VERSION(2, 1, 0)) /*!< Version 2.1.0 */
  21. /*@}*/
  22. /*!< @brief ASRC IN edma QUEUE size */
  23. #define ASRC_XFER_IN_QUEUE_SIZE 4U
  24. #define ASRC_XFER_OUT_QUEUE_SIZE (ASRC_XFER_QUEUE_SIZE * 2U)
  25. typedef struct _asrc_edma_handle asrc_edma_handle_t;
  26. /*! @brief ASRC eDMA transfer callback function for finish and error */
  27. typedef void (*asrc_edma_callback_t)(ASRC_Type *base, asrc_edma_handle_t *handle, status_t status, void *userData);
  28. /*! @brief ASRC trigger peripheral function pointer */
  29. typedef void (*asrc_start_peripheral_t)(bool start);
  30. /*! @brief destination peripheral configuration */
  31. typedef struct _asrc_p2p_edma_config
  32. {
  33. uint8_t watermark; /*!< peripheral watermark */
  34. uint8_t channel; /*!< peripheral channel number */
  35. asrc_start_peripheral_t startPeripheral; /*!< trigger peripheral start */
  36. } asrc_p2p_edma_config_t;
  37. /*!@ brief asrc in edma handler */
  38. typedef struct _asrc_in_edma_handle
  39. {
  40. edma_handle_t *inDmaHandle; /*!< DMA handler for ASRC in */
  41. uint8_t tcd[(ASRC_XFER_IN_QUEUE_SIZE + 1U) * sizeof(edma_tcd_t)]; /*!< TCD pool for eDMA send. */
  42. uint32_t sampleWidth; /*!< input data width */
  43. uint32_t fifoThreshold; /*!< ASRC input fifo threshold */
  44. uint32_t *asrcQueue[ASRC_XFER_IN_QUEUE_SIZE]; /*!< Transfer queue storing queued transfer. */
  45. size_t transferSize[ASRC_XFER_IN_QUEUE_SIZE]; /*!< Data bytes need to transfer */
  46. volatile uint8_t queueUser; /*!< Index for user to queue transfer. */
  47. volatile uint8_t queueDriver; /*!< Index for driver to get the transfer data and size */
  48. uint32_t state; /*!< Internal state for ASRC eDMA transfer */
  49. const asrc_p2p_edma_config_t *peripheralConfig; /*!< peripheral configuration pointer */
  50. } asrc_in_edma_handle_t;
  51. /*!@ brief asrc out edma handler */
  52. typedef struct _asrc_out_edma_handle
  53. {
  54. edma_handle_t *outDmaHandle; /*!< DMA handler for ASRC out */
  55. uint8_t tcd[(ASRC_XFER_OUT_QUEUE_SIZE + 1U) * sizeof(edma_tcd_t)]; /*!< TCD pool for eDMA send. */
  56. uint32_t sampleWidth; /*!< output data width */
  57. uint32_t fifoThreshold; /*!< ASRC output fifo threshold */
  58. uint32_t *asrcQueue[ASRC_XFER_OUT_QUEUE_SIZE]; /*!< Transfer queue storing queued transfer. */
  59. size_t transferSize[ASRC_XFER_OUT_QUEUE_SIZE]; /*!< Data bytes need to transfer */
  60. volatile uint8_t queueUser; /*!< Index for user to queue transfer. */
  61. volatile uint8_t queueDriver; /*!< Index for driver to get the transfer data and size */
  62. uint32_t state; /*!< Internal state for ASRC eDMA transfer */
  63. const asrc_p2p_edma_config_t *peripheralConfig; /*!< peripheral configuration pointer */
  64. } asrc_out_edma_handle_t;
  65. /*! @brief ASRC DMA transfer handle.*/
  66. struct _asrc_edma_handle
  67. {
  68. asrc_in_edma_handle_t in; /*!< asrc in handler */
  69. asrc_out_edma_handle_t out; /*!< asrc out handler */
  70. asrc_channel_pair_t channelPair; /*!< channel pair */
  71. void *userData; /*!< User callback parameter */
  72. asrc_edma_callback_t callback; /*!< Callback for users while transfer finish or error occurs */
  73. };
  74. /*******************************************************************************
  75. * APIs
  76. ******************************************************************************/
  77. #if defined(__cplusplus)
  78. extern "C" {
  79. #endif
  80. /*!
  81. * @name eDMA Transactional
  82. * @{
  83. */
  84. /*!
  85. * @brief Initializes the ASRC IN eDMA handle.
  86. *
  87. * This function initializes the ASRC DMA handle, which can be used for other ASRC transactional APIs.
  88. * Usually, for a specified ASRC channel pair, call this API once to get the initialized handle.
  89. *
  90. * @param base ASRC base pointer.
  91. * @param channelPair ASRC channel pair
  92. * @param handle ASRC eDMA handle pointer.
  93. * @param callback Pointer to user callback function.
  94. * @param inDmaHandle DMA handler for ASRC in.
  95. * @param periphConfig peripheral configuration.
  96. * @param userData User parameter passed to the callback function.
  97. */
  98. void ASRC_TransferInCreateHandleEDMA(ASRC_Type *base,
  99. asrc_edma_handle_t *handle,
  100. asrc_channel_pair_t channelPair,
  101. asrc_edma_callback_t callback,
  102. edma_handle_t *inDmaHandle,
  103. const asrc_p2p_edma_config_t *periphConfig,
  104. void *userData);
  105. /*!
  106. * @brief Initializes the ASRC OUT eDMA handle.
  107. *
  108. * This function initializes the ASRC DMA handle, which can be used for other ASRC transactional APIs.
  109. * Usually, for a specified ASRC channel pair, call this API once to get the initialized handle.
  110. *
  111. * @param base ASRC base pointer.
  112. * @param channelPair ASRC channel pair
  113. * @param handle ASRC eDMA handle pointer.
  114. * @param callback Pointer to user callback function.
  115. * @param outDmaHandle DMA handler for ASRC out.
  116. * @param periphConfig peripheral configuration.
  117. * @param userData User parameter passed to the callback function.
  118. */
  119. void ASRC_TransferOutCreateHandleEDMA(ASRC_Type *base,
  120. asrc_edma_handle_t *handle,
  121. asrc_channel_pair_t channelPair,
  122. asrc_edma_callback_t callback,
  123. edma_handle_t *outDmaHandle,
  124. const asrc_p2p_edma_config_t *periphConfig,
  125. void *userData);
  126. /*!
  127. * @brief Configures the ASRC P2P channel pair.
  128. *
  129. *
  130. * @param base ASRC base pointer.
  131. * @param handle ASRC eDMA handle pointer.
  132. * @param asrcConfig asrc configurations.
  133. * @param inSampleRate ASRC input sample rate.
  134. * @param outSampleRate ASRC output sample rate.
  135. */
  136. status_t ASRC_TransferSetChannelPairConfigEDMA(ASRC_Type *base,
  137. asrc_edma_handle_t *handle,
  138. asrc_channel_pair_config_t *asrcConfig,
  139. uint32_t inSampleRate,
  140. uint32_t outSampleRate);
  141. /*!
  142. * @brief Get output sample buffer size can be transferred by edma.
  143. *
  144. * @note This API is depends on the ASRC output configuration, should be called after the
  145. * ASRC_TransferSetChannelPairConfigEDMA.
  146. *
  147. * @param base asrc base pointer.
  148. * @param handle ASRC channel pair edma handle.
  149. * @param inSampleRate input sample rate.
  150. * @param outSampleRate output sample rate.
  151. * @param inSamplesize input sampleS size.
  152. * @retval output buffer size in byte.
  153. */
  154. uint32_t ASRC_GetOutSamplesSizeEDMA(
  155. ASRC_Type *base, asrc_edma_handle_t *handle, uint32_t inSampleRate, uint32_t outSampleRate, uint32_t inSamplesize);
  156. /*!
  157. * @brief Performs a non-blocking ASRC m2m convert using EDMA.
  158. *
  159. * @note This interface returns immediately after the transfer initiates.
  160. * @param base ASRC base pointer.
  161. * @param handle ASRC eDMA handle pointer.
  162. * @param xfer Pointer to the DMA transfer structure.
  163. * @retval kStatus_Success Start a ASRC eDMA send successfully.
  164. * @retval kStatus_InvalidArgument The input argument is invalid.
  165. * @retval kStatus_ASRCQueueFull ASRC EDMA driver queue is full.
  166. */
  167. status_t ASRC_TransferEDMA(ASRC_Type *base, asrc_edma_handle_t *handle, asrc_transfer_t *xfer);
  168. /*!
  169. * @brief Aborts a ASRC IN transfer using eDMA.
  170. *
  171. * This function only aborts the current transfer slots, the other transfer slots' information still kept
  172. * in the handler. If users want to terminate all transfer slots, just call ASRC_TransferTerminalP2PEDMA.
  173. *
  174. * @param base ASRC base pointer.
  175. * @param handle ASRC eDMA handle pointer.
  176. */
  177. void ASRC_TransferInAbortEDMA(ASRC_Type *base, asrc_edma_handle_t *handle);
  178. /*!
  179. * @brief Aborts a ASRC OUT transfer using eDMA.
  180. *
  181. * This function only aborts the current transfer slots, the other transfer slots' information still kept
  182. * in the handler. If users want to terminate all transfer slots, just call ASRC_TransferTerminalP2PEDMA.
  183. *
  184. * @param base ASRC base pointer.
  185. * @param handle ASRC eDMA handle pointer.
  186. */
  187. void ASRC_TransferOutAbortEDMA(ASRC_Type *base, asrc_edma_handle_t *handle);
  188. /*!
  189. * @brief Terminate In ASRC Convert.
  190. *
  191. * This function will clear all transfer slots buffered in the asrc queue. If users only want to abort the
  192. * current transfer slot, please call ASRC_TransferAbortPP2PEDMA.
  193. *
  194. * @param base ASRC base pointer.
  195. * @param handle ASRC eDMA handle pointer.
  196. */
  197. void ASRC_TransferInTerminalEDMA(ASRC_Type *base, asrc_edma_handle_t *handle);
  198. /*!
  199. * @brief Terminate Out ASRC Convert.
  200. *
  201. * This function will clear all transfer slots buffered in the asrc queue. If users only want to abort the
  202. * current transfer slot, please call ASRC_TransferAbortPP2PEDMA.
  203. *
  204. * @param base ASRC base pointer.
  205. * @param handle ASRC eDMA handle pointer.
  206. */
  207. void ASRC_TransferOutTerminalEDMA(ASRC_Type *base, asrc_edma_handle_t *handle);
  208. /*! @} */
  209. #if defined(__cplusplus)
  210. }
  211. #endif
  212. /*!
  213. * @}
  214. */
  215. #endif