test.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:4k
- #include "Tcpip.h"
- #include "osp.h"
- //ST20 DM9000AE test code.
- #define udelay(x) task_delay(ST_GetClocksPerSecond()/1000 * x)
- #define DEBUG_OUT printf
- //-------------------------------------------------------------------------------------------//
- #define DM9KS_ID 0x90000A46
- #define DM9010_ID 0x90100A46
- /*-------register name-----------------------*/
- #define DM9KS_NCR 0x00 /* Network control Reg.*/
- #define DM9KS_NSR 0x01 /* Network Status Reg.*/
- #define DM9KS_TCR 0x02 /* TX control Reg.*/
- #define DM9KS_TSRI 0x03
- #define DM9KS_TSRII 0x04
- #define DM9KS_RXCR 0x05 /* RX control Reg.*/
- #define DM9KS_RSR 0x06
- #define DM9KS_ROCR 0x07
- #define DM9KS_BPTR 0x08
- #define DM9KS_FCTR 0x09
- #define DM9KS_FCR 0x0a
- #define DM9KS_EPCR 0x0b
- #define DM9KS_EPAR 0x0c
- #define DM9KS_EPDRL 0x0d
- #define DM9KS_EPDRH 0x0e
- #define DM9KS_WCR 0x0f
- #define DM9KS_GPCR 0x1e
- #define DM9KS_GPR 0x1f /* General purpose register */
- #define DM9KS_TRPAL 0x22
- #define DM9KS_TRPAH 0x23
- #define DM9KS_RWPAL 0x24
- #define DM9KS_RWPAH 0x25
- #define DM9KS_VID_L 0x28
- #define DM9KS_VID_H 0x29
- #define DM9KS_PID_L 0x2A
- #define DM9KS_PID_H 0x2B
- #define DM9KS_CHIPR 0x2C
- #define DM9KS_TCR2 0x2d
- #define DM9KS_OCR 0x2E
- #define DM9KS_SMCR 0x2f /* Special Mode Control Reg.*/
- #define DM9KS_ETXCSR 0x30 /* Early Transmit control/status Reg.*/
- #define DM9KS_TCCR 0x31 /* Checksum cntrol Reg. */
- #define DM9KS_RCSR 0x32 /* Receive Checksum status Reg.*/
- #define DM9KS_MPAR 0x33
- #define DM9KS_LEDCR 0x34
- #define DM9KS_BUSCR 0x38
- #define DM9KS_INTCR 0x39
- #define DM9KS_SCCR 0x50
- #define DM9KS_RSCCR 0x51
- #define DM9KS_MRCMDX 0xf0
- #define DM9KS_MRCMDX1 0xf1
- #define DM9KS_MRCMD 0xf2
- #define DM9KS_MDRAL 0xf4
- #define DM9KS_MDRAH 0xf5
- #define DM9KS_MWCMDX 0xf6
- #define DM9KS_MWCMD 0xf8
- #define DM9KS_MWRL 0xfa
- #define DM9KS_MWRH 0xfb
- #define DM9KS_TXPLL 0xfc
- #define DM9KS_TXPLH 0xfd
- #define DM9KS_ISR 0xfe
- #define DM9KS_IMR 0xff
- #define DM9KS_PHY 0x40 /* PHY address 0x01 */
- //-------------------------------------------------------------------------------------------//
- u32 iobase = 0x41000000; //DM9000AE bank address
- u32 iodata = 0x41000004; //CMD --> addr2
- #if 0
- // debug start
- u8 inb(u32 addr)
- {
- return (u8)(*(volatile u8 *)addr);
- }
- void outb(u8 reg, u32 addr)
- {
- *(volatile u8 *)addr = reg;
- }
- // debug end
- /*
- Read a byte from I/O port
- */
- u8 ior(u8 reg, u32 addr)
- {
- outb(reg, addr);
- return inb(iodata);
- }
- /*
- Write a byte to I/O port
- */
- void iow(u8 reg, u8 value)
- {
- outb(reg, iobase);
- outb(value, iodata);
- }
- /*
- Write a word to phyxcer
- */
- void phy_write(u8 reg, u16 value)
- {
- /* Fill the phyxcer register into REG_0C */
- iow( DM9KS_EPAR, DM9KS_PHY | reg);
- /* Fill the written data into REG_0D & REG_0E */
- iow( DM9KS_EPDRL, (value & 0xff));
- iow( DM9KS_EPDRH, ( (value >> 8) & 0xff));
- iow( DM9KS_EPCR, 0xa); /* Issue phyxcer write command */
- udelay(500); /* Wait write complete */
- iow( DM9KS_EPCR, 0x0); /* Clear phyxcer write command */
- }
- #endif
- void dm9ks_test(void)
- {
- u8 io_mode;
- u32 id_val;
-
- /* I/O mode */
- io_mode = ior( DM9KS_ISR, iobase) >> 6; /* ISR bit7:6 keeps I/O mode */
- DEBUG_OUT("<DM9KS>:io_mode = 0x%x ",io_mode);
- if(io_mode==0)
- DEBUG_OUT("(16bit)rn");
- else
- DEBUG_OUT("(8bit)rn");
- outb(DM9KS_VID_L, iobase);
- id_val = inb(iodata);
- outb(DM9KS_VID_H, iobase);
- id_val |= inb(iodata) << 8;
- outb(DM9KS_PID_L, iobase);
- id_val |= inb(iodata) << 16;
- outb(DM9KS_PID_H, iobase);
- id_val |= inb(iodata) << 24;
-
- DEBUG_OUT("<DM9KS>:I/O: 0x%x, VID: 0x%x rn",iobase, id_val);
-
- if (id_val == DM9KS_ID || id_val == DM9010_ID)
- {
- DEBUG_OUT("<DM9KS>:Init DM9KS...rn");
-
-
- iow(DM9KS_GPR, 1); /* Power-Down PHY */
- udelay(2000);
-
- /* set the internal PHY power-on, GPIOs normal, and wait 2ms */
- iow( DM9KS_GPR, 0); /* GPR (reg_1Fh)bit GPIO0=0 pre-activate PHY */
- udelay(2000); /* wait 2ms for PHY power-on ready */
-
- /* do a software reset and wait 20us */
- iow( DM9KS_NCR, 3);
- udelay(20); /* wait 20us at least for software reset ok */
- iow( DM9KS_NCR, 3); /* NCR (reg_00h) bit[0] RST=1 & Loopback=1, reset on. Added by SPenser */
- udelay(20); /* wait 20us at least for software reset ok */
-
- phy_write(0, 0x1200);
- phy_write(4, 0x01e1);
- iow(DM9KS_TCR2, 0x80);
-
- DEBUG_OUT("Init OK!n");
- }
- else
- {
-
- DEBUG_OUT("<DM9KS>:************ERROR! NO DM9000A!rn");
-
- while(1);
- }
- }