XilinxProcessorIPLib/drivers/axiethernet/examples/avb/xavb_rtc_sync.c
void XAvb_CalcDelay(XAvb * InstancePtr) {
  u32 T4MinusT1 = 0;
  u32 T3MinusT2 = 0;
  u32 Delay     = 0;

  /** 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.
   */
#ifdef DEBUG_XAVB_LEVEL2
    xil_printf("\r\nXAvb_CalcDelay()");
    xil_printf("\r\nt1        %x ", InstancePtr->PtpRecords.PDelayTimestampT1);
    xil_printf("\r\nt2        %x ", InstancePtr->PtpRecords.PDelayTimestampT2);
    xil_printf("\r\nt3        %x ", InstancePtr->PtpRecords.PDelayTimestampT3);
    xil_printf("\r\nt4        %x ", InstancePtr->PtpRecords.PDelayTimestampT4);
#endif

  /** If the nanoseconds count has wrapped, add on 1 second to ensure we get the right answer*/
  if (InstancePtr->PtpRecords.PDelayTimestampT4 < InstancePtr->PtpRecords.PDelayTimestampT1) {
     T4MinusT1 = (InstancePtr->PtpRecords.PDelayTimestampT4 + XAVB_ONE_SECOND)
                - InstancePtr->PtpRecords.PDelayTimestampT1;
  } else {
     T4MinusT1 = InstancePtr->PtpRecords.PDelayTimestampT4
                - InstancePtr->PtpRecords.PDelayTimestampT1;
  }
  /** If the nanoseconds count has wrapped, add on 1 second to ensure we get the right answer*/
  if (InstancePtr->PtpRecords.PDelayTimestampT3 < InstancePtr->PtpRecords.PDelayTimestampT2) {
    T3MinusT2 = (InstancePtr->PtpRecords.PDelayTimestampT3 + XAVB_ONE_SECOND)
                - InstancePtr->PtpRecords.PDelayTimestampT2;
  } else {
     T3MinusT2 = InstancePtr->PtpRecords.PDelayTimestampT3
                - InstancePtr->PtpRecords.PDelayTimestampT2;
  }

  Delay       = (T4MinusT1 - T3MinusT2) >> 1;

  /** For now we are simply going to throw out any absurdly large link delays.*/
  if (Delay < XAVB_NEIGHBOR_PROP_DELAY_THRESH ) {

    InstancePtr->PtpRecords.LinkDelay  = Delay;

    /** The peer has responded to the pDelay_Req and the measured delay is
    * within tolerance: the peer is deemed to be AS capable */
    XAvb_ChangePeerASCapability(InstancePtr, 1);

  } else {
    xil_printf("\r\n Bad Link Delay %d ", Delay);
#ifdef DEBUG_XAVB_LEVEL2
    xil_printf("\r\nXAvb_CalcDelay()");
    xil_printf("\r\nt1        %x ", InstancePtr->PtpRecords.PDelayTimestampT1);
    xil_printf("\r\nt2        %x ", InstancePtr->PtpRecords.PDelayTimestampT2);
    xil_printf("\r\nt3        %x ", InstancePtr->PtpRecords.PDelayTimestampT3);
    xil_printf("\r\nt4        %x ", InstancePtr->PtpRecords.PDelayTimestampT4);
    xil_printf("\r\nLinkDelay %x ", InstancePtr->PtpRecords.LinkDelay);
#endif
  }
}
/*****************************************************************************/
/***
*
* A function to Measure the Link Delay of the local full-duplex Ethernet link
*
* @param  InstancePtr is a pointer to the XAvb instance to be worked on
*
* @return None.
*
* @note   None.
*
*****************************************************************************/
A function to Measure the Link Delay of the local full-duplex Ethernet link
A function to Measure the Link Delay of the local full - duplex Ethernet link
void XAvb_CalcDelay(XAvb * InstancePtr) {
  u32 T4MinusT1 = 0;
  u32 T3MinusT2 = 0;
  u32 Delay     = 0;
#ifdef DEBUG_XAVB_LEVEL2
    xil_printf("\r\nXAvb_CalcDelay()");
    xil_printf("\r\nt1        %x ", InstancePtr->PtpRecords.PDelayTimestampT1);
    xil_printf("\r\nt2        %x ", InstancePtr->PtpRecords.PDelayTimestampT2);
    xil_printf("\r\nt3        %x ", InstancePtr->PtpRecords.PDelayTimestampT3);
    xil_printf("\r\nt4        %x ", InstancePtr->PtpRecords.PDelayTimestampT4);
#endif
  if (InstancePtr->PtpRecords.PDelayTimestampT4 < InstancePtr->PtpRecords.PDelayTimestampT1) {
     T4MinusT1 = (InstancePtr->PtpRecords.PDelayTimestampT4 + XAVB_ONE_SECOND)
                - InstancePtr->PtpRecords.PDelayTimestampT1;
  } else {
     T4MinusT1 = InstancePtr->PtpRecords.PDelayTimestampT4
                - InstancePtr->PtpRecords.PDelayTimestampT1;
  }
  if (InstancePtr->PtpRecords.PDelayTimestampT3 < InstancePtr->PtpRecords.PDelayTimestampT2) {
    T3MinusT2 = (InstancePtr->PtpRecords.PDelayTimestampT3 + XAVB_ONE_SECOND)
                - InstancePtr->PtpRecords.PDelayTimestampT2;
  } else {
     T3MinusT2 = InstancePtr->PtpRecords.PDelayTimestampT3
                - InstancePtr->PtpRecords.PDelayTimestampT2;
  }
  Delay       = (T4MinusT1 - T3MinusT2) >> 1;
  if (Delay < XAVB_NEIGHBOR_PROP_DELAY_THRESH ) {
    InstancePtr->PtpRecords.LinkDelay  = Delay;
    XAvb_ChangePeerASCapability(InstancePtr, 1);
  } else {
    xil_printf("\r\n Bad Link Delay %d ", Delay);
#ifdef DEBUG_XAVB_LEVEL2
    xil_printf("\r\nXAvb_CalcDelay()");
    xil_printf("\r\nt1        %x ", InstancePtr->PtpRecords.PDelayTimestampT1);
    xil_printf("\r\nt2        %x ", InstancePtr->PtpRecords.PDelayTimestampT2);
    xil_printf("\r\nt3        %x ", InstancePtr->PtpRecords.PDelayTimestampT3);
    xil_printf("\r\nt4        %x ", InstancePtr->PtpRecords.PDelayTimestampT4);
    xil_printf("\r\nLinkDelay %x ", InstancePtr->PtpRecords.LinkDelay);
#endif
  }
}
void XAvb_CalcDelay ( XAvb * InstancePtr ) { u32 T4MinusT1 = 0 ; u32 T3MinusT2 = 0 ; u32 Delay = 0 ; #ifdef DEBUG_XAVB_LEVEL2 xil_printf ( " \r \n " ) ; xil_printf ( " \r \n " , InstancePtr -> PtpRecords . PDelayTimestampT1 ) ; xil_printf ( " \r \n " , InstancePtr -> PtpRecords . PDelayTimestampT2 ) ; xil_printf ( " \r \n " , InstancePtr -> PtpRecords . PDelayTimestampT3 ) ; xil_printf ( " \r \n " , InstancePtr -> PtpRecords . PDelayTimestampT4 ) ; #endif if ( InstancePtr -> PtpRecords . PDelayTimestampT4 < InstancePtr -> PtpRecords . PDelayTimestampT1 ) { T4MinusT1 = ( InstancePtr -> PtpRecords . PDelayTimestampT4 + XAVB_ONE_SECOND ) - InstancePtr -> PtpRecords . PDelayTimestampT1 ; } else { T4MinusT1 = InstancePtr -> PtpRecords . PDelayTimestampT4 - InstancePtr -> PtpRecords . PDelayTimestampT1 ; } if ( InstancePtr -> PtpRecords . PDelayTimestampT3 < InstancePtr -> PtpRecords . PDelayTimestampT2 ) { T3MinusT2 = ( InstancePtr -> PtpRecords . PDelayTimestampT3 + XAVB_ONE_SECOND ) - InstancePtr -> PtpRecords . PDelayTimestampT2 ; } else { T3MinusT2 = InstancePtr -> PtpRecords . PDelayTimestampT3 - InstancePtr -> PtpRecords . PDelayTimestampT2 ; } Delay = ( T4MinusT1 - T3MinusT2 ) >> 1 ; if ( Delay < XAVB_NEIGHBOR_PROP_DELAY_THRESH ) { InstancePtr -> PtpRecords . LinkDelay = Delay ; XAvb_ChangePeerASCapability ( InstancePtr , 1 ) ; } else { xil_printf ( " \r \n " , Delay ) ; #ifdef DEBUG_XAVB_LEVEL2 xil_printf ( " \r \n " ) ; xil_printf ( " \r \n " , InstancePtr -> PtpRecords . PDelayTimestampT1 ) ; xil_printf ( " \r \n " , InstancePtr -> PtpRecords . PDelayTimestampT2 ) ; xil_printf ( " \r \n " , InstancePtr -> PtpRecords . PDelayTimestampT3 ) ; xil_printf ( " \r \n " , InstancePtr -> PtpRecords . PDelayTimestampT4 ) ; xil_printf ( " \r \n " , InstancePtr -> PtpRecords . LinkDelay ) ; #endif } }
A function to Measure the Link Delay of the local full-duplex Ethernet link
A function to Measure the Link Delay of the local full - duplex Ethernet link
/** 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 */