⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ft245_8c-source.html

📁 方便飞利浦arm7tdmi 处理器lpc2100开发的C函数库 Procyon ARMlib-LPC2100 C-Language Function Library for Philips LPC21
💻 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 ARMlib-LPC2100: ft245.c 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&nbsp;Page</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="globals.html">Globals</a></div><h1>ft245.c</h1><a href="ft245_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/*! \file ft245.c \brief FTDI FT245 USB Inferface Driver Library. */</span>00002 <span class="comment">//*****************************************************************************</span>00003 <span class="comment">//</span>00004 <span class="comment">// File Name    : 'ft245.c'</span>00005 <span class="comment">// Title        : FTDI FT245 USB Inferface Driver Library</span>00006 <span class="comment">// Author       : Pascal Stang - Copyright (C) 2004</span>00007 <span class="comment">// Created      : 2004.02.10</span>00008 <span class="comment">// Revised      : 2004.02.19</span>00009 <span class="comment">// Version      : 0.1</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">// NOTE: This code is currently below version 1.0, and therefore is considered</span>00014 <span class="comment">// to be lacking in some functionality or documentation, or may not be fully</span>00015 <span class="comment">// tested.  Nonetheless, you can expect most functions to work.</span>00016 <span class="comment">//</span>00017 <span class="comment">// This code is distributed under the GNU Public License</span>00018 <span class="comment">//      which can be found at http://www.gnu.org/licenses/gpl.txt</span>00019 <span class="comment">//</span>00020 <span class="comment">//*****************************************************************************</span>00021 00022 <span class="preprocessor">#include "lpc210x.h"</span>00023 <span class="comment">//#include &lt;avr/io.h&gt;</span>00024 <span class="comment">//#include &lt;avr/signal.h&gt;</span>00025 <span class="comment">//#include &lt;avr/interrupt.h&gt;</span>00026 00027 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>00028 <span class="preprocessor">#include "<a class="code" href="timer_8h.html">timer.h</a>"</span>00029 <span class="preprocessor">#include "<a class="code" href="membus_8h.html">membus.h</a>"</span>00030 <span class="preprocessor">#include "<a class="code" href="ft245_8h.html">ft245.h</a>"</span>00031 00032 <span class="comment">// global variables</span>00033 <span class="keyword">static</span> <span class="keywordtype">char</span> ft245RxData[FT245_RX_BUFFER_SIZE];00034 cBuffer ft245RxBuffer;00035 00036 <span class="comment">// Functions</span>00037 <span class="keywordtype">void</span> ft245Init(<span class="keywordtype">void</span>)00038 {00039 <span class="preprocessor">#ifdef FT245_PORT_INTERFACE</span>00040 <span class="preprocessor"></span>    <span class="comment">// initialize port pins</span>00041     <span class="comment">// configure input pins</span>00042     cbi(FT245_CTRL_DDR, FT245_TXE);00043     cbi(FT245_CTRL_DDR, FT245_RXF);00044     <span class="comment">//cbi(FT245_CTRL_DDR, FT245_SUSPEND);</span>00045     <span class="comment">// use pullups</span>00046     sbi(FT245_CTRL_PORT, FT245_TXE);00047     sbi(FT245_CTRL_PORT, FT245_RXF);00048     <span class="comment">//sbi(FT245_CTRL_PORT, FT245_SUSPEND);</span>00049 00050     <span class="comment">// configure output pins</span>00051     sbi(FT245_CTRL_DDR, FT245_RESET);00052     sbi(FT245_CTRL_DDR, FT245_WR);00053     sbi(FT245_CTRL_DDR, FT245_RD);00054     <span class="comment">// preset the outputs</span>00055     sbi(FT245_CTRL_PORT, FT245_RESET);00056     cbi(FT245_CTRL_PORT, FT245_WR);00057     sbi(FT245_CTRL_PORT, FT245_RD);00058 00059     <span class="comment">// configure data bus</span>00060     outb(FT245_DATA_DDR, 0x00);00061     outb(FT245_DATA_PORT, 0xFF);00062 <span class="preprocessor">#endif</span>00063 <span class="preprocessor"></span><span class="preprocessor">#ifdef FT245_PORT_INTERFACE</span>00064 <span class="preprocessor"></span>    <span class="comment">// initialize the memory bus</span>00065     membusInit();00066     <span class="comment">// configure status pins</span>00067     IODIR &amp;= FT245_TXE;00068     IODIR &amp;= FT245_RXF;00069 <span class="preprocessor">#endif</span>00070 <span class="preprocessor"></span>    <span class="comment">// initialize the RX buffer</span>00071     <a class="code" href="buffer_8h.html#a1">bufferInit</a>(&amp;ft245RxBuffer, ft245RxData, FT245_RX_BUFFER_SIZE);00072 00073     <span class="comment">// reset the FT245</span>00074     <span class="comment">//ft245Reset();</span>00075 00076 }00077 00078 <span class="keywordtype">void</span> ft245Reset(<span class="keywordtype">void</span>)00079 {00080 <span class="preprocessor">#ifdef FT245_PORT_INTERFACE</span>00081 <span class="preprocessor"></span>    <span class="comment">// activate reset line</span>00082     cbi(FT245_CTRL_PORT, FT245_RESET);00083     <span class="comment">// hold for 1ms</span>00084     timerPause(1);00085     <span class="comment">// release reset</span>00086     sbi(FT245_CTRL_PORT, FT245_RESET);00087 <span class="preprocessor">#endif</span>00088 <span class="preprocessor"></span><span class="preprocessor">#ifdef FT245_MEMBUS_INTERFACE</span>00089 <span class="preprocessor"></span>00090 <span class="preprocessor">#endif</span>00091 <span class="preprocessor"></span>}00092 00093 u08 ft245ReadByte(<span class="keywordtype">void</span>)00094 {00095 <span class="preprocessor">#ifdef FT245_PORT_INTERFACE</span>00096 <span class="preprocessor"></span>    u08 data;00097     <span class="comment">// data bus set for input</span>00098     outb(FT245_DATA_DDR, 0x00);00099     <span class="comment">// assert RD line</span>00100     cbi(FT245_CTRL_PORT, FT245_RD);00101     <span class="comment">// wait</span>00102     <span class="keyword">asm</span> <span class="keyword">volatile</span> (<span class="stringliteral">"nop"</span>);00103     <span class="keyword">asm</span> <span class="keyword">volatile</span> (<span class="stringliteral">"nop"</span>);00104     <span class="keyword">asm</span> <span class="keyword">volatile</span> (<span class="stringliteral">"nop"</span>);00105     <span class="keyword">asm</span> <span class="keyword">volatile</span> (<span class="stringliteral">"nop"</span>);00106     <span class="comment">// read data</span>00107     data = inb(FT245_DATA_PORTIN);00108     <span class="comment">// release RD line</span>00109     sbi(FT245_CTRL_PORT, FT245_RD);00110     <span class="comment">// return data</span>00111     <span class="keywordflow">return</span> data;00112 <span class="preprocessor">#endif</span>00113 <span class="preprocessor"></span><span class="preprocessor">#ifdef FT245_MEMBUS_INTERFACE</span>00114 <span class="preprocessor"></span>    <span class="keywordflow">return</span> membusRead(FT245_BASE_ADDRESS);00115 <span class="preprocessor">#endif</span>00116 <span class="preprocessor"></span>}00117 00118 <span class="keywordtype">void</span> ft245WriteByte(u08 data)00119 {00120 <span class="preprocessor">#ifdef FT245_PORT_INTERFACE</span>00121 <span class="preprocessor"></span>    <span class="comment">// wait for transmit fifo to be ready</span>00122     <span class="keywordflow">while</span>(!ft245CheckTxFifo());00123     <span class="comment">// assert WR line</span>00124     sbi(FT245_CTRL_PORT, FT245_WR);00125     <span class="comment">// data bus set for output</span>00126     outb(FT245_DATA_DDR, 0xFF);00127     <span class="comment">// write data</span>00128     outb(FT245_DATA_PORT, data);00129     <span class="comment">// wait</span>00130     <span class="keyword">asm</span> <span class="keyword">volatile</span> (<span class="stringliteral">"nop"</span>);00131     <span class="keyword">asm</span> <span class="keyword">volatile</span> (<span class="stringliteral">"nop"</span>);00132     <span class="keyword">asm</span> <span class="keyword">volatile</span> (<span class="stringliteral">"nop"</span>);00133     <span class="keyword">asm</span> <span class="keyword">volatile</span> (<span class="stringliteral">"nop"</span>);00134     <span class="comment">// release WR line</span>00135     cbi(FT245_CTRL_PORT, FT245_WR);00136     <span class="comment">// return data bus to input + pullups</span>00137     outb(FT245_DATA_DDR, 0x00);00138     outb(FT245_DATA_PORT, 0xFF);00139 <span class="preprocessor">#endif</span>00140 <span class="preprocessor"></span><span class="preprocessor">#ifdef FT245_MEMBUS_INTERFACE</span>00141 <span class="preprocessor"></span>    <span class="keywordflow">return</span> membusWrite(FT245_BASE_ADDRESS, data);00142 <span class="preprocessor">#endif</span>00143 <span class="preprocessor"></span>}00144 00145 u08 ft245CheckRxFifo(<span class="keywordtype">void</span>)00146 {00147     <span class="comment">// check state of RXF line</span>00148     <span class="comment">// RXF = L  =&gt; Data in fifo ready to be read</span>00149     <span class="comment">// RXF = H  =&gt; No data, or not ready</span>00150 <span class="preprocessor">#ifdef FT245_PORT_INTERFACE</span>00151 <span class="preprocessor"></span>    <span class="keywordflow">if</span>( inb(FT245_CTRL_PORTIN) &amp; (1&lt;&lt;FT245_RXF) )00152         <span class="keywordflow">return</span> FALSE;   <span class="comment">// no data</span>00153     <span class="keywordflow">else</span>00154         <span class="keywordflow">return</span> TRUE;    <span class="comment">// data is available</span>00155 <span class="preprocessor">#endif</span>00156 <span class="preprocessor"></span><span class="preprocessor">#ifdef FT245_MEMBUS_INTERFACE</span>00157 <span class="preprocessor"></span>    <span class="keywordflow">if</span>(IOPIN &amp; FT245_RXF)00158         <span class="keywordflow">return</span> FALSE;   <span class="comment">// no data</span>00159     <span class="keywordflow">else</span>00160         <span class="keywordflow">return</span> TRUE;    <span class="comment">// data is available</span>00161 <span class="preprocessor">#endif</span>00162 <span class="preprocessor"></span>}00163 00164 u08 ft245CheckTxFifo(<span class="keywordtype">void</span>)00165 {00166     <span class="comment">// check state of TXE line</span>00167     <span class="comment">// TXE = L  =&gt; Tx fifo is ready to be written</span>00168     <span class="comment">// TXE = H  =&gt; Tx fifo full or not ready</span>00169 <span class="preprocessor">#ifdef FT245_PORT_INTERFACE</span>00170 <span class="preprocessor"></span>    <span class="keywordflow">if</span>( inb(FT245_CTRL_PORTIN) &amp; (1&lt;&lt;FT245_TXE) )00171         <span class="keywordflow">return</span> FALSE;   <span class="comment">// full or not ready</span>00172     <span class="keywordflow">else</span>00173         <span class="keywordflow">return</span> TRUE;    <span class="comment">// tx fifo space is available</span>00174 <span class="preprocessor">#endif</span>00175 <span class="preprocessor"></span><span class="preprocessor">#ifdef FT245_MEMBUS_INTERFACE</span>00176 <span class="preprocessor"></span>    <span class="keywordflow">if</span>(IOPIN &amp; FT245_TXE)00177         <span class="keywordflow">return</span> FALSE;   <span class="comment">// full or not ready</span>00178     <span class="keywordflow">else</span>00179         <span class="keywordflow">return</span> TRUE;    <span class="comment">// tx fifo space is available</span>00180 <span class="preprocessor">#endif</span>00181 <span class="preprocessor"></span>}00182 00183 <span class="comment">/*</span>00184 <span class="comment">u08 ft245IsSuspended(void)</span>00185 <span class="comment">{</span>00186 <span class="comment">    // check state of SUSPEND line</span>00187 <span class="comment">    // SUSPEND = L  =&gt; Data in fifo ready to be read</span>00188 <span class="comment">    // SUSPEND = H  =&gt; No data, or not ready</span>00189 <span class="comment">    if( inb(FT245_CTRL_PORTIN) &amp; (1&lt;&lt;FT245_RXF) )</span>00190 <span class="comment">        return FALSE;   // no data</span>00191 <span class="comment">    else</span>00192 <span class="comment">        return TRUE;    // data is available</span>00193 <span class="comment">}</span>00194 <span class="comment">*/</span>00195 00196 cBuffer* ft245GetRxBuffer(<span class="keywordtype">void</span>)00197 {00198     <span class="comment">// since there is an internal buffer in the FT245 chip</span>00199     <span class="comment">// we don't read in bytes immediately on reception.</span>00200     <span class="comment">// instead, the FT245 buffer is read in when the </span>00201     <span class="comment">// receive buffer is requested</span>00202 00203     <span class="comment">// read in receive buffer</span>00204     <span class="keywordflow">while</span>(ft245CheckRxFifo())00205     {00206         <a class="code" href="buffer_8h.html#a5">bufferAddToEnd</a>(&amp;ft245RxBuffer, ft245ReadByte());00207     }00208 00209     <span class="keywordflow">return</span> &amp;ft245RxBuffer;00210 }</pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue Jul 13 03:38:11 2004 for Procyon ARMlib-LPC2100 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 + -