1 /* 2 * Copyright (c) 2016, Freescale Semiconductor, Inc. 3 * Copyright 2016-2020 NXP 4 * All rights reserved. 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 #ifndef _FSL_DMIC_DMA_H_ 9 #define _FSL_DMIC_DMA_H_ 10 11 #include "fsl_common.h" 12 #include "fsl_dma.h" 13 14 /*! 15 * @addtogroup dmic_dma_driver 16 * @{ 17 */ 18 19 /*! @file */ 20 21 /******************************************************************************* 22 * Definitions 23 ******************************************************************************/ 24 25 /*! 26 * @name DMIC DMA version 27 * @{ 28 */ 29 30 /*! @brief DMIC DMA driver version 2.3.0 */ 31 #define FSL_DMIC_DMA_DRIVER_VERSION (MAKE_VERSION(2, 3, 0)) 32 /*@}*/ 33 34 /*! @brief DMIC transfer structure. */ 35 typedef struct _dmic_transfer 36 { 37 void *data; /*!< The buffer of data to be transfer.*/ 38 uint8_t dataWidth; /*!< DMIC support 16bit/32bit */ 39 size_t dataSize; /*!< The byte count to be transfer. */ 40 uint8_t dataAddrInterleaveSize; /*!< destination address interleave size */ 41 42 struct _dmic_transfer *linkTransfer; /*!< use to support link transfer */ 43 } dmic_transfer_t; 44 45 /* Forward declaration of the handle typedef. */ 46 typedef struct _dmic_dma_handle dmic_dma_handle_t; 47 48 /*! @brief DMIC transfer callback function. */ 49 typedef void (*dmic_dma_transfer_callback_t)(DMIC_Type *base, 50 dmic_dma_handle_t *handle, 51 status_t status, 52 void *userData); 53 54 /*! 55 * @brief DMIC DMA handle 56 */ 57 struct _dmic_dma_handle 58 { 59 DMIC_Type *base; /*!< DMIC peripheral base address. */ 60 dma_handle_t *rxDmaHandle; /*!< The DMA RX channel used. */ 61 dmic_dma_transfer_callback_t callback; /*!< Callback function. */ 62 void *userData; /*!< DMIC callback function parameter.*/ 63 size_t transferSize; /*!< Size of the data to receive. */ 64 volatile uint8_t state; /*!< Internal state of DMIC DMA transfer */ 65 66 dma_descriptor_t *desLink; /*!< descriptor pool pointer */ 67 size_t linkNum; /*!< number of descriptor in descriptors pool */ 68 }; 69 70 /******************************************************************************* 71 * API 72 ******************************************************************************/ 73 74 #ifdef __cplusplus 75 extern "C" { 76 #endif /* _cplusplus */ 77 78 /*! 79 * @name DMA transactional 80 * @{ 81 */ 82 83 /*! 84 * @brief Initializes the DMIC handle which is used in transactional functions. 85 * @param base DMIC peripheral base address. 86 * @param handle Pointer to dmic_dma_handle_t structure. 87 * @param callback Callback function. 88 * @param userData User data. 89 * @param rxDmaHandle User-requested DMA handle for RX DMA transfer. 90 */ 91 status_t DMIC_TransferCreateHandleDMA(DMIC_Type *base, 92 dmic_dma_handle_t *handle, 93 dmic_dma_transfer_callback_t callback, 94 void *userData, 95 dma_handle_t *rxDmaHandle); 96 97 /*! 98 * @brief Receives data using DMA. 99 * 100 * This function receives data using DMA. This is a non-blocking function, which returns 101 * right away. When all data is received, the receive callback function is called. 102 * 103 * @param base USART peripheral base address. 104 * @param handle Pointer to usart_dma_handle_t structure. 105 * @param xfer DMIC DMA transfer structure. See #dmic_transfer_t. 106 * @param channel DMIC start channel number. 107 * @retval kStatus_Success 108 */ 109 status_t DMIC_TransferReceiveDMA(DMIC_Type *base, dmic_dma_handle_t *handle, dmic_transfer_t *xfer, uint32_t channel); 110 111 /*! 112 * @brief Aborts the received data using DMA. 113 * 114 * This function aborts the received data using DMA. 115 * 116 * @param base DMIC peripheral base address 117 * @param handle Pointer to dmic_dma_handle_t structure 118 */ 119 void DMIC_TransferAbortReceiveDMA(DMIC_Type *base, dmic_dma_handle_t *handle); 120 121 /*! 122 * @brief Get the number of bytes that have been received. 123 * 124 * This function gets the number of bytes that have been received. 125 * 126 * @param base DMIC peripheral base address. 127 * @param handle DMIC handle pointer. 128 * @param count Receive bytes count. 129 * @retval kStatus_NoTransferInProgress No receive in progress. 130 * @retval kStatus_InvalidArgument Parameter is invalid. 131 * @retval kStatus_Success Get successfully through the parameter count; 132 */ 133 status_t DMIC_TransferGetReceiveCountDMA(DMIC_Type *base, dmic_dma_handle_t *handle, uint32_t *count); 134 135 /*! 136 * @brief Install DMA descriptor memory. 137 * 138 * This function used to register DMA descriptor memory for linked transfer, a typical case is ping pong 139 * transfer which will request more than one DMA descriptor memory space, it should be called after 140 * DMIC_TransferCreateHandleDMA. 141 * User should be take care about the address of DMA descriptor pool which required align with 16BYTE at least. 142 * 143 * @param handle Pointer to DMA channel transfer handle. 144 * @param linkAddr DMA link descriptor address. 145 * @param linkNum DMA link descriptor number. 146 */ 147 void DMIC_InstallDMADescriptorMemory(dmic_dma_handle_t *handle, void *linkAddr, size_t linkNum); 148 149 /* @} */ 150 151 #if defined(__cplusplus) 152 } 153 #endif 154 155 /*! @}*/ 156 157 #endif /* _FSL_DMIC_DMA_H_ */ 158