1 /* 2 * Copyright (c) 2018, Freescale Semiconductor, Inc. 3 * Copyright 2019 - 2020, NXP 4 * All rights reserved. 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #ifndef FSL_PDM_SDMA_H_ 10 #define FSL_PDM_SDMA_H_ 11 12 #include "fsl_pdm.h" 13 #include "fsl_sdma.h" 14 15 /*! 16 * @addtogroup pdm_sdma PDM SDMA Driver 17 * @ingroup pdm 18 * @{ 19 */ 20 21 /******************************************************************************* 22 * Definitions 23 ******************************************************************************/ 24 25 /*! @name Driver version */ 26 /*! @{ */ 27 #define FSL_PDM_SDMA_DRIVER_VERSION (MAKE_VERSION(2, 7, 0)) /*!< Version 2.7.0 */ 28 /*! @} */ 29 30 typedef struct _pdm_sdma_handle pdm_sdma_handle_t; 31 32 /*! @brief PDM eDMA transfer callback function for finish and error */ 33 typedef void (*pdm_sdma_callback_t)(PDM_Type *base, pdm_sdma_handle_t *handle, status_t status, void *userData); 34 35 /*! @brief PDM DMA transfer handle, users should not touch the content of the handle.*/ 36 struct _pdm_sdma_handle 37 { 38 sdma_handle_t *dmaHandle; /*!< DMA handler for PDM send */ 39 uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */ 40 uint8_t fifoWidth; /*!< fifo width */ 41 uint8_t endChannel; /*!< The last enabled channel */ 42 uint8_t channelNums; /*!< total channel numbers */ 43 uint32_t count; /*!< The transfer data count in a DMA request */ 44 uint32_t state; /*!< Internal state for PDM eDMA transfer */ 45 uint32_t eventSource; /*!< PDM event source number */ 46 pdm_sdma_callback_t callback; /*!< Callback for users while transfer finish or error occurs */ 47 void *userData; /*!< User callback parameter */ 48 sdma_buffer_descriptor_t bdPool[PDM_XFER_QUEUE_SIZE]; /*!< BD pool for SDMA transfer. */ 49 pdm_transfer_t pdmQueue[PDM_XFER_QUEUE_SIZE]; /*!< Transfer queue storing queued transfer. */ 50 size_t transferSize[PDM_XFER_QUEUE_SIZE]; /*!< Data bytes need to transfer */ 51 volatile uint8_t queueUser; /*!< Index for user to queue transfer. */ 52 volatile uint8_t queueDriver; /*!< Index for driver to get the transfer data and size */ 53 }; 54 55 /******************************************************************************* 56 * APIs 57 ******************************************************************************/ 58 #if defined(__cplusplus) 59 extern "C" { 60 #endif 61 62 /*! 63 * @name eDMA Transactional 64 * @{ 65 */ 66 67 /*! 68 * @brief Initializes the PDM eDMA handle. 69 * 70 * This function initializes the PDM DMA handle, which can be used for other PDM master transactional APIs. 71 * Usually, for a specified PDM instance, call this API once to get the initialized handle. 72 * 73 * @param base PDM base pointer. 74 * @param handle PDM eDMA handle pointer. 75 * @param callback Pointer to user callback function. 76 * @param userData User parameter passed to the callback function. 77 * @param dmaHandle eDMA handle pointer, this handle shall be static allocated by users. 78 * @param eventSource PDM event source number. 79 */ 80 void PDM_TransferCreateHandleSDMA(PDM_Type *base, 81 pdm_sdma_handle_t *handle, 82 pdm_sdma_callback_t callback, 83 void *userData, 84 sdma_handle_t *dmaHandle, 85 uint32_t eventSource); 86 87 /*! 88 * @brief Performs a non-blocking PDM receive using eDMA. 89 * 90 * @note This interface returns immediately after the transfer initiates. Call 91 * the PDM_GetReceiveRemainingBytes to poll the transfer status and check whether the PDM transfer is finished. 92 * 93 * @param base PDM base pointer 94 * @param handle PDM eDMA handle pointer. 95 * @param xfer Pointer to DMA transfer structure. 96 * @retval kStatus_Success Start a PDM eDMA receive successfully. 97 * @retval kStatus_InvalidArgument The input argument is invalid. 98 * @retval kStatus_RxBusy PDM is busy receiving data. 99 */ 100 status_t PDM_TransferReceiveSDMA(PDM_Type *base, pdm_sdma_handle_t *handle, pdm_transfer_t *xfer); 101 102 /*! 103 * @brief Aborts a PDM receive using eDMA. 104 * 105 * @param base PDM base pointer 106 * @param handle PDM eDMA handle pointer. 107 */ 108 void PDM_TransferAbortReceiveSDMA(PDM_Type *base, pdm_sdma_handle_t *handle); 109 110 /*! 111 * @brief PDM channel configurations. 112 * 113 * @param base PDM base pointer. 114 * @param handle PDM eDMA handle pointer. 115 * @param channel channel number. 116 * @param config channel configurations. 117 */ 118 void PDM_SetChannelConfigSDMA(PDM_Type *base, 119 pdm_sdma_handle_t *handle, 120 uint32_t channel, 121 const pdm_channel_config_t *config); 122 123 /*! 124 * @brief Terminate all the PDM sdma receive transfer. 125 * 126 * @param base PDM base pointer. 127 * @param handle PDM SDMA handle pointer. 128 */ 129 void PDM_TransferTerminateReceiveSDMA(PDM_Type *base, pdm_sdma_handle_t *handle); 130 131 /*! @} */ 132 133 #if defined(__cplusplus) 134 } 135 #endif 136 137 /*! 138 * @} 139 */ 140 #endif 141