00001 /* ---------------------------------------------------------------------------- */ 00002 /* Atmel Microcontroller Software Support */ 00003 /* SAM Software Package License */ 00004 /* ---------------------------------------------------------------------------- */ 00005 /* Copyright (c) 2015, Atmel Corporation */ 00006 /* */ 00007 /* All rights reserved. */ 00008 /* */ 00009 /* Redistribution and use in source and binary forms, with or without */ 00010 /* modification, are permitted provided that the following condition is met: */ 00011 /* */ 00012 /* - Redistributions of source code must retain the above copyright notice, */ 00013 /* this list of conditions and the disclaimer below. */ 00014 /* */ 00015 /* Atmel's name may not be used to endorse or promote products derived from */ 00016 /* this software without specific prior written permission. */ 00017 /* */ 00018 /* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */ 00019 /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ 00020 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */ 00021 /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */ 00022 /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 00023 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */ 00024 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ 00025 /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */ 00026 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */ 00027 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 00028 /* ---------------------------------------------------------------------------- */ 00029 00030 /** 00031 * \file 00032 * 00033 * Implementation of UART driver, transfer data through DMA. 00034 * 00035 */ 00036 00037 #ifndef _UART_DMA_ 00038 #define _UART_DMA_ 00039 00040 /*---------------------------------------------------------------------------- 00041 * Headers 00042 *----------------------------------------------------------------------------*/ 00043 00044 #include "chip.h" 00045 00046 /*---------------------------------------------------------------------------- 00047 * Definitions 00048 *----------------------------------------------------------------------------*/ 00049 00050 /** An unspecified error has occurred.*/ 00051 #define UARTD_ERROR 1 00052 00053 /** UART driver is currently in use.*/ 00054 #define UARTD_ERROR_LOCK 2 00055 00056 00057 #ifdef __cplusplus 00058 extern "C" { 00059 #endif 00060 00061 /*---------------------------------------------------------------------------- 00062 * Types 00063 *----------------------------------------------------------------------------*/ 00064 00065 /** UART transfer complete callback. */ 00066 typedef void (*UartdCallback)(uint8_t, void *); 00067 00068 /** \brief usart Transfer Request prepared by the application upper layer. 00069 * 00070 * This structure is sent to the UART_Send or UART_Rcv to start the transfer. 00071 * At the end of the transfer, the callback is invoked by the interrupt handler. 00072 */ 00073 typedef struct { 00074 /** Pointer to the Buffer. */ 00075 uint8_t *pBuff; 00076 /** Buff size in bytes. */ 00077 uint32_t BuffSize; 00078 /** Dma channel num. */ 00079 uint32_t ChNum; 00080 /** Callback function invoked at the end of transfer. */ 00081 UartdCallback callback; 00082 /** Callback arguments. */ 00083 void *pArgument; 00084 /** flag to indicate the current transfer. */ 00085 volatile uint8_t sempaphore; 00086 /* DMA LLI structure */ 00087 LinkedListDescriporView1 *pLLIview; 00088 /* DMA transfer type */ 00089 eXdmadProgState dmaProgrammingMode; 00090 /* DMA LLI size */ 00091 uint16_t dmaBlockSize; 00092 /* Flag using ring buffer or FiFo*/ 00093 uint8_t dmaRingBuffer; 00094 } UartChannel; 00095 00096 /** Constant structure associated with UART port. This structure prevents 00097 client applications to have access in the same time. */ 00098 typedef struct { 00099 /** USART Id as defined in the product datasheet */ 00100 uint8_t uartId; 00101 /** Pointer to DMA driver */ 00102 sXdmad *pXdmad; 00103 /** Pointer to UART Hardware registers */ 00104 Uart *pUartHw; 00105 /** Current Uart Rx channel */ 00106 UartChannel *pRxChannel; 00107 /** Current Uart Tx channel */ 00108 UartChannel *pTxChannel; 00109 } UartDma; 00110 00111 /*---------------------------------------------------------------------------- 00112 * Exported functions 00113 *----------------------------------------------------------------------------*/ 00114 00115 uint32_t UARTD_Configure(UartDma *pUartd , 00116 uint8_t uartId, 00117 uint32_t uartMode, 00118 uint32_t baud, 00119 uint32_t clk); 00120 00121 uint32_t UARTD_EnableTxChannels(UartDma *pUartd, UartChannel *pTxCh); 00122 00123 uint32_t UARTD_EnableRxChannels(UartDma *pUartd, UartChannel *pRxCh); 00124 00125 uint32_t UARTD_DisableTxChannels(UartDma *pUartd, UartChannel *pTxCh); 00126 00127 uint32_t UARTD_DisableRxChannels(UartDma *pUartd, UartChannel *pRxCh); 00128 00129 uint32_t UARTD_SendData(UartDma *pUartd); 00130 00131 uint32_t UARTD_RcvData(UartDma *pUartd); 00132 00133 #ifdef __cplusplus 00134 } 00135 #endif 00136 00137 #endif /* #ifndef _UART_DMA_ */