📄 uart_8h-source.html
字号:
<!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: uart.h Source File</title><link href="dox.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.6 --><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="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a></div><h1>uart.h</h1><a href="uart_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/*! \file uart.h \brief UART driver with buffer support. */</span>00002 <span class="comment">//*****************************************************************************</span>00003 <span class="comment">//</span>00004 <span class="comment">// File Name : 'uart.h'</span>00005 <span class="comment">// Title : UART driver with buffer support</span>00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2000-2002</span>00007 <span class="comment">// Created : 11/22/2000</span>00008 <span class="comment">// Revised : 02/01/2004</span>00009 <span class="comment">// Version : 1.3</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>00016 <span class="comment">//*****************************************************************************</span>00017 00018 <span class="preprocessor">#ifndef UART_H</span>00019 <span class="preprocessor"></span><span class="preprocessor">#define UART_H</span>00020 <span class="preprocessor"></span>00021 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>00022 <span class="preprocessor">#include "<a class="code" href="buffer_8h.html">buffer.h</a>"</span>00023 <span class="comment"></span>00024 <span class="comment">//! default baud rate</span>00025 <span class="comment">//! can be changed by using uartSetBaudRate()</span><a name="l00026"></a><a class="code" href="uart_8h.html#a0">00026</a> <span class="comment"></span><span class="preprocessor">#define UART_DEFAULT_BAUD_RATE 9600</span>00027 <span class="preprocessor"></span>00028 <span class="comment">// buffer memory allocation defines</span>00029 <span class="comment">// buffer sizes</span>00030 <span class="preprocessor">#ifndef UART_TX_BUFFER_SIZE</span><a name="l00031"></a><a class="code" href="uart_8h.html#a1">00031</a> <span class="preprocessor"></span><span class="preprocessor">#define UART_TX_BUFFER_SIZE 0x0040 </span><span class="comment">///< number of bytes for uart transmit buffer</span>00032 <span class="comment"></span>#endif00033 <span class="preprocessor">#ifndef UART_RX_BUFFER_SIZE</span><a name="l00034"></a><a class="code" href="uart_8h.html#a2">00034</a> <span class="preprocessor"></span><span class="preprocessor">#define UART_RX_BUFFER_SIZE 0x0040 </span><span class="comment">///< number of bytes for uart receive buffer</span>00035 <span class="comment"></span>#endif00036 00037 <span class="comment">// define this key if you wish to use</span>00038 <span class="comment">// external RAM for the UART buffers</span>00039 <span class="comment">//#define UART_BUFFER_EXTERNAL_RAM</span>00040 <span class="preprocessor">#ifdef UART_BUFFER_EXTERNAL_RAM</span>00041 <span class="preprocessor"></span> <span class="comment">// absolute address of uart buffers</span>00042 <span class="preprocessor"> #define UART_TX_BUFFER_ADDR 0x1000</span>00043 <span class="preprocessor"></span><span class="preprocessor"> #define UART_RX_BUFFER_ADDR 0x1100</span>00044 <span class="preprocessor"></span><span class="preprocessor">#endif</span>00045 <span class="preprocessor"></span>00046 <span class="comment">// type of interrupt handler to use</span>00047 <span class="comment">// *do not change unless you know what you're doing</span>00048 <span class="comment">// Value may be SIGNAL or INTERRUPT</span>00049 <span class="preprocessor">#ifndef UART_INTERRUPT_HANDLER</span>00050 <span class="preprocessor"></span><span class="preprocessor">#define UART_INTERRUPT_HANDLER SIGNAL</span>00051 <span class="preprocessor"></span><span class="preprocessor">#endif</span>00052 <span class="preprocessor"></span>00053 <span class="comment">// compatibility with most newer processors</span>00054 <span class="preprocessor">#ifdef UCSRB</span>00055 <span class="preprocessor"></span><span class="preprocessor"> #define UCR UCSRB</span>00056 <span class="preprocessor"></span><span class="preprocessor">#endif</span>00057 <span class="preprocessor"></span><span class="comment">// compatibility with old Mega processors</span>00058 <span class="preprocessor">#if defined(UBRR) && !defined(UBRRL)</span>00059 <span class="preprocessor"></span><span class="preprocessor"> #define UBRRL UBRR</span>00060 <span class="preprocessor"></span><span class="preprocessor">#endif</span>00061 <span class="preprocessor"></span><span class="comment">// compatibility with dual-uart processors</span>00062 <span class="comment">// (if you need to use both uarts, please use the uart2 library)</span>00063 <span class="preprocessor">#if defined(__AVR_ATmega128__)</span>00064 <span class="preprocessor"></span><span class="preprocessor"> #define UDR UDR0</span>00065 <span class="preprocessor"></span><span class="preprocessor"> #define UCR UCSR0B</span>00066 <span class="preprocessor"></span><span class="preprocessor"> #define UBRRL UBRR0L</span>00067 <span class="preprocessor"></span><span class="preprocessor"> #define UBRRH UBRR0H</span>00068 <span class="preprocessor"></span><span class="preprocessor"> #define SIG_UART_TRANS SIG_UART0_TRANS</span>00069 <span class="preprocessor"></span><span class="preprocessor"> #define SIG_UART_RECV SIG_UART0_RECV</span>00070 <span class="preprocessor"></span><span class="preprocessor"> #define SIG_UART_DATA SIG_UART0_DATA</span>00071 <span class="preprocessor"></span><span class="preprocessor">#endif</span>00072 <span class="preprocessor"></span><span class="preprocessor">#if defined(__AVR_ATmega161__)</span>00073 <span class="preprocessor"></span><span class="preprocessor"> #define UDR UDR0</span>00074 <span class="preprocessor"></span><span class="preprocessor"> #define UCR UCSR0B</span>00075 <span class="preprocessor"></span><span class="preprocessor"> #define UBRRL UBRR0</span>00076 <span class="preprocessor"></span><span class="preprocessor"> #define SIG_UART_TRANS SIG_UART0_TRANS</span>00077 <span class="preprocessor"></span><span class="preprocessor"> #define SIG_UART_RECV SIG_UART0_RECV</span>00078 <span class="preprocessor"></span><span class="preprocessor"> #define SIG_UART_DATA SIG_UART0_DATA</span>00079 <span class="preprocessor"></span><span class="preprocessor">#endif</span>00080 <span class="preprocessor"></span>00081 <span class="comment">// functions</span>00082 <span class="comment"></span>00083 <span class="comment">//! initializes transmit and receive buffers</span>00084 <span class="comment"></span><span class="comment">// called from uartInit()</span>00085 <span class="keywordtype">void</span> <a class="code" href="uart_8c.html#a10">uartInitBuffers</a>(<span class="keywordtype">void</span>);00086 <span class="comment"></span>00087 <span class="comment">//! initializes uart</span>00088 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="uart_8c.html#a9">uartInit</a>(<span class="keywordtype">void</span>);00089 <span class="comment"></span>00090 <span class="comment">//! redirects received data to a user function</span>00091 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="uart2_8h.html#a22">uartSetRxHandler</a>(<span class="keywordtype">void</span> (*rx_func)(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c));00092 <span class="comment"></span>00093 <span class="comment">//! sets the uart baud rate</span>00094 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="uart2_8h.html#a23">uartSetBaudRate</a>(u32 baudrate);00095 <span class="comment"></span>00096 <span class="comment">//! returns pointer to the receive buffer structure</span>00097 <span class="comment"></span>cBuffer* <a class="code" href="uart_8c.html#a13">uartGetRxBuffer</a>(<span class="keywordtype">void</span>);00098 <span class="comment"></span>00099 <span class="comment">//! returns pointer to the transmit buffer structure</span>00100 <span class="comment"></span>cBuffer* <a class="code" href="uart_8c.html#a14">uartGetTxBuffer</a>(<span class="keywordtype">void</span>);00101 <span class="comment"></span>00102 <span class="comment">//! sends a single byte over the uart</span>00103 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="uart2_8h.html#a26">uartSendByte</a>(u08 data);00104 <span class="comment"></span>00105 <span class="comment">//! gets a single byte from the uart receive buffer (getchar-style)</span>00106 <span class="comment"></span><span class="comment">// returns the byte, or -1 if no byte is available</span>00107 <span class="keywordtype">int</span> <a class="code" href="uart_8c.html#a16">uartGetByte</a>(<span class="keywordtype">void</span>);00108 <span class="comment"></span>00109 <span class="comment">//! gets a single byte from the uart receive buffer</span>00110 <span class="comment"></span><span class="comment">// Function returns TRUE if data was available, FALSE if not.</span>00111 <span class="comment">// Actual data is returned in variable pointed to by "data".</span>00112 <span class="comment">// example usage:</span>00113 <span class="comment">// char myReceivedByte;</span>00114 <span class="comment">// uartReceiveByte( &myReceivedByte );</span>00115 u08 <a class="code" href="uart2_8h.html#a31">uartReceiveByte</a>(u08* data);00116 <span class="comment"></span>00117 <span class="comment">//! returns TRUE/FALSE if receive buffer is empty/not-empty</span>00118 <span class="comment"></span>u08 <a class="code" href="uart_8c.html#a19">uartReceiveBufferIsEmpty</a>(<span class="keywordtype">void</span>);00119 <span class="comment"></span>00120 <span class="comment">//! flushes (deletes) all data from receive buffer</span>00121 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="uart_8c.html#a18">uartFlushReceiveBuffer</a>(<span class="keywordtype">void</span>);00122 <span class="comment"></span>00123 <span class="comment">//! add byte to end of uart Tx buffer</span>00124 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="uart2_8h.html#a34">uartAddToTxBuffer</a>(u08 data);00125 <span class="comment"></span>00126 <span class="comment">//! begins transmission of the transmit buffer under interrupt control</span>00127 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="uart_8c.html#a21">uartSendTxBuffer</a>(<span class="keywordtype">void</span>);00128 <span class="comment"></span>00129 <span class="comment">//! sends a buffer of length nBytes via the uart using interrupt control</span>00130 <span class="comment"></span>u08 <a class="code" href="uart2_8h.html#a38">uartSendBuffer</a>(<span class="keywordtype">char</span> *buffer, u16 nBytes);00131 00132 <span class="preprocessor">#endif</span>00133 <span class="preprocessor"></span>00134 </pre></div><hr size="1"><address style="align: right;"><small>Generated on Fri Oct 15 03:50:22 2004 for Procyon AVRlib by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 > </a>1.3.6 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -