fsl_spdif_edma.h 9.3 KB

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