亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? ethernetif.c

?? 一個單片機實現(xiàn)以太網(wǎng)通信的程序
?? C
?? 第 1 頁 / 共 2 頁
字號:
/*
 * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
 * All rights reserved. 
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission. 
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
 * OF SUCH DAMAGE.
 *
 * This file is part of the lwIP TCP/IP stack.
 * 
 * Author: Adam Dunkels <adam@sics.se>
 *
 */

/*
 * This file is a skeleton for developing Ethernet network interface
 * drivers for lwIP. Add code to the low_level functions and do a
 * search-and-replace for the word "ethernetif" to replace it with
 * something that better describes your network interface.
 *
 * THIS CODE NEEDS TO BE FIXED - IT IS NOT In SYNC WITH CURRENT ETHARP API
 */

#include "lwip/opt.h"
#include "lwip/def.h"
#include "lwip/mem.h"
#include "lwip/pbuf.h"
#include "lwip/sys.h"
#include "lwip/stats.h"
#include "netif/etharp.h"
#include "Dm9000.h"
#include "hardware.h"
/* Define those to better describe your network interface. */

#define PIOBData  ((volatile u16_t *)(P_IOB_Data))
#define PIOBDir  ((volatile u16_t *)(P_IOB_Dir))
#define PIOAData  ((volatile u16_t *)(P_IOA_Data))
#define PIOADir  ((volatile u16_t *)(P_IOA_Dir))

enum DM9K_PHY_mode {
	DM9K_10MHD   = 0, 
	DM9K_100MHD  = 1, 
	DM9K_10MFD   = 4,
	DM9K_100MFD  = 5, 
	DM9K_AUTO    = 8,
    DM9K_DISCONN = 9
};

extern void delay(u16_t);


u16_t inb(int port)
{
	 int iData,i;
	 *PIOBData=0x4070;               //置位
	 *PIOADir=0x0000;
	 *PIOBData=0x0070|port;            //cs 拉低
	 *PIOBData=0x0020|port;              //讀數(shù)據(jù)&地址	 
	 *PIOADir=0x0000;
	 iData=*PIOAData;            //
	 *PIOBData=0x0070|port;            //cs拉低	 
	 *PIOBData=0x4070|port;               //置位
	 *PIOADir=0xffff;
     return(iData & 0x00ff);
}

void outb(int data,int port)
{
	int i;
	 *PIOADir=0xffff;	 
	 *PIOAData=data;   
	 *PIOBData=0x4070|port;               //置位
	 *PIOBData=0x0070|port;            //cs
    *PIOBData=0x0010|port;              //寫數(shù)據(jù)	 
*PIOBData=0x4070;               //置位
}

u16_t inw(int port)
{
	 int iData,i;
	 *PIOBData=0x4070;               //置位
	 *PIOADir=0x0000;
	 *PIOBData=0x0070|port;            //cs
	 	 *PIOBData=0x0020|port;              //讀數(shù)據(jù)
	 iData=*PIOAData;            //
	 *PIOBData=0x0070|port;            //cs
	 *PIOBData=0x4070|port;               //置位
	 *PIOADir=0xffff;	 
	 return(iData);
}

void outw(int data,int port)
{
	 int i;
	 *PIOADir=0xffff;	 
	 *PIOAData=data;  
	 *PIOBData=0x4070|port;               //置位
	 *PIOBData=0x0070|port;            //cs	 
	 *PIOBData=0x0010|port;              //寫數(shù)據(jù)
	 *PIOBData=0x0070|port;            //cs	 	 
	 *PIOBData=0x4070|port;               //置位
}
void r_pack(unsigned int len,unsigned int *payload) //連續(xù)接收數(shù)據(jù),接收緩沖區(qū)起始地址為payload,接收長度為len(以字為單位)
{
     unsigned int i,j=0;
	 *PIOBData=0x4074;               //置位
	 *PIOADir=0x0000;
     for(j=0;j<len;j++)
    { 
	 //*PIOBData=0x0070;            //cs  
	 *PIOBData=0x0024;              //讀數(shù)據(jù)	 
	 *(payload++)=*PIOAData;            //
	 //*PIOBData=0x0074;            //cs 
	 *PIOBData=0x0034;              //wr pull high		 
     //*PIOBData=0x4074;               //置位
    }	 
	 *PIOADir=0xffff;
}

void drop(unsigned int len) //連續(xù)接收數(shù)據(jù),接收緩沖區(qū)起始地址為payload,接收長度為len(以字為單位)
{
     unsigned int i,j=0;
	 *PIOBData=0x4070;               //置位
	 *PIOADir=0x0000;
     for(j=0;j<len;j++)
    { 
	 //*PIOBData=0x0074;            //cs  
     *PIOBData=0x0024;              //讀數(shù)據(jù)
	 *PIOBData=0x0034;            //cs	 
	 //*PIOBData=0x4074;               //置位
    }	 
	 *PIOADir=0xffff;
}

void s_pack(unsigned int len,unsigned int *payload)
{
	 unsigned int i,j=0;
	 *PIOBData=0x4070;               //置位
 	 *PIOADir=0xffff;
     for(j=0;j<len;j++)
    {
     *PIOAData=*(payload++);            // 
	 *PIOBData=0x4074;               //置位
	 //*PIOBData=0x0070;            //cs 
	  //*PIOBData=0x0074;            //cs  	 
	 *PIOBData=0x0014;              //寫數(shù)據(jù)
	 //*PIOBData=0x0034;              //wr pull high
	 //*PIOBData=0x0074;            //cs	 	 
	 *PIOBData=0x4074;               //置位
    }
}

void delay(u16_t delay_time);

static const struct eth_addr ethbroadcast = {{0xffff,0xffff,0xffff}};
/* Forward declarations. */
static void  ethernetif_input(struct netif *netif);
static err_t ethernetif_output(struct netif *netif, struct pbuf *p,struct ip_addr *ipaddr);

typedef struct EtherDev{
    u16_t   base_addr;
    struct eth_addr dev_addr;
	u8_t op_mode;			/* PHY operation mode */
	u8_t io_mode;			/* 0:word, 2:byte */
	u16_t link_mode;	
	//u16_t runt_length_counter;	/* counter: RX length < 64byte */ 
	//u16_t long_length_counter;	/* counter: RX length > 1514byte */ 
	//u16_t reset_counter;		/* counter: RESET */ 
	u16_t reset_rx_status;		/* RESET caused by RX Statsus wrong */ 
	//u16_t rx_fifo_errors;
	//u16_t rx_crc_errors;
	//u16_t rx_length_errors;
	u16_t rx_packets;
	u16_t tx_packets;
	//u16_t drop_packets;

} Dm9000_t;



/* Global variable declaration ----------------------------- */
static struct EtherDev * dmfe_dev = NULL;
/* function declaration ------------------------------------- */
int dmfe_probe(struct EtherDev *);
static int dmfe_stop(struct EtherDev *);
static void dmfe_init_DM9K(struct EtherDev *);         

volatile static u8_t ior(int);
static void iow(int, u8_t);
volatile static u16_t phy_read( int);
static void phy_write(int, u16_t);
static u16_t read_srom_word(int);
#if 0
u32_t CRC_32(u8_t *CRC_Data , u16_t Data_len);
static void DM9K_hash_table(struct EtherDev *);      
static unsigned long cal_CRC(u8_t *, unsigned int, u8_t);  
struct dev_mc_list mc2 = {NULL,(0x01,0x02,0x03,0x04,0x05,0x05)};
struct dev_mc_list mc1 = {&mc2,(0xFF,0xFF,0xFF,0xFF,0xFF,0xFF)};     
#endif
/*           from DM9K linux driver                                              */

/*  Search DM9K board, allocate space and register it
*/
struct EtherDev *init_etherdev(struct EtherDev *dev, u16_t opt)
{
dev = mem_malloc(sizeof (struct EtherDev));
memset(dev,0,sizeof (struct EtherDev));
return(dev);
}




int dmfe_probe(struct EtherDev *dev)
{
	u32_t id_val;
	u16_t iobase = DM9K_MIN_IO;
	u16_t i, DM9K_found = FALSE,oft;
	DMFE_DBUG(0, "dmfe_probe()",0);

	/* Search All DM9K NIC */
		outb(DM9K_VID_L, iobase);
		id_val = inb(iobase + 4);
		outb(DM9K_VID_H, iobase);
		id_val |= inb(iobase + 4) << 8;
		outb(DM9K_PID_L, iobase);
		id_val |= (u32_t)inb(iobase + 4) << 16;
		outb(DM9K_PID_H, iobase);
		id_val |= (u32_t)inb(iobase + 4) << 24;
		if (id_val == DM9K_ID) {
			DEBUGF(DM9K_DEBUG | DBG_TRACE , ("<DM9K> I/O: %x, VID: %x \n",iobase, id_val));
			DM9K_found = TRUE;
			/* Init network device */
			dev = init_etherdev(dev, 0);
			/* Allocated board information structure */
			dmfe_dev    = dev;
			dev->base_addr 		= iobase;
			#if 0
            dev->mc_list = &mc1;
            dev->mc_count = 2;
            #endif

            dev->dev_addr.addr[0]=0x6000;
            dev->dev_addr.addr[1]=0x006e;
            dev->dev_addr.addr[2]=0x0090;
            
            for (i = 0, oft = 0x10; i < 6; i++, oft++)
	        iow(oft, GETMAC(dev->dev_addr, i));
			/* Set Node Address */
		}

	return DM9K_found ? 0:-ENODEV;
}

/*
  Open the interface.
  The interface is opened whenever "ifconfig" actives it.
*/
void low_level_init(struct netif *netif)
{
	struct EtherDev * dev = netif->state;
	dmfe_init_DM9K(dev);
}

/* Set PHY operationg mode
*/
static void set_PHY_mode(u16_t op_mode)
{
	u16_t phy_reg4 = 0x01e1, phy_reg0=0x1000;
	switch(op_mode) {
			case DM9K_10MHD:  phy_reg4 = 0x21; 
                        	            phy_reg0 = 0x0000; 
					    break;
			case DM9K_10MFD:  phy_reg4 = 0x41; 
                        	            phy_reg0 = 0x1100; 
                                	    break;
			case DM9K_100MHD: phy_reg4 = 0x81; 
					    phy_reg0 = 0x2000; 
				    	    break;
			case DM9K_100MFD: phy_reg4 = 0x101; 
				    	    phy_reg0 =0x3100; 
				   	    break;
		}
		phy_write(4, phy_reg4);	/* Set PHY media mode */
		phy_write(0, phy_reg0);	/*  Tmp */
	iow( 0x1e, 0x01);			/* Let GPIO0 output */
	iow( 0x1f, 0x00);			/* Enable PHY */
}


/*
  Hardware start transmission.
  Send a packet to media from the upper layer.
*/

err_t
low_level_output(struct netif *netif, struct pbuf *skb)
{
    struct EtherDev *dev = netif->state;
	u16_t * data_ptr;
	int i, tmplen;
	struct pbuf *q;
	/* Disable all interrupt */	
	/* Move data to DM9K TX RAM */
	ior(0x05);
	outb(0xf8, DM9KADDR);
	#if 0
	if (db->io_mode == DM9K_BYTE_MODE) {
		/* Byte mode */
		for (i = 0; i < skb->len; i++)
			outb((data_ptr[i] & 0xff), DM9KADDR);
			while(1);
	} else 
	#endif 
	if (dev->io_mode == DM9K_WORD_MODE) {
		/* Word mode */
  for(q = skb ; q != NULL; q = q->next) {
    /* Send the data from the pbuf to the interface, one pbuf at a
       time. The size of the data in each pbuf is kept in the ->len
       variable. */
   if ((q->len % 2) && (q->next !=NULL))
   {
   DEBUGF(DM9K_DEBUG | DBG_TRACE, ("data error ! odd bytes. q->len\n",q->len));
   while(1);
   }
   data_ptr = q->payload;
   tmplen = (q->len + 1) / 2;
   s_pack(tmplen, data_ptr);
  }
       dev->tx_packets++;
		/* Set TX length to DM9K */
		iow( 0xfc, skb->tot_len & 0xff);
		iow( 0xfd, (skb->tot_len >> 8) & 0xff);
		iow( 0x02, 0x01);
        while (!( ior( 0x01) & (4 | 8)));
	return ERR_OK;
	}
	
}

/* Initilize DM9K board
*/
static void dmfe_init_DM9K(struct EtherDev *dev)
{ 	
	/* RESET device */

	iow( 0, 3);
	delay(100);			  /* delay 100us */
	iow( 0, 0);
	iow( 0, 3);
	delay(100);			  /* delay 100us */
	iow( 0, 0);
	/* I/O mode */
	dev->io_mode = ior( 0xfe) >> 6; /* ISR bit7:6 keeps I/O mode */
    DEBUGF(DM9K_DEBUG | DBG_TRACE, ("io_mode = %d\n", dev->io_mode));
	delay(200);			  /* delay 100us */
	/* Set PHY */
	dev->op_mode = DM9K_10MFD;
	set_PHY_mode(dev->op_mode);
	delay(500);
	if (!(ior(NSR) &1<<6)) 
	dev->link_mode = DM9K_DISCONN;
	else dev->link_mode = dev->op_mode;
	//while(!(ior( NSR) & 1<<6));	
	/* Init needed register value */	
	/* Program operating register */
	iow( 0x00, DM9K_REG00);
	iow( 0x02, 0);		/* TX Polling clear */
	iow( 0x08, 0x3f);		/* Less 3Kb, 200us */
	iow( 0x09, DM9K_REG09);	/* Flow Control : High/Low Water */
	iow( 0x0a, DM9K_REG0A);	/* Flow Control */
	iow( 0x2f, 0);		/* Special Mode */
	iow( 0x01, 0x2c);		/* clear TX status */
	iow( 0xfe, 0x0f); 		/* Clear interrupt status */
 	/* Set address filter table */
 	#if 0
	DM9K_hash_table(dev);
	#endif 
	/* Activate DM9K */
	iow( 0x05, DM9K_REG05 | 1);	/* RX enable */
	iow( 0xff, DM9K_REGFF); 	/* Enable TX/RX interrupt mask */
 	/* Init Driver variable */
}

/*
  Stop the interface.
  The interface is stopped when it is brought.
*/
static int dmfe_stop(struct EtherDev *dev)
{
	DMFE_DBUG(0, "dmfe_stop", 0);
	/* RESET devie */
	phy_write( 0x00, 0x8000);	/* PHY RESET */
	delay(200);
	iow( 0x1f, 0x01); 		/* Power-Down PHY */
	iow( 0xff, 0x80);		/* Disable all interrupt */
	iow( 0x05, 0x00);		/* Disable RX */

    delay(200);
	/* Dump Statistic counter */
#if DM9K_DEBUG
	Print("\nRX FIFO OVERFLOW %lx\n", db->stats.rx_fifo_errors);
	Print("RX CRC %lx\n", db->stats.rx_crc_errors);
	Print("RX LEN Err %lx\n", dev->rx_length_errors);
	Print("RX LEN < 64byte %x\n", dev->runt_length_counter);
	Print("RX LEN > 1514byte %x\n", dev->long_length_counter);
	Print("RESET %x\n", dev->reset_counter);
#endif
return 0;
}

