| axiethernet Vitis Drivers API Documentation

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

Functions
xavb_ptp_packets.c File Reference

## Overview

The XAvb driver.

Functions in this file all contain functions which decode the received Precise Timing Protocol (PTP) frames, or to format and transmit PTP frames.

    MODIFICATION HISTORY:

    Ver   Who  Date     Changes

    1.00a mbr  09/19/08 First release
    1.01a mbr  06/24/09 PTP frame format updates for IEEE802.1 AS draft 5-0
    2_02a mbr  09/16/09 Updates for programmable PTP timers
    2_04a kag  07/23/10 PTP frame format updates for IEEE802.1 AS draft 6-7
    3_01a kag  08/29/11 Added new APIs to update the RX Filter Control Reg.
                  Fix for CR:572539. Updated bit map for Rx Filter
                  control reg.

## Functions
u32 | XAvb_CompareClockIdentity (u32 BaseAddress, XAvb_ClockIdentity Identity1, XAvb_ClockIdentity Identity2)
| A function to compare two ClockIdentity values. More...
u32 | XAvb_ComparePortIdentity (u32 BaseAddress, XAvb_PortIdentity Identity1, XAvb_PortIdentity Identity2)
| A function to compare two PortIdentity values. More...
void | XAvb_GetPortIdentity (u32 BaseAddress, u32 PtpFrameBaseAddr, u32 PortIdOffset, XAvb_PortIdentity *portID)
| A function to extract portIdentity information from a received PTP frame. More...
void | XAvb_WriteToMultipleTxPtpFrames (u32 BaseAddress, u32 PtpFieldAddress, u32 Data, u32 DataBitEnable, u8 BufferEnable)
| A function to write common data (eg the Source Address) to all PTP frames stored in the Tx PTP Packet buffer. More...
u32 | XAvb_ReorderWord (u32 Data)
| This function switches the bytes in a 4-byte word, swapping the MSB for the LSB, and vice-versa. More...
u32 | XAvb_IncSequenceId (u32 BaseAddress, u32 PtpFrameBaseAddress)
| A function to increment the sequenceId in a PTP frame template. More...
void | XAvb_WaitOnTxPtpQueue (XAvb *InstancePtr)
| The software drivers are kept simple by only requesting a single PTP frame to be transmitted at a time. More...
void | XAvb_MasterSendAnnounce (XAvb *InstancePtr)
| A function to format then request the transmission of a PTP Announce Packet. More...
void | XAvb_MasterSendSync (XAvb *InstancePtr)
| A function to format then request the transmission of a PTP Sync Packet. More...
void | XAvb_MasterSendFollowUp (XAvb *InstancePtr)
| A function to format then request the transmission of a PTP Follow-Up Packet. More...
void | XAvb_SendPDelayReq (XAvb *InstancePtr)
| A function to format then request the transmission of a PTP PDelay Request Packet. More...
void | XAvb_SendPDelayResp (XAvb *InstancePtr, u32 PtpFrameBaseAddr)
| A function to format then request the transmission of a PTP PDelay Response Packet. More...
void | XAvb_SendPDelayRespFollowUp (XAvb *InstancePtr)
| A function to format then request the transmission of a PTP PDelay Response Follow-Up Packet. More...
u32 | XAvb_IsRxFramePTP (XAvb *InstancePtr, u32 PtpFrameBaseAddr)
| A function to check that various fields in the received frame contain the expected values which define it as a valid AVB PTP frame. More...
void | XAvb_DecodeRxSync (XAvb *InstancePtr, u32 PtpFrameBaseAddr)
| A function to decode a received PTP Sync Packet. More...
void | XAvb_DecodeRxFollowUp (XAvb *InstancePtr, u32 PtpFrameBaseAddr)
| A function to decode a received PTP Follow-up Packet. More...
void | XAvb_DecodeRxPDelayResp (XAvb *InstancePtr, u32 PtpFrameBaseAddr)
| A function to decode a received PDelayResp Packet. More...
void | XAvb_DecodeRxPDelayRespFollowUp (XAvb *InstancePtr, u32 PtpFrameBaseAddr)
| A function to decode a received PDelayRespFollowUp Packet. More...
void | XAvb_DecodeRxSignaling (XAvb *InstancePtr, u32 PtpFrameBaseAddr)
| A function to decode a received Signalling Packet and modify the TX PTP Buffers based on the requested values. More...
u16 | XAvb_UpdateIntervalDuration (u16 currentIntervalDuration, char logMeanVal)
| A function to update a PTP message Interval Duration (defined as a fraction of 128 seconds). More...
u16 | XAvb_ConvertLogMeanToDuration (char logMeanVal)
| A function to convert a logMean (power of 2) value into a fraction of 128 that is compatible with Signalling data. More...
char | XAvb_ConvertDurationToLogMean (u16 fractionalVal)
| A function to convert a fraction of 128 value that is compatible with Signalling data into a logMean (power of 2) value;. More...
void | XAvb_UpdateLogMeanMessageInterval (u32 BaseAddress, u32 PtpFrameBaseAddr, u16 intervalDuration)
| A function to update the logMeanMessageInterval field in a PTP packet. More...
void | XAvb_SetupSourcePortIdentity (XAvb *InstancePtr, XAvb_PortIdentity systemIdentity)
| This function updates the portIdLocal local copy of the sourcePortIdentity and writes this value into the TX PTP frame buffer templates. More...

