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

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

?? ethernet.c

?? 用于三星S3C44BOX ARM7芯片的Demon板測試
?? C
字號:
/*********************************************************************************************
* File:	EtherNet.c
* Author:	embest	
* Desc:	ethernet MAC protocol and control code
* History:	
*********************************************************************************************/

/*--- include files ---*/

#include "44b.h"
#include "44blib.h"
#include "def.h"
#include "option.h"
#include "ethernet.h"

/*--- global variables ---*/

/* local MAC Address */
char mac_addr[6] = { 0x00,0x06,0x98,0x01,0x7E,0x8F };

/* data buffer and operate signal */
char  net_out_data[1536];
char  net_in_data[1536];
int	  iReceiveData;
int   iSendData;

/* Ethernet control address */
volatile UCHAR *ether_base = (UCHAR *)0x02180000;
int EtherOutput(UCHAR *dmac,char* pdata, USHORT len);
int EtherInput(USHORT tms);
int iLoopBackMode;

/*--- function decleare ---*/

int  NicReset(void);
void NicInit(void);
void NicClose(void);
void DelayTimes(int num);

/*--- function code ---*/

/*********************************************************************************************
* name:		NicInit
* func:		initialize 8019AS chip
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void NicInit(void)
{
    int i;
    char temp;

	if(NicReset())
	{
		Uart_Printf("\nReset 8019AS fail!\n");
        LCD_view(vcol,vrow,BLACK,"Reset 8019AS fail!");
		return;
	}
        
	nic_write(NIC_PG0_IMR, 0x0);		// disable 8019 interrupt
    nic_write(NIC_PG0_ISR, 0xff);		// clear interrupt status
    
    /* stop command,complete DMA,RTL8019 configuration(Page 3) */
    nic_write(NIC_CR, NIC_CR_STP | NIC_CR_RD2 | NIC_CR_PS0 | NIC_CR_PS1);
    /* write register enable */
    nic_write(NIC_PG3_EECR, NIC_EECR_EEM0 | NIC_EECR_EEM1);	
    /* jumper mode, half-duplex */
    nic_write(NIC_PG3_CONFIG3, 0x0);
    /* 8019as */
    nic_write(NIC_PG3_CONFIG0, 0x0);
    /* Auto-detect, BROM disable */
    nic_write(NIC_PG3_CONFIG2, NIC_CONFIG2_BSELB);
    /* write register disable */
    nic_write(NIC_PG3_EECR, 0x0);
    DelayTimes(100);						// delay some times
    /* Page 0 configure */
    nic_write(NIC_CR, NIC_CR_STP | NIC_CR_RD2);
   	/* Normal Operate, FIFO threshold 1 */
    nic_write(NIC_PG0_DCR, NIC_DCR_LS | NIC_DCR_FT1);
    /* clear Remote byte count Register */
    nic_write(NIC_PG0_RBCR0, 0x0);
    nic_write(NIC_PG0_RBCR1, 0x0);
    /* receive monitor mode */
    nic_write(NIC_PG0_RCR, NIC_RCR_MON);
    /* Internel Loopback */
    nic_write(NIC_PG0_TCR, NIC_TCR_LB0);
    /* Transmit Page Start */
    nic_write(NIC_PG0_TPSR, NIC_FIRST_TX_PAGE);
    /* Boundary */
    nic_write(NIC_PG0_BNRY, NIC_STOP_PAGE-1);
    /* Receive Page Start */
    nic_write(NIC_PG0_PSTART, NIC_FIRST_RX_PAGE);
    /* Receive Page Stop */
    nic_write(NIC_PG0_PSTOP, NIC_STOP_PAGE);
    nic_write(NIC_PG0_ISR, 0xff);		// clear interrupt status
    /* Page 1 configure */
    nic_write(NIC_CR, NIC_CR_STP | NIC_CR_RD2 | NIC_CR_PS0);
    /* set MAC address */
    for( i = 0; i < 6; i++ )
        nic_write(NIC_PG1_PAR0 + i, mac_addr[i]);
    /* broadcast address is 0x0 */
    for( i = 0; i < 8; i++ )
        nic_write(NIC_PG1_MAR0 + i, 0);
    /* Current Page */
    nic_write(NIC_PG1_CURR, NIC_FIRST_RX_PAGE);
    /* Page 0 Configure */
    nic_write(NIC_CR, NIC_CR_STP | NIC_CR_RD2);
    /* only accept destination address message */
    nic_write(NIC_PG0_RCR, 0x0);
    nic_write(NIC_PG0_ISR, 0xff);		// clear interrupt status
    /* enable received interrupt */
    nic_write(NIC_PG0_IMR, NIC_IMR_PRXE);			
    /* Start command */
    nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD2);
   	/* CRC enable, Normal Operate */
    nic_write(NIC_PG0_TCR, 0x0);
    DelayTimes(100);						// delay some times
}

