fsl_spdif_edma.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * Copyright (c) 2016, Freescale Semiconductor, Inc.
  3. * All rights reserved.
  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 Freescale Semiconductor, Inc. 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_SPDIF_EDMA_H_
  31. #define _FSL_SPDIF_EDMA_H_
  32. #include "fsl_spdif.h"
  33. #include "fsl_edma.h"
  34. /*!
  35. * @addtogroup spdif_edma
  36. * @{
  37. */
  38. /*******************************************************************************
  39. * Definitions
  40. ******************************************************************************/
  41. typedef struct _spdif_edma_handle spdif_edma_handle_t;
  42. /*! @brief SPDIF eDMA transfer callback function for finish and error */
  43. typedef void (*spdif_edma_callback_t)(SPDIF_Type *base, spdif_edma_handle_t *handle, status_t status, void *userData);
  44. /*! @brief SPDIF transfer structure */
  45. typedef struct _spdif_edma_transfer
  46. {
  47. uint8_t *leftData; /*!< Data start address to transfer. */
  48. uint8_t *rightData; /*!< Data start address to transfer. */
  49. size_t dataSize; /*!< Transfer size. */
  50. } spdif_edma_transfer_t;
  51. /*! @brief SPDIF DMA transfer handle, users should not touch the content of the handle.*/
  52. struct _spdif_edma_handle
  53. {
  54. edma_handle_t *dmaLeftHandle; /*!< DMA handler for SPDIF left channel */
  55. edma_handle_t *dmaRightHandle; /*!< DMA handler for SPDIF right channel */
  56. uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */
  57. uint8_t count; /*!< The transfer data count in a DMA request */
  58. uint32_t state; /*!< Internal state for SPDIF eDMA transfer */
  59. spdif_edma_callback_t callback; /*!< Callback for users while transfer finish or error occurs */
  60. void *userData; /*!< User callback parameter */
  61. edma_tcd_t leftTcd[SPDIF_XFER_QUEUE_SIZE + 1U]; /*!< TCD pool for eDMA transfer. */
  62. edma_tcd_t rightTcd[SPDIF_XFER_QUEUE_SIZE + 1U]; /*!< TCD pool for eDMA transfer. */
  63. spdif_edma_transfer_t spdifQueue[SPDIF_XFER_QUEUE_SIZE]; /*!< Transfer queue storing queued transfer. */
  64. size_t transferSize[SPDIF_XFER_QUEUE_SIZE]; /*!< Data bytes need to transfer, left and right are the same, so use
  65. one */
  66. volatile uint8_t queueUser; /*!< Index for user to queue transfer. */
  67. volatile uint8_t queueDriver; /*!< Index for driver to get the transfer data and size */
  68. };
  69. /*******************************************************************************
  70. * APIs
  71. ******************************************************************************/
  72. #if defined(__cplusplus)
  73. extern "C" {
  74. #endif
  75. /*!
  76. * @name eDMA Transactional
  77. * @{
  78. */
  79. /*!
  80. * @brief Initializes the SPDIF eDMA handle.
  81. *
  82. * This function initializes the SPDIF master DMA handle, which can be used for other SPDIF master transactional APIs.
  83. * Usually, for a specified SPDIF instance, call this API once to get the initialized handle.
  84. *
  85. * @param base SPDIF base pointer.
  86. * @param handle SPDIF eDMA handle pointer.
  87. * @param base SPDIF peripheral base address.
  88. * @param callback Pointer to user callback function.
  89. * @param userData User parameter passed to the callback function.
  90. * @param dmaLeftHandle eDMA handle pointer for left channel, this handle shall be static allocated by users.
  91. * @param dmaRightHandle eDMA handle pointer for right channel, this handle shall be static allocated by users.
  92. */
  93. void SPDIF_TransferTxCreateHandleEDMA(SPDIF_Type *base,
  94. spdif_edma_handle_t *handle,
  95. spdif_edma_callback_t callback,
  96. void *userData,
  97. edma_handle_t *dmaLeftHandle,
  98. edma_handle_t *dmaRightHandle);
  99. /*!
  100. * @brief Initializes the SPDIF Rx eDMA handle.
  101. *
  102. * This function initializes the SPDIF slave DMA handle, which can be used for other SPDIF master transactional APIs.
  103. * Usually, for a specified SPDIF instance, call this API once to get the initialized handle.
  104. *
  105. * @param base SPDIF base pointer.
  106. * @param handle SPDIF eDMA handle pointer.
  107. * @param base SPDIF peripheral base address.
  108. * @param callback Pointer to user callback function.
  109. * @param userData User parameter passed to the callback function.
  110. * @param dmaLeftHandle eDMA handle pointer for left channel, this handle shall be static allocated by users.
  111. * @param dmaRightHandle eDMA handle pointer for right channel, this handle shall be static allocated by users.
  112. */
  113. void SPDIF_TransferRxCreateHandleEDMA(SPDIF_Type *base,
  114. spdif_edma_handle_t *handle,
  115. spdif_edma_callback_t callback,
  116. void *userData,
  117. edma_handle_t *dmaLeftHandle,
  118. edma_handle_t *dmaRightHandle);
  119. /*!
  120. * @brief Performs a non-blocking SPDIF transfer using DMA.
  121. *
  122. * @note This interface returns immediately after the transfer initiates. Call
  123. * SPDIF_GetTransferStatus to poll the transfer status and check whether the SPDIF transfer is finished.
  124. *
  125. * @param base SPDIF base pointer.
  126. * @param handle SPDIF eDMA handle pointer.
  127. * @param xfer Pointer to the DMA transfer structure.
  128. * @retval kStatus_Success Start a SPDIF eDMA send successfully.
  129. * @retval kStatus_InvalidArgument The input argument is invalid.
  130. * @retval kStatus_TxBusy SPDIF is busy sending data.
  131. */
  132. status_t SPDIF_TransferSendEDMA(SPDIF_Type *base, spdif_edma_handle_t *handle, spdif_edma_transfer_t *xfer);
  133. /*!
  134. * @brief Performs a non-blocking SPDIF receive using eDMA.
  135. *
  136. * @note This interface returns immediately after the transfer initiates. Call
  137. * the SPDIF_GetReceiveRemainingBytes to poll the transfer status and check whether the SPDIF transfer is finished.
  138. *
  139. * @param base SPDIF base pointer
  140. * @param handle SPDIF eDMA handle pointer.
  141. * @param xfer Pointer to DMA transfer structure.
  142. * @retval kStatus_Success Start a SPDIF eDMA receive successfully.
  143. * @retval kStatus_InvalidArgument The input argument is invalid.
  144. * @retval kStatus_RxBusy SPDIF is busy receiving data.
  145. */
  146. status_t SPDIF_TransferReceiveEDMA(SPDIF_Type *base, spdif_edma_handle_t *handle, spdif_edma_transfer_t *xfer);
  147. /*!
  148. * @brief Aborts a SPDIF transfer using eDMA.
  149. *
  150. * @param base SPDIF base pointer.
  151. * @param handle SPDIF eDMA handle pointer.
  152. */
  153. void SPDIF_TransferAbortSendEDMA(SPDIF_Type *base, spdif_edma_handle_t *handle);
  154. /*!
  155. * @brief Aborts a SPDIF receive using eDMA.
  156. *
  157. * @param base SPDIF base pointer
  158. * @param handle SPDIF eDMA handle pointer.
  159. */
  160. void SPDIF_TransferAbortReceiveEDMA(SPDIF_Type *base, spdif_edma_handle_t *handle);
  161. /*!
  162. * @brief Gets byte count sent by SPDIF.
  163. *
  164. * @param base SPDIF base pointer.
  165. * @param handle SPDIF eDMA handle pointer.
  166. * @param count Bytes count sent by SPDIF.
  167. * @retval kStatus_Success Succeed get the transfer count.
  168. * @retval kStatus_NoTransferInProgress There is no non-blocking transaction in progress.
  169. */
  170. status_t SPDIF_TransferGetSendCountEDMA(SPDIF_Type *base, spdif_edma_handle_t *handle, size_t *count);
  171. /*!
  172. * @brief Gets byte count received by SPDIF.
  173. *
  174. * @param base SPDIF base pointer
  175. * @param handle SPDIF eDMA handle pointer.
  176. * @param count Bytes count received by SPDIF.
  177. * @retval kStatus_Success Succeed get the transfer count.
  178. * @retval kStatus_NoTransferInProgress There is no non-blocking transaction in progress.
  179. */
  180. status_t SPDIF_TransferGetReceiveCountEDMA(SPDIF_Type *base, spdif_edma_handle_t *handle, size_t *count);
  181. /*! @} */
  182. #if defined(__cplusplus)
  183. }
  184. #endif
  185. /*!
  186. * @}
  187. */
  188. #endif