📄 prism2_8c-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: net/prism2.c 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><div class="nav"><a class="el" href="dir_000001.html">net</a></div><h1>prism2.c</h1><a href="prism2_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file prism2.c \brief Prism2 802.11b Wireless-LAN Interface Driver. */</span>00002 <span class="comment">//*****************************************************************************</span>00003 <span class="comment">//</span>00004 <span class="comment">// File Name : 'prism2.c'</span>00005 <span class="comment">// Title : Prism2 802.11b Wireless-LAN Interface Driver</span>00006 <span class="comment">// Author : Pascal Stang</span>00007 <span class="comment">// Created : 12/27/2004</span>00008 <span class="comment">// Revised : 1/7/2005</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">// Description : This driver provides initialization and transmit/receive</span>00014 <span class="comment">// functions for the Prism2 802.11b Wireless-LAN Controller.</span>00015 <span class="comment">//</span>00016 <span class="comment">//*****************************************************************************</span>00017 00018 <span class="preprocessor">#include <avr/io.h></span>00019 <span class="preprocessor">#include <avr/interrupt.h></span>00020 <span class="preprocessor">#include <string.h></span>00021 00022 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>00023 <span class="preprocessor">#include "<a class="code" href="timer_8h.html">timer.h</a>"</span>00024 <span class="preprocessor">#include "<a class="code" href="rprintf_8h.html">rprintf.h</a>"</span>00025 <span class="preprocessor">#include "<a class="code" href="debug_8h.html">debug.h</a>"</span>00026 00027 <span class="preprocessor">#include "<a class="code" href="net_8h.html">net.h</a>"</span>00028 <span class="preprocessor">#include "<a class="code" href="prism2_8h.html">prism2.h</a>"</span>00029 00030 <span class="comment">// include configuration</span>00031 <span class="preprocessor">#include "<a class="code" href="prism2conf_8h.html">prism2conf.h</a>"</span>00032 00033 u16 TxHeader[34];00034 <a name="l00035"></a><a class="code" href="group__nic.html#ga0">00035</a> <span class="keywordtype">void</span> <a class="code" href="group__nic.html#ga0">nicInit</a>(<span class="keywordtype">void</span>)00036 {00037 prism2Init();00038 }00039 <a name="l00040"></a><a class="code" href="group__nic.html#ga1">00040</a> <span class="keywordtype">void</span> <a class="code" href="group__nic.html#ga1">nicSend</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> len, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* packet)00041 {00042 u16 i;00043 u16 txfid;00044 u08 stat;00045 <span class="comment">// request free buffer space to store outgoing frame</span>00046 prism2Command(PRISM2_CMD_ALLOC, len+44+14+6);00047 <span class="comment">// wait for buffer to be allocated</span>00048 <span class="keywordflow">while</span>( !(prism2Read16(PRISM2_REG_EVSTAT) & PRISM2_EVENT_ALLOC) );00049 <span class="comment">// get the buffer FID</span>00050 txfid = prism2Read16(PRISM2_REG_ALLOCFID);00051 <span class="comment">// ACK the alloc event</span>00052 prism2Write16(PRISM2_REG_EVACK, PRISM2_EVENT_ALLOC);00053 00054 <span class="comment">// rprintf("PRISM2: TxFID=0x");</span>00055 <span class="comment">// rprintfu16(txfid);</span>00056 <span class="comment">// rprintfCRLF();</span>00057 00058 <span class="comment">// adjust packet length because MAC addresses and type</span>00059 <span class="comment">// will be written seperately from packet payload</span>00060 len-=14;00061 00062 <span class="comment">// write the outgoing frame to BAP</span>00063 <span class="comment">// begin with control structure</span>00064 prism2SetupTxHeader(TxHeader);00065 00066 <span class="comment">// write dest and src MAC addresses</span>00067 <span class="keywordflow">for</span>(i=0;i<6;++i)00068 TxHeader[23+i] = packet[i*2+1]<<8 | packet[i*2];00069 <span class="comment">// write length</span>00070 TxHeader[29] = <a class="code" href="group__net.html#ga2">htons</a>(len+8);00071 <span class="comment">// write type</span>00072 TxHeader[33] = packet[13]<<8 | packet[12];00073 00074 <span class="comment">// debugPrintHexTable(34*2, (u08*)TxHeader);</span>00075 <span class="comment">// rprintfCRLF();</span>00076 <span class="comment">// debugPrintHexTable(len, &packet[14]);</span>00077 00078 <span class="comment">// write Tx header out to BAP</span>00079 prism2WriteBAP0(txfid, 0, TxHeader, 34);00080 <span class="comment">// write packet out to BAP</span>00081 prism2WriteBAP0(txfid, 68, (u16*)&packet[14], (len+1)>>1);00082 <span class="comment">// issue transmit command </span>00083 stat = prism2Command(PRISM2_CMD_TX, txfid);00084 <span class="keywordflow">if</span>(stat)00085 rprintf(<span class="stringliteral">"Transmit failed: 0x%x\r\n"</span>, stat);00086 <span class="comment">// do cleanup</span>00087 prism2EventCheck();00088 }00089 00090 <span class="keywordtype">void</span> nicGetMacAddress(u08* macaddr)00091 {00092 prism2GetMacAddress(macaddr);00093 }00094 00095 <span class="keywordtype">void</span> nicSetMacAddress(u08* macaddr)00096 {00097 <span class="comment">// not yet supported</span>00098 }00099 <a name="l00100"></a><a class="code" href="group__nic.html#ga5">00100</a> <span class="keywordtype">void</span> <a class="code" href="group__nic.html#ga5">nicRegDump</a>(<span class="keywordtype">void</span>)00101 {00102 prism2CardRegDump();00103 prism2RegDump();00104 }00105 00106 <span class="keywordtype">void</span> prism2SetupTxHeader(u16* header)00107 {00108 u16 i;00109 00110 <span class="comment">// clear out header</span>00111 <span class="keywordflow">for</span>(i=0;i<22;i++)00112 header[i] = 0x00;00113 00114 <span class="comment">// set TxRate and retry count</span>00115 header[5] = (0<<8) | 0;00116 <span class="comment">// 0x00 = automatic selection</span>00117 <span class="comment">// 0x0A = 10 = 1.0Mbit/s</span>00118 <span class="comment">// 0x14 = 20 = 2.0Mbit/s</span>00119 <span class="comment">// 0x37 = 55 = 5.5Mbit/s</span>00120 <span class="comment">// 0x6E = 110 = 11 Mbit/s</span>00121 00122 <span class="comment">// set TxControl</span>00123 header[6] = 0x0004;00124 00125 <span class="comment">// write length</span>00126 <span class="comment">// (not really needed since card will pull info from 802.3 header)</span>00127 <span class="comment">//TxHeader[22] = len+8;</span>00128 00129 <span class="comment">// fill in 802.3 header fields</span>00130 TxHeader[30] = 0xAAAA;00131 TxHeader[31] = 0x0003;00132 TxHeader[32] = 0x0000;00133 00134 <span class="comment">// src mac address @ byte offset 52</span>00135 }00136 00137 <span class="keywordtype">void</span> prism2EventCheck(<span class="keywordtype">void</span>)00138 {00139 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> evstat_data;00140 00141 evstat_data = prism2Read16(PRISM2_REG_EVSTAT);00142 00143 <span class="keywordflow">if</span>(evstat_data & PRISM2_EVENT_TX)00144 {00145 prism2Write16(PRISM2_REG_EVACK,PRISM2_EVENT_TX);00146 }00147 00148 <span class="keywordflow">if</span>(evstat_data & PRISM2_EVENT_TXEXEC)00149 {00150 prism2Write16(PRISM2_REG_EVACK,PRISM2_EVENT_TXEXEC);00151 }00152 00153 <span class="keywordflow">if</span>(evstat_data & PRISM2_EVENT_ALLOC)00154 {00155 prism2Write16(PRISM2_REG_EVACK, 0x0002);00156 }00157 00158 <span class="keywordflow">if</span>(evstat_data & PRISM2_EVENT_CMD)00159 {00160 prism2Write16(PRISM2_REG_EVACK, PRISM2_EVENT_CMD);00161 }00162 00163 <span class="keywordflow">if</span>(evstat_data & PRISM2_EVENT_INFO)00164 {00165 prism2Read16(PRISM2_REG_INFOFID);00166 prism2Write16(PRISM2_REG_EVACK, PRISM2_EVENT_INFO);00167 }00168 00169 <span class="keywordflow">if</span>(evstat_data & PRISM2_EVENT_INFDROP)00170 {00171 prism2Write16(PRISM2_REG_EVACK, PRISM2_EVENT_INFDROP);00172 }00173 00174 <span class="keywordflow">if</span>(evstat_data & PRISM2_EVENT_WTERR)00175 {00176 prism2Write16(PRISM2_REG_EVACK, PRISM2_EVENT_WTERR);00177 }00178 }00179 00180 <a name="l00181"></a><a class="code" href="group__nic.html#ga2">00181</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="group__nic.html#ga2">nicPoll</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> maxlen, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* packet)00182 {00183 u16 rxfid=0;00184 u16 packetLength=0;00185 00186 <span class="comment">// check if packets have been received</span>00187 <span class="keywordflow">if</span>(prism2Read16(PRISM2_REG_EVSTAT) & PRISM2_EVENT_RX)00188 {00189 <span class="comment">// we have a receive event</span>00190 <span class="comment">// get RxFID</span>00191 rxfid = prism2Read16(PRISM2_REG_RXFID);00192 <span class="comment">// read the packet length</span>00193 prism2ReadBAP0(rxfid, 44, &packetLength, 1);00194 }00195 00196 <span class="comment">// if there's no packet or an error - exit</span>00197 <span class="keywordflow">if</span>( !packetLength )00198 <span class="keywordflow">return</span> 0;00199 00200 <span class="comment">// drop anything too big for the buffer</span>00201 <span class="keywordflow">if</span>( packetLength > maxlen )00202 {00203 <span class="comment">// ACK the receive event to finish up</span>00204 prism2Write16(PRISM2_REG_EVACK, PRISM2_EVENT_RX);00205 <span class="keywordflow">return</span> 0;00206 }00207 00208 <span class="comment">// packet is available, retrieve data</span>00209 <span class="comment">// this is a hack: while reading in data,</span>00210 <span class="comment">// convert 802.2/3 header to ethernet header</span>00211 <span class="comment">// first get dest and src MAC addresses</span>00212 prism2ReadBAP0(rxfid, 46, (u16*)&packet[0], 6);00213 <span class="comment">// skip length, snap, and ctrl fields</span>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -