?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 6

Line No. Rev Author Line
1 6 kaklik <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
3 <title>Procyon AVRlib: uart.h Source File</title>
4 <link href="dox.css" rel="stylesheet" type="text/css">
5 </head><body>
6 <!-- Generated by Doxygen 1.4.2 -->
7 <div class="qindex"><a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div>
8 <h1>uart.h</h1><a href="uart_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file uart.h \brief UART driver with buffer support. */</span>
9 00002 <span class="comment">//*****************************************************************************</span>
10 00003 <span class="comment">//</span>
11 00004 <span class="comment">// File Name : 'uart.h'</span>
12 00005 <span class="comment">// Title : UART driver with buffer support</span>
13 00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2000-2002</span>
14 00007 <span class="comment">// Created : 11/22/2000</span>
15 00008 <span class="comment">// Revised : 02/01/2004</span>
16 00009 <span class="comment">// Version : 1.3</span>
17 00010 <span class="comment">// Target MCU : ATMEL AVR Series</span>
18 00011 <span class="comment">// Editor Tabs : 4</span>
19 00012 <span class="comment">//</span>
20 00013 <span class="comment">// This code is distributed under the GNU Public License</span>
21 00014 <span class="comment">// which can be found at http://www.gnu.org/licenses/gpl.txt</span>
22 00015 <span class="comment">//</span><span class="comment"></span>
23 00016 <span class="comment">/// \ingroup driver_avr</span>
24 00017 <span class="comment">/// \defgroup uart UART Driver/Function Library (uart.c)</span>
25 00018 <span class="comment">/// \code #include "uart.h" \endcode</span>
26 00019 <span class="comment">/// \par Overview</span>
27 00020 <span class="comment">/// This library provides both buffered and unbuffered transmit and receive</span>
28 00021 <span class="comment">/// functions for the AVR processor UART.  Buffered access means that the</span>
29 00022 <span class="comment">/// UART can transmit and receive data in the "background", while your code</span>
30 00023 <span class="comment">/// continues executing.  Also included are functions to initialize the</span>
31 00024 <span class="comment">/// UART, set the baud rate, flush the buffers, and check buffer status.</span>
32 00025 <span class="comment">///</span>
33 00026 <span class="comment">/// \note For full text output functionality, you may wish to use the rprintf</span>
34 00027 <span class="comment">/// functions along with this driver.</span>
35 00028 <span class="comment">///</span>
36 00029 <span class="comment">/// \par About UART operations</span>
37 00030 <span class="comment">/// Most Atmel AVR-series processors contain one or more hardware UARTs</span>
38 00031 <span class="comment">/// (aka, serial ports). UART serial ports can communicate with other </span>
39 00032 <span class="comment">/// serial ports of the same type, like those used on PCs. In general,</span>
40 00033 <span class="comment">/// UARTs are used to communicate with devices that are RS-232 compatible</span>
41 00034 <span class="comment">/// (RS-232 is a certain kind of serial port).</span>
42 00035 <span class="comment">/// \par</span>
43 00036 <span class="comment">/// By far, the most common use for serial communications on AVR processors</span>
44 00037 <span class="comment">/// is for sending information and data to a PC running a terminal program.</span>
45 00038 <span class="comment">/// Here is an exmaple:</span>
46 00039 <span class="comment">/// \code</span>
47 00040 <span class="comment">/// uartInit(); // initialize UART (serial port)</span>
48 00041 <span class="comment">/// uartSetBaudRate(9600); // set UART speed to 9600 baud</span>
49 00042 <span class="comment">/// rprintfInit(uartSendByte); // configure rprintf to use UART for output</span>
50 00043 <span class="comment">/// rprintf("Hello World\r\n"); // send "hello world" message via serial port</span>
51 00044 <span class="comment">/// \endcode</span>
52 00045 <span class="comment">///</span>
53 00046 <span class="comment">/// \warning The CPU frequency (F_CPU) must be set correctly in \c global.h</span>
54 00047 <span class="comment">/// for the UART library to calculate correct baud rates. Furthermore,</span>
55 00048 <span class="comment">/// certain CPU frequencies will not produce exact baud rates due to</span>
56 00049 <span class="comment">/// integer frequency division round-off. See your AVR processor's</span>
57 00050 <span class="comment">/// datasheet for full details.</span>
58 00051 <span class="comment"></span><span class="comment">//</span>
59 00052 <span class="comment">//*****************************************************************************</span><span class="comment"></span>
60 00053 <span class="comment">//@{</span>
61 00054 <span class="comment"></span>
62 00055 <span class="preprocessor">#ifndef UART_H</span>
63 00056 <span class="preprocessor"></span><span class="preprocessor">#define UART_H</span>
64 00057 <span class="preprocessor"></span>
65 00058 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>
66 00059 <span class="preprocessor">#include "<a class="code" href="buffer_8h.html">buffer.h</a>"</span>
67 00060 <span class="comment"></span>
68 00061 <span class="comment">//! Default uart baud rate.</span>
69 00062 <span class="comment">/// This is the default speed after a uartInit() command,</span>
70 00063 <span class="comment">/// and can be changed by using uartSetBaudRate().</span>
71 <a name="l00064"></a><a class="code" href="group__uart.html#ga14">00064</a> <span class="comment"></span><span class="preprocessor">#define UART_DEFAULT_BAUD_RATE 9600</span>
72 00065 <span class="preprocessor"></span>
73 00066 <span class="comment">// buffer memory allocation defines</span>
74 00067 <span class="comment">// buffer sizes</span>
75 00068 <span class="preprocessor">#ifndef UART_TX_BUFFER_SIZE</span><span class="comment"></span>
76 00069 <span class="comment">//! Number of bytes for uart transmit buffer.</span>
77 00070 <span class="comment">/// Do not change this value in uart.h, but rather override</span>
78 00071 <span class="comment">/// it with the desired value defined in your project's global.h</span>
79 <a name="l00072"></a><a class="code" href="group__uart.html#ga15">00072</a> <span class="comment"></span>#define UART_TX_BUFFER_SIZE 0x0040
80 00073 <span class="preprocessor">#endif</span>
81 00074 <span class="preprocessor"></span><span class="preprocessor">#ifndef UART_RX_BUFFER_SIZE</span><span class="comment"></span>
82 00075 <span class="comment">//! Number of bytes for uart receive buffer.</span>
83 00076 <span class="comment">/// Do not change this value in uart.h, but rather override</span>
84 00077 <span class="comment">/// it with the desired value defined in your project's global.h</span>
85 <a name="l00078"></a><a class="code" href="group__uart.html#ga16">00078</a> <span class="comment"></span>#define UART_RX_BUFFER_SIZE 0x0040
86 00079 <span class="preprocessor">#endif</span>
87 00080 <span class="preprocessor"></span>
88 00081 <span class="comment">// define this key if you wish to use</span>
89 00082 <span class="comment">// external RAM for the UART buffers</span>
90 00083 <span class="comment">//#define UART_BUFFER_EXTERNAL_RAM</span>
91 00084 <span class="preprocessor">#ifdef UART_BUFFER_EXTERNAL_RAM</span>
92 00085 <span class="preprocessor"></span> <span class="comment">// absolute address of uart buffers</span>
93 00086 <span class="preprocessor"> #define UART_TX_BUFFER_ADDR 0x1000</span>
94 00087 <span class="preprocessor"></span><span class="preprocessor"> #define UART_RX_BUFFER_ADDR 0x1100</span>
95 00088 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
96 00089 <span class="preprocessor"></span><span class="comment"></span>
97 00090 <span class="comment">//! Type of interrupt handler to use for uart interrupts.</span>
98 00091 <span class="comment">/// Value may be SIGNAL or INTERRUPT.</span>
99 00092 <span class="comment">/// \warning Do not change unless you know what you're doing.</span>
100 00093 <span class="comment"></span><span class="preprocessor">#ifndef UART_INTERRUPT_HANDLER</span>
101 <a name="l00094"></a><a class="code" href="group__uart.html#ga17">00094</a> <span class="preprocessor"></span><span class="preprocessor">#define UART_INTERRUPT_HANDLER SIGNAL</span>
102 00095 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
103 00096 <span class="preprocessor"></span>
104 00097 <span class="comment">// compatibility with most newer processors</span>
105 00098 <span class="preprocessor">#ifdef UCSRB</span>
106 00099 <span class="preprocessor"></span><span class="preprocessor"> #define UCR UCSRB</span>
107 00100 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
108 00101 <span class="preprocessor"></span><span class="comment">// compatibility with old Mega processors</span>
109 00102 <span class="preprocessor">#if defined(UBRR) &amp;&amp; !defined(UBRRL)</span>
110 00103 <span class="preprocessor"></span><span class="preprocessor"> #define UBRRL UBRR</span>
111 00104 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
112 00105 <span class="preprocessor"></span><span class="comment">// compatibility with megaXX8 processors</span>
113 00106 <span class="preprocessor">#if defined(__AVR_ATmega88__) || \</span>
114 00107 <span class="preprocessor"> defined(__AVR_ATmega168__) || \</span>
115 00108 <span class="preprocessor"> defined(__AVR_ATmega644__)</span>
116 00109 <span class="preprocessor"></span><span class="preprocessor"> #define UDR UDR0</span>
117 00110 <span class="preprocessor"></span><span class="preprocessor"> #define UCR UCSR0B</span>
118 00111 <span class="preprocessor"></span><span class="preprocessor"> #define RXCIE RXCIE0</span>
119 00112 <span class="preprocessor"></span><span class="preprocessor"> #define TXCIE TXCIE0</span>
120 00113 <span class="preprocessor"></span><span class="preprocessor"> #define RXC RXC0</span>
121 00114 <span class="preprocessor"></span><span class="preprocessor"> #define TXC TXC0</span>
122 00115 <span class="preprocessor"></span><span class="preprocessor"> #define RXEN RXEN0</span>
123 00116 <span class="preprocessor"></span><span class="preprocessor"> #define TXEN TXEN0</span>
124 00117 <span class="preprocessor"></span><span class="preprocessor"> #define UBRRL UBRR0L</span>
125 00118 <span class="preprocessor"></span><span class="preprocessor"> #define UBRRH UBRR0H</span>
126 00119 <span class="preprocessor"></span><span class="preprocessor"> #define SIG_UART_TRANS SIG_USART_TRANS</span>
127 00120 <span class="preprocessor"></span><span class="preprocessor"> #define SIG_UART_RECV SIG_USART_RECV</span>
128 00121 <span class="preprocessor"></span><span class="preprocessor"> #define SIG_UART_DATA SIG_USART_DATA</span>
129 00122 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
130 00123 <span class="preprocessor"></span><span class="comment">// compatibility with mega169 processors</span>
131 00124 <span class="preprocessor">#if defined(__AVR_ATmega169__)</span>
132 00125 <span class="preprocessor"></span><span class="preprocessor"> #define SIG_UART_TRANS SIG_USART_TRANS</span>
133 00126 <span class="preprocessor"></span><span class="preprocessor"> #define SIG_UART_RECV SIG_USART_RECV</span>
134 00127 <span class="preprocessor"></span><span class="preprocessor"> #define SIG_UART_DATA SIG_USART_DATA</span>
135 00128 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
136 00129 <span class="preprocessor"></span><span class="comment">// compatibility with dual-uart processors</span>
137 00130 <span class="comment">// (if you need to use both uarts, please use the uart2 library)</span>
138 00131 <span class="preprocessor">#if defined(__AVR_ATmega161__)</span>
139 00132 <span class="preprocessor"></span><span class="preprocessor"> #define UDR UDR0</span>
140 00133 <span class="preprocessor"></span><span class="preprocessor"> #define UCR UCSR0B</span>
141 00134 <span class="preprocessor"></span><span class="preprocessor"> #define UBRRL UBRR0</span>
142 00135 <span class="preprocessor"></span><span class="preprocessor"> #define SIG_UART_TRANS SIG_UART0_TRANS</span>
143 00136 <span class="preprocessor"></span><span class="preprocessor"> #define SIG_UART_RECV SIG_UART0_RECV</span>
144 00137 <span class="preprocessor"></span><span class="preprocessor"> #define SIG_UART_DATA SIG_UART0_DATA</span>
145 00138 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
146 00139 <span class="preprocessor"></span><span class="preprocessor">#if defined(__AVR_ATmega128__)</span>
147 00140 <span class="preprocessor"></span><span class="preprocessor">#ifdef UART_USE_UART1</span>
148 00141 <span class="preprocessor"></span><span class="preprocessor"> #define UDR UDR1</span>
149 00142 <span class="preprocessor"></span><span class="preprocessor"> #define UCR UCSR1B</span>
150 00143 <span class="preprocessor"></span><span class="preprocessor"> #define UBRRL UBRR1L</span>
151 00144 <span class="preprocessor"></span><span class="preprocessor"> #define UBRRH UBRR1H</span>
152 00145 <span class="preprocessor"></span><span class="preprocessor"> #define SIG_UART_TRANS SIG_UART1_TRANS</span>
153 00146 <span class="preprocessor"></span><span class="preprocessor"> #define SIG_UART_RECV SIG_UART1_RECV</span>
154 00147 <span class="preprocessor"></span><span class="preprocessor"> #define SIG_UART_DATA SIG_UART1_DATA</span>
155 00148 <span class="preprocessor"></span><span class="preprocessor">#else</span>
156 00149 <span class="preprocessor"></span><span class="preprocessor"> #define UDR UDR0</span>
157 00150 <span class="preprocessor"></span><span class="preprocessor"> #define UCR UCSR0B</span>
158 00151 <span class="preprocessor"></span><span class="preprocessor"> #define UBRRL UBRR0L</span>
159 00152 <span class="preprocessor"></span><span class="preprocessor"> #define UBRRH UBRR0H</span>
160 00153 <span class="preprocessor"></span><span class="preprocessor"> #define SIG_UART_TRANS SIG_UART0_TRANS</span>
161 00154 <span class="preprocessor"></span><span class="preprocessor"> #define SIG_UART_RECV SIG_UART0_RECV</span>
162 00155 <span class="preprocessor"></span><span class="preprocessor"> #define SIG_UART_DATA SIG_UART0_DATA</span>
163 00156 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
164 00157 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
165 00158 <span class="preprocessor"></span>
166 00159 <span class="comment">// functions</span>
167 00160 <span class="comment"></span>
168 00161 <span class="comment">//! Initializes uart.</span>
169 00162 <span class="comment">/// \note After running this init function, the processor</span>
170 00163 <span class="comment">/// I/O pins that used for uart communications (RXD, TXD)</span>
171 00164 <span class="comment">/// are no long available for general purpose I/O.</span>
172 00165 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__uart.html#ga0">uartInit</a>(<span class="keywordtype">void</span>);
173 00166 <span class="comment"></span>
174 00167 <span class="comment">//! Initializes transmit and receive buffers.</span>
175 00168 <span class="comment">/// Automatically called from uartInit()</span>
176 00169 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__uart.html#ga1">uartInitBuffers</a>(<span class="keywordtype">void</span>);
177 00170 <span class="comment"></span>
178 00171 <span class="comment">//! Redirects received data to a user function.</span>
179 00172 <span class="comment">///</span>
180 00173 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__uart.html#ga2">uartSetRxHandler</a>(<span class="keywordtype">void</span> (*rx_func)(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c));
181 00174 <span class="comment"></span>
182 00175 <span class="comment">//! Sets the uart baud rate.</span>
183 00176 <span class="comment">/// Argument should be in bits-per-second, like \c uartSetBaudRate(9600);</span>
184 00177 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__uart.html#ga3">uartSetBaudRate</a>(u32 baudrate);
185 00178 <span class="comment"></span>
186 00179 <span class="comment">//! Returns pointer to the receive buffer structure.</span>
187 00180 <span class="comment">///</span>
188 00181 <span class="comment"></span><a class="code" href="structstruct__cBuffer.html">cBuffer</a>* <a class="code" href="group__uart.html#ga4">uartGetRxBuffer</a>(<span class="keywordtype">void</span>);
189 00182 <span class="comment"></span>
190 00183 <span class="comment">//! Returns pointer to the transmit buffer structure.</span>
191 00184 <span class="comment">///</span>
192 00185 <span class="comment"></span><a class="code" href="structstruct__cBuffer.html">cBuffer</a>* <a class="code" href="group__uart.html#ga5">uartGetTxBuffer</a>(<span class="keywordtype">void</span>);
193 00186 <span class="comment"></span>
194 00187 <span class="comment">//! Sends a single byte over the uart.</span>
195 00188 <span class="comment">/// \note This function waits for the uart to be ready,</span>
196 00189 <span class="comment">/// therefore, consecutive calls to uartSendByte() will</span>
197 00190 <span class="comment">/// go only as fast as the data can be sent over the</span>
198 00191 <span class="comment">/// serial port.</span>
199 00192 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__uart.html#ga6">uartSendByte</a>(u08 data);
200 00193 <span class="comment"></span>
201 00194 <span class="comment">//! Gets a single byte from the uart receive buffer.</span>
202 00195 <span class="comment">/// Returns the byte, or -1 if no byte is available (getchar-style).</span>
203 00196 <span class="comment"></span><span class="keywordtype">int</span> <a class="code" href="group__uart.html#ga7">uartGetByte</a>(<span class="keywordtype">void</span>);
204 00197 <span class="comment"></span>
205 00198 <span class="comment">//! Gets a single byte from the uart receive buffer.</span>
206 00199 <span class="comment">/// Function returns TRUE if data was available, FALSE if not.</span>
207 00200 <span class="comment">/// Actual data is returned in variable pointed to by "data".</span>
208 00201 <span class="comment">/// Example usage:</span>
209 00202 <span class="comment">/// \code</span>
210 00203 <span class="comment">/// char myReceivedByte;</span>
211 00204 <span class="comment">/// uartReceiveByte( &amp;myReceivedByte );</span>
212 00205 <span class="comment">/// \endcode</span>
213 00206 <span class="comment"></span>u08 <a class="code" href="group__uart.html#ga8">uartReceiveByte</a>(u08* data);
214 00207 <span class="comment"></span>
215 00208 <span class="comment">//! Returns TRUE/FALSE if receive buffer is empty/not-empty.</span>
216 00209 <span class="comment">///</span>
217 00210 <span class="comment"></span>u08 <a class="code" href="group__uart.html#ga9">uartReceiveBufferIsEmpty</a>(<span class="keywordtype">void</span>);
218 00211 <span class="comment"></span>
219 00212 <span class="comment">//! Flushes (deletes) all data from receive buffer.</span>
220 00213 <span class="comment">///</span>
221 00214 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__uart.html#ga10">uartFlushReceiveBuffer</a>(<span class="keywordtype">void</span>);
222 00215 <span class="comment"></span>
223 00216 <span class="comment">//! Add byte to end of uart Tx buffer.</span>
224 00217 <span class="comment">/// Returns TRUE if successful, FALSE if failed (no room left in buffer).</span>
225 00218 <span class="comment"></span>u08 <a class="code" href="group__uart.html#ga11">uartAddToTxBuffer</a>(u08 data);
226 00219 <span class="comment"></span>
227 00220 <span class="comment">//! Begins transmission of the transmit buffer under interrupt control.</span>
228 00221 <span class="comment">///</span>
229 00222 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__uart.html#ga12">uartSendTxBuffer</a>(<span class="keywordtype">void</span>);
230 00223 <span class="comment"></span>
231 00224 <span class="comment">//! Sends a block of data via the uart using interrupt control.</span>
232 00225 <span class="comment">/// \param buffer pointer to data to be sent</span>
233 00226 <span class="comment">/// \param nBytes length of data (number of bytes to sent)</span>
234 00227 <span class="comment"></span>u08 <a class="code" href="group__uart.html#ga13">uartSendBuffer</a>(<span class="keywordtype">char</span> *buffer, u16 nBytes);
235 00228
236 00229 <span class="preprocessor">#endif</span>
237 00230 <span class="preprocessor"></span><span class="comment">//@}</span>
238 00231 <span class="comment"></span>
239 00232
240 </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:08 2006 for Procyon AVRlib by&nbsp;
241 <a href="http://www.doxygen.org/index.html">
242 <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address>
243 </body>
244 </html>
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3