GPIB_AVR
uart.h
Go to the documentation of this file.
00001 #ifndef UART_H
00002 #define UART_H
00003 /************************************************************************
00004 Title:    Interrupt UART library with receive/transmit circular buffers
00005 Author:   Peter Fleury <pfleury@gmx.ch>   http://jump.to/fleury
00006 File:     $Id: uart.h,v 1.8.2.1 2007/07/01 11:14:38 peter Exp $
00007 Software: AVR-GCC 4.1, AVR Libc 1.4
00008 Hardware: any AVR with built-in UART, tested on AT90S8515 & ATmega8 at 4 Mhz
00009 License:  GNU General Public License 
00010 Usage:    see Doxygen manual
00011 
00012 LICENSE:
00013     Copyright (C) 2006 Peter Fleury
00014 
00015     This program is free software; you can redistribute it and/or modify
00016     it under the terms of the GNU General Public License as published by
00017     the Free Software Foundation; either version 2 of the License, or
00018     any later version.
00019 
00020     This program is distributed in the hope that it will be useful,
00021     but WITHOUT ANY WARRANTY; without even the implied warranty of
00022     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023     GNU General Public License for more details.
00024     
00025 ************************************************************************/
00026 
00051 #if (__GNUC__ * 100 + __GNUC_MINOR__) < 304
00052 #error "This library requires AVR-GCC 3.4 or later, update to newer AVR-GCC compiler !"
00053 #endif
00054 
00055 
00056 /*
00057 ** constants and macros
00058 */
00059 
00064 #define UART_BAUD_SELECT(baudRate,xtalCpu) ((xtalCpu)/((baudRate)*16l)-1)
00065 
00070 #define UART_BAUD_SELECT_DOUBLE_SPEED(baudRate,xtalCpu) (((xtalCpu)/((baudRate)*8l)-1)|0x8000)
00071 
00072 
00074 #ifndef UART_RX_BUFFER_SIZE
00075 #define UART_RX_BUFFER_SIZE 32
00076 #endif
00077 
00078 #ifndef UART_TX_BUFFER_SIZE
00079 #define UART_TX_BUFFER_SIZE 32
00080 #endif
00081 
00082 /* test if the size of the circular buffers fits into SRAM */
00083 #if ( (UART_RX_BUFFER_SIZE+UART_TX_BUFFER_SIZE) >= (RAMEND-0x60 ) )
00084 #error "size of UART_RX_BUFFER_SIZE + UART_TX_BUFFER_SIZE larger than size of SRAM"
00085 #endif
00086 
00087 /* 
00088 ** high byte error return code of uart_getc()
00089 */
00090 #define UART_FRAME_ERROR      0x0800              /* Framing Error by UART       */
00091 #define UART_OVERRUN_ERROR    0x0400              /* Overrun condition by UART   */
00092 #define UART_BUFFER_OVERFLOW  0x0200              /* receive ringbuffer overflow */
00093 #define UART_NO_DATA          0x0100              /* no receive data available   */
00094 
00095 
00096 /*
00097 ** function prototypes
00098 */
00099 
00105 extern void uart_init(unsigned int baudrate);
00106 
00107 
00133 extern unsigned int uart_getc(void);
00134 
00135 
00141 extern void uart_putc(unsigned char data);
00142 
00143 
00154 extern void uart_puts(const char *s );
00155 
00156 
00168 extern void uart_puts_p(const char *s );
00169 
00173 #define uart_puts_P(__s)       uart_puts_p(PSTR(__s))
00174 
00175 
00176 
00178 extern void uart1_init(unsigned int baudrate);
00180 extern unsigned int uart1_getc(void);
00182 extern void uart1_putc(unsigned char data);
00184 extern void uart1_puts(const char *s );
00186 extern void uart1_puts_p(const char *s );
00188 #define uart1_puts_P(__s)       uart1_puts_p(PSTR(__s))
00189 
00193 #endif // UART_H 
00194