SAMV71 Xplained Ultra Software Package 1.5

usart_dma.h

Go to the documentation of this file.
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 USART driver, transfer data through DMA.
00034  *
00035  */
00036 
00037 #ifndef _USART_DMA_H_
00038 #define _USART_DMA_H_
00039 
00040 /*----------------------------------------------------------------------------
00041  *        Headers
00042  *----------------------------------------------------------------------------*/
00043 
00044 #include "chip.h"
00045 
00046 /*----------------------------------------------------------------------------
00047  *        Definitions
00048  *----------------------------------------------------------------------------*/
00049 
00050 /** An unspecified error has occurred.*/
00051 #define USARTD_ERROR          1
00052 
00053 /** USART driver is currently in use.*/
00054 #define USARTD_ERROR_LOCK     2
00055 
00056 
00057 #ifdef __cplusplus
00058 extern "C" {
00059 #endif
00060 
00061 /*----------------------------------------------------------------------------
00062  *        Types
00063  *----------------------------------------------------------------------------*/
00064 
00065 /** USART transfer complete callback. */
00066 typedef void (*UsartdCallback)(uint8_t, void *);
00067 
00068 /** \brief usart Transfer Request prepared by the application upper layer.
00069  *
00070  * This structure is sent to the USART_Send or USART_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     uint8_t ChNum;
00080     /** Callback function invoked at the end of transfer. */
00081     UsartdCallback callback;
00082     /** Callback arguments. */
00083     void *pArgument;
00084     /** flag to indicate the current transfer progress */
00085     volatile uint8_t dmaProgress;
00086     /* DMA LLI structure */
00087     LinkedListDescriporView1    *pLLIview;
00088     /* DMA transfer type */
00089     eXdmadProgState dmaProgrammingMode;
00090     /* DMA LLI size or num of micro block*/
00091     uint16_t dmaBlockSize;
00092     /* Flag using ring buffer or FiFo*/
00093     uint8_t dmaRingBuffer;
00094 } UsartChannel;
00095 
00096 /** Constant structure associated with USART 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 usartId;
00101     /** Pointer to USART Hardware registers */
00102     Usart *pUsartHw;
00103     /** Current Usart Rx channel */
00104     UsartChannel *pRxChannel;
00105     /** Current Usart Tx channel */
00106     UsartChannel *pTxChannel;
00107     /** Pointer to DMA driver */
00108     sXdmad *pXdmad;
00109 } UsartDma;
00110 
00111 /*----------------------------------------------------------------------------
00112  *        Exported functions
00113  *----------------------------------------------------------------------------*/
00114 
00115 uint32_t USARTD_Configure(UsartDma *pUsartd ,
00116                            uint8_t USARTId,
00117                            uint32_t UsartMode,
00118                            uint32_t BaudRate,
00119                            uint32_t UsartClk);
00120 
00121 uint32_t USARTD_EnableTxChannels(UsartDma *pUsartd, UsartChannel *pTxCh);
00122 
00123 uint32_t USARTD_EnableRxChannels(UsartDma *pUsartd, UsartChannel *pRxCh);
00124 
00125 uint32_t USARTD_DisableTxChannels(UsartDma *pUsartd, UsartChannel *pTxCh);
00126 
00127 uint32_t USARTD_DisableRxChannels(UsartDma *pUsartd, UsartChannel *pTxCh);
00128 
00129 uint32_t USARTD_SendData(UsartDma *pUsartd);
00130 
00131 uint32_t USARTD_RcvData(UsartDma *pUsartd);
00132 
00133 #ifdef __cplusplus
00134 }
00135 #endif
00136 
00137 #endif /* #ifndef _USART_DMA_ */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines