00001 /* ---------------------------------------------------------------------------- 00002 * SAM Software Package License 00003 * ---------------------------------------------------------------------------- 00004 * Copyright (c) 2011, Atmel Corporation 00005 * 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions are met: 00010 * 00011 * - Redistributions of source code must retain the above copyright notice, 00012 * this list of conditions and the disclaimer below. 00013 * 00014 * Atmel's name may not be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR 00018 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00019 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 00020 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, 00021 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00022 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00023 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00024 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00025 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 00026 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 * ---------------------------------------------------------------------------- 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 { 00075 /** Pointer to the Buffer. */ 00076 uint8_t *pBuff; 00077 /** Buff size in bytes. */ 00078 uint32_t BuffSize; 00079 /** Dma channel num. */ 00080 uint32_t ChNum; 00081 /** Callback function invoked at the end of transfer. */ 00082 UartdCallback callback; 00083 /** Callback arguments. */ 00084 void *pArgument; 00085 /** flag to indicate the current transfer. */ 00086 volatile uint8_t sempaphore; 00087 /* DMA LLI structure */ 00088 LinkedListDescriporView1 *pLLIview; 00089 /* DMA transfer type */ 00090 eXdmadProgState dmaProgrammingMode; 00091 /* DMA LLI size */ 00092 uint16_t dmaBlockSize; 00093 /* Flag using ring buffer or FiFo*/ 00094 uint8_t dmaRingBuffer; 00095 } UartChannel ; 00096 00097 /** Constant structure associated with UART port. This structure prevents 00098 client applications to have access in the same time. */ 00099 typedef struct 00100 { 00101 /** USART Id as defined in the product datasheet */ 00102 uint8_t uartId ; 00103 /** Pointer to DMA driver */ 00104 sXdmad* pXdmad; 00105 /** Pointer to UART Hardware registers */ 00106 Uart* pUartHw ; 00107 /** Current Uart Rx channel */ 00108 UartChannel *pRxChannel ; 00109 /** Current Uart Tx channel */ 00110 UartChannel *pTxChannel ; 00111 } UartDma; 00112 00113 /*---------------------------------------------------------------------------- 00114 * Exported functions 00115 *----------------------------------------------------------------------------*/ 00116 00117 uint32_t UARTD_Configure( UartDma *pUartd , 00118 uint8_t uartId, 00119 uint32_t uartMode, 00120 uint32_t baud, 00121 uint32_t clk ); 00122 00123 uint32_t UARTD_EnableTxChannels( UartDma *pUartd, UartChannel *pTxCh); 00124 00125 uint32_t UARTD_EnableRxChannels( UartDma *pUartd, UartChannel *pRxCh); 00126 00127 uint32_t UARTD_DisableTxChannels( UartDma *pUartd, UartChannel *pTxCh); 00128 00129 uint32_t UARTD_DisableRxChannels( UartDma *pUartd, UartChannel *pRxCh); 00130 00131 uint32_t UARTD_SendData( UartDma* pUartd ) ; 00132 00133 uint32_t UARTD_RcvData( UartDma *pUartd); 00134 00135 #ifdef __cplusplus 00136 } 00137 #endif 00138 00139 #endif /* #ifndef _UART_DMA_ */