fsl_flexio_i2s_edma.h 10 KB

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