📄 prism2_8c-source.html
字号:
00214 <span class="comment">// begin data copy again at type field</span>00215 prism2ReadBAP0(rxfid, 46+12+8, (u16*)&packet[12], packetLength-6);00216 <span class="comment">// ACK the receive event to finish up</span>00217 prism2Write16(PRISM2_REG_EVACK, PRISM2_EVENT_RX);00218 00219 <span class="keywordflow">return</span> packetLength;00220 }00221 00222 <span class="keywordtype">void</span> prism2InitPorts(<span class="keywordtype">void</span>)00223 {00224 <span class="preprocessor">#if NIC_CONNECTION == MEMORY_MAPPED</span>00225 <span class="preprocessor"></span> <span class="comment">// enable external SRAM interface - no wait states</span>00226 sbi(MCUSR, SRE);00227 <span class="preprocessor">#else</span>00228 <span class="preprocessor"></span> <span class="comment">// set address port to output</span>00229 outb(PRISM2_ADDRESS_DDR, PRISM2_ADDRESS_MASK);00230 outb(PRISM2_HADDRESS_DDR, PRISM2_HADDRESS_MASK);00231 00232 <span class="comment">// set data port to input with pull-ups</span>00233 outb(PRISM2_DATA_DDR, 0x00);00234 outb(PRISM2_DATA_PORT, 0xFF);00235 00236 <span class="comment">// initialize the control port read and write pins to de-asserted</span>00237 sbi( PRISM2_CONTROL_PORT, PRISM2_CONTROL_IORD );00238 sbi( PRISM2_CONTROL_PORT, PRISM2_CONTROL_IOWR );00239 sbi( PRISM2_CONTROL_PORT, PRISM2_CONTROL_MEMRD );00240 sbi( PRISM2_CONTROL_PORT, PRISM2_CONTROL_MEMWR );00241 <span class="comment">// set the read and write pins to output</span>00242 sbi( PRISM2_CONTROL_DDR, PRISM2_CONTROL_IORD );00243 sbi( PRISM2_CONTROL_DDR, PRISM2_CONTROL_IOWR );00244 sbi( PRISM2_CONTROL_DDR, PRISM2_CONTROL_MEMRD );00245 sbi( PRISM2_CONTROL_DDR, PRISM2_CONTROL_MEMWR );00246 <span class="preprocessor">#endif</span>00247 <span class="preprocessor"></span> <span class="comment">// set reset pin to output</span>00248 sbi( PRISM2_RESET_DDR, PRISM2_RESET_PIN );00249 00250 <span class="comment">// clear -REG pin</span>00251 sbi(DDRB, 6);00252 cbi(PORTB, 6);00253 <span class="comment">// setup IREQ pin</span>00254 cbi(DDRB, 7);00255 sbi(PORTB, 7);00256 }00257 00258 <span class="keywordtype">void</span> prism2Init(<span class="keywordtype">void</span>)00259 {00260 u08 result;00261 u16 buffer[20];00262 00263 rprintf(<span class="stringliteral">"Init ports\r\n"</span>);00264 prism2InitPorts();00265 00266 <span class="comment">// assert hardware reset</span>00267 sbi( PRISM2_RESET_PORT, PRISM2_RESET_PIN );00268 <span class="comment">// wait</span>00269 delay_ms(10);00270 <span class="comment">// release hardware reset</span>00271 cbi( PRISM2_RESET_PORT, PRISM2_RESET_PIN );00272 delay_ms(100);00273 00274 <span class="comment">/*</span>00275 <span class="comment"> // soft-reset card</span>00276 <span class="comment"> prism2WriteMem(0x3E0+PCMCIA_ATTR_COR, 0x80);</span>00277 <span class="comment"> delay_ms(10);</span>00278 <span class="comment"> prism2WriteMem(0x3E0+PCMCIA_ATTR_COR, 0x00);</span>00279 <span class="comment"> // wait until soft-reset is done</span>00280 <span class="comment"> delay_ms(500);</span>00281 <span class="comment"></span>00282 <span class="comment"> // set 8-bit PCMCIA I/O mode</span>00283 <span class="comment"> prism2WriteMem(0x3E0+PCMCIA_ATTR_CSR, 0x20);</span>00284 <span class="comment"></span>00285 <span class="comment"> prism2WriteMem(0x3E0+PCMCIA_ATTR_CSR, 0x04);</span>00286 <span class="comment"> timerPause(1000);</span>00287 <span class="comment"> prism2WriteMem(0x3E0+PCMCIA_ATTR_CSR, 0x00);</span>00288 <span class="comment">*/</span>00289 <span class="comment">// enable PCMCIA I/O mode</span>00290 prism2WriteMem(0x3E0+PCMCIA_ATTR_COR, prism2ReadMem(0x3E0+PCMCIA_ATTR_COR) | 0x01);00291 prism2CardRegDump();00292 00293 rprintf(<span class="stringliteral">"Prism2 Initializing...\r\n"</span>);00294 <span class="keywordflow">if</span>( (result = prism2Command(PRISM2_CMD_INIT,0)) )00295 {00296 rprintf(<span class="stringliteral">"Prism2 Initialization Failure\r\n"</span>);00297 rprintf(<span class="stringliteral">"Result Code = %x\r\n"</span>,result);00298 }00299 00300 rprintf(<span class="stringliteral">"Prism2 Initialized\r\n"</span>);00301 00302 <span class="comment">// set SSID</span>00303 prism2SetSSID(<span class="stringliteral">"airdrop"</span>);00304 00305 <span class="comment">// set max packet size</span>00306 buffer[0] = 0x0002;00307 buffer[1] = PRISM2_RID_CNFMAXDATALEN;00308 buffer[2] = 0x05DC;00309 prism2WriteRID(PRISM2_RID_CNFMAXDATALEN, 0, buffer, 3);00310 00311 <span class="comment">// set operating mode / port type</span>00312 buffer[0] = 0x0002;00313 buffer[1] = PRISM2_RID_CNFPORTTYPE;00314 <span class="comment">//buffer[2] = 0x0000; // IBSS</span>00315 buffer[2] = 0x0001; <span class="comment">// BSS</span>00316 prism2WriteRID(PRISM2_RID_CNFPORTTYPE, 0, buffer, 3);00317 00318 <span class="comment">// set channel</span>00319 <span class="comment">// buffer[0] = 0x0002;</span>00320 <span class="comment">// buffer[1] = 0xFC03;</span>00321 <span class="comment">// buffer[2] = 0x0001;</span>00322 <span class="comment">// prism2WriteRID(0xFC00, 0, buffer, 3);</span>00323 00324 <span class="comment">// enable the interface</span>00325 prism2Command(PRISM2_CMD_ENABLE_MAC0,0);00326 }00327 00328 <span class="keywordtype">void</span> prism2Off(<span class="keywordtype">void</span>)00329 {00330 <span class="comment">// turn off communication</span>00331 prism2Command(PRISM2_CMD_DISABLE_MAC0,0);00332 <span class="comment">// wait for all events to complete</span>00333 delay_ms(100);00334 <span class="comment">// reset card</span>00335 prism2Command(PRISM2_CMD_INIT,0);00336 }00337 00338 <span class="keywordtype">void</span> prism2GetMacAddress(u08* macaddr)00339 {00340 u16 buffer[5];00341 00342 <span class="comment">// read MAC address register</span>00343 prism2ReadRID(PRISM2_RID_CNFOWNMACADDR, 0, buffer, 5);00344 00345 *macaddr++ = buffer[2];00346 *macaddr++ = buffer[2]>>8;00347 *macaddr++ = buffer[3];00348 *macaddr++ = buffer[3]>>8;00349 *macaddr++ = buffer[4];00350 *macaddr++ = buffer[4]>>8;00351 }00352 00353 <span class="keywordtype">void</span> prism2SetSSID(u08* ssid)00354 {00355 u16 buffer[12];00356 00357 <span class="comment">// prepare buffer for SSID write</span>00358 buffer[0] = 0x0012;00359 buffer[1] = PRISM2_RID_CNFDESIREDSSID;00360 buffer[2] = strlen(ssid);00361 <span class="comment">// copy ssid string to buffer</span>00362 strcpy((<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*)&buffer[3], ssid);00363 <span class="comment">// write SSID</span>00364 prism2WriteRID(PRISM2_RID_CNFDESIREDSSID, 0, buffer, buffer[0]);00365 }00366 00367 <span class="keywordtype">void</span> prism2SetWEPKey(u08* wepkey)00368 {00369 u16 buffer[9];00370 00371 <span class="comment">// prepare buffer for SSID write</span>00372 buffer[0] = 0x0008;00373 buffer[1] = PRISM2_RID_CNFWEPDEFAULTKEY0;00374 <span class="comment">// copy ssid string to buffer</span>00375 strncpy((<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*)&buffer[2], wepkey, 13);00376 buffer[8] &= 0x00FF;00377 <span class="comment">// write SSID</span>00378 prism2WriteRID(PRISM2_RID_CNFWEPDEFAULTKEY0, 0, buffer, buffer[0]);00379 00380 <span class="comment">// set WEP active</span>00381 buffer[0] = 0x0002;00382 buffer[1] = PRISM2_RID_CNFWEPFLAGS;00383 buffer[2] = 0x0001;00384 prism2WriteRID(PRISM2_RID_CNFWEPFLAGS, 0, buffer, buffer[0]);00385 <span class="comment">// set WEP active</span>00386 buffer[0] = 0x0002;00387 buffer[1] = 0xfc2a;00388 buffer[2] = 0x0001;00389 prism2WriteRID(0xfc2a, 0, buffer, buffer[0]);00390 <span class="comment">// set WEP active</span>00391 buffer[0] = 0x0002;00392 buffer[1] = 0xfc23;00393 buffer[2] = 0x0000;00394 prism2WriteRID(0xfc23, 0, buffer, buffer[0]);00395 00396 }00397 00398 u08 prism2Command(u16 cmd, u16 param0)00399 {00400 u16 result;00401 00402 <span class="comment">// wait until card not busy</span>00403 <span class="comment">// rprintf("PRISM_CMD: Wait until card ready\r\n");</span>00404 <span class="keywordflow">while</span>(prism2Read16(PRISM2_REG_CMD) & PRISM2_CMD_BUSY);00405 00406 <span class="comment">// rprintf("PRISM_CMD: Issue Command = 0x%x\r\n", cmd);</span>00407 prism2Write16(PRISM2_REG_PARAM0, param0);00408 prism2Write16(PRISM2_REG_CMD, cmd);00409 00410 <span class="comment">// wait until card not busy</span>00411 <span class="comment">// rprintf("PRISM_CMD: Wait until card ready\r\n");</span>00412 <span class="keywordflow">while</span>(prism2Read16(PRISM2_REG_CMD) & PRISM2_CMD_BUSY);00413 00414 <span class="comment">// read event register - wait for command to complete</span>00415 <span class="comment">// rprintf("PRISM_CMD: Wait for command to complete\r\n");</span>00416 <span class="keywordflow">while</span>(!(prism2Read16(PRISM2_REG_EVSTAT) & PRISM2_EVENT_CMD));00417 00418 <span class="comment">// read status register</span>00419 result = prism2Read16(PRISM2_REG_STATUS)>>8;00420 <span class="comment">// rprintf("PRISM_CMD: Result = 0x%x\r\n", result>>8);</span>00421 <span class="comment">// rprintf("PRISM_CMD: CmdCode = 0x%x\r\n", result);</span>00422 00423 <span class="comment">// acknowledge event</span>00424 <span class="comment">// rprintf("PRISM_CMD: Ack command event\r\n");</span>00425 prism2Write16(PRISM2_REG_EVACK, PRISM2_EVENT_CMD);00426 00427 <span class="comment">// return command result</span>00428 <span class="keywordflow">return</span> result;00429 }00430 00431 u08 prism2ReadRID(u16 <span class="keywordtype">id</span>, u16 offset, u16* data, u16 len)00432 {00433 prism2Command(PRISM2_CMD_ACCESS_RD, <span class="keywordtype">id</span>);00434 <span class="keywordflow">return</span> prism2ReadBAP0(<span class="keywordtype">id</span>, offset, data, len);00435 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -