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

📄 ne2kif_bak.c

📁 前段时间把lwip和ucos移植在44b0平台上,用的是hfrk44b0开发板.已经调试通过,并且在板子上运行正常.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * 10/20/2003: modefied for 51eda-arm-board           *              hgxxx <hgx2000@mail.china.com> * 04/27/2003: delete code: set mac addr manually,  *             add code: get mac addr from skyeye ne2k nic, which get from skyeye.conf *	 			chenyu <chenyu@hpclab.cs.tsinghua.edu.cn> * 01/21/2003: ne2k driver for lwip(OS independent) initial version * 				yangye <yangye@163.net> */#include "lwip/debug.h"#include "arch/cc.h"#include "lwip/opt.h"#include "lwip/def.h"#include "lwip/ip.h"#include "lwip/mem.h"#include "lwip/pbuf.h"#include "lwip/sys.h"#include "etharp.h"#include "ne2kif.h"#include "string.h"#include "../../inc/44b.h"#include "../../inc/44blib.h"struct RTL8019if {  struct eth_addr *ethaddr;  /* Add whatever per-interface state that is needed here. */};const struct eth_addr ethbroadcast = {0xff,0xff,0xff,0xff,0xff,0xff};struct netif *rtl8019if_netif;   //points to the real netif ,used by ne2k_isrstatic void ne2k_copyin(u16_t count, u8_t *buf);static void ne2k_copyout(u16_t count, u8_t *buf);static void ne2k_discard(u16_t count);void ne2k_isr(void);static void low_level_init(struct netif * netif);static struct pbuf * low_level_receive(struct RTL8019if *rtl8019if);static err_t low_level_send(struct RTL8019if *rtl8019if,struct pbuf *p);/* * Read the specified number of bytes from the device DMA port into * the supplied buffer. */static void ne2k_copyin(u16_t len, u8_t *buf){	u16_t count;	u16_t *dataw;		count = NE_WORDMODE ? len >> 1 : len;	  	#if NE_WORDMODE    	dataw = (unsigned short *)buf;				// Use pointer for speed     	while(count--)                      		// Get words         	*dataw++ = NE_DATAW;    	if (len & 0x01)                        		// If odd length, do last byte         	*(unsigned char *)dataw = NE_DATAB;	#else    	while(count--)                      		// Get bytes         	*buf++ = NE_DATAB;	#endif}/* * Write the specified number of bytes from the device DMA port into * the supplied buffer. */ static void ne2k_copyout(u16_t len, u8_t *buf){	u16_t count;		count = NE_WORDMODE ? len >> 1 : len;		#if NE_WORDMODE                   	// Word transfer?		if((u32_t)buf & 0x01)		{								// 若为奇数地址则按字节读取	   		while(count--)    		{        		NE_DATAW = (*buf) | ((u16_t)*(buf + 1)) << 8;				buf += 2;    		}        	if (len & 0x01)         	// If odd length, do last byte         		NE_DATAW = *buf;		}		else		{								// 若为偶数地址则按半字读取			u16_t *dataw;			dataw = (u16_t *)buf;			while(count--)        		NE_DATAW = *dataw++;        	if (len & 0x01)            	// If odd length, do last byte         		NE_DATAW = *(u8_t *)dataw;		}	#else    	while(count--)               	NE_DATAB = *buf++;	#endif	}static void ne2k_outpad(u16_t len){	u16_t count;		count = NE_WORDMODE ? len >> 1 : len;		#if NE_WORDMODE                			/* Word transfer? */    	while(count--)        	NE_DATAW = 0;	#else    	while(count--)                  	/* O/P bytes */        	NE_DATAB = 0;	#endif	}/* * Pull the specified number of bytes from the device DMA port, * and throw them away. */static void ne2k_discard(u16_t len){	u8_t tmp;	u16_t tmpw;	u16_t count;		count = NE_WORDMODE ? len >> 1 : len;	  	#if NE_WORDMODE      	while(count--)                      		// Get words         	tmpw = NE_DATAW;    	if (len & 0x01)                        		// If odd length, do last byte         	tmp = NE_DATAB;	#else    	while(count--)                      		// Get bytes         	tmp = NE_DATAB;	#endif}// void NICISR(void) interrupt void ne2k_isr(void){	u8_t  isr,curr,bnry;	//	struct netif *netif;	rI_ISPC = BIT_EINT3;	rINTMSK = rINTMSK | BIT_EINT3;	//close nic	NE_CR = ENCR_PAGE0 | ENCR_NODMA | ENCR_STOP;		//in PAGE0	isr = NE_ISR;	// ram overflow interrupt	if (isr & ENISR_OVER)	{		NE_ISR = ENISR_OVER;				// clear interrupt	}		// error transfer interrupt ,NIC abort tx due to excessive collisions		if (isr & ENISR_TX_ERR)	{		NE_ISR = ENISR_TX_ERR;				// clear interrupt	 	//temporarily do nothing	}	// Rx error , reset BNRY pointer to CURR (use SEND PACKET mode)	if (isr & ENISR_RX_ERR)	{		NE_ISR = ENISR_RX_ERR;		// clear interrupt				NE_CR = ENCR_PAGE1 | ENCR_NODMA | ENCR_STOP;		curr = NE_CURR;		NE_CR = ENCR_PAGE0 | ENCR_NODMA | ENCR_STOP;		NE_BNRY = curr;	}		//got packet with no errors	if (isr & ENISR_RX)	{		NE_ISR = ENISR_RX;		// clear interrupt		NE_CR = ENCR_PAGE1 | ENCR_NODMA | ENCR_STOP;		curr  = NE_CURR;		NE_CR = ENCR_PAGE0 | ENCR_NODMA | ENCR_STOP;		bnry = NE_BNRY;		//get more than one packet until receive buffer is empty		while(curr != bnry)		{			ne2k_recv_packet(rtl8019if_netif);			NE_CR = ENCR_PAGE1 | ENCR_NODMA | ENCR_STOP;			curr =  NE_CURR;			NE_CR = ENCR_PAGE0 | ENCR_NODMA | ENCR_STOP;			bnry = NE_BNRY;					}	}			//Transfer complelte, do nothing here	if( isr & ENISR_TX)	{//		PRINT("ne2k_isr: is ISR_PTX\n");		NE_ISR = ENISR_TX;          	// clear interrupt	}			NE_CR = ENCR_PAGE0 | ENCR_NODMA | ENCR_STOP;	NE_ISR = 0xff;					// clear ISR			//open nic for next packet	NE_CR = ENCR_PAGE0 | ENCR_NODMA | ENCR_START;	rINTMSK = rINTMSK & (~BIT_EINT3);	}/** * Initialize the rtk8019as, resetting the interface and getting the ethernet * address. */static void low_level_init(struct netif * netif){	u8_t temp;	struct RTL8019if *rtl8019if;	u8_t mac_addr[6];	//	NE_CR = 0x22;	rtl8019if = netif->state;		mac_addr[0] = 0;	mac_addr[1] = 1;	mac_addr[2] = 2;	mac_addr[3] = 3;	mac_addr[4] = 4;	mac_addr[5] = 5;		NE_CR = ENCR_PAGE0 + ENCR_NODMA + ENCR_START;    Delay(100);			rPCONC |= 0x10000000;	#if NE_WORDMODE		rPDATC |= 0x4000;	#else		rPDATC &= 0xbfff;	#endif	Delay(500);	temp = NE_RESET;	NE_RESET = temp;	Delay(500);	rPDATC &= 0xbfff;	rPCONC &= 0xcfffffff;    NE_CR = ENCR_PAGE0 + ENCR_NODMA + ENCR_STOP;    Delay(100);        if(NE_ISR & ENISR_RESET)    {//    	Uart_Printf("\nNIC Reset OK!\n\n");    }    else    {    	Uart_Printf("\nNIC Reset Failed!\n\n");    	return;    }    NE_DCR 		= NE_DCRVAL;    NE_RBCR0 	= 0x00; 				/* MSB remote byte count reg */    NE_RBCR1 	= 0x00; 				/* LSB remote byte count reg */    NE_RCR 		= ENRCR_RXOFF; 			/* RX configuration reg    Monitor mode (no packet receive) */    NE_TCR 		= ENTCR_TXOFF; 			/* TX configuration reg    set internal loopback mode  */    NE_TPSR     = TX_START_PG;    NE_PSTART   = RX_START_PG ; 		/* DMA START PAGE 46h */     NE_PSTOP  	= RX_STOP_PG;    		/* Ending page +1 of ring buffer */    NE_BNRY 	= RX_START_PG;			/* Boundary page of ring buffer */    NE_ISR      = 0xff; 				/* INTerrupt stauts reg */    NE_IMR      = ENIMR_RX | ENIMR_RX_ERR | ENIMR_TX | ENIMR_TX_ERR;		//hgxxx 2003-10-11 add    NE_CR = ENCR_PAGE1 + ENCR_NODMA + ENCR_STOP;    Delay(100);		NE_PAR0 = mac_addr[0];	NE_PAR1 = mac_addr[1];	NE_PAR2 = mac_addr[2];	NE_PAR3 = mac_addr[3];	NE_PAR4 = mac_addr[4];	NE_PAR5 = mac_addr[5];    NE_MAR0 	= 0xff;      NE_MAR1 	= 0xff;    NE_MAR2 	= 0xff;    NE_MAR3 	= 0xff;    NE_MAR4 	= 0xff;    NE_MAR5 	= 0xff;    NE_MAR6 	= 0xff;    NE_MAR7 	= 0xff;    NE_CURR 	= RX_START_PG; 		/* RX_CURR_PG; Current memory page = RX_CURR_PG  ? */  	/* make up an address. */  	rtl8019if->ethaddr->addr[0] = mac_addr[0];  	rtl8019if->ethaddr->addr[1] = mac_addr[1];  	rtl8019if->ethaddr->addr[2] = mac_addr[2];  	rtl8019if->ethaddr->addr[3] = mac_addr[3];  	rtl8019if->ethaddr->addr[4] = mac_addr[4];  	rtl8019if->ethaddr->addr[5] = mac_addr[5];/*	netif->hwaddr[0] = mac_addr[0];	netif->hwaddr[1] = mac_addr[1];	netif->hwaddr[2] = mac_addr[2];	netif->hwaddr[3] = mac_addr[3];	netif->hwaddr[4] = mac_addr[4];	netif->hwaddr[5] = mac_addr[5];*/	    NE_CR = ENCR_PAGE0 + ENCR_NODMA ;  	/* 00001010B: PS1 PS0 RD2 RD1 RD0 TXP STA STP */    Delay(100);    NE_RCR 		= ENRCR_RXCONFIG;   	/* rx on(broadcasts, no multicast,errors   04*/    NE_TCR 		= ENTCR_TXCONFIG; 		/* xmit on. */    NE_ISR 		= 0xff; 	 			/* Individual bits are cleared by writing a "1" into it. */    NE_IMR 		= ENISR_ALL; 			/* INTerrupt mask reg */    	NE_CR = ENCR_PAGE0 + ENCR_NODMA + ENCR_START;	 	rtl8019if_netif = netif;}/* * Function to do the actual writing of a packet into the devices * transmit buffer.  INT is disable during the function!!!!

⌨️ 快捷键说明

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