## Function Documentation

u32 XAvb_CompareClockIdentity | ( | u32 | BaseAddress,
|  | XAvb_ClockIdentity | Identity1,
|  | XAvb_ClockIdentity | Identity2
| ) |  |

A function to compare two ClockIdentity values.

Parameters

  BaseAddress | is the base address of the device
  Identity1 | is the first ClockIdentity to be compared
  Identity2 | is the second ClockIdentity to be compared

Returns
  1 if the two values are equal, 0 if not equal

Note

values are equal

References XAvb_ClockIdentity::ClockIdentityLower, and XAvb_ClockIdentity::ClockIdentityUpper.

Referenced by XAvb_DecodeRxAnnounceFrame().

u32 XAvb_ComparePortIdentity | ( | u32 | BaseAddress,
|  | XAvb_PortIdentity | Identity1,
|  | XAvb_PortIdentity | Identity2
| ) |  |

A function to compare two PortIdentity values.

Parameters

  BaseAddress | is the base address of the device
  Identity1 | is the first sourcePortIdentity to be compared
  Identity2 | is the second sourcePortIdentity to be compared

Returns
  1 if the two values are equal, 0 if not equal

Note
  None.

values are equal

References XAvb_PortIdentity::ClockIdentityLower, XAvb_PortIdentity::ClockIdentityUpper, and XAvb_PortIdentity::PortNumber.

Referenced by XAvb_DecodeRxAnnounceFrame(), XAvb_DecodeRxFollowUp(), XAvb_DecodeRxPDelayResp(), XAvb_DecodeRxPDelayRespFollowUp(), and XAvb_DecodeRxSync().

char XAvb_ConvertDurationToLogMean | ( | u16 | fractionalVal | ) |

A function to convert a fraction of 128 value that is compatible with Signalling data into a logMean (power of 2) value;.

Parameters

  fractionalVal | is the Signalling data value that is to be converted

Returns
  fractionalVal represented as logMean (power of 2) value

Note
  None.

just in case fractionalVal is not a power of 2, we'll only look at the most significant bit Count how many shifts it takes for most significant set bit to be in the highest (16th) bit location

logMeanVal = 0 = 2^0 = 128/128 would give us a numShifts result of 8, so 8 will be our base

Referenced by XAvb_UpdateLogMeanMessageInterval().

u16 XAvb_ConvertLogMeanToDuration | ( | char | logMeanVal | ) |

A function to convert a logMean (power of 2) value into a fraction of 128 that is compatible with Signalling data.

Parameters

  logMeanVal | is the base2 value that is to be converted

Returns
  logMeanVal represented as a fraction of 128

Note
  None.

Referenced by XAvb_DecodeRxAnnounceFrame(), XAvb_DecodeRxSync(), XAvb_Reset(), and XAvb_UpdateIntervalDuration().

void XAvb_DecodeRxFollowUp | ( | XAvb * | InstancePtr,
|  | u32 | PtpFrameBaseAddr
| ) |  |

A function to decode a received PTP Follow-up Packet.

Parameters

  InstancePtr | is a pointer to the XAvb instance to be worked on
  PtpFrameBaseAddr | is the base address of the received Announce Packet in the Rx PTP Packet Buffer

Returns
  None.

Note
  None.

Read sourcePortIdentity from packet

Only decode if configured for a slave and if SA is that of the RTC Clock Master

Capture the Follow Up SequenceID

SequenceID in Follow Up Frame should always match that of the Sync Frame

Capture the correction field from follow up frame

Perform the Course RTC Offset correction for every Sync / FollowUp pair

Every n Sync / FollowUp pairs, we are going to calculate a corrected increment rate of RTC

Reset the CounterSyncEvents Counter

Capture the Sequence ID of the Follow Up frame

Perform the RTC increment rate adjustment calculation

Sample Sync Frame Time sent (as estimated by the slave) for comparison in ten more repetition's time

Sample Sync Frame Time sent (as calculated by the master) for comparison in ten more repetition's time

Sample the current Follow Up Sequence ID for comparison in ten more repetition's time

References XAvb_Config::BaseAddress, XAvb::Config, XAvb_Counters::CounterSyncEvents, XAvb::CurrentBmc, XAvb_SequenceIdStruct::FollowUpSequenceId, XAvb_BmcData::IAmTheRtcMaster, XAvb_PtpStruct::MasterCorrectionField, XAvb_PtpStruct::NewMasterTime, XAvb_PtpStruct::NewSlaveTime, XAvb_SequenceIdStruct::NewSyncSequenceId, XAvb_PtpStruct::OldMasterTime, XAvb_PtpStruct::OldSlaveTime, XAvb_SequenceIdStruct::OldSyncSequenceId, XAvb::PtpCounters, XAvb::PtpRecords, XAvb::SequenceIdRecords, XAvb_BmcData::SourcePortIdentity, XAvb_SequenceIdStruct::SyncSequenceId, XAvb_CalcRtcOffset(), XAvb_ComparePortIdentity(), XAvb_GetPortIdentity(), XAvb_ReadPtpBuffer, XAvb_ReorderWord(), and XAvb_UpdateRtcIncrement().

Referenced by XAvb_PtpRxInterruptHandler().

void XAvb_DecodeRxPDelayResp | ( | XAvb * | InstancePtr,
|  | u32 | PtpFrameBaseAddr
| ) |  |

A function to decode a received PDelayResp Packet.

Parameters

  InstancePtr | is a pointer to the XAvb instance to be worked on
  PtpFrameBaseAddr | is the base address of the received Announce Packet in the Rx PTP Packet Buffer

Returns
  None.

Note
  None.

Have we already seen a PDelayResp since the last PDelayReq was sent? If so, ignore the packet

Find the ClockIdentity of the Sender

Is the PDelayResp message from ourself? If so, the Peer is most likely a dumb hub and should be considered not ASCapable

Capture the requestingPortIdentity

Capture the PDelayResp SequenceID

Verify that the requestingPortIdentity matches our portIdentity

Only process if the received frame's sequenceId matches the sequenceId sent in the last pDelay_Req packet

Mark this as a valid PDelayResp packet

Capture timestamp for receipt time of PDelayReq at Master (t2)

Capture timestamp for receipt time of PDelayResp at Slave (t4) and adjust it for MAC receive latency

References XAvb_Config::BaseAddress, XAvb::Config, XAvb_SequenceIdStruct::PDelayReqSequenceId, XAvb_SequenceIdStruct::PDelayRespSequenceId, XAvb_PtpStruct::PDelayTimestampT2, XAvb_PtpStruct::PDelayTimestampT4, XAvb::portIdLocal, XAvb::PtpRecords, XAvb_StateMachineData::rcvdPDelayResp, XAvb_StateMachineData::respPortIdentity, XAvb_StateMachineData::respReqPortIdentity, XAvb::SequenceIdRecords, XAvb::StateMachineData, XAvb_CaptureNanoSec(), XAvb_ChangePeerASCapability(), XAvb_ComparePortIdentity(), XAvb_GetPortIdentity(), XAvb_ReadPtpBuffer, and XAvb_ReorderWord().

Referenced by XAvb_PtpRxInterruptHandler().

void XAvb_DecodeRxPDelayRespFollowUp | ( | XAvb * | InstancePtr,
|  | u32 | PtpFrameBaseAddr
| ) |  |

A function to decode a received PDelayRespFollowUp Packet.

Parameters

  InstancePtr | is a pointer to the XAvb instance to be worked on
  PtpFrameBaseAddr | is the base address of the received Announce Packet in the Rx PTP Packet Buffer

Returns
  None.

Note
  None.

Has a valid PDelayResp packet been received since the last PDelayReq packet was sent?

Capture the PDelayRespFollowUp SequenceID

Get the sourcePortIdentity of the sender

The sourcePortIdentity of the PDelayRespFollowUp should match that of the last PDelayResp packet received

Get the requestingPortIdentity of the sender

The requestingPortIdentity of the PDelayRespFollowUp should match that of the last PDelayResp packet received

SequenceID of PDelayRespFollowUp Frame should always match that of the PDelayResp Frame and the original PDelayReq Frame.

Mark this as a valid PDelayRespFollowUp packet

Capture the timestamp for transmit time of PDelayResp at Master (t3)

Now we know t1, t2, t3 and t4, calculate the link delay

References XAvb_Config::BaseAddress, XAvb::Config, XAvb_SequenceIdStruct::PDelayFollowUpSequenceId, XAvb_SequenceIdStruct::PDelayRespSequenceId, XAvb_PtpStruct::PDelayTimestampT3, XAvb::PtpRecords, XAvb_StateMachineData::rcvdPDelayResp, XAvb_StateMachineData::rcvdPDelayRespFollowUp, XAvb_StateMachineData::respPortIdentity, XAvb_StateMachineData::respReqPortIdentity, XAvb::SequenceIdRecords, XAvb::StateMachineData, XAvb_CalcDelay(), XAvb_CaptureNanoSec(), XAvb_ComparePortIdentity(), XAvb_GetPortIdentity(), XAvb_ReadPtpBuffer, and XAvb_ReorderWord().

Referenced by XAvb_PtpRxInterruptHandler().

void XAvb_DecodeRxSignaling | ( | XAvb * | InstancePtr,
|  | u32 | PtpFrameBaseAddr
| ) |  |

A function to decode a received Signalling Packet and modify the TX PTP Buffers based on the requested values.

Parameters

  InstancePtr | is a pointer to the XAvb instance to be worked on
  PtpFrameBaseAddr | is the base address of the received Signaling Packet in the Rx PTP Packet Buffer

Returns
  None.

Note
  None.

Read the requested logMeanMessage durations from the Signalling frame

update linkDelayInterval

don't change the interval

currently only support the default value

set the interval to initial value

Update logMeanMessageInterval in the pre-loaded TX PDELAYREQ message buffer

stop sending pDelay messages

update timeSyncInterval

don't change the interval

set the interval to initial value

Update logMeanMessageInterval in the pre-loaded TX SYNC message buffer

Update logMeanMessageInterval in the pre-loaded TX FOLLOW_UP message buffer

stop sending sync messages

update announceInterval

don't change the interval

set the interval to initial value

Update logMeanMessageInterval in the pre-loaded TX ANNOUNCE message buffer

stop sending Announce messages

References XAvb_SignallingFrameData::AnnounceIntervalDuration, XAvb_Config::BaseAddress, XAvb::Config, XAvb_SignallingFrameData::LinkDelayIntervalDuration, XAvb::SignallingFrameData, XAvb_SignallingFrameData::SyncIntervalDuration, XAvb_ReadPtpBuffer, XAvb_ReorderWord(), XAvb_UpdateIntervalDuration(), and XAvb_UpdateLogMeanMessageInterval().

Referenced by XAvb_PtpRxInterruptHandler().

void XAvb_DecodeRxSync | ( | XAvb * | InstancePtr,
|  | u32 | PtpFrameBaseAddr
| ) |  |

A function to decode a received PTP Sync Packet.

Parameters

  InstancePtr | is a pointer to the XAvb instance to be worked on
  PtpFrameBaseAddr | is the base address of the received Announce Packet in the Rx PTP Packet Buffer

Returns
  None.

Note
  None.

Read sourcePortIdentity from packet

Only decode if configured for a slave and if SourcePortID is that of the RTC Clock Master

Reset Sync Interval Counter as we have received a valid Sync

Capture the local Timestamp for receipt of this frame and adjust it for MAC receive latency

Capture the Sync SequenceID

Capture the logMeanMessageInterval and convert into a useful duration (NOTE: there is an implicit conversion from u32 to char here)

We don't need to capture the correction field - unless we want to check that it is 0.

References XAvb_Config::BaseAddress, XAvb_PortIdentity::ClockIdentityLower, XAvb_PortIdentity::ClockIdentityUpper, XAvb::Config, XAvb_Counters::CounterSyncInterval, XAvb::CurrentBmc, XAvb_BmcData::IAmTheRtcMaster, XAvb::latestMDSyncReceive, XAvb_MDSyncReceive::logMessageInterval, XAvb_PortIdentity::PortNumber, XAvb::PtpCounters, XAvb::PtpRecords, XAvb::SequenceIdRecords, XAvb_PtpStruct::SlaveSyncTimestamp, XAvb_BmcData::SourcePortIdentity, XAvb_MDSyncReceive::SyncIntervalDuration, XAvb_SequenceIdStruct::SyncSequenceId, XAvb_ComparePortIdentity(), XAvb_ConvertLogMeanToDuration(), XAvb_GetPortIdentity(), XAvb_ReadPtpBuffer, and XAvb_ReorderWord().

Referenced by XAvb_PtpRxInterruptHandler().

void XAvb_GetPortIdentity | ( | u32 | BaseAddress,
|  | u32 | PtpFrameBaseAddr,
|  | u32 | PortIdOffset,
|  | XAvb_PortIdentity * | portID
| ) |  |

A function to extract portIdentity information from a received PTP frame.

This can be any portIdentity field (header portIdentity, requestingPortIdentity, etc.)

Parameters

  BaseAddress | is the base address of the device
  PtpFrameBaseAddr | is the base address of the received Announce Packet in the Rx PTP Packet Buffer
  PortIdOffset | is the packet offset of the first byte of the portIdentity field to be parsed
  portID | is the XAvb_PortIdentity struct that the data will be written to.

Returns
  None, but portID will be updated with the portIdentity information

Note
  None.

References XAvb_PortIdentity::ClockIdentityLower, XAvb_PortIdentity::ClockIdentityUpper, XAvb_PortIdentity::PortNumber, XAvb_ReadPtpBuffer, and XAvb_ReorderWord().

