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 base SPDIF peripheral base address. 82 * @param callback Pointer to user callback function. 83 * @param userData User parameter passed to the callback function. 84 * @param dmaLeftHandle eDMA handle pointer for left channel, this handle shall be static allocated by users. 85 * @param dmaRightHandle eDMA handle pointer for right channel, this handle shall be static allocated by users. 86 */ 87 void SPDIF_TransferTxCreateHandleEDMA(SPDIF_Type *base, 88 spdif_edma_handle_t *handle, 89 spdif_edma_callback_t callback, 90 void *userData, 91 edma_handle_t *dmaLeftHandle, 92 edma_handle_t *dmaRightHandle); 93 94 /*! 95 * @brief Initializes the SPDIF Rx eDMA handle. 96 * 97 * This function initializes the SPDIF slave DMA handle, which can be used for other SPDIF master transactional APIs. 98 * Usually, for a specified SPDIF instance, call this API once to get the initialized handle. 99 * 100 * @param base SPDIF base pointer. 101 * @param handle SPDIF eDMA handle pointer. 102 * @param base SPDIF peripheral base address. 103 * @param callback Pointer to user callback function. 104 * @param userData User parameter passed to the callback function. 105 * @param dmaLeftHandle eDMA handle pointer for left channel, this handle shall be static allocated by users. 106 * @param dmaRightHandle eDMA handle pointer for right channel, this handle shall be static allocated by users. 107 */ 108 void SPDIF_TransferRxCreateHandleEDMA(SPDIF_Type *base, 109 spdif_edma_handle_t *handle, 110 spdif_edma_callback_t callback, 111 void *userData, 112 edma_handle_t *dmaLeftHandle, 113 edma_handle_t *dmaRightHandle); 114 115 /*! 116 * @brief Performs a non-blocking SPDIF transfer using DMA. 117 * 118 * @note This interface returns immediately after the transfer initiates. Call 119 * SPDIF_GetTransferStatus to poll the transfer status and check whether the SPDIF transfer is finished. 120 * 121 * @param base SPDIF base pointer. 122 * @param handle SPDIF eDMA handle pointer. 123 * @param xfer Pointer to the DMA transfer structure. 124 * @retval kStatus_Success Start a SPDIF eDMA send successfully. 125 * @retval kStatus_InvalidArgument The input argument is invalid. 126 * @retval kStatus_TxBusy SPDIF is busy sending data. 127 */ 128 status_t SPDIF_TransferSendEDMA(SPDIF_Type *base, spdif_edma_handle_t *handle, spdif_edma_transfer_t *xfer); 129 130 /*! 131 * @brief Performs a non-blocking SPDIF receive using eDMA. 132 * 133 * @note This interface returns immediately after the transfer initiates. Call 134 * the SPDIF_GetReceiveRemainingBytes to poll the transfer status and check whether the SPDIF transfer is finished. 135 * 136 * @param base SPDIF base pointer 137 * @param handle SPDIF eDMA handle pointer. 138 * @param xfer Pointer to DMA transfer structure. 139 * @retval kStatus_Success Start a SPDIF eDMA receive successfully. 140 * @retval kStatus_InvalidArgument The input argument is invalid. 141 * @retval kStatus_RxBusy SPDIF is busy receiving data. 142 */ 143 status_t SPDIF_TransferReceiveEDMA(SPDIF_Type *base, spdif_edma_handle_t *handle, spdif_edma_transfer_t *xfer); 144 145 /*! 146 * @brief Aborts a SPDIF transfer using eDMA. 147 * 148 * @param base SPDIF base pointer. 149 * @param handle SPDIF eDMA handle pointer. 150 */ 151 void SPDIF_TransferAbortSendEDMA(SPDIF_Type *base, spdif_edma_handle_t *handle); 152 153 /*! 154 * @brief Aborts a SPDIF receive using eDMA. 155 * 156 * @param base SPDIF base pointer 157 * @param handle SPDIF eDMA handle pointer. 158 */ 159 void SPDIF_TransferAbortReceiveEDMA(SPDIF_Type *base, spdif_edma_handle_t *handle); 160 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 /*! 173 * @brief Gets byte count received by SPDIF. 174 * 175 * @param base SPDIF base pointer 176 * @param handle SPDIF eDMA handle pointer. 177 * @param count Bytes count received by SPDIF. 178 * @retval kStatus_Success Succeed get the transfer count. 179 * @retval kStatus_NoTransferInProgress There is no non-blocking transaction in progress. 180 */ 181 status_t SPDIF_TransferGetReceiveCountEDMA(SPDIF_Type *base, spdif_edma_handle_t *handle, size_t *count); 182 183 /*! @} */ 184 185 #if defined(__cplusplus) 186 } 187 #endif 188 189 /*! 190 * @} 191 */ 192 #endif 193