读出来的数是错的.
正确包如:
00 01 02 03 04 05 06 07 ......
现在读成了:
00 02 04 06 ......
起初我以为是c=r10; 造成的,但后来去掉这句
则变成00 00 02 02 04 04 06 06......
请教各位,是何原因?
而读取的却是:
FF FF FF D0 09 77 00 00 54 A1 00 11 A7 A8
很明显,NIC接收正确,但我读取DMA时错。这是为什么?
请各虾们指点。谢谢
另:我用的是DM9008,但我认真看了9008与8019的说明书,
并没什么区别。
以下是程序.
/* store 类似于 outportb */
/* take 类似于 inport */
void Ne2000Init()
{
set_io(ETH_RST,1);
delay_20ms();
set_io(ETH_RST,0);
delay_20ms(); /* DM9008 RESET */
store(ETH_R00,0x22);
store(ETH_R01,0x4c); /* Pstart 接收缓冲区起始页 */
store(ETH_R02,0x80); /* Pstop 接收缓冲区结束页 */
store(ETH_R03,0x4c); /* NBRY 已被读取的页 */
store(ETH_R04,0x45); /* TPSR 发送缓冲区起始页 */
store(ETH_R0C,0xcc); /* RCR 接收配置 0xcc */
store(ETH_R0D,0xe0); /* TCR 接收配置 */
store(ETH_R0E,0xc8); /* DCR DMA数据配置 */
store(ETH_R0F,0x00); /* IMR 中断配置 */
page(1);
store(ETH_R07,0x4d); /* CURR 接收指针 */
store(ETH_R08,0x00); /* MAR0----MAR7 */
store(ETH_R09,0x41);
store(ETH_R0A,0x00);
store(ETH_R0B,0x80);
store(ETH_R0C,0x00);
store(ETH_R0D,0x00);
store(ETH_R0E,0x00);
store(ETH_R0F,0x00);
page(0);
}
/* 从任何一个位置读 8019RAM地址 数据区 字节数 */
void ReadNe2000Ram(uint ram_addr,uchar *buf,int len)
{
uint ui;
uchar uc;
int i;
page(0);
ui=(ram_addr & 0xff00)>>8;
uc=(char)ui;
store(ETH_R09,uc); /* Set High address */
ui=ram_addr & 0x00ff;
uc=(char)ui;
store(ETH_R08,uc); /* Set low address */
ui=( (len*2) & 0xff00)>>8; /* len or len*2? */
uc=(char)ui;
store(ETH_R0B,uc); /* Set read counter High */
ui=( len*2 ) & 0x00ff; /* len or len*2? */
uc=(char)ui;
store(ETH_R0A,uc); /* Set read counter low */
store(ETH_R00,0x0a); /* Read DMA */
for(i=0;i<len;i++)
{
uc=take(ETH_R10);
buf[i]=uc;
take(ETH_R10); /* 抛弃一个,如果不抛弃,则变成
FF FF FF FF FF FF D0 D0 09 09
77 77 00 00 ....(真是,该来的
不来,不该来的却来了)
*/
}
}
/* 写8019的RAM 8019RAM地址 数据区 字节数 */
void WriteNe2000Ram(uint ram_addr,uchar *buf,int len)
{
uint ui;
uchar uc;
int i;
page(0);
ui=(ram_addr & 0xff00)>>8;
uc=(char)ui;
store(ETH_R09,uc); /* Set High address */
ui=ram_addr & 0x00ff;
uc=(char)ui;
store(ETH_R08,uc); /* Set low address */
ui=((len*2) & 0xff00)>>8; /* len or len*2? */
uc=(char)ui;
store(ETH_R0B,uc); /* Set read counter High */
ui=(len*2) & 0x00ff; /* len or len*2? */
uc=(char)ui;
store(ETH_R0A,uc); /* Set read counter low */
store(ETH_R00,0x12); /* 00 010 0 10 Write DMA */
for(i=0;i<len;i++){store(ETH_R10,buf[i]); store(ETH_R10,buf[i]); }
}
/* 读8019已接收但还未被读取的当前页 */
void ReadOnePage(char *buf)
{
int address;
uchar c;
c=take(ETH_R03); /* Get Now BNRY */
c++;
address=c;
address=address<<8;
ReadNe2000Ram(address,buf,256);
if(c==RcvBufEnd) c=RcvBufBeg;
store(ETH_R03,c); /* BNRY=BNRY+1 */
}
如果设成16位DMA,我把DCR=CD C9 CB,均不行,而且错得更离谱。