Main Page   Data Structures   File List   Data Fields   Globals  

/uart.h

Go to the documentation of this file.
00001 /*! \file uart.h \brief UART driver with buffer support. */
00002 //*****************************************************************************
00003 //
00004 // File Name    : 'uart.h'
00005 // Title        : UART driver with buffer support
00006 // Author       : Pascal Stang - Copyright (C) 2000-2002
00007 // Created      : 11/22/2000
00008 // Revised      : 06/09/2003
00009 // Version      : 1.3
00010 // Target MCU   : ATMEL AVR Series
00011 // Editor Tabs  : 4
00012 //
00013 // This code is distributed under the GNU Public License
00014 //      which can be found at http://www.gnu.org/licenses/gpl.txt
00015 //
00016 //*****************************************************************************
00017 
00018 #ifndef UART_H
00019 #define UART_H
00020 
00021 #include "global.h"
00022 #include "buffer.h"
00023 
00024 //! default baud rate
00025 //! can be changed by using uartSetBaudRate()
00026 #define UART_DEFAULT_BAUD_RATE  9600
00027 
00028 // buffer memory allocation defines
00029 // buffer sizes
00030 #ifndef UART_TX_BUFFER_SIZE
00031 #define UART_TX_BUFFER_SIZE     0x0040  ///< number of bytes for uart transmit buffer
00032 #endif
00033 #ifndef UART_RX_BUFFER_SIZE
00034 #define UART_RX_BUFFER_SIZE     0x0040  ///< number of bytes for uart receive buffer
00035 #endif
00036 
00037 // define this key if you wish to use
00038 // external RAM for the UART buffers
00039 //#define UART_BUFFER_EXTERNAL_RAM
00040 #ifdef UART_BUFFER_EXTERNAL_RAM
00041     // absolute address of uart buffers
00042     #define UART_TX_BUFFER_ADDR 0x1000
00043     #define UART_RX_BUFFER_ADDR 0x1100
00044 #endif
00045 
00046 // type of interrupt handler to use
00047 // *do not change unless you know what you're doing
00048 // Value may be SIGNAL or INTERRUPT
00049 #ifndef UART_INTERRUPT_HANDLER
00050 #define UART_INTERRUPT_HANDLER  SIGNAL
00051 #endif
00052 
00053 // compatibility with old Mega processors
00054 #ifdef UBRRL
00055     #define UBRR                UBRRL
00056 #endif
00057 
00058 // compatibility with dual-uart processors
00059 // (if you need to use both uarts, please use the uart2 library)
00060 #ifdef UDR0
00061     #define UDR                 UDR0
00062     #define UBRR                UBRR0L
00063     #define SIG_UART_TRANS      SIG_UART0_TRANS
00064     #define SIG_UART_RECV       SIG_UART0_RECV
00065     #define SIG_UART_DATA       SIG_UART0_DATA
00066 #endif
00067 // compatibility for the mega161
00068 #ifdef __AVR_ATmega161__
00069     #define RXCIE   RXCIE0
00070     #define TXCIE   TXCIE0
00071     #define UDRIE   UDRIE0
00072     #define RXEN    RXEN0
00073     #define TXEN    TXEN0
00074     #define CHR9    CHR90
00075     #define RXB8    RXB80
00076     #define TXB8    TXB80
00077     #define UBRR0L  UBRR0
00078     #define UBRR1L  UBRR1
00079 #endif
00080 
00081 // functions
00082 
00083 //! initializes transmit and receive buffers
00084 // called from uartInit()
00085 void uartInitBuffers(void);
00086 
00087 //! initializes uart
00088 void uartInit(void);
00089 
00090 //! redirects received data to a user function
00091 void uartSetRxHandler(void (*rx_func)(unsigned char c));
00092 
00093 //! sets the uart baud rate
00094 void uartSetBaudRate(u32 baudrate);
00095 
00096 //! returns pointer to the receive buffer structure
00097 cBuffer* uartGetRxBuffer(void);
00098 
00099 //! returns pointer to the transmit buffer structure
00100 cBuffer* uartGetTxBuffer(void);
00101 
00102 //! sends a single byte over the uart
00103 void uartSendByte(u08 data);
00104 
00105 //! gets a single byte from the uart receive buffer
00106 // Function returns TRUE if data was available, FALSE if not.
00107 // Actual data is returned in variable pointed to by "data".
00108 // example usage:
00109 // char myReceivedByte;
00110 // uartReceiveByte( &myReceivedByte );
00111 u08 uartReceiveByte(u08* data);
00112 
00113 //! returns TRUE/FALSE if receive buffer is empty/not-empty
00114 u08 uartReceiveBufferIsEmpty(void);
00115 
00116 //! flushes (deletes) all data from receive buffer
00117 void uartFlushReceiveBuffer(void);
00118 
00119 //! add byte to end of uart Tx buffer
00120 void uartAddToTxBuffer(u08 data);
00121 
00122 //! begins transmission of the transmit buffer under interrupt control
00123 void uartSendTxBuffer(void);
00124 
00125 //! sends a buffer of length nBytes via the uart using interrupt control
00126 u08  uartSendBuffer(char *buffer, u16 nBytes);
00127 
00128 // interrupt service handlers
00129 void uartTransmitService(void);
00130 void uartReceiveService(void);
00131 
00132 #endif
00133 
00134 

Generated on Fri Aug 1 10:42:42 2003 for Procyon AVRlib by doxygen1.2.18