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_SPIFI_DMA_H_
9 #define FSL_SPIFI_DMA_H_
10 
11 #include "fsl_dma.h"
12 #include "fsl_spifi.h"
13 
14 /*!
15  * @addtogroup spifi
16  * @{
17  */
18 
19 /*******************************************************************************
20  * Definitions
21  ******************************************************************************/
22 
23 /*! @name Driver version */
24 /*! @{ */
25 /*! @brief SPIFI DMA driver version 2.0.3. */
26 #define FSL_SPIFI_DMA_DRIVER_VERSION (MAKE_VERSION(2, 0, 3))
27 /*! @} */
28 
29 typedef struct _spifi_dma_handle spifi_dma_handle_t;
30 
31 /*! @brief SPIFI DMA transfer callback function for finish and error */
32 typedef void (*spifi_dma_callback_t)(SPIFI_Type *base, spifi_dma_handle_t *handle, status_t status, void *userData);
33 
34 /*! @brief SPIFI DMA transfer handle, users should not touch the content of the handle.*/
35 struct _spifi_dma_handle
36 {
37     dma_handle_t *dmaHandle;       /*!< DMA handler for SPIFI send */
38     size_t transferSize;           /*!< Bytes need to transfer. */
39     uint32_t state;                /*!< Internal state for SPIFI DMA transfer */
40     spifi_dma_callback_t callback; /*!< Callback for users while transfer finish or error occurred */
41     void *userData;                /*!< User callback parameter */
42 };
43 
44 /*******************************************************************************
45  * APIs
46  ******************************************************************************/
47 #if defined(__cplusplus)
48 extern "C" {
49 #endif
50 
51 /*!
52  * @name DMA Transactional
53  * @{
54  */
55 
56 /*!
57  * @brief Initializes the SPIFI handle for send which is used in transactional functions and set the callback.
58  *
59  * @param base SPIFI peripheral base address
60  * @param handle Pointer to spifi_dma_handle_t structure
61  * @param callback SPIFI callback, NULL means no callback.
62  * @param userData User callback function data.
63  * @param dmaHandle User requested DMA handle for DMA transfer
64  */
65 void SPIFI_TransferTxCreateHandleDMA(SPIFI_Type *base,
66                                      spifi_dma_handle_t *handle,
67                                      spifi_dma_callback_t callback,
68                                      void *userData,
69                                      dma_handle_t *dmaHandle);
70 
71 /*!
72  * @brief Initializes the SPIFI handle for receive which is used in transactional functions and set the callback.
73  *
74  * @param base SPIFI peripheral base address
75  * @param handle Pointer to spifi_dma_handle_t structure
76  * @param callback SPIFI callback, NULL means no callback.
77  * @param userData User callback function data.
78  * @param dmaHandle User requested DMA handle for DMA transfer
79  */
80 void SPIFI_TransferRxCreateHandleDMA(SPIFI_Type *base,
81                                      spifi_dma_handle_t *handle,
82                                      spifi_dma_callback_t callback,
83                                      void *userData,
84                                      dma_handle_t *dmaHandle);
85 
86 /*!
87  * @brief Transfers SPIFI data using an DMA non-blocking method.
88  *
89  * This function writes data to the SPIFI transmit FIFO. This function is non-blocking.
90  * @param base Pointer to QuadSPI Type.
91  * @param handle Pointer to spifi_dma_handle_t structure
92  * @param xfer SPIFI transfer structure.
93  */
94 status_t SPIFI_TransferSendDMA(SPIFI_Type *base, spifi_dma_handle_t *handle, spifi_transfer_t *xfer);
95 
96 /*!
97  * @brief Receives data using an DMA non-blocking method.
98  *
99  * This function receive data from the SPIFI receive buffer/FIFO. This function is non-blocking.
100  * @param base Pointer to QuadSPI Type.
101  * @param handle Pointer to spifi_dma_handle_t structure
102  * @param xfer SPIFI transfer structure.
103  */
104 status_t SPIFI_TransferReceiveDMA(SPIFI_Type *base, spifi_dma_handle_t *handle, spifi_transfer_t *xfer);
105 
106 /*!
107  * @brief Aborts the sent data using DMA.
108  *
109  * This function aborts the sent data using DMA.
110  *
111  * @param base SPIFI peripheral base address.
112  * @param handle Pointer to spifi_dma_handle_t structure
113  */
114 void SPIFI_TransferAbortSendDMA(SPIFI_Type *base, spifi_dma_handle_t *handle);
115 
116 /*!
117  * @brief Aborts the receive data using DMA.
118  *
119  * This function abort receive data which using DMA.
120  *
121  * @param base SPIFI peripheral base address.
122  * @param handle Pointer to spifi_dma_handle_t structure
123  */
124 void SPIFI_TransferAbortReceiveDMA(SPIFI_Type *base, spifi_dma_handle_t *handle);
125 
126 /*!
127  * @brief Gets the transferred counts of send.
128  *
129  * @param base Pointer to QuadSPI Type.
130  * @param handle Pointer to spifi_dma_handle_t structure.
131  * @param count Bytes sent.
132  * @retval kStatus_Success Succeed get the transfer count.
133  * @retval kStatus_NoTransferInProgress There is not a non-blocking transaction currently in progress.
134  */
135 status_t SPIFI_TransferGetSendCountDMA(SPIFI_Type *base, spifi_dma_handle_t *handle, size_t *count);
136 
137 /*!
138  * @brief Gets the status of the receive transfer.
139  *
140  * @param base Pointer to QuadSPI Type.
141  * @param handle Pointer to spifi_dma_handle_t structure
142  * @param count Bytes received.
143  * @retval kStatus_Success Succeed get the transfer count.
144  * @retval kStatus_NoTransferInProgress There is not a non-blocking transaction currently in progress.
145  */
146 status_t SPIFI_TransferGetReceiveCountDMA(SPIFI_Type *base, spifi_dma_handle_t *handle, size_t *count);
147 
148 /*! @} */
149 
150 #if defined(__cplusplus)
151 }
152 #endif
153 
154 /*! @} */
155 
156 #endif /* FSL_SPIFI_DMA_H_ */
157