|
新手请教一个网卡驱动的问题(对网卡芯片的操作,不涉及TCP/IP)
[复制链接]
我用的控制芯片为S3C2410,网卡芯片是AX88796, 网卡在BANK2上,基地址为0x200,逻辑地址为0x10000200。Ax88796的寄存器宽度为8位,映射到从基地址200h到21fh地址空间内。
首先是两个对Ax88796的寄存器读写的操作函数:ax88796Write()和ax88796Read()
void ax88796Write(unsigned char regno,unsigned char val)
{
*(volatile unsigned char *)(regno+MEMORY_BASIC_AX88796) = val;
}
unsigned char ax88796Read(unsigned char regno)
{
return (*(unsigned char *) (regno+MEMORY_BASIC_AX88796));
}
其中#define MEMORY_BASIC_AX88796 0x10000200
然后是AX88796 控制寄存器的偏移值:
// AX88796 控制寄存器的偏移值
// Page 0 - 读/写
#define CR 0x00 // Command Register
#define PSTART 0x01 // Page Start Register
#define PSTOP 0x02 // Page Stop Register
#define BNRY 0x03 // Boundary Pointer
#define RDMAPORT 0x10 // DMA Data Port
#define MEMR 0x14 // MII/EEPROM Access Register
#define TR 0x15 // Test Register
#define SPP_DPR 0x18 // Standard Printer Port Data
#define SSP_SPR 0x19 // Standard Printer Port Status
#define SSP_CPR 0x1A // Standard Printer Port Control
// Page 0 - 读
#define TSR 0x04 // Transmit Status Register
#define NCR 0x05 // Number of Collisions Register
#define ISR 0x07 // Interrupt Status Register
#define CRDA0 0x08 // Current Remote DMA Address 0
#define CRDA1 0x09 // Current Remote DMA Address 1
#define RSR 0x0C // Receive Status Register
#define CNTR0 0x0D
#define CNTR1 0x0E
#define CNTR2 0x0F
#define GPI 0x17 // General-Purpose Input
#define RSTPORT 0x1F // Reset
// Page 0 - 写
#define TPSR 0x04 // Transmit Page Start Address
#define TBCR0 0x05 // Transmit Byte Count Register 0
#define TBCR1 0x06 // Transmit Byte Count Register 1
#define RSAR0 0x08 // Remote Start Address Register 0
#define RSAR1 0x09 // Remote Start Address Register 1
#define RBCR0 0x0A // Remote Byte Count 0
#define RBCR1 0x0B // Remote Byte Count 1
#define RCR 0x0C // Receive Config Register
#define TCR 0x0D // Transmit Config Register
#define DCR 0x0E // Data Config Register
#define IMR 0x0F // Interrupt Mask Register
#define GPOC 0x17 // General-Purpose Output Control
// Page 1 - 读/写
#define PAR0 0x01 // Physical Address Register 0
#define PAR1 0x02 // Physical Address Register 0
#define PAR2 0x03 // Physical Address Register 0
#define PAR3 0x04 // Physical Address Register 0
#define PAR4 0x05 // Physical Address Register 0
#define PAR5 0x06 // Physical Address Register 0
#define CURR 0x07 // Page 1
#define CPR 0x07 // Current Page Register
#define MAR0 0x08
#define MAR1 0x09
#define MAR2 0x0a
#define MAR3 0x0b
#define MAR4 0x0c
#define MAR5 0x0d
#define MAR6 0x0e
#define MAR7 0x0f
下面是Ax88796初始化的函数:AX88796_Init()
void AX88796_Init(void){
ax88796Write(CR,0x01);//停止网卡
AX88796Delay(100000);
AX88796_Reset();
ax88796Write(CR,0x21); // 选择page0,网卡停止运行
AX88796Delay(500000); //delay 5ms
ax88796Write(DCR,0x00); //数据配置寄存器,第0位,0表示DMA传输以位为宽度
ax88796Write(RBCR0,0x00); //远程位计数器0,赋初值为0
ax88796Write(RBCR1,0x00); //远程位计数器1,赋初值为0
ax88796Write(RCR,0x44); //中断触发为high active 并且接受广播数据包
ax88796Write(TPSR,TXSTART_INIT);//将发送缓存的首地址写入TPSR寄存器
ax88796Write(TCR,0x02);//发送配置寄存器
ax88796Write(BNRY,0x4c);//边界指针寄存器(Boundary Pointer Register),其中 RXSTART_INIT为接收起始地址
ax88796Write(PSTART,0x4c);//页起始地址寄存器(Page Start Register). RXSTART_INIT为接收器起始地址
ax88796Write(PSTOP,0x80);//页结束地址寄存器(Page Stop Register), RXSTOP_INIT为接收器结束地址
ax88796Write(ISR,0xFF); //清中断状态寄存器
ax88796Write(IMR,0x11); //此为中断屏蔽寄存器, PRX 和 OVW中断允许
// 选择page1
ax88796Write(CR,0x61);//选择Page1, 网卡停止运行
// 写网卡的MAC地址,网卡地址存储在PAR0-PAR5寄存器中,只要将值写入这5个寄存器中即可,多播地址MAR0-MAR7全为0
ax88796Write(PAR0+0, MAC[0]);
ax88796Write(PAR0+1, MAC[1]);
ax88796Write(PAR0+2, MAC[2]);
ax88796Write(PAR0+3, MAC[3]);
ax88796Write(PAR0+4, MAC[4]);
ax88796Write(PAR0+5, MAC[5]);
ax88796Write(MAR0,0x00);
ax88796Write(MAR1,0x00);
ax88796Write(MAR2,0x00);
ax88796Write(MAR3,0x00);
ax88796Write(MAR4,0x00);
ax88796Write(MAR5,0x00);
ax88796Write(MAR6,0x00);
ax88796Write(MAR7,0x00);
ax88796Write(CURR,0x4d);
ax88796Write(CR,0x22);//选择Page0,运行网卡
ax88796Write(TCR,0xe0);//****TCR 发送配置寄存器,启用crc自动生成和自动校验,工作在正常模式。
//***TCR = 0xe0
ax88796Write(ISR,0xFF);//清中断状态寄存器
AX88796Delay(100000);
}
调试了一下(调试工具为ADS1.2),看看是否这些值都已经赋到了各自的寄存器中,结果如下:
page1中的寄存器设置成功了(发不了截图):
address 0 1 2 3 4 5 6 7 8 9 a b c d e f
0x10000200 61 00 e1 23 a0 68 99 4d 00 00 00 00 00 00 00 00
其中0x10000200为CR的值(选择page1),0x10000201-0x10000206为网卡地址,0x10000207为Current Page Register的值,0x10000208-0x1000020f为MAR0-MAR7的值。
但是page0的设置却有问题:所要赋值的寄存器有CR,DCR,RBCR0,RBCR1,IMR,ISR,RCR,TCR,BNRY,PSTART,PSTOP。但是调试发现只有CR,BNRY,PSTART,PSTOP这4个寄存器可以赋值,其他几个都没有成功赋值。
address 0 1 2 3 4 5 6 7 8 9 a b c d e f
0x10000200 21 4c 80 4c
我的问题是:为什么有些寄存器赋值成功,有些寄存器就没法赋值呢?
有没有高手帮我看下原因啊?十分感谢!!!
|
|