Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages   Examples  

/opentcp/ethernet.c File Reference


Detailed Description

Author:
Version:
1.0
Date:
19.2.2002
Bug:
Warning:
Todo:
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.

Definition in file ethernet.c.

Go to the source code of this file.

Functions

void outNE2000 (UINT8 reg, UINT8 dat)
 Write data to NE2000 register.

void outNE2000again (UINT8 dat)
 Write data to the same NE2000 register as before.

UINT8 inNE2000 (UINT8 reg)
 Read byte from NE2000 register.

UINT8 inNE2000again (void)
 Continue reading byte(s) from NE2000.

UINT8 NE2000CheckRxFrame (void)
 Check to see if new frame has been received.

void NE2000DumpRxFrame (void)
 Discard current received frame.

void NE2000Init (UINT8 *mac)
 Initialize and configure RTL8019AS.

void NE2000CheckOverFlow (void)
 Check if receive-buffer overflow occured.

UINT8 NE2000ReceiveFrame (void)
 Checks if new Ethernet frame exists and initializes variables accordingly.

void InitTransmission (UINT8 page)
 Initialize transmission of new packet.

void NE2000WriteEthernetHeader (struct ethernet_frame *frame)
 Write Ethernet Header to transmission buffer.

void NE2000DMAInit (UINT8 page)
 Initialize NE2000 in preparation for remote DMA.

void NE2000DMAInit_position (UINT16 pos)
 Initialize reading from NE2000.

void NE2000SendFrame (UINT16 len)
 Instruct NIC to send the Ethernet frame.

void NE2000EnterSleep (void)
 Put NE2000 to sleep mode.

void NE2000ExitSleep (void)
 Restore NE2000 from sleep mode.


Variables

UINT8 NE2000NextPktPtr
UINT8 NE2000CurrPktPtr
UINT8 EtherSleep = 0
ethernet_frame received_frame
 Used for storing various information about the received Ethernet frame.

ethernet_frame send_frame
 Used for storing various information about the Ethernet frame that will be sent.


Function Documentation

void outNE2000 UINT8    reg,
UINT8    dat
 

Author:
Date:
19.02.2002
Parameters:
reg  NE2000 register address
dat  new register content
Write data to NE2000 register.

Definition at line 119 of file ethernet.c.

References ADRBUS, DATABUS, DATADIR, DDR_OUT, IOCHRDY, and IOW.

Referenced by InitTransmission(), NE2000CheckOverFlow(), NE2000CheckRxFrame(), NE2000DMAInit(), NE2000DMAInit_position(), NE2000DumpRxFrame(), NE2000EnterSleep(), NE2000ExitSleep(), NE2000Init(), NE2000ReceiveFrame(), and NE2000SendFrame().

void outNE2000again UINT8    dat
 

Author:
Date:
19.02.2002
Parameters:
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 not set up.

Use SEND_NETWORK_B() macro instead of invoking this function directly.

Definition at line 150 of file ethernet.c.

References DATABUS, IOCHRDY, and IOW.

Referenced by NE2000SendFrame(), and NE2000WriteEthernetHeader().

UINT8 inNE2000 UINT8    reg
 

Author:
Date:
19.02.2002
Parameters:
reg  NE2000 register address
Returns:
Register content
Invoke this function to read contents of a NE2000 register.

Definition at line 175 of file ethernet.c.

References ADRBUS, DATABUS, DATADIR, DDR_IN, IOCHRDY, and IOR.

Referenced by InitTransmission(), NE2000CheckOverFlow(), NE2000CheckRxFrame(), and NE2000ReceiveFrame().

UINT8 inNE2000again void   
 

Author:
Date:
19.02.2002
Returns:
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.

Definition at line 204 of file ethernet.c.

References DATABUS, IOCHRDY, and IOR.

Referenced by NE2000ReceiveFrame().

UINT8 NE2000CheckRxFrame void   
 

Author:
Date:
19.02.2002
Returns:
  • TRUE - if there is a new packet waiting
  • 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.

Definition at line 231 of file ethernet.c.

