1 /*
2  * Copyright (c) 2015, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 #ifndef _FSL_FLEXIO_UART_EDMA_H_
9 #define _FSL_FLEXIO_UART_EDMA_H_
10 
11 #include "fsl_flexio_uart.h"
12 #include "fsl_edma.h"
13 
14 /*!
15  * @addtogroup flexio_edma_uart
16  * @{
17  */
18 
19 /*******************************************************************************
20  * Definitions
21  ******************************************************************************/
22 
23 /* Forward declaration of the handle typedef. */
24 typedef struct _flexio_uart_edma_handle flexio_uart_edma_handle_t;
25 
26 /*! @brief UART transfer callback function. */
27 typedef void (*flexio_uart_edma_transfer_callback_t)(FLEXIO_UART_Type *base,
28                                                      flexio_uart_edma_handle_t *handle,
29                                                      status_t status,
30                                                      void *userData);
31 
32 /*!
33 * @brief UART eDMA handle
34 */
35 struct _flexio_uart_edma_handle
36 {
37     flexio_uart_edma_transfer_callback_t callback; /*!< Callback function. */
38     void *userData;                                /*!< UART callback function parameter.*/
39 
40     size_t txDataSizeAll; /*!< Total bytes to be sent. */
41     size_t rxDataSizeAll; /*!< Total bytes to be received. */
42 
43     edma_handle_t *txEdmaHandle; /*!< The eDMA TX channel used. */
44     edma_handle_t *rxEdmaHandle; /*!< The eDMA RX channel used. */
45 
46     uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */
47 
48     volatile uint8_t txState; /*!< TX transfer state. */
49     volatile uint8_t rxState; /*!< RX transfer state */
50 };
51 
52 /*******************************************************************************
53  * API
54  ******************************************************************************/
55 
56 #if defined(__cplusplus)
57 extern "C" {
58 #endif
59 
60 /*!
61  * @name eDMA transactional
62  * @{
63  */
64 
65 /*!
66  * @brief Initializes the UART handle which is used in transactional functions.
67  *
68  * @param base Pointer to FLEXIO_UART_Type.
69  * @param handle Pointer to flexio_uart_edma_handle_t structure.
70  * @param callback The callback function.
71  * @param userData The parameter of the callback function.
72  * @param rxEdmaHandle User requested DMA handle for RX DMA transfer.
73  * @param txEdmaHandle User requested DMA handle for TX DMA transfer.
74  * @retval kStatus_Success Successfully create the handle.
75  * @retval kStatus_OutOfRange The FlexIO SPI eDMA type/handle table out of range.
76  */
77 status_t FLEXIO_UART_TransferCreateHandleEDMA(FLEXIO_UART_Type *base,
78                                               flexio_uart_edma_handle_t *handle,
79                                               flexio_uart_edma_transfer_callback_t callback,
80                                               void *userData,
81                                               edma_handle_t *txEdmaHandle,
82                                               edma_handle_t *rxEdmaHandle);
83 
84 /*!
85  * @brief Sends data using eDMA.
86  *
87  * This function sends data using eDMA. This is a non-blocking function, which returns
88  * right away. When all data is sent out, the send callback function is called.
89  *
90  * @param base Pointer to FLEXIO_UART_Type
91  * @param handle UART handle pointer.
92  * @param xfer UART eDMA transfer structure, see #flexio_uart_transfer_t.
93  * @retval kStatus_Success if succeed, others failed.
94  * @retval kStatus_FLEXIO_UART_TxBusy Previous transfer on going.
95  */
96 status_t FLEXIO_UART_TransferSendEDMA(FLEXIO_UART_Type *base,
97                                       flexio_uart_edma_handle_t *handle,
98                                       flexio_uart_transfer_t *xfer);
99 
100 /*!
101  * @brief Receives data using eDMA.
102  *
103  * This function receives data using eDMA. This is a non-blocking function, which returns
104  * right away. When all data is received, the receive callback function is called.
105  *
106  * @param base Pointer to FLEXIO_UART_Type
107  * @param handle Pointer to flexio_uart_edma_handle_t structure
108  * @param xfer UART eDMA transfer structure, see #flexio_uart_transfer_t.
109  * @retval kStatus_Success if succeed, others failed.
110  * @retval kStatus_UART_RxBusy Previous transfer on going.
111  */
112 status_t FLEXIO_UART_TransferReceiveEDMA(FLEXIO_UART_Type *base,
113                                          flexio_uart_edma_handle_t *handle,
114                                          flexio_uart_transfer_t *xfer);
115 
116 /*!
117  * @brief Aborts the sent data which using eDMA.
118  *
119  * This function aborts sent data which using eDMA.
120  *
121  * @param base Pointer to FLEXIO_UART_Type
122  * @param handle Pointer to flexio_uart_edma_handle_t structure
123  */
124 void FLEXIO_UART_TransferAbortSendEDMA(FLEXIO_UART_Type *base, flexio_uart_edma_handle_t *handle);
125 
126 /*!
127  * @brief Aborts the receive data which using eDMA.
128  *
129  * This function aborts the receive data which using eDMA.
130  *
131  * @param base Pointer to FLEXIO_UART_Type
132  * @param handle Pointer to flexio_uart_edma_handle_t structure
133  */
134 void FLEXIO_UART_TransferAbortReceiveEDMA(FLEXIO_UART_Type *base, flexio_uart_edma_handle_t *handle);
135 
136 /*!
137  * @brief Gets the number of bytes sent out.
138  *
139  * This function gets the number of bytes sent out.
140  *
141  * @param base Pointer to FLEXIO_UART_Type
142  * @param handle Pointer to flexio_uart_edma_handle_t structure
143  * @param count Number of bytes sent so far by the non-blocking transaction.
144  * @retval kStatus_NoTransferInProgress transfer has finished or no transfer in progress.
145  * @retval kStatus_Success Successfully return the count.
146  */
147 status_t FLEXIO_UART_TransferGetSendCountEDMA(FLEXIO_UART_Type *base, flexio_uart_edma_handle_t *handle, size_t *count);
148 
149 /*!
150  * @brief Gets the number of bytes received.
151  *
152  * This function gets the number of bytes received.
153  *
154  * @param base Pointer to FLEXIO_UART_Type
155  * @param handle Pointer to flexio_uart_edma_handle_t structure
156  * @param count Number of bytes received so far by the non-blocking transaction.
157  * @retval kStatus_NoTransferInProgress transfer has finished or no transfer in progress.
158  * @retval kStatus_Success Successfully return the count.
159  */
160 status_t FLEXIO_UART_TransferGetReceiveCountEDMA(FLEXIO_UART_Type *base,
161                                                  flexio_uart_edma_handle_t *handle,
162                                                  size_t *count);
163 
164 /*@}*/
165 
166 #if defined(__cplusplus)
167 }
168 #endif
169 
170 /*! @}*/
171 
172 #endif /* _FSL_UART_EDMA_H_ */
173