Software Drivers

xemaclite.c File Reference

#include "xil_io.h"
#include "xenv.h"
#include "xemaclite.h"
#include "xemaclite_i.h"

Functions

int XEmacLite_CfgInitialize (XEmacLite *InstancePtr, XEmacLite_Config *EmacLiteConfigPtr, u32 EffectiveAddr)
int XEmacLite_Send (XEmacLite *InstancePtr, u8 *FramePtr, unsigned ByteCount)
u16 XEmacLite_Recv (XEmacLite *InstancePtr, u8 *FramePtr)
void XEmacLite_SetMacAddress (XEmacLite *InstancePtr, u8 *AddressPtr)
void StubHandler (void *CallBackRef)
int XEmacLite_TxBufferAvailable (XEmacLite *InstancePtr)
void XEmacLite_FlushReceive (XEmacLite *InstancePtr)
int XEmacLite_PhyRead (XEmacLite *InstancePtr, u32 PhyAddress, u32 RegNum, u16 *PhyDataPtr)
int XEmacLite_PhyWrite (XEmacLite *InstancePtr, u32 PhyAddress, u32 RegNum, u16 PhyData)
void XEmacLite_EnableLoopBack (XEmacLite *InstancePtr)
void XEmacLite_DisableLoopBack (XEmacLite *InstancePtr)

Detailed Description

Functions in this file are the minimum required functions for the EmacLite driver. See xemaclite.h for a detailed description of the driver.

 MODIFICATION HISTORY:
 Ver   Who  Date     Changes
 ----- ---- -------- --------------------------------------------------------
 1.01a ecm  01/31/04 First release
 1.11a mta  03/21/07 Updated to new coding style
 1.11a ecm  05/18/07 Updated the TxBufferAvailable routine to look at both
                     the active and busy bits
 1.13a sv   02/1/08  Updated the TxBufferAvailable routine to return
		      busy status properly
 2.00a ktn  02/16/09 Added support for MDIO
 2.01a ktn  07/20/09 Modified XEmacLite_Send function to use Ping buffers
                     Interrupt enable bit since this alone is used to enable
                     the interrupts for both Ping and Pong Buffers.
 3.00a ktn  10/22/09 Updated driver to use the HAL APIs/macros.
		      The macros have been renamed to remove _m from the name.
 3.01a ktn  07/08/10 The macro XEmacLite_GetReceiveDataLength is changed to
		      a static function.
		      Updated the XEmacLite_GetReceiveDataLength and
		      XEmacLite_Recv functions to support little endian
		      MicroBlaze.
 3.02a sdm  07/22/11 Removed redundant code in XEmacLite_Recv functions for
		      CR617290
 3.04a srt  04/13/13 Removed warnings (CR 705000).
 

Function Documentation

void StubHandler ( void *  CallBackRef  ) 

This is a stub for the send and receive callbacks. The stub is here in case the upper layers forget to set the handlers.

Parameters:
CallBackRef is a pointer to the upper layer callback reference.
Returns:
None.
Note:
None.
int XEmacLite_CfgInitialize ( XEmacLite InstancePtr,
XEmacLite_Config EmacLiteConfigPtr,
u32  EffectiveAddr 
)

Initialize a specific XEmacLite instance/driver. The initialization entails:

  • Initialize fields of the XEmacLite instance structure.

The driver defaults to polled mode operation.

Parameters:
InstancePtr is a pointer to the XEmacLite instance.
EmacLiteConfigPtr points to the XEmacLite device configuration structure.
EffectiveAddr is the device base address in the virtual memory address space. If the address translation is not used then the physical address is passed. Unexpected errors may occur if the address mapping is changed after this function is invoked.
Returns:
  • XST_SUCCESS if initialization was successful.
Note:
The initialization of the PHY device is not done in this function. The user needs to use XEmacLite_PhyRead and XEmacLite_PhyWrite functions to access the PHY device.
void XEmacLite_DisableLoopBack ( XEmacLite InstancePtr  ) 

Disable Internal loop back functionality.

Parameters:
InstancePtr is the pointer to the instance of the driver.
Returns:
None.
Note:
None.
void XEmacLite_EnableLoopBack ( XEmacLite InstancePtr  ) 

Enable Internal loop back functionality.

Parameters:
InstancePtr is the pointer to the instance of the driver.
Returns:
None.
Note:
None.
void XEmacLite_FlushReceive ( XEmacLite InstancePtr  ) 

Flush the Receive buffers. All data will be lost.

Parameters:
InstancePtr is the pointer to the instance of the driver to be worked on.
Returns:
None.
Note:
None.
int XEmacLite_PhyRead ( XEmacLite InstancePtr,
u32  PhyAddress,
u32  RegNum,
u16 *  PhyDataPtr 
)

Read the specified PHY register.

Parameters:
InstancePtr is the pointer to the instance of the driver.
PhyAddress is the address of the PHY device. The valid range is is from 0 to 31.
RegNum is the register number in the PHY device which is to be read. The valid range is is from 0 to 31.
PhyDataPtr is a pointer to the data in which the data read from the PHY device is returned.
Returns:
  • XST_SUCCESS if the data is read from the PHY.
  • XST_DEVICE_BUSY if MDIO is busy.
Note:
This function waits for the completion of MDIO data transfer.
int XEmacLite_PhyWrite ( XEmacLite InstancePtr,
u32  PhyAddress,
u32  RegNum,
u16  PhyData 
)

Write the given data to the specified register in the PHY device.

Parameters:
InstancePtr is the pointer to the instance of the driver.
PhyAddress is the address of the PHY device. The valid range is is from 0 to 31.
RegNum is the register number in the PHY device which is to be written. The valid range is is from 0 to 31.
PhyData is the data to be written to the specified register in the PHY device.
Returns:
  • XST_SUCCESS if the data is written to the PHY.
  • XST_DEVICE_BUSY if MDIO is busy.
Note:
This function waits for the completion of MDIO data transfer.
u16 XEmacLite_Recv ( XEmacLite InstancePtr,
u8 *  FramePtr 
)

Receive a frame. Intended to be called from the interrupt context or with a wrapper which waits for the receive frame to be available.

Parameters:
InstancePtr is a pointer to the XEmacLite instance.
FramePtr is a pointer to a buffer where the frame will be stored. The buffer must be at least XEL_MAX_FRAME_SIZE bytes. For optimal performance, a 32-bit aligned buffer should be used but it is not required, the function will align the data if necessary.
Returns:

The type/length field of the frame received. When the type/length field contains the type, XEL_MAX_FRAME_SIZE bytes will be copied out of the buffer and it is up to the higher layers to sort out the frame. Function returns 0 if there is no data waiting in the receive buffer or the pong buffer if configured.

Note:

This function call is not blocking in nature, i.e. it will not wait until a frame arrives.

int XEmacLite_Send ( XEmacLite InstancePtr,
u8 *  FramePtr,
unsigned  ByteCount 
)

Send an Ethernet frame. The ByteCount is the total frame size, including header.

Parameters:
InstancePtr is a pointer to the XEmacLite instance.
FramePtr is a pointer to frame. For optimal performance, a 32-bit aligned buffer should be used but it is not required, the function will align the data if necessary.
ByteCount is the size, in bytes, of the frame
Returns:
  • XST_SUCCESS if data was transmitted.
  • XST_FAILURE if buffer(s) was (were) full and no valid data was transmitted.
Note:

This function call is not blocking in nature, i.e. it will not wait until the frame is transmitted.

void XEmacLite_SetMacAddress ( XEmacLite InstancePtr,
u8 *  AddressPtr 
)

Set the MAC address for this device. The address is a 48-bit value.

Parameters:
InstancePtr is a pointer to the XEmacLite instance.
AddressPtr is a pointer to a 6-byte MAC address. the format of the MAC address is major octet to minor octet
Returns:
None.
Note:
  • TX must be idle and RX should be idle for deterministic results. It is recommended that this function should be called after the initialization and before transmission of any packets from the device.
  • Function will not return if hardware is absent or not functioning properly.
  • The MAC address can be programmed using any of the two transmit buffers (if configured).
int XEmacLite_TxBufferAvailable ( XEmacLite InstancePtr  ) 

Determine if there is a transmit buffer available.

Parameters:
InstancePtr is the pointer to the instance of the driver to be worked on.
Returns:
  • TRUE if there is a TX buffer available for data to be written
  • FALSE if Tx Buffer is not available.
Note:
None.