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 * @retval kStatus_Success Audio format set successfully. 114 * @retval kStatus_InvalidArgument The input arguments is invalid. 115 */ 116 void FLEXIO_I2S_TransferSetFormatEDMA(FLEXIO_I2S_Type *base, 117 flexio_i2s_edma_handle_t *handle, 118 flexio_i2s_format_t *format, 119 uint32_t srcClock_Hz); 120 121 /*! 122 * @brief Performs a non-blocking FlexIO I2S transfer using DMA. 123 * 124 * @note This interface returned immediately after transfer initiates. Users should call 125 * FLEXIO_I2S_GetTransferStatus to poll the transfer status and check whether the FlexIO I2S transfer is finished. 126 * 127 * @param base FlexIO I2S peripheral base address. 128 * @param handle FlexIO I2S DMA handle pointer. 129 * @param xfer Pointer to DMA transfer structure. 130 * @retval kStatus_Success Start a FlexIO I2S eDMA send successfully. 131 * @retval kStatus_InvalidArgument The input arguments is invalid. 132 * @retval kStatus_TxBusy FlexIO I2S is busy sending data. 133 */ 134 status_t FLEXIO_I2S_TransferSendEDMA(FLEXIO_I2S_Type *base, 135 flexio_i2s_edma_handle_t *handle, 136 flexio_i2s_transfer_t *xfer); 137 138 /*! 139 * @brief Performs a non-blocking FlexIO I2S receive using eDMA. 140 * 141 * @note This interface returned immediately after transfer initiates. Users should call 142 * FLEXIO_I2S_GetReceiveRemainingBytes to poll the transfer status and check whether the FlexIO I2S transfer is 143 * finished. 144 * 145 * @param base FlexIO I2S peripheral base address. 146 * @param handle FlexIO I2S DMA handle pointer. 147 * @param xfer Pointer to DMA transfer structure. 148 * @retval kStatus_Success Start a FlexIO I2S eDMA receive successfully. 149 * @retval kStatus_InvalidArgument The input arguments is invalid. 150 * @retval kStatus_RxBusy FlexIO I2S is busy receiving data. 151 */ 152 status_t FLEXIO_I2S_TransferReceiveEDMA(FLEXIO_I2S_Type *base, 153 flexio_i2s_edma_handle_t *handle, 154 flexio_i2s_transfer_t *xfer); 155 156 /*! 157 * @brief Aborts a FlexIO I2S transfer using eDMA. 158 * 159 * @param base FlexIO I2S peripheral base address. 160 * @param handle FlexIO I2S DMA handle pointer. 161 */ 162 void FLEXIO_I2S_TransferAbortSendEDMA(FLEXIO_I2S_Type *base, flexio_i2s_edma_handle_t *handle); 163 164 /*! 165 * @brief Aborts a FlexIO I2S receive using eDMA. 166 * 167 * @param base FlexIO I2S peripheral base address. 168 * @param handle FlexIO I2S DMA handle pointer. 169 */ 170 void FLEXIO_I2S_TransferAbortReceiveEDMA(FLEXIO_I2S_Type *base, flexio_i2s_edma_handle_t *handle); 171 172 /*! 173 * @brief Gets the remaining bytes to be sent. 174 * 175 * @param base FlexIO I2S peripheral base address. 176 * @param handle FlexIO I2S DMA handle pointer. 177 * @param count Bytes sent. 178 * @retval kStatus_Success Succeed get the transfer count. 179 * @retval kStatus_NoTransferInProgress There is not a non-blocking transaction currently in progress. 180 */ 181 status_t FLEXIO_I2S_TransferGetSendCountEDMA(FLEXIO_I2S_Type *base, flexio_i2s_edma_handle_t *handle, size_t *count); 182 183 /*! 184 * @brief Get the remaining bytes to be received. 185 * 186 * @param base FlexIO I2S peripheral base address. 187 * @param handle FlexIO I2S DMA handle pointer. 188 * @param count Bytes received. 189 * @retval kStatus_Success Succeed get the transfer count. 190 * @retval kStatus_NoTransferInProgress There is not a non-blocking transaction currently in progress. 191 */ 192 status_t FLEXIO_I2S_TransferGetReceiveCountEDMA(FLEXIO_I2S_Type *base, flexio_i2s_edma_handle_t *handle, size_t *count); 193 194 /*! @} */ 195 196 #if defined(__cplusplus) 197 } 198 #endif 199 200 /*! 201 * @} 202 */ 203 #endif 204