axiethernet: xaxiethernet_example_util.c File Reference

| axiethernet Xilinx SDK Drivers API Documentation

- Overview
- Data Structures
- APIs
- File List
- Examples

Macros | Functions
xaxiethernet_example_util.c File Reference

## Overview

This file implements the utility functions for the Axi Ethernet example code.

    MODIFICATION HISTORY:

    Ver   Who  Date     Changes

    1.00a asa  6/30/10 First release based on the ll temac driver
    3.01a srt  02/03/13 Added support for SGMII mode (CR 676793).
               02/14/13 Added support for Zynq (CR 681136).
    3.02a srt  04/24/13 Modified parameter *_SGMII_PHYADDR to *_PHYADDR, the
                        config parameter C_PHYADDR applies to SGMII/1000BaseX
                        modes of operation and added support for 1000BaseX mode
                  (CR 704195). Added function *_ConfigureInternalPhy()
                  for this purpose.
               04/24/13 Added support for RGMII mode.
    3.02a srt  08/06/13 Fixed CR 717949:
                    Configures external Marvel 88E1111 PHY based on the
                    axi ethernet physical interface type and allows to
                    operate in specific interface mode without changing
                    jumpers on the Microblaze board.
    5.4     adk  07/12/16  Added Support for TI PHY DP83867.
          ms   04/05/17  Added tabspace for return statements in functions
                         for proper documentation while generating doxygen.

## Macros
#define | PHY_DETECT_REG 1
| This function detects the PHY address by looking for successful MII status register contents (PHY register 1). More...
#define | PHY_R0_CTRL_REG 0
| Set PHY to loopback mode. More...

## Functions
void | AxiEthernetUtilFrameHdrFormatMAC (EthernetFrame *FramePtr, char *DestAddr)
| Set the MAC addresses in the frame. More...
void | AxiEthernetUtilFrameHdrFormatType (EthernetFrame *FramePtr, u16 FrameType)
| Set the frame type for the specified frame. More...
void | AxiEthernetUtilFrameSetPayloadData (EthernetFrame *FramePtr, int PayloadSize)
| This function places a pattern in the payload section of a frame. More...
void | AxiEthernetUtilFrameHdrVlanFormatVid (EthernetFrame *FramePtr, u32 VlanNumber, u32 Vid)
| Set the frame VLAN info for the specified frame. More...
void | AxiEthernetUtilFrameHdrVlanFormatType (EthernetFrame *FramePtr, u16 FrameType, u32 VlanNumber)
| Set the frame type for the specified frame. More...
void | AxiEthernetUtilFrameSetVlanPayloadData (EthernetFrame *FramePtr, int PayloadSize, u32 VlanNumber)
| This function places a pattern in the payload section of a frame. More...
int | AxiEthernetUtilFrameVerify (EthernetFrame *CheckFrame, EthernetFrame *ActualFrame)
| This function verifies the frame data against a CheckFrame. More...
void | AxiEthernetUtilFrameMemClear (EthernetFrame *FramePtr)
| This function sets all bytes of a frame to 0. More...
int | AxiEthernetUtilEnterLoopback (XAxiEthernet *AxiEthernetInstancePtr, int Speed)
| This function sets the PHY to loopback mode. More...
void | AxiEthernetUtilErrorTrap (char *Message)
| This function is called by example code when an error is detected. More...
void | AxiEthernetUtilPhyDelay (unsigned int Seconds)
| For Microblaze we use an assembly loop that is roughly the same regardless of optimization level, although caches and memory access time can make the delay vary. More...
int | AxiEthernetUtilConfigureInternalPhy (XAxiEthernet *AxiEthernetInstancePtr, int Speed)
| This function configures the internal phy for SGMII and 1000baseX modes. More...

## Macro Definition Documentation

#define PHY_DETECT_REG 1

This function detects the PHY address by looking for successful MII status register contents (PHY register 1).

It looks for a PHY that supports auto-negotiation and 10Mbps full-duplex and half-duplex. So, this code won't work for PHYs that don't support those features, but it's a bit more general purpose than matching a specific PHY manufacturer ID.

