XilinxProcessorIPLib/drivers/axiethernet/examples/avb/xavb_ptp_packets.c
void XAvb_DecodeRxSync(XAvb * InstancePtr,
                       u32    PtpFrameBaseAddr) {

  u32 ReadWord = 0;
  XAvb_PortIdentity syncPortID;

  /** Read sourcePortIdentity from packet */
  XAvb_GetPortIdentity(InstancePtr->Config.BaseAddress, PtpFrameBaseAddr,
                       XAVB_PTP_RX_PKT_PORTID_UPPER_OFFSET, &syncPortID);

  /** Only decode if configured for a slave and if SourcePortID is that of the
   * RTC Clock Master */
  if ( (InstancePtr->CurrentBmc.IAmTheRtcMaster == 0) &&
        XAvb_ComparePortIdentity(InstancePtr->Config.BaseAddress,
                                 InstancePtr->CurrentBmc.SourcePortIdentity,
                                 syncPortID) ) {

    /** Reset Sync Interval Counter as we have received a valid Sync */
    InstancePtr->PtpCounters.CounterSyncInterval = 0;

    /** Capture the local Timestamp for receipt of this frame and adjust it for
     *  MAC receive latency */
    InstancePtr->PtpRecords.SlaveSyncTimestamp
        = XAvb_ReadPtpBuffer(InstancePtr->Config.BaseAddress,
                              PtpFrameBaseAddr,
                              XAVB_PTP_PKT_CAPTURED_TIMESTAMP_OFFSET)
          - XAVB_RX_MAC_LATENCY_IN_NS;

    /**  Capture the Sync SequenceID */
    ReadWord = XAvb_ReorderWord(XAvb_ReadPtpBuffer(InstancePtr->Config.BaseAddress,
                                PtpFrameBaseAddr,
                                XAVB_PTP_RX_PKT_SEQUENCEID_OFFSET));
    InstancePtr->SequenceIdRecords.SyncSequenceId = (ReadWord >> 16);

    /** Capture the logMeanMessageInterval and convert into a useful duration
     * (NOTE: there is an implicit conversion from u32 to char here)
     */
    InstancePtr->latestMDSyncReceive.logMessageInterval = ReadWord & 0x000000ff;
    InstancePtr->latestMDSyncReceive.SyncIntervalDuration =
                 XAvb_ConvertLogMeanToDuration(InstancePtr->latestMDSyncReceive.logMessageInterval);

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

  } else {
    xil_printf("\r\nXAvb_DecodeRxSync()");
    xil_printf("\r\nSync ignored due to unmatched SourcePortID");
#ifdef DEBUG_XAVB_LEVEL1
    xil_printf("\r\nInstancePtr->CurrentBmc.SourcePortIdentity.ClockIdentityUpper = %x",InstancePtr->CurrentBmc.SourcePortIdentity.ClockIdentityUpper);
    xil_printf("\r\nInstancePtr->CurrentBmc.SourcePortIdentity.ClockIdentityLower = %x",InstancePtr->CurrentBmc.SourcePortIdentity.ClockIdentityLower);
    xil_printf("\r\nInstancePtr->CurrentBmc.SourcePortIdentity.PortNumber = %x\r\n",InstancePtr->CurrentBmc.SourcePortIdentity.PortNumber);
    xil_printf("\r\nsyncPortID.ClockIdentityUpper = %x",syncPortID.ClockIdentityUpper);
    xil_printf("\r\nsyncPortID.ClockIdentityLower = %x",syncPortID.ClockIdentityLower);
    xil_printf("\r\nsyncPortID.PortNumber = %x\r\n",syncPortID.PortNumber);
#endif
  }
}
/****************************************************************************/
/**
*
* A function to decode a received PTP Sync Packet
*
* @param  InstancePtr is a pointer to the XAvb instance to be worked on
* @param  PtpFrameBaseAddr is the base address of the received Announce Packet
*         in the Rx PTP Packet Buffer
*
* @return None.
*
* @note   None.
*
*****************************************************************************/
A function to decode a received PTP Sync Packet
A function to decode a received PTP Sync Packet
void XAvb_DecodeRxSync(XAvb * InstancePtr,
                       u32    PtpFrameBaseAddr) {
  u32 ReadWord = 0;
  XAvb_PortIdentity syncPortID;
  XAvb_GetPortIdentity(InstancePtr->Config.BaseAddress, PtpFrameBaseAddr,
                       XAVB_PTP_RX_PKT_PORTID_UPPER_OFFSET, &syncPortID);
  if ( (InstancePtr->CurrentBmc.IAmTheRtcMaster == 0) &&
        XAvb_ComparePortIdentity(InstancePtr->Config.BaseAddress,
                                 InstancePtr->CurrentBmc.SourcePortIdentity,
                                 syncPortID) ) {
    InstancePtr->PtpCounters.CounterSyncInterval = 0;
    InstancePtr->PtpRecords.SlaveSyncTimestamp
        = XAvb_ReadPtpBuffer(InstancePtr->Config.BaseAddress,
                              PtpFrameBaseAddr,
                              XAVB_PTP_PKT_CAPTURED_TIMESTAMP_OFFSET)
          - XAVB_RX_MAC_LATENCY_IN_NS;
    ReadWord = XAvb_ReorderWord(XAvb_ReadPtpBuffer(InstancePtr->Config.BaseAddress,
                                PtpFrameBaseAddr,
                                XAVB_PTP_RX_PKT_SEQUENCEID_OFFSET));
    InstancePtr->SequenceIdRecords.SyncSequenceId = (ReadWord >> 16);
    InstancePtr->latestMDSyncReceive.logMessageInterval = ReadWord & 0x000000ff;
    InstancePtr->latestMDSyncReceive.SyncIntervalDuration =
                 XAvb_ConvertLogMeanToDuration(InstancePtr->latestMDSyncReceive.logMessageInterval);
  } else {
    xil_printf("\r\nXAvb_DecodeRxSync()");
    xil_printf("\r\nSync ignored due to unmatched SourcePortID");
#ifdef DEBUG_XAVB_LEVEL1
    xil_printf("\r\nInstancePtr->CurrentBmc.SourcePortIdentity.ClockIdentityUpper = %x",InstancePtr->CurrentBmc.SourcePortIdentity.ClockIdentityUpper);
    xil_printf("\r\nInstancePtr->CurrentBmc.SourcePortIdentity.ClockIdentityLower = %x",InstancePtr->CurrentBmc.SourcePortIdentity.ClockIdentityLower);
    xil_printf("\r\nInstancePtr->CurrentBmc.SourcePortIdentity.PortNumber = %x\r\n",InstancePtr->CurrentBmc.SourcePortIdentity.PortNumber);
    xil_printf("\r\nsyncPortID.ClockIdentityUpper = %x",syncPortID.ClockIdentityUpper);
    xil_printf("\r\nsyncPortID.ClockIdentityLower = %x",syncPortID.ClockIdentityLower);
    xil_printf("\r\nsyncPortID.PortNumber = %x\r\n",syncPortID.PortNumber);
#endif
  }
}
void XAvb_DecodeRxSync ( XAvb * InstancePtr , u32 PtpFrameBaseAddr ) { u32 ReadWord = 0 ; XAvb_PortIdentity syncPortID ; XAvb_GetPortIdentity ( InstancePtr -> Config . BaseAddress , PtpFrameBaseAddr , XAVB_PTP_RX_PKT_PORTID_UPPER_OFFSET , & syncPortID ) ; if ( ( InstancePtr -> CurrentBmc . IAmTheRtcMaster == 0 ) && XAvb_ComparePortIdentity ( InstancePtr -> Config . BaseAddress , InstancePtr -> CurrentBmc . SourcePortIdentity , syncPortID ) ) { InstancePtr -> PtpCounters . CounterSyncInterval = 0 ; InstancePtr -> PtpRecords . SlaveSyncTimestamp = XAvb_ReadPtpBuffer ( InstancePtr -> Config . BaseAddress , PtpFrameBaseAddr , XAVB_PTP_PKT_CAPTURED_TIMESTAMP_OFFSET ) - XAVB_RX_MAC_LATENCY_IN_NS ; ReadWord = XAvb_ReorderWord ( XAvb_ReadPtpBuffer ( InstancePtr -> Config . BaseAddress , PtpFrameBaseAddr , XAVB_PTP_RX_PKT_SEQUENCEID_OFFSET ) ) ; InstancePtr -> SequenceIdRecords . SyncSequenceId = ( ReadWord >> 16 ) ; InstancePtr -> latestMDSyncReceive . logMessageInterval = ReadWord & 0x000000ff ; InstancePtr -> latestMDSyncReceive . SyncIntervalDuration = XAvb_ConvertLogMeanToDuration ( InstancePtr -> latestMDSyncReceive . logMessageInterval ) ; } else { xil_printf ( " \r \n " ) ; xil_printf ( " \r \n " ) ; #ifdef DEBUG_XAVB_LEVEL1 xil_printf ( " \r \n " , InstancePtr -> CurrentBmc . SourcePortIdentity . ClockIdentityUpper ) ; xil_printf ( " \r \n " , InstancePtr -> CurrentBmc . SourcePortIdentity . ClockIdentityLower ) ; xil_printf ( " \r \n \r \n " , InstancePtr -> CurrentBmc . SourcePortIdentity . PortNumber ) ; xil_printf ( " \r \n " , syncPortID . ClockIdentityUpper ) ; xil_printf ( " \r \n " , syncPortID . ClockIdentityLower ) ; xil_printf ( " \r \n \r \n " , syncPortID . PortNumber ) ; #endif } }
A function to decode a received PTP Sync Packet
A function to decode a received PTP Sync Packet
/** 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.*/