References BOUNDARY, CR, CURR, inNE2000(), and outNE2000().

Referenced by NE2000ReceiveFrame().

void NE2000DumpRxFrame void   
 

Author:
Date:
19.02.2002
Discard the current received frame by advancing the receive circular buffer tail pointer.

Definition at line 259 of file ethernet.c.

References BOUNDARY, CR, NE2000NextPktPtr, and outNE2000().

Referenced by NE2000CheckOverFlow().

UINT8 NE2000ReceiveFrame void   
 

Author:
Date:
19.02.2002
Returns:
  • TRUE - new frame exists, variables initialized so further processing may start
  • 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.

Definition at line 412 of file ethernet.c.

References BOUNDARY, ethernet_frame::buf_index, CR, ethernet_frame::destination, FALSE, ethernet_frame::frame_size, inNE2000(), inNE2000again(), IOPORT, NE2000CheckRxFrame(), NE2000CurrPktPtr, NE2000NextPktPtr, outNE2000(), ethernet_frame::protocol, RBCR0, RSAR0, and ethernet_frame::source.

void InitTransmission UINT8    page
 

Author:
Date:
19.02.2002
Parameters:
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 page address.

Do not invoke this function directly, but instead use NETWORK_SEND_INITIALIZE() macro.

Definition at line 500 of file ethernet.c.

References ADRBUS, CR, DATADIR, inNE2000(), IOPORT, outNE2000(), RBCR0, RSAR0, and TPSR.

void NE2000WriteEthernetHeader struct ethernet_frame   frame
 

Author:
Date:
19.02.2002
Parameters:
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.

Definition at line 538 of file ethernet.c.

References ethernet_frame::destination, outNE2000again(), ethernet_frame::protocol, and ethernet_frame::source.

void NE2000DMAInit UINT8    page
 

Author:
Date:
19.02.2002
Parameters:
page  Address for the DMA

Definition at line 569 of file ethernet.c.

References CR, outNE2000(), RBCR0, and RSAR0.

void NE2000DMAInit_position UINT16    pos
 

Author:
Date:
19.02.2002
Parameters:
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.

Definition at line 595 of file ethernet.c.

References ADRBUS, CR, DATADIR, IOPORT, NE2000CurrPktPtr, outNE2000(), RBCR0, RSAR0, RXBUF_END, and RXBUF_START.

void NE2000SendFrame UINT16    len
 

Author:
Date:
19.02.2002
Parameters:
len  Length of packet stored in the NIC's buffer
Warning:
  • 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.

Definition at line 655 of file ethernet.c.

References CR, outNE2000(), outNE2000again(), TBCR0, and TBCR1.

void NE2000EnterSleep void   
 

Author:
Date:
19.02.2002
Invoke this function to put Ethernet controller to sleep mode.

Definition at line 690 of file ethernet.c.

References CR, EtherSleep, and outNE2000().

void NE2000ExitSleep void   
 

Author:
Date:
19.02.2002
Invoke this function to instruct NE2000 to exit sleep mode and continue normal operation.

Definition at line 709 of file ethernet.c.

References CR, EtherSleep, and outNE2000().


Variable Documentation

UINT8 NE2000NextPktPtr
 

Start address of next packet in the Ethernet controller

Definition at line 80 of file ethernet.c.

Referenced by NE2000DumpRxFrame(), and NE2000ReceiveFrame().

UINT8 NE2000CurrPktPtr
 

Start address of current packet in the Ethernet controller

Definition at line 81 of file ethernet.c.

Referenced by NE2000DMAInit_position(), and NE2000ReceiveFrame().

UINT8 EtherSleep = 0
 

Used for storing state of Ethernet controller (0 = awake; 1 = sleeping)

Definition at line 83 of file ethernet.c.

Referenced by NE2000EnterSleep(), and NE2000ExitSleep().

struct ethernet_frame received_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.

Definition at line 94 of file ethernet.c.

struct ethernet_frame send_frame
 

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.

Definition at line 106 of file ethernet.c.


Generated on Sat Jan 25 17:13:15 2003 for OpenTCP by doxygen1.2.18