emacps: xemacps_ieee1588.c File Reference

| emacps Xilinx SDK Drivers API Documentation

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

Functions
xemacps_ieee1588.c File Reference

## Overview

This file implements the following functionalities.

- Contains a routine upon reception of Tx done ISR to store the time stamp of the transmitted packet.
- Does formatting and initiates a Tx for Announce frame, Sync frame, FollowUp frame, PDelayReq, PDelayResp and PDelayRespFollowUp frames.
- Decodes and processes the received PTP frames of type Sync Frame, FollowUp frame, Announce Frame, PDelayReq frame, PDelayResp frame and PDelayRespFollowUp frame.
- Implements the best master clock algorithm.
- Contains function that calculates the link delay from existing data.
- Contains function that calculates the clock offset from existing data and applies the clock offset to correct the PTP clock.

    MODIFICATION HISTORY:

    Ver   Who  Date     Changes

    1.00a asa  09/16/11 First release based on the AVB driver.
    1.01a asa  03/03/12 Support for Zynq is added.
    3.3   asa  05/19/16 Removed code specific to PEEP.

## Functions
void | XEmacPs_PtpTxDoFurtherProcessing (XEmacPs_Ieee1588 *InstancePtr, u8 *PacketBuf)
| This function is invoked from the TxDone callback. More...
void | XEmacPs_MasterSendAnnounce (XEmacPs_Ieee1588 *InstancePtr)
| A function to format and then initiate the Tx of a PTP Announce Packet. More...
void | XEmacPs_MasterSendSync (XEmacPs_Ieee1588 *InstancePtr)
| A function to format and then initiate the Tx of a PTP SYNC Packet. More...
void | XEmacPs_MasterSendFollowUp (XEmacPs_Ieee1588 *InstancePtr)
| A function to format and then initiate the Tx of a PTP FOLLOWUP Packet. More...
void | XEmacPs_SendPDelayReq (XEmacPs_Ieee1588 *InstancePtr)
| A function to format and then initiate the Tx of a PTP PDelayReq Packet. More...
void | XEmacPs_SendPDelayResp (XEmacPs_Ieee1588 *InstancePtr)
| A function to format and then initiate the Tx of a PTP PDelayResp Packet. More...
void | XEmacPs_SendPDelayRespFollowUp (XEmacPs_Ieee1588 *InstancePtr)
| A function to format and then initiate the Tx of a PTP PDelayRespFollowUp Packet. More...
void | XEmacPs_DecodeRxSync (XEmacPs_Ieee1588 *InstancePtr, u8 *PacketBuf)
| A function to decode a received PTP Sync Packet. More...
void | XEmacPs_DecodeRxFollowUp (XEmacPs_Ieee1588 *InstancePtr, u8 *PacketBuf)
| A function to decode a received PTP FollowUp Packet. More...
void | XEmacPs_DecodeRxPDelayResp (XEmacPs_Ieee1588 *InstancePtr, u8 *PacketBuf)
| A function to decode a received PTP PDelayResp Packet. More...
void | XEmacPs_DecodeRxPDelayRespFollowUp (XEmacPs_Ieee1588 *InstancePtr, u8 *PacketBuf)
| A function to decode a received PTP PDelayRespFollowUp Packet. More...
void | XEmacPs_DecodeRxSignaling (XEmacPs_Ieee1588 *InstancePtr, u8 *PacketBuf)
| A function to decode a received PTP Signalling Packet. More...
void | XEmacPs_DecodeTxAnnounceFrame (XEmacPs_Ieee1588 *InstancePtr, u8 *PacketBuf)
| This function is invoked to compare the Current Master clock's parameter with that of the PTP node's (own) and run Best Master Clock Algorithm. More...
void | XEmacPs_ReadAnnounceFrame (u8 *PacketBuf, XEmacPs_BmcData *AnnounceFrame)
| This function is invoked from various places to extract clock information from a buffer and populate the XEmacPs_BmcData instance passed. More...
void | XEmacPs_DecodeRxAnnounceFrame (XEmacPs_Ieee1588 *InstancePtr, u8 *PacketBuf)
| This function is invoked when a new Announce frame is received. More...
u32 | XEmacPs_BestMasterClockAlgorithm (XEmacPs_BmcData *AnnounceFrame, XEmacPs_BmcData *CurrentBmc)
| This function will accept the data pointer to the current BMCA records, accept a pointer to an equivalent data structure for the new Announce Packet. More...
void | XEmacPs_UpdateBmcRecords (XEmacPs_BmcData *NewMaster, XEmacPs_BmcData *CurrentBmc)
| This function updates the PTP master records (BMC records) with incoming BMC data. More...
void | XEmacPs_BecomeRtcMaster (XEmacPs_Ieee1588 *InstancePtr, u8 txAnnounceHasWon)
| This function is called when the PTP node becomes RTC or PTP Master. More...
void | XEmacPs_BecomeRtcSlave (XEmacPs_Ieee1588 *InstancePtr)
| This function is called when the PTP node becomes PTP Slave. More...
void | XEmacPs_ChangePeerIeee1588v2Capability (XEmacPs_Ieee1588 *InstancePtr, u8 Capable)
| This function is called to change the Peer capability of processing Iee1588v2 specific frames, e.g. More...
void | XEmacPs_CalcDelay (XEmacPs_Ieee1588 *InstancePtr)
| This function is called to calculate the link delay. More...
void | XEmacPs_CalcRtcOffset (XEmacPs_Ieee1588 *InstancePtr)
| This function calculates the Slave Offset from the GrandMaster time. More...
void | XEmacPs_UpdateRtcIncrement (XEmacPs_Ieee1588 *InstancePtr)
| This function clock rate adjustment. More...

## Function Documentation

void XEmacPs_BecomeRtcMaster | ( | XEmacPs_Ieee1588 * | InstancePtr,
|  | u8 | txAnnounceHasWon
| ) |  |

This function is called when the PTP node becomes RTC or PTP Master.

This will make any adjustments needed when the node becomes the Grand Master, including resetting the RTC to its nominal value

Parameters

  InstancePtr | is a pointer to the XEmacPs_Ieee1588 instance.
  txAnnounceHasWon | if 1, indicates that this function has been called from the function XEmacPs_DecodeTxAnnounceFrame(). This way it can avoid performing things that are already done.

Returns
  None.

Note
  None.

References XEMACPS_1588_INC_OFFSET, XEmacPs_ReadAnnounceFrame(), XEmacPs_TsuCalcClk(), XEmacPs_UpdateBmcRecords(), and XEmacPs_WriteReg.

Referenced by XEmacPs_DecodeTxAnnounceFrame(), XEmacPs_InitializeProtocolData(), and XEmacPs_TimerInterruptHandler().

void XEmacPs_BecomeRtcSlave | ( | XEmacPs_Ieee1588 * | InstancePtr | ) |

This function is called when the PTP node becomes PTP Slave.

Parameters

  InstancePtr | is a pointer to the XEmacPs_Ieee1588 instance.

Returns
  None.

Note
  None.

Referenced by XEmacPs_DecodeRxAnnounceFrame().

u32 XEmacPs_BestMasterClockAlgorithm | ( | XEmacPs_BmcData * | AnnounceFrame,
|  | XEmacPs_BmcData * | CurrentBmc
| ) |  |

This function will accept the data pointer to the current BMCA records, accept a pointer to an equivalent data structure for the new Announce Packet.

TheBest Master Clock Algorithm (BMCA) is then performed on these two data structures by comparing the data fields

Parameters

  AnnounceFrame | of the received new frame
  CurrentBmc | is the existing BMC records

Returns
  None.

Note
  None.

Referenced by XEmacPs_DecodeRxAnnounceFrame(), and XEmacPs_DecodeTxAnnounceFrame().

void XEmacPs_CalcDelay | ( | XEmacPs_Ieee1588 * | InstancePtr | ) |

This function is called to calculate the link delay.

This is called after a complete sequence of PDelay packets. The PTP node sends a PDelayReq packet to start. Afterwards it receives the PDelayResp and PDelayRespFollowUp frames. Upon receiving the PDelayRespFollowUp, this function is invoked to calculate the link delay.

Parameters

  InstancePtr | is a pointer to the XEmacPs_Ieee1588 instance.

Returns
  None.

Note
  None.

References XEmacPs_ChangePeerIeee1588v2Capability().

Referenced by XEmacPs_DecodeRxPDelayRespFollowUp().

void XEmacPs_CalcRtcOffset | ( | XEmacPs_Ieee1588 * | InstancePtr | ) |

This function calculates the Slave Offset from the GrandMaster time.

It is called after receiving a Sync and FollowUp frame pair.

Parameters

  InstancePtr | is a pointer to the XEmacPs_Ieee1588 instance.

Returns
  None.

Note
  None.

References XEMACPS_1588_ADJ_OFFSET, XEMACPS_1588_SEC_OFFSET, XEmacPs_ReadReg, and XEmacPs_WriteReg.

Referenced by XEmacPs_DecodeRxFollowUp().

void XEmacPs_ChangePeerIeee1588v2Capability | ( | XEmacPs_Ieee1588 * | InstancePtr,
|  | u8 | Capable
| ) |  |

This function is called to change the Peer capability of processing Iee1588v2 specific frames, e.g.

PDelayReq, PDelayResp etc. A peer is Ieee1588v2 capable when it is able to send PDelayReq frames or able to respond to PDelayReq frames.

Parameters

  InstancePtr | is a pointer to the XEmacPs_Ieee1588 instance.
  capable | is Peer's capability

Returns
  None.

Note
  None.

Referenced by XEmacPs_CalcDelay(), XEmacPs_DecodeRxPDelayResp(), XEmacPs_InitializeProtocolData(), and XEmacPs_TimerInterruptHandler().

void XEmacPs_DecodeRxAnnounceFrame | ( | XEmacPs_Ieee1588 * | InstancePtr,
|  | u8 * | PacketBuf
| ) |  |

This function is invoked when a new Announce frame is received.

This function first reads the Announce frame parameters. If it is found that the announce frame has been received from the PTP master then the records are updated with the clock parameters. The Best Master Clock Algorithm is run in case any of the parameters in the announce frame has changed. There can be cases when the PTP master reduces its clock priority that may force the current PTP node to become master. If the PTP node is master and it has received this announce frame, then BMCA is run and if the incoming clock parameters are better tyhan that of the present node, the present node becomes SLAVE.

Parameters

  InstancePtr | is a pointer to the XEmacPs_Ieee1588 instance.
  PacketBuf | is the buffer that contains the Announce Frame.

Returns
  None.

Note
  None.

References XEmacPs_BecomeRtcSlave(), XEmacPs_BestMasterClockAlgorithm(), XEmacPs_CompareClockIdentity(), XEmacPs_ComparePortIdentity(), XEmacPs_DecodeTxAnnounceFrame(), XEmacPs_ReadAnnounceFrame(), and XEmacPs_UpdateBmcRecords().

Referenced by XEmacPs_HandleRecdPTPPacket().

void XEmacPs_DecodeRxFollowUp | ( | XEmacPs_Ieee1588 * | InstancePtr,
|  | u8 * | PacketBuf
| ) |  |

A function to decode a received PTP FollowUp Packet.

If the PTP node is master, source port identity of the received FollowUp frame matches that with this node's source port identity, the sequence Id of the received folowup frame matches that of last received Sync frame sequence Id, the function XEmacPs_CalcRtcOffset is invoked to calculate clock offset. Similalry for every 2 sync frames clock rate adjustment is done by calling XEmacPs_UpdateRtcIncrement. However, as of now, this function is not implemented and is empty.

Parameters

  InstancePtr | is a pointer to the XEmacPs_Ieee1588 instance.
  PacketBuf | is the buffer that contains the followup packet.

Returns
  None.

Note
  The clock rate adjustment is not implemented as of now. Though the function XEmacPs_UpdateRtcIncrement is called from here, the function does nothing!

References XEmacPs_CalcRtcOffset(), XEmacPs_ComparePortIdentity(), XEmacPs_GetPortIdentity(), XEmacPs_GetSequenceId(), and XEmacPs_UpdateRtcIncrement().

Referenced by XEmacPs_HandleRecdPTPPacket().

void XEmacPs_DecodeRxPDelayResp | ( | XEmacPs_Ieee1588 * | InstancePtr,
|  | u8 * | PacketBuf
| ) |  |

A function to decode a received PTP PDelayResp Packet.

Parameters

  InstancePtr | is a pointer to the XEmacPs_Ieee1588 instance.
  PacketBuf | is the buffer that contains the PDelayResp packet.

Returns
  None.

Note
  None.

References XEmacPs_ChangePeerIeee1588v2Capability(), XEmacPs_ComparePortIdentity(), XEmacPs_GetPortIdentity(), XEmacPs_GetSequenceId(), XEMACPS_PTPP_RXNANOSEC_OFFSET, and XEmacPs_ReadReg.

Referenced by XEmacPs_HandleRecdPTPPacket().

void XEmacPs_DecodeRxPDelayRespFollowUp | ( | XEmacPs_Ieee1588 * | InstancePtr,
|  | u8 * | PacketBuf
| ) |  |

A function to decode a received PTP PDelayRespFollowUp Packet.

Parameters

  InstancePtr | is a pointer to the XEmacPs_Ieee1588 instance.
  PacketBuf | is the buffer that contains the PDelayRespFollowUp packet.

