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 
9 #ifndef _FSL_FLEXIO_MCULCD_EDMA_H_
10 #define _FSL_FLEXIO_MCULCD_EDMA_H_
11 
12 #include "fsl_edma.h"
13 #include "fsl_flexio_mculcd.h"
14 
15 /*!
16  * @addtogroup flexio_edma_mculcd
17  * @{
18  */
19 
20 /*******************************************************************************
21  * Definitions
22  ******************************************************************************/
23 
24 /*@{*/
25 /*! @brief FlexIO MCULCD EDMA driver version. */
26 #define FSL_FLEXIO_MCULCD_EDMA_DRIVER_VERSION (MAKE_VERSION(2, 0, 4))
27 /*@}*/
28 
29 /*! @brief  typedef for flexio_mculcd_edma_handle_t in advance. */
30 typedef struct _flexio_mculcd_edma_handle flexio_mculcd_edma_handle_t;
31 
32 /*! @brief FlexIO MCULCD master callback for transfer complete.
33  *
34  * When transfer finished, the callback function is called and returns the
35  * @p status as kStatus_FLEXIO_MCULCD_Idle.
36  */
37 typedef void (*flexio_mculcd_edma_transfer_callback_t)(FLEXIO_MCULCD_Type *base,
38                                                        flexio_mculcd_edma_handle_t *handle,
39                                                        status_t status,
40                                                        void *userData);
41 
42 /*! @brief FlexIO MCULCD eDMA transfer handle, users should not touch the
43  * content of the handle.*/
44 struct _flexio_mculcd_edma_handle
45 {
46     FLEXIO_MCULCD_Type *base;       /*!< Pointer to the FLEXIO_MCULCD_Type. */
47     uint8_t txShifterNum;           /*!< Number of shifters used for TX. */
48     uint8_t rxShifterNum;           /*!< Number of shifters used for RX. */
49     uint32_t minorLoopBytes;        /*!< eDMA transfer minor loop bytes. */
50     edma_modulo_t txEdmaModulo;     /*!< Modulo value for the FlexIO shifter buffer access. */
51     edma_modulo_t rxEdmaModulo;     /*!< Modulo value for the FlexIO shifter buffer access. */
52     uint32_t dataAddrOrSameValue;   /*!< When sending the same value for many times,
53                                          this is the value to send. When writing or
54                                          reading array, this is the address of the
55                                          data array. */
56     size_t dataCount;               /*!< Total count to be transferred. */
57     volatile size_t remainingCount; /*!< Remaining count still not transfered. */
58     volatile uint32_t state;        /*!< FlexIO MCULCD driver internal state. */
59     edma_handle_t *txDmaHandle;     /*!< DMA handle for MCULCD TX */
60     edma_handle_t *rxDmaHandle;     /*!< DMA handle for MCULCD RX */
61     flexio_mculcd_edma_transfer_callback_t completionCallback; /*!< Callback for MCULCD DMA transfer */
62     void *userData;                                            /*!< User Data for MCULCD DMA callback */
63 };
64 
65 /*******************************************************************************
66  * APIs
67  ******************************************************************************/
68 #if defined(__cplusplus)
69 extern "C" {
70 #endif
71 
72 /*!
73  * @name eDMA Transactional
74  * @{
75  */
76 
77 /*!
78  * @brief Initializes the FLEXO MCULCD master eDMA handle.
79  *
80  * This function initializes the FLEXO MCULCD master eDMA handle which can be
81  * used for other FLEXO MCULCD transactional APIs. For a specified FLEXO MCULCD
82  * instance, call this API once to get the initialized handle.
83  *
84  * @param base Pointer to FLEXIO_MCULCD_Type structure.
85  * @param handle Pointer to flexio_mculcd_edma_handle_t structure to store the
86  * transfer state.
87  * @param callback MCULCD transfer complete callback, NULL means no callback.
88  * @param userData callback function parameter.
89  * @param txDmaHandle User requested eDMA handle for FlexIO MCULCD eDMA TX,
90  * the DMA request source of this handle should be the first of TX shifters.
91  * @param rxDmaHandle User requested eDMA handle for FlexIO MCULCD eDMA RX,
92  * the DMA request source of this handle should be the last of RX shifters.
93  * @retval kStatus_Success Successfully create the handle.
94  */
95 status_t FLEXIO_MCULCD_TransferCreateHandleEDMA(FLEXIO_MCULCD_Type *base,
96                                                 flexio_mculcd_edma_handle_t *handle,
97                                                 flexio_mculcd_edma_transfer_callback_t callback,
98                                                 void *userData,
99                                                 edma_handle_t *txDmaHandle,
100                                                 edma_handle_t *rxDmaHandle);
101 
102 /*!
103  * @brief Performs a non-blocking FlexIO MCULCD transfer using eDMA.
104  *
105  * This function returns immediately after transfer initiates. To check whether
106  * the transfer is completed, user could:
107  * 1. Use the transfer completed callback;
108  * 2. Polling function FLEXIO_MCULCD_GetTransferCountEDMA
109  *
110  * @param base pointer to FLEXIO_MCULCD_Type structure.
111  * @param handle pointer to flexio_mculcd_edma_handle_t structure to store the
112  * transfer state.
113  * @param xfer Pointer to FlexIO MCULCD transfer structure.
114  * @retval kStatus_Success Successfully start a transfer.
115  * @retval kStatus_InvalidArgument Input argument is invalid.
116  * @retval kStatus_FLEXIO_MCULCD_Busy FlexIO MCULCD is not idle, it is running another
117  * transfer.
118  */
119 status_t FLEXIO_MCULCD_TransferEDMA(FLEXIO_MCULCD_Type *base,
120                                     flexio_mculcd_edma_handle_t *handle,
121                                     flexio_mculcd_transfer_t *xfer);
122 
123 /*!
124  * @brief Aborts a FlexIO MCULCD transfer using eDMA.
125  *
126  * @param base pointer to FLEXIO_MCULCD_Type structure.
127  * @param handle FlexIO MCULCD eDMA handle pointer.
128  */
129 void FLEXIO_MCULCD_TransferAbortEDMA(FLEXIO_MCULCD_Type *base, flexio_mculcd_edma_handle_t *handle);
130 
131 /*!
132  * @brief Gets the remaining bytes for FlexIO MCULCD eDMA transfer.
133  *
134  * @param base pointer to FLEXIO_MCULCD_Type structure.
135  * @param handle FlexIO MCULCD eDMA handle pointer.
136  * @param count Number of count transferred so far by the eDMA transaction.
137  * @retval kStatus_Success Get the transferred count Successfully.
138  * @retval kStatus_NoTransferInProgress No transfer in process.
139  */
140 status_t FLEXIO_MCULCD_TransferGetCountEDMA(FLEXIO_MCULCD_Type *base,
141                                             flexio_mculcd_edma_handle_t *handle,
142                                             size_t *count);
143 
144 /*! @} */
145 
146 #if defined(__cplusplus)
147 }
148 #endif
149 
150 /*!
151  * @}
152  */
153 #endif /* _FSL_FLEXIO_MCULCD_EDMA_H_ */
154