/*********************************************************************************************
* name:		NicClose
* func:		close 8019AS chip
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void NicClose(void)
{
	/* close ethernet */
	nic_write(NIC_PG0_IMR, 0);			// disable interrupt
    nic_write(NIC_PG0_ISR, 0xff);		// clear interrupt status
	nic_write(NIC_CR, NIC_CR_STP | NIC_CR_RD2);
}

/*********************************************************************************************
* name:		NicReset
* func:		Reset 8019AS chip
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
int NicReset(void)
{
    UCHAR i;
    UCHAR j;

    for( j = 0; j < 20; j++ )
    {
        i = nic_read(NIC_RESET);
        DelayTimes(50);
        nic_write(NIC_RESET, i);
        for( i = 0; i < 20; i++ )
        {
            DelayTimes(50);
            if(nic_read(NIC_PG0_ISR) & NIC_ISR_RST)
                return 0;
        }
    }
    return -1;
}

/*********************************************************************************************
* name:		EtherOutput
* func:		output data through ethernet 8019AS chip
* para:		pdata -- data pointer
*			len	  -- data length
* ret:		0 -- success 		-1 -- fail
* modify:
* comment:		
*********************************************************************************************/
int EtherOutput(UCHAR *dmac,char* pdata, USHORT len)
{
    USHORT i;
    USHORT send_len;
    UCHAR *cp;
	struct ETHERHDR *eh;
	
	/* set MAC address */
	eh = (struct ETHERHDR *)pdata;
    for(i = 0; i < 6; i++)
        eh->ether_shost[i] = mac_addr[i];
    for(i = 0; i < 6; i++)
        eh->ether_dhost[i] = dmac[i];
    
    send_len = len + sizeof(struct ETHERHDR);
    if( send_len > 1518 )
    {
    	Uart_Printf("\nCann't send data more than 1518 bytes!\n");
    	return -1;
    }
    /* at less send 60 byte */
    if( send_len < 60 )
        send_len = 60;

	/* Register Page 0 operate */
    nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD2);
    /* set byte count */
    nic_write(NIC_PG0_RBCR0, (UCHAR)(send_len));
    /* set byte count */
    nic_write(NIC_PG0_RBCR1, (UCHAR)(send_len >> 8));
    /* Remote Start Address*/
    nic_write(NIC_PG0_RSAR0, 0);
    /* Remote Start Address */
    nic_write(NIC_PG0_RSAR1, NIC_FIRST_TX_PAGE);
    /* remote write */
    nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD1);
    
    /* Transfer data. */
    cp = pdata;
    for( i = 0; i < send_len; i++, cp++ )
        nic_write(NIC_IOPORT, *cp);
    for( i = send_len; i < 60; i++ )
        nic_write(NIC_IOPORT, 0);
    
    /** Complete remote dma. */
    nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD2);
    /* if completed */
    for( i = 0; i <= 20; i++ )
        if(nic_read(NIC_PG0_ISR) & NIC_ISR_RDC)
            break;
    /* clear status */
    nic_write(NIC_PG0_ISR, NIC_ISR_RDC);
        
    /* Number of bytes to be transmitted. */
    nic_write(NIC_PG0_TBCR0, ((send_len) & 0xff));
    nic_write(NIC_PG0_TBCR1, ((send_len >> 8) & 0xff));
        
    /* First page of packet to be transmitted. */
    nic_write(NIC_PG0_TPSR, NIC_FIRST_TX_PAGE);
        
    /* Start transmission. */
    nic_write(NIC_CR, NIC_CR_STA | NIC_CR_TXP | NIC_CR_RD1 | NIC_CR_RD0);

    /* Wait until transmission is completed or aborted. */
    while(nic_read(NIC_CR) & NIC_CR_TXP);

	/* Complete DMA. */
    nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD2 );

	iSendData = 0;
	
    return 0;
}

/*********************************************************************************************
* name:		EtherInput
* func:		get data from ethernet
* para:		tms -- timeout value
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
int EtherInput(USHORT tms)
{
    int    rc = 0;
    UCHAR  isr = 0;
    struct NICPKYTHEADER hdr;
    UCHAR  *buf;
    UCHAR  nextpg;
    UCHAR  bnry;
    UCHAR  curr;
    USHORT i;
    UCHAR  wtc;

	tms = tms*50;
    while( (tms && rc) == 0 )
    {
        for( wtc = 1; tms; wtc++ )
        {
            isr = nic_read(NIC_PG0_ISR);
            /* Is error ? */
            if( isr & NIC_ISR_RXE )
            {
            	/* clear interrupt status register */
            	nic_write(NIC_PG0_ISR,isr);
                return -1;
            }
            /* get packet */
            if( isr & NIC_ISR_PRX )
                break;
            /* Is timeout */
            if( wtc == 0 )
                tms--;
             
            if(Uart_GetKey()|(key_read() != -1)) Main();
        }
        
        /* Any frame received? */
        if( (isr & NIC_ISR_PRX) == 0 )
        {
        	/* clear interrupt status register */
            nic_write(NIC_PG0_ISR, isr);
            break;
        }
    
        /* Get the current page pointer. It points to the page where the NIC 
         * will start saving the next incoming packet. */
        nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD2 | NIC_CR_PS0);
        curr = nic_read(NIC_PG1_CURR);
        nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD2);
        
        /* Get the pointer to the last page we read from. The following page
         * is the one where we start reading. */
        if( (bnry = (nic_read(NIC_PG0_BNRY) + 1)) >= NIC_STOP_PAGE )
            bnry = NIC_FIRST_RX_PAGE;
            
        /* if bnry equal curr, mean not data ,nothing to read */
        if( bnry == curr )
        {
            nic_write(NIC_PG0_ISR, isr);
            continue;
        }
        
        /* Read the NIC specific packet header. */
        nic_write(NIC_PG0_RBCR0, sizeof(struct NICPKYTHEADER));
        nic_write(NIC_PG0_RBCR1, 0);
        nic_write(NIC_PG0_RSAR0, 0);
        nic_write(NIC_PG0_RSAR1, bnry);
        buf = (UCHAR *)&hdr;
        nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD0);
        for( i = 0; i < sizeof(struct NICPKYTHEADER); i++ )
            *buf++ = nic_read(NIC_IOPORT);
        
        /** Complete remote dma. */
        nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD2);
        for( i = 0; i <= 20; i++ )
        {
            if(nic_read(NIC_PG0_ISR) & NIC_ISR_RDC)
                break;
        }
        nic_write(NIC_PG0_ISR, NIC_ISR_RDC);
        
        /* Check packet length. */
        if( hdr.ph_size < (60 + sizeof(struct NICPKYTHEADER)) ||
            hdr.ph_size > (1518 + sizeof(struct NICPKYTHEADER)) )
        {
        	nic_write(NIC_PG0_ISR, isr);
            return 0;
        }
        
        /* Calculate the page of the next packet. If it differs from the
         * pointer in the packet header, we discard the whole buffer
         * and return a null pointer. */
        nextpg = bnry + (hdr.ph_size >> 8) + ((hdr.ph_size & 0xFF) != 0);
        if( nextpg >= NIC_STOP_PAGE )
        {
            nextpg -= NIC_STOP_PAGE;
            nextpg += NIC_FIRST_RX_PAGE;
        }
        if( nextpg != hdr.ph_nextpg )
        {
            UCHAR nextpg1 = nextpg + 1;
            
            if( nextpg1 >= NIC_STOP_PAGE )
            {
                nextpg1 -= NIC_STOP_PAGE;
                nextpg1 += NIC_FIRST_RX_PAGE;
            }
            if( nextpg1 != hdr.ph_nextpg )
            {
                nic_write(NIC_PG0_ISR, isr);
                break;
            }
            nextpg = nextpg1;
        }
        
        /* Check packet status. */
        if( (hdr.ph_status & 0x0F) == 1 )
        {
            rc = hdr.ph_size - sizeof(struct NICPKYTHEADER);
            
            /* Set remote dma byte count and start address. Don't read the
             * header again. */
            nic_write(NIC_PG0_RBCR0, (UCHAR)rc);
            nic_write(NIC_PG0_RBCR1, (UCHAR)((USHORT)rc >> 8));
            nic_write(NIC_PG0_RSAR0, sizeof(struct NICPKYTHEADER));
            nic_write(NIC_PG0_RSAR1, bnry);
            
            /* Perform the read. */
            nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD0);
            buf = net_in_data;
            for( i = 0; i < rc; i++ )
                *buf++ = nic_read(NIC_IOPORT);
            
            /* Complete remote dma. */
            nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD2);
            
            for( i = 0; i <= 20; i++ )
            {
                if(nic_read(NIC_PG0_ISR) & NIC_ISR_RDC)
                    break;
            }
            nic_write(NIC_PG0_ISR, NIC_ISR_RDC);
            iReceiveData = 1;
        }
        
        /* Set boundary register to the last page we read. */
        if( --nextpg < NIC_FIRST_RX_PAGE )
            nextpg = NIC_STOP_PAGE - 1;
        nic_write(NIC_PG0_BNRY, nextpg);
    }
    
    return rc;
}
/*********************************************************************************************
* name:		DelayTimes
* func:		delay time
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void DelayTimes(int num)
{
	int i;
	
	for( i = 0 ; i < num ; i++ )
		;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人av先锋影音| 午夜精品一区二区三区三上悠亚 | 国产精品美女久久久久久久| 久久99精品久久久久久国产越南| 7799精品视频| 久久99精品国产.久久久久 | 另类小说欧美激情| 日韩免费在线观看| 国产一区二区0| 国产精品欧美一区喷水| 色综合视频在线观看| 亚洲免费毛片网站| 欧美喷潮久久久xxxxx| 奇米精品一区二区三区四区 | 亚洲精品在线免费播放| 国产综合色产在线精品| 国产欧美一区二区三区在线老狼| jlzzjlzz亚洲日本少妇| 亚洲二区在线视频| 精品国产99国产精品| av动漫一区二区| 视频一区免费在线观看| 国产三级三级三级精品8ⅰ区| 99久精品国产| 日本sm残虐另类| 久久精品亚洲精品国产欧美| 99久久国产综合精品色伊| 午夜成人在线视频| 国产亚洲欧洲997久久综合 | 成人黄色av电影| 亚洲一区二区三区四区的| 精品久久久久久最新网址| aaa亚洲精品| 久久不见久久见中文字幕免费| 国产精品久久久久桃色tv| 7777精品久久久大香线蕉| 成人av午夜电影| 日韩成人一级片| 国产精品美女视频| 欧美一区二区美女| 成人动漫一区二区在线| 青青草一区二区三区| 国产精品夫妻自拍| 欧美va在线播放| 色欲综合视频天天天| 国内精品免费**视频| 亚洲福利电影网| 日韩美女视频19| 久久麻豆一区二区| 91精品国产综合久久小美女| 99国产精品久久久久久久久久 | 亚洲精品欧美二区三区中文字幕| 日韩免费高清视频| 欧美亚洲综合一区| av中文一区二区三区| 韩国欧美国产一区| 日本成人中文字幕| 亚洲国产sm捆绑调教视频 | 亚洲综合色视频| 国产日产欧产精品推荐色| 678五月天丁香亚洲综合网| 色伊人久久综合中文字幕| 国产成人精品三级麻豆| 久久精品国产久精国产| 天堂久久一区二区三区| 亚洲精品国产无天堂网2021 | 国产精品久久久久久久久免费樱桃 | 色综合久久久久综合体| 成人免费视频播放| 国产精品99久| 国产一本一道久久香蕉| 久久99国内精品| 蜜桃视频第一区免费观看| 亚洲不卡一区二区三区| 一区av在线播放| 亚洲男女毛片无遮挡| 亚洲日本在线视频观看| 综合久久国产九一剧情麻豆| 国产精品丝袜91| 国产精品国产三级国产aⅴ入口| 久久精品亚洲一区二区三区浴池| 精品成人a区在线观看| 亚洲精品一区二区在线观看| 欧美本精品男人aⅴ天堂| 欧美成人a∨高清免费观看| 欧美v亚洲v综合ⅴ国产v| 欧美电影免费观看高清完整版在线观看 | 国产丝袜在线精品| 中文字幕av资源一区| 欧美国产精品专区| 中文字幕日韩精品一区| 亚洲人成网站色在线观看| 一区二区三区毛片| 亚洲国产视频a| 日韩成人精品视频| 精品一区二区精品| 国产91对白在线观看九色| 不卡的av在线| 日本高清不卡视频| 制服丝袜国产精品| 国产婷婷色一区二区三区四区 | 亚洲三级在线免费观看| 樱桃国产成人精品视频| 日本伊人午夜精品| 国产激情一区二区三区四区| 94色蜜桃网一区二区三区| 在线视频综合导航| 日韩手机在线导航| 国产欧美一区二区三区在线看蜜臀 | 亚洲美女在线一区| 视频一区中文字幕国产| 国产高清不卡一区二区| 色嗨嗨av一区二区三区| 精品少妇一区二区三区免费观看 | 欧美一二三区在线观看| 国产三级精品三级| 亚洲国产视频直播| 国产伦理精品不卡| 欧美艳星brazzers| 久久久久久麻豆| 亚洲午夜电影网| 成人自拍视频在线观看| 欧美日韩国产在线观看| 国产欧美一区二区三区在线看蜜臀 | 欧美日韩不卡一区二区| 国产区在线观看成人精品 | 国产精品99久久久久久宅男| 色婷婷激情久久| 538prom精品视频线放| 久久久久国产一区二区三区四区 | 99久久99久久综合| 日韩视频在线观看一区二区| 国产欧美日韩综合精品一区二区| 中文字幕一区二区三区精华液| 亚洲一区二区综合| 国产精品主播直播| 在线视频亚洲一区| 久久久久青草大香线综合精品| 亚洲国产综合人成综合网站| 精品一二线国产| 色综合久久久久综合体桃花网| 日韩午夜在线观看视频| 中文字幕一区在线观看| 蜜臀久久99精品久久久久久9| 不卡视频在线看| 欧美一区二区免费观在线| 亚洲一区二区三区在线看| 国产一区欧美一区| 欧美三区在线观看| 国产精品网站导航| 国产麻豆午夜三级精品| 欧美日韩免费视频| 久久美女艺术照精彩视频福利播放| 国产精品久久免费看| 美女视频黄久久| 欧美日韩三级一区| 亚洲天堂福利av| 韩日精品视频一区| 亚洲精品一区二区三区在线观看 | 日本系列欧美系列| 色8久久人人97超碰香蕉987| 国产欧美一区二区精品忘忧草| 日韩不卡一区二区| 欧美日韩一级大片网址| 亚洲视频你懂的| 成人午夜av影视| 国产网红主播福利一区二区| 久久国产剧场电影| 欧美精品1区2区| 亚洲一区二区精品3399| 色综合天天做天天爱| 国产精品网友自拍| 97久久久精品综合88久久| 国产日韩av一区二区| 国产精品1区二区.| 久久久精品tv| 成人avav在线| 国产精品美女一区二区三区| 成人污视频在线观看| 久久精品夜色噜噜亚洲aⅴ| 成人性生交大片| 国产欧美日韩精品一区| 国产乱码精品一区二区三区五月婷| 日韩三级av在线播放| 国产精品主播直播| 久久综合狠狠综合| 国产精品一区不卡| 精品粉嫩超白一线天av| 成人深夜福利app| 亚洲视频一二三区| 91行情网站电视在线观看高清版| 樱花草国产18久久久久| 欧美色综合天天久久综合精品| 一区二区成人在线| 欧美人动与zoxxxx乱| 国产精品伊人色| 国产精品人成在线观看免费| 97se亚洲国产综合自在线不卡| 亚洲免费视频中文字幕| 欧美一级二级三级乱码|