Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

# uart.h

    00001 /*! \file uart.h \brief UART driver for AT91SAM7S. */
    00002 //*****************************************************************************
    00003 //
    00004 // File Name    : 'uart.h'
    00005 // Title        : UART driver for AT91SAM7S
    00006 // Author       : Pascal Stang - Copyright (C) 2004-2006
    00007 // Created      : 4/3/2004
    00008 // Revised      : 7/4/2006
    00009 // Version      : 0.1
    00010 // Target MCU   : Atmel ARM AT91SAM7S Series
    00011 // Editor Tabs  : 4
    00012 //
    00013 /// \ingroup driver_arm_at91
    00014 /// \defgroup uart_at91 UART driver for AT91SAM7S (armlib/arch/at91/uart.c)
    00015 /// \code #include "uart.h" \endcode
    00016 /// \par Overview
    00017 ///     To be written...
    00018 //
    00019 // This code is distributed under the GNU Public License
    00020 //      which can be found at http://www.gnu.org/licenses/gpl.txt
    00021 //
    00022 //*****************************************************************************
    00023 //@{
    00024
    00025 #ifndef ARMLIB_UART_H
    00026 #define ARMLIB_UART_H
    00027
    00028 #include "at91sam7s64.h"
    00029
    00030 #include "global.h"
    00031
    00032 // defines
    00033
    00034 // UART_BAUD calculates a division rate given a baud rate
    00035 // for use with uart0Init() and uart1Init()
    00036 // example: uart0Init(UART_BAUD(115200), UART_8N1);
    00037 //
    00038 // BEWARE: additional code will be generated if 'baud' is not a constant
    00039 #define UART_BAUD(baud) (uint16_t)((F_CPU+baud*8L)/(baud*16))
    00040
    00041 // Definitions for UART mode settings (databits, parity, stopbits)
    00042 #define UART_8N1      (AT91C_US_CHRL_8_BITS | AT91C_US_PAR_NONE | AT91C_US_NBSTOP_1_BIT)
    00043 #define UART_8N2      (AT91C_US_CHRL_8_BITS | AT91C_US_PAR_NONE | AT91C_US_NBSTOP_2_BIT)
    00044 #define UART_7N1      (AT91C_US_CHRL_7_BITS | AT91C_US_PAR_NONE | AT91C_US_NBSTOP_1_BIT)
    00045 #define UART_7N2      (AT91C_US_CHRL_7_BITS | AT91C_US_PAR_NONE | AT91C_US_NBSTOP_2_BIT)
    00046
    00047 #define UART_8E1      (AT91C_US_CHRL_8_BITS | AT91C_US_PAR_EVEN | AT91C_US_NBSTOP_1_BIT)
    00048 #define UART_8E2      (AT91C_US_CHRL_8_BITS | AT91C_US_PAR_EVEN | AT91C_US_NBSTOP_2_BIT)
    00049 #define UART_7E1      (AT91C_US_CHRL_7_BITS | AT91C_US_PAR_EVEN | AT91C_US_NBSTOP_1_BIT)
    00050 #define UART_7E2      (AT91C_US_CHRL_7_BITS | AT91C_US_PAR_EVEN | AT91C_US_NBSTOP_2_BIT)
    00051
    00052 #define UART_8O1      (AT91C_US_CHRL_8_BITS | AT91C_US_PAR_ODD  | AT91C_US_NBSTOP_1_BIT)
    00053 #define UART_8O2      (AT91C_US_CHRL_8_BITS | AT91C_US_PAR_ODD  | AT91C_US_NBSTOP_2_BIT)
    00054 #define UART_7O1      (AT91C_US_CHRL_7_BITS | AT91C_US_PAR_ODD  | AT91C_US_NBSTOP_1_BIT)
    00055 #define UART_7O2      (AT91C_US_CHRL_7_BITS | AT91C_US_PAR_ODD  | AT91C_US_NBSTOP_2_BIT)
    00056
    00057 // functions
    00058
    00059 //! initializes uart
    00060 void uart0Init(uint16_t bauddiv, uint32_t mode);
    00061 void uart1Init(uint16_t bauddiv, uint32_t mode);
    00062 void uart2Init(uint16_t bauddiv, uint32_t mode);
    00063
    00064 //! sends a single byte over the uart
    00065 int uart0SendByte(int data);
    00066 int uart1SendByte(int data);
    00067 int uart2SendByte(int data);
    00068
    00069 //! gets a single byte from the uart
    00070 int uart0GetByte(void);
    00071 int uart1GetByte(void);
    00072 int uart2GetByte(void);
    00073
    00074 #endif
    00075 //@}