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

  XAvb_PortIdentity followUpPortID;

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

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

    /** Capture the Follow Up SequenceID */
    InstancePtr->SequenceIdRecords.FollowUpSequenceId
       = XAvb_ReorderWord(XAvb_ReadPtpBuffer(InstancePtr->Config.BaseAddress,
                                              PtpFrameBaseAddr,
                                              XAVB_PTP_RX_PKT_SEQUENCEID_OFFSET))
         >> 16;

    /** SequenceID in Follow Up Frame should always match that of the
     * Sync Frame */
    if (InstancePtr->SequenceIdRecords.FollowUpSequenceId
         == InstancePtr->SequenceIdRecords.SyncSequenceId) {

      /** Capture the correction field from follow up frame */
      InstancePtr->PtpRecords.MasterCorrectionField
         = XAvb_ReorderWord(XAvb_ReadPtpBuffer(InstancePtr->Config.BaseAddress,
                                                PtpFrameBaseAddr,
                                                XAVB_PTP_RX_PKT_CORRECTION_FIELD_OFFSET));

      /** Perform the Course RTC Offset correction for every Sync /
       * FollowUp pair */
      XAvb_CalcRtcOffset(InstancePtr,
                         PtpFrameBaseAddr);

      /** Every n Sync / FollowUp pairs, we are going to calculate a
       * corrected increment rate of RTC */
      if ((InstancePtr->PtpCounters.CounterSyncEvents & 0xF)
          == (XAVB_NUM_SYNC_FU_PAIR_CALC_RTC_INCREMENT - 1)) {

        /** Reset the CounterSyncEvents Counter */
        InstancePtr->PtpCounters.CounterSyncEvents = 0x0;

        /** Capture the Sequence ID of the Follow Up frame */
        InstancePtr->SequenceIdRecords.NewSyncSequenceId
            = XAvb_ReadPtpBuffer(InstancePtr->Config.BaseAddress,
                                  PtpFrameBaseAddr,
                                  XAVB_PTP_RX_PKT_SEQUENCEID_OFFSET);

        InstancePtr->SequenceIdRecords.NewSyncSequenceId
            = (XAvb_ReorderWord
                   (InstancePtr->SequenceIdRecords.NewSyncSequenceId)
               ) >> 16;

        /** Perform the RTC increment rate adjustment calculation */
        XAvb_UpdateRtcIncrement(InstancePtr);

        /** Sample Sync Frame Time sent (as estimated by the slave) for
         * comparison in ten more repetition's time */
        InstancePtr->PtpRecords.OldSlaveTime
            = InstancePtr->PtpRecords.NewSlaveTime;

        /** Sample Sync Frame Time sent (as calculated by the master)
         * for comparison in ten more repetition's time */
        InstancePtr->PtpRecords.OldMasterTime
            = InstancePtr->PtpRecords.NewMasterTime;

        /** Sample the current Follow Up Sequence ID for comparison in
         * ten more repetition's time */
        InstancePtr->SequenceIdRecords.OldSyncSequenceId
            = InstancePtr->SequenceIdRecords.NewSyncSequenceId;

      } else {
        InstancePtr->PtpCounters.CounterSyncEvents
             = InstancePtr->PtpCounters.CounterSyncEvents + 1;
      }
    } else {
      xil_printf("SequenceIDs on RxFollowup don't match.\r\n");
    }
  } else {
    xil_printf("\r\nXAvb_DecodeRxFollowUp()");
    xil_printf("\r\nFollowUp ignored due to unmatched SourcePortID\r\n");
  }
}
/****************************************************************************/
/**
*
* A function to decode a received PTP Follow-up 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 Follow-up Packet
A function to decode a received PTP Follow - up Packet
void XAvb_DecodeRxFollowUp(XAvb * InstancePtr,
                           u32    PtpFrameBaseAddr) {
  XAvb_PortIdentity followUpPortID;
  XAvb_GetPortIdentity(InstancePtr->Config.BaseAddress, PtpFrameBaseAddr,
                       XAVB_PTP_RX_PKT_PORTID_UPPER_OFFSET, &followUpPortID);
  if ( (InstancePtr->CurrentBmc.IAmTheRtcMaster == 0) &&
        XAvb_ComparePortIdentity(InstancePtr->Config.BaseAddress,
                                 InstancePtr->CurrentBmc.SourcePortIdentity,
                                 followUpPortID) ) {
    InstancePtr->SequenceIdRecords.FollowUpSequenceId
       = XAvb_ReorderWord(XAvb_ReadPtpBuffer(InstancePtr->Config.BaseAddress,
                                              PtpFrameBaseAddr,
                                              XAVB_PTP_RX_PKT_SEQUENCEID_OFFSET))
         >> 16;
    if (InstancePtr->SequenceIdRecords.FollowUpSequenceId
         == InstancePtr->SequenceIdRecords.SyncSequenceId) {
      InstancePtr->PtpRecords.MasterCorrectionField
         = XAvb_ReorderWord(XAvb_ReadPtpBuffer(InstancePtr->Config.BaseAddress,
                                                PtpFrameBaseAddr,
                                                XAVB_PTP_RX_PKT_CORRECTION_FIELD_OFFSET));
      XAvb_CalcRtcOffset(InstancePtr,
                         PtpFrameBaseAddr);
      if ((InstancePtr->PtpCounters.CounterSyncEvents & 0xF)
          == (XAVB_NUM_SYNC_FU_PAIR_CALC_RTC_INCREMENT - 1)) {
        InstancePtr->PtpCounters.CounterSyncEvents = 0x0;
        InstancePtr->SequenceIdRecords.NewSyncSequenceId
            = XAvb_ReadPtpBuffer(InstancePtr->Config.BaseAddress,
                                  PtpFrameBaseAddr,
                                  XAVB_PTP_RX_PKT_SEQUENCEID_OFFSET);
        InstancePtr->SequenceIdRecords.NewSyncSequenceId
            = (XAvb_ReorderWord
                   (InstancePtr->SequenceIdRecords.NewSyncSequenceId)
               ) >> 16;
        XAvb_UpdateRtcIncrement(InstancePtr);
        InstancePtr->PtpRecords.OldSlaveTime
            = InstancePtr->PtpRecords.NewSlaveTime;
        InstancePtr->PtpRecords.OldMasterTime
            = InstancePtr->PtpRecords.NewMasterTime;
        InstancePtr->SequenceIdRecords.OldSyncSequenceId
            = InstancePtr->SequenceIdRecords.NewSyncSequenceId;
      } else {
        InstancePtr->PtpCounters.CounterSyncEvents
             = InstancePtr->PtpCounters.CounterSyncEvents + 1;
      }
    } else {
      xil_printf("SequenceIDs on RxFollowup don't match.\r\n");
    }
  } else {
    xil_printf("\r\nXAvb_DecodeRxFollowUp()");
    xil_printf("\r\nFollowUp ignored due to unmatched SourcePortID\r\n");
  }
}
void XAvb_DecodeRxFollowUp ( XAvb * InstancePtr , u32 PtpFrameBaseAddr ) { XAvb_PortIdentity followUpPortID ; XAvb_GetPortIdentity ( InstancePtr -> Config . BaseAddress , PtpFrameBaseAddr , XAVB_PTP_RX_PKT_PORTID_UPPER_OFFSET , & followUpPortID ) ; if ( ( InstancePtr -> CurrentBmc . IAmTheRtcMaster == 0 ) && XAvb_ComparePortIdentity ( InstancePtr -> Config . BaseAddress , InstancePtr -> CurrentBmc . SourcePortIdentity , followUpPortID ) ) { InstancePtr -> SequenceIdRecords . FollowUpSequenceId = XAvb_ReorderWord ( XAvb_ReadPtpBuffer ( InstancePtr -> Config . BaseAddress , PtpFrameBaseAddr , XAVB_PTP_RX_PKT_SEQUENCEID_OFFSET ) ) >> 16 ; if ( InstancePtr -> SequenceIdRecords . FollowUpSequenceId == InstancePtr -> SequenceIdRecords . SyncSequenceId ) { InstancePtr -> PtpRecords . MasterCorrectionField = XAvb_ReorderWord ( XAvb_ReadPtpBuffer ( InstancePtr -> Config . BaseAddress , PtpFrameBaseAddr , XAVB_PTP_RX_PKT_CORRECTION_FIELD_OFFSET ) ) ; XAvb_CalcRtcOffset ( InstancePtr , PtpFrameBaseAddr ) ; if ( ( InstancePtr -> PtpCounters . CounterSyncEvents & 0xF ) == ( XAVB_NUM_SYNC_FU_PAIR_CALC_RTC_INCREMENT - 1 ) ) { InstancePtr -> PtpCounters . CounterSyncEvents = 0x0 ; InstancePtr -> SequenceIdRecords . NewSyncSequenceId = XAvb_ReadPtpBuffer ( InstancePtr -> Config . BaseAddress , PtpFrameBaseAddr , XAVB_PTP_RX_PKT_SEQUENCEID_OFFSET ) ; InstancePtr -> SequenceIdRecords . NewSyncSequenceId = ( XAvb_ReorderWord ( InstancePtr -> SequenceIdRecords . NewSyncSequenceId ) ) >> 16 ; XAvb_UpdateRtcIncrement ( InstancePtr ) ; InstancePtr -> PtpRecords . OldSlaveTime = InstancePtr -> PtpRecords . NewSlaveTime ; InstancePtr -> PtpRecords . OldMasterTime = InstancePtr -> PtpRecords . NewMasterTime ; InstancePtr -> SequenceIdRecords . OldSyncSequenceId = InstancePtr -> SequenceIdRecords . NewSyncSequenceId ; } else { InstancePtr -> PtpCounters . CounterSyncEvents = InstancePtr -> PtpCounters . CounterSyncEvents + 1 ; } } else { xil_printf ( " \r \n " ) ; } } else { xil_printf ( " \r \n " ) ; xil_printf ( " \r \n \r \n " ) ; } }
A function to decode a received PTP Follow-up Packet
A function to decode a received PTP Follow - up Packet
/** 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 */