| axiethernet Vitis Drivers API Documentation

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

Data Structures | Typedefs | Functions
xavb.h File Reference

## Overview

This header file contains the identifiers and basic driver functions (or macros) that can be used to access the device.

Other driver functions are defined in xavb.h.

    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.
    4_0     asa  03/06/14 Fix for CR 740863. The value of XAVB_CLOCK_LOCK_THRESHOLD
                                      is increased to 1000ns (1 us) to make it more
                                      meningful and reasonable.

## Data Structures
struct | XAvb_Config
| This typedef contains configuration information for a device. More...
struct | XAvb_PortIdentity
| This typedef defines the format for a data structure which stores the Port Identity information from received Announce packets. More...
struct | XAvb_ClockIdentity
| This typedef defines the format for a data structure which stores the Clock Identity information from received Announce packets. More...
struct | XAvb_ClockQuality
| This typedef defines the quality of a clock. More...
struct | XAvb_BmcData
| This typedef defines the format for a data structure which stores the relevant fields which are captured from Announce Packets. More...
struct | XAvb_PtpStruct
| This typedef defines the format for a data structure which stores information relating to the 1588 based PTP timing calculations. More...
struct | XAvb_SequenceIdStruct
| This typedef defines the format for a data structure which stores the last used sequence ID for all of the PTP timing frames. More...
struct | XAvb_SignallingFrameData
| The Signalling frame defines the delays to be used between Sync Frames, Link Delay measurements and Announce Frame events. More...
struct | XAvb_Counters
| This typedef defines the various counters which have to maintained for the PTP operation. More...
struct | XAvb_StateMachineData
| Keep track of state machine data to make sure we're fully compliant with the spec. More...
struct | XAvb_MDSyncReceive
| This struct captures information from RX'd Sync/FollowUp message pairs in a format similar to the MDSyncReceive structure described in the IEEE P802.1AS specification. More...
struct | XAvb
| The XAvb driver instance data. More...

## Macros
MAC Latency Definitions
#define | XAVB_TX_MAC_LATENCY_IN_NS 80
#define | XAVB_RX_MAC_LATENCY_IN_NS 80
PTP Buffer Storage Definitions
#define | XAVB_PTP_TX_SYNC 0x0
#define | XAVB_PTP_TX_FOLLOW_UP 0x1
#define | XAVB_PTP_TX_PDELAYREQ 0x2
#define | XAVB_PTP_TX_PDELAYRESP 0x3
#define | XAVB_PTP_TX_PDELAYRESP_FOLLOW_UP 0x4
#define | XAVB_PTP_TX_ANNOUNCE 0x5
#define | XAVB_PTP_TX_SIGNALING 0x6
PTP Packet Message Type Definitions
#define | XAVB_PTP_TYPE_SYNC 0x0
#define | XAVB_PTP_TYPE_FOLLOW_UP 0x8
#define | XAVB_PTP_TYPE_PDELAYREQ 0x2
#define | XAVB_PTP_TYPE_PDELAYRESP 0x3
#define | XAVB_PTP_TYPE_PDELAYRESP_FOLLOW_UP 0xA
#define | XAVB_PTP_TYPE_ANNOUNCE 0xB
#define | XAVB_PTP_TYPE_SIGNALING 0xC
Common PTP Frame Structure Definitions.
#define | XAVB_PTP_PKT_CAPTURED_TIMESTAMP_OFFSET 0x000000FC
General Tx PTP Frame Structure Definitions.
#define | XAVB_PTP_TX_PKT_SA_UPPER_OFFSET 0x0000000C
#define | XAVB_PTP_TX_PKT_SA_LOWER_OFFSET 0x00000010
#define | XAVB_PTP_TX_PKT_TYPE_OFFSET 0x00000014
#define | XAVB_PTP_TX_PKT_CORRECTION_FIELD_OFFSET 0x00000020
#define | XAVB_PTP_TX_PKT_PORTID_UPPER_OFFSET 0x00000028
#define | XAVB_PTP_TX_PKT_PORTID_MID_OFFSET 0x0000002C
#define | XAVB_PTP_TX_PKT_PORTID_LOWER_OFFSET 0x00000030
#define | XAVB_PTP_TX_PKT_SEQUENCEID_OFFSET 0x00000034
#define | XAVB_PTP_TX_PKT_TIMESTAMP_UPPER_OFFSET 0x00000038
#define | XAVB_PTP_TX_PKT_TIMESTAMP_MID_OFFSET 0x0000003C
#define | XAVB_PTP_TX_PKT_TIMESTAMP_LOWER_OFFSET 0x00000040 /* upper 2 bytes */
#define | XAVB_PTP_TX_PKT_REQ_PORTID_UPPER_OFFSET 0x00000040 /* lower 2 bytes */
#define | XAVB_PTP_TX_PKT_REQ_PORTID_MID_OFFSET 0x00000044
#define | XAVB_PTP_TX_PKT_REQ_PORTID_LOWER_OFFSET 0x00000048
Tx Announce PTP Frame Structure Definitions.
#define | XAVB_PTP_TX_PKT_ANNOUNCE_CURR_UTCOFF_OFFSET 0x00000040
#define | XAVB_PTP_TX_PKT_ANNOUNCE_QUAL_LOW_PRI2_GMID_HI_OFFSET 0x00000048
#define | XAVB_PTP_TX_PKT_ANNOUNCE_GMID_MID_OFFSET 0x0000004C
#define | XAVB_PTP_TX_PKT_ANNOUNCE_GMID_LOW_STEPSREMOVED_HI_OFFSET 0x00000050
#define | XAVB_PTP_TX_PKT_ANNOUNCE_STEPSREMOVED_LOW_TIMESRC_OFFSET 0x00000054
#define | XAVB_PTP_TX_PKT_ANNOUNCE_TLVLEN_PATHSEQ_START_OFFSET 0x00000058
PTP frame constant definitions
Constant value for the control field and LogMeanMessageInterval field for pDelayResp and pDelayRespFollowUp PTP frames (defined in IEEE802.1 AS)
#define | XAVB_PDELAY_LOG_MEAN_MESSAGE_INT 0x7F050000
Default LogMeanInterval values
#define | XAVB_DEFAULT_LOG_MEAN_SYNC_INTERVAL (-3) /** 2^(-3) = 125ms */
#define | XAVB_DEFAULT_LOG_MEAN_PDELAY_REQ_INTERVAL 0 /** 128/128 = 2^(0) = 1 s */
#define | XAVB_DEFAULT_LOG_MEAN_ANNOUNCE_INTERVAL 0 /** 128/128 = 2^(0) = 1 s */
#define | XAVB_PKT_TYPE_DISABLED 0xffff
#define | XAVB_MAX_SUPPORTED_LOG_MEAN_INTERVAL 8 /** 32768/128 = 256 s */
#define | XAVB_MIN_SUPPORTED_LOG_MEAN_INTERVAL (-7) /** 1/128 s */
Announce / Sync Timeout values
#define | XAVB_ANNOUNCE_RECEIPT_TIMEOUT 2
| XAVB_ANNOUNCE_RECEIPT_TIMEOUT is the number of announce intervals without the receipt of an Announce message from the GM that are allowed before the GM is assumed to be no longer present and BMCA should be run again. More...
#define | XAVB_SYNC_RECEIPT_TIMEOUT 3
| XAVB_SYNC_RECEIPT_TIMEOUT is the number of sync intervals without the receipt of an Sync message from the GM that are allowed before the GM is assumed to be no longer present and BMCA should be run again. More...
AS Network Requirements
#define | XAVB_NEIGHBOR_PROP_DELAY_THRESH 5000
| XAVB_NEIGHBOR_PROP_DELAY_THRESH is the maximum allowed delay (in nanosecs) across a full duplex link for which the AVB protocol is allowed to function. More...
#define | XAVB_ALLOWED_LOST_RESPONSES 3
| XAVB_ALLOWED_LOST_RESPONSES is the number of Pdelay_Req messages for which a valid response is not received, above which the Peer should no longer be considered ASCapable. More...
General Rx PTP Frame Structure Definitions.
#define | XAVB_PTP_RX_PKT_SA_UPPER_OFFSET 0x00000004
#define | XAVB_PTP_RX_PKT_SA_LOWER_OFFSET 0x00000008
#define | XAVB_PTP_RX_PKT_TYPE_OFFSET 0x0000000C
#define | XAVB_PTP_RX_PKT_CORRECTION_FIELD_OFFSET 0x00000018
#define | XAVB_PTP_RX_PKT_PORTID_UPPER_OFFSET 0x00000020
#define | XAVB_PTP_RX_PKT_PORTID_MID_OFFSET 0x00000024
#define | XAVB_PTP_RX_PKT_PORTID_LOWER_OFFSET 0x00000028
#define | XAVB_PTP_RX_PKT_SEQUENCEID_OFFSET 0x0000002C
#define | XAVB_PTP_RX_PKT_TIMESTAMP_UPPER_OFFSET 0x00000030
#define | XAVB_PTP_RX_PKT_TIMESTAMP_MID_OFFSET 0x00000034
#define | XAVB_PTP_RX_PKT_TIMESTAMP_LOWER_OFFSET 0x00000038 /* upper 2 bytes */
#define | XAVB_PTP_RX_PKT_REQ_PORTID_UPPER_OFFSET 0x00000038 /* lower 2 bytes */
#define | XAVB_PTP_RX_PKT_REQ_PORTID_MID_OFFSET 0x0000003C
#define | XAVB_PTP_RX_PKT_REQ_PORTID_LOWER_OFFSET 0x00000040
Rx Announce PTP Frame Structure Definitions.
#define | XAVB_PTP_RX_PKT_ANNOUNCE_PRI1_QUAL_HI_OFFSET 0x0000003C
#define | XAVB_PTP_RX_PKT_ANNOUNCE_QUAL_LOW_PRI2_GMID_HI_OFFSET 0x00000040
#define | XAVB_PTP_RX_PKT_ANNOUNCE_GMID_MID_OFFSET 0x00000044
#define | XAVB_PTP_RX_PKT_ANNOUNCE_GMID_LOW_STEPSREMOVED_HI_OFFSET 0x00000048
#define | XAVB_PTP_RX_PKT_ANNOUNCE_STEPSREMOVED_LOW_TIMESRC_OFFSET 0x0000004C
Rx Signalling PTP Frame Structure Definitions.
#define | XAVB_PTP_RX_PKT_SIGNALING_DELAY_INTERVAL_OFFSET 0x00000044
Standard PTP Frame Field Definitions (from IEEE802.1AS specification).
#define | XAVB_PTP_ETHERTYPE 0x88F7
#define | XAVB_PTP_VERSION_PTP 2
Real Time Clock Definitions.
#define | XAVB_ONE_SECOND 1000000000
| Value in ns. More...
#define | XAVB_PERIOD_8KHZ 125000
| Value in ns. More...
Real Time Clock Locked Definitions.
If the Slave error is > this threshold then define PTP to be unlocked and link not asCapable. Note : This threshold is not specified in IEEE 802.1as.
#define | XAVB_CLOCK_LOCK_THRESHOLD 1000
| Value in ns. More...
RTC Increment Value Update Definitions
Define how often to re-calculate the RTC Increment This value indicates how many good Sync/FollowUp message pairs are received before the re-calculation is performed.
#define | XAVB_NUM_SYNC_FU_PAIR_CALC_RTC_INCREMENT 2

## Typedefs
typedef void(* | XAvb_Handler )(void *CallBackRef, u32 TimestampsUncertain)
| Callback function. More...

