1 /* 2 * Copyright (c) 2016, Freescale Semiconductor, Inc. 3 * Copyright 2016-2020, 2023 NXP 4 * All rights reserved. 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #ifndef _FSL_FLEXSPI_EDMA_H_ 10 #define _FSL_FLEXSPI_EDMA_H_ 11 12 #include "fsl_flexspi.h" 13 #if defined(FSL_FEATURE_SOC_DMAMUX_COUNT) && FSL_FEATURE_SOC_DMAMUX_COUNT 14 #include "fsl_dmamux.h" 15 #endif 16 #include "fsl_edma.h" 17 18 /*! 19 * @addtogroup flexspi_edma 20 * @{ 21 */ 22 23 /******************************************************************************* 24 * Definitions 25 ******************************************************************************/ 26 27 /*! @name Driver version */ 28 /*@{*/ 29 /*! @brief FLEXSPI EDMA driver version. */ 30 #define FSL_FLEXSPI_EDMA_DRIVER_VERSION (MAKE_VERSION(2, 3, 3)) 31 /*@}*/ 32 33 typedef struct _flexspi_edma_handle flexspi_edma_handle_t; 34 35 /*! @brief FLEXSPI eDMA transfer callback function for finish and error */ 36 typedef void (*flexspi_edma_callback_t)(FLEXSPI_Type *base, 37 flexspi_edma_handle_t *handle, 38 status_t status, 39 void *userData); 40 41 /*! @brief eDMA transfer configuration */ 42 typedef enum _flexspi_edma_ntransfer_size 43 { 44 kFLEXPSI_EDMAnSize1Bytes = 0x1U, /*!< Source/Destination data transfer size is 1 byte every time */ 45 kFLEXPSI_EDMAnSize2Bytes = 0x2U, /*!< Source/Destination data transfer size is 2 bytes every time */ 46 kFLEXPSI_EDMAnSize4Bytes = 0x4U, /*!< Source/Destination data transfer size is 4 bytes every time */ 47 kFLEXPSI_EDMAnSize8Bytes = 0x8U, /*!< Source/Destination data transfer size is 8 bytes every time */ 48 kFLEXPSI_EDMAnSize32Bytes = 0x20U, /*!< Source/Destination data transfer size is 32 bytes every time */ 49 } flexspi_edma_transfer_nsize_t; 50 51 /*! @brief FLEXSPI DMA transfer handle, users should not touch the content of the handle.*/ 52 struct _flexspi_edma_handle 53 { 54 edma_handle_t *txDmaHandle; /*!< eDMA handler for FLEXSPI Tx. */ 55 edma_handle_t *rxDmaHandle; /*!< eDMA handler for FLEXSPI Rx. */ 56 size_t transferSize; /*!< Bytes need to transfer. */ 57 flexspi_edma_transfer_nsize_t nsize; /*!< eDMA SSIZE/DSIZE in each transfer. */ 58 uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */ 59 uint8_t count; /*!< The transfer data count in a DMA request. */ 60 uint32_t state; /*!< Internal state for FLEXSPI eDMA transfer. */ 61 flexspi_edma_callback_t completionCallback; /*!< A callback function called after the eDMA transfer is finished. */ 62 void *userData; /*!< User callback parameter */ 63 }; 64 65 /******************************************************************************* 66 * APIs 67 ******************************************************************************/ 68 #if defined(__cplusplus) 69 extern "C" { 70 #endif 71 72 /*! 73 * @name FLEXSPI eDMA Transactional 74 * @{ 75 */ 76 77 /*! 78 * @brief Initializes the FLEXSPI handle for transfer which is used in transactional functions and set the callback. 79 * 80 * @param base FLEXSPI peripheral base address 81 * @param handle Pointer to flexspi_edma_handle_t structure 82 * @param callback FLEXSPI callback, NULL means no callback. 83 * @param userData User callback function data. 84 * @param txDmaHandle User requested DMA handle for TX DMA transfer. 85 * @param rxDmaHandle User requested DMA handle for RX DMA transfer. 86 */ 87 void FLEXSPI_TransferCreateHandleEDMA(FLEXSPI_Type *base, 88 flexspi_edma_handle_t *handle, 89 flexspi_edma_callback_t callback, 90 void *userData, 91 edma_handle_t *txDmaHandle, 92 edma_handle_t *rxDmaHandle); 93 94 /*! 95 * @brief Update FLEXSPI EDMA transfer source data transfer size(SSIZE) and destination data transfer size(DSIZE). 96 * 97 * @param base FLEXSPI peripheral base address 98 * @param handle Pointer to flexspi_edma_handle_t structure 99 * @param nsize FLEXSPI DMA transfer data transfer size(SSIZE/DSIZE), by default the size is 100 * kFLEXPSI_EDMAnSize1Bytes(one byte). 101 * @see flexspi_edma_transfer_nsize_t . 102 */ 103 void FLEXSPI_TransferUpdateSizeEDMA(FLEXSPI_Type *base, 104 flexspi_edma_handle_t *handle, 105 flexspi_edma_transfer_nsize_t nsize); 106 107 /*! 108 * @brief Transfers FLEXSPI data using an eDMA non-blocking method. 109 * 110 * This function writes/receives data to/from the FLEXSPI transmit/receive FIFO. This function is non-blocking. 111 * @param base FLEXSPI peripheral base address. 112 * @param handle Pointer to flexspi_edma_handle_t structure 113 * @param xfer FLEXSPI transfer structure. 114 * @retval kStatus_FLEXSPI_Busy FLEXSPI is busy transfer. 115 * @retval kStatus_InvalidArgument The watermark configuration is invalid, the watermark should be power of 116 2 to do successfully EDMA transfer. 117 * @retval kStatus_Success FLEXSPI successfully start edma transfer. 118 */ 119 status_t FLEXSPI_TransferEDMA(FLEXSPI_Type *base, flexspi_edma_handle_t *handle, flexspi_transfer_t *xfer); 120 121 /*! 122 * @brief Aborts the transfer data using eDMA. 123 * 124 * This function aborts the transfer data using eDMA. 125 * 126 * @param base FLEXSPI peripheral base address. 127 * @param handle Pointer to flexspi_edma_handle_t structure 128 */ 129 void FLEXSPI_TransferAbortEDMA(FLEXSPI_Type *base, flexspi_edma_handle_t *handle); 130 131 /*! 132 * @brief Gets the transferred counts of transfer. 133 * 134 * @param base FLEXSPI peripheral base address. 135 * @param handle Pointer to flexspi_edma_handle_t structure. 136 * @param count Bytes transfer. 137 * @retval kStatus_Success Succeed get the transfer count. 138 * @retval kStatus_NoTransferInProgress There is not a non-blocking transaction currently in progress. 139 */ 140 status_t FLEXSPI_TransferGetTransferCountEDMA(FLEXSPI_Type *base, flexspi_edma_handle_t *handle, size_t *count); 141 142 /* @} */ 143 144 #if defined(__cplusplus) 145 } 146 #endif 147 148 /* @} */ 149 150 #endif /* _FSL_FLEXSPI_EDMA_H_ */ 151