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_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 /*! @name Driver version */ 24 /*@{*/ 25 /*! @brief FlexIO UART EDMA driver version. */ 26 #define FSL_FLEXIO_UART_EDMA_DRIVER_VERSION (MAKE_VERSION(2, 4, 1)) 27 /*@}*/ 28 29 /* Forward declaration of the handle typedef. */ 30 typedef struct _flexio_uart_edma_handle flexio_uart_edma_handle_t; 31 32 /*! @brief UART transfer callback function. */ 33 typedef void (*flexio_uart_edma_transfer_callback_t)(FLEXIO_UART_Type *base, 34 flexio_uart_edma_handle_t *handle, 35 status_t status, 36 void *userData); 37 38 /*! 39 * @brief UART eDMA handle 40 */ 41 struct _flexio_uart_edma_handle 42 { 43 flexio_uart_edma_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 edma_handle_t *txEdmaHandle; /*!< The eDMA TX channel used. */ 50 edma_handle_t *rxEdmaHandle; /*!< The eDMA RX channel used. */ 51 52 uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */ 53 54 volatile uint8_t txState; /*!< TX transfer state. */ 55 volatile uint8_t rxState; /*!< RX transfer state */ 56 }; 57 58 /******************************************************************************* 59 * API 60 ******************************************************************************/ 61 62 #if defined(__cplusplus) 63 extern "C" { 64 #endif 65 66 /*! 67 * @name eDMA transactional 68 * @{ 69 */ 70 71 /*! 72 * @brief Initializes the UART handle which is used in transactional functions. 73 * 74 * @param base Pointer to FLEXIO_UART_Type. 75 * @param handle Pointer to flexio_uart_edma_handle_t structure. 76 * @param callback The callback function. 77 * @param userData The parameter of the callback function. 78 * @param rxEdmaHandle User requested DMA handle for RX DMA transfer. 79 * @param txEdmaHandle User requested DMA handle for TX DMA transfer. 80 * @retval kStatus_Success Successfully create the handle. 81 * @retval kStatus_OutOfRange The FlexIO SPI eDMA type/handle table out of range. 82 */ 83 status_t FLEXIO_UART_TransferCreateHandleEDMA(FLEXIO_UART_Type *base, 84 flexio_uart_edma_handle_t *handle, 85 flexio_uart_edma_transfer_callback_t callback, 86 void *userData, 87 edma_handle_t *txEdmaHandle, 88 edma_handle_t *rxEdmaHandle); 89 90 /*! 91 * @brief Sends data using eDMA. 92 * 93 * This function sends data using eDMA. This is a non-blocking function, which returns 94 * right away. When all data is sent out, the send callback function is called. 95 * 96 * @param base Pointer to FLEXIO_UART_Type 97 * @param handle UART handle pointer. 98 * @param xfer UART eDMA transfer structure, see #flexio_uart_transfer_t. 99 * @retval kStatus_Success if succeed, others failed. 100 * @retval kStatus_FLEXIO_UART_TxBusy Previous transfer on going. 101 */ 102 status_t FLEXIO_UART_TransferSendEDMA(FLEXIO_UART_Type *base, 103 flexio_uart_edma_handle_t *handle, 104 flexio_uart_transfer_t *xfer); 105 106 /*! 107 * @brief Receives data using eDMA. 108 * 109 * This function receives data using eDMA. This is a non-blocking function, which returns 110 * right away. When all data is received, the receive callback function is called. 111 * 112 * @param base Pointer to FLEXIO_UART_Type 113 * @param handle Pointer to flexio_uart_edma_handle_t structure 114 * @param xfer UART eDMA transfer structure, see #flexio_uart_transfer_t. 115 * @retval kStatus_Success if succeed, others failed. 116 * @retval kStatus_UART_RxBusy Previous transfer on going. 117 */ 118 status_t FLEXIO_UART_TransferReceiveEDMA(FLEXIO_UART_Type *base, 119 flexio_uart_edma_handle_t *handle, 120 flexio_uart_transfer_t *xfer); 121 122 /*! 123 * @brief Aborts the sent data which using eDMA. 124 * 125 * This function aborts sent data which using eDMA. 126 * 127 * @param base Pointer to FLEXIO_UART_Type 128 * @param handle Pointer to flexio_uart_edma_handle_t structure 129 */ 130 void FLEXIO_UART_TransferAbortSendEDMA(FLEXIO_UART_Type *base, flexio_uart_edma_handle_t *handle); 131 132 /*! 133 * @brief Aborts the receive data which using eDMA. 134 * 135 * This function aborts the receive data which using eDMA. 136 * 137 * @param base Pointer to FLEXIO_UART_Type 138 * @param handle Pointer to flexio_uart_edma_handle_t structure 139 */ 140 void FLEXIO_UART_TransferAbortReceiveEDMA(FLEXIO_UART_Type *base, flexio_uart_edma_handle_t *handle); 141 142 /*! 143 * @brief Gets the number of bytes sent out. 144 * 145 * This function gets the number of bytes sent out. 146 * 147 * @param base Pointer to FLEXIO_UART_Type 148 * @param handle Pointer to flexio_uart_edma_handle_t structure 149 * @param count Number of bytes sent so far by the non-blocking transaction. 150 * @retval kStatus_NoTransferInProgress transfer has finished or no transfer in progress. 151 * @retval kStatus_Success Successfully return the count. 152 */ 153 status_t FLEXIO_UART_TransferGetSendCountEDMA(FLEXIO_UART_Type *base, flexio_uart_edma_handle_t *handle, size_t *count); 154 155 /*! 156 * @brief Gets the number of bytes received. 157 * 158 * This function gets the number of bytes received. 159 * 160 * @param base Pointer to FLEXIO_UART_Type 161 * @param handle Pointer to flexio_uart_edma_handle_t structure 162 * @param count Number of bytes received so far by the non-blocking transaction. 163 * @retval kStatus_NoTransferInProgress transfer has finished or no transfer in progress. 164 * @retval kStatus_Success Successfully return the count. 165 */ 166 status_t FLEXIO_UART_TransferGetReceiveCountEDMA(FLEXIO_UART_Type *base, 167 flexio_uart_edma_handle_t *handle, 168 size_t *count); 169 170 /*@}*/ 171 172 #if defined(__cplusplus) 173 } 174 #endif 175 176 /*! @}*/ 177 178 #endif /* _FSL_UART_EDMA_H_ */ 179