SAM3S8/SD8 Software Package: libraries/libchip_sam3s/include/usart.h Source File

SAM3S8/SD8 Software Package 1.2

# usart.h

Go to the documentation of this file.

    00001 /* ----------------------------------------------------------------------------
    00002  *         ATMEL Microcontroller Software Support
    00003  * ----------------------------------------------------------------------------
    00004  * Copyright (c) 2009, 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 and
    00046  *    USART_WriteBuffer methods.
    00047  * -# Receive data from the USART using the USART_Read and
    00048  *    USART_ReadBuffer functions; the availability of data can be polled
    00049  *    with USART_IsDataAvailable.
    00050  * -# Disable the transmitter and/or the receiver of the USART with
    00051  *    USART_SetTransmitterEnabled and USART_SetReceiverEnabled.
    00052  */
    00053
    00054 #ifndef _USART_
    00055 #define _USART_
    00056
    00057 /*------------------------------------------------------------------------------
    00058  *         Headers
    00059  *------------------------------------------------------------------------------*/
    00060
    00061 #include "chip.h"
    00062
    00063 #include <stdint.h>
    00064
    00065 /*------------------------------------------------------------------------------
    00066  *         Definitions
    00067  *------------------------------------------------------------------------------*/
    00068
    00069 /** \section USART_mode USART modes
    00070  * This section lists several common operating modes for an USART peripheral.
    00071  *
    00072  * \b Modes
    00073  * - USART_MODE_ASYNCHRONOUS
    00074  * - USART_MODE_IRDA
    00075  */
    00076
    00077 /** Basic asynchronous mode, i.e. 8 bits no parity.*/
    00078 #define USART_MODE_ASYNCHRONOUS        (US_MR_CHRL_8_BIT | US_MR_PAR_NO)
    00079
    00080 /** IRDA mode*/
    00081 #define USART_MODE_IRDA                (AT91C_US_USMODE_IRDA | AT91C_US_CHRL_8_BITS | AT91C_US_PAR_NONE | AT91C_US_FILTER)
    00082
    00083 /** SPI mode*/
    00084 #define AT91C_US_USMODE_SPIM     0xE
    00085 #define US_SPI_CPOL_0           (0x0<<16)
    00086 #define US_SPI_CPHA_0            (0x0<<8)
    00087 #define US_SPI_CPOL_1            (0x1<<16)
    00088 #define US_SPI_CPHA_1            (0x1<<8)
    00089 #define US_SPI_BPMODE_0    (US_SPI_CPOL_0|US_SPI_CPHA_1)
    00090 #define US_SPI_BPMODE_1    (US_SPI_CPOL_0|US_SPI_CPHA_0)
    00091 #define US_SPI_BPMODE_2    (US_SPI_CPOL_1|US_SPI_CPHA_1)
    00092 #define US_SPI_BPMODE_3    (US_SPI_CPOL_1|US_SPI_CPHA_0)
    00093
    00094 #ifdef __cplusplus
    00095  extern "C" {
    00096 #endif
    00097
    00098 /*------------------------------------------------------------------------------*/
    00099 /*         Exported functions                                                   */
    00100 /*------------------------------------------------------------------------------*/
    00101
    00102 extern void USART_Configure( Usart *usart, uint32_t mode, uint32_t baudrate, uint32_t masterClock ) ;
    00103 extern uint32_t USART_GetStatus( Usart *usart ) ;
    00104 extern void USART_EnableIt( Usart *usart,uint32_t mode ) ;
    00105 extern void USART_DisableIt( Usart *usart,uint32_t mode ) ;
    00106 extern void USART_SetTransmitterEnabled( Usart *usart, uint8_t enabled ) ;
    00107
    00108 extern void USART_SetReceiverEnabled( Usart *usart, uint8_t enabled ) ;
    00109
    00110 extern void USART_Write( Usart *usart, uint16_t data, volatile uint32_t timeOut ) ;
    00111
    00112 extern uint8_t USART_WriteBuffer( Usart *usart, void *buffer, uint32_t size ) ;
    00113
    00114 extern uint16_t USART_Read( Usart *usart, volatile uint32_t timeOut ) ;
    00115
    00116 extern uint8_t USART_ReadBuffer( Usart *usart, void *buffer, uint32_t size ) ;
    00117
    00118 extern uint8_t USART_IsDataAvailable( Usart *usart ) ;
    00119
    00120 extern void USART_SetIrdaFilter(Usart *pUsart, uint8_t filter);
    00121
    00122 extern void USART_PutChar( Usart *usart, uint8_t c ) ;
    00123
    00124 extern uint32_t USART_IsRxReady( Usart *usart ) ;
    00125
    00126 extern uint8_t USART_GetChar( Usart *usart ) ;
    00127
    00128 #ifdef __cplusplus
    00129 }
    00130 #endif
    00131
    00132 #endif /* #ifndef _USART_ */
    00133

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines