1 /* 2 * Copyright (c) 2015, Freescale Semiconductor, Inc. 3 * Copyright 2016-2017 NXP 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * o Redistributions of source code must retain the above copyright notice, this list 9 * of conditions and the following disclaimer. 10 * 11 * o Redistributions in binary form must reproduce the above copyright notice, this 12 * list of conditions and the following disclaimer in the documentation and/or 13 * other materials provided with the distribution. 14 * 15 * o Neither the name of the copyright holder nor the names of its 16 * contributors may be used to endorse or promote products derived from this 17 * software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 #ifndef _FSL_UART_EDMA_H_ 31 #define _FSL_UART_EDMA_H_ 32 33 #include "fsl_uart.h" 34 #include "fsl_dmamux.h" 35 #include "fsl_edma.h" 36 37 /*! 38 * @addtogroup uart_edma_driver 39 * @{ 40 */ 41 42 /******************************************************************************* 43 * Definitions 44 ******************************************************************************/ 45 46 /* Forward declaration of the handle typedef. */ 47 typedef struct _uart_edma_handle uart_edma_handle_t; 48 49 /*! @brief UART transfer callback function. */ 50 typedef void (*uart_edma_transfer_callback_t)(UART_Type *base, 51 uart_edma_handle_t *handle, 52 status_t status, 53 void *userData); 54 55 /*! 56 * @brief UART eDMA handle 57 */ 58 struct _uart_edma_handle 59 { 60 uart_edma_transfer_callback_t callback; /*!< Callback function. */ 61 void *userData; /*!< UART callback function parameter.*/ 62 size_t rxDataSizeAll; /*!< Size of the data to receive. */ 63 size_t txDataSizeAll; /*!< Size of the data to send out. */ 64 65 edma_handle_t *txEdmaHandle; /*!< The eDMA TX channel used. */ 66 edma_handle_t *rxEdmaHandle; /*!< The eDMA RX channel used. */ 67 68 uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */ 69 70 volatile uint8_t txState; /*!< TX transfer state. */ 71 volatile uint8_t rxState; /*!< RX transfer state */ 72 }; 73 74 /******************************************************************************* 75 * API 76 ******************************************************************************/ 77 78 #if defined(__cplusplus) 79 extern "C" { 80 #endif 81 82 /*! 83 * @name eDMA transactional 84 * @{ 85 */ 86 87 /*! 88 * @brief Initializes the UART handle which is used in transactional functions. 89 * @param base UART peripheral base address. 90 * @param handle Pointer to the uart_edma_handle_t structure. 91 * @param callback UART callback, NULL means no callback. 92 * @param userData User callback function data. 93 * @param rxEdmaHandle User-requested DMA handle for RX DMA transfer. 94 * @param txEdmaHandle User-requested DMA handle for TX DMA transfer. 95 */ 96 void UART_TransferCreateHandleEDMA(UART_Type *base, 97 uart_edma_handle_t *handle, 98 uart_edma_transfer_callback_t callback, 99 void *userData, 100 edma_handle_t *txEdmaHandle, 101 edma_handle_t *rxEdmaHandle); 102 103 /*! 104 * @brief Sends data using eDMA. 105 * 106 * This function sends data using eDMA. This is a non-blocking function, which returns 107 * right away. When all data is sent, the send callback function is called. 108 * 109 * @param base UART peripheral base address. 110 * @param handle UART handle pointer. 111 * @param xfer UART eDMA transfer structure. See #uart_transfer_t. 112 * @retval kStatus_Success if succeeded; otherwise failed. 113 * @retval kStatus_UART_TxBusy Previous transfer ongoing. 114 * @retval kStatus_InvalidArgument Invalid argument. 115 */ 116 status_t UART_SendEDMA(UART_Type *base, uart_edma_handle_t *handle, uart_transfer_t *xfer); 117 118 /*! 119 * @brief Receives data using eDMA. 120 * 121 * This function receives data using eDMA. This is a non-blocking function, which returns 122 * right away. When all data is received, the receive callback function is called. 123 * 124 * @param base UART peripheral base address. 125 * @param handle Pointer to the uart_edma_handle_t structure. 126 * @param xfer UART eDMA transfer structure. See #uart_transfer_t. 127 * @retval kStatus_Success if succeeded; otherwise failed. 128 * @retval kStatus_UART_RxBusy Previous transfer ongoing. 129 * @retval kStatus_InvalidArgument Invalid argument. 130 */ 131 status_t UART_ReceiveEDMA(UART_Type *base, uart_edma_handle_t *handle, uart_transfer_t *xfer); 132 133 /*! 134 * @brief Aborts the sent data using eDMA. 135 * 136 * This function aborts sent data using eDMA. 137 * 138 * @param base UART peripheral base address. 139 * @param handle Pointer to the uart_edma_handle_t structure. 140 */ 141 void UART_TransferAbortSendEDMA(UART_Type *base, uart_edma_handle_t *handle); 142 143 /*! 144 * @brief Aborts the receive data using eDMA. 145 * 146 * This function aborts receive data using eDMA. 147 * 148 * @param base UART peripheral base address. 149 * @param handle Pointer to the uart_edma_handle_t structure. 150 */ 151 void UART_TransferAbortReceiveEDMA(UART_Type *base, uart_edma_handle_t *handle); 152 153 /*! 154 * @brief Gets the number of bytes that have been written to UART TX register. 155 * 156 * This function gets the number of bytes that have been written to UART TX 157 * register by DMA. 158 * 159 * @param base UART peripheral base address. 160 * @param handle UART handle pointer. 161 * @param count Send bytes count. 162 * @retval kStatus_NoTransferInProgress No send in progress. 163 * @retval kStatus_InvalidArgument Parameter is invalid. 164 * @retval kStatus_Success Get successfully through the parameter \p count; 165 */ 166 status_t UART_TransferGetSendCountEDMA(UART_Type *base, uart_edma_handle_t *handle, uint32_t *count); 167 168 /*! 169 * @brief Gets the number of received bytes. 170 * 171 * This function gets the number of received bytes. 172 * 173 * @param base UART peripheral base address. 174 * @param handle UART handle pointer. 175 * @param count Receive bytes count. 176 * @retval kStatus_NoTransferInProgress No receive in progress. 177 * @retval kStatus_InvalidArgument Parameter is invalid. 178 * @retval kStatus_Success Get successfully through the parameter \p count; 179 */ 180 status_t UART_TransferGetReceiveCountEDMA(UART_Type *base, uart_edma_handle_t *handle, uint32_t *count); 181 182 /*@}*/ 183 184 #if defined(__cplusplus) 185 } 186 #endif 187 188 /*! @}*/ 189 190 #endif /* _FSL_UART_EDMA_H_ */ 191