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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ethernetif.c

?? MCS-51的一個Free小型操作系統,在KeilC中下編譯工作
?? C
字號:
/*
 * Copyright (c) 2001-2004 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>
 *
 */

/* lwIP includes. */
#include <string.h>
#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"

/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "SAM7_EMAC.h"
#include "Emac.h"

#define netifMTU							( 1500 )
#define netifINTERFACE_TASK_STACK_SIZE		( 350 )
#define netifINTERFACE_TASK_PRIORITY		( configMAX_PRIORITIES - 1 )
#define netifGUARD_BLOCK_TIME				( 250 )
#define IFNAME0 'e'
#define IFNAME1 'm'

/* lwIP definitions. */
struct ethernetif
{
	struct eth_addr *ethaddr;
};
static const struct eth_addr    ethbroadcast = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
static struct netif *xNetIf = NULL;

/* Forward declarations. */
static void ethernetif_input( void * );
static err_t ethernetif_output( struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr );
err_t ethernetif_init( struct netif *netif );


/*-----------------------------------------------------------*/

static void low_level_init( struct netif *netif )
{
unsigned portBASE_TYPE uxPriority;

	/* set MAC hardware address length */
	netif->hwaddr_len = 6;

	/* set MAC hardware address */
	netif->hwaddr[0] = emacETHADDR0;
	netif->hwaddr[1] = emacETHADDR1;
	netif->hwaddr[2] = emacETHADDR2;
	netif->hwaddr[3] = emacETHADDR3;
	netif->hwaddr[4] = emacETHADDR4;
	netif->hwaddr[5] = emacETHADDR5;

	/* maximum transfer unit */
	netif->mtu = netifMTU;

	/* broadcast capability */
	netif->flags = NETIF_FLAG_BROADCAST;

	xNetIf = netif;

	/* Initialise the EMAC.  This routine contains code that polls status bits.  
	If the Ethernet cable is not plugged in then this can take a considerable 
	time.  To prevent this starving lower priority tasks of processing time we
	lower our priority prior to the call, then raise it back again once the
	initialisation is complete. */
	uxPriority = uxTaskPriorityGet( NULL );
	vTaskPrioritySet( NULL, tskIDLE_PRIORITY );
	while( xEMACInit() == NULL )
	{
		__asm( "NOP" );
	}
	vTaskPrioritySet( NULL, uxPriority );

	/* Create the task that handles the EMAC. */
	xTaskCreate( ethernetif_input, ( signed portCHAR * ) "ETH_INT", netifINTERFACE_TASK_STACK_SIZE, NULL, netifINTERFACE_TASK_PRIORITY, NULL );
}
/*-----------------------------------------------------------*/

/*
 * low_level_output(): Should do the actual transmission of the packet. The 
 * packet is contained in the pbuf that is passed to the function. This pbuf 
 * might be chained.
 */
static err_t low_level_output( struct netif *netif, struct pbuf *p )
{
struct pbuf *q;
static xSemaphoreHandle xTxSemaphore = NULL;
err_t xReturn = ERR_OK;

	/* Parameter not used. */
	( void ) netif;

	if( xTxSemaphore == NULL )
	{
		vSemaphoreCreateBinary( xTxSemaphore );
	}

	#if ETH_PAD_SIZE
		pbuf_header( p, -ETH_PAD_SIZE );    /* drop the padding word */
	#endif

	/* Access to the EMAC is guarded using a semaphore. */
	if( xSemaphoreTake( xTxSemaphore, netifGUARD_BLOCK_TIME ) )
	{
		for( q = p; 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->next == NULL then this is the last pbuf in the
			chain. */
			if( !lEMACSend( q->payload, q->len, ( q->next == NULL ) ) )
			{
				xReturn = ~ERR_OK;
			}
		}

        xSemaphoreGive( xTxSemaphore );
	}
	

	#if ETH_PAD_SIZE
		pbuf_header( p, ETH_PAD_SIZE );     /* reclaim the padding word */
	#endif

	#if LINK_STATS
		lwip_stats.link.xmit++;
	#endif /* LINK_STATS */

    return xReturn;
}
/*-----------------------------------------------------------*/

/*
 * low_level_input(): Should allocate a pbuf and transfer the bytes of the 
 * incoming packet from the interface into the pbuf. 
 */
static struct pbuf *low_level_input( struct netif *netif )
{
struct pbuf         *p = NULL, *q;
u16_t               len = 0;
static xSemaphoreHandle xRxSemaphore = NULL;

	/* Parameter not used. */
	( void ) netif;

	if( xRxSemaphore == NULL )
	{
		vSemaphoreCreateBinary( xRxSemaphore );
	}

	/* Access to the emac is guarded using a semaphore. */
   	if( xSemaphoreTake( xRxSemaphore, netifGUARD_BLOCK_TIME ) )
	{
		/* Obtain the size of the packet. */
		len = ulEMACInputLength();
	
		if( len )
		{
			#if ETH_PAD_SIZE
				len += ETH_PAD_SIZE;    /* allow room for Ethernet padding */
			#endif
	
			/* We allocate a pbuf chain of pbufs from the pool. */
			p = pbuf_alloc( PBUF_RAW, len, PBUF_POOL );
		
			if( p != NULL )
			{
				#if ETH_PAD_SIZE
					pbuf_header( p, -ETH_PAD_SIZE );    /* drop the padding word */
				#endif
		
				/* Let the driver know we are going to read a new packet. */
				vEMACRead( NULL, 0, len );
					
				/* We iterate over the pbuf chain until we have read the entire
				packet into the pbuf. */				
				for( q = p; q != NULL; q = q->next )
				{
					/* Read enough bytes to fill this pbuf in the chain. The 
					available data in the pbuf is given by the q->len variable. */
					vEMACRead( q->payload, q->len, len );
				}
		
				#if ETH_PAD_SIZE
					pbuf_header( p, ETH_PAD_SIZE );     /* reclaim the padding word */
				#endif
				#if LINK_STATS
					lwip_stats.link.recv++;
				#endif /* LINK_STATS */
			}
			else
			{
				#if LINK_STATS
					lwip_stats.link.memerr++;
					lwip_stats.link.drop++;
				#endif /* LINK_STATS */
			}
		}

		xSemaphoreGive( xRxSemaphore );
	}

	return p;
}
/*-----------------------------------------------------------*/

/*
 * ethernetif_output(): This function is called by the TCP/IP stack when an 
 * IP packet should be sent. It calls the function called low_level_output() 
 * to do the actual transmission of the packet.
 */
static err_t ethernetif_output( struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr )
{
    /* resolve hardware address, then send (or queue) packet */
    return etharp_output( netif, ipaddr, p );
}
/*-----------------------------------------------------------*/

/*
 * ethernetif_input(): This function should be called when a packet is ready to 
 * be read from the interface. It uses the function low_level_input() that 
 * should handle the actual reception of bytes from the network interface.
 */
static void ethernetif_input( void * pvParameters )
{
struct ethernetif   *ethernetif;
struct eth_hdr      *ethhdr;
struct pbuf         *p;

	( void ) pvParameters;

	for( ;; )
	{
		do
		{
			ethernetif = xNetIf->state;

			/* move received packet into a new pbuf */
			p = low_level_input( xNetIf );

			if( p == NULL )
			{
				/* No packet could be read.  Wait a for an interrupt to tell us 
				there is more data available. */
				vEMACWaitForInput();
			}

		} while( p == NULL );
	
		/* points to packet payload, which starts with an Ethernet header */
		ethhdr = p->payload;
	
		#if LINK_STATS
			lwip_stats.link.recv++;
		#endif /* LINK_STATS */
	
		ethhdr = p->payload;
	
		switch( htons( ethhdr->type ) )
		{
			/* IP packet? */
			case ETHTYPE_IP:
				/* update ARP table */
				etharp_ip_input( xNetIf, p );
		
				/* skip Ethernet header */
				pbuf_header( p, (s16_t)-sizeof(struct eth_hdr) );
		
				/* pass to network layer */
				xNetIf->input( p, xNetIf );
				break;
		
			case ETHTYPE_ARP:
				/* pass p to ARP module */
				etharp_arp_input( xNetIf, ethernetif->ethaddr, p );
				break;
		
			default:
				pbuf_free( p );
				p = NULL;
				break;
		}
	}
}
/*-----------------------------------------------------------*/