Returns
  None.

Note
  None.

References XEmacPs_CalcDelay(), XEmacPs_ComparePortIdentity(), XEmacPs_GetPortIdentity(), and XEmacPs_GetSequenceId().

Referenced by XEmacPs_HandleRecdPTPPacket().

void XEmacPs_DecodeRxSignaling | ( | XEmacPs_Ieee1588 * | InstancePtr,
|  | u8 * | PacketBuf
| ) |  |

A function to decode a received PTP Signalling Packet.

Empty as of now.

Parameters

  InstancePtr | is a pointer to the XEmacPs_Ieee1588 instance.
  PacketBuf | is the buffer that contains the signalling packet.

Returns
  None.

Note
  None.

Referenced by XEmacPs_HandleRecdPTPPacket().

void XEmacPs_DecodeRxSync | ( | XEmacPs_Ieee1588 * | InstancePtr,
|  | u8 * | PacketBuf
| ) |  |

A function to decode a received PTP Sync Packet.

It extracts the sync frame time stamp and stores it in appropriate buffer. It stores the sequence ID as well.

Parameters

  InstancePtr | is a pointer to the XEmacPs_Ieee1588 instance.
  PacketBuf | is the buffer that contains the sync packet.

Returns
  None.

Note
  None.

References XEmacPs_ComparePortIdentity(), XEmacPs_GetPortIdentity(), XEmacPs_GetSequenceId(), XEMACPS_PTP_RXNANOSEC_OFFSET, XEMACPS_PTP_RXSEC_OFFSET, and XEmacPs_ReadReg.

Referenced by XEmacPs_HandleRecdPTPPacket().

void XEmacPs_DecodeTxAnnounceFrame | ( | XEmacPs_Ieee1588 * | InstancePtr,
|  | u8 * | PacketBuf
| ) |  |

This function is invoked to compare the Current Master clock's parameter with that of the PTP node's (own) and run Best Master Clock Algorithm.

A typical scenario is a new Announce frame has been received from the PTP Master and the PTP master record has been updated. Then this function is invoked to run Best Master Clock Algorithm with the PTP node's Announce Frame parameters and Current PTP Master's parameter.

Parameters

  InstancePtr | is a pointer to the XEmacPs_Ieee1588 instance.
  PacketBuf | is the buffer that contains the Announce Frame. For this function the buffer passed is the Tx Announce Frame stored in the buffer AnnounceFrmToTx in XEmacPs_Ieee1588 instance.

Returns
  None.

Note
  None.

References XEmacPs_BecomeRtcMaster(), XEmacPs_BestMasterClockAlgorithm(), XEmacPs_ReadAnnounceFrame(), and XEmacPs_UpdateBmcRecords().

Referenced by XEmacPs_DecodeRxAnnounceFrame(), and XEmacPs_InitializeProtocolData().

void XEmacPs_MasterSendAnnounce | ( | XEmacPs_Ieee1588 * | InstancePtr | ) |

A function to format and then initiate the Tx of a PTP Announce Packet.

The sequence Id of the announce frame is incremented before initiating the Tx.

Parameters

  InstancePtr | is a pointer to the XEmacPs_Ieee1588 instance.

Returns
  None.

Note
  None.

References XEmacPs_IncSequenceId(), and XEmacPs_PtpTxPacket().

Referenced by XEmacPs_TimerInterruptHandler().

void XEmacPs_MasterSendFollowUp | ( | XEmacPs_Ieee1588 * | InstancePtr | ) |

A function to format and then initiate the Tx of a PTP FOLLOWUP Packet.

Updates the correction field in the buffer.

Parameters

  InstancePtr | is a pointer to the XEmacPs_Ieee1588 instance.

Returns
  None.

Note
  The correction field is hard coded to zero as of now.

References XEmacPs_PtpTxPacket().

Referenced by XEmacPs_RunIEEE1588Protocol().

void XEmacPs_MasterSendSync | ( | XEmacPs_Ieee1588 * | InstancePtr | ) |

A function to format and then initiate the Tx of a PTP SYNC Packet.

The sequence Id of the announce frame is incremented before initiating the Tx.

Parameters

  InstancePtr | is a pointer to the XEmacPs_Ieee1588 instance.

Returns
  None.

Note
  None.

References XEmacPs_IncSequenceId().

Referenced by XEmacPs_TimerInterruptHandler().

void XEmacPs_PtpTxDoFurtherProcessing | ( | XEmacPs_Ieee1588 * | InstancePtr,
|  | u8 * | PacketBuf
| ) |  |

This function is invoked from the TxDone callback.

For sync frame it obtains the time stamp and populates the FollowUp frame Tx buffer. For PDelayReq and PDelayResp frames it obtains the time stamp and stores it is appropriate buffers.

Parameters

  InstancePntr | is a pointer to the instance of the XEmacPs_Ieee1588.
  PacketBuf | which contains the buffer just transmitted

Returns
  None.

Note
  None.

References XEmacPs_GetMsgType(), XEmacPs_GetSequenceId(), XEMACPS_PTP_TXNANOSEC_OFFSET, XEMACPS_PTP_TXSEC_OFFSET, XEMACPS_PTPP_TXNANOSEC_OFFSET, XEMACPS_PTPP_TXSEC_OFFSET, and XEmacPs_ReadReg.

Referenced by XEmacPs_PtpTxInterruptHandler().

void XEmacPs_ReadAnnounceFrame | ( | u8 * | PacketBuf,
|  | XEmacPs_BmcData * | AnnounceFrame
| ) |  |

This function is invoked from various places to extract clock information from a buffer and populate the XEmacPs_BmcData instance passed.

Parameters

  PacketBuf | from which the clock information is extracted
  AnnounceFrame | which is populated with clock information

Returns
  None.

Note
  None.

References XEmacPs_GetPortIdentity().

Referenced by XEmacPs_BecomeRtcMaster(), XEmacPs_DecodeRxAnnounceFrame(), and XEmacPs_DecodeTxAnnounceFrame().

void XEmacPs_SendPDelayReq | ( | XEmacPs_Ieee1588 * | InstancePtr | ) |

A function to format and then initiate the Tx of a PTP PDelayReq Packet.

The sequence Id of the announce frame is incremented before initiating the Tx.

Parameters

  InstancePtr | is a pointer to the XEmacPs_Ieee1588 instance.

Returns
  None.

Note
  None.

References XEmacPs_IncSequenceId().

Referenced by XEmacPs_TimerInterruptHandler().

void XEmacPs_SendPDelayResp | ( | XEmacPs_Ieee1588 * | InstancePtr | ) |

A function to format and then initiate the Tx of a PTP PDelayResp Packet.

This function is invoked upon receiving a PDelayReq frame. It first gets the time stamps of the received PDelayReq from the hardware and stores them at appropriate entries in the structure instance PtpRecords. It then formats the PDelayResp frame with these time stamp values.

Parameters

  InstancePtr | is a pointer to the XEmacPs_Ieee1588 instance.

Returns
  None.

Note
  None.

References XEmacPs_GetPortIdentity(), XEmacPs_GetSequenceId(), XEMACPS_PTPP_RXNANOSEC_OFFSET, XEMACPS_PTPP_RXSEC_OFFSET, and XEmacPs_ReadReg.

Referenced by XEmacPs_HandleRecdPTPPacket().

void XEmacPs_SendPDelayRespFollowUp | ( | XEmacPs_Ieee1588 * | InstancePtr | ) |

A function to format and then initiate the Tx of a PTP PDelayRespFollowUp Packet.

This function is invoked after a PDelayResp is successfully sent out (Tx done interrupt is received for PDelayResp packet). It populates the PDelayRespFollowUp frame with time stamps of the just transmitted PDelayResp packet.

Parameters

  InstancePtr | is a pointer to the XEmacPs_Ieee1588 instance.

Returns
  None.

Note
  None.

References XEmacPs_GetPortIdentity(), XEmacPs_GetSequenceId(), and XEmacPs_PtpTxPacket().

Referenced by XEmacPs_RunIEEE1588Protocol().

void XEmacPs_UpdateBmcRecords | ( | XEmacPs_BmcData * | NewMaster,
|  | XEmacPs_BmcData * | CurrentBmc
| ) |  |

This function updates the PTP master records (BMC records) with incoming BMC data.

Parameters

  NewMaster | is the new data to be updated
  CurrentBmc | is the existing BMC records that needs to be updated.

Returns
  None.

Note
  None.

Referenced by XEmacPs_BecomeRtcMaster(), XEmacPs_DecodeRxAnnounceFrame(), and XEmacPs_DecodeTxAnnounceFrame().

void XEmacPs_UpdateRtcIncrement | ( | XEmacPs_Ieee1588 * | InstancePtr | ) |

This function clock rate adjustment.

Not implemented as of now.

Parameters

  InstancePtr | is a pointer to the XEmacPs_Ieee1588 instance.

Returns
  None.

Note
  None.

Referenced by XEmacPs_DecodeRxFollowUp().