1 /*
2  * Copyright 2016-2020 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 #ifndef _FSL_UART_SDMA_H_
7 #define _FSL_UART_SDMA_H_
8 
9 #include "fsl_uart.h"
10 #include "fsl_sdma.h"
11 
12 /*!
13  * @addtogroup uart_sdma
14  * @{
15  */
16 
17 /*******************************************************************************
18  * Definitions
19  ******************************************************************************/
20 
21 /*! @name Driver version */
22 /*@{*/
23 /*! @brief UART SDMA driver version. */
24 #define FSL_UART_SDMA_DRIVER_VERSION (MAKE_VERSION(2, 3, 0))
25 /*@}*/
26 
27 /* Forward declaration of the handle typedef. */
28 typedef struct _uart_sdma_handle uart_sdma_handle_t;
29 
30 /*! @brief UART transfer callback function. */
31 typedef void (*uart_sdma_transfer_callback_t)(UART_Type *base,
32                                               uart_sdma_handle_t *handle,
33                                               status_t status,
34                                               void *userData);
35 
36 /*!
37  * @brief UART sDMA handle
38  */
39 struct _uart_sdma_handle
40 {
41     uart_sdma_transfer_callback_t callback; /*!< Callback function. */
42     void *userData;                         /*!< UART callback function parameter.*/
43     size_t rxDataSizeAll;                   /*!< Size of the data to receive. */
44     size_t txDataSizeAll;                   /*!< Size of the data to send out. */
45     sdma_handle_t *txSdmaHandle;            /*!< The sDMA TX channel used. */
46     sdma_handle_t *rxSdmaHandle;            /*!< The sDMA RX channel used. */
47     volatile uint8_t txState;               /*!< TX transfer state. */
48     volatile uint8_t rxState;               /*!< RX transfer state */
49 };
50 
51 /*******************************************************************************
52  * API
53  ******************************************************************************/
54 
55 #if defined(__cplusplus)
56 extern "C" {
57 #endif
58 
59 /*!
60  * @name sDMA transactional
61  * @{
62  */
63 
64 /*!
65  * @brief Initializes the UART handle which is used in transactional functions.
66  * @param base UART peripheral base address.
67  * @param handle Pointer to the uart_sdma_handle_t structure.
68  * @param callback UART callback, NULL means no callback.
69  * @param userData User callback function data.
70  * @param rxSdmaHandle User-requested DMA handle for RX DMA transfer.
71  * @param txSdmaHandle User-requested DMA handle for TX DMA transfer.
72  * @param eventSourceTx Eventsource for TX DMA transfer.
73  * @param eventSourceRx Eventsource for RX DMA transfer.
74  */
75 void UART_TransferCreateHandleSDMA(UART_Type *base,
76                                    uart_sdma_handle_t *handle,
77                                    uart_sdma_transfer_callback_t callback,
78                                    void *userData,
79                                    sdma_handle_t *txSdmaHandle,
80                                    sdma_handle_t *rxSdmaHandle,
81                                    uint32_t eventSourceTx,
82                                    uint32_t eventSourceRx);
83 
84 /*!
85  * @brief Sends data using sDMA.
86  *
87  * This function sends data using sDMA. This is a non-blocking function, which returns
88  * right away. When all data is sent, the send callback function is called.
89  *
90  * @param base UART peripheral base address.
91  * @param handle UART handle pointer.
92  * @param xfer UART sDMA transfer structure. See #uart_transfer_t.
93  * @retval kStatus_Success if succeeded; otherwise failed.
94  * @retval kStatus_UART_TxBusy Previous transfer ongoing.
95  * @retval kStatus_InvalidArgument Invalid argument.
96  */
97 status_t UART_SendSDMA(UART_Type *base, uart_sdma_handle_t *handle, uart_transfer_t *xfer);
98 
99 /*!
100  * @brief Receives data using sDMA.
101  *
102  * This function receives data using sDMA. This is a non-blocking function, which returns
103  * right away. When all data is received, the receive callback function is called.
104  *
105  * @param base UART peripheral base address.
106  * @param handle Pointer to the uart_sdma_handle_t structure.
107  * @param xfer UART sDMA transfer structure. See #uart_transfer_t.
108  * @retval kStatus_Success if succeeded; otherwise failed.
109  * @retval kStatus_UART_RxBusy Previous transfer ongoing.
110  * @retval kStatus_InvalidArgument Invalid argument.
111  */
112 status_t UART_ReceiveSDMA(UART_Type *base, uart_sdma_handle_t *handle, uart_transfer_t *xfer);
113 
114 /*!
115  * @brief Aborts the sent data using sDMA.
116  *
117  * This function aborts sent data using sDMA.
118  *
119  * @param base UART peripheral base address.
120  * @param handle Pointer to the uart_sdma_handle_t structure.
121  */
122 void UART_TransferAbortSendSDMA(UART_Type *base, uart_sdma_handle_t *handle);
123 
124 /*!
125  * @brief Aborts the receive data using sDMA.
126  *
127  * This function aborts receive data using sDMA.
128  *
129  * @param base UART peripheral base address.
130  * @param handle Pointer to the uart_sdma_handle_t structure.
131  */
132 void UART_TransferAbortReceiveSDMA(UART_Type *base, uart_sdma_handle_t *handle);
133 
134 /*!
135  * @brief UART IRQ handle function.
136  *
137  * This function handles the UART transmit complete IRQ request and invoke user callback.
138  *
139  * @param base UART peripheral base address.
140  * @param uartSdmaHandle UART handle pointer.
141  */
142 void UART_TransferSdmaHandleIRQ(UART_Type *base, void *uartSdmaHandle);
143 /*@}*/
144 
145 #if defined(__cplusplus)
146 }
147 #endif
148 
149 /*! @}*/
150 
151 #endif /* _FSL_UART_SDMA_H_ */
152