Referenced by XAvb_DecodeRxFollowUp(), XAvb_DecodeRxPDelayResp(), XAvb_DecodeRxPDelayRespFollowUp(), XAvb_DecodeRxSync(), and XAvb_ReadAnnounceFrame().

u32 XAvb_IncSequenceId | ( | u32 | BaseAddress,
|  | u32 | PtpFrameBaseAddress
| ) |  |

A function to increment the sequenceId in a PTP frame template.

Parameters

  BaseAddress | is the base address of the device
  PtpFrameBaseAddress | is the base address of the TX PTP Buffer whose SequenceID is to be incremented

Returns
  None. But the relevant TX PTP Packet Buffer is written to with the updated SequenceID

Note
  None.

Read the 32-bit BufferWord containing the SequenceId from the PTP buffer

Swap byte order into correct binary and increment the SequenceId

Swap back the byte order into frame storage order

Write the 32-bit BufferWord variable containing the updated SequenceId

References XAvb_ReadPtpBuffer, XAvb_ReorderWord(), and XAvb_WritePtpBuffer.

Referenced by XAvb_MasterSendAnnounce(), XAvb_MasterSendSync(), and XAvb_SendPDelayReq().

u32 XAvb_IsRxFramePTP | ( | XAvb * | InstancePtr,
|  | u32 | PtpFrameBaseAddr
| ) |  |

A function to check that various fields in the received frame contain the expected values which define it as a valid AVB PTP frame.

If this check does not pass then the frame should not be decoded and used.

Parameters

  InstancePtr | is a pointer to the XAvb instance to be worked on
  PtpFrameBaseAddr | is the base address of the received Announce Packet in the Rx PTP Packet Buffer

Returns
  An updated True/False decision as to whether this received frame really is a valid PTP type.

Note
  None.

Start by assuming that it is a valid PTP frame

Perform a 32-bit read from the relevant position in the frame

Check the Length/Type field for a valid Ethertype

Check the versionPTP

References XAvb_Config::BaseAddress, XAvb::Config, XAvb_ReadPtpBuffer, and XAvb_ReorderWord().

Referenced by XAvb_PtpRxInterruptHandler().

void XAvb_MasterSendAnnounce | ( | XAvb * | InstancePtr | ) |

A function to format then request the transmission of a PTP Announce Packet.

Parameters

  InstancePtr | is a pointer to the XAvb instance to be worked on

Returns
  None. But the relevant Tx PTP Packet Buffer is written to with the updated PTP fields, and then the Tx PTP Packet Buffer Control Register is written to request the frame transmission.

Note
  None.

Wait until there are no PTP frames to be transmitted

Increment the sequenceId

Send the Announce Frame!

References XAvb_Config::BaseAddress, XAvb::Config, XAvb_IncSequenceId(), XAVB_PTP_TX_CONTROL_OFFSET, XAvb_ReadReg, XAVB_RTC_NANOSEC_VALUE_OFFSET, XAVB_RTC_SEC_LOWER_VALUE_OFFSET, XAvb_WaitOnTxPtpQueue(), and XAvb_WriteReg.

Referenced by XAvb_PtpTimerInterruptHandler().

void XAvb_MasterSendFollowUp | ( | XAvb * | InstancePtr | ) |

A function to format then request the transmission of a PTP Follow-Up Packet.

Parameters

  InstancePtr | is a pointer to the XAvb instance to be worked on

Returns
  None. But the relevant Tx PTP Packet Buffer is written to with the updated PTP fields, and then the Tx PTP Packet Buffer Control Register is written to request the frame transmission.

Note
  None.

Wait until there are no PTP frames to be transmitted

Read the current RTC offset

Read the Timestamp and adjust it for the MAC transmit latency

Adjust the Timestamp with current RTC ns offset

Calculate the Correction Field

Format the Correction Field into correct byte positioning for PTP frame storage in the buffer

Write the Correction Field to the Follow Up frame

Send the Follow Up Frame!

References XAvb_Config::BaseAddress, XAvb::Config, XAvb_PtpStruct::Nanosec, XAvb::PtpRecords, XAVB_ONE_SECOND, XAVB_PTP_TX_CONTROL_OFFSET, XAvb_ReadPtpBuffer, XAvb_ReadReg, XAvb_ReorderWord(), XAVB_RTC_NANOSEC_OFFSET, XAvb_WaitOnTxPtpQueue(), XAvb_WritePtpBuffer, and XAvb_WriteReg.

Referenced by XAvb_PtpTimerInterruptHandler().

void XAvb_MasterSendSync | ( | XAvb * | InstancePtr | ) |

A function to format then request the transmission of a PTP Sync Packet.

Parameters

  InstancePtr | is a pointer to the XAvb instance to be worked on

Returns
  None. But the relevant Tx PTP Packet Buffer is written to with the updated PTP fields, and then the Tx PTP Packet Buffer Control Register is written to request the frame transmission.

Note
  None.

Wait until there are no PTP frames to be transmitted

Increment the sequenceId in the Sync frame

Read the current RTC Offset values

Send the Sync Frame!

## Now some pre-work on the Follow-Up Frame

Write the same sequenceId to the Follow-up frame

Format the Timestamp (RTC) into correct byte positioning. Note: this is how the Timestamp is stored in the PTP frame itself (transmitted MSB of Epoch first):

|----------——|----------——|----------——|----------——|

seconds[23:16] | seconds[31:24] | epoch[7:0] | epoch[15:8]
--- | --- | --- | ---
nanosec[23:16] | nanosec[31:24] | seconds[7:0] | seconds[15:8]
----------—— | ----------—— | ----------—— | ----------——
0's | 0's | nanosec[7:0] | nanosec[15:8]
----------—— | ----------—— | ----------—— | ----------——

Write the Timestamp (RTC) to the Follow-up frame

References XAvb_Config::BaseAddress, XAvb::Config, XAvb_PtpStruct::Nanosec, XAvb::PtpRecords, XAvb_IncSequenceId(), XAVB_PTP_TX_CONTROL_OFFSET, XAvb_ReadPtpBuffer, XAvb_ReadReg, XAvb_ReorderWord(), XAVB_RTC_NANOSEC_VALUE_OFFSET, XAVB_RTC_SEC_LOWER_VALUE_OFFSET, XAVB_RTC_SEC_UPPER_VALUE_OFFSET, XAvb_WaitOnTxPtpQueue(), XAvb_WritePtpBuffer, and XAvb_WriteReg.

Referenced by XAvb_PtpTimerInterruptHandler().

u32 XAvb_ReorderWord | ( | u32 | Data | ) |

This function switches the bytes in a 4-byte word, swapping the MSB for the LSB, and vice-versa.

Parameters

  Data | is the 4-byte input data word

Returns
  The input data word with the bytes swapped (most significant down to least significant

Note
  None.

Referenced by main(), XAvb_CalcRtcOffset(), XAvb_CaptureNanoSec(), XAvb_DecodeRxFollowUp(), XAvb_DecodeRxPDelayResp(), XAvb_DecodeRxPDelayRespFollowUp(), XAvb_DecodeRxSignaling(), XAvb_DecodeRxSync(), XAvb_GetPortIdentity(), XAvb_IncSequenceId(), XAvb_IsRxFramePTP(), XAvb_MasterSendFollowUp(), XAvb_MasterSendSync(), XAvb_ReadAnnounceFrame(), XAvb_ReadAnnounceReceiptTimeout(), XAvb_SendPDelayReq(), XAvb_SendPDelayResp(), XAvb_SendPDelayRespFollowUp(), and XAvb_SetupSourcePortIdentity().

void XAvb_SendPDelayReq | ( | XAvb * | InstancePtr | ) |

A function to format then request the transmission of a PTP PDelay Request Packet.

Parameters

  InstancePtr | is a pointer to the XAvb instance to be worked on

Returns
  None. But the relevant Tx PTP Packet Buffer is written to with the updated PTP fields, and then the Tx PTP Packet Buffer Control Register is written to request the frame transmission.

Note
  None.

Wait until there are no PTP frames to be transmitted

Increment the SequenceId

Send the PDelayReq Frame!

Wait for the frame to be transmitted

Capture the Timestamp for Tx of PDelayReq (t1) and adjust it for MAC transmit latency

Capture the SequenceID of the the PDelayReq

References XAvb_Config::BaseAddress, XAvb::Config, XAvb_SequenceIdStruct::PDelayReqSequenceId, XAvb_PtpStruct::PDelayTimestampT1, XAvb::PtpRecords, XAvb::SequenceIdRecords, XAvb_IncSequenceId(), XAVB_PTP_TX_CONTROL_OFFSET, XAvb_ReadPtpBuffer, XAvb_ReorderWord(), XAvb_WaitOnTxPtpQueue(), and XAvb_WriteReg.

Referenced by XAvb_PtpTimerInterruptHandler().

void XAvb_SendPDelayResp | ( | XAvb * | InstancePtr,
|  | u32 | PtpFrameBaseAddr
| ) |  |

A function to format then request the transmission of a PTP PDelay Response Packet.

Parameters

  InstancePtr | is a pointer to the XAvb instance to be worked on
  PtpFrameBaseAddr | is the base address of the received Announce Packet in the Rx PTP Packet Buffer

Returns
  None. But the relevant Tx PTP Packet Buffer is written to with the updated PTP fields, and then the Tx PTP Packet Buffer Control Register is written to request the frame transmission.

Note
  None.

Wait until there are no PTP frames to be transmitted

## Format the Timestamp

Capture the current Synchronised time

Read the current RTC offset

Read the TimestampT2 for PDelayReq reception and adjust it for MAC receive latency

The TimestampT2 was captured using syntonised ns time. We need to convert this into synchronised time by adding on the current offset

Check for ns wrap-around condition

Even though we read the RTC value at the beginning of this function, there would have been processing delay between the actual reception (and timestamping) of the PDelayReq frame and the start of this function. During this time, the RTC Seconds field could have wrapped around. We need to detect this and if it has done, the slave Seconds field would also have incremented (so it needs to be set back).

NanoSec has wrapped since timestamp was taken so decrement the Seconds field

Format the Timestamp (t2) into correct byte positioning for PTP frame storage, then write the Timestamp (t2) to the PDelayResp frame

## Format the SequenceId

Set the SequenceId in the PDelayResp and PDelayRespFollowUp frame to be that of the received PDelayReq frame

## Format the sourcePortIdentity

Copy the sourcePortIdentity field from the PDelayReq into the PDelayResp and PDelayRespFollowUp frame

## Send the PDelayResp Frame!

References XAvb_Config::BaseAddress, XAvb::Config, XAvb_PtpStruct::NsOffsetForPDelayResp, XAvb::PtpRecords, XAVB_ONE_SECOND, XAVB_PTP_TX_CONTROL_OFFSET, XAvb_ReadPtpBuffer, XAvb_ReadReg, XAvb_ReorderWord(), XAVB_RTC_NANOSEC_OFFSET, XAVB_RTC_NANOSEC_VALUE_OFFSET, XAVB_RTC_SEC_LOWER_VALUE_OFFSET, XAVB_RTC_SEC_UPPER_VALUE_OFFSET, XAvb_WaitOnTxPtpQueue(), XAvb_WritePtpBuffer, and XAvb_WriteReg.

Referenced by XAvb_PtpRxInterruptHandler().

void XAvb_SendPDelayRespFollowUp | ( | XAvb * | InstancePtr | ) |

A function to format then request the transmission of a PTP PDelay Response Follow-Up Packet.

Parameters

  InstancePtr | is a pointer to the XAvb instance to be worked on

Returns
  None. But the relevant Tx PTP Packet Buffer is written to with the updated PTP fields, and then the Tx PTP Packet Buffer Control Register is written to request the frame transmission.

Note
  None.

Wait until there are no PTP frames to be transmitted

## Format the Timestamp

Capture the current Synchronised time

Read the TimestampT3 for PDelayResp transmission and adjust it for MAC transmit latency

The TimestampT3 was captured using syntonised ns time. We need to convert this into synchronised time by adding on the ns offset. We use the same offset here as for the PDelayResp frame since if a ns offset change had been made between PDelayResp and , PDelayRespFollowUp, this would result in an error in the link delay measurement.

Check for ns wrap-around condition

Even though we read the RTC value at the beginning of this function, there would have been processing delay between the actual reception (and timestamping) of the PDelayReq frame and the start of this function. During this time, the RTC seconds field could have wrapped around. We need to detect this and if it has done, the slave seconds field would also have incremented (so it needs to be set back).

nanosec has wrapped since timestamp was taken so decrement the seconds field

Format the Timestamp (t3) into correct byte positioning for PTP frame storage, the write the Timestamp (t3) to the PDelayRespFollowUp frame

## Send the PDelayRespFollowUp Frame!

References XAvb_Config::BaseAddress, XAvb::Config, XAvb_RtcFormat::NanoSeconds, XAvb_PtpStruct::NsOffsetForPDelayResp, XAvb::PtpRecords, XAvb_RtcFormat::SecondsLower, XAvb_RtcFormat::SecondsUpper, XAVB_ONE_SECOND, XAVB_PTP_TX_CONTROL_OFFSET, XAvb_ReadPtpBuffer, XAvb_ReadRtc(), XAvb_ReorderWord(), XAvb_WaitOnTxPtpQueue(), XAvb_WritePtpBuffer, and XAvb_WriteReg.

Referenced by XAvb_PtpRxInterruptHandler().

void XAvb_SetupSourcePortIdentity | ( | XAvb * | InstancePtr,
|  | XAvb_PortIdentity | systemIdentity
| ) |  |

This function updates the portIdLocal local copy of the sourcePortIdentity and writes this value into the TX PTP frame buffer templates.

The fields that are written are: o sourcePortIdentity for all default PTP frames o Announce:: grandmasterIdentity o Announce:: TLV clockIdentity

Parameters

  InstancePtr | is a pointer to the XAvb instance to be worked on
  systemIdentity | is the clockIdentity and portNumber for this endpoint

Returns
  None.

Note
  Announce::TLV. By default the tlvType and length field are set up in the BRAM, assuming that N = 1.

Write the sourcePortIdentity into the header for all TX PTP buffers except the empty default buffer AND write the GMID for TX announce AND Write the ClockIdentity into the TX Announce TLV

(a) Write the upper 2 bytes of the ClockIdentityUpper

- REM: Swap back the byte order into frame storage order

(b) Write the lower 2 bytes of the ClockIdentityUpper and upper 2 bytes of the ClockIdentityLower.

- REM: Swap back the byte order into frame storage order

(c) Write the lower 2 bytes of the ClockIdentityLower and the portNumber

- REM: Swap back the byte order into frame storage order

Write the grandmasterIdentity into the header for the TX Announce PTP buffer

(a) Write 1 byte of GMID (Upper)

(b) Write 3 bytes of GMID (Upper) and 1 byte of GMID (Lower)

(c) Write 3 bytes of GMID (Lower)

References XAvb_Config::BaseAddress, XAvb_PortIdentity::ClockIdentityLower, XAvb_PortIdentity::ClockIdentityUpper, XAvb::Config, XAvb::portIdLocal, XAvb_PortIdentity::PortNumber, XAvb_ReadPtpBuffer, XAvb_ReorderWord(), XAvb_WritePtpBuffer, and XAvb_WriteToMultipleTxPtpFrames().

Referenced by main().

u16 XAvb_UpdateIntervalDuration | ( | u16 | currentIntervalDuration,
|  | char | logMeanVal
| ) |  |

A function to update a PTP message Interval Duration (defined as a fraction of 128 seconds).

If the endpoint cannot support a requested logMeanVal then do not perform the conversion - return the current value.

Parameters

  currentIntervalDuration | is the Interval Duration to be updated
  logMeanVal | is the base2 value that is to be converted

Returns
  logMeanVal represented as a fraction of 128

Note
  This endpoint only supports logMeanValues >=-7 and <=8.

References XAvb_ConvertLogMeanToDuration().

Referenced by XAvb_DecodeRxSignaling().

void XAvb_UpdateLogMeanMessageInterval | ( | u32 | BaseAddress,
|  | u32 | PtpFrameBaseAddr,
|  | u16 | intervalDuration
| ) |  |

A function to update the logMeanMessageInterval field in a PTP packet.

Parameters

  BaseAddress | is the base address of the device
  PtpFrameBaseAddr | is the base address of the TX PTP Buffer to be updated
  intervalDuration | is the "fraction of 128" value of the data to be written

Returns
  None. But the relevant Tx PTP Packet Buffer is written to with the updated logMeanMessageInterval

Note
  None.

Convert intervalDuration to a logMean value

Read the current fields

Update just the logMeanMessageInterval field

Write back

References XAvb_ConvertDurationToLogMean(), XAvb_ReadPtpBuffer, and XAvb_WritePtpBuffer.

Referenced by XAvb_DecodeRxSignaling(), and XAvb_Reset().

void XAvb_WaitOnTxPtpQueue | ( | XAvb * | InstancePtr | ) |

The software drivers are kept simple by only requesting a single PTP frame to be transmitted at a time.

This function checks (and if necessary waits) until the previously request PTP frame has been transmitted.

Parameters

  InstancePtr | is a pointer to the XAvb instance to be worked on

Returns
  None.

Note
  None.

Wait until any queued PTP frame has been transmitted. This is a software safety feature, not a hardware restriction

References XAvb_Config::BaseAddress, XAvb::Config, XAVB_PTP_TX_CONTROL_OFFSET, and XAvb_ReadReg.

Referenced by XAvb_MasterSendAnnounce(), XAvb_MasterSendFollowUp(), XAvb_MasterSendSync(), XAvb_SendPDelayReq(), XAvb_SendPDelayResp(), and XAvb_SendPDelayRespFollowUp().

void XAvb_WriteToMultipleTxPtpFrames | ( | u32 | BaseAddress,
|  | u32 | PtpFieldAddress,
|  | u32 | Data,
|  | u32 | DataBitEnable,
|  | u8 | BufferEnable
| ) |  |

A function to write common data (eg the Source Address) to all PTP frames stored in the Tx PTP Packet buffer.

Parameters

  BaseAddress | is the base address of the device
  PtpFieldAddress | is the offset address of the relevant field in PTP frames.
  Data | is the common data to be written to all Tx PTP frame templates
  DataBitEnable | allows only selected bits of the 32-bit Data word to be modified.
  BufferEnable | allows the selected buffer to be selected: there are 8 PTP buffers - these are encoded as one-hot. For example, 0x3F will write the selected data to the first 6 buffers only.

Returns
  None. But the Tx PTP Packet Buffer is written to as requested

Note
  None.

Write to all 8 PTP frame templates

Only write to selected buffers

Read the current value

Only change the selected data bits

Write the updated value

References XAvb_ReadPtpBuffer, and XAvb_WritePtpBuffer.

Referenced by main(), and XAvb_SetupSourcePortIdentity().