/*
  Received a packet and pass to upper layer
*/

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美一区二区三区喷汁尤物| 欧美老女人第四色| 午夜精品福利在线| 久久婷婷久久一区二区三区| 91美女精品福利| 韩国v欧美v日本v亚洲v| 悠悠色在线精品| 国产校园另类小说区| 欧美日韩一区在线观看| 成人午夜av在线| 美女网站视频久久| 亚洲狠狠丁香婷婷综合久久久| 日韩电影免费一区| 久久夜色精品国产噜噜av | 亚洲资源在线观看| 久久久久久久久一| 欧美巨大另类极品videosbest | 欧美人牲a欧美精品| 成人av片在线观看| 国内精品在线播放| 天天综合色天天综合色h| 中文字幕亚洲精品在线观看| 久久免费美女视频| 日韩一区二区精品在线观看| 欧美色视频在线观看| 99久久精品国产精品久久| 国产一区激情在线| 蜜桃精品视频在线观看| 一区二区三区资源| 久久婷婷成人综合色| 中文字幕一区二区三| 欧美大片一区二区| 欧美一区二区三区色| 精品视频在线看| 在线看国产一区二区| 色综合中文字幕国产 | 日韩午夜在线影院| 欧美日韩三级一区二区| 在线免费亚洲电影| 91蜜桃视频在线| 色综合久久中文综合久久牛| 波多野结衣中文字幕一区 | 91国内精品野花午夜精品 | 精品88久久久久88久久久 | 国产精品久久看| 国产视频一区二区在线| 国产色综合久久| 国产网红主播福利一区二区| 久久精品视频在线看| 国产日韩欧美一区二区三区综合 | 国产人成亚洲第一网站在线播放| 久久综合久久综合久久综合| 久久综合色综合88| 日本一区二区成人在线| 中文在线一区二区| 亚洲人吸女人奶水| 亚洲综合一区二区三区| 午夜一区二区三区在线观看| 天天综合网天天综合色| 精品一区二区在线观看| 国产在线乱码一区二区三区| 粉嫩av一区二区三区粉嫩| 不卡的电影网站| 日本韩国精品一区二区在线观看| 欧美无乱码久久久免费午夜一区| 欧美美女网站色| 久久综合久久综合九色| 日本一区二区视频在线| 亚洲欧美另类久久久精品2019| 亚洲mv大片欧洲mv大片精品| 亚洲国产精品一区二区www在线| 午夜久久久久久电影| 乱中年女人伦av一区二区| 欧美丰满少妇xxxxx高潮对白| 欧美日韩视频一区二区| 日韩欧美在线123| 中文字幕巨乱亚洲| 亚洲综合一二三区| 精品一区二区久久| 91免费国产在线| 欧美片网站yy| 国产日韩成人精品| 亚洲欧美日韩一区二区| 青娱乐精品视频在线| 成人亚洲精品久久久久软件| 欧美亚洲综合另类| 2021久久国产精品不只是精品| 亚洲日韩欧美一区二区在线| 天堂一区二区在线免费观看| 国产成人综合在线观看| 在线观看精品一区| 久久精品这里都是精品| 亚洲一卡二卡三卡四卡无卡久久 | 美女诱惑一区二区| 91在线视频播放地址| 国产成a人亚洲精品| 日韩福利视频网| 成人自拍视频在线| 欧美日韩精品欧美日韩精品一 | 99精品视频一区二区三区| 在线播放国产精品二区一二区四区| 国产亚洲一二三区| 亚洲成人久久影院| kk眼镜猥琐国模调教系列一区二区| 7878成人国产在线观看| 亚洲人快播电影网| 国产成人一区在线| 欧美丰满高潮xxxx喷水动漫| 综合在线观看色| 国产精品一二三区在线| 91精品国产色综合久久久蜜香臀| ㊣最新国产の精品bt伙计久久| 国产综合色在线| 5566中文字幕一区二区电影 | 一区二区在线看| 国产91综合网| 精品成人a区在线观看| 亚洲成年人影院| 色诱视频网站一区| 国产精品日韩成人| 国产精品夜夜爽| 日韩欧美另类在线| 婷婷一区二区三区| 欧美亚洲免费在线一区| 中文字幕一区三区| 成人短视频下载| 国产亚洲欧美在线| 狠狠狠色丁香婷婷综合激情| 欧美一级高清大全免费观看| 午夜精品一区在线观看| 在线观看欧美黄色| 亚洲欧美日韩国产成人精品影院| 成人精品视频.| 国产欧美日韩在线看| 国产一区二区三区四区五区美女| 日韩一级二级三级精品视频| 三级欧美在线一区| 欧美久久久久久蜜桃| 亚洲18影院在线观看| 欧美视频一二三区| 亚洲国产日产av| 欧美日韩高清一区二区| 天天爽夜夜爽夜夜爽精品视频| 欧美日韩一区二区在线视频| 午夜天堂影视香蕉久久| 欧美电影在线免费观看| 美女任你摸久久| 欧美大片在线观看一区| 国产真实乱对白精彩久久| 久久久精品国产免费观看同学| 国产精品69毛片高清亚洲| 亚洲国产成人自拍| 97久久久精品综合88久久| 亚洲精品国产精华液| 欧美体内she精高潮| 丝袜亚洲另类欧美| 精品欧美乱码久久久久久| 欧美一级黄色片| 色综合久久中文字幕综合网| 中文字幕一区二区三区蜜月| 99国产欧美久久久精品| 亚洲色图欧洲色图| 在线视频你懂得一区| 日韩黄色小视频| 2023国产精品视频| www..com久久爱| 亚洲一区二区欧美日韩 | 91蜜桃免费观看视频| 亚洲高清在线精品| 欧美xfplay| 99视频精品免费视频| 亚洲成人资源在线| 久久亚洲二区三区| 日本乱人伦一区| 欧美bbbbb| 国产精品久久久久久久裸模| 欧美视频一区二区三区| 国产一区 二区| 亚洲免费视频成人| 欧美成人精品二区三区99精品| 国产成人免费高清| 亚洲大尺度视频在线观看| www激情久久| 精品国产99国产精品| 久久久久99精品国产片| 91在线小视频| 亚洲国产另类av| 久久精品视频一区二区三区| 91丨porny丨首页| 久久91精品久久久久久秒播| 亚洲欧洲国产日本综合| 欧美精选午夜久久久乱码6080| 国产在线不卡一区| 夜夜操天天操亚洲| 国产欧美日韩综合| 欧美一区二区国产| 一本久道中文字幕精品亚洲嫩| 久久成人免费网| 一区二区三区四区激情| 国产日韩精品一区二区浪潮av |