-------------------------------------------------------------------------------------------------------------- //返回值:0 表示没有收到新数据包,1 表示接收到新数据包 unsigned char Rec_NewPacket() { unsigned char i; unsigned int j; Page_Select(0); bnry=NIC_R03; //读页指针 ,bnry为全局变量 Page_Select(1); curr=NIC_R07; //写页指针 ,curr为全局变量 Page_Select(0); if(curr==0) return(0); //读的过程出错 bnry=bnry++; if(bnry>0x7f) bnry=0x4c; if(bnry!=curr) //表示有新的数据包在缓冲区里 { Page_Select(0); NIC_R09=bnry; //读页地址的高字节 NIC_R08=0x00; // NIC_R0b=0x00; // NIC_R0a=18; //由以太帧的结构和8019的特性决定 NIC_R00=0x0a; for(i=0;i<18;i++) //读取一数据包的前18个字节。4字节RTL8019AS头部,6字节目的地址,6字节源地址 //2字节协议 { NetD_R_Buf.bytes.bytebuf[i]=NIC_R10; // love[i]=NetD_R_Buf.bytes.bytebuf[i]; } //中止DMA操作 NIC_R0b=0x00; NIC_R0a=0x00; NIC_R00=0x22; i=NetD_R_Buf.bytes.bytebuf[3]; NetD_R_Buf.bytes.bytebuf[3]=NetD_R_Buf.bytes.bytebuf[2]; NetD_R_Buf.bytes.bytebuf[2]=i; NetD_R_Buf.EtherFrame.length=NetD_R_Buf.EtherFrame.length-4; //去掉4个字节的CRC // i=NetD_R_Buf.bytes.bytebuf[0]; if(((NetD_R_Buf.bytes.bytebuf[0]&0x01)==0)||(NetD_R_Buf.bytes.bytebuf[1]>0x7f)||(NetD_R_Buf.bytes.bytebuf[1]<0x4c)||(NetD_R_Buf.bytes.bytebuf[2]>0x06)) { //包接收错误或下一数据包起始页地址错误或接收的数据包长度>1536字节 Page_Select(1); curr=NIC_R07; Page_Select(0); bnry=curr-1; if(bnry<0x4c) bnry=0x7f; NIC_R03=bnry; NIC_R07=0xff; //清中断 } else //否则不是数据包是完好的,读取余下的数据 { fuck=NetD_R_Buf.EtherFrame.NextProtocol; fuc=NetD_R_Buf.words.wordbuf[2]; if((NetD_R_Buf.EtherFrame.NextProtocol==0x0800)||(NetD_R_Buf.EtherFrame.NextProtocol==0x0806)) { //为IP协议或ARP协议才接收 NIC_R09=bnry; NIC_R08=4; //去掉4字节的8019AS头 NIC_R0b=NetD_R_Buf.EtherFrame.length>>8; NIC_R0a=NetD_R_Buf.EtherFrame.length&0x00ff; NIC_R00=0x0a; for(j=4;j