fsl_flexio_i2s_edma.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2017 NXP
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * o Redistributions of source code must retain the above copyright notice, this list
  9. * of conditions and the following disclaimer.
  10. *
  11. * o Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * o Neither the name of the copyright holder nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef _FSL_FLEXIO_I2S_EDMA_H_
  31. #define _FSL_FLEXIO_I2S_EDMA_H_
  32. #include "fsl_flexio_i2s.h"
  33. #include "fsl_edma.h"
  34. /*!
  35. * @addtogroup flexio_edma_i2s
  36. * @{
  37. */
  38. /*******************************************************************************
  39. * Definitions
  40. ******************************************************************************/
  41. typedef struct _flexio_i2s_edma_handle flexio_i2s_edma_handle_t;
  42. /*! @brief FlexIO I2S eDMA transfer callback function for finish and error */
  43. typedef void (*flexio_i2s_edma_callback_t)(FLEXIO_I2S_Type *base,
  44. flexio_i2s_edma_handle_t *handle,
  45. status_t status,
  46. void *userData);
  47. /*! @brief FlexIO I2S DMA transfer handle, users should not touch the content of the handle.*/
  48. struct _flexio_i2s_edma_handle
  49. {
  50. edma_handle_t *dmaHandle; /*!< DMA handler for FlexIO I2S send */
  51. uint8_t bytesPerFrame; /*!< Bytes in a frame */
  52. uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */
  53. uint32_t state; /*!< Internal state for FlexIO I2S eDMA transfer */
  54. flexio_i2s_edma_callback_t callback; /*!< Callback for users while transfer finish or error occurred */
  55. void *userData; /*!< User callback parameter */
  56. edma_tcd_t tcd[FLEXIO_I2S_XFER_QUEUE_SIZE + 1U]; /*!< TCD pool for eDMA transfer. */
  57. flexio_i2s_transfer_t queue[FLEXIO_I2S_XFER_QUEUE_SIZE]; /*!< Transfer queue storing queued transfer. */
  58. size_t transferSize[FLEXIO_I2S_XFER_QUEUE_SIZE]; /*!< Data bytes need to transfer */
  59. volatile uint8_t queueUser; /*!< Index for user to queue transfer. */
  60. volatile uint8_t queueDriver; /*!< Index for driver to get the transfer data and size */
  61. };
  62. /*******************************************************************************
  63. * APIs
  64. ******************************************************************************/
  65. #if defined(__cplusplus)
  66. extern "C" {
  67. #endif
  68. /*!
  69. * @name eDMA Transactional
  70. * @{
  71. */
  72. /*!
  73. * @brief Initializes the FlexIO I2S eDMA handle.
  74. *
  75. * This function initializes the FlexIO I2S master DMA handle which can be used for other FlexIO I2S master
  76. * transactional APIs.
  77. * Usually, for a specified FlexIO I2S instance, call this API once to get the initialized handle.
  78. *
  79. * @param base FlexIO I2S peripheral base address.
  80. * @param handle FlexIO I2S eDMA handle pointer.
  81. * @param callback FlexIO I2S eDMA callback function called while finished a block.
  82. * @param userData User parameter for callback.
  83. * @param dmaHandle eDMA handle for FlexIO I2S. This handle is a static value allocated by users.
  84. */
  85. void FLEXIO_I2S_TransferTxCreateHandleEDMA(FLEXIO_I2S_Type *base,
  86. flexio_i2s_edma_handle_t *handle,
  87. flexio_i2s_edma_callback_t callback,
  88. void *userData,
  89. edma_handle_t *dmaHandle);
  90. /*!
  91. * @brief Initializes the FlexIO I2S Rx eDMA handle.
  92. *
  93. * This function initializes the FlexIO I2S slave DMA handle which can be used for other FlexIO I2S master transactional
  94. * APIs.
  95. * Usually, for a specified FlexIO I2S instance, call this API once to get the initialized handle.
  96. *
  97. * @param base FlexIO I2S peripheral base address.
  98. * @param handle FlexIO I2S eDMA handle pointer.
  99. * @param callback FlexIO I2S eDMA callback function called while finished a block.
  100. * @param userData User parameter for callback.
  101. * @param dmaHandle eDMA handle for FlexIO I2S. This handle is a static value allocated by users.
  102. */
  103. void FLEXIO_I2S_TransferRxCreateHandleEDMA(FLEXIO_I2S_Type *base,
  104. flexio_i2s_edma_handle_t *handle,
  105. flexio_i2s_edma_callback_t callback,
  106. void *userData,
  107. edma_handle_t *dmaHandle);
  108. /*!
  109. * @brief Configures the FlexIO I2S Tx audio format.
  110. *
  111. * Audio format can be changed in run-time of FlexIO I2S. This function configures the sample rate and audio data
  112. * format to be transferred. This function also sets the eDMA parameter according to format.
  113. *
  114. * @param base FlexIO I2S peripheral base address.
  115. * @param handle FlexIO I2S eDMA handle pointer
  116. * @param format Pointer to FlexIO I2S audio data format structure.
  117. * @param srcClock_Hz FlexIO I2S clock source frequency in Hz, it should be 0 while in slave mode.
  118. * @retval kStatus_Success Audio format set successfully.
  119. * @retval kStatus_InvalidArgument The input arguments is invalid.
  120. */
  121. void FLEXIO_I2S_TransferSetFormatEDMA(FLEXIO_I2S_Type *base,
  122. flexio_i2s_edma_handle_t *handle,
  123. flexio_i2s_format_t *format,
  124. uint32_t srcClock_Hz);
  125. /*!
  126. * @brief Performs a non-blocking FlexIO I2S transfer using DMA.
  127. *
  128. * @note This interface returned immediately after transfer initiates. Users should call
  129. * FLEXIO_I2S_GetTransferStatus to poll the transfer status and check whether the FlexIO I2S transfer is finished.
  130. *
  131. * @param base FlexIO I2S peripheral base address.
  132. * @param handle FlexIO I2S DMA handle pointer.
  133. * @param xfer Pointer to DMA transfer structure.
  134. * @retval kStatus_Success Start a FlexIO I2S eDMA send successfully.
  135. * @retval kStatus_InvalidArgument The input arguments is invalid.
  136. * @retval kStatus_TxBusy FlexIO I2S is busy sending data.
  137. */
  138. status_t FLEXIO_I2S_TransferSendEDMA(FLEXIO_I2S_Type *base,
  139. flexio_i2s_edma_handle_t *handle,
  140. flexio_i2s_transfer_t *xfer);
  141. /*!
  142. * @brief Performs a non-blocking FlexIO I2S receive using eDMA.
  143. *
  144. * @note This interface returned immediately after transfer initiates. Users should call
  145. * FLEXIO_I2S_GetReceiveRemainingBytes to poll the transfer status and check whether the FlexIO I2S transfer is finished.
  146. *
  147. * @param base FlexIO I2S peripheral base address.
  148. * @param handle FlexIO I2S DMA handle pointer.
  149. * @param xfer Pointer to DMA transfer structure.
  150. * @retval kStatus_Success Start a FlexIO I2S eDMA receive successfully.
  151. * @retval kStatus_InvalidArgument The input arguments is invalid.
  152. * @retval kStatus_RxBusy FlexIO I2S is busy receiving data.
  153. */
  154. status_t FLEXIO_I2S_TransferReceiveEDMA(FLEXIO_I2S_Type *base,
  155. flexio_i2s_edma_handle_t *handle,
  156. flexio_i2s_transfer_t *xfer);
  157. /*!
  158. * @brief Aborts a FlexIO I2S transfer using eDMA.
  159. *
  160. * @param base FlexIO I2S peripheral base address.
  161. * @param handle FlexIO I2S DMA handle pointer.
  162. */
  163. void FLEXIO_I2S_TransferAbortSendEDMA(FLEXIO_I2S_Type *base, flexio_i2s_edma_handle_t *handle);
  164. /*!
  165. * @brief Aborts a FlexIO I2S receive using eDMA.
  166. *
  167. * @param base FlexIO I2S peripheral base address.
  168. * @param handle FlexIO I2S DMA handle pointer.
  169. */
  170. void FLEXIO_I2S_TransferAbortReceiveEDMA(FLEXIO_I2S_Type *base, flexio_i2s_edma_handle_t *handle);
  171. /*!
  172. * @brief Gets the remaining bytes to be sent.
  173. *
  174. * @param base FlexIO I2S peripheral base address.
  175. * @param handle FlexIO I2S DMA handle pointer.
  176. * @param count Bytes sent.
  177. * @retval kStatus_Success Succeed get the transfer count.
  178. * @retval kStatus_NoTransferInProgress There is not a non-blocking transaction currently in progress.
  179. */
  180. status_t FLEXIO_I2S_TransferGetSendCountEDMA(FLEXIO_I2S_Type *base, flexio_i2s_edma_handle_t *handle, size_t *count);
  181. /*!
  182. * @brief Get the remaining bytes to be received.
  183. *
  184. * @param base FlexIO I2S peripheral base address.
  185. * @param handle FlexIO I2S DMA handle pointer.
  186. * @param count Bytes received.
  187. * @retval kStatus_Success Succeed get the transfer count.
  188. * @retval kStatus_NoTransferInProgress There is not a non-blocking transaction currently in progress.
  189. */
  190. status_t FLEXIO_I2S_TransferGetReceiveCountEDMA(FLEXIO_I2S_Type *base, flexio_i2s_edma_handle_t *handle, size_t *count);
  191. /*! @} */
  192. #if defined(__cplusplus)
  193. }
  194. #endif
  195. /*!
  196. * @}
  197. */
  198. #endif