SAMV71 Xplained Ultra Software Package 1.3

usart_dma.h

Go to the documentation of this file.
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 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 {
00075     /** Pointer to the Buffer. */
00076     uint8_t *pBuff;
00077     /** Buff size in bytes. */
00078     uint32_t BuffSize;
00079     /** Dma channel num. */
00080     uint8_t ChNum;
00081     /** Callback function invoked at the end of transfer. */
00082     UsartdCallback callback;
00083     /** Callback arguments. */
00084     void *pArgument;
00085     /** flag to indicate the current transfer progress */
00086     volatile uint8_t dmaProgress;   
00087     /* DMA LLI structure */
00088     LinkedListDescriporView1    *pLLIview;
00089      /* DMA transfer type */
00090     eXdmadProgState dmaProgrammingMode;
00091     /* DMA LLI size or num of micro block*/
00092     uint16_t dmaBlockSize;
00093     /* Flag using ring buffer or FiFo*/
00094     uint8_t dmaRingBuffer;
00095 } UsartChannel ;
00096 
00097 /** Constant structure associated with USART 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 usartId ;
00103     /** Pointer to USART Hardware registers */
00104     Usart* pUsartHw ;    
00105     /** Current Usart Rx channel */
00106     UsartChannel *pRxChannel ;
00107     /** Current Usart Tx channel */
00108     UsartChannel *pTxChannel ;
00109     /** Pointer to DMA driver */
00110     sXdmad* pXdmad;
00111 } UsartDma;
00112 
00113 /*----------------------------------------------------------------------------
00114  *        Exported functions
00115  *----------------------------------------------------------------------------*/
00116 
00117 uint32_t USARTD_Configure( UsartDma *pUsartd ,
00118                                  uint8_t USARTId,
00119                                  uint32_t UsartMode,
00120                                  uint32_t BaudRate,
00121                                  uint32_t UsartClk);
00122 
00123 uint32_t USARTD_EnableTxChannels( UsartDma *pUsartd, UsartChannel *pTxCh);
00124 
00125 uint32_t USARTD_EnableRxChannels( UsartDma *pUsartd, UsartChannel *pRxCh);
00126 
00127 uint32_t USARTD_DisableTxChannels( UsartDma *pUsartd, UsartChannel *pTxCh);
00128 
00129 uint32_t USARTD_DisableRxChannels( UsartDma *pUsartd, UsartChannel *pTxCh);
00130 
00131 uint32_t USARTD_SendData( UsartDma* pUsartd ) ;
00132 
00133 uint32_t USARTD_RcvData( UsartDma *pUsartd);
00134 
00135 #ifdef __cplusplus
00136 }
00137 #endif
00138 
00139 #endif /* #ifndef _USART_DMA_ */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines