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 #ifndef _FSL_UART_DMA_H_ 9 #define _FSL_UART_DMA_H_ 10 11 #include "fsl_uart.h" 12 #include "fsl_dma.h" 13 14 /*! 15 * @addtogroup uart_dma_driver 16 * @{ 17 */ 18 19 /******************************************************************************* 20 * Definitions 21 ******************************************************************************/ 22 23 /*! @name Driver version */ 24 /*@{*/ 25 /*! @brief UART DMA driver version. */ 26 #define FSL_UART_DMA_DRIVER_VERSION (MAKE_VERSION(2, 5, 0)) 27 /*@}*/ 28 29 /* Forward declaration of the handle typedef. */ 30 typedef struct _uart_dma_handle uart_dma_handle_t; 31 32 /*! @brief UART transfer callback function. */ 33 typedef void (*uart_dma_transfer_callback_t)(UART_Type *base, 34 uart_dma_handle_t *handle, 35 status_t status, 36 void *userData); 37 38 /*! 39 * @brief UART DMA handle 40 */ 41 struct _uart_dma_handle 42 { 43 UART_Type *base; /*!< UART peripheral base address. */ 44 45 uart_dma_transfer_callback_t callback; /*!< Callback function. */ 46 void *userData; /*!< UART callback function parameter.*/ 47 size_t rxDataSizeAll; /*!< Size of the data to receive. */ 48 size_t txDataSizeAll; /*!< Size of the data to send out. */ 49 50 dma_handle_t *txDmaHandle; /*!< The DMA TX channel used. */ 51 dma_handle_t *rxDmaHandle; /*!< The DMA RX channel used. */ 52 53 volatile uint8_t txState; /*!< TX transfer state. */ 54 volatile uint8_t rxState; /*!< RX transfer state */ 55 }; 56 57 /******************************************************************************* 58 * API 59 ******************************************************************************/ 60 61 #if defined(__cplusplus) 62 extern "C" { 63 #endif 64 65 /*! 66 * @name eDMA transactional 67 * @{ 68 */ 69 70 /*! 71 * @brief Initializes the UART handle which is used in transactional functions and sets the callback. 72 * 73 * @param base UART peripheral base address. 74 * @param handle Pointer to the uart_dma_handle_t structure. 75 * @param callback UART callback, NULL means no callback. 76 * @param userData User callback function data. 77 * @param rxDmaHandle User requested DMA handle for the RX DMA transfer. 78 * @param txDmaHandle User requested DMA handle for the TX DMA transfer. 79 */ 80 void UART_TransferCreateHandleDMA(UART_Type *base, 81 uart_dma_handle_t *handle, 82 uart_dma_transfer_callback_t callback, 83 void *userData, 84 dma_handle_t *txDmaHandle, 85 dma_handle_t *rxDmaHandle); 86 87 /*! 88 * @brief Sends data using DMA. 89 * 90 * This function sends data using DMA. This is non-blocking function, which returns 91 * right away. When all data is sent, the send callback function is called. 92 * 93 * @param base UART peripheral base address. 94 * @param handle UART handle pointer. 95 * @param xfer UART DMA transfer structure. See #uart_transfer_t. 96 * @retval kStatus_Success if succeeded; otherwise failed. 97 * @retval kStatus_UART_TxBusy Previous transfer ongoing. 98 * @retval kStatus_InvalidArgument Invalid argument. 99 */ 100 status_t UART_TransferSendDMA(UART_Type *base, uart_dma_handle_t *handle, uart_transfer_t *xfer); 101 102 /*! 103 * @brief Receives data using DMA. 104 * 105 * This function receives data using DMA. This is non-blocking function, which returns 106 * right away. When all data is received, the receive callback function is called. 107 * 108 * @param base UART peripheral base address. 109 * @param handle Pointer to the uart_dma_handle_t structure. 110 * @param xfer UART DMA transfer structure. See #uart_transfer_t. 111 * @retval kStatus_Success if succeeded; otherwise failed. 112 * @retval kStatus_UART_RxBusy Previous transfer on going. 113 * @retval kStatus_InvalidArgument Invalid argument. 114 */ 115 status_t UART_TransferReceiveDMA(UART_Type *base, uart_dma_handle_t *handle, uart_transfer_t *xfer); 116 117 /*! 118 * @brief Aborts the send data using DMA. 119 * 120 * This function aborts the sent data using DMA. 121 * 122 * @param base UART peripheral base address. 123 * @param handle Pointer to uart_dma_handle_t structure. 124 */ 125 void UART_TransferAbortSendDMA(UART_Type *base, uart_dma_handle_t *handle); 126 127 /*! 128 * @brief Aborts the received data using DMA. 129 * 130 * This function abort receive data which using DMA. 131 * 132 * @param base UART peripheral base address. 133 * @param handle Pointer to uart_dma_handle_t structure. 134 */ 135 void UART_TransferAbortReceiveDMA(UART_Type *base, uart_dma_handle_t *handle); 136 137 /*! 138 * @brief Gets the number of bytes written to UART TX register. 139 * 140 * This function gets the number of bytes written to UART TX 141 * register by DMA. 142 * 143 * @param base UART peripheral base address. 144 * @param handle UART handle pointer. 145 * @param count Send bytes count. 146 * @retval kStatus_NoTransferInProgress No send in progress. 147 * @retval kStatus_InvalidArgument Parameter is invalid. 148 * @retval kStatus_Success Get successfully through the parameter \p count; 149 */ 150 status_t UART_TransferGetSendCountDMA(UART_Type *base, uart_dma_handle_t *handle, uint32_t *count); 151 152 /*! 153 * @brief Gets the number of bytes that have been received. 154 * 155 * This function gets the number of bytes that have been received. 156 * 157 * @param base UART peripheral base address. 158 * @param handle UART handle pointer. 159 * @param count Receive bytes count. 160 * @retval kStatus_NoTransferInProgress No receive in progress. 161 * @retval kStatus_InvalidArgument Parameter is invalid. 162 * @retval kStatus_Success Get successfully through the parameter \p count; 163 */ 164 status_t UART_TransferGetReceiveCountDMA(UART_Type *base, uart_dma_handle_t *handle, uint32_t *count); 165 166 /*! 167 * @brief UART DMA IRQ handle function. 168 * 169 * This function handles the UART transmit complete IRQ request and invoke user callback. 170 * 171 * @param base UART peripheral base address. 172 * @param uartDmaHandle UART handle pointer. 173 */ 174 void UART_TransferDMAHandleIRQ(UART_Type *base, void *uartDmaHandle); 175 /*@}*/ 176 177 #if defined(__cplusplus) 178 } 179 #endif 180 181 /*! @}*/ 182 183 #endif /* _FSL_UART_DMA_H_ */ 184