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