emacps: xemacps_example_util.c File Reference

| emacps Xilinx SDK Drivers API Documentation

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

Macros | Functions
xemacps_example_util.c File Reference

## Overview

This file implements the utility functions for the XEmacPs example code.

    MODIFICATION HISTORY:

    Ver   Who  Date     Changes

    1.00a wsy  01/10/10 First release
    1.00a asa  01/24/12 A new version of EmacPsUtilEnterLoopback is used for
                          Zynq boards. Now there are two versions of
                          EmacPsUtilEnterLoopback, one for PEEP and one for Zynq.
                          If the example is to be run  on a PEEP board, define PEEP
                          in xemacps_example.h.
    1.01a asa  02/27/12 The sleep value after PHY loopback is setup is reduced
                  for Zynq.
    3.0   kpc  01/23/15 Removed PEEP board related code
    3.2     hk   09/30/15 Added support for TI PHY DP83867
    3.2   mus  02/20/16 Added support for microblaze.
    3.9   hk   02/12/19 Use selected speed in loopback mode.

## Macros
#define | PHY_DETECT_REG1 2
| This function detects the PHY address by looking for successful MII status register contents. More...
#define | PHY_REG0_RESET 0x8000
| This function sets the PHY to loopback mode. More...

## Functions
void | EmacPsUtilFrameHdrFormatMAC (EthernetFrame *FramePtr, char *DestAddr)
| Set the MAC addresses in the frame. More...
void | EmacPsUtilFrameHdrFormatType (EthernetFrame *FramePtr, u16 FrameType)
| Set the frame type for the specified frame. More...
void | EmacPsUtilFrameSetPayloadData (EthernetFrame *FramePtr, u32 PayloadSize)
| This function places a pattern in the payload section of a frame. More...
LONG | EmacPsUtilFrameVerify (EthernetFrame *CheckFrame, EthernetFrame *ActualFrame)
| This function verifies the frame data against a CheckFrame. More...
void | EmacPsUtilFrameMemClear (EthernetFrame *FramePtr)
| This function sets all bytes of a frame to 0. More...
void | EmacPsUtilstrncpy (char *Destination, const char *Source, u32 n)
| This function copies data from source to desitnation for n bytes. More...
void | EmacPsUtilEnterLocalLoopback (XEmacPs *EmacPsInstancePtr)
| This function sets the emacps to loopback mode. More...
void | EmacpsDelay (u32 delay)
| This function provides delays in seconds. More...
void | EmacPsUtilErrorTrap (const char *Message)
| This function is called by example code when an error is detected. More...

## Macro Definition Documentation

#define PHY_DETECT_REG1 2

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

Parameters

  The | XEMACPS driver instance

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

Note
  None.

#define PHY_REG0_RESET 0x8000

This function sets the PHY to loopback mode.

Parameters

  The | XEMACPS driver instance
  Speed | is the loopback speed 10/100 Mbit.

Returns
  XST_SUCCESS if successful, else XST_FAILURE.

Note
  None.

## Function Documentation

void EmacpsDelay | ( | u32 | delay | ) |

This function provides delays in seconds.

Parameters

  Delay | in seconds

Returns
  None.

Note
  for microblaze the delay is not accurate and it need to tuned.

Referenced by EmacPsDmaIntrExample().

void EmacPsUtilEnterLocalLoopback | ( | XEmacPs * | EmacPsInstancePtr | ) |

This function sets the emacps to loopback mode.

Parameters

  EmacPsInstancePtr | is the XEmacPs driver instance.

Note
  None.

References XEmacPs_Config::BaseAddress, XEMACPS_NWCTRL_LOOPEN_MASK, XEMACPS_NWCTRL_OFFSET, XEmacPs_ReadReg, and XEmacPs_WriteReg.

void EmacPsUtilErrorTrap | ( | const 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 EmacPsDmaIntrExample(), EmacPsDmaSingleFrameIntrExample(), and main().

void EmacPsUtilFrameHdrFormatMAC | ( | 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 EmacPsDmaSingleFrameIntrExample().

void EmacPsUtilFrameHdrFormatType | ( | 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 EmacPsDmaSingleFrameIntrExample().

void EmacPsUtilFrameMemClear | ( | 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 EmacPsDmaSingleFrameIntrExample().

void EmacPsUtilFrameSetPayloadData | ( | EthernetFrame * | FramePtr,
|  | u32 | 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 EmacPsDmaSingleFrameIntrExample().

LONG EmacPsUtilFrameVerify | ( | 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, else XST_FAILURE.

Note
  None.

Referenced by EmacPsDmaSingleFrameIntrExample().

void EmacPsUtilstrncpy | ( | char * | Destination,
|  | const char * | Source,
|  | u32 | n
| ) |  |

This function copies data from source to desitnation for n bytes.

Parameters

  Destination | is the targeted string to copy to.
  Source | is the source string to copy from.
  n | is number of bytes to be copied.

Note
  This function is similar to strncpy(), however strncpy will stop either at null byte or n bytes is been copied. This function will copy n bytes without checking the content.