1 /* 2 * Copyright (c) 2015, Freescale Semiconductor, Inc. 3 * Copyright 2016-2020 NXP 4 * All rights reserved. 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #ifndef _FSL_QSPI_EDMA_H_ 10 #define _FSL_QSPI_EDMA_H_ 11 12 #include "fsl_qspi.h" 13 #include "fsl_edma.h" 14 15 /*! 16 * @addtogroup qspi_edma_driver 17 * @{ 18 */ 19 20 /******************************************************************************* 21 * Definitions 22 ******************************************************************************/ 23 24 /*! @name Driver version */ 25 /*@{*/ 26 /*! @brief QSPI EDMA driver version 2.2.2. */ 27 #define FSL_QSPI_EDMA_DRIVER_VERSION (MAKE_VERSION(2, 2, 2)) 28 /*@}*/ 29 30 typedef struct _qspi_edma_handle qspi_edma_handle_t; 31 32 /*! @brief QSPI eDMA transfer callback function for finish and error */ 33 typedef void (*qspi_edma_callback_t)(QuadSPI_Type *base, qspi_edma_handle_t *handle, status_t status, void *userData); 34 35 /*! @brief QSPI DMA transfer handle, users should not touch the content of the handle.*/ 36 struct _qspi_edma_handle 37 { 38 edma_handle_t *dmaHandle; /*!< eDMA handler for QSPI send */ 39 size_t transferSize; /*!< Bytes need to transfer. */ 40 uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */ 41 uint8_t count; /*!< The transfer data count in a DMA request */ 42 uint32_t state; /*!< Internal state for QSPI eDMA transfer */ 43 qspi_edma_callback_t callback; /*!< Callback for users while transfer finish or error occurred */ 44 void *userData; /*!< User callback parameter */ 45 }; 46 47 /******************************************************************************* 48 * APIs 49 ******************************************************************************/ 50 #if defined(__cplusplus) 51 extern "C" { 52 #endif 53 54 /*! 55 * @name eDMA Transactional 56 * @{ 57 */ 58 59 /*! 60 * @brief Initializes the QSPI handle for send which is used in transactional functions and set the callback. 61 * 62 * @param base QSPI peripheral base address 63 * @param handle Pointer to qspi_edma_handle_t structure 64 * @param callback QSPI callback, NULL means no callback. 65 * @param userData User callback function data. 66 * @param dmaHandle User requested eDMA handle for eDMA transfer 67 */ 68 void QSPI_TransferTxCreateHandleEDMA(QuadSPI_Type *base, 69 qspi_edma_handle_t *handle, 70 qspi_edma_callback_t callback, 71 void *userData, 72 edma_handle_t *dmaHandle); 73 74 /*! 75 * @brief Initializes the QSPI handle for receive which is used in transactional functions and set the callback. 76 * 77 * @param base QSPI peripheral base address 78 * @param handle Pointer to qspi_edma_handle_t structure 79 * @param callback QSPI callback, NULL means no callback. 80 * @param userData User callback function data. 81 * @param dmaHandle User requested eDMA handle for eDMA transfer 82 */ 83 void QSPI_TransferRxCreateHandleEDMA(QuadSPI_Type *base, 84 qspi_edma_handle_t *handle, 85 qspi_edma_callback_t callback, 86 void *userData, 87 edma_handle_t *dmaHandle); 88 89 /*! 90 * @brief Transfers QSPI data using an eDMA non-blocking method. 91 * 92 * This function writes data to the QSPI transmit FIFO. This function is non-blocking. 93 * @param base Pointer to QuadSPI Type. 94 * @param handle Pointer to qspi_edma_handle_t structure 95 * @param xfer QSPI transfer structure. 96 */ 97 status_t QSPI_TransferSendEDMA(QuadSPI_Type *base, qspi_edma_handle_t *handle, qspi_transfer_t *xfer); 98 99 /*! 100 * @brief Receives data using an eDMA non-blocking method. 101 * 102 * This function receive data from the QSPI receive buffer/FIFO. This function is non-blocking. Users shall notice that 103 * this receive size shall not bigger than 64 bytes. As this interface is used to read flash status registers. 104 * For flash contents read, please use AHB bus read, this is much more efficiency. 105 * 106 * @param base Pointer to QuadSPI Type. 107 * @param handle Pointer to qspi_edma_handle_t structure 108 * @param xfer QSPI transfer structure. 109 */ 110 status_t QSPI_TransferReceiveEDMA(QuadSPI_Type *base, qspi_edma_handle_t *handle, qspi_transfer_t *xfer); 111 112 /*! 113 * @brief Aborts the sent data using eDMA. 114 * 115 * This function aborts the sent data using eDMA. 116 * 117 * @param base QSPI peripheral base address. 118 * @param handle Pointer to qspi_edma_handle_t structure 119 */ 120 void QSPI_TransferAbortSendEDMA(QuadSPI_Type *base, qspi_edma_handle_t *handle); 121 122 /*! 123 * @brief Aborts the receive data using eDMA. 124 * 125 * This function abort receive data which using eDMA. 126 * 127 * @param base QSPI peripheral base address. 128 * @param handle Pointer to qspi_edma_handle_t structure 129 */ 130 void QSPI_TransferAbortReceiveEDMA(QuadSPI_Type *base, qspi_edma_handle_t *handle); 131 132 /*! 133 * @brief Gets the transferred counts of send. 134 * 135 * @param base Pointer to QuadSPI Type. 136 * @param handle Pointer to qspi_edma_handle_t structure. 137 * @param count Bytes sent. 138 * @retval kStatus_Success Succeed get the transfer count. 139 * @retval kStatus_NoTransferInProgress There is not a non-blocking transaction currently in progress. 140 */ 141 status_t QSPI_TransferGetSendCountEDMA(QuadSPI_Type *base, qspi_edma_handle_t *handle, size_t *count); 142 143 /*! 144 * @brief Gets the status of the receive transfer. 145 * 146 * @param base Pointer to QuadSPI Type. 147 * @param handle Pointer to qspi_edma_handle_t structure 148 * @param count Bytes received. 149 * @retval kStatus_Success Succeed get the transfer count. 150 * @retval kStatus_NoTransferInProgress There is not a non-blocking transaction currently in progress. 151 */ 152 status_t QSPI_TransferGetReceiveCountEDMA(QuadSPI_Type *base, qspi_edma_handle_t *handle, size_t *count); 153 154 /* @} */ 155 156 #if defined(__cplusplus) 157 } 158 #endif 159 160 /* @} */ 161 162 #endif /* _FSL_QSPI_EDMA_H_ */ 163