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_FLEXIO_UART_DMA_H_ 9 #define FSL_FLEXIO_UART_DMA_H_ 10 11 #include "fsl_flexio_uart.h" 12 #include "fsl_dma.h" 13 14 /*! 15 * @addtogroup flexio_dma_uart 16 * @{ 17 */ 18 19 /******************************************************************************* 20 * Definitions 21 ******************************************************************************/ 22 23 /*! @name Driver version */ 24 /*! @{ */ 25 /*! @brief FlexIO UART DMA driver version. */ 26 #define FSL_FLEXIO_UART_DMA_DRIVER_VERSION (MAKE_VERSION(2, 4, 0)) 27 /*! @} */ 28 29 /* Forward declaration of the handle typedef. */ 30 typedef struct _flexio_uart_dma_handle flexio_uart_dma_handle_t; 31 32 /*! @brief UART transfer callback function. */ 33 typedef void (*flexio_uart_dma_transfer_callback_t)(FLEXIO_UART_Type *base, 34 flexio_uart_dma_handle_t *handle, 35 status_t status, 36 void *userData); 37 38 /*! 39 * @brief UART DMA handle 40 */ 41 struct _flexio_uart_dma_handle 42 { 43 flexio_uart_dma_transfer_callback_t callback; /*!< Callback function. */ 44 void *userData; /*!< UART callback function parameter.*/ 45 46 size_t txDataSizeAll; /*!< Total bytes to be sent. */ 47 size_t rxDataSizeAll; /*!< Total bytes to be received. */ 48 49 dma_handle_t *txDmaHandle; /*!< The DMA TX channel used. */ 50 dma_handle_t *rxDmaHandle; /*!< The DMA RX channel used. */ 51 52 volatile uint8_t txState; /*!< TX transfer state. */ 53 volatile uint8_t rxState; /*!< RX transfer state */ 54 }; 55 56 /******************************************************************************* 57 * API 58 ******************************************************************************/ 59 60 #if defined(__cplusplus) 61 extern "C" { 62 #endif 63 64 /*! 65 * @name eDMA transactional 66 * @{ 67 */ 68 69 /*! 70 * @brief Initializes the FLEXIO_UART handle which is used in transactional functions. 71 * 72 * @param base Pointer to FLEXIO_UART_Type structure. 73 * @param handle Pointer to flexio_uart_dma_handle_t structure. 74 * @param callback FlexIO UART callback, NULL means no callback. 75 * @param userData User callback function data. 76 * @param txDmaHandle User requested DMA handle for TX DMA transfer. 77 * @param rxDmaHandle User requested DMA handle for RX DMA transfer. 78 * @retval kStatus_Success Successfully create the handle. 79 * @retval kStatus_OutOfRange The FlexIO UART DMA type/handle table out of range. 80 */ 81 status_t FLEXIO_UART_TransferCreateHandleDMA(FLEXIO_UART_Type *base, 82 flexio_uart_dma_handle_t *handle, 83 flexio_uart_dma_transfer_callback_t callback, 84 void *userData, 85 dma_handle_t *txDmaHandle, 86 dma_handle_t *rxDmaHandle); 87 88 /*! 89 * @brief Sends data using DMA. 90 * 91 * This function send data using DMA. This is non-blocking function, which returns 92 * right away. When all data is sent out, the send callback function is called. 93 * 94 * @param base Pointer to FLEXIO_UART_Type structure 95 * @param handle Pointer to flexio_uart_dma_handle_t structure 96 * @param xfer FLEXIO_UART DMA transfer structure, see #flexio_uart_transfer_t. 97 * @retval kStatus_Success if succeed, others failed. 98 * @retval kStatus_FLEXIO_UART_TxBusy Previous transfer on going. 99 */ 100 status_t FLEXIO_UART_TransferSendDMA(FLEXIO_UART_Type *base, 101 flexio_uart_dma_handle_t *handle, 102 flexio_uart_transfer_t *xfer); 103 104 /*! 105 * @brief Receives data using DMA. 106 * 107 * This function receives data using DMA. This is non-blocking function, which returns 108 * right away. When all data is received, the receive callback function is called. 109 * 110 * @param base Pointer to FLEXIO_UART_Type structure 111 * @param handle Pointer to flexio_uart_dma_handle_t structure 112 * @param xfer FLEXIO_UART DMA transfer structure, see #flexio_uart_transfer_t. 113 * @retval kStatus_Success if succeed, others failed. 114 * @retval kStatus_FLEXIO_UART_RxBusy Previous transfer on going. 115 */ 116 status_t FLEXIO_UART_TransferReceiveDMA(FLEXIO_UART_Type *base, 117 flexio_uart_dma_handle_t *handle, 118 flexio_uart_transfer_t *xfer); 119 120 /*! 121 * @brief Aborts the sent data which using DMA. 122 * 123 * This function aborts the sent data which using DMA. 124 * 125 * @param base Pointer to FLEXIO_UART_Type structure 126 * @param handle Pointer to flexio_uart_dma_handle_t structure 127 */ 128 void FLEXIO_UART_TransferAbortSendDMA(FLEXIO_UART_Type *base, flexio_uart_dma_handle_t *handle); 129 130 /*! 131 * @brief Aborts the receive data which using DMA. 132 * 133 * This function aborts the receive data which using DMA. 134 * 135 * @param base Pointer to FLEXIO_UART_Type structure 136 * @param handle Pointer to flexio_uart_dma_handle_t structure 137 */ 138 void FLEXIO_UART_TransferAbortReceiveDMA(FLEXIO_UART_Type *base, flexio_uart_dma_handle_t *handle); 139 140 /*! 141 * @brief Gets the number of bytes sent out. 142 * 143 * This function gets the number of bytes sent out. 144 * 145 * @param base Pointer to FLEXIO_UART_Type structure 146 * @param handle Pointer to flexio_uart_dma_handle_t structure 147 * @param count Number of bytes sent so far by the non-blocking transaction. 148 * @retval kStatus_NoTransferInProgress transfer has finished or no transfer in progress. 149 * @retval kStatus_Success Successfully return the count. 150 */ 151 status_t FLEXIO_UART_TransferGetSendCountDMA(FLEXIO_UART_Type *base, flexio_uart_dma_handle_t *handle, size_t *count); 152 153 /*! 154 * @brief Gets the number of bytes received. 155 * 156 * This function gets the number of bytes received. 157 * 158 * @param base Pointer to FLEXIO_UART_Type structure 159 * @param handle Pointer to flexio_uart_dma_handle_t structure 160 * @param count Number of bytes received so far by the non-blocking transaction. 161 * @retval kStatus_NoTransferInProgress transfer has finished or no transfer in progress. 162 * @retval kStatus_Success Successfully return the count. 163 */ 164 status_t FLEXIO_UART_TransferGetReceiveCountDMA(FLEXIO_UART_Type *base, 165 flexio_uart_dma_handle_t *handle, 166 size_t *count); 167 168 /*! @} */ 169 170 #if defined(__cplusplus) 171 } 172 #endif 173 174 /*! @}*/ 175 176 #endif /* FSL_UART_DMA_H_ */ 177