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

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

?? enc28j60.c

?? 用于Microchip 16位單片機的通信應用程序庫 1042
?? 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, PIC24F, PIC24H, dsPIC30F, dsPIC33F
 * Complier:        Microchip C18 v3.02 or higher
 *					Microchip C30 v2.01 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		6/16/06 Synchronized with PIC18F97J60 code
 * Howard Schlunder		7/17/06 Updated TestMemory() for C30
********************************************************************/
#define THIS_IS_MAC_LAYER

#include <string.h>
#include "..\Include\StackTsk.h"
#include "..\Include\Helpers.h"
#include "..\Include\Delay.h"
#include "..\Include\MAC.h"
#include "..\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 ****************************************************/
// IMPORTANT SPI NOTE: The code in this file expects that the SPI interrupt 
//		flag (ENC_SPI_IF) be clear at all times.  If the SPI is shared with 
//		other hardware, the other code should clear the ENC_SPI_IF 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)

// 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 (0b010<<5)			// Write Control Register command
#define BFS (0b100<<5)			// Bit Field Set command
#define	BFC (0b101<<5)			// Bit Field Clear command
#define	RCR (0b000<<5)			// Read Control Register command
#define RBM ((0b001<<5) | 0x1A)	// Read Buffer Memory command
#define	WBM ((0b011<<5) | 0x1A) // Write Buffer Memory command
#define	SR  ((0b111<<5) | 0x1F)	// System Reset command does not use an address.  
								//   It requires 0x1F, however.

#define ETHER_IP	(0x00u)
#define ETHER_ARP	(0x06u)

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

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

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

    MAC_ADDR        DestMACAddr;
    MAC_ADDR        SourceMACAddr;
    WORD_VAL        Type;
} ENC_PREAMBLE;

typedef struct _DATA_BUFFER
{
	WORD_VAL StartAddress;
	WORD_VAL EndAddress;
	struct 
	{
		unsigned char bFree : 1;
		unsigned char bTransmitted : 1;
	} Flags;
} DATA_BUFFER;


// Prototypes of functions intended for MAC layer use only.
static void BankSel(WORD Register);
static REG ReadETHReg(BYTE Address);
static REG ReadMACReg(BYTE Address);
static void WriteReg(BYTE Address, BYTE Data);
static void BFCReg(BYTE Address, BYTE Data);
static void BFSReg(BYTE Address, BYTE Data);
static void SendSystemReset(void);
//static void GetRegs(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
BUFFER CurrentTxBuffer;
BUFFER LastTXedBuffer;

// Internal MAC level variables and flags.
WORD_VAL NextPacketLocation;
WORD_VAL CurrentPacketLocation;
BOOL WasDiscarded;
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;
	
	// Set up the SPI module on the PIC for communications with the ENC28J60
	ENC_CS_IO = 1;
	ENC_CS_TRIS = 0;		// Make the Chip Select pin an output
    ENC_SCK_TRIS = 0;
    ENC_SDO_TRIS = 0;
    ENC_SDI_TRIS = 1;

    // Set up SPI
#if defined(__18CXX)
	ENC_SPICON1 = 0x20;			// SSPEN bit is set, SPI in master mode, FOSC/4, 
							//   IDLE state is low level
	ENC_SPI_IF = 0;
	ENC_SPISTATbits.CKE = 1; 	// Transmit data on rising edge of clock
	ENC_SPISTATbits.SMP = 0;	// Input sampled at middle of data output time
#else
    ENC_SPISTAT = 0;    	// clear SPI
#if defined(__PIC24H__) || defined(__dsPIC33F__)
    ENC_SPICON1 = 0x0F; 	// 1:1 primary prescale, 5:1 secondary prescale	(8MHz  @ 40MIPS)
//    ENC_SPICON1 = 0x1E; 	// 4:1 primary prescale, 1:1 secondary prescale	(10MHz @ 40MIPS, Doesn't work.  CLKRDY is incorrectly reported as being clear.  Problem caused by dsPIC33/PIC24H ES silicon bug.)
#elif defined(__PIC24F__)
//    ENC_SPICON1 = 0x1F; 	// 1:1 prescale	broken on PIC24F ES silicon 	(16MHz @ 16MIPS)
    ENC_SPICON1 = 0x1B; 	// 1:1 primary prescale, 2:1 secondary prescale	(8MHz  @ 16MIPS)
#else	// dsPIC30F
    ENC_SPICON1 = 0x17; 	// 1:1 primary prescale, 3:1 secondary prescale	(10MHz @ 30MIPS)
#endif
    ENC_SPICON2 = 0;
    ENC_SPICON1bits.CKE = 1;
    ENC_SPICON1bits.MSTEN = 1;
    ENC_SPISTATbits.SPIEN = 1;
#endif

	// 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 there is something wrong with the SPI 
	// connection.  This loop makes sure that we can communicate with the 
	// ENC28J60 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();	
    DelayMs(1);

#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.Val = TXSTART + ((WORD)i * (MAC_TX_BUFFER_SIZE+8));
        TxBuffers[i].Flags.bFree = TRUE;
    }
#endif
    CurrentTxBuffer = 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);

	// Enable the receive portion of the MAC
	WriteReg((BYTE)MACON1, MACON1_TXPAUS | MACON1_RXPAUS | MACON1_MARXEN);
	
	// Pad packets to 60 bytes, add CRC, and check Type/Length field.
	WriteReg((BYTE)MACON3, MACON3_PADCFG0 | MACON3_TXCRCEN | MACON3_FRMLNEN);

    // Allow infinite deferals if the medium is continuously busy 
    // (do not time out a transmission if the half duplex medium is 
    // completely saturated with other people's data)
    WriteReg((BYTE)MACON4, MACON4_DEFER);

	// Late collisions occur beyond 63+8 bytes (8 bytes for preamble/start of frame delimiter)
	// 55 is all that is needed for IEEE 802.3, but ENC28J60 B5 errata for improper link pulse 
	// collisions will occur less often with a larger number.
    WriteReg((BYTE)MACLCON2, 63);
	
	// 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((BYTE)MAIPGL, 0x12);
	WriteReg((BYTE)MAIPGH, 0x0C);

	// Set the maximum packet size which the controller will accept
	WriteReg((BYTE)MAMXFLL, LOW(MAXFRAMEC));	
	WriteReg((BYTE)MAMXFLH, HIGH(MAXFRAMEC));
	
    // Enter Bank 3 and initialize physical MAC address registers
	BankSel(MAADR1);
    WriteReg((BYTE)MAADR1, AppConfig.MyMACAddr.v[0]);
    WriteReg((BYTE)MAADR2, AppConfig.MyMACAddr.v[1]);
    WriteReg((BYTE)MAADR3, AppConfig.MyMACAddr.v[2]);
    WriteReg((BYTE)MAADR4, AppConfig.MyMACAddr.v[3]);
    WriteReg((BYTE)MAADR5, AppConfig.MyMACAddr.v[4]);
    WriteReg((BYTE)MAADR6, AppConfig.MyMACAddr.v[5]);

	// 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;
}


/******************************************************************************
 * Function:        BOOL MACIsTxReady(BOOL HighPriority)
 *
 * PreCondition:    None
 *
 * Input:           HighPriority: TRUE: Check the hardware ECON1.TXRTS bit
 *								  FALSE: Check if a TX buffer is free
 *
 * 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(BOOL HighPriority)
{
#if MAC_TX_BUFFER_COUNT > 1
	BUFFER i;

	if(HighPriority)
#endif
	{
	    return !ReadETHReg(ECON1).ECON1bits.TXRTS;
	}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲精品一线二线三线无人区| 老鸭窝一区二区久久精品| 国产真实精品久久二三区| 国产成人综合亚洲网站| 精品1区2区在线观看| 日韩在线一二三区| 欧美日韩成人一区| 午夜精品一区二区三区三上悠亚| 色综合天天综合网天天看片| 国产精品成人一区二区三区夜夜夜 | 欧美一区二区视频在线观看| 亚洲国产日韩综合久久精品| 色偷偷88欧美精品久久久| 18涩涩午夜精品.www| 国产综合一区二区| 国产精品麻豆欧美日韩ww| 粉嫩av一区二区三区在线播放| 久久精品视频一区| 国产成人av电影在线播放| 国产午夜精品福利| 成人app软件下载大全免费| 国产精品视频九色porn| 91蜜桃在线免费视频| 一卡二卡欧美日韩| 色噜噜偷拍精品综合在线| 一区二区高清免费观看影视大全 | 日精品一区二区三区| 91精品国产综合久久福利软件 | 中文字幕国产一区二区| 国产精品香蕉一区二区三区| 国产欧美一区二区精品久导航 | 亚洲午夜精品网| 日韩视频中午一区| 国产成人a级片| 亚洲欧美国产77777| 欧美日韩国产成人在线91| 亚洲已满18点击进入久久| 欧美精品三级日韩久久| 国产在线视频一区二区三区| 国产精品理伦片| 精品视频1区2区| 极品美女销魂一区二区三区免费| 中文字幕av不卡| 欧美日韩dvd在线观看| 久久91精品久久久久久秒播| 欧美国产精品一区二区| 欧美性感一区二区三区| 国产自产v一区二区三区c| 自拍偷在线精品自拍偷无码专区| 欧美日韩五月天| 国产精品一区二区三区网站| 一区二区三区四区激情| 欧美午夜电影网| 国产精品1区2区3区在线观看| 亚洲综合激情网| 久久这里只有精品6| 一本久道中文字幕精品亚洲嫩| 蜜臀av性久久久久av蜜臀妖精| 亚洲国产精品99久久久久久久久| 欧美日韩在线观看一区二区 | 欧美一区二区三区男人的天堂| 国产在线视频精品一区| 亚洲第一福利一区| 国产精品久久综合| 精品久久久三级丝袜| 欧美三级韩国三级日本三斤| 成熟亚洲日本毛茸茸凸凹| 免费精品视频在线| 一区二区三区美女| 国产精品久久夜| 久久五月婷婷丁香社区| 在线观看亚洲精品| 成人av片在线观看| 国内精品免费**视频| 日韩在线一区二区三区| 亚洲欧美国产高清| 国产精品久久久久久久久快鸭| 日韩欧美亚洲国产精品字幕久久久| 一本大道久久a久久综合婷婷| 国产精品资源网站| 午夜精品福利一区二区蜜股av| 日韩西西人体444www| 欧美绝品在线观看成人午夜影视| 99国产精品视频免费观看| 国产精品一区专区| 久久成人免费日本黄色| 蜜桃久久久久久| 看电视剧不卡顿的网站| 美女一区二区三区在线观看| 石原莉奈在线亚洲二区| 日韩va亚洲va欧美va久久| 亚洲二区视频在线| 亚洲成人三级小说| 午夜在线电影亚洲一区| 亚洲香肠在线观看| 亚洲国产精品一区二区久久| 综合av第一页| 国产无遮挡一区二区三区毛片日本| 亚洲精品一区二区三区香蕉| 精品国产污网站| 欧美xfplay| 久久精品亚洲乱码伦伦中文| 国产视频一区二区在线观看| 久久免费看少妇高潮| 久久免费午夜影院| 国产精品免费aⅴ片在线观看| 日韩一区二区视频| 在线播放欧美女士性生活| 日韩一区二区电影在线| 欧美精品一区二| 欧美激情综合五月色丁香| 亚洲欧洲三级电影| 亚洲日本va在线观看| 亚洲午夜三级在线| 麻豆一区二区99久久久久| 国产精品一区二区91| jiyouzz国产精品久久| 成人激情av网| 成人一级片在线观看| 国产电影一区二区三区| av电影天堂一区二区在线| 欧美最猛黑人xxxxx猛交| 91精品国产麻豆| 国产区在线观看成人精品| 成人免费一区二区三区视频| 亚洲国产综合91精品麻豆| 久久精品国产99| 成人一区二区视频| 97久久人人超碰| 欧美久久久久久久久中文字幕| 欧美成人乱码一区二区三区| 国产精品久久久久久一区二区三区| 亚洲免费在线观看视频| 男男视频亚洲欧美| 国产ts人妖一区二区| 欧美综合久久久| 欧美成人欧美edvon| 久久精品免费在线观看| 亚洲影视在线观看| 国产91精品一区二区| 欧美精品免费视频| 国产精品久久久久一区二区三区 | 在线观看免费成人| 久久一二三国产| 午夜不卡在线视频| 一本色道久久综合狠狠躁的推荐| 精品电影一区二区| 亚洲午夜在线视频| 99麻豆久久久国产精品免费| 欧美一区二区啪啪| 亚洲精品日产精品乱码不卡| 久久精品国产亚洲a| 91丨porny丨最新| 国产人妖乱国产精品人妖| 日韩极品在线观看| 在线观看免费视频综合| 国产精品理论在线观看| 久久精品理论片| 在线综合亚洲欧美在线视频| 亚洲美女视频在线| 成人黄色777网| 欧美激情一区二区三区| 丁香天五香天堂综合| 中文字幕欧美区| 不卡高清视频专区| 国产精品成人免费| 91色porny在线视频| 成人欧美一区二区三区白人| 成年人国产精品| 国产精品成人免费| 在线亚洲一区二区| 亚洲一区二区三区在线看| 欧美视频一区在线| 日韩和欧美一区二区三区| 日韩一区二区电影在线| 精品在线你懂的| 国产精品久久久久天堂| 一本色道久久综合亚洲91| 亚洲午夜免费福利视频| 欧美一区二区黄| 精品一区二区三区视频| 国产欧美日韩综合精品一区二区| 粉嫩aⅴ一区二区三区四区| 最新久久zyz资源站| 91成人免费电影| 日韩二区三区四区| 日韩一卡二卡三卡四卡| 国产一区二区三区在线观看免费| 国产女人aaa级久久久级| 日本精品一区二区三区高清 | 欧美精品一卡二卡| 麻豆一区二区99久久久久| 国产三级精品视频| 色综合一个色综合亚洲| 奇米在线7777在线精品| 国产精品热久久久久夜色精品三区 | 国产一区中文字幕| 自拍偷拍欧美激情| 欧美高清hd18日本| 国产高清在线观看免费不卡|