static void arp_timer( void *arg )
{
	( void ) arg;

    etharp_tmr();
    sys_timeout( ARP_TMR_INTERVAL, arp_timer, NULL );
}
/*-----------------------------------------------------------*/

err_t ethernetif_init( struct netif *netif )
{
struct ethernetif   *ethernetif;

	ethernetif = mem_malloc( sizeof(struct ethernetif) );

	if( ethernetif == NULL )
	{
		LWIP_DEBUGF( NETIF_DEBUG, ("ethernetif_init: out of memory\n") );
		return ERR_MEM;
	}

	netif->state = ethernetif;
	netif->name[0] = IFNAME0;
	netif->name[1] = IFNAME1;
	netif->output = ethernetif_output;
	netif->linkoutput = low_level_output;

	ethernetif->ethaddr = ( struct eth_addr * ) &( netif->hwaddr[0] );

	low_level_init( netif );
	etharp_init();
	sys_timeout( ARP_TMR_INTERVAL, arp_timer, NULL );

	return ERR_OK;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产最新精品免费| 日韩一区国产二区欧美三区| 欧美日韩综合不卡| 久久嫩草精品久久久精品一| 亚洲精品中文在线观看| 精品亚洲aⅴ乱码一区二区三区| av男人天堂一区| 欧美不卡在线视频| 亚洲影院理伦片| 成人app在线| 国产午夜精品一区二区三区嫩草 | 奇米影视7777精品一区二区| 国产成人av福利| 欧美成人精品二区三区99精品| 亚洲精品ww久久久久久p站| 国产在线观看免费一区| 91精品国产综合久久婷婷香蕉 | 美女精品自拍一二三四| 一本一道综合狠狠老| 中文子幕无线码一区tr| 久久成人18免费观看| 欧美日韩一区二区三区四区| 亚洲女人的天堂| 成人丝袜高跟foot| 久久久久成人黄色影片| 狠狠色丁香婷婷综合| 日韩一本二本av| 免费人成在线不卡| 日韩一级大片在线观看| 日韩经典一区二区| 欧美精品乱码久久久久久| 亚洲成av人影院| 欧美精品18+| 日本系列欧美系列| 日韩欧美亚洲另类制服综合在线| 午夜精品久久久| 7777精品伊人久久久大香线蕉| 一区二区三区国产精品| 欧美日韩综合在线| 婷婷久久综合九色国产成人| 欧美日韩精品一区二区三区蜜桃 | 亚洲欧美一区二区久久| 国产在线不卡一区| 欧美国产日韩精品免费观看| 国产成人免费在线观看不卡| 中文字幕在线观看一区| 91捆绑美女网站| 亚洲精品高清在线观看| 欧美性猛片xxxx免费看久爱| 五月激情丁香一区二区三区| 欧美一区二区免费观在线| 久久精品噜噜噜成人88aⅴ| 久久综合中文字幕| 成人av电影在线网| 亚洲视频一区在线| 欧美视频在线一区二区三区 | 亚洲一区二区三区美女| 91精品国产一区二区| 狠狠色丁香九九婷婷综合五月| 国产精品日产欧美久久久久| 欧美日韩一级视频| 久久99精品网久久| 成人免费小视频| 777午夜精品视频在线播放| 韩国v欧美v日本v亚洲v| 亚洲色图制服诱惑| 7777精品伊人久久久大香线蕉最新版| 久久精品99国产国产精| 亚洲国产高清不卡| 欧美美女网站色| 国产精品一卡二| 日韩综合一区二区| 亚洲国产成人在线| 91精品国产品国语在线不卡| 国产成人丝袜美腿| 日韩av在线免费观看不卡| 国产精品午夜春色av| 欧美精品久久99久久在免费线| 国产成人丝袜美腿| 秋霞电影一区二区| 一区2区3区在线看| 国产欧美日韩中文久久| 欧美日韩不卡在线| 93久久精品日日躁夜夜躁欧美| 偷拍日韩校园综合在线| 欧美国产欧美综合| 日韩免费成人网| 欧美日韩精品一区二区天天拍小说| 国产激情精品久久久第一区二区| 亚洲高清视频在线| 亚洲天堂精品在线观看| 久久免费电影网| 7777精品伊人久久久大香线蕉| av在线一区二区| 国产一区二区三区在线观看免费 | 亚洲欧洲99久久| 久久精品视频在线免费观看| 7777精品伊人久久久大香线蕉超级流畅 | 2023国产精华国产精品| 6080yy午夜一二三区久久| 色视频一区二区| 99精品久久免费看蜜臀剧情介绍| 国产福利不卡视频| 久久精品噜噜噜成人av农村| 日韩不卡一二三区| 无码av免费一区二区三区试看| 亚洲综合色噜噜狠狠| 亚洲欧洲精品成人久久奇米网| 国产日韩欧美在线一区| 精品国产乱码久久久久久久久| 911国产精品| 日韩三级视频在线看| 日韩欧美aaaaaa| 欧美一卡二卡在线观看| 91精品久久久久久久久99蜜臂| 欧美日本乱大交xxxxx| 欧美日韩国产免费| 欧美片在线播放| 7777精品久久久大香线蕉| 日韩欧美中文字幕公布| 日韩精品一区二区三区中文不卡 | 国产精品一二三四| 国产高清成人在线| 成人综合婷婷国产精品久久蜜臀 | 国产成人精品一区二区三区网站观看| 国模少妇一区二区三区| 国产一区久久久| 成人动漫视频在线| 91蝌蚪porny成人天涯| 色丁香久综合在线久综合在线观看| 色狠狠一区二区三区香蕉| 日本福利一区二区| 欧美日韩中文字幕一区| 91精品婷婷国产综合久久竹菊| 日韩欧美电影一区| 2014亚洲片线观看视频免费| 国产精品视频看| 亚洲综合男人的天堂| 麻豆国产一区二区| 成人av午夜影院| 欧美日韩国产高清一区二区| 日韩限制级电影在线观看| 欧美精彩视频一区二区三区| 亚洲精品国产a| 日韩精品成人一区二区三区 | 国产精品家庭影院| 亚洲国产一区视频| 狠狠狠色丁香婷婷综合激情 | 国产亚洲婷婷免费| 亚洲视频免费看| 蜜桃久久久久久| 97精品久久久午夜一区二区三区| 欧美私人免费视频| 久久久精品欧美丰满| 亚洲图片有声小说| 国产一区二区中文字幕| 欧美性生活影院| 久久精品免视看| 丝袜亚洲另类欧美| 国产不卡在线播放| 91精品午夜视频| 国产精品高潮呻吟| 免费在线看一区| 色婷婷综合久久久久中文| 精品久久久久久久久久久久久久久| 亚洲欧美日韩久久| 国产成人丝袜美腿| 日韩美女视频在线| 亚洲一区二区中文在线| 成人高清免费在线播放| 91.成人天堂一区| 亚洲一卡二卡三卡四卡| 国产精品99久久久| 欧美成人女星排名| 香蕉久久夜色精品国产使用方法| 91小视频在线| 国产亚洲一本大道中文在线| 日本系列欧美系列| 欧美无乱码久久久免费午夜一区| 国产精品色在线观看| 韩国午夜理伦三级不卡影院| 欧美日韩不卡一区| 亚洲影院久久精品| 99精品国产91久久久久久| 久久久精品日韩欧美| 九九**精品视频免费播放| 欧美三级中文字幕| 国产精品日韩成人| 成人在线综合网站| 国产午夜精品理论片a级大结局| 国内久久精品视频| 精品国产乱码91久久久久久网站| 男人操女人的视频在线观看欧美| 欧美系列亚洲系列| 亚洲精品国产一区二区精华液 | 成人免费视频免费观看| 久久亚洲精华国产精华液| 蜜桃在线一区二区三区| 欧美一区二区三区四区视频| 日韩av一区二区三区|