⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dm9000x.c

📁 使用Linux ARM GCC编译器来编译
💻 C
📖 第 1 页 / 共 2 页
字号:
	for (i = 0, oft = 0x10; i < 6; i++)		DM9000_iow(oft++, bd->bi_enetaddr[i]);	for (i = 0; i < 7; i++)		DM9000_iow(oft++, 0xff);//DM9000_iow(oft++, 0x00);	//DM9000_iow(oft, 0x80);	/* read back mac, just to be sure */	//for (i = 0, oft = 0x10; i < 6; i++, oft++)	//	DM9000_DBG("%02x:", DM9000_ior(oft));	//DM9000_DBG("\n");	/* Activate DM9000 */	DM9000_iow(DM9000_RCR, RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN);	/* RX enable */	//DM9000_iow(DM9000_IMR, IMR_PAR);	/* Enable TX/RX interrupt mask */	DM9000_iow(DM9000_IMR, 0xA3);	i = 0;	while (!(phy_read(1) & 0x20)) {	/* autonegation complete bit */		udelay(1000);		i++;		if (i >= 10000) {			printk("could not establish link\n");			return 0;		}	}	/* see what we've got */	lnk = phy_read(17) >> 12;	printk("operating at ");	switch (lnk) {	case 1:		printk("10M half duplex ");		break;	case 2:		printk("10M full duplex ");		break;	case 4:		printk("100M half duplex ");		break;	case 8:		printk("100M full duplex ");		break;	default:		printk("unknown: %d ", lnk);		break;	}	printk("mode\n");	return 0;}void putc(uchar);/*  Hardware start transmission.  Send a packet to media from the upper layer.*/inteth_send(volatile void *packet, int length){	char *data_ptr;	u32 tmplen, i;	int tmo;#ifdef CONFIG_DM9000_DEBUG	DM9000_DBG_T("eth_send: length: %d", length);	for (i = 0; i < length; i++) {		if (i % 8 == 0)			DM9000_DBG("\nSend: %02x: ", i);		DM9000_DBG("%02x ", ((unsigned char *) packet)[i]);	} DM9000_DBG_D("\n");#endif	/* Move data to DM9000 TX RAM */	data_ptr = (char *) packet;	DM9000_outb(DM9000_MWCMD, DM9000_IO);#ifdef CONFIG_DM9000_USE_8BIT	/* Byte mode */	for (i = 0; i < length; i++)		DM9000_outb((data_ptr[i] & 0xff), DM9000_DATA);#endif				/*  */#ifdef CONFIG_DM9000_USE_16BIT	tmplen = (length + 1) / 2;	for (i = 0; i < tmplen; i++)		DM9000_outw(((u16 *) data_ptr)[i], DM9000_DATA);#endif				/*  */#ifdef CONFIG_DM9000_USE_32BIT	tmplen = (length + 3) / 4;	for (i = 0; i < tmplen; i++)		DM9000_outl(((u32 *) data_ptr)[i], DM9000_DATA);#endif				/*  */	/* Set TX length to DM9000 */	DM9000_iow(DM9000_TXPLH, (length >> 8) & 0xff);	DM9000_iow(DM9000_TXPLL, length & 0xff);	/* Issue TX polling command */	DM9000_iow(DM9000_TCR, TCR_TXREQ);	/* Cleared after TX complete */	/* wait for end of transmission */	tmo = get_timer(0) + 5 * CFG_HZ;	/*while (!(DM9000_ior(DM9000_NSR) & (NSR_TX1END|NSR_TX2END))) {		if (get_timer(0) >= tmo) {			printk("transmission timeout\n");			break;		}	}*/	while (DM9000_ior(DM9000_TCR) & TCR_TXREQ) {		if (get_timer(0) >= tmo) {			printk("transmission timeout\n");			break;		}	}	DM9000_DBG("transmit done\n\n");	//putc('>');	//printk ("transmit done time:%08lx\n",get_timer(0));	return 0;}/*  Stop the interface.  The interface is stopped when it is brought.*/voideth_halt(void){	DM9000_DBG_T("eth_halt\n");	//putc('!');	/* RESET devie */	phy_write(0, 0x8000);	/* PHY RESET */	DM9000_iow(DM9000_GPR, 0x01);	/* Power-Down PHY */	DM9000_iow(DM9000_IMR, 0x80);	/* Disable all interrupt */	DM9000_iow(DM9000_RCR, 0x00);	/* Disable RX */}/*  Received a packet and pass to upper layer*/inteth_rx(void){	u8 rxbyte, *rdptr = (u8 *) NetRxPackets[0];	u16 RxStatus, RxLen = 0;	u32 tmplen, i;	//while(1) {    	/* Check packet ready or not */    	DM9000_ior(DM9000_MRCMDX);	/* Dummy read */    	//rxbyte = DM9000_inb(DM9000_DATA);	/* Got most updated data */    	DM9000_ior(DM9000_MRRH); /* important!!! */
		DM9000_ior(DM9000_MRRL); /* important!!! */    	rxbyte = DM9000_ior(DM9000_MRCMDX);    	if (rxbyte == 0) {    	    //udelay(1000);    		return 0;    	}    	//if (rxbyte != 1)    	//	break;        	/* Status check: this byte must be 0 or 1 */    	if (rxbyte > 1) {    		DM9000_iow(DM9000_RCR, 0x00);	/* Stop Device */    		DM9000_iow(DM9000_ISR, 0x80);	/* Stop INT request */    		printk ("rx status check: %d\n", rxbyte);    			dm9000_reset();    			return 0;    	}    	//DM9000_DBG("receiving packet\n");    	//printk(__FUNCTION__"():receiving packet\n");        	/* A packet ready now  & Get status/length */    	DM9000_outb(DM9000_MRCMD, DM9000_IO);        #ifdef CONFIG_DM9000_USE_8BIT    	RxStatus = DM9000_inb(DM9000_DATA) + (DM9000_inb(DM9000_DATA) << 8);    	RxLen = DM9000_inb(DM9000_DATA) + (DM9000_inb(DM9000_DATA) << 8);        #endif				/*  */    #ifdef CONFIG_DM9000_USE_16BIT    	RxStatus = DM9000_inw(DM9000_DATA);    	RxLen = DM9000_inw(DM9000_DATA);        #endif				/*  */    #ifdef CONFIG_DM9000_USE_32BIT    	tmpdata = DM9000_inl(DM9000_DATA);    	RxStatus = tmpdata;    	RxLen = tmpdata >> 16;        #endif				/*  */    	//DM9000_DBG("rx status: 0x%04x rx len: %d\n", RxStatus, RxLen);    	//printk(__FUNCTION__"():rx status: 0x%04x rx len: %d\n", RxStatus, RxLen);        	/* Move data from DM9000 */    	/* Read received packet from RX SRAM */    #ifdef CONFIG_DM9000_USE_8BIT    	for (i = 0; i < RxLen; i++)    		rdptr[i] = DM9000_inb(DM9000_DATA);        #endif				/*  */    #ifdef CONFIG_DM9000_USE_16BIT    	tmplen = (RxLen + 1) / 2;    	for (i = 0; i < tmplen; i++)    		((u16 *) rdptr)[i] = DM9000_inw(DM9000_DATA);        #endif				/*  */    #ifdef CONFIG_DM9000_USE_32BIT    	tmplen = (RxLen + 3) / 4;    	for (i = 0; i < tmplen; i++)    		((u32 *) rdptr)[i] = DM9000_inl(DM9000_DATA);        #endif				/*  */    	if ((RxStatus & 0xbf00) || (RxLen < 0x40)    	    || (RxLen > DM9000_PKT_MAX)) {    		if (RxStatus & 0x100) {    			printk("rx fifo error\n");    		}    		if (RxStatus & 0x200) {    			printk("rx crc error\n");    		}    		if (RxStatus & 0x8000) {    			printk("rx length error\n");    		}    		/*if (RxStatus & 0x0800) {				printk("physical layer error\n");			}*/    		if (RxLen > DM9000_PKT_MAX) {    			printk("rx length too big\n");    			dm9000_reset();    			return 0;    		}    		//continue;    	} else {        		/* Pass to upper layer */    		DM9000_DBG("passing packet to upper layer\n");#ifdef CONFIG_DM9000_DEBUG    		DM9000_DBG("length: %d", RxLen);        	for (i = 0; i < RxLen; i++) {        		if (i % 8 == 0)        			DM9000_DBG("\nRecv: %02x: ", i);        		DM9000_DBG("%02x ", rdptr[i]);        	} DM9000_DBG("\n");    		//printk(__FUNCTION__"():passing packet to upper layer\n");#endif    		//putc('<');    		//printk ("recieve packet time:%08lx\n",get_timer(0));    		NetReceive(NetRxPackets[0], RxLen);    		return RxLen;    	}    //};	return 0;}#if 0/*  Read a word data from SROM*/static u16read_srom_word(int offset){	DM9000_iow(DM9000_EPAR, offset);	DM9000_iow(DM9000_EPCR, 0x4);	udelay(200);	DM9000_iow(DM9000_EPCR, 0x0);	return (DM9000_ior(DM9000_EPDRL) + (DM9000_ior(DM9000_EPDRH) << 8));}#endif/*   Read a byte from I/O port*/static u8DM9000_ior(int reg){	DM9000_outb(reg, DM9000_IO);	return DM9000_inb(DM9000_DATA);}/*   Write a byte to I/O port*/static voidDM9000_iow(int reg, u8 value){	DM9000_outb(reg, DM9000_IO);	DM9000_outb(value, DM9000_DATA);}/*   Read a word from phyxcer*/static u16phy_read(int reg){	u16 val;	/* Fill the phyxcer register into REG_0C */	DM9000_iow(DM9000_EPAR, DM9000_PHY | reg);	DM9000_iow(DM9000_EPCR, 0xc);	/* Issue phyxcer read command */	udelay(100);		/* Wait read complete */	DM9000_iow(DM9000_EPCR, 0x0);	/* Clear phyxcer read command */	val = (DM9000_ior(DM9000_EPDRH) << 8) | DM9000_ior(DM9000_EPDRL);	/* The read data keeps on REG_0D & REG_0E */	DM9000_DBG("phy_read(%d): %d\n", reg, val);	return val;}/*   Write a word to phyxcer*/static voidphy_write(int reg, u16 value){	/* Fill the phyxcer register into REG_0C */	DM9000_iow(DM9000_EPAR, DM9000_PHY | reg);	/* Fill the written data into REG_0D & REG_0E */	DM9000_iow(DM9000_EPDRL, (value & 0xff));	DM9000_iow(DM9000_EPDRH, ((value >> 8) & 0xff));	DM9000_iow(DM9000_EPCR, 0xa);	/* Issue phyxcer write command */	udelay(500);		/* Wait write complete */	DM9000_iow(DM9000_EPCR, 0x0);	/* Clear phyxcer write command */	DM9000_DBG("phy_write(reg:%d, value:%d)\n", reg, value);}#endif				/* CONFIG_DRIVER_DM9000 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -