<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Procyon AVRlib: uart2.h Source File</title>
<link href="dox.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.2 -->
<div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a></div>
<h1>uart2.h</h1><a href="uart2_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file uart2.h \brief Dual UART driver with buffer support. */</span>
00002 <span class="comment">//*****************************************************************************</span>
00003 <span class="comment">//</span>
00004 <span class="comment">// File Name : 'uart2.h'</span>
00005 <span class="comment">// Title : Dual UART driver with buffer support</span>
00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2000-2002</span>
00007 <span class="comment">// Created : 11/20/2000</span>
00008 <span class="comment">// Revised : 07/04/2004</span>
00009 <span class="comment">// Version : 1.0</span>
00010 <span class="comment">// Target MCU : ATMEL AVR Series</span>
00011 <span class="comment">// Editor Tabs : 4</span>
00012 <span class="comment">//</span>
00013 <span class="comment">// This code is distributed under the GNU Public License</span>
00014 <span class="comment">// which can be found at http://www.gnu.org/licenses/gpl.txt</span>
00015 <span class="comment">//</span><span class="comment"></span>
00016 <span class="comment">/// \ingroup driver_avr</span>
00017 <span class="comment">/// \defgroup uart2 UART Driver/Function Library for dual-UART processors (uart2.c)</span>
00018 <span class="comment">/// \code #include "uart2.h" \endcode</span>
00019 <span class="comment">/// \par Overview</span>
00020 <span class="comment">/// This is a UART driver for AVR-series processors with two hardware</span>
00021 <span class="comment">/// UARTs such as the mega161 and mega128. This library provides both</span>
00022 <span class="comment">/// buffered and unbuffered transmit and receive functions for the AVR</span>
00023 <span class="comment">/// processor UART. Buffered access means that the UART can transmit</span>
00024 <span class="comment">/// and receive data in the "background", while your code continues</span>
00025 <span class="comment">/// executing. Also included are functions to initialize the UARTs,</span>
00026 <span class="comment">/// set the baud rate, flush the buffers, and check buffer status.</span>
00027 <span class="comment">///</span>
00028 <span class="comment">/// \note For full text output functionality, you may wish to use the rprintf</span>
00029 <span class="comment">/// functions along with this driver.</span>
00030 <span class="comment">///</span>
00031 <span class="comment">/// \par About UART operations</span>
00032 <span class="comment">/// Most Atmel AVR-series processors contain one or more hardware UARTs</span>
00033 <span class="comment">/// (aka, serial ports). UART serial ports can communicate with other </span>
00034 <span class="comment">/// serial ports of the same type, like those used on PCs. In general,</span>
00035 <span class="comment">/// UARTs are used to communicate with devices that are RS-232 compatible</span>
00036 <span class="comment">/// (RS-232 is a certain kind of serial port).</span>
00037 <span class="comment">/// \par</span>
00038 <span class="comment">/// By far, the most common use for serial communications on AVR processors</span>
00039 <span class="comment">/// is for sending information and data to a PC running a terminal program.</span>
00040 <span class="comment">/// Here is an exmaple:</span>
00041 <span class="comment">/// \code</span>
00042 <span class="comment">/// uartInit(); // initialize UARTs (serial ports)</span>
00043 <span class="comment">/// uartSetBaudRate(0, 9600); // set UART0 speed to 9600 baud</span>
00044 <span class="comment">/// uartSetBaudRate(1, 115200); // set UART1 speed to 115200 baud</span>
00045 <span class="comment">///</span>
00046 <span class="comment">/// rprintfInit(uart0SendByte); // configure rprintf to use UART0 for output</span>
00047 <span class="comment">/// rprintf("Hello UART0\r\n"); // send "hello world" message via UART0</span>
00048 <span class="comment">///</span>
00049 <span class="comment">/// rprintfInit(uart1SendByte); // configure rprintf to use UART1 for output</span>
00050 <span class="comment">/// rprintf("Hello UART1\r\n"); // send "hello world" message via UART1</span>
00051 <span class="comment">/// \endcode</span>
00052 <span class="comment">///</span>
00053 <span class="comment">/// \warning The CPU frequency (F_CPU) must be set correctly in \c global.h</span>
00054 <span class="comment">/// for the UART library to calculate correct baud rates. Furthermore,</span>
00055 <span class="comment">/// certain CPU frequencies will not produce exact baud rates due to</span>
00056 <span class="comment">/// integer frequency division round-off. See your AVR processor's</span>
00057 <span class="comment">/// datasheet for full details.</span>
00058 <span class="comment"></span><span class="comment">//</span>
00059 <span class="comment">//*****************************************************************************</span><span class="comment"></span>
00060 <span class="comment">//@{</span>
00061 <span class="comment"></span>
00062 <span class="preprocessor">#ifndef UART2_H</span>
00063 <span class="preprocessor"></span><span class="preprocessor">#define UART2_H</span>
00064 <span class="preprocessor"></span>
00065 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>
00066 <span class="preprocessor">#include "<a class="code" href="buffer_8h.html">buffer.h</a>"</span>
00067 <span class="comment"></span>
00068 <span class="comment">//! Default uart baud rate.</span>
00069 <span class="comment">/// This is the default speed after a uartInit() command,</span>
00070 <span class="comment">/// and can be changed by using uartSetBaudRate().</span>
<a name="l00071"></a><a class="code" href="group__uart2.html#ga24">00071</a> <span class="comment"></span><span class="preprocessor">#define UART0_DEFAULT_BAUD_RATE 9600 </span><span class="comment">///< default baud rate for UART0</span>
<a name="l00072"></a><a class="code" href="group__uart2.html#ga25">00072</a> <span class="comment"></span>#define UART1_DEFAULT_BAUD_RATE 9600 <span class="comment">///< default baud rate for UART1</span>
00073 <span class="comment"></span>
00074 <span class="comment">// buffer memory allocation defines</span>
00075 <span class="comment">// buffer sizes</span>
00076 <span class="preprocessor">#ifndef UART0_TX_BUFFER_SIZE</span>
<a name="l00077"></a><a class="code" href="group__uart2.html#ga26">00077</a> <span class="preprocessor"></span><span class="preprocessor">#define UART0_TX_BUFFER_SIZE 0x0010 </span><span class="comment">///< number of bytes for uart0 transmit buffer</span>
00078 <span class="comment"></span>#endif
00079 <span class="preprocessor">#ifndef UART0_RX_BUFFER_SIZE</span>
<a name="l00080"></a><a class="code" href="group__uart2.html#ga27">00080</a> <span class="preprocessor"></span><span class="preprocessor">#define UART0_RX_BUFFER_SIZE 0x0080 </span><span class="comment">///< number of bytes for uart0 receive buffer</span>
00081 <span class="comment"></span>#endif
00082 <span class="preprocessor">#ifndef UART1_TX_BUFFER_SIZE</span>
<a name="l00083"></a><a class="code" href="group__uart2.html#ga28">00083</a> <span class="preprocessor"></span><span class="preprocessor">#define UART1_TX_BUFFER_SIZE 0x0010 </span><span class="comment">///< number of bytes for uart1 transmit buffer</span>
00084 <span class="comment"></span>#endif
00085 <span class="preprocessor">#ifndef UART1_RX_BUFFER_SIZE</span>
<a name="l00086"></a><a class="code" href="group__uart2.html#ga29">00086</a> <span class="preprocessor"></span><span class="preprocessor">#define UART1_RX_BUFFER_SIZE 0x0080 </span><span class="comment">///< number of bytes for uart1 receive buffer</span>
00087 <span class="comment"></span>#endif
00088
00089 <span class="comment">// define this key if you wish to use</span>
00090 <span class="comment">// external RAM for the UART buffers</span>
00091 <span class="comment">//#define UART_BUFFER_EXTERNAL_RAM</span>
00092 <span class="preprocessor">#ifdef UART_BUFFER_EXTERNAL_RAM</span>
00093 <span class="preprocessor"></span> <span class="comment">// absolute address of uart0 buffers</span>
00094 <span class="preprocessor"> #define UART0_TX_BUFFER_ADDR 0x1000</span>
00095 <span class="preprocessor"></span><span class="preprocessor"> #define UART0_RX_BUFFER_ADDR 0x1100</span>
00096 <span class="preprocessor"></span> <span class="comment">// absolute address of uart1 buffers</span>
00097 <span class="preprocessor"> #define UART1_TX_BUFFER_ADDR 0x1200</span>
00098 <span class="preprocessor"></span><span class="preprocessor"> #define UART1_RX_BUFFER_ADDR 0x1300</span>
00099 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
00100 <span class="preprocessor"></span><span class="comment"></span>
00101 <span class="comment">//! Type of interrupt handler to use for uart interrupts.</span>
00102 <span class="comment">/// Value may be SIGNAL or INTERRUPT.</span>
00103 <span class="comment">/// \warning Do not change unless you know what you're doing.</span>
00104 <span class="comment"></span><span class="preprocessor">#ifndef UART_INTERRUPT_HANDLER</span>
<a name="l00105"></a><a class="code" href="group__uart2.html#ga30">00105</a> <span class="preprocessor"></span><span class="preprocessor">#define UART_INTERRUPT_HANDLER SIGNAL</span>
00106 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
00107 <span class="preprocessor"></span>
00108 <span class="comment">// compatibility for the mega161</span>
00109 <span class="preprocessor">#ifndef RXCIE</span>
00110 <span class="preprocessor"></span><span class="preprocessor"> #define RXCIE RXCIE0</span>
00111 <span class="preprocessor"></span><span class="preprocessor"> #define TXCIE TXCIE0</span>
00112 <span class="preprocessor"></span><span class="preprocessor"> #define UDRIE UDRIE0</span>
00113 <span class="preprocessor"></span><span class="preprocessor"> #define RXEN RXEN0</span>
00114 <span class="preprocessor"></span><span class="preprocessor"> #define TXEN TXEN0</span>
00115 <span class="preprocessor"></span><span class="preprocessor"> #define CHR9 CHR90</span>
00116 <span class="preprocessor"></span><span class="preprocessor"> #define RXB8 RXB80</span>
00117 <span class="preprocessor"></span><span class="preprocessor"> #define TXB8 TXB80</span>
00118 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
00119 <span class="preprocessor"></span><span class="preprocessor">#ifndef UBRR0L</span>
00120 <span class="preprocessor"></span><span class="preprocessor"> #define UBRR0L UBRR0</span>
00121 <span class="preprocessor"></span><span class="preprocessor"> #define UBRR1L UBRR1</span>
00122 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
00123 <span class="preprocessor"></span>
00124 <span class="comment">// functions</span>
00125 <span class="comment"></span>
00126 <span class="comment">//! Initializes UARTs.</span>
00127 <span class="comment">/// \note After running this init function, the processor</span>
00128 <span class="comment">/// I/O pins that used for uart communications (RXD, TXD)</span>
00129 <span class="comment">/// are no long available for general purpose I/O.</span>
00130 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__uart.html#ga0">uartInit</a>(<span class="keywordtype">void</span>);
00131 <span class="comment"></span>
00132 <span class="comment">//! Initializes UART0 only.</span>
00133 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__uart2.html#ga1">uart0Init</a>(<span class="keywordtype">void</span>);
00134 <span class="comment"></span>
00135 <span class="comment">//! Initializes UART1 only.</span>
00136 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__uart2.html#ga2">uart1Init</a>(<span class="keywordtype">void</span>);
00137 <span class="comment"></span>
00138 <span class="comment">//! Initializes transmit and receive buffers.</span>
00139 <span class="comment">/// Automatically called from uartInit()</span>
00140 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__uart2.html#ga3">uart0InitBuffers</a>(<span class="keywordtype">void</span>);
00141 <span class="keywordtype">void</span> uart1InitBuffers(<span class="keywordtype">void</span>);
00142 <span class="comment"></span>
00143 <span class="comment">//! Redirects received data to a user function.</span>
00144 <span class="comment">///</span>
00145 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__uart.html#ga2">uartSetRxHandler</a>(u08 nUart, <span class="keywordtype">void</span> (*rx_func)(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c));
00146 <span class="comment"></span>
00147 <span class="comment">//! Sets the uart baud rate.</span>
00148 <span class="comment">/// Argument should be in bits-per-second, like \c uartSetBaudRate(9600);</span>
00149 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__uart.html#ga3">uartSetBaudRate</a>(u08 nUart, u32 baudrate);
00150 <span class="comment"></span>
00151 <span class="comment">//! Returns pointer to the receive buffer structure.</span>
00152 <span class="comment">///</span>
00153 <span class="comment"></span><a class="code" href="structstruct__cBuffer.html">cBuffer</a>* <a class="code" href="group__uart.html#ga4">uartGetRxBuffer</a>(u08 nUart);
00154 <span class="comment"></span>
00155 <span class="comment">//! Returns pointer to the transmit buffer structure.</span>
00156 <span class="comment">///</span>
00157 <span class="comment"></span><a class="code" href="structstruct__cBuffer.html">cBuffer</a>* <a class="code" href="group__uart.html#ga5">uartGetTxBuffer</a>(u08 nUart);
00158 <span class="comment"></span>
00159 <span class="comment">//! Sends a single byte over the uart.</span>
00160 <span class="comment">///</span>
00161 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__uart.html#ga6">uartSendByte</a>(u08 nUart, u08 data);
00162 <span class="comment"></span>
00163 <span class="comment">//! SendByte commands with the UART number hardcoded</span>
00164 <span class="comment">/// Use these with printfInit() - example: \c printfInit(uart0SendByte);</span>
00165 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__uart2.html#ga10">uart0SendByte</a>(u08 data);
00166 <span class="keywordtype">void</span> uart1SendByte(u08 data);
00167 <span class="comment"></span>
00168 <span class="comment">//! Gets a single byte from the uart receive buffer.</span>
00169 <span class="comment">/// Returns the byte, or -1 if no byte is available (getchar-style).</span>
00170 <span class="comment"></span><span class="keywordtype">int</span> <a class="code" href="group__uart2.html#ga12">uart0GetByte</a>(<span class="keywordtype">void</span>);
00171 <span class="keywordtype">int</span> uart1GetByte(<span class="keywordtype">void</span>);
00172 <span class="comment"></span>
00173 <span class="comment">//! Gets a single byte from the uart receive buffer.</span>
00174 <span class="comment">/// Function returns TRUE if data was available, FALSE if not.</span>
00175 <span class="comment">/// Actual data is returned in variable pointed to by "data".</span>
00176 <span class="comment">/// Example usage:</span>
00177 <span class="comment">/// \code</span>
00178 <span class="comment">/// char myReceivedByte;</span>
00179 <span class="comment">/// uartReceiveByte(0, &myReceivedByte );</span>
00180 <span class="comment">/// \endcode</span>
00181 <span class="comment"></span>u08 <a class="code" href="group__uart.html#ga8">uartReceiveByte</a>(u08 nUart, u08* data);
00182 <span class="comment"></span>
00183 <span class="comment">//! Returns TRUE/FALSE if receive buffer is empty/not-empty.</span>
00184 <span class="comment">///</span>
00185 <span class="comment"></span>u08 <a class="code" href="group__uart.html#ga9">uartReceiveBufferIsEmpty</a>(u08 nUart);
00186 <span class="comment"></span>
00187 <span class="comment">//! Flushes (deletes) all data from receive buffer.</span>
00188 <span class="comment">///</span>
00189 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__uart.html#ga10">uartFlushReceiveBuffer</a>(u08 nUart);
00190 <span class="comment"></span>
00191 <span class="comment">//! Add byte to end of uart Tx buffer.</span>
00192 <span class="comment">///</span>
00193 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__uart.html#ga11">uartAddToTxBuffer</a>(u08 nUart, u08 data);
00194 <span class="comment"></span>
00195 <span class="comment">//! AddToTxBuffer commands with the UART number hardcoded</span>
00196 <span class="comment">/// Use this with printfInit() - example: \c printfInit(uart0AddToTxBuffer);</span>
00197 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__uart2.html#ga18">uart0AddToTxBuffer</a>(u08 data);
00198 <span class="keywordtype">void</span> uart1AddToTxBuffer(u08 data);
00199 <span class="comment"></span>
00200 <span class="comment">//! Begins transmission of the transmit buffer under interrupt control.</span>
00201 <span class="comment">///</span>
00202 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__uart.html#ga12">uartSendTxBuffer</a>(u08 nUart);
00203 <span class="comment"></span>
00204 <span class="comment">//! sends a buffer of length nBytes via the uart using interrupt control.</span>
00205 <span class="comment">///</span>
00206 <span class="comment"></span>u08 <a class="code" href="group__uart.html#ga13">uartSendBuffer</a>(u08 nUart, <span class="keywordtype">char</span> *buffer, u16 nBytes);
00207 <span class="comment"></span>
00208 <span class="comment">//! interrupt service handlers</span>
00209 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__uart2.html#ga22">uartTransmitService</a>(u08 nUart);
00210 <span class="keywordtype">void</span> uartReceiveService(u08 nUart);
00211
00212 <span class="preprocessor">#endif</span>
00213 <span class="preprocessor"></span>
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:08 2006 for Procyon AVRlib by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address>
</body>
</html>
|