📄 dm9000.c
字号:
#include "MyLib.h"
U32 gEthInit;//用到gMyPhy[6];
U32 DM_readreg(U32 reg)
{
DM9000_ADDR=reg;
return DM9000_DATA;
}
void DM_writereg(U32 reg, U8 value)
{
DM9000_ADDR=reg;
DM9000_DATA=value;
}
void DM9000_SetPhy(U8 *Phy)
{
U32 i;
for(i=0; i<6; i++)
gMyPhy[i]=Phy[i];
}
U8 DM9000_init(void)
{
U32 i;
gEthInit=0;
GPDR1|=0x40000000;
GPSR1=0x40000000;
Delay_us(10000);
GPCR1=0x40000000;
Delay_us(100000);
DM_writereg(0x00, 0x01); // Reset DM9000
Delay_us(2000);
if((DM_readreg(0x28)==0x46)&&(DM_readreg(0x29)==0x0A)&&
(DM_readreg(0x2A)==0x00)&&(DM_readreg(0x2B)==0x90)){
gEthInit=1;
for(i=0; i<6; i++)
DM_writereg(16+i, gMyPhy[i]); // Set PHY address
for(i=0x16; i<=0x1D; i++) // Set Multicast Address
DM_writereg(i, 0xFF);
DM_writereg(0x1F, 0x00); // Power up PHY
DM_writereg(0xFF, 0x80); // Enable SRAM auto rewind
DM_writereg(0x05, 0x31); // RX enable, Discard Long Packet and CRC Error Packet
return 1;
}else{
return 0;
}
}
void RTL8019_SendBuf(U8 *buf,U32 len);// 发送一个数据包的命令,长度最小为60字节,最大1514字节
U32 RTL8019_RecvBuf(U8 *buf);
void DM9000_SendBuf(U8 *buf, U32 len)
{
RTL8019_SendBuf((U8*)buf,len);
}
U32 DM9000_RecvBuf(U8 *buf)
{
return RTL8019_RecvBuf((U8*)buf);
}
/*
void DM9000_SendBuf(U32 *buf, U32 len)
{
U32 i;
if(!gEthInit)
return;
DM9000_ADDR=0xF8; // Set Auto Increase mode
for(i=0; i<(len+3)/4; i++) // Fill TX data
DM9000_DATA=buf[i];
DM_writereg(0xFC, len&0xFF);
DM_writereg(0xFD, (len>>8)&0xFF);
DM_writereg(0x02, 0x01); // Send Start
while(DM_readreg(0x02)&0x01); // Wait until send complete
}
U32 DM9000_RecvBuf(U32 *buf)
{
U32 status,i,ret;
U16 RxStatus,RxLen;
if(!gEthInit)
return 0;
ret=0;
status=DM_readreg(0xF0); // Get RX status
status=DM_readreg(0xF0); // Get RX status
switch(status&0xFF){ // First byte must be 0 or 1
case 0: // No valid packet
break;
case 1: // Valid packet
status=DM_readreg(0xF2); // Read and move pointer
RxStatus=status&0xFFFF; RxLen=(status>>16)&0xFFFF;
if((RxStatus&0xBF00)||(RxLen<64)||(RxLen>1540)){ // Error
DM9000_init();
}else{
for(i=0; i<(RxLen+3)/4; i++)
buf[i]=DM9000_DATA;
ret=RxLen-4;
}
break;
default: // Error
DM9000_init();
break;
}
return ret;
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -