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

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

?? enc28j60.c

?? 凌陽SPCE3200 系統開發板隨機自帶源程序。共安排了32個子目錄
?? C
?? 第 1 頁 / 共 5 頁
字號:
/*********************************************************************
 *
 *     MAC Module (Microchip ENC28J60) for Microchip TCP/IP Stack
 *
 *********************************************************************
 * FileName:        ENC28J60.c
 * Dependencies:    ENC28J60.h
 *					MAC.h
 *					string.h
 *                  StackTsk.h
 *                  Helpers.h
 *					Delay.h
 * Processor:       PIC18
 * Complier:        MCC18 v3.00 or higher
 *                  HITECH PICC-18 V8.10PL1 or higher
 * Company:         Microchip Technology, Inc.
 *
 * Software License Agreement
 *
 * This software is owned by Microchip Technology Inc. ("Microchip") 
 * and is supplied to you for use exclusively as described in the 
 * associated software agreement.  This software is protected by 
 * software and other intellectual property laws.  Any use in 
 * violation of the software license may subject the user to criminal 
 * sanctions as well as civil liability.  Copyright 2006 Microchip
 * Technology Inc.  All rights reserved.
 *
 * This software is provided "AS IS."  MICROCHIP DISCLAIMS ALL 
 * WARRANTIES, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, NOT LIMITED 
 * TO MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND 
 * INFRINGEMENT.  Microchip shall in no event be liable for special, 
 * incidental, or consequential damages.
 *
 * Author               Date   		Comment
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * Howard Schlunder		6/28/04	Original
 * Howard Schlunder		10/8/04	Cleanup
 * Howard Schlunder		10/19/04 Small optimizations and more cleanup
 * Howard Schlunder		11/29/04 Added Set/GetCLKOUT
 * Howard Schlunder		12/23/05 Added B1 silicon errata workarounds
 * Howard Schlunder		1/09/06	Added comments and minor mods
 * Howard Schlunder		1/18/06 Added more silicon errata workarounds
 * Howard Schlunder		2/20/06 Fixed TXSTART, RXSTOP
********************************************************************/
#define THIS_IS_MAC_LAYER

#include <string.h>
#include "StackTsk.h"
#include "Helpers.h"
//#include "Delay.h"
#include "MAC.h"
#include "ENC28J60.h"


#if defined(STACK_USE_SLIP)
#error Unexpected module is detected.
#error This file must be linked when SLIP module is not in use.
#endif


/** D E F I N I T I O N S ****************************************************/
/* Hardware interface to NIC. */
#define MCP_RESET_TRIS	(TRISB_RB5)
#define MCP_RESET_IO	(LATB5)
#define MCP_CS_TRIS		(TRISB_RB3)
#define MCP_CS_IO		(LATB3)
// The following SPI pins are used but are not configurable
//   RC3 is used for the SCK pin and is an output
//   RC4 is used for the SDI pin and is an input
//   RC5 is used for the SDO pin and is an output
// IMPORTANT SPI NOTE: The code in this file expects that the SPI interrupt 
//		flag (PIR1_SSPIF) be clear at all times.  If the SPI is shared with 
//		other hardware, the other code should clear the PIR1_SSPIF when it is 
//		done using the SPI.

// Since the ENC28J60 doesn't support auto-negotiation, full-duplex mode is 
// not compatible with most switches/routers.  If a dedicated network is used 
// where the duplex of the remote node can be manually configured, you may 
// change this configuration.  Otherwise, half duplex should always be used.
#define HALF_DUPLEX
//#define FULL_DUPLEX
//#define LEDB_DUPLEX

/* Pseudo Functions */
#define LOW(a) 					(a & 0xFF)
#define HIGH(a) 				((a>>8) & 0xFF)
#define SPISelectEthernet()		MCP_CS_IO = 0
#define SPIUnselectEthernet()	MCP_CS_IO = 1

/* NIC RAM definitions */
#define RAMSIZE	8192ul		
#define TXSTART (RAMSIZE-(MAC_TX_BUFFER_COUNT * (MAC_TX_BUFFER_SIZE + 8ul)))
#define RXSTART	(0ul)						// Should be an even memory address
#define	RXSTOP	((TXSTART-2ul) | 0x0001ul)	// Odd for errata workaround
#define RXSIZE	(RXSTOP-RXSTART+1ul)

/* ENC28J60 Opcodes (to be ORed with a 5 bit address) */
#define	WCR (0x2<<5)			// Write Control Register command
#define BFS (0x4<<5)			// Bit Field Set command
#define	BFC (0x5<<5)			// Bit Field Clear command
#define	RCR (0x000<<5)			// Read Control Register command
#define RBM ((0x1<<5) | 0x1A)	// Read Buffer Memory command
#define	WBM ((0x3<<5) | 0x1A) // Write Buffer Memory command
#define	SR  ((0x7<<5) | 0x1F)	// System Reset command does not use an address.  
								//   It requires 0x1F, however.

#define ETHER_IP	(0x00)
#define ETHER_ARP	(0x06)

#define MAXFRAMEC	(1500+sizeof(ETHER_HEADER)+4)

// A generic structure representing the Ethernet header starting all Ethernet 
// frames
typedef struct _ETHER_HEADER
{
    MAC_ADDR        DestMACAddr;
    MAC_ADDR        SourceMACAddr;
    WORD_VAL        Type;
}__attribute__ ((packed)) ETHER_HEADER;

// A header appended at the start of all RX frames by the hardware
typedef struct _MCP_PREAMBLE
{
    WORD			NextPacketPointer;//2
    RXSTATUS		StatusVector;//4

    MAC_ADDR        DestMACAddr;//6
    MAC_ADDR        SourceMACAddr;//6
    WORD_VAL        Type;//2
} __attribute__ ((packed)) MCP_PREAMBLE;

typedef struct _DATA_BUFFER
{
	WORD_VAL StartAddress;
//	WORD_VAL EndAddress;
	BOOL bFree;
}__attribute__ ((packed)) DATA_BUFFER;


/* Prototypes of functions intended for MAC layer use only */
 void BankSel(WORD Register);
 REG ReadETHReg(BYTE Address);
 REG ReadMACReg(BYTE Address);
 void WriteReg(BYTE Address, BYTE Data);
 void BFCReg(BYTE Address, BYTE Data);
 void BFSReg(BYTE Address, BYTE Data);
 void SendSystemReset(void);
 
 void Software_Reset_Ethernet(void);
unsigned char  Read_RCR(unsigned char addr);
unsigned char  Read_MACRCR(unsigned char addr);
void Write_WCR(unsigned char addr,unsigned char data);
unsigned char  Read_RBM(void);
void Write_WBM(unsigned char data);
void Set_BFS(unsigned char addr,unsigned char data);
void Clear_BFC(unsigned char addr,unsigned char data);
void Bank_Select(unsigned char bank);
void Write_PHY(unsigned char addr,unsigned int data);
unsigned int  Read_PHY(unsigned char addr);
unsigned int  Scan_PHY(unsigned char addr);
void Led_Init(void);
 
#ifdef MAC_POWER_ON_TEST
static BOOL TestMemory(void);
#endif

/* Internal and externally used MAC level variables */
#if MAC_TX_BUFFER_COUNT > 1
static DATA_BUFFER TxBuffers[MAC_TX_BUFFER_COUNT];
#endif
BYTE NICCurrentTxBuffer;

/* Internal MAC level variables and flags */
WORD_VAL NextPacketLocation;
WORD_VAL CurrentPacketLocation;
BOOL WasDiscarded;

/***added by lfei 2007/02/05********/
/*   function: 給MACFLUSH函數用于數據包發送使用*/
BYTE ENCRevID;

/*******************************/


/******************************************************************************
 * Function:        void MACInit(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        MACInit sets up the PIC's SPI module and all the 
 *					registers in the ENC28J60 so that normal operation can 
 *					begin.
 *
 * Note:            None
 *****************************************************************************/
void MACInit(void)
{
	BYTE i;


	// Wait for CLKRDY to become set.
	// Bit 3 in ESTAT is an unimplemented bit.  If it reads out as '1' that
	// means the part is in RESET or otherwise our SPI pin is being driven
	// incorrectly.  Make sure it is working before proceeding.
	do
	{
		i = ReadETHReg(ESTAT).Val;

	} while((i & 0x08) || (~i & ESTAT_CLKRDY));


#ifdef MAC_POWER_ON_TEST
	// Do the memory test and enter a while always trap if a hardware error 
	// occured.  The LEDA and LEDB pins will be configured to blink 
	// periodically in an abnormal manner to indicate to the user that the 
	// error occured.
	if( !TestMemory() )
	{
		SetLEDConfig(0x0AA2);		// Set LEDs to blink periodically
		while(1);			
	}
#endif

	// RESET the entire ENC28J60, clearing all registers
	SendSystemReset();	
	delay(1000);

#if MAC_TX_BUFFER_COUNT > 1
    // On Init, all transmit buffers are free.
    for (i = 0; i < MAC_TX_BUFFER_COUNT; i++ )
    {
        TxBuffers[i].StartAddress = TXSTART + ((WORD)i * (MAC_TX_BUFFER_SIZE+8));
        TxBuffers[i].bFree = TRUE;
    }
#endif
    NICCurrentTxBuffer = 0;
	
	/*
	 * Start up in Bank 0 and configure the receive buffer boundary pointers 
	 * and the buffer write protect pointer (receive buffer read pointer)
	 */
	WasDiscarded = TRUE;
	NextPacketLocation.Val = RXSTART;
	WriteReg(ERXSTL, LOW(RXSTART));
	WriteReg(ERXSTH, HIGH(RXSTART));

	WriteReg(ERXRDPTL, LOW(RXSTOP));	// Write low byte first
	WriteReg(ERXRDPTH, HIGH(RXSTOP));	// Write high byte last

#if RXSTOP != 0x1FFF	// The RESET default ERXND is 0x1FFF
	WriteReg(ERXNDL, LOW(RXSTOP));
	WriteReg(ERXNDH, HIGH(RXSTOP));
#endif
#if TXSTART != 0		// The RESET default ETXST is 0
	WriteReg(ETXSTL, LOW(TXSTART));
	WriteReg(ETXSTH, HIGH(TXSTART));
#endif

	/*
	 * Enter Bank 1 and configure Receive Filters 
	 * (No need to reconfigure - Unicast OR Broadcast with CRC checking is 
	 * acceptable)
	 */
	 BankSel(ERXFCON);
	 WriteReg(ERXFCON, ERXFCON_CRCEN);

	/*
	 * Enter Bank 2 and configure the MAC
	 */
	BankSel(MACON1);

	/*--------added by lfei 2007/01/21--*/
	// 將MACON2中的MARST位清零,使MAC退出復位狀態
	
	WriteReg( MACON2, MACON2_MARST_CLR);
	
	/*-------------------------------*/

	// Enable the receive portion of the MAC
	WriteReg(MACON1, MACON1_TXPAUS | MACON1_RXPAUS | MACON1_MARXEN);
	
	// Pad packets to 60 bytes, add CRC, and check Type/Length field.
	// FULDPX位使用的是默認狀態0,即MAC工作在半雙工模式
	WriteReg(MACON3, MACON3_PADCFG0 | MACON3_TXCRCEN | MACON3_FRMLNEN);
	
	// Set non-back-to-back inter-packet gap to 9.6us.  The back-to-back 
	// inter-packet gap (MABBIPG) is set by MACSetDuplex() which is called 
	// later.
	WriteReg(MAIPGL, 0x12);
	WriteReg(MAIPGH, 0x0C);

	// Set the maximum packet size which the controller will accept
	WriteReg(MAMXFLL, LOW(MAXFRAMEC));	
	WriteReg(MAMXFLH, HIGH(MAXFRAMEC));
	
	/*
     * Enter Bank 3 and initialize physical MAC address registers
	 */
	BankSel(MAADR1);
	print1("Set MAC address:\n");
    WriteReg(MAADR1, MY_MAC_BYTE1);
    print2("MAADR1 :", 0, Read_MACRCR(MAADR1));
    WriteReg(MAADR2, MY_MAC_BYTE2);
    print2("MAADR2 :", 0, Read_MACRCR(MAADR2));
    WriteReg(MAADR3, MY_MAC_BYTE3);
    print2("MAADR3 :", 0, Read_MACRCR(MAADR3));
    WriteReg(MAADR4, MY_MAC_BYTE4);
    print2("MAADR4 :", 0, Read_MACRCR(MAADR4));
    WriteReg(MAADR5, MY_MAC_BYTE5);
    print2("MAADR5 :", 0, Read_MACRCR(MAADR5));
    WriteReg(MAADR6, MY_MAC_BYTE6);
    print2("MAADR6 :", 0, Read_MACRCR(MAADR6));

/***added by lfei 2007/02/05********************/
	// Get the Rev ID so that we can implement the correct errata workarounds
	ENCRevID = ReadETHReg((BYTE)EREVID).Val;
/*******************************************/

	// Disable half duplex loopback in PHY.  Bank bits changed to Bank 2 as a 
	// side effect.
	WritePHYReg(PHCON2, PHCON2_HDLDIS);

	// Configure LEDA to display LINK status, LEDB to display TX/RX activity
	SetLEDConfig(0x0472);
	
	// Set the MAC and PHY into the proper duplex state
#if defined(FULL_DUPLEX)
	MACSetDuplex(FULL);		// Function exits with Bank 2 selected
#elif defined(HALF_DUPLEX)
	MACSetDuplex(HALF);		// Function exits with Bank 2 selected
#else
	// Use the external LEDB polarity to determine weather full or half duplex 
	// communication mode should be set.  
	MACSetDuplex(USE_PHY);	// Function exits with Bank 2 selected
#endif

	// Enable packet reception
	BFSReg(ECON1, ECON1_RXEN);

}//end MACInit


/******************************************************************************
 * Function:        BOOL MACIsLinked(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          TRUE: If the PHY reports that a link partner is present 
 *						  and the link has been up continuously since the last 
 *						  call to MACIsLinked()
 *					FALSE: If the PHY reports no link partner, or the link went 
 *						   down momentarily since the last call to MACIsLinked()
 *
 * Side Effects:    None
 *
 * Overview:        Returns the PHSTAT1.LLSTAT bit.
 *
 * Note:            None
 *****************************************************************************/
BOOL MACIsLinked(void)
{
	// LLSTAT is a latching low link status bit.  Therefore, if the link 
	// goes down and comes back up before a higher level stack program calls
	// MACIsLinked(), MACIsLinked() will still return FALSE.  The next 
	// call to MACIsLinked() will return TRUE (unless the link goes down 
	// again).
	return ReadPHYReg(PHSTAT1).PHSTAT1bits.LLSTAT;
//	return 0;
}

/******************************************************************************
 * Function:        BOOL MACIsTxReady(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          TRUE: If no Ethernet transmission is in progress
 *					FALSE: If a previous transmission was started, and it has 
 *						   not completed yet.  While FALSE, the data in the 
 *						   transmit buffer and the TXST/TXND pointers must not
 *						   be changed.
 *
 * Side Effects:    None
 *
 * Overview:        Returns the ECON1.TXRTS bit.
 *
 * Note:            None
 *****************************************************************************/
BOOL MACIsTxReady(void)

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久亚洲精品国产精品紫薇| 亚洲精品国产无套在线观| 亚洲天堂免费看| 狂野欧美性猛交blacked| 成人激情开心网| 精品久久久三级丝袜| 亚洲小说欧美激情另类| 成人午夜免费视频| 91精品国产欧美一区二区| 亚洲天堂成人网| 国产乱色国产精品免费视频| 91精品国产综合久久香蕉的特点 | 亚洲成人av一区二区| 高清不卡在线观看av| 精品国产污网站| 视频在线在亚洲| 日本韩国视频一区二区| 国产精品人成在线观看免费| 国产精品主播直播| 精品国产乱码久久久久久久| 天天色综合天天| 91福利国产成人精品照片| 国产精品高清亚洲| 国产91在线看| 久久久蜜臀国产一区二区| 免费高清不卡av| 欧美一级在线免费| 日日摸夜夜添夜夜添精品视频 | 粉嫩久久99精品久久久久久夜| 欧美一区二区三区在| 亚洲一区二区三区视频在线播放| 色婷婷av一区二区三区大白胸| 国产精品久久夜| 成人午夜精品在线| 欧美激情中文字幕| aaa欧美色吧激情视频| 国产精品网站导航| 不卡视频一二三四| 又紧又大又爽精品一区二区| 欧美艳星brazzers| 香蕉av福利精品导航| 欧美少妇xxx| 日产欧产美韩系列久久99| 日韩三级视频中文字幕| 精东粉嫩av免费一区二区三区| www欧美成人18+| 风间由美一区二区av101| 中文字幕乱码久久午夜不卡| 波多野结衣在线aⅴ中文字幕不卡| 中文字幕av不卡| 色菇凉天天综合网| 天天av天天翘天天综合网| 欧美一级二级三级乱码| 国产毛片精品国产一区二区三区| 中文字幕乱码久久午夜不卡 | 欧美精品乱码久久久久久按摩| 日韩精品欧美成人高清一区二区| 欧美在线|欧美| 一区二区三区**美女毛片| 在线精品视频免费播放| 日本aⅴ精品一区二区三区 | 亚洲精品欧美二区三区中文字幕| 欧美日韩性生活| 国产精品自拍一区| 一区二区三区四区视频精品免费 | 亚洲美女在线国产| 884aa四虎影成人精品一区| 精品一区二区影视| 一区二区三区色| 精品久久国产字幕高潮| 99国产精品久久久久| 日韩精品视频网| 国产精品天美传媒沈樵| 欧美一区二区三区在线观看| 成人高清在线视频| 日本欧美加勒比视频| 欧美激情综合五月色丁香小说| 欧美天堂一区二区三区| 国产精品白丝jk黑袜喷水| 夜夜嗨av一区二区三区| 久久夜色精品国产噜噜av| 色天使色偷偷av一区二区| 国产一区二区三区在线看麻豆| 一区二区三区欧美| 欧美激情中文字幕一区二区| 91精品福利在线一区二区三区| 成人黄色片在线观看| 久久国产免费看| 亚洲第一福利视频在线| 中文字幕一区二区三区蜜月| 91麻豆精品国产自产在线观看一区 | 国产精品麻豆久久久| 日韩欧美国产1| 欧美午夜理伦三级在线观看| 成人美女视频在线看| 看电视剧不卡顿的网站| 一区二区三区免费看视频| 亚洲国产成人一区二区三区| 久久女同精品一区二区| 欧美一区二区免费观在线| 色综合久久66| 成人国产精品视频| 国产一区二区三区| 久久精品国产澳门| 美日韩黄色大片| 天涯成人国产亚洲精品一区av| 一区二区三区中文字幕电影 | 欧美a级理论片| 日韩精品每日更新| 日韩精品亚洲专区| 日本不卡视频在线| 欧美aaaaa成人免费观看视频| 香港成人在线视频| 一级日本不卡的影视| 一区二区三区免费在线观看| 亚洲精品欧美激情| 亚洲一区二区三区四区的| 天天综合天天做天天综合| 亚洲午夜私人影院| 天天做天天摸天天爽国产一区| 日韩精品免费专区| 蜜桃视频一区二区| 国产伦精品一区二区三区免费迷| 久久成人羞羞网站| 国产乱码精品一区二区三区av| 国产高清在线观看免费不卡| 国产精品一区三区| 岛国精品一区二区| 91麻豆国产香蕉久久精品| 色菇凉天天综合网| 337p亚洲精品色噜噜噜| 日韩欧美国产一区二区在线播放| 日韩精品一区二| 国产农村妇女毛片精品久久麻豆| 国产精品久久久久国产精品日日 | 亚洲精品一区二区精华| 久久久美女毛片| 中文字幕一区二区三区四区| 一区二区三区高清| 日本不卡中文字幕| 国产精品一区二区久久精品爱涩| 成人动漫一区二区在线| 欧美三级电影在线看| 日韩精品一区二区三区在线播放| 亚洲国产精品av| 亚洲一区在线观看视频| 美日韩黄色大片| av在线不卡免费看| 8x福利精品第一导航| 久久精品一区蜜桃臀影院| 亚洲女同一区二区| 精品亚洲成a人在线观看| www.亚洲色图.com| 在线综合视频播放| 中文字幕在线不卡| 日韩精品免费专区| 波多野结衣中文一区| 制服丝袜中文字幕一区| 欧美国产精品专区| 五月天中文字幕一区二区| 成人免费看视频| 欧美一区二区三区在| 日韩美女啊v在线免费观看| 久久精品国产一区二区三区免费看| 不卡一区二区中文字幕| 日韩三级视频中文字幕| 亚洲免费大片在线观看| 久久97超碰色| 欧美图片一区二区三区| 国产精品久久久久久福利一牛影视| 日韩激情视频在线观看| 一本到一区二区三区| 中国av一区二区三区| 人人精品人人爱| 欧美日韩精品一区视频| 国产精品久久久久久户外露出 | 三级不卡在线观看| 99久久99久久精品免费观看 | 欧美丰满少妇xxxbbb| 亚洲美女屁股眼交3| 国产成人av影院| 26uuu欧美日本| 免费精品视频在线| 欧美狂野另类xxxxoooo| 亚洲人成网站精品片在线观看| 成人亚洲一区二区一| 欧美大片一区二区三区| 日韩精品国产精品| 欧美日韩一区久久| 亚洲第一二三四区| 色噜噜狠狠一区二区三区果冻| 中文字幕一区二区三区av| 国产成人综合亚洲91猫咪| 亚洲精品一区二区三区精华液| 免费的成人av| 日韩欧美美女一区二区三区| 日本特黄久久久高潮| 制服丝袜中文字幕一区| 国产高清无密码一区二区三区| 日韩欧美在线影院|