⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ethernet.c

📁 用于以太网开发
💻 C
字号:
/*
 *Copyright (c) 2000-2002 Viola Systems Ltd.
 *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 end-user documentation included with the redistribution, if 
 *any, must include the following acknowledgment:
 *	"This product includes software developed by Viola 
 *	Systems (http://www.violasystems.com/)."
 *
 *Alternately, this acknowledgment may appear in the software itself, 
 *if and wherever such third-party acknowledgments normally appear.
 *
 *4. The names "OpenTCP" and "Viola Systems" must not be used to 
 *endorse or promote products derived from this software without prior 
 *written permission. For written permission, please contact 
 *opentcp@opentcp.org.
 *
 *5. Products derived from this software may not be called "OpenTCP", 
 *nor may "OpenTCP" appear in their name, without prior written 
 *permission of the Viola Systems Ltd.
 *
 *THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED 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 VIOLA SYSTEMS LTD. OR ITS CONTRIBUTORS 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.
 *====================================================================
 *
 *OpenTCP is the unified open source TCP/IP stack available on a series 
 *of 8/16-bit microcontrollers, please see <http://www.opentcp.org>.
 *
 *For more information on how to network-enable your devices, or how to 
 *obtain commercial technical support for OpenTCP, please see 
 *<http://www.violasystems.com/>.
 */

/** \file ethernet.c
 *	\brief OpenTCP Ethernet protocol and driver for Realtek's RTL8019AS
 *	\author 
 *		\li Jari Lahti (jari.lahti@violasystems.com)
 *		\li Vladan Jovanovic (vladan.jovanovic@violasystems.com)
 *	\version 1.0
 *	\date 19.2.2002
 *	\bug
 *	\warning
 *	\todo
 *		\li How to adopt to different MCU speeds in the code?
 *  
 *	OpenTCP implementation of Ethernet protocol and driver for
 *	Realtek's RTL8019AS Ethernet controller. Function declarations,data
 *	structures etc. may be found in inet/ethernet.h.
 */
 
#include <inet/debug.h>
#include <inet/datatypes.h>
#include <inet/system.h>
#include <inet/ethernet.h>


#include <inet/arch/config.h>

/*  >>>>>>>>>>>>>>>>>>> RENE
//UINT8	NE2000NextPktPtr;			/**< Start address of next packet in the Ethernet controller */
//UINT8 	NE2000CurrPktPtr;			/**< Start address of current packet in the Ethernet controller */
// <<<<<<<<<<<<<<<<<<<<<<

UINT8 	EtherSleep = 0;	/**< Used for storing state of Ethernet controller (0 = awake; 1 = sleeping) */

/** \brief Used for storing various information about the received Ethernet frame
 *	
 *	Fields from Ethernet packet (dest/source hardware address, 
 *	protocol, frame size, start of the Ethernet packet in Ethernet controller)
 *	are stored in this structure. These values are later used from upper
 *	layer protocols (IP, ARP). See ethernet_frame definition for more
 *	information about struct fields.
 *
 */	
struct ethernet_frame received_frame;

/** \brief Used for storing various information about the Ethernet frame that will be sent
 *	
 *	Fields from Ethernet packet (dest/source hardware address, 
 *	protocol, frame size) are stored in this structure by the
 *	upper layer protocols (IP, ARP, other). These values are 
 *	then used for initializing transmission of an Ethernet frame.
 *	See ethernet_frame definition for more
 *	information about struct fields.
 *
 */
struct ethernet_frame send_frame;



/** \brief Write data to the same NE2000 register as before
 * 	\author 
 *		\li Jari Lahti (jari.lahti@violasystems.com)
 *	\date 19.02.2002
 *	\param dat new register content
 *
 *	Invoke this function to write data to the same register as 
 *	in previously invoked outNE2000(). Saves some cycles because
 *	data direction registers and address are set up.
 *
 *	Use SEND_NETWORK_B() macro instead of invoking this function
 *	directly.
 */
void Ethernet_OutAgain (UINT8 dat)
{
}


/** \brief Write buffer data to the same NE2000 register as before
 * 	\author 
 *		\li Jari Lahti (jari.lahti@violasystems.com)
 *	\date 20.07.2003
 *	\param buf pointer to buffer from which we're taking data
 *	\param len number of bytes from buffer to write
 *
 *	Invoke this function to write data from a buffer to the same 
 *	register as in previously invoked outNE2000(). Saves some 
 *	cycles because data direction registers and address are set up.
 *
 *	Use SEND_NETWORK_BUF() macro instead of invoking this function
 *	directly.
 */
void Ethernet_OutAgainBuf (UINT8* buf, UINT16 len)
{

}



/** \brief Continue reading byte(s) from NE2000
 * 	\author 
 *		\li Jari Lahti (jari.lahti@violasystems.com)
 *	\date 19.02.2002
 *	\return Register content
 *
 *	Invoke this function to continue reading contents of a NE2000 register,
 *	usefull when reading a sequence of bytes from Ethernet controller.
 *
 *	Use RECEIVE_NETWORK_B() macro instead of directly invoking this
 *	function for easier driver change.
 */


/** \brief Read bytes from NE2000 to buffer
 * 	\author 
 *		\li Jari Lahti (jari.lahti@violasystems.com)
 *	\date 20.07.2003
 *
 *	Invoke this function to continue reading contents of a NE2000 register,
 *	only this time to a buffer directly.
 *
 *	Use RECEIVE_NETWORK_BUF() macro instead of directly invoking this
 *	function for easier driver change.
 */
void Ethernet_InAgainBuf (UINT8* buf, UINT16 len)
{
}


/** \brief Check to see if new frame has been received
 * 	\author 
 *		\li Jari Lahti (jari.lahti@violasystems.com)
 *	\date 19.02.2002
 *	\return
 *		\li #TRUE - if there is a new packet waiting
 *		\li #FALSE - if there is no new packet waiting
 *
 *	Invoke this function to check if there is a new Ethernet frame
 *	in the NIC's buffer waiting to be processed.
 */
UINT8 NE2000CheckRxFrame (void)
{
 
}

/** \brief Discard current received frame
 * 	\author 
 *		\li Jari Lahti (jari.lahti@violasystems.com)
 *	\date 19.02.2002
 *
 *	Discard the current received frame by advancing the receive circular
 *	buffer tail pointer.
 */
void NE2000DumpRxFrame (void)
{
 
 
}
 
 
/** \brief Initialize and configure RTL8019AS
 *	\ingroup core_initializer
 * 	\author 
 *		\li Jari Lahti (jari.lahti@violasystems.com)
 *	\date 19.02.2002
 *	\param mac Pointer to NIC's hardware address
 *
 *	Invoke this function at startup to properly initialize NIC's registers,
 *	HW address and operation.
 */ 
void NE2000Init (UINT8* mac)
{
}


/** \brief Check if receive-buffer overflow occured
 *	\ingroup periodic_functions
 * 	\author 
 *		\li Jari Lahti (jari.lahti@violasystems.com)
 *	\date 19.02.2002
 *
 *	This function checks if receive-buffer overflow has happened. If it did,
 *	NIC is reinitialized to ensure proper operation.
 *
 *	Invoke this function periodically to ensure proper operation under
 *	heavy load.
 */
void NE2000CheckOverFlow (void)
{
}

/** \brief Checks if new Ethernet frame exists and initializes variables
 *		accordingly
 * 	\author 
 *		\li Jari Lahti (jari.lahti@violasytems.com)
 *	\date 19.02.2002
 *	\return
 *		\li #TRUE - new frame exists, variables initialized so further
 *			processing may start
 *		\li #FALSE - no new Ethernet frame detected
 *
 *	Invoke this function periodically (better not directly but by invoking
 *	NETWORK_CHECK_IF_RECEIVED() macro) to test for newly-arrived Ethernet
 *	packets.
 *
 *	Once this function detects a new Etherent packet, internal variables 
 *	are initialized (NE2000CurrPktPtr, NE2000NextPktPtr and received_frame
 *	structure) and TRUE is returned, indicating that processing of
 *	newly-arrived frame may begin.
 */
UINT8 NE2000ReceiveFrame (void)
{
	
}

/** \brief Initialize transmission of new packet
 * 	\author 
 *		\li Jari Lahti (jari.lahti@violasystems.com)
 *	\date 19.02.2002
 *	\param page Address in Ethernet controller where outgoing packet
 *		buffered
 *
 *	This function is used to initialize transmission of an Ethernet 
 *	packet. Packet is created starting from <i>page</i> address.
 *
 *	Do not invoke this function directly, but instead use 
 *	NETWORK_SEND_INITIALIZE() macro.
 */
void InitTransmission (UINT8 page)
{

}

/** \brief Write Ethernet Header to transmission buffer
 * 	\author 
 *		\li Jari Lahti (jari.lahti@violasystems.com)
 *	\date 19.02.2002
 *	\param frame Pointer to ethernet_frame structure containing information
 *		about the new Ethernet frame
 *
 *	Invoke this function (through NETWORK_ADD_DATALINK() macro) to create
 *	an Ethernet header in the NIC's transmit buffer. Do this only after
 *	invoking NETWORK_SEND_INITIALIZE() macro.
 *
 */
void NE2000WriteEthernetHeader (struct ethernet_frame* frame)
{

}

/** \brief Initialize NE2000 in preparation for remote DMA
 * 	\author 
 *		\li Jari Lahti (jari.lahti@violasystems.com)
 *	\date 19.02.2002
 *	\param page Address for the DMA
 *
 *	
 */
void NE2000DMAInit (UINT8 page)
{
 	
}

/** \brief Initialize reading from NE2000
 * 	\author 
 *		\li Jari Lahti (jari.lahti@violasystems.com)
 *	\date 19.02.2002
 *	\param pos Position from the start of current frame from which DMA
 *		is initialized.
 *
 *	Invoke this function (through NETWORK_RECEIVE_INITIALIZE() macro) 
 *	to prepair NIC for reading from the specified position.
 */
void Ethernet_InitPosition (UINT16 pos)
{
}



/** \brief Instruct NIC to send the Ethernet frame
 * 	\author 
 *		\li Jari Lahti (jari.lahti@violasystems.com)
 *	\date 19.02.2002
 *	\param len Length of packet stored in the NIC's buffer
 *	\warning
 *		\li Minimum Ethernet packet size is 64 bytes
 *
 *	Invoke this function (through NETWORK_COMPLETE_SEND() macro) when
 *	the whole packet is formed inside NIC's memory and is ready to be 
 *	sent. Proper length of the packet must be supplied so that NIC
 *	knows how much data to put on the line.
 */
void NE2000SendFrame ( UINT16 len )
{
 	
}

/** \brief Put NE2000 to sleep mode
 * 	\author 
 *		\li Jari Lahti (jari.lahti@violasystems.com)
 *	\date 19.02.2002
 *
 *	Invoke this function to put Ethernet controller to sleep mode.
 *
 */
void NE2000EnterSleep (void) 
{
}

/** \brief Restore NE2000 from sleep mode
 * 	\author 
 *		\li Jari Lahti (jari.lahti@violasystems.com)
 *	\date 19.02.2002
 *
 *	Invoke this function to instruct NE2000 to exit sleep mode and 
 *	continue normal operation.
 */
void NE2000ExitSleep (void) 
{
		
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -