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_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, 5, 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 * @param base LPUART peripheral base address. 73 * @param handle Pointer to lpuart_edma_handle_t structure. 74 * @param callback Callback function. 75 * @param userData User data. 76 * @param txEdmaHandle User requested DMA handle for TX DMA transfer. 77 * @param rxEdmaHandle User requested DMA handle for RX DMA transfer. 78 */ 79 void LPUART_TransferCreateHandleEDMA(LPUART_Type *base, 80 lpuart_edma_handle_t *handle, 81 lpuart_edma_transfer_callback_t callback, 82 void *userData, 83 edma_handle_t *txEdmaHandle, 84 edma_handle_t *rxEdmaHandle); 85 86 /*! 87 * @brief Sends data using eDMA. 88 * 89 * This function sends data using eDMA. This is a non-blocking function, which returns 90 * right away. When all data is sent, the send callback function is called. 91 * 92 * @param base LPUART peripheral base address. 93 * @param handle LPUART handle pointer. 94 * @param xfer LPUART eDMA transfer structure. See #lpuart_transfer_t. 95 * @retval kStatus_Success if succeed, others failed. 96 * @retval kStatus_LPUART_TxBusy Previous transfer on going. 97 * @retval kStatus_InvalidArgument Invalid argument. 98 */ 99 status_t LPUART_SendEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, lpuart_transfer_t *xfer); 100 101 /*! 102 * @brief Receives data using eDMA. 103 * 104 * This function receives data using eDMA. This is non-blocking function, which returns 105 * right away. When all data is received, the receive callback function is called. 106 * 107 * @param base LPUART peripheral base address. 108 * @param handle Pointer to lpuart_edma_handle_t structure. 109 * @param xfer LPUART eDMA transfer structure, see #lpuart_transfer_t. 110 * @retval kStatus_Success if succeed, others fail. 111 * @retval kStatus_LPUART_RxBusy Previous transfer ongoing. 112 * @retval kStatus_InvalidArgument Invalid argument. 113 */ 114 status_t LPUART_ReceiveEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, lpuart_transfer_t *xfer); 115 116 /*! 117 * @brief Aborts the sent data using eDMA. 118 * 119 * This function aborts the sent data using eDMA. 120 * 121 * @param base LPUART peripheral base address. 122 * @param handle Pointer to lpuart_edma_handle_t structure. 123 */ 124 void LPUART_TransferAbortSendEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle); 125 126 /*! 127 * @brief Aborts the received data using eDMA. 128 * 129 * This function aborts the received data using eDMA. 130 * 131 * @param base LPUART peripheral base address. 132 * @param handle Pointer to lpuart_edma_handle_t structure. 133 */ 134 void LPUART_TransferAbortReceiveEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle); 135 136 /*! 137 * @brief Gets the number of bytes written to the LPUART TX register. 138 * 139 * This function gets the number of bytes written to the LPUART TX 140 * register by DMA. 141 * 142 * @param base LPUART peripheral base address. 143 * @param handle LPUART handle pointer. 144 * @param count Send bytes count. 145 * @retval kStatus_NoTransferInProgress No send in progress. 146 * @retval kStatus_InvalidArgument Parameter is invalid. 147 * @retval kStatus_Success Get successfully through the parameter \p count; 148 */ 149 status_t LPUART_TransferGetSendCountEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, uint32_t *count); 150 151 /*! 152 * @brief Gets the number of received bytes. 153 * 154 * This function gets the number of received bytes. 155 * 156 * @param base LPUART peripheral base address. 157 * @param handle LPUART handle pointer. 158 * @param count Receive bytes count. 159 * @retval kStatus_NoTransferInProgress No receive in progress. 160 * @retval kStatus_InvalidArgument Parameter is invalid. 161 * @retval kStatus_Success Get successfully through the parameter \p count; 162 */ 163 status_t LPUART_TransferGetReceiveCountEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, uint32_t *count); 164 165 /*! 166 * @brief LPUART eDMA IRQ handle function. 167 * 168 * This function handles the LPUART tx complete IRQ request and invoke user callback. 169 * It is not set to static so that it can be used in user application. 170 * 171 * @param base LPUART peripheral base address. 172 * @param lpuartEdmaHandle LPUART handle pointer. 173 */ 174 void LPUART_TransferEdmaHandleIRQ(LPUART_Type *base, void *lpuartEdmaHandle); 175 176 /*@}*/ 177 178 #if defined(__cplusplus) 179 } 180 #endif 181 182 /*! @}*/ 183 184 #endif /* _FSL_LPUART_EDMA_H_ */ 185