fsl_flexio_i2s_edma.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2019 NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef _FSL_FLEXIO_I2S_EDMA_H_
  9. #define _FSL_FLEXIO_I2S_EDMA_H_
  10. #include "fsl_flexio_i2s.h"
  11. #include "fsl_edma.h"
  12. /*!
  13. * @addtogroup flexio_edma_i2s
  14. * @{
  15. */
  16. /*******************************************************************************
  17. * Definitions
  18. ******************************************************************************/
  19. /*! @name Driver version */
  20. /*@{*/
  21. /*! @brief FlexIO I2S EDMA driver version 2.1.7. */
  22. #define FSL_FLEXIO_I2S_EDMA_DRIVER_VERSION (MAKE_VERSION(2, 1, 7))
  23. /*@}*/
  24. typedef struct _flexio_i2s_edma_handle flexio_i2s_edma_handle_t;
  25. /*! @brief FlexIO I2S eDMA transfer callback function for finish and error */
  26. typedef void (*flexio_i2s_edma_callback_t)(FLEXIO_I2S_Type *base,
  27. flexio_i2s_edma_handle_t *handle,
  28. status_t status,
  29. void *userData);
  30. /*! @brief FlexIO I2S DMA transfer handle, users should not touch the content of the handle.*/
  31. struct _flexio_i2s_edma_handle
  32. {
  33. edma_handle_t *dmaHandle; /*!< DMA handler for FlexIO I2S send */
  34. uint8_t bytesPerFrame; /*!< Bytes in a frame */
  35. uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */
  36. uint32_t state; /*!< Internal state for FlexIO I2S eDMA transfer */
  37. flexio_i2s_edma_callback_t callback; /*!< Callback for users while transfer finish or error occurred */
  38. void *userData; /*!< User callback parameter */
  39. edma_tcd_t tcd[FLEXIO_I2S_XFER_QUEUE_SIZE + 1U]; /*!< TCD pool for eDMA transfer. */
  40. flexio_i2s_transfer_t queue[FLEXIO_I2S_XFER_QUEUE_SIZE]; /*!< Transfer queue storing queued transfer. */
  41. size_t transferSize[FLEXIO_I2S_XFER_QUEUE_SIZE]; /*!< Data bytes need to transfer */
  42. volatile uint8_t queueUser; /*!< Index for user to queue transfer. */
  43. volatile uint8_t queueDriver; /*!< Index for driver to get the transfer data and size */
  44. };
  45. /*******************************************************************************
  46. * APIs
  47. ******************************************************************************/
  48. #if defined(__cplusplus)
  49. extern "C" {
  50. #endif
  51. /*!
  52. * @name eDMA Transactional
  53. * @{
  54. */
  55. /*!
  56. * @brief Initializes the FlexIO I2S eDMA handle.
  57. *
  58. * This function initializes the FlexIO I2S master DMA handle which can be used for other FlexIO I2S master
  59. * transactional APIs.
  60. * Usually, for a specified FlexIO I2S instance, call this API once to get the initialized handle.
  61. *
  62. * @param base FlexIO I2S peripheral base address.
  63. * @param handle FlexIO I2S eDMA handle pointer.
  64. * @param callback FlexIO I2S eDMA callback function called while finished a block.
  65. * @param userData User parameter for callback.
  66. * @param dmaHandle eDMA handle for FlexIO I2S. This handle is a static value allocated by users.
  67. */
  68. void FLEXIO_I2S_TransferTxCreateHandleEDMA(FLEXIO_I2S_Type *base,
  69. flexio_i2s_edma_handle_t *handle,
  70. flexio_i2s_edma_callback_t callback,
  71. void *userData,
  72. edma_handle_t *dmaHandle);
  73. /*!
  74. * @brief Initializes the FlexIO I2S Rx eDMA handle.
  75. *
  76. * This function initializes the FlexIO I2S slave DMA handle which can be used for other FlexIO I2S master transactional
  77. * APIs.
  78. * Usually, for a specified FlexIO I2S instance, call this API once to get the initialized handle.
  79. *
  80. * @param base FlexIO I2S peripheral base address.
  81. * @param handle FlexIO I2S eDMA handle pointer.
  82. * @param callback FlexIO I2S eDMA callback function called while finished a block.
  83. * @param userData User parameter for callback.
  84. * @param dmaHandle eDMA handle for FlexIO I2S. This handle is a static value allocated by users.
  85. */
  86. void FLEXIO_I2S_TransferRxCreateHandleEDMA(FLEXIO_I2S_Type *base,
  87. flexio_i2s_edma_handle_t *handle,
  88. flexio_i2s_edma_callback_t callback,
  89. void *userData,
  90. edma_handle_t *dmaHandle);
  91. /*!
  92. * @brief Configures the FlexIO I2S Tx audio format.
  93. *
  94. * Audio format can be changed in run-time of FlexIO I2S. This function configures the sample rate and audio data
  95. * format to be transferred. This function also sets the eDMA parameter according to format.
  96. *
  97. * @param base FlexIO I2S peripheral base address.
  98. * @param handle FlexIO I2S eDMA handle pointer
  99. * @param format Pointer to FlexIO I2S audio data format structure.
  100. * @param srcClock_Hz FlexIO I2S clock source frequency in Hz, it should be 0 while in slave mode.
  101. */
  102. void FLEXIO_I2S_TransferSetFormatEDMA(FLEXIO_I2S_Type *base,
  103. flexio_i2s_edma_handle_t *handle,
  104. flexio_i2s_format_t *format,
  105. uint32_t srcClock_Hz);
  106. /*!
  107. * @brief Performs a non-blocking FlexIO I2S transfer using DMA.
  108. *
  109. * @note This interface returned immediately after transfer initiates. Users should call
  110. * FLEXIO_I2S_GetTransferStatus to poll the transfer status and check whether the FlexIO I2S transfer is finished.
  111. *
  112. * @param base FlexIO I2S peripheral base address.
  113. * @param handle FlexIO I2S DMA handle pointer.
  114. * @param xfer Pointer to DMA transfer structure.
  115. * @retval kStatus_Success Start a FlexIO I2S eDMA send successfully.
  116. * @retval kStatus_InvalidArgument The input arguments is invalid.
  117. * @retval kStatus_TxBusy FlexIO I2S is busy sending data.
  118. */
  119. status_t FLEXIO_I2S_TransferSendEDMA(FLEXIO_I2S_Type *base,
  120. flexio_i2s_edma_handle_t *handle,
  121. flexio_i2s_transfer_t *xfer);
  122. /*!
  123. * @brief Performs a non-blocking FlexIO I2S receive using eDMA.
  124. *
  125. * @note This interface returned immediately after transfer initiates. Users should call
  126. * FLEXIO_I2S_GetReceiveRemainingBytes to poll the transfer status and check whether the FlexIO I2S transfer is
  127. * finished.
  128. *
  129. * @param base FlexIO I2S peripheral base address.
  130. * @param handle FlexIO I2S DMA handle pointer.
  131. * @param xfer Pointer to DMA transfer structure.
  132. * @retval kStatus_Success Start a FlexIO I2S eDMA receive successfully.
  133. * @retval kStatus_InvalidArgument The input arguments is invalid.
  134. * @retval kStatus_RxBusy FlexIO I2S is busy receiving data.
  135. */
  136. status_t FLEXIO_I2S_TransferReceiveEDMA(FLEXIO_I2S_Type *base,
  137. flexio_i2s_edma_handle_t *handle,
  138. flexio_i2s_transfer_t *xfer);
  139. /*!
  140. * @brief Aborts a FlexIO I2S transfer using eDMA.
  141. *
  142. * @param base FlexIO I2S peripheral base address.
  143. * @param handle FlexIO I2S DMA handle pointer.
  144. */
  145. void FLEXIO_I2S_TransferAbortSendEDMA(FLEXIO_I2S_Type *base, flexio_i2s_edma_handle_t *handle);
  146. /*!
  147. * @brief Aborts a FlexIO I2S receive using eDMA.
  148. *
  149. * @param base FlexIO I2S peripheral base address.
  150. * @param handle FlexIO I2S DMA handle pointer.
  151. */
  152. void FLEXIO_I2S_TransferAbortReceiveEDMA(FLEXIO_I2S_Type *base, flexio_i2s_edma_handle_t *handle);
  153. /*!
  154. * @brief Gets the remaining bytes to be sent.
  155. *
  156. * @param base FlexIO I2S peripheral base address.
  157. * @param handle FlexIO I2S DMA handle pointer.
  158. * @param count Bytes sent.
  159. * @retval kStatus_Success Succeed get the transfer count.
  160. * @retval kStatus_NoTransferInProgress There is not a non-blocking transaction currently in progress.
  161. */
  162. status_t FLEXIO_I2S_TransferGetSendCountEDMA(FLEXIO_I2S_Type *base, flexio_i2s_edma_handle_t *handle, size_t *count);
  163. /*!
  164. * @brief Get the remaining bytes to be received.
  165. *
  166. * @param base FlexIO I2S peripheral base address.
  167. * @param handle FlexIO I2S DMA handle pointer.
  168. * @param count Bytes received.
  169. * @retval kStatus_Success Succeed get the transfer count.
  170. * @retval kStatus_NoTransferInProgress There is not a non-blocking transaction currently in progress.
  171. */
  172. status_t FLEXIO_I2S_TransferGetReceiveCountEDMA(FLEXIO_I2S_Type *base, flexio_i2s_edma_handle_t *handle, size_t *count);
  173. /*! @} */
  174. #if defined(__cplusplus)
  175. }
  176. #endif
  177. /*!
  178. * @}
  179. */
  180. #endif