1 /* 2 * Copyright (c) 2015, Freescale Semiconductor, Inc. 3 * Copyright 2016-2022 NXP 4 * All rights reserved. 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 #ifndef _FSL_LPUART_EDMA_H_ 9 #define _FSL_LPUART_EDMA_H_ 10 11 #include "fsl_lpuart.h" 12 #include "fsl_edma.h" 13 14 /*! 15 * @addtogroup lpuart_edma_driver 16 * @{ 17 */ 18 19 /******************************************************************************* 20 * Definitions 21 ******************************************************************************/ 22 23 /*! @name Driver version */ 24 /*@{*/ 25 /*! @brief LPUART EDMA driver version. */ 26 #define FSL_LPUART_EDMA_DRIVER_VERSION (MAKE_VERSION(2, 6, 0)) 27 /*@}*/ 28 29 /* Forward declaration of the handle typedef. */ 30 typedef struct _lpuart_edma_handle lpuart_edma_handle_t; 31 32 /*! @brief LPUART transfer callback function. */ 33 typedef void (*lpuart_edma_transfer_callback_t)(LPUART_Type *base, 34 lpuart_edma_handle_t *handle, 35 status_t status, 36 void *userData); 37 38 /*! 39 * @brief LPUART eDMA handle 40 */ 41 struct _lpuart_edma_handle 42 { 43 lpuart_edma_transfer_callback_t callback; /*!< Callback function. */ 44 void *userData; /*!< LPUART callback function parameter.*/ 45 size_t rxDataSizeAll; /*!< Size of the data to receive. */ 46 size_t txDataSizeAll; /*!< Size of the data to send out. */ 47 48 edma_handle_t *txEdmaHandle; /*!< The eDMA TX channel used. */ 49 edma_handle_t *rxEdmaHandle; /*!< The eDMA RX channel used. */ 50 51 uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */ 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 LPUART handle which is used in transactional functions. 72 * 73 * @note This function disables all LPUART interrupts. 74 * 75 * @param base LPUART peripheral base address. 76 * @param handle Pointer to lpuart_edma_handle_t structure. 77 * @param callback Callback function. 78 * @param userData User data. 79 * @param txEdmaHandle User requested DMA handle for TX DMA transfer. 80 * @param rxEdmaHandle User requested DMA handle for RX DMA transfer. 81 */ 82 void LPUART_TransferCreateHandleEDMA(LPUART_Type *base, 83 lpuart_edma_handle_t *handle, 84 lpuart_edma_transfer_callback_t callback, 85 void *userData, 86 edma_handle_t *txEdmaHandle, 87 edma_handle_t *rxEdmaHandle); 88 89 /*! 90 * @brief Sends data using eDMA. 91 * 92 * This function sends data using eDMA. This is a non-blocking function, which returns 93 * right away. When all data is sent, the send callback function is called. 94 * 95 * @param base LPUART peripheral base address. 96 * @param handle LPUART handle pointer. 97 * @param xfer LPUART eDMA transfer structure. See #lpuart_transfer_t. 98 * @retval kStatus_Success if succeed, others failed. 99 * @retval kStatus_LPUART_TxBusy Previous transfer on going. 100 * @retval kStatus_InvalidArgument Invalid argument. 101 */ 102 status_t LPUART_SendEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, lpuart_transfer_t *xfer); 103 104 /*! 105 * @brief Receives data using eDMA. 106 * 107 * This function receives data using eDMA. 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 LPUART peripheral base address. 111 * @param handle Pointer to lpuart_edma_handle_t structure. 112 * @param xfer LPUART eDMA transfer structure, see #lpuart_transfer_t. 113 * @retval kStatus_Success if succeed, others fail. 114 * @retval kStatus_LPUART_RxBusy Previous transfer ongoing. 115 * @retval kStatus_InvalidArgument Invalid argument. 116 */ 117 status_t LPUART_ReceiveEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, lpuart_transfer_t *xfer); 118 119 /*! 120 * @brief Aborts the sent data using eDMA. 121 * 122 * This function aborts the sent data using eDMA. 123 * 124 * @param base LPUART peripheral base address. 125 * @param handle Pointer to lpuart_edma_handle_t structure. 126 */ 127 void LPUART_TransferAbortSendEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle); 128 129 /*! 130 * @brief Aborts the received data using eDMA. 131 * 132 * This function aborts the received data using eDMA. 133 * 134 * @param base LPUART peripheral base address. 135 * @param handle Pointer to lpuart_edma_handle_t structure. 136 */ 137 void LPUART_TransferAbortReceiveEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle); 138 139 /*! 140 * @brief Gets the number of bytes written to the LPUART TX register. 141 * 142 * This function gets the number of bytes written to the LPUART TX 143 * register by DMA. 144 * 145 * @param base LPUART peripheral base address. 146 * @param handle LPUART handle pointer. 147 * @param count Send bytes count. 148 * @retval kStatus_NoTransferInProgress No send in progress. 149 * @retval kStatus_InvalidArgument Parameter is invalid. 150 * @retval kStatus_Success Get successfully through the parameter \p count; 151 */ 152 status_t LPUART_TransferGetSendCountEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, uint32_t *count); 153 154 /*! 155 * @brief Gets the number of received bytes. 156 * 157 * This function gets the number of received bytes. 158 * 159 * @param base LPUART peripheral base address. 160 * @param handle LPUART handle pointer. 161 * @param count Receive bytes count. 162 * @retval kStatus_NoTransferInProgress No receive in progress. 163 * @retval kStatus_InvalidArgument Parameter is invalid. 164 * @retval kStatus_Success Get successfully through the parameter \p count; 165 */ 166 status_t LPUART_TransferGetReceiveCountEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, uint32_t *count); 167 168 /*! 169 * @brief LPUART eDMA IRQ handle function. 170 * 171 * This function handles the LPUART tx complete IRQ request and invoke user callback. 172 * It is not set to static so that it can be used in user application. 173 * @note This function is used as default IRQ handler by double weak mechanism. 174 * If user's specific IRQ handler is implemented, make sure this function is invoked in the handler. 175 * 176 * @param base LPUART peripheral base address. 177 * @param lpuartEdmaHandle LPUART handle pointer. 178 */ 179 void LPUART_TransferEdmaHandleIRQ(LPUART_Type *base, void *lpuartEdmaHandle); 180 181 /*@}*/ 182 183 #if defined(__cplusplus) 184 } 185 #endif 186 187 /*! @}*/ 188 189 #endif /* _FSL_LPUART_EDMA_H_ */ 190