Note also that on some (older) Xilinx ML4xx boards, PHY address 0 does not properly respond to this query. But, since the default is 0 and assuming no other address responds, then it seems to work OK.

Parameters

  The | Axi Ethernet driver instance

Returns
  The address of the PHY (defaults to 0 if none detected)

Note
  None.

#define PHY_R0_CTRL_REG 0

Set PHY to loopback mode.

This works with the marvell PHY common on ML40x evaluation boards

Parameters

  Speed | is the loopback speed 10, 100, or 1000 Mbit

Referenced by AxiEthernetUtilConfigureInternalPhy(), and AxiEthernetUtilEnterLoopback().

## Function Documentation

int AxiEthernetUtilConfigureInternalPhy | ( | XAxiEthernet * | AxiEthernetInstancePtr,
|  | int | Speed
| ) |  |

This function configures the internal phy for SGMII and 1000baseX modes.

- Parameters

    AxiEthernetInstancePtr | is a pointer to the instance of the AxiEthernet component.
    Speed | is the loopback speed 10, 100, or 1000 Mbit.

  Returns
    - XST_SUCCESS if successful.
    - XST_FAILURE, in case of failure..
  Note
    None.

References AxiEthernetUtilErrorTrap(), AxiEthernetUtilPhyDelay(), PHY_R0_CTRL_REG, XAE_SPEED_1000_MBPS, XAE_SPEED_100_MBPS, XAE_SPEED_10_MBPS, and XAE_SPEED_2500_MBPS.

Referenced by AxiEthernetUtilEnterLoopback().

int AxiEthernetUtilEnterLoopback | ( | XAxiEthernet * | AxiEthernetInstancePtr,
|  | int | Speed
| ) |  |

This function sets the PHY to loopback mode.

This works with the marvell PHY common on ML40x evaluation boards.

Parameters

  AxiEthernetInstancePtr | is a pointer to the instance of the AxiEthernet component.
  Speed | is the loopback speed 10, 100, or 1000 Mbit.

Returns
  - XST_SUCCESS if successful.
  - XST_FAILURE, in case of failure..

Note
  None.

References AxiEthernetUtilConfigureInternalPhy(), AxiEthernetUtilErrorTrap(), AxiEthernetUtilPhyDelay(), PHY_R0_CTRL_REG, XAE_SPEED_1000_MBPS, XAE_SPEED_100_MBPS, XAE_SPEED_10_MBPS, XAE_SPEED_2500_MBPS, and XAxiEthernet_GetPhysicalInterface.

Referenced by AxiEthernetExtVlanExample(), AxiEthernetFifoIntrExample(), AxiEthernetMcastExample(), AxiEthernetPolledExample(), AxiEthernetSgDmaIntrExample(), and AxiEthernetSgDmaPollExample().

void AxiEthernetUtilErrorTrap | ( | char * | Message | ) |

This function is called by example code when an error is detected.

It can be set as a breakpoint with a debugger or it can be used to print out the given message if there is a UART or STDIO device.

Parameters

  Message | is the text explaining the error

Returns
  None

Note
  None

Referenced by AxiEthernetExtVlanExample(), AxiEthernetFifoIntrExample(), AxiEthernetMcastExample(), AxiEthernetMultipleFramesIntrExample(), AxiEthernetMultipleFramesPolledExample(), AxiEthernetPolledExample(), AxiEthernetPollForRxStatus(), AxiEthernetPollForTxStatus(), AxiEthernetResetDevice(), AxiEthernetSgDmaFullChecksumOffloadExample(), AxiEthernetSgDmaIntrCoalescingExample(), AxiEthernetSgDmaIntrExample(), AxiEthernetSgDmaIntrExtMulticastExample(), AxiEthernetSgDmaIntrExtVlanExample(), AxiEthernetSgDmaIntrMultiFrameExample(), AxiEthernetSgDmaIntrSingleFrameExample(), AxiEthernetSgDmaMultiFrameExample(), AxiEthernetSgDmaPartialChecksumOffloadExample(), AxiEthernetSgDmaPollExample(), AxiEthernetSgDmaSingleFrameExample(), AxiEthernetSingleFrameIntrExample(), AxiEthernetSingleFrameNonContIntrExample(), AxiEthernetSingleFramePolledExample(), AxiEthernetUtilConfigureInternalPhy(), AxiEthernetUtilEnterLoopback(), and main().

void AxiEthernetUtilFrameHdrFormatMAC | ( | EthernetFrame * | FramePtr,
|  | char * | DestAddr
| ) |  |

Set the MAC addresses in the frame.

Parameters

  FramePtr | is the pointer to the frame.
  DestAddr | is the Destination MAC address.

Returns
  None.

Note
  None.

Referenced by AxiEthernetMultipleFramesIntrExample(), AxiEthernetMultipleFramesPolledExample(), AxiEthernetSgDmaFullChecksumOffloadExample(), AxiEthernetSgDmaIntrCoalescingExample(), AxiEthernetSgDmaIntrExtMulticastExample(), AxiEthernetSgDmaIntrExtVlanExample(), AxiEthernetSgDmaIntrMultiFrameExample(), AxiEthernetSgDmaIntrSingleFrameExample(), AxiEthernetSgDmaMultiFrameExample(), AxiEthernetSgDmaPartialChecksumOffloadExample(), AxiEthernetSgDmaSingleFrameExample(), AxiEthernetSingleFrameIntrExample(), AxiEthernetSingleFrameNonContIntrExample(), and AxiEthernetSingleFramePolledExample().

void AxiEthernetUtilFrameHdrFormatType | ( | EthernetFrame * | FramePtr,
|  | u16 | FrameType
| ) |  |

Set the frame type for the specified frame.

Parameters

  FramePtr | is the pointer to the frame.
  FrameType | is the Type to set in frame.

Returns
  None.

Note
  None.

Referenced by AxiEthernetMultipleFramesIntrExample(), AxiEthernetMultipleFramesPolledExample(), AxiEthernetSgDmaFullChecksumOffloadExample(), AxiEthernetSgDmaIntrCoalescingExample(), AxiEthernetSgDmaIntrExtMulticastExample(), AxiEthernetSgDmaIntrMultiFrameExample(), AxiEthernetSgDmaIntrSingleFrameExample(), AxiEthernetSgDmaMultiFrameExample(), AxiEthernetSgDmaPartialChecksumOffloadExample(), AxiEthernetSgDmaSingleFrameExample(), AxiEthernetSingleFrameIntrExample(), AxiEthernetSingleFrameNonContIntrExample(), and AxiEthernetSingleFramePolledExample().

void AxiEthernetUtilFrameHdrVlanFormatType | ( | EthernetFrame * | FramePtr,
|  | u16 | FrameType,
|  | u32 | VlanNumber
| ) |  |

Set the frame type for the specified frame.

Parameters

  FramePtr | is the pointer to the frame.
  FrameType | is the Type to set in frame.
  VlanNumber | is the VLAN friendly adjusted insertion position to set in frame.

Returns
  None.

Note
  None.

Referenced by AxiEthernetSgDmaIntrExtVlanExample().

void AxiEthernetUtilFrameHdrVlanFormatVid | ( | EthernetFrame * | FramePtr,
|  | u32 | VlanNumber,
|  | u32 | Vid
| ) |  |

Set the frame VLAN info for the specified frame.

Parameters

  FramePtr | is the pointer to the frame.
  VlanNumber | is the VlanValue insertion position to set in frame.
  Vid | is the 4 bytes Vlan value (TPID, Priority, CFI, VID) to be set in frame.

Returns
  None.

Note
  None.

Referenced by AxiEthernetSgDmaIntrExtVlanExample().

void AxiEthernetUtilFrameMemClear | ( | EthernetFrame * | FramePtr | ) |

This function sets all bytes of a frame to 0.

Parameters

  FramePtr | is a pointer to the frame itself.

Returns
  None.

Note
  None.

Referenced by AxiEthernetMultipleFramesIntrExample(), AxiEthernetSgDmaIntrExtMulticastExample(), AxiEthernetSgDmaIntrExtVlanExample(), AxiEthernetSgDmaIntrMultiFrameExample(), AxiEthernetSgDmaIntrSingleFrameExample(), AxiEthernetSgDmaMultiFrameExample(), AxiEthernetSgDmaPartialChecksumOffloadExample(), AxiEthernetSgDmaSingleFrameExample(), AxiEthernetSingleFrameIntrExample(), AxiEthernetSingleFrameNonContIntrExample(), and AxiEthernetSingleFramePolledExample().

