Main Page   Data Structures   File List   Data Fields   Globals  

uart2.h

Go to the documentation of this file.
00001 /*! \file uart2.h \brief Dual UART driver with buffer support. */
00002 //*****************************************************************************
00003 //
00004 // File Name    : 'uart2.h'
00005 // Title        : Dual UART driver with buffer support
00006 // Author       : Pascal Stang - Copyright (C) 2000-2002
00007 // Created      : 2000.11.20
00008 // Revised      : 2002.08.22
00009 // Version      : 1.0
00010 // Target MCU   : ATMEL AVR Series
00011 // Editor Tabs  : 4
00012 //
00013 // Description  : This is a UART driver for AVR-series processors with two
00014 //      hardware UARTs such as the mega161 and mega128 
00015 //
00016 // This code is distributed under the GNU Public License
00017 //      which can be found at http://www.gnu.org/licenses/gpl.txt
00018 //
00019 //*****************************************************************************
00020 
00021 #ifndef UART2_H
00022 #define UART2_H
00023 
00024 #include "global.h"
00025 #include "buffer.h"
00026 
00027 // default baud rate
00028 // can be changed by using uartSetBaudRate()
00029 #define UART0_BAUD_RATE             9600
00030 #define UART1_BAUD_RATE             9600
00031 
00032 // buffer memory allocation defines
00033 // buffer sizes
00034 #define UART0_TX_BUFFER_SIZE        0x0010  // number of bytes for uart0 transmit buffer
00035 #define UART0_RX_BUFFER_SIZE        0x0080  // number of bytes for uart0 receive buffer
00036 #define UART1_TX_BUFFER_SIZE        0x0010  // number of bytes for uart1 transmit buffer
00037 #define UART1_RX_BUFFER_SIZE        0x0080  // number of bytes for uart1 receive buffer
00038 
00039 // define this key if you wish to use
00040 // external RAM for the UART buffers
00041 //#define UART_BUFFER_EXTERNAL_RAM
00042 #ifdef UART_BUFFER_EXTERNAL_RAM
00043     // absolute address of uart0 buffers
00044     #define UART0_TX_BUFFER_ADDR    0x1000
00045     #define UART0_RX_BUFFER_ADDR    0x1100
00046     // absolute address of uart1 buffers
00047     #define UART1_TX_BUFFER_ADDR    0x1200
00048     #define UART1_RX_BUFFER_ADDR    0x1300
00049 #endif
00050 
00051 // compatibility for the mega161
00052 #ifndef RXCIE
00053     #define RXCIE   RXCIE0
00054     #define TXCIE   TXCIE0
00055     #define UDRIE   UDRIE0
00056     #define RXEN    RXEN0
00057     #define TXEN    TXEN0
00058     #define CHR9    CHR90
00059     #define RXB8    RXB80
00060     #define TXB8    TXB80
00061 #endif
00062 #ifndef UBRR0L
00063     #define UBRR0L  UBRR0
00064     #define UBRR1L  UBRR1
00065 #endif
00066 
00067 // functions
00068 
00069 // initializes transmit and receive buffers
00070 // called from uartInit()
00071 void uartInitBuffers(void);
00072 
00073 // initializes uart
00074 void uartInit(void);
00075 
00076 // sets the uart baud rate
00077 void uartSetBaudRate(u08 nUart, u32 baudrate);
00078 
00079 // returns pointer to the receive buffer structure
00080 cBuffer* uartGetRxBuffer(u08 nUart);
00081 
00082 // returns pointer to the transmit buffer structure
00083 cBuffer* uartGetTxBuffer(u08 nUart);
00084 
00085 // sends a single byte over the uart
00086 void uartSendByte(u08 nUart, u08 data);
00087 // SendByte commands with the UART number hardcoded
00088 // use this with printfInit() - example: printfInit(uart0SendByte);
00089 void uart0SendByte(u08 data);
00090 void uart1SendByte(u08 data);
00091 
00092 // gets a single byte from the uart receive buffer
00093 // function returns TRUE if data was available, FALSE if not
00094 // actual data is returned in variable pointed to by "data"
00095 // example usage:
00096 // char myReceivedByte;
00097 // uartReceiveByte( &myReceivedByte );
00098 u08 uartReceiveByte(u08 nUart, u08* data);
00099 
00100 // returns TRUE/FALSE if receive buffer is empty/not-empty
00101 u08 uartReceiveBufferIsEmpty(u08 nUart);
00102 
00103 // flushes (deletes) all data from receive buffer
00104 void uartFlushReceiveBuffer(u08 nUart);
00105 
00106 // begins transmission of the transmit buffer under interrupt control
00107 void uartSendTxBuffer(u08 nUart);
00108 
00109 // sends a buffer of length nBytes via the uart using interrupt control
00110 u08 uartSendBuffer(u08 nUart, char *buffer, u16 nBytes);
00111 
00112 // interrupt service handlers
00113 void uartTransmitService(u08 nUart);
00114 void uartReceiveService(u08 nUart);
00115 
00116 #endif
00117 

Generated on Tue Feb 4 20:18:37 2003 for Procyon AVRlib by doxygen1.3-rc2