基于51單片機(jī)RTL8019AS的網(wǎng)卡驅(qū)動程序
}本文引用地址:http://www.ex-cimer.com/article/172229.htm
if(txd_buffer_select) reg04=0x40; //txd packet start;
else reg04=0x46; //txd packet start;
reg06=length>>8; //high byte counter
reg05=length0xFF; //low byte counter
reg00=0x3E; //to sendpacket;
}
bit recv_packet(union netcard *rxdnet)//ne2000收包子程序
{
unsigned char i;
unsigned int ii;
unsigned char bnry,curr;
page(0);
reg07=0xFF;
bnry=reg03; //bnry page have read 讀頁指針
page(1);
curr=reg07; //curr writepoint 8019寫頁指針
page(0);
if(curr==0)
return 0; //讀的過程出錯
bnry=bnry++;
if(bnry>0x7F) bnry=0x4C;
if(bnry!=curr){ //此時表示有新的數(shù)據(jù)包在緩沖區(qū)里
//讀取一包的前18個字節(jié):4字節(jié)的8019頭部,6字節(jié)目的地址,6字節(jié)原地址,2字節(jié)協(xié)議
//在任何操作都最好返回page0
page(0);
reg09=bnry; //read page address high
reg08=0x00; //read page address low
reg0b=0x00; //read count high
reg0a=18; //read count low;
reg00=0x0A; //read dma
for(i=0;i18;i++)
rxdnet->bytes.bytebuf[i]=reg10;
i=rxdnet->bytes.bytebuf[3]; //將長度字段的高低字節(jié)掉轉(zhuǎn)
rxdnet->bytes.bytebuf[3]=rxdnet->bytes.bytebuf[2];
rxdnet->bytes.bytebuf[2]=i;
rxdnet->etherframe.length=rxdnet->etherframe.length-4; //去掉4個字節(jié)的CRC
//表示讀入的數(shù)據(jù)包有效
if(((rxdnet->bytes.bytebuf[0]0x01)==0)||(rxdnet->bytes.bytebuf[1]>0x7F)||(rxdnet->bytes.bytebuf[1]0x4C)||(rxdnet->bytes.bytebuf[2]>0x06)){
//接收狀態(tài)錯誤,或者next_page_start錯誤或者長度錯誤,將丟棄所有數(shù)據(jù)包
page(1);
curr=reg07; //page1
page(0); //切換回page0
bnry=curr-1;
if(bnry0x4C) bnry=0x7F;
reg03=bnry; //write to bnry
return 0;
}
else{//表示數(shù)據(jù)包是完好的.讀取剩下的數(shù)據(jù)
if((rxdnet->etherframe.protocal==0x0800)||(rxdnet->etherframe.protocal==0x0806)){
//協(xié)議為IP或ARP才接收
reg09=bnry; //read page address high
reg08=4; //read page address low
reg0b=rxdnet->etherframe.length>>8; //read count high
reg0a=rxdnet->etherframe.length0xFF; //read count low;
reg00=0x0A; //read dma
for(ii=4;iietherframe.length+4;ii++)
rxdnet->bytes.bytebuf[ii]=reg10;
}
bnry=rxdnet->bytes.bytebuf[1]-1;//next page start-1
if(bnry0x4C) bnry=0x7F;
reg03=bnry; //write to bnry
return 1; //have new packet
}
}
return 0;
}
評論