1 /* 2 * Copyright (c) 2015, Freescale Semiconductor, Inc. 3 * Copyright 2016-2019 NXP 4 * All rights reserved. 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 #ifndef FSL_FLEXIO_I2S_EDMA_H_ 9 #define FSL_FLEXIO_I2S_EDMA_H_ 10 11 #include "fsl_flexio_i2s.h" 12 #include "fsl_edma.h" 13 14 /*! 15 * @addtogroup flexio_edma_i2s 16 * @{ 17 */ 18 19 /******************************************************************************* 20 * Definitions 21 ******************************************************************************/ 22 23 /*! @name Driver version */ 24 /*! @{ */ 25 /*! @brief FlexIO I2S EDMA driver version 2.1.7. */ 26 #define FSL_FLEXIO_I2S_EDMA_DRIVER_VERSION (MAKE_VERSION(2, 1, 7)) 27 /*! @} */ 28 29 typedef struct _flexio_i2s_edma_handle flexio_i2s_edma_handle_t; 30 31 /*! @brief FlexIO I2S eDMA transfer callback function for finish and error */ 32 typedef void (*flexio_i2s_edma_callback_t)(FLEXIO_I2S_Type *base, 33 flexio_i2s_edma_handle_t *handle, 34 status_t status, 35 void *userData); 36 37 /*! @brief FlexIO I2S DMA transfer handle, users should not touch the content of the handle.*/ 38 struct _flexio_i2s_edma_handle 39 { 40 edma_handle_t *dmaHandle; /*!< DMA handler for FlexIO I2S send */ 41 uint8_t bytesPerFrame; /*!< Bytes in a frame */ 42 uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */ 43 uint32_t state; /*!< Internal state for FlexIO I2S eDMA transfer */ 44 flexio_i2s_edma_callback_t callback; /*!< Callback for users while transfer finish or error occurred */ 45 void *userData; /*!< User callback parameter */ 46 edma_tcd_t tcd[FLEXIO_I2S_XFER_QUEUE_SIZE + 1U]; /*!< TCD pool for eDMA transfer. */ 47 flexio_i2s_transfer_t queue[FLEXIO_I2S_XFER_QUEUE_SIZE]; /*!< Transfer queue storing queued transfer. */ 48 size_t transferSize[FLEXIO_I2S_XFER_QUEUE_SIZE]; /*!< Data bytes need to transfer */ 49 volatile uint8_t queueUser; /*!< Index for user to queue transfer. */ 50 volatile uint8_t queueDriver; /*!< Index for driver to get the transfer data and size */ 51 }; 52 53 /******************************************************************************* 54 * APIs 55 ******************************************************************************/ 56 #if defined(__cplusplus) 57 extern "C" { 58 #endif 59 60 /*! 61 * @name eDMA Transactional 62 * @{ 63 */ 64 65 /*! 66 * @brief Initializes the FlexIO I2S eDMA handle. 67 * 68 * This function initializes the FlexIO I2S master DMA handle which can be used for other FlexIO I2S master 69 * transactional APIs. 70 * Usually, for a specified FlexIO I2S instance, call this API once to get the initialized handle. 71 * 72 * @param base FlexIO I2S peripheral base address. 73 * @param handle FlexIO I2S eDMA handle pointer. 74 * @param callback FlexIO I2S eDMA callback function called while finished a block. 75 * @param userData User parameter for callback. 76 * @param dmaHandle eDMA handle for FlexIO I2S. This handle is a static value allocated by users. 77 */ 78 void FLEXIO_I2S_TransferTxCreateHandleEDMA(FLEXIO_I2S_Type *base, 79 flexio_i2s_edma_handle_t *handle, 80 flexio_i2s_edma_callback_t callback, 81 void *userData, 82 edma_handle_t *dmaHandle); 83 84 /*! 85 * @brief Initializes the FlexIO I2S Rx eDMA handle. 86 * 87 * This function initializes the FlexIO I2S slave DMA handle which can be used for other FlexIO I2S master transactional 88 * APIs. 89 * Usually, for a specified FlexIO I2S instance, call this API once to get the initialized handle. 90 * 91 * @param base FlexIO I2S peripheral base address. 92 * @param handle FlexIO I2S eDMA handle pointer. 93 * @param callback FlexIO I2S eDMA callback function called while finished a block. 94 * @param userData User parameter for callback. 95 * @param dmaHandle eDMA handle for FlexIO I2S. This handle is a static value allocated by users. 96 */ 97 void FLEXIO_I2S_TransferRxCreateHandleEDMA(FLEXIO_I2S_Type *base, 98 flexio_i2s_edma_handle_t *handle, 99 flexio_i2s_edma_callback_t callback, 100 void *userData, 101 edma_handle_t *dmaHandle); 102 103 /*! 104 * @brief Configures the FlexIO I2S Tx audio format. 105 * 106 * Audio format can be changed in run-time of FlexIO I2S. This function configures the sample rate and audio data 107 * format to be transferred. This function also sets the eDMA parameter according to format. 108 * 109 * @param base FlexIO I2S peripheral base address. 110 * @param handle FlexIO I2S eDMA handle pointer 111 * @param format Pointer to FlexIO I2S audio data format structure. 112 * @param srcClock_Hz FlexIO I2S clock source frequency in Hz, it should be 0 while in slave mode. 113 */ 114 void FLEXIO_I2S_TransferSetFormatEDMA(FLEXIO_I2S_Type *base, 115 flexio_i2s_edma_handle_t *handle, 116 flexio_i2s_format_t *format, 117 uint32_t srcClock_Hz); 118 119 /*! 120 * @brief Performs a non-blocking FlexIO I2S transfer using DMA. 121 * 122 * @note This interface returned immediately after transfer initiates. Users should call 123 * FLEXIO_I2S_GetTransferStatus to poll the transfer status and check whether the FlexIO I2S transfer is finished. 124 * 125 * @param base FlexIO I2S peripheral base address. 126 * @param handle FlexIO I2S DMA handle pointer. 127 * @param xfer Pointer to DMA transfer structure. 128 * @retval kStatus_Success Start a FlexIO I2S eDMA send successfully. 129 * @retval kStatus_InvalidArgument The input arguments is invalid. 130 * @retval kStatus_TxBusy FlexIO I2S is busy sending data. 131 */ 132 status_t FLEXIO_I2S_TransferSendEDMA(FLEXIO_I2S_Type *base, 133 flexio_i2s_edma_handle_t *handle, 134 flexio_i2s_transfer_t *xfer); 135 136 /*! 137 * @brief Performs a non-blocking FlexIO I2S receive using eDMA. 138 * 139 * @note This interface returned immediately after transfer initiates. Users should call 140 * FLEXIO_I2S_GetReceiveRemainingBytes to poll the transfer status and check whether the FlexIO I2S transfer is 141 * finished. 142 * 143 * @param base FlexIO I2S peripheral base address. 144 * @param handle FlexIO I2S DMA handle pointer. 145 * @param xfer Pointer to DMA transfer structure. 146 * @retval kStatus_Success Start a FlexIO I2S eDMA receive successfully. 147 * @retval kStatus_InvalidArgument The input arguments is invalid. 148 * @retval kStatus_RxBusy FlexIO I2S is busy receiving data. 149 */ 150 status_t FLEXIO_I2S_TransferReceiveEDMA(FLEXIO_I2S_Type *base, 151 flexio_i2s_edma_handle_t *handle, 152 flexio_i2s_transfer_t *xfer); 153 154 /*! 155 * @brief Aborts a FlexIO I2S transfer using eDMA. 156 * 157 * @param base FlexIO I2S peripheral base address. 158 * @param handle FlexIO I2S DMA handle pointer. 159 */ 160 void FLEXIO_I2S_TransferAbortSendEDMA(FLEXIO_I2S_Type *base, flexio_i2s_edma_handle_t *handle); 161 162 /*! 163 * @brief Aborts a FlexIO I2S receive using eDMA. 164 * 165 * @param base FlexIO I2S peripheral base address. 166 * @param handle FlexIO I2S DMA handle pointer. 167 */ 168 void FLEXIO_I2S_TransferAbortReceiveEDMA(FLEXIO_I2S_Type *base, flexio_i2s_edma_handle_t *handle); 169 170 /*! 171 * @brief Gets the remaining bytes to be sent. 172 * 173 * @param base FlexIO I2S peripheral base address. 174 * @param handle FlexIO I2S DMA handle pointer. 175 * @param count Bytes sent. 176 * @retval kStatus_Success Succeed get the transfer count. 177 * @retval kStatus_NoTransferInProgress There is not a non-blocking transaction currently in progress. 178 */ 179 status_t FLEXIO_I2S_TransferGetSendCountEDMA(FLEXIO_I2S_Type *base, flexio_i2s_edma_handle_t *handle, size_t *count); 180 181 /*! 182 * @brief Get the remaining bytes to be received. 183 * 184 * @param base FlexIO I2S peripheral base address. 185 * @param handle FlexIO I2S DMA handle pointer. 186 * @param count Bytes received. 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_TransferGetReceiveCountEDMA(FLEXIO_I2S_Type *base, flexio_i2s_edma_handle_t *handle, size_t *count); 191 192 /*! @} */ 193 194 #if defined(__cplusplus) 195 } 196 #endif 197 198 /*! 199 * @} 200 */ 201 #endif 202