void AxiEthernetUtilFrameSetPayloadData | ( | EthernetFrame * | FramePtr,
|  | int | PayloadSize
| ) |  |

This function places a pattern in the payload section of a frame.

The pattern is a 8 bit incrementing series of numbers starting with 0. Once the pattern reaches 256, then the pattern changes to a 16 bit incrementing pattern:

      0, 1, 2, ... 254, 255, 00, 00, 00, 01, 00, 02, ...

Parameters

  FramePtr | is a pointer to the frame to change.
  PayloadSize | is the number of bytes in the payload that will be set.

Returns
  None.

Note
  None.

Referenced by AxiEthernetMultipleFramesIntrExample(), AxiEthernetMultipleFramesPolledExample(), AxiEthernetSgDmaFullChecksumOffloadExample(), AxiEthernetSgDmaIntrCoalescingExample(), AxiEthernetSgDmaIntrExtMulticastExample(), AxiEthernetSgDmaIntrMultiFrameExample(), AxiEthernetSgDmaIntrSingleFrameExample(), AxiEthernetSgDmaMultiFrameExample(), AxiEthernetSgDmaPartialChecksumOffloadExample(), AxiEthernetSgDmaSingleFrameExample(), AxiEthernetSingleFrameIntrExample(), and AxiEthernetSingleFramePolledExample().

void AxiEthernetUtilFrameSetVlanPayloadData | ( | EthernetFrame * | FramePtr,
|  | int | PayloadSize,
|  | u32 | VlanNumber
| ) |  |

This function places a pattern in the payload section of a frame.

The pattern is a 8 bit incrementing series of numbers starting with 0. Once the pattern reaches 256, then the pattern changes to a 16 bit incrementing pattern:

      0, 1, 2, ... 254, 255, 00, 00, 00, 01, 00, 02, ...

Parameters

  FramePtr | is a pointer to the frame to change.
  PayloadSize | is the number of bytes in the payload that will be set.
  VlanNumber | is the VLAN friendly adjusted insertion position to set in frame.

Returns
  None.

Note
  None.

Referenced by AxiEthernetSgDmaIntrExtVlanExample().

int AxiEthernetUtilFrameVerify | ( | EthernetFrame * | CheckFrame,
|  | EthernetFrame * | ActualFrame
| ) |  |

This function verifies the frame data against a CheckFrame.

Validation occurs by comparing the ActualFrame to the header of the CheckFrame. If the headers match, then the payload of ActualFrame is verified for the same pattern Util_FrameSetPayloadData() generates.

Parameters

  CheckFrame | is a pointer to a frame containing the 14 byte header that should be present in the ActualFrame parameter.
  ActualFrame | is a pointer to a frame to validate.

Returns
  - XST_SUCCESS if successful.
  - XST_FAILURE in case of failure.

Note
  None.

Referenced by AxiEthernetMultipleFramesIntrExample(), AxiEthernetMultipleFramesPolledExample(), AxiEthernetSgDmaIntrExtMulticastExample(), AxiEthernetSgDmaIntrExtVlanExample(), AxiEthernetSgDmaIntrSingleFrameExample(), and AxiEthernetSingleFramePolledExample().

void AxiEthernetUtilPhyDelay | ( | unsigned int | Seconds | ) |

For Microblaze we use an assembly loop that is roughly the same regardless of optimization level, although caches and memory access time can make the delay vary.

Just keep in mind that after resetting or updating the PHY modes, the PHY typically needs time to recover.

Returns
  None

Note
  None

Referenced by AxiEthernetExtVlanExample(), AxiEthernetFifoIntrExample(), AxiEthernetMcastExample(), AxiEthernetPolledExample(), AxiEthernetSgDmaIntrExample(), AxiEthernetSgDmaPollExample(), AxiEthernetUtilConfigureInternalPhy(), and AxiEthernetUtilEnterLoopback().