SAMV71 Xplained Ultra Software Package 1.3

usart.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  * \par Purpose
00034  *
00035  * This module provides several definitions and methods for using an USART
00036  * peripheral.
00037  *
00038  * \par Usage
00039  *
00040  * -# Enable the USART peripheral clock in the PMC.
00041  * -# Enable the required USART PIOs (see pio.h).
00042  * -# Configure the UART by calling USART_Configure.
00043  * -# Enable the transmitter and/or the receiver of the USART using
00044  *    USART_SetTransmitterEnabled and USART_SetReceiverEnabled.
00045  * -# Send data through the USART using the USART_Write methods.
00046  * -# Receive data from the USART using the USART_Read functions; the 
00047  * availability of data can be polled
00048  *    with USART_IsDataAvailable.
00049  * -# Disable the transmitter and/or the receiver of the USART with
00050  *    USART_SetTransmitterEnabled and USART_SetReceiverEnabled.
00051  */
00052 
00053 #ifndef _USART_
00054 #define _USART_
00055 
00056 /*------------------------------------------------------------------------------
00057  *         Headers
00058  *----------------------------------------------------------------------------*/
00059 
00060 #include "chip.h"
00061 
00062 #include <stdint.h>
00063 
00064 /*------------------------------------------------------------------------------
00065  *         Definitions
00066  *----------------------------------------------------------------------------*/
00067 
00068 /** \section USART_mode USART modes
00069  * This section lists several common operating modes for an USART peripheral.
00070  *
00071  * \b Modes
00072  * - USART_MODE_ASYNCHRONOUS
00073  * - USART_MODE_IRDA
00074  */
00075 
00076 /** Basic asynchronous mode, i.e. 8 bits no parity.*/
00077 #define USART_MODE_ASYNCHRONOUS        (US_MR_CHRL_8_BIT | US_MR_PAR_NO)
00078 
00079 #define MAX_RX_TIMEOUT          131071
00080 
00081 /** IRDA mode*/
00082 #define USART_MODE_IRDA \
00083     (US_MR_USART_MODE_IRDA | US_MR_CHRL_8_BIT | US_MR_PAR_NO | US_MR_FILTER)
00084 
00085 /** SPI mode*/
00086 #define AT91C_US_USMODE_SPIM     0xE
00087 #define US_SPI_CPOL_0           (0x0<<16)
00088 #define US_SPI_CPHA_0            (0x0<<8)
00089 #define US_SPI_CPOL_1            (0x1<<16)
00090 #define US_SPI_CPHA_1            (0x1<<8)
00091 #define US_SPI_BPMODE_0    (US_SPI_CPOL_0|US_SPI_CPHA_1)
00092 #define US_SPI_BPMODE_1    (US_SPI_CPOL_0|US_SPI_CPHA_0)
00093 #define US_SPI_BPMODE_2    (US_SPI_CPOL_1|US_SPI_CPHA_1)
00094 #define US_SPI_BPMODE_3    (US_SPI_CPOL_1|US_SPI_CPHA_0)
00095 
00096 #ifdef __cplusplus
00097  extern "C" {
00098 #endif
00099 
00100 /*------------------------------------------------------------------------------*/
00101 /*         Exported functions                                                   */
00102 /*------------------------------------------------------------------------------*/
00103 
00104    
00105 void USART_Configure( Usart *pUsart, uint32_t mode, uint32_t baudrate,
00106                     uint32_t masterClock ) ;
00107 
00108 void USART_SetBaudrate(Usart *pUsart,  uint8_t OverSamp, uint32_t baudrate,
00109                     uint32_t masterClock);
00110 
00111 uint32_t USART_GetStatus( Usart *usart ) ;
00112 
00113 
00114 void USART_ResetRx(Usart *pUsart);
00115 
00116 void USART_ResetTx(Usart *pUsart);
00117 
00118 void USART_EnableTx(Usart *pUsart);
00119 
00120 void USART_EnableRx(Usart *pUsart);
00121 
00122 void USART_DisableRx(Usart *pUsart);
00123 
00124 void USART_DisableTx(Usart *pUsart);
00125 
00126 void USART_EnableIt( Usart *usart,uint32_t mode ) ;
00127 
00128 void USART_DisableIt( Usart *usart,uint32_t mode ) ;
00129 
00130 uint32_t USART_GetItMask( Usart * usart ) ;
00131 
00132 void USART_SetTransmitterEnabled( Usart *usart, uint8_t enabled ) ;
00133 
00134 void USART_SetReceiverEnabled( Usart *usart, uint8_t enabled ) ;
00135 
00136 void USART_SetRTSEnabled(Usart *usart, uint8_t enabled);
00137 
00138 void USART_Write( Usart *usart, uint16_t data, volatile uint32_t timeOut ) ;
00139 
00140 uint16_t USART_Read( Usart *usart, volatile uint32_t timeOut ) ;
00141 
00142 uint8_t USART_IsDataAvailable( Usart *usart ) ;
00143 
00144 void USART_SetIrdaFilter(Usart *pUsart, uint8_t filter);
00145 
00146 void USART_PutChar( Usart *usart, uint8_t c ) ;
00147 
00148 uint32_t USART_IsRxReady( Usart *usart ) ;
00149 
00150 uint8_t USART_GetChar( Usart *usart ) ;
00151 
00152 void USART_EnableRecvTimeOut(Usart *usart, uint32_t timeout);
00153 
00154 void USART_EnableTxTimeGaurd(Usart *pUsart, uint32_t TimeGaurd);
00155 
00156 void USART_AcknowledgeRxTimeOut(Usart *usart, uint8_t Periodic);
00157 
00158 
00159 #ifdef __cplusplus
00160 }
00161 #endif
00162 
00163 #endif /* #ifndef _USART_ */
00164 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines