1 /* 2 * Copyright (c) 2015, Freescale Semiconductor, Inc. 3 * Copyright 2016-2017 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 /* Forward declaration of the handle typedef. */ 24 typedef struct _lpuart_edma_handle lpuart_edma_handle_t; 25 26 /*! @brief LPUART transfer callback function. */ 27 typedef void (*lpuart_edma_transfer_callback_t)(LPUART_Type *base, 28 lpuart_edma_handle_t *handle, 29 status_t status, 30 void *userData); 31 32 /*! 33 * @brief LPUART eDMA handle 34 */ 35 struct _lpuart_edma_handle 36 { 37 lpuart_edma_transfer_callback_t callback; /*!< Callback function. */ 38 void *userData; /*!< LPUART callback function parameter.*/ 39 size_t rxDataSizeAll; /*!< Size of the data to receive. */ 40 size_t txDataSizeAll; /*!< Size of the data to send out. */ 41 42 edma_handle_t *txEdmaHandle; /*!< The eDMA TX channel used. */ 43 edma_handle_t *rxEdmaHandle; /*!< The eDMA RX channel used. */ 44 45 uint8_t nbytes; /*!< eDMA minor byte transfer count initially configured. */ 46 47 volatile uint8_t txState; /*!< TX transfer state. */ 48 volatile uint8_t rxState; /*!< RX transfer state */ 49 }; 50 51 /******************************************************************************* 52 * API 53 ******************************************************************************/ 54 55 #if defined(__cplusplus) 56 extern "C" { 57 #endif 58 59 /*! 60 * @name eDMA transactional 61 * @{ 62 */ 63 64 /*! 65 * @brief Initializes the LPUART handle which is used in transactional functions. 66 * @param base LPUART peripheral base address. 67 * @param handle Pointer to lpuart_edma_handle_t structure. 68 * @param callback Callback function. 69 * @param userData User data. 70 * @param txEdmaHandle User requested DMA handle for TX DMA transfer. 71 * @param rxEdmaHandle User requested DMA handle for RX DMA transfer. 72 */ 73 void LPUART_TransferCreateHandleEDMA(LPUART_Type *base, 74 lpuart_edma_handle_t *handle, 75 lpuart_edma_transfer_callback_t callback, 76 void *userData, 77 edma_handle_t *txEdmaHandle, 78 edma_handle_t *rxEdmaHandle); 79 80 /*! 81 * @brief Sends data using eDMA. 82 * 83 * This function sends data using eDMA. This is a non-blocking function, which returns 84 * right away. When all data is sent, the send callback function is called. 85 * 86 * @param base LPUART peripheral base address. 87 * @param handle LPUART handle pointer. 88 * @param xfer LPUART eDMA transfer structure. See #lpuart_transfer_t. 89 * @retval kStatus_Success if succeed, others failed. 90 * @retval kStatus_LPUART_TxBusy Previous transfer on going. 91 * @retval kStatus_InvalidArgument Invalid argument. 92 */ 93 status_t LPUART_SendEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, lpuart_transfer_t *xfer); 94 95 /*! 96 * @brief Receives data using eDMA. 97 * 98 * This function receives data using eDMA. This is non-blocking function, which returns 99 * right away. When all data is received, the receive callback function is called. 100 * 101 * @param base LPUART peripheral base address. 102 * @param handle Pointer to lpuart_edma_handle_t structure. 103 * @param xfer LPUART eDMA transfer structure, see #lpuart_transfer_t. 104 * @retval kStatus_Success if succeed, others fail. 105 * @retval kStatus_LPUART_RxBusy Previous transfer ongoing. 106 * @retval kStatus_InvalidArgument Invalid argument. 107 */ 108 status_t LPUART_ReceiveEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, lpuart_transfer_t *xfer); 109 110 /*! 111 * @brief Aborts the sent data using eDMA. 112 * 113 * This function aborts the sent data using eDMA. 114 * 115 * @param base LPUART peripheral base address. 116 * @param handle Pointer to lpuart_edma_handle_t structure. 117 */ 118 void LPUART_TransferAbortSendEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle); 119 120 /*! 121 * @brief Aborts the received data using eDMA. 122 * 123 * This function aborts the received data using eDMA. 124 * 125 * @param base LPUART peripheral base address. 126 * @param handle Pointer to lpuart_edma_handle_t structure. 127 */ 128 void LPUART_TransferAbortReceiveEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle); 129 130 /*! 131 * @brief Gets the number of bytes written to the LPUART TX register. 132 * 133 * This function gets the number of bytes written to the LPUART TX 134 * register by DMA. 135 * 136 * @param base LPUART peripheral base address. 137 * @param handle LPUART handle pointer. 138 * @param count Send bytes count. 139 * @retval kStatus_NoTransferInProgress No send in progress. 140 * @retval kStatus_InvalidArgument Parameter is invalid. 141 * @retval kStatus_Success Get successfully through the parameter \p count; 142 */ 143 status_t LPUART_TransferGetSendCountEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, uint32_t *count); 144 145 /*! 146 * @brief Gets the number of received bytes. 147 * 148 * This function gets the number of received bytes. 149 * 150 * @param base LPUART peripheral base address. 151 * @param handle LPUART handle pointer. 152 * @param count Receive bytes count. 153 * @retval kStatus_NoTransferInProgress No receive in progress. 154 * @retval kStatus_InvalidArgument Parameter is invalid. 155 * @retval kStatus_Success Get successfully through the parameter \p count; 156 */ 157 status_t LPUART_TransferGetReceiveCountEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, uint32_t *count); 158 159 /*@}*/ 160 161 #if defined(__cplusplus) 162 } 163 #endif 164 165 /*! @}*/ 166 167 #endif /* _FSL_LPUART_EDMA_H_ */ 168