|
平台是S3C2410 DM9000连在ngsc1上
我主要是把dm9000的功能先加到eboot中,使之可以在eboot中下载内核文件
现在,已经可以读到DM9000的产品ID
这个说明硬件和时序都没什么问题。
但是在发送sent bootme to 255.255.255.255的时候,在网口的数据tx+ tx-都没有数据输出
(从平滑的直线编程有小幅度的类波形输出)
在电脑主机方面也收不到任何的数据
dm9000的代码(初始化和发送的代码):
-
- #include
- #include
- #define DM9000_ID 0x90000A46
- // Hash creation constants.
- //
- #define CRC_PRIME 0xFFFFFFFF;
- #define CRC_POLYNOMIAL 0x04C11DB6;
- #define IOREAD(o) ((UCHAR)*((volatile UCHAR *)(o)))
- #define IOWRITE(o, d) *((volatile UCHAR *)(o)) = (UCHAR)(d)
- #define IOREAD16(o) ((USHORT)*((volatile USHORT *)(o)))
- #define IOWRITE16(o, d) *((volatile USHORT *)(o)) = (USHORT)(d)
- #define IOREAD32(o) ((ULONG)*((volatile ULONG *)(o)))
- #define IOWRITE32(o, d) *((volatile ULONG *)(o)) = (ULONG)(d)
- #define MEMREAD(o) ((USHORT)*((volatile USHORT *)(dwEthernetMemBase + (o))))
- #define MEMWRITE(o, d) *((volatile USHORT *)(dwEthernetMemBase + (o))) = (USHORT)(d)
- static DWORD dwEthernetIOBase;
- static DWORD dwEthernetDataPort;
- static UCHAR DM9000_iomode;
- static USHORT hash_table[4];
- static DWORD dwEthernetMemBase;
- //V1.02
- static UCHAR DM9000_rev;
- #define DM9000_DWORD_MODE 1
- #define DM9000_BYTE_MODE 2
- #define DM9000_WORD_MODE 0
- //#define DM9000_MEM_MODE
- #ifdef DM9000_MEM_MODE
- #define READ_REG1 ReadReg
- #define READ_REG2 MEMREAD
- #define WRITE_REG1 WriteReg
- #define WRITE_REG2 MEMWRITE
- #else
- #define READ_REG1 ReadReg
- #define READ_REG2 ReadReg
- #define WRITE_REG1 WriteReg
- #define WRITE_REG2 WriteReg
- #endif
- static BOOL bIsPacket;
- static UCHAR
- ReadReg(USHORT offset)
- {
- IOWRITE(dwEthernetIOBase, offset);
- return IOREAD(dwEthernetDataPort);
- }
- static void
- WriteReg(USHORT offset, UCHAR data)
- {
- IOWRITE(dwEthernetIOBase, offset);
- IOWRITE(dwEthernetDataPort, data);
- }
- /*
- @func BYTE | CalculateHashIndex | Computes the logical addres filter hash index value. This used when there are multiple
- destination addresses to be filtered.
- @rdesc Hash index value.
- @comm
- @xref
- */
- BYTE CalculateHashIndex( BYTE *pMulticastAddr )
- {
- DWORD CRC;
- BYTE HashIndex;
- BYTE AddrByte;
- DWORD HighBit;
- int Byte;
- int Bit;
- // Prime the CRC.
- CRC = CRC_PRIME;
- // For each of the six bytes of the multicast address.
- for ( Byte=0; Byte<6; Byte++ )
- {
- AddrByte = *pMulticastAddr++;
- // For each bit of the byte.
- for ( Bit=8; Bit>0; Bit-- )
- {
- HighBit = CRC >> 31;
- CRC <<= 1;
- if ( HighBit ^ (AddrByte & 1) )
- {
- CRC ^= CRC_POLYNOMIAL;
- CRC |= 1;
- }
- AddrByte >>= 1;
- }
- }
- // Take the least significant six bits of the CRC and copy them
- // to the HashIndex in reverse order.
- for( Bit=0,HashIndex=0; Bit<6; Bit++ )
- {
- HashIndex <<= 1;
- HashIndex |= (BYTE)(CRC & 1);
- CRC >>= 1;
- }
- return(HashIndex);
- }
- void DM9000_Delay(DWORD dwCounter)
- {
- // Simply loop...
- while (dwCounter--);
- }
- void dm9000_hash_table(USHORT *mac)
- {
- USHORT i, oft;
- /* Set Node address */
- WRITE_REG1(0x10, (UINT8)(mac[0] & 0xFF));
- WRITE_REG1(0x11, (UINT8)(mac[0] >> 8));
- WRITE_REG1(0x12, (UINT8)(mac[1] & 0xFF));
- WRITE_REG1(0x13, (UINT8)(mac[1] >> 8));
- WRITE_REG1(0x14, (UINT8)(mac[2] & 0xFF));
- WRITE_REG1(0x15, (UINT8)(mac[2] >> 8));
- /* Clear Hash Table */
- for (i = 0; i < 4; i++)
- hash_table[i] = 0x0;
- /* broadcast address */
- hash_table[3] = 0x8000;
- /* Write the hash table to MAC MD table */
- for (i = 0, oft = 0x16; i < 4; i++)
- {
- WRITE_REG1(oft++, (UINT8)(hash_table[i] & 0xff));
- WRITE_REG1(oft++, (UINT8)((hash_table[i] >> 8) & 0xff));
- }
-
- }
- /*
- * This function is used to detect DM9000 chip
- * input : void
- * return : TRUE, detect DM9000
- * FALSE, Not find DM9000
- */
- static BOOL Probe(void)
- {
- BOOL r = FALSE;
- DWORD id_val;
-
- id_val = READ_REG1(0x28);
- id_val |= READ_REG1(0x29) << 8;
- id_val |= READ_REG1(0x2a) << 16;
- id_val |= READ_REG1(0x2b) << 24;
-
- if (id_val == DM9000_ID) {
- RETAILMSG(1, (TEXT("INFO: Probe: DM9000 is detected.\r\n")));
- DM9000_rev = READ_REG1(0x2c);
-
- r = TRUE;
- }
- else {
- RETAILMSG(1, (TEXT("ERROR: Probe: Can not find DM9000.\r\n")));
- }
- return r;
- }
- /*
- * This function enables TX/RX interrupt mask
- * input : void
- * return : viod
- */
- void DM9000DBG_EnableInts(void)
- {
- /*only enable RX interrupt*/
- WRITE_REG1(0xff, 0x81);
- }
- /*
- * This function disables TX/RX interrupt mask
- * input : void
- * return void
- */
- void DM9000DBG_DisableInts(void)
- {
- WRITE_REG1(0xff, 0x80);
- }
- /* Send a data block via Ethernet. */
- static USHORT dm9000_send (BYTE *pbData, USHORT length)
- {
- int i;
- int tmplen;
- IOWRITE(dwEthernetIOBase, 0xf8); /* data copy ready set */
- /* copy data to FIFO */
- switch (DM9000_iomode)
- {
- case DM9000_BYTE_MODE:
- tmplen = length ;
- for (i = 0; i < tmplen; i++)
- IOWRITE(dwEthernetDataPort, ((UCHAR *)pbData)[i]);
- break;
- case DM9000_WORD_MODE:
- tmplen = (length+1)/2;
- for (i = 0; i < tmplen; i++)
- IOWRITE16(dwEthernetDataPort, ((USHORT *)pbData)[i]);
- break;
- case DM9000_DWORD_MODE:
- tmplen = (length+3)/4;
- for (i = 0; i < tmplen; i++)
- IOWRITE32(dwEthernetDataPort, ((ULONG *)pbData)[i]);
- default:
- EdbgOutputDebugString("[DM9000][TX]Move data error!!!");
- break;
- }
- /*set packet leng */
- WRITE_REG1(0xfd, (length >> 8) & 0xff);
- WRITE_REG1(0xfc, length & 0xff);
- /* start transmit */
- WRITE_REG1(0x02, 1);
-
- /*wait TX complete*/
- while(1)
- {
- if (READ_REG1(0xfe) & 2) { //TX completed
- WRITE_REG1(0xfe, 2);
- break;
- }
- DM9000_Delay(1000);
- }
- return 0;
- }
- /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
- /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
- BOOL DM9000DBG_Init(BYTE *iobase, ULONG membase, USHORT MacAddr[3])
- {
- BOOL r = FALSE;
- bIsPacket = FALSE;
- dwEthernetIOBase = (DWORD)iobase;
- dwEthernetDataPort = dwEthernetIOBase + 4;
- dwEthernetMemBase = membase;
-
- r = Probe(); /*Detect DM9000 */
-
- EdbgOutputDebugString("DM9000: MAC Address: %x:%x:%x:%x:%x:%x\r\n",
- MacAddr[0] & 0x00FF, MacAddr[0] >> 8,
- MacAddr[1] & 0x00FF, MacAddr[1] >> 8,
- MacAddr[2] & 0x00FF, MacAddr[2] >> 8);
- /* set the internal PHY power-on, GPIOs normal */
- WRITE_REG1(0x1f, 0); /* GPR (reg_1Fh)bit GPIO0=0 pre-activate PHY */
- DM9000_Delay(200000000);
- /* do a software reset */
- WRITE_REG1(0x0, 3); /* NCR (reg_00h) bit[0] RST=1 & Loopback=1, reset on */
- DM9000_Delay(200000000);
- WRITE_REG1(0x0, 3); /* NCR (reg_00h) bit[0] RST=1 & Loopback=1, reset on */
- DM9000_Delay(200000000);
- /* I/O mode */
- DM9000_iomode = READ_REG1(0xfe) >> 6; /* ISR bit7:6 keeps I/O mode */
- /* Program operating register */
- WRITE_REG1(0x0, 0);
- WRITE_REG1(0x02, 0); /* TX Polling clear */
- WRITE_REG1(0x2f, 0); /* Special Mode */
- WRITE_REG1(0x01, 0x2c); /* clear TX status */
- WRITE_REG1(0xfe, 0x0f); /* Clear interrupt status */
- /* Set address filter table */
- dm9000_hash_table(MacAddr);
- /* Activate DM9000A/DM9010 */
- WRITE_REG1(0x05, 0x30 | 1); /* Discard long packet and CRC error packets*//* RX enable */
- WRITE_REG1(0xff, 0x80); /* Enable SRAM automatically return */
-
- /* wait link ok */
- while(1)
- {
- if(READ_REG1(0x01)&0x40)
- break;
- }
-
- return r;
- }
- //----------------------------------------------------------------------
复制代码
|
|