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