ATmega8GPSLoggerBasismodul  20131018
uart.c File Reference

Interrupt UART library with receive/transmit circular buffers. More...

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "uart.h"
Include dependency graph for uart.c:

Go to the source code of this file.

Macros

#define UART_RX_BUFFER_MASK   ( UART_RX_BUFFER_SIZE - 1)
 
#define UART_TX_BUFFER_MASK   ( UART_TX_BUFFER_SIZE - 1)
 

Functions

 SIGNAL (UART0_RECEIVE_INTERRUPT)
 
 SIGNAL (UART0_TRANSMIT_INTERRUPT)
 
void uart_init (unsigned int baudrate)
 Initialize UART and set baudrate. More...
 
unsigned int uart_getc (void)
 Get received byte from ringbuffer. More...
 
void uart_putc (unsigned char data)
 Put byte to ringbuffer for transmitting via UART. More...
 
void uart_puts (const char *s)
 Put string to ringbuffer for transmitting via UART. More...
 
void uart_puts_p (const char *progmem_s)
 Put string from program memory to ringbuffer for transmitting via UART. More...
 

Detailed Description

Interrupt UART library with receive/transmit circular buffers.

Author
Peter Fleury <pfleury@gmx.ch>
Peter Fleury
Date
2007-07-01
Version
1.6.2.1

Software: AVR-GCC 4.1, AVR Libc 1.4.6 or higher
Hardware: any AVR with built-in UART
License: GNU General Public License

DESCRIPTION:
An interrupt is generated when the UART has finished transmitting or receiving a byte. The interrupt handling routines use circular buffers for buffering received and transmitted data.

The UART_RX_BUFFER_SIZE and UART_TX_BUFFER_SIZE variables define the buffer size in bytes. Note that these variables must be a power of 2.

USAGE:
Refere to the header file uart.h for a description of the routines. See also example test_uart.c.

Note
Based on Atmel Application Note AVR306

LICENSE: Copyright (C) 2006 Peter Fleury

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Definition in file uart.c.

Macro Definition Documentation

#define UART_RX_BUFFER_MASK   ( UART_RX_BUFFER_SIZE - 1)

constants and macros

size of RX/TX buffers

Definition at line 52 of file uart.c.

Referenced by SIGNAL(), and uart_getc().

#define UART_TX_BUFFER_MASK   ( UART_TX_BUFFER_SIZE - 1)

Definition at line 53 of file uart.c.

Referenced by SIGNAL(), and uart_putc().

Function Documentation

SIGNAL ( UART0_RECEIVE_INTERRUPT  )

UART Receive Complete interrupt called when the UART has received a character

read UART status register and UART data register

calculate buffer index

error: receive buffer overflow

store new index

store received data in buffer

Definition at line 248 of file uart.c.

References UART_BUFFER_OVERFLOW, and UART_RX_BUFFER_MASK.

SIGNAL ( UART0_TRANSMIT_INTERRUPT  )

UART Data Register Empty interrupt called when the UART is ready to transmit the next byte

calculate and store new buffer index

get one byte from buffer and write it to UART

tx buffer empty, disable UDRE interrupt

Definition at line 290 of file uart.c.

References UART_TX_BUFFER_MASK.