## Functions
XStatus | XAvb_CfgInitialize (XAvb *InstancePtr, XAvb_Config *ConfigPtr, u32 EffectiveAddress)
| A function to initialise variables in the data structure records. More...
void | XAvb_Reset (XAvb *InstancePtr)
| This function resets all of the AVB device driver functions to the start-up (reset) defaults. More...
void | XAvb_Start (XAvb *InstancePtr)
| This function will start the PTP drivers running. More...
void | XAvb_Stop (XAvb *InstancePtr)
| This function will stop the PTP drivers from running. More...
void | XAvb_PtpTimerInterruptHandler (XAvb *InstancePtr)
| The Interrupt subroutine for the "interruptPtpTimer" signal. More...
void | XAvb_PtpRxInterruptHandler (XAvb *InstancePtr)
| The Interrupt subroutine for the "interrupt_ptp_rx" signal. More...
void | XAvb_SetupRxFilterControlPcp (XAvb *InstancePtr, u32 VlanPriority, u8 SrClass)
| A function to set the VLAN PCP field for either SR A or B traffic in the RX Filtering Control Register - such that AV traffic is correctly filtered by the RX Splitter. More...
void | XAvb_SetupRxFilterControlVid (XAvb *InstancePtr, u32 VlanVid, u8 SrClass)
| A function to set the VLAN VID field for either SR A or B traffic in the RX Filtering Control Register - such that AV traffic is correctly filtered by the RX Splitter. More...
void | XAvb_SetupRxFilterControlMatchMode (XAvb *InstancePtr, u32 VlanMatchMode)
| A function to set the VLAN Match Mode field for the RX Filtering Control Register - such that AV traffic is correctly filtered by the RX Splitter. 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_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_WriteToMultipleTxPtpFrames (u32 BaseAddress, u32 Address, 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_IncSequenceId (u32 BaseAddress, u32 PTPFrameBaseAddress)
| A function to increment the sequenceId in a PTP frame template. 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_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...
void | XAvb_DecodeTxAnnounceFrame (XAvb *InstancePtr)
| A New Announce Packet has been written to this device to transmit. More...
void | XAvb_DecodeRxAnnounceFrame (XAvb *InstancePtr, u32 PtpFrameBaseAddr)
| A New Announce Packet has been received. More...
void | XAvb_ReadAnnounceFrame (u32 BaseAddress, u32 PtpFrameBaseAddr, XAvb_BmcData *AnnounceFrame)
| A New Announce Packet is to be analyzed. More...
void | XAvb_ReadAnnounceReceiptTimeout (u32 BaseAddress, u32 PtpFrameBaseAddr, XAvb_BmcData *AnnounceFrame)
| This function reads the logMessageinteval from an RX PTP Buffer and updates the AnnounceFrame struct with the value read. More...
void | XAvb_UpdateBmcRecords (XAvb_BmcData *NewMaster, XAvb_BmcData *CurrentBmc)
| This function will accept the data pointer to the current BMCA records, accept an equivalent pointer to a new (winning) Grand Masters Announce Packet information. More...
u32 | XAvb_BestMasterClockAlgorithm (XAvb_BmcData *AnnounceFrame, XAvb_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 | XAvb_BecomeRtcMaster (XAvb *InstancePtr, u8 txAnnounceHasWon)
| This function will make any adjustments needed when the node becomes the Grand Master, including resetting the RTC to its nominal value. More...
void | XAvb_BecomeRtcSlave (XAvb *InstancePtr)
| This function will make any adjustments needed when the node becomes a PTP slave. More...
void | XAvb_ChangePTPLockStatus (XAvb *InstancePtr, u8 locked)
| Operations needed when PTP locks or unlocks. More...
void | XAvb_ChangePeerASCapability (XAvb *InstancePtr, u8 capable)
| Operations needed when the peer's AS capability changes. More...
void | XAvb_SetGMDiscontinuityHandler (XAvb *InstancePtr, XAvb_Handler FuncPtr, void *CallBackRef)
| This function sets the handler that will be called when a GM discontinuity event is identified by the driver. More...
u32 | XAvb_CaptureNanoSec (u32 BaseAddress, u32 PtpFrameBaseAddr)
void | XAvb_CalcDelay (XAvb *InstancePtr)
void | XAvb_CalcRtcOffset (XAvb *InstancePtr, u32 PtpFrameBaseAddr)
void | XAvb_UpdateRtcIncrement (XAvb *InstancePtr)
void | XAvb_Adjust8kClock (u32 BaseAddress, u32 NewOffset)

## Macro Definition Documentation

#define XAVB_ALLOWED_LOST_RESPONSES 3

XAVB_ALLOWED_LOST_RESPONSES is the number of Pdelay_Req messages for which a valid response is not received, above which the Peer should no longer be considered ASCapable.

Referenced by XAvb_PtpTimerInterruptHandler().

#define XAVB_ANNOUNCE_RECEIPT_TIMEOUT 2

XAVB_ANNOUNCE_RECEIPT_TIMEOUT is the number of announce intervals without the receipt of an Announce message from the GM that are allowed before the GM is assumed to be no longer present and BMCA should be run again.

Referenced by XAvb_PtpTimerInterruptHandler().

#define XAVB_CLOCK_LOCK_THRESHOLD 1000

Value in ns.

Referenced by XAvb_UpdateRtcIncrement().

#define XAVB_NEIGHBOR_PROP_DELAY_THRESH 5000

XAVB_NEIGHBOR_PROP_DELAY_THRESH is the maximum allowed delay (in nanosecs) across a full duplex link for which the AVB protocol is allowed to function.

Although this parameter is defined in the IEEE spec, no default is defined.

Referenced by XAvb_CalcDelay().

#define XAVB_ONE_SECOND 1000000000

Value in ns.

Referenced by XAvb_CalcDelay(), XAvb_CalcRtcOffset(), XAvb_MasterSendFollowUp(), XAvb_SendPDelayResp(), XAvb_SendPDelayRespFollowUp(), and XAvb_UpdateRtcIncrement().

#define XAVB_PERIOD_8KHZ 125000

Value in ns.

Referenced by XAvb_Adjust8kClock().

#define XAVB_SYNC_RECEIPT_TIMEOUT 3

XAVB_SYNC_RECEIPT_TIMEOUT is the number of sync intervals without the receipt of an Sync message from the GM that are allowed before the GM is assumed to be no longer present and BMCA should be run again.

Referenced by XAvb_PtpTimerInterruptHandler().

## Typedef Documentation

typedef void(* XAvb_Handler)(void *CallBackRef, u32 TimestampsUncertain)

Callback function.

The first argument is a callback reference passed in by the upper layer when setting the callback functions, and passed back to the upper layer when the callback is invoked. The second argument is a '1' if a Grandmaster Discontinuity event has occurred otherwise it is '0'.

## Function Documentation

void XAvb_Adjust8kClock | ( | u32 | BaseAddress,
|  | u32 | NewOffset
| ) |  |

Read the previous offset

Calculate the change in the previous and current RTC ns offset

Is the adjustment "large"? "large" is chosen here to be one 8k clock period which is a somewhat arbitrary figure

The value XAVB_PERIOD_8KHZ is one 8k clock period in ns. We divide the RTC ns offset change by this to get the offset change in a multiple of 8k clock periods, the add 1 so that we always round up. Then multiply this by XAVB_PERIOD_8KHZ again so that we are always phased aligned to the RTC master (only evey adjust in a multiple of 8k periods.

Write the results to the 8K clock logic Offset register

References XAVB_PERIOD_8KHZ, XAvb_ReadReg, XAVB_RTC_8K_OFFSET_OFFSET, XAVB_RTC_NANOSEC_OFFSET, and XAvb_WriteReg.

Referenced by XAvb_CalcRtcOffset().

void XAvb_BecomeRtcMaster | ( | XAvb * | InstancePtr,
|  | u8 | txAnnounceHasWon
| ) |  |

This function 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 XAvb instance to be worked on
  txAnnounceHasWon | indicates that this function has been called from the function XAvb_DecodeTxAnnounceFrame(). Is this is set then this function has no need to repeat actions that have been already performed.

Returns
  None.

Note
  None.

Update the BMCA records to this device's information

Read the attributes in the Tx PTP buffer

Update records

reset the RTC to a nominal value

set timestamp uncertainty if new status

inform the rest of the system

References XAvb_Config::BaseAddress, XAvb::Config, XAvb::CurrentBmc, XAvb::GMDiscCallBackRef, XAvb::GMDiscHandler, XAvb_BmcData::IAmTheRtcMaster, XAvb_ReadAnnounceFrame(), XAVB_RTC_INCREMENT_NOMINAL_RATE, XAVB_RTC_INCREMENT_OFFSET, XAvb_UpdateBmcRecords(), and XAvb_WriteReg.

Referenced by XAvb_DecodeTxAnnounceFrame(), XAvb_PtpTimerInterruptHandler(), and XAvb_Reset().

void XAvb_BecomeRtcSlave | ( | XAvb * | InstancePtr | ) |

This function will make any adjustments needed when the node becomes a PTP slave.

Parameters

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

Returns
  None.

Note
  None.

set timestamp uncertainty if new status

References XAvb_Counters::CounterSyncInterval, XAvb::CurrentBmc, XAvb::GMDiscCallBackRef, XAvb::GMDiscHandler, XAvb_BmcData::IAmTheRtcMaster, and XAvb::PtpCounters.

Referenced by XAvb_DecodeRxAnnounceFrame().

u32 XAvb_BestMasterClockAlgorithm | ( | XAvb_BmcData * | AnnounceFrame,
|  | XAvb_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.

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

Parameters

  CurrentBmc | is a pointer to a suitable data structure, designed to record the current fields from the current Grand Master's Announce Packet.
  AnnounceFrame | is a pointer to a suitable data structure, designed to record the useful fields from the received Announce Packet

Returns
  An updated True/False decision as to whether there is to be a change of Grand Master in the network.

Note
  None.

Priority1 takes precedence over all over priorites

we have found a better master!

convert structs to u32 values for easy comparison

ClockQuality has the next priority

we have found a better master!

Priority2 provides fine grained ordering amongst otherwise equal clocks

we have found a better master!

Next compare the Clock Identities

we have found a better master!

we have found a better master!

Next compare stepsRemoved

we have found a better master!

Next compare SourcePortIdentity

we have found a better master!

we have found a better master!

If all else fails, the SourcePortIdentity Port Number must act as the tie-breaker

A new master has won on the tie-break!

References XAvb_ClockQuality::clockAccuracy, XAvb_ClockQuality::clockClass, XAvb_PortIdentity::ClockIdentityLower, XAvb_ClockIdentity::ClockIdentityLower, XAvb_PortIdentity::ClockIdentityUpper, XAvb_ClockIdentity::ClockIdentityUpper, XAvb_BmcData::ClockQuality, XAvb_BmcData::GrandmasterIdentity, XAvb_BmcData::GrandmasterPriority1, XAvb_BmcData::GrandmasterPriority2, XAvb_ClockQuality::offsetScaledLogVariance, XAvb_PortIdentity::PortNumber, XAvb_BmcData::SourcePortIdentity, and XAvb_BmcData::stepsRemoved.

Referenced by XAvb_DecodeRxAnnounceFrame(), and XAvb_DecodeTxAnnounceFrame().

void XAvb_CalcDelay | ( | XAvb * | InstancePtr | ) |

Since we are only using the nanoseconds field here we need to account for wrap. So we add one second to the T4 and T3 terms to ensure that the T4MinusT1 and T3MinusT2 results cannot be negative. These two additional seconds then cancel each other out in the T4MinusT1 - T3MinusT2 equation.

If the nanoseconds count has wrapped, add on 1 second to ensure we get the right answer

If the nanoseconds count has wrapped, add on 1 second to ensure we get the right answer

For now we are simply going to throw out any absurdly large link delays.

The peer has responded to the pDelay_Req and the measured delay is within tolerance: the peer is deemed to be AS capable

References XAvb_PtpStruct::LinkDelay, XAvb_PtpStruct::PDelayTimestampT1, XAvb_PtpStruct::PDelayTimestampT2, XAvb_PtpStruct::PDelayTimestampT3, XAvb_PtpStruct::PDelayTimestampT4, XAvb::PtpRecords, XAvb_ChangePeerASCapability(), XAVB_NEIGHBOR_PROP_DELAY_THRESH, and XAVB_ONE_SECOND.

Referenced by XAvb_DecodeRxPDelayRespFollowUp().

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

## Capture the Slave Time

We do this immediately to get the slave time ASAP (since processing time is uncertain and the RTC does not stand still).

## Capture the Master Origin Timestamp (from received FollowUp Frame)

read the Words from the PTP frame buffer containing the RTC seconds field

Now re-arrange the required data from the Words to obtain the required seconds field timestamp in binary format

## Correct the Nanoseconds

NOTE: we are trying to compare the value of the slave RTC nano- seconds field timestamp with the nano-seconds value of the Masters RTC nanosecond field at exactly that time.

Sync Frame routing delay is equal to the value of the correction field (sum of correction fields in Sync and FollowUp frames) plus the link delay measurement made by this slave.

MasterNsCorrected time here is the calculated time that the master will be at the point in time when the sync frame is received (and timestamped) at the slave. This is calculated from the originTimeStamp (from the FollowUpframe), plus the Sync Frame routing delay. A direct comparison can then be made between master and slave.

Check for ns wrap-around condition

Make the Master and Slave comparison and discover the difference!

Check for ns wrap-around condition

Return these comparison figures in the form of a pointer (RTC increment rate adjust function also needs to know this information)

Adjust the 8k clock logic (if necessary)

## Correct the Seconds and Epoch

NOTE: we are trying to compare the value of the slave RTC seconds field at the exact time when the timestamp was taken with the RTC seconds value of the Master at that time.

We need to know the value of the slaves synchronised nano-seconds field at the time when the timestamp was taken (since timestamps use the syntonised time). So we add the current nanosecond field offset value:

Check for ns wrap-around condition

Even though we read the slave RTC value at the beginning of this function, there would have been processing delay between the actual reception (and timestamping) of the FollowUp frame and the start of this function. During this time, the slave 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).

slave_nanosec has wrapped since timestamp so decrement the seconds field

If the Master nano seconds field wrapped during the Sync frame routing delay, then we need to increment the seconds field.

Calculate the slave RTC error: the master time minus the timestamp taken by this slave for Sync Frame reception.

## Write the results to the RTC Offset registers

References XAvb_Config::BaseAddress, XAvb::Config, XAvb_PtpStruct::LinkDelay, XAvb_PtpStruct::MasterCorrectionField, XAvb_RtcFormat::NanoSeconds, XAvb_PtpStruct::NewMasterTime, XAvb_PtpStruct::NewSlaveTime, XAvb::PtpRecords, XAvb_RtcFormat::SecondsLower, XAvb_RtcFormat::SecondsUpper, XAvb_PtpStruct::SlaveSyncTimestamp, XAvb_Adjust8kClock(), XAvb_CaptureNanoSec(), XAVB_ONE_SECOND, XAvb_ReadPtpBuffer, XAvb_ReadReg, XAvb_ReadRtc(), XAvb_ReorderWord(), XAVB_RTC_NANOSEC_OFFSET, XAVB_RTC_SEC_LOWER_VALUE_OFFSET, and XAvb_WriteRtcOffset().

Referenced by XAvb_DecodeRxFollowUp().

u32 XAvb_CaptureNanoSec | ( | u32 | BaseAddress,
|  | u32 | PtpFrameBaseAddr
| ) |  |

The timestamp is located over several 32-bit Words of the PTP frame buffer Read the relevant Words containing the ns timestamp:

Now re-arrange the data from the Words to obtain the required ns Timestamp in binrary format

References XAvb_ReadPtpBuffer, and XAvb_ReorderWord().

Referenced by XAvb_CalcRtcOffset(), XAvb_DecodeRxPDelayResp(), and XAvb_DecodeRxPDelayRespFollowUp().

XStatus XAvb_CfgInitialize | ( | XAvb * | InstancePtr,
|  | XAvb_Config * | ConfigPtr,
|  | u32 | EffectiveAddress
| ) |  |

A function to initialise variables in the data structure records.

Parameters

  InstancePtr | is a pointer to the XAvb instance to be worked on
  ConfigPtr | is the Configuration Pointer
  EffectiveAddress | is the base address of the Configuration Pointer

Returns
  - XST_SUCCESS if initialization was successful
  - XST_DEVICE_NOT_FOUND if device configuration information was not found for a device with the supplied device ID.*

Note
  None.

The component is not yet ready to use

Clear instance memory

Lookup the device configuration in the temporary CROM table. Use this configuration info down below when initializing this component.

Populate Base Address field using the base address value in the configuration structure.

Indicate the component is now ready to use.

Set the callback handler to a stub

References XAvb_Config::BaseAddress, XAvb::Config, XAvb::GMDiscHandler, and XAvb::IsReady.

Referenced by main().

void XAvb_ChangePeerASCapability | ( | XAvb * | InstancePtr,
|  | u8 | capable
| ) |  |

Operations needed when the peer's AS capability changes.

Parameters

  InstancePtr | is a pointer to the XAvb instance to be worked on
  capable | is 1 if the peer is ASCapable, 0 otherwise

Returns
  None.

Note
  None.

References XAvb::PeerASCapable.

Referenced by XAvb_CalcDelay(), XAvb_ChangePTPLockStatus(), XAvb_DecodeRxPDelayResp(), XAvb_PtpTimerInterruptHandler(), XAvb_Reset(), and XAvb_Start().

void XAvb_ChangePTPLockStatus | ( | XAvb * | InstancePtr,
|  | u8 | locked
| ) |  |

Operations needed when PTP locks or unlocks.

Parameters

  InstancePtr | is a pointer to the XAvb instance to be worked on
  locked | is 1 if changing to locked status, zero if unlocked

Returns
  None.

Note
  None.

set status variable

set timestamp uncertainty if necessary

References XAvb::GMDiscCallBackRef, XAvb::GMDiscHandler, XAvb::PTPLocked, and XAvb_ChangePeerASCapability().

Referenced by XAvb_UpdateRtcIncrement().

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_DecodeRxAnnounceFrame | ( | XAvb * | InstancePtr,
|  | u32 | PtpFrameBaseAddr
| ) |  |

A New Announce Packet has been received.

We need to decode it and rerun the Best Master Clock Algorithm (BMCA)

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 an updated True/False decision as to whether this device should operate as a clock master or a slave is written into the CurrentBmc data structure.

Note
  None.

Read the attributes for the new Announce frame received

If the received packet's clockIdentity matches our clockIdentity, ignore the packet

If the received packet's stepsRemoved field is >= 255, ignore the packet

If the Announce packet's GMID matches that of our current GM record, then update its records based on the current packet, just in case something (such as priority) has changed.

update timeout information

Compare against this device's information to see if we should be GM

run BMCA on this announce to see if it is better than me

Update records with the NEW best master

Capture the Announce Receipt Timeout Interval. Reset the announce receipt timeout interval to use the new value.

New Rx Announce Packet has won - so this device cannot be a master

References XAvb_BmcData::AnnounceIntervalDuration, XAvb_Config::BaseAddress, XAvb_ClockQuality::clockClass, XAvb_ClockIdentity::ClockIdentityLower, XAvb_ClockIdentity::ClockIdentityUpper, XAvb_BmcData::ClockQuality, XAvb::Config, XAvb_Counters::CounterAnnounceInterval, XAvb::CurrentBmc, XAvb_BmcData::GrandmasterIdentity, XAvb_BmcData::GrandmasterPriority1, XAvb_BmcData::GrandmasterPriority2, XAvb_BmcData::IAmTheRtcMaster, XAvb_BmcData::logMessageInterval, XAvb::portIdLocal, XAvb::PtpCounters, XAvb_BmcData::SourcePortIdentity, XAvb_BmcData::stepsRemoved, XAvb_BecomeRtcSlave(), XAvb_BestMasterClockAlgorithm(), XAvb_CompareClockIdentity(), XAvb_ComparePortIdentity(), XAvb_ConvertLogMeanToDuration(), XAvb_DecodeTxAnnounceFrame(), XAvb_ReadAnnounceFrame(), XAvb_ReadAnnounceReceiptTimeout(), and XAvb_UpdateBmcRecords().

Referenced by XAvb_PtpRxInterruptHandler().

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_DecodeTxAnnounceFrame | ( | XAvb * | InstancePtr | ) |

A New Announce Packet has been written to this device to transmit.

We need to decode it and rerun the Best Master Clock Algorithm (BMCA)

Parameters

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

Returns
  None. But an updated True/False decision as to whether this device should operate as a clock master or a slave is written into the CurrentBmc data structure.

Note
  None.

Read the attributes for the new Announce frame in the Tx PTP buffer

Compare the clock attributes between then new Announce frame and the current master

Update records with the NEW best master

Our new Tx Announce Packet has won - so this device must be the master

References XAvb_Config::BaseAddress, XAvb_ClockQuality::clockClass, XAvb_ClockIdentity::ClockIdentityLower, XAvb_ClockIdentity::ClockIdentityUpper, XAvb_BmcData::ClockQuality, XAvb::Config, XAvb::CurrentBmc, XAvb_BmcData::GrandmasterIdentity, XAvb_BmcData::GrandmasterPriority1, XAvb_BmcData::GrandmasterPriority2, XAvb_BmcData::IAmTheRtcMaster, XAvb_BecomeRtcMaster(), XAvb_BestMasterClockAlgorithm(), XAvb_ReadAnnounceFrame(), and XAvb_UpdateBmcRecords().

Referenced by XAvb_DecodeRxAnnounceFrame(), and XAvb_Start().

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().

void XAvb_PtpRxInterruptHandler | ( | XAvb * | InstancePtr | ) |

The Interrupt subroutine for the "interrupt_ptp_rx" signal.

This interrupt fires whenever a PTP frame has been received. The main function is to identify, decode, and act on the type of PTP frame received.

Parameters

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

Returns
  None.

Note
  None.

RxPtpHardPointer indicates the bin location of the last frame to be received and written into the Rx PTP buffer in hardware. This read will also clear the interrupt.

If PTP functions are marked as not running, then take no further action

RxPtpSoftPointer indicates the bin location of the last frame to be processed in software.

decode the rx'd frames until RxPtpHardPointer = RxPtpSoftPointer

Set the base address of the current PTP frame in the Buffer

Perform very basic sanity checking of the frame : is it a PTP?

Determine which PTP frame was received.

Now act on the received frame

## Sync Frame

## Follow Up Frame

## PDelayReq Frame

Send a send PDelayResp frame after receiving a PDelayReq Frame

Send a send PDelayRespFollowUp frame after a PDelayResp Frame

## PDelayResp Frame

## PDelayRespFollowUp Frame

## Announce Frame

## Signaling Frame

## Unknown Frame

PTP is not running so just consume the packets so they are not left in the queue and cause problems when we actually start

RxPtpSoftPointer indicates the bin location of the last frame to be processed in software.

decode the rx'd frames until RxPtpHardPointer = RxPtpSoftPointer

References XAvb_Config::BaseAddress, XAvb::Config, XAvb::PtpCounters, XAvb::PtpIsRunning, XAvb_Counters::RxPtpHardPointer, XAvb_Counters::RxPtpSoftPointer, XAvb_DecodeRxAnnounceFrame(), XAvb_DecodeRxFollowUp(), XAvb_DecodeRxPDelayResp(), XAvb_DecodeRxPDelayRespFollowUp(), XAvb_DecodeRxSignaling(), XAvb_DecodeRxSync(), XAvb_IsRxFramePTP(), XAVB_PTP_RX_CONTROL_OFFSET, XAvb_ReadPtpBuffer, XAvb_ReadReg, XAvb_SendPDelayResp(), and XAvb_SendPDelayRespFollowUp().

void XAvb_PtpTimerInterruptHandler | ( | XAvb * | InstancePtr | ) |

The Interrupt subroutine for the "interruptPtpTimer" signal.

This interrupt fires regularly on a 1/128 second period (based on the RTC).

Parameters

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

Returns
  None.

Note
  None.

Clear Interrupt

If PTP functions are marked as not running, then take no further action

If the Link Partner is not AS capable, then take no further action

If a Master, then initiate Sync Frames and Announce frames at the correct intervals

Master will initiate a Sync Frame when the SyncIntervalDuration expires (SyncIntervalDuration is used to count/time the duration)

- unless a Signalling frame has told us not to send Sync Frames

Following a Sync Frame, a Follow Up frame should always be sent

Master will initiate an Announce Frame when the AnnounceIntervalDuration expires (CounterAnnounceInterval is used to count/time the duration)

- unless a Signalling frame has told us not to send Announce Frames

If a Slave, monitor Announce/Sync Packet reception from the Master

Timeout for Announce Packet reception: XAVB_ANNOUNCE_RECEIPT_TIMEOUT The AnnounceIntervalDuration is stored with the GrandMaster BMCA data as it is captured from the last Announce frame that was received.

No Announce received from GM for timeout interval: we become the master

Timeout for Sync Packet reception: XAVB_SYNC_RECEIPT_TIMEOUT * The SyncIntervalDuration is stored with the Received Sync data as it is captured from the last Sync frame that was received.

No Syncs received from GM for timeout interval: we become the master

Both Master and Slave will initiate a link delay measurement when the LinkDelayIntervalDuration expires (LinkDelayIntervalDuration is used to count/time the duration)

- unless a Signalling frame has told us not to send PdelayReq Frames

Check to see if we've received PDelayResp and PDelayRespFollowUp messages since the last PDelayReq was sent

the peer is no longer ASCapable

avoid potential overflow

end of 'if (InstancePtr->PtpIsRunning == 1)'

References XAvb_BmcData::AnnounceIntervalDuration, XAvb_SignallingFrameData::AnnounceIntervalDuration, XAvb_Config::BaseAddress, XAvb::Config, XAvb_Counters::CounterAnnounceInterval, XAvb_Counters::CounterLinkDelayInterval, XAvb_Counters::CounterSyncInterval, XAvb::CurrentBmc, XAvb_BmcData::IAmTheRtcMaster, XAvb::latestMDSyncReceive, XAvb_SignallingFrameData::LinkDelayIntervalDuration, XAvb_StateMachineData::lostResponses, XAvb::PeerASCapable, XAvb::PtpCounters, XAvb::PtpIsRunning, XAvb_StateMachineData::rcvdPDelayResp, XAvb_StateMachineData::rcvdPDelayRespFollowUp, XAvb::SignallingFrameData, XAvb::StateMachineData, XAvb_SignallingFrameData::SyncIntervalDuration, XAvb_MDSyncReceive::SyncIntervalDuration, XAVB_ALLOWED_LOST_RESPONSES, XAVB_ANNOUNCE_RECEIPT_TIMEOUT, XAvb_BecomeRtcMaster(), XAvb_ChangePeerASCapability(), XAvb_MasterSendAnnounce(), XAvb_MasterSendFollowUp(), XAvb_MasterSendSync(), XAVB_RTC_CLEAR_INT_OFFSET, XAvb_SendPDelayReq(), XAVB_SYNC_RECEIPT_TIMEOUT, and XAvb_WriteReg.

void XAvb_ReadAnnounceFrame | ( | u32 | BaseAddress,
|  | u32 | PtpFrameBaseAddr,
|  | XAvb_BmcData * | AnnounceFrame
| ) |  |

A New Announce Packet is to be analyzed.

This function will read in the packet, decode it, and extract the relevant information fields to the "AnnounceFrame" data pointer.

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
  AnnounceFrame | is a pointer to a suitable data structure, designed to record the useful fields from the received Announce Packet

Returns
  The AnnounceFrame data structure is updated.

Note
  None.

Get the Source Port Identity of the port sending the Announce Packet

Read priority1 and top half of ClockQuality

Read bottom half of ClockQuality, priority2, and top byte of GMID

Read bytes 4-7 of GMID

Read bytes 1-3 of GMID and high byte of stepsRemoved

Read low byte of stepsRemoved

References XAvb_ClockQuality::clockAccuracy, XAvb_ClockQuality::clockClass, XAvb_PortIdentity::ClockIdentityLower, XAvb_ClockIdentity::ClockIdentityLower, XAvb_PortIdentity::ClockIdentityUpper, XAvb_ClockIdentity::ClockIdentityUpper, XAvb_BmcData::ClockQuality, XAvb_BmcData::GrandmasterIdentity, XAvb_BmcData::GrandmasterPriority1, XAvb_BmcData::GrandmasterPriority2, XAvb_ClockQuality::offsetScaledLogVariance, XAvb_BmcData::SourcePortIdentity, XAvb_BmcData::stepsRemoved, XAvb_GetPortIdentity(), XAvb_ReadPtpBuffer, and XAvb_ReorderWord().

Referenced by XAvb_BecomeRtcMaster(), XAvb_DecodeRxAnnounceFrame(), and XAvb_DecodeTxAnnounceFrame().

void XAvb_ReadAnnounceReceiptTimeout | ( | u32 | BaseAddress,
|  | u32 | PtpFrameBaseAddr,
|  | XAvb_BmcData * | AnnounceFrame
| ) |  |

This function reads the logMessageinteval from an RX PTP Buffer and updates the AnnounceFrame struct with the value read.

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
  AnnounceFrame | is a pointer to a suitable data structure, designed to record the useful fields from the received Announce Packet

Returns
  The AnnounceFrame data structure is updated.

Note
  None.

References XAvb_BmcData::logMessageInterval, XAvb_ReadPtpBuffer, and XAvb_ReorderWord().

Referenced by XAvb_DecodeRxAnnounceFrame().

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_Reset | ( | XAvb * | InstancePtr | ) |

This function resets all of the AVB device driver functions to the start-up (reset) defaults.

Parameters

  InstancePtr | is a pointer to the Xavb instance to be worked on.

Returns
  None.

Note
  None.

Assert bad arguments and conditions

Perform a Software Reset of the AVB Core. This will reset both the transmitter and receiver paths. The RTC counter is not reset here.

Set IEEE specification default values in the device's data structure

Update logMeanMessageInterval in the pre-loaded TX SYNC message buffer

Update logMeanMessageInterval in the pre-loaded TX FOLLOW_UP message buffer

Update logMeanMessageInterval in the pre-loaded TX PDELAYREQ message buffer

Update logMeanMessageInterval in the pre-loaded TX ANNOUNCE message buffer

Initialise other driver variables in the device's data structure

References XAvb_SignallingFrameData::AnnounceIntervalDuration, XAvb_Config::BaseAddress, XAvb::Config, XAvb_Counters::CounterAnnounceInterval, XAvb_Counters::CounterLinkDelayInterval, XAvb_Counters::CounterSyncEvents, XAvb_Counters::CounterSyncInterval, XAvb::IsReady, XAvb::latestMDSyncReceive, XAvb_PtpStruct::LinkDelay, XAvb_SignallingFrameData::LinkDelayIntervalDuration, XAvb_StateMachineData::lostResponses, XAvb::PtpCounters, XAvb::PtpIsRunning, XAvb::PtpRecords, XAvb_StateMachineData::rcvdPDelayResp, XAvb_StateMachineData::rcvdPDelayRespFollowUp, XAvb_Counters::RxPtpHardPointer, XAvb_Counters::RxPtpSoftPointer, XAvb::SignallingFrameData, XAvb::StateMachineData, XAvb_SignallingFrameData::SyncIntervalDuration, XAvb_MDSyncReceive::SyncIntervalDuration, XAvb_BecomeRtcMaster(), XAvb_ChangePeerASCapability(), XAvb_ConvertLogMeanToDuration(), XAVB_SW_RESET_OFFSET, XAvb_UpdateLogMeanMessageInterval(), and XAvb_WriteReg.

Referenced by main(), and XAvb_Stop().

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_SetGMDiscontinuityHandler | ( | XAvb * | InstancePtr,
|  | XAvb_Handler | FuncPtr,
|  | void * | CallBackRef
| ) |  |

This function sets the handler that will be called when a GM discontinuity event is identified by the driver.

The purpose of the handler is to allow application specific processing to be performed.

Parameters

  InstancePtr | is a pointer to the XAvb instance.
  FuncPtr | is the pointer to the callback function.
  CallBackRef | is the upper layer callback reference passed back when the callback function is invoked.

Returns
  None.

Note
  There is no assert on the CallBackRef since the driver doesn't know what it is (nor should it)

References XAvb::GMDiscCallBackRef, XAvb::GMDiscHandler, and XAvb::IsReady.

Referenced by main().

void XAvb_SetupRxFilterControlMatchMode | ( | XAvb * | InstancePtr,
|  | u32 | VlanMatchMode
| ) |  |

A function to set the VLAN Match Mode field for the RX Filtering Control Register - such that AV traffic is correctly filtered by the RX Splitter.

Parameters

  InstancePtr | is a pointer to the XAvb instance to be worked on
  VlanMatchMode | contains the 1-bit value to be written to the register in the correct bit position as defined in the address map

Returns
  None.

Note
  None.

References XAvb_Config::BaseAddress, XAvb::Config, XAvb_ReadReg, XAVB_RX_FILTER_CONTROL, and XAvb_WriteReg.

void XAvb_SetupRxFilterControlPcp | ( | XAvb * | InstancePtr,
|  | u32 | VlanPriority,
|  | u8 | SrClass
| ) |  |

A function to set the VLAN PCP field for either SR A or B traffic in the RX Filtering Control Register - such that AV traffic is correctly filtered by the RX Splitter.

Parameters

  InstancePtr | is a pointer to the XAvb instance to be worked on
  VlanPriority | contains the 3-bit value to be written to the register in the correct bit positions as defined in the address map
  SrClass | is '0' if VLAN Priority (PCP) A is to be updated and is '1' if VLAN Priority (PCP) B is to be updated

Returns
  None.

Note
  None.

References XAvb_Config::BaseAddress, XAvb::Config, XAvb_ReadReg, XAVB_RX_FILTER_CONTROL, and XAvb_WriteReg.

void XAvb_SetupRxFilterControlVid | ( | XAvb * | InstancePtr,
|  | u32 | VlanVid,
|  | u8 | SrClass
| ) |  |

A function to set the VLAN VID field for either SR A or B traffic in the RX Filtering Control Register - such that AV traffic is correctly filtered by the RX Splitter.

Parameters

  InstancePtr | is a pointer to the XAvb instance to be worked on
  VlanVid | contains the 12-bit value to be written to the register in the correct bit positions as defined in the address map
  SrClass | is '0' if VLAN VID A is to be updated and is '1' if VLAN VID B is to be updated

Returns
  None.

Note
  None.

References XAvb_Config::BaseAddress, XAvb::Config, XAvb_ReadReg, XAVB_RX_FILTER_CONTROL, and XAvb_WriteReg.

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().

void XAvb_Start | ( | XAvb * | InstancePtr | ) |

This function will start the PTP drivers running.

Parameters

  InstancePtr | is a pointer to the Xavb instance to be worked on.

Returns
  None.

Note
  None.

Assert bad arguments and conditions

Re-run the BMCA algorithm with the current PTP buffer Announce Packet

Set to PTP running in the PTP data structure

Assume that the Peer is not AS capable until it replies to a pDelay_Req frame

References XAvb::IsReady, XAvb::PtpIsRunning, XAvb_ChangePeerASCapability(), and XAvb_DecodeTxAnnounceFrame().

Referenced by main().

void XAvb_Stop | ( | XAvb * | InstancePtr | ) |

This function will stop the PTP drivers from running.

Parameters

  InstancePtr | is a pointer to the Xavb instance to be worked on.

Returns
  None.

Note
  None.

Assert bad arguments and conditions

References XAvb::IsReady, and XAvb_Reset().

void XAvb_UpdateBmcRecords | ( | XAvb_BmcData * | NewMaster,
|  | XAvb_BmcData * | CurrentBmc
| ) |  |

This function will accept the data pointer to the current BMCA records, accept an equivalent pointer to a new (winning) Grand Masters Announce Packet information.

The CurrentBmc data structure is then updated with the information from the NewMaster.

Parameters

  NewMaster | is a pointer to a suitable data structure which has recorded the relevant Announce Packet fields of the new (winning) Grand Master.
  CurrentBmc | is a pointer to a suitable data structure which has recorded the current fields of the current Grand Master's Announce Packet.

Returns
  The CurrentBmc data structure is updated.

Note
  None.

References XAvb_PortIdentity::ClockIdentityLower, XAvb_ClockIdentity::ClockIdentityLower, XAvb_PortIdentity::ClockIdentityUpper, XAvb_ClockIdentity::ClockIdentityUpper, XAvb_BmcData::ClockQuality, XAvb_BmcData::GrandmasterIdentity, XAvb_BmcData::GrandmasterPriority1, XAvb_BmcData::GrandmasterPriority2, XAvb_PortIdentity::PortNumber, XAvb_BmcData::SourcePortIdentity, and XAvb_BmcData::stepsRemoved.

Referenced by XAvb_BecomeRtcMaster(), XAvb_DecodeRxAnnounceFrame(), and XAvb_DecodeTxAnnounceFrame().

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_UpdateRtcIncrement | ( | XAvb * | InstancePtr | ) |

Sanity Check that Sync Frames were n apart. This safeguards the calculation against the ethernet cable being pulled out and then replaced, etc.

Measure the time duration, as measured by the RTC master of the M sync delay measurement period.

Measure the time duration, as measured by the RTC slave of the M sync delay measurement period.

Therefore calculate the slave error (in ns)

If the slave error is zero, skip the remainder of function. (Note : a zero error would otherwise get stuck in the while loop further down this function).

Analyse msb of error signal to see which clock is running fastest

This check is in addition to the checks described in IEEE802.1as. If the SlaveError is unexpectedly large, then set asCapable to 0.

SlaveError signal is 32-bits (ns). This can indicate > 4 sec of error: this is too large for 100 ms measurement period. So we expect upper bits to be zero.

This function will shift the 1st none zero bit of SlaveError up to bit 31, so that forthcoming calculation uses maximum accuracy.

This shift is equivalent to a multiply (of the error signal). A shift the opposite way (equivalent to a divide) will follow at end of full calculation.

Calculate the relative error: can be thought of as a scaled ratio of error per time unit

Obtain the current increment value

Calculate the increment adjustment: multiply NormalisedError by the increment time unit. Then shift back the other way to correct the calculation (restore to ns).

Now calculate the new increment value

Add some rails so that recovery is possible after a string of bad pDelay values. The RTC should be able to lock to within 100ppm of the slowest allowable clock (25 MHz). This equates to +/-4ps. Let's arbitrarily set the rails to 400ppm (+/-16ps) just in case someone decides to use a particularly bad oscillator. The lowest 20 bits of NewIncrement are fractions of a nanosecond, which equates to +/- 0x04189

And write the new increment value!

References XAvb_Config::BaseAddress, XAvb::Config, XAvb_PtpStruct::NewMasterTime, XAvb_PtpStruct::NewSlaveTime, XAvb_SequenceIdStruct::NewSyncSequenceId, XAvb_PtpStruct::OldMasterTime, XAvb_PtpStruct::OldSlaveTime, XAvb_SequenceIdStruct::OldSyncSequenceId, XAvb::PtpRecords, XAvb::SequenceIdRecords, XAvb_ChangePTPLockStatus(), XAVB_CLOCK_LOCK_THRESHOLD, XAVB_ONE_SECOND, XAvb_ReadReg, XAVB_RTC_400PPM_OFFSET, XAVB_RTC_INCREMENT_NOMINAL_RATE, XAVB_RTC_INCREMENT_OFFSET, and XAvb_WriteReg.

Referenced by XAvb_DecodeRxFollowUp().

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().