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_LPSCI_DMA_H_ 31 #define _FSL_LPSCI_DMA_H_ 32 33 #include "fsl_lpsci.h" 34 #include "fsl_dmamux.h" 35 #include "fsl_dma.h" 36 37 /*! 38 * @addtogroup lpsci_dma_driver 39 * @{ 40 */ 41 42 43 /******************************************************************************* 44 * Definitions 45 ******************************************************************************/ 46 47 /* Forward declaration of the handle typedef. */ 48 typedef struct _lpsci_dma_handle lpsci_dma_handle_t; 49 50 /*! @brief LPSCI transfer callback function. */ 51 typedef void (*lpsci_dma_transfer_callback_t)(UART0_Type *base, 52 lpsci_dma_handle_t *handle, 53 status_t status, 54 void *userData); 55 56 /*! 57 * @brief LPSCI DMA handle 58 */ 59 struct _lpsci_dma_handle 60 { 61 UART0_Type *base; /*!< LPSCI peripheral base address. */ 62 63 lpsci_dma_transfer_callback_t callback; /*!< Callback function. */ 64 void *userData; /*!< UART callback function parameter.*/ 65 size_t rxDataSizeAll; /*!< Size of the data to receive. */ 66 size_t txDataSizeAll; /*!< Size of the data to send out. */ 67 68 dma_handle_t *txDmaHandle; /*!< The DMA TX channel used. */ 69 dma_handle_t *rxDmaHandle; /*!< The DMA RX channel used. */ 70 71 volatile uint8_t txState; /*!< TX transfer state. */ 72 volatile uint8_t rxState; /*!< RX transfer state */ 73 }; 74 75 /******************************************************************************* 76 * API 77 ******************************************************************************/ 78 79 #if defined(__cplusplus) 80 extern "C" { 81 #endif 82 83 /*! 84 * @name eDMA transactional 85 * @{ 86 */ 87 88 /*! 89 * @brief Initializes the LPSCI handle which is used in transactional functions. 90 * @param handle Pointer to lpsci_dma_handle_t structure 91 * @param base LPSCI peripheral base address 92 * @param rxDmaHandle User requested DMA handle for RX DMA transfer 93 * @param txDmaHandle User requested DMA handle for TX DMA transfer 94 */ 95 void LPSCI_TransferCreateHandleDMA(UART0_Type *base, 96 lpsci_dma_handle_t *handle, 97 lpsci_dma_transfer_callback_t callback, 98 void *userData, 99 dma_handle_t *txDmaHandle, 100 dma_handle_t *rxDmaHandle); 101 102 /*! 103 * @brief Sends data using DMA. 104 * 105 * This function sends data using DMA. This is a non-blocking function, which returns 106 * immediately. When all data is sent, the send callback function is called. 107 * 108 * @param handle LPSCI handle pointer. 109 * @param xfer LPSCI DMA transfer structure, see #lpsci_transfer_t. 110 * @retval kStatus_Success if successful, others failed. 111 * @retval kStatus_LPSCI_TxBusy Previous transfer on going. 112 * @retval kStatus_InvalidArgument Invalid argument. 113 */ 114 status_t LPSCI_TransferSendDMA(UART0_Type *base, lpsci_dma_handle_t *handle, lpsci_transfer_t *xfer); 115 116 /*! 117 * @brief Receives data using DMA. 118 * 119 * This function receives data using DMA. This is a non-blocking function, which returns 120 * immediately. When all data is received, the receive callback function is called. 121 * 122 * @param handle Pointer to lpsci_dma_handle_t structure 123 * @param xfer LPSCI DMA transfer structure, see #lpsci_transfer_t. 124 * @retval kStatus_Success if successful, others failed. 125 * @retval kStatus_LPSCI_RxBusy Previous transfer on going. 126 * @retval kStatus_InvalidArgument Invalid argument. 127 */ 128 status_t LPSCI_TransferReceiveDMA(UART0_Type *base, lpsci_dma_handle_t *handle, lpsci_transfer_t *xfer); 129 130 /*! 131 * @brief Aborts the sent data using DMA. 132 * 133 * This function aborts the sent data using DMA. 134 * 135 * @param handle Pointer to lpsci_dma_handle_t structure. 136 */ 137 void LPSCI_TransferAbortSendDMA(UART0_Type *base, lpsci_dma_handle_t *handle); 138 139 /*! 140 * @brief Aborts the receive data using DMA. 141 * 142 * This function aborts the receive data using DMA. 143 * 144 * @param handle Pointer to lpsci_dma_handle_t structure. 145 */ 146 void LPSCI_TransferAbortReceiveDMA(UART0_Type *base, lpsci_dma_handle_t *handle); 147 148 /*! 149 * @brief Gets the number of bytes written to the LPSCI TX register. 150 * 151 * This function gets the number of bytes that have been written to the LPSCI TX 152 * register by DMA. 153 * 154 * @param base LPSCI peripheral base address. 155 * @param handle LPSCI handle pointer. 156 * @param count Send bytes count. 157 * @retval kStatus_NoTransferInProgress No send in progress. 158 * @retval kStatus_InvalidArgument Parameter is invalid. 159 * @retval kStatus_Success Get successfully through the parameter \p count; 160 */ 161 status_t LPSCI_TransferGetSendCountDMA(UART0_Type *base, lpsci_dma_handle_t *handle, uint32_t *count); 162 163 /*! 164 * @brief Gets the number of bytes that have been received. 165 * 166 * This function gets the number of bytes that have been received. 167 * 168 * @param base LPSCI peripheral base address. 169 * @param handle LPSCI handle pointer. 170 * @param count Receive bytes count. 171 * @retval kStatus_NoTransferInProgress No receive in progress. 172 * @retval kStatus_InvalidArgument Parameter is invalid. 173 * @retval kStatus_Success Get successfully through the parameter \p count; 174 */ 175 status_t LPSCI_TransferGetReceiveCountDMA(UART0_Type *base, lpsci_dma_handle_t *handle, uint32_t *count); 176 177 /*@}*/ 178 179 #if defined(__cplusplus) 180 } 181 #endif 182 183 /*! @}*/ 184 185 #endif /* _FSL_LPSCI_DMA_H_ */ 186