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      : 11/20/2000
00008 // Revised      : 06/09/2003
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_DEFAULT_BAUD_RATE     9600
00030 #define UART1_DEFAULT_BAUD_RATE     9600
00031 
00032 // buffer memory allocation defines
00033 // buffer sizes
00034 #ifndef UART0_TX_BUFFER_SIZE
00035 #define UART0_TX_BUFFER_SIZE        0x0010  ///< number of bytes for uart0 transmit buffer
00036 #endif
00037 #ifndef UART0_RX_BUFFER_SIZE
00038 #define UART0_RX_BUFFER_SIZE        0x0080  ///< number of bytes for uart0 receive buffer
00039 #endif
00040 #ifndef UART1_TX_BUFFER_SIZE
00041 #define UART1_TX_BUFFER_SIZE        0x0010  ///< number of bytes for uart1 transmit buffer
00042 #endif
00043 #ifndef UART1_RX_BUFFER_SIZE
00044 #define UART1_RX_BUFFER_SIZE        0x0080  ///< number of bytes for uart1 receive buffer
00045 #endif
00046 
00047 // define this key if you wish to use
00048 // external RAM for the UART buffers
00049 //#define UART_BUFFER_EXTERNAL_RAM
00050 #ifdef UART_BUFFER_EXTERNAL_RAM
00051     // absolute address of uart0 buffers
00052     #define UART0_TX_BUFFER_ADDR    0x1000
00053     #define UART0_RX_BUFFER_ADDR    0x1100
00054     // absolute address of uart1 buffers
00055     #define UART1_TX_BUFFER_ADDR    0x1200
00056     #define UART1_RX_BUFFER_ADDR    0x1300
00057 #endif
00058 
00059 // type of interrupt handler to use
00060 // *do not change unless you know what you're doing
00061 // Value may be SIGNAL or INTERRUPT
00062 #ifndef UART_INTERRUPT_HANDLER
00063 #define UART_INTERRUPT_HANDLER  SIGNAL
00064 #endif
00065 
00066 // compatibility for the mega161
00067 #ifndef RXCIE
00068     #define RXCIE   RXCIE0
00069     #define TXCIE   TXCIE0
00070     #define UDRIE   UDRIE0
00071     #define RXEN    RXEN0
00072     #define TXEN    TXEN0
00073     #define CHR9    CHR90
00074     #define RXB8    RXB80
00075     #define TXB8    TXB80
00076 #endif
00077 #ifndef UBRR0L
00078     #define UBRR0L  UBRR0
00079     #define UBRR1L  UBRR1
00080 #endif
00081 
00082 // functions
00083 
00084 // initializes transmit and receive buffers
00085 // called from uartInit()
00086 void uartInitBuffers(void);
00087 
00088 // initializes uart
00089 void uartInit(void);
00090 
00091 // redirects received data to a user function
00092 void uartSetRxHandler(u08 nUart, void (*rx_func)(unsigned char c));
00093 
00094 // sets the uart baud rate
00095 void uartSetBaudRate(u08 nUart, u32 baudrate);
00096 
00097 // returns pointer to the receive buffer structure
00098 cBuffer* uartGetRxBuffer(u08 nUart);
00099 
00100 // returns pointer to the transmit buffer structure
00101 cBuffer* uartGetTxBuffer(u08 nUart);
00102 
00103 // sends a single byte over the uart
00104 void uartSendByte(u08 nUart, u08 data);
00105 // SendByte commands with the UART number hardcoded
00106 // use this with printfInit() - example: printfInit(uart0SendByte);
00107 void uart0SendByte(u08 data);
00108 void uart1SendByte(u08 data);
00109 
00110 // gets a single byte from the uart receive buffer
00111 // function returns TRUE if data was available, FALSE if not
00112 // actual data is returned in variable pointed to by "data"
00113 // example usage:
00114 // char myReceivedByte;
00115 // uartReceiveByte( &myReceivedByte );
00116 u08 uartReceiveByte(u08 nUart, u08* data);
00117 
00118 // returns TRUE/FALSE if receive buffer is empty/not-empty
00119 u08 uartReceiveBufferIsEmpty(u08 nUart);
00120 
00121 // flushes (deletes) all data from receive buffer
00122 void uartFlushReceiveBuffer(u08 nUart);
00123 
00124 //! add byte to end of uart Tx buffer
00125 void uartAddToTxBuffer(u08 nUart, u08 data);
00126 // AddToTxBuffer commands with the UART number hardcoded
00127 // use this with printfInit() - example: printfInit(uart0AddToTxBuffer);
00128 void uart0AddToTxBuffer(u08 data);
00129 void uart1AddToTxBuffer(u08 data);
00130 
00131 // begins transmission of the transmit buffer under interrupt control
00132 void uartSendTxBuffer(u08 nUart);
00133 
00134 // sends a buffer of length nBytes via the uart using interrupt control
00135 u08 uartSendBuffer(u08 nUart, char *buffer, u16 nBytes);
00136 
00137 // interrupt service handlers
00138 void uartTransmitService(u08 nUart);
00139 void uartReceiveService(u08 nUart);
00140 
00141 #endif
00142 

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