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

  /** Have we already seen a PDelayResp since the last
   *  PDelayReq was sent? If so, ignore the packet */
  if( InstancePtr->StateMachineData.rcvdPDelayResp ) {
    xil_printf("Error: already saw a PDelayResp since the last PDelayReq was sent\r\n");
    return;
  }

  /** Find the ClockIdentity of the Sender */
  XAvb_GetPortIdentity(InstancePtr->Config.BaseAddress, PtpFrameBaseAddr,
                       XAVB_PTP_RX_PKT_PORTID_UPPER_OFFSET,
                       &InstancePtr->StateMachineData.respPortIdentity);

  /** Is the PDelayResp message from ourself?  If so, the Peer
   *  is most likely a dumb hub and should be considered not
   *  ASCapable */
  if( XAvb_ComparePortIdentity(InstancePtr->Config.BaseAddress,
                               InstancePtr->portIdLocal,
                               InstancePtr->StateMachineData.respPortIdentity) ) {

    XAvb_ChangePeerASCapability(InstancePtr, 0);

    xil_printf("\r\nXAvb_DecodeRxPDelayResp():The peer is no longer ASCapable ");
    xil_printf("\r\nXAvb_DecodeRxPDelayResp():Saw a PDelayResp from myself\r\n");
    return;

  }

  /** Capture the requestingPortIdentity */
  XAvb_GetPortIdentity(InstancePtr->Config.BaseAddress, PtpFrameBaseAddr,
                       XAVB_PTP_RX_PKT_REQ_PORTID_UPPER_OFFSET,
                       &InstancePtr->StateMachineData.respReqPortIdentity);

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

  /** Verify that the requestingPortIdentity matches our
   *  portIdentity */
  if( !XAvb_ComparePortIdentity(InstancePtr->Config.BaseAddress,
                           InstancePtr->portIdLocal,
                           InstancePtr->StateMachineData.respReqPortIdentity) ) {
    xil_printf("Error: PDelayResp reqPortID doesn't match our portID\r\n");
    return;
  }

  /** Only process if the received frame's sequenceId matches
   *  the sequenceId sent in the last pDelay_Req packet */
  if( (InstancePtr->SequenceIdRecords.PDelayReqSequenceId ==
       InstancePtr->SequenceIdRecords.PDelayRespSequenceId) ) {

    /** Mark this as a valid PDelayResp packet */
    InstancePtr->StateMachineData.rcvdPDelayResp = 1;

    /** Capture timestamp for receipt time of PDelayReq at Master (t2) */
    InstancePtr->PtpRecords.PDelayTimestampT2 =
        XAvb_CaptureNanoSec(InstancePtr->Config.BaseAddress,
                            PtpFrameBaseAddr);

    /** Capture timestamp for receipt time of PDelayResp at Slave (t4) and adjust
     *  it for MAC receive latency */
    InstancePtr->PtpRecords.PDelayTimestampT4 =
        XAvb_ReadPtpBuffer(InstancePtr->Config.BaseAddress,
                            PtpFrameBaseAddr,
                            XAVB_PTP_PKT_CAPTURED_TIMESTAMP_OFFSET)
        - XAVB_RX_MAC_LATENCY_IN_NS;
  } else {
    xil_printf("Error: PDelayResp seqID's don't match\r\n");
  }
}
/****************************************************************************/
/**
*
* A function to decode a received PDelayResp 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 PDelayResp Packet
A function to decode a received PDelayResp Packet
void XAvb_DecodeRxPDelayResp(XAvb * InstancePtr,
                             u32    PtpFrameBaseAddr) {
  if( InstancePtr->StateMachineData.rcvdPDelayResp ) {
    xil_printf("Error: already saw a PDelayResp since the last PDelayReq was sent\r\n");
    return;
  }
  XAvb_GetPortIdentity(InstancePtr->Config.BaseAddress, PtpFrameBaseAddr,
                       XAVB_PTP_RX_PKT_PORTID_UPPER_OFFSET,
                       &InstancePtr->StateMachineData.respPortIdentity);
  if( XAvb_ComparePortIdentity(InstancePtr->Config.BaseAddress,
                               InstancePtr->portIdLocal,
                               InstancePtr->StateMachineData.respPortIdentity) ) {
    XAvb_ChangePeerASCapability(InstancePtr, 0);
    xil_printf("\r\nXAvb_DecodeRxPDelayResp():The peer is no longer ASCapable ");
    xil_printf("\r\nXAvb_DecodeRxPDelayResp():Saw a PDelayResp from myself\r\n");
    return;
  }
  XAvb_GetPortIdentity(InstancePtr->Config.BaseAddress, PtpFrameBaseAddr,
                       XAVB_PTP_RX_PKT_REQ_PORTID_UPPER_OFFSET,
                       &InstancePtr->StateMachineData.respReqPortIdentity);
  InstancePtr->SequenceIdRecords.PDelayRespSequenceId =
      XAvb_ReorderWord(XAvb_ReadPtpBuffer(InstancePtr->Config.BaseAddress,
                       PtpFrameBaseAddr,
                       XAVB_PTP_RX_PKT_SEQUENCEID_OFFSET)) >> 16;
  if( !XAvb_ComparePortIdentity(InstancePtr->Config.BaseAddress,
                           InstancePtr->portIdLocal,
                           InstancePtr->StateMachineData.respReqPortIdentity) ) {
    xil_printf("Error: PDelayResp reqPortID doesn't match our portID\r\n");
    return;
  }
  if( (InstancePtr->SequenceIdRecords.PDelayReqSequenceId ==
       InstancePtr->SequenceIdRecords.PDelayRespSequenceId) ) {
    InstancePtr->StateMachineData.rcvdPDelayResp = 1;
    InstancePtr->PtpRecords.PDelayTimestampT2 =
        XAvb_CaptureNanoSec(InstancePtr->Config.BaseAddress,
                            PtpFrameBaseAddr);
    InstancePtr->PtpRecords.PDelayTimestampT4 =
        XAvb_ReadPtpBuffer(InstancePtr->Config.BaseAddress,
                            PtpFrameBaseAddr,
                            XAVB_PTP_PKT_CAPTURED_TIMESTAMP_OFFSET)
        - XAVB_RX_MAC_LATENCY_IN_NS;
  } else {
    xil_printf("Error: PDelayResp seqID's don't match\r\n");
  }
}
void XAvb_DecodeRxPDelayResp ( XAvb * InstancePtr , u32 PtpFrameBaseAddr ) { if ( InstancePtr -> StateMachineData . rcvdPDelayResp ) { xil_printf ( " \r \n " ) ; return ; } XAvb_GetPortIdentity ( InstancePtr -> Config . BaseAddress , PtpFrameBaseAddr , XAVB_PTP_RX_PKT_PORTID_UPPER_OFFSET , & InstancePtr -> StateMachineData . respPortIdentity ) ; if ( XAvb_ComparePortIdentity ( InstancePtr -> Config . BaseAddress , InstancePtr -> portIdLocal , InstancePtr -> StateMachineData . respPortIdentity ) ) { XAvb_ChangePeerASCapability ( InstancePtr , 0 ) ; xil_printf ( " \r \n " ) ; xil_printf ( " \r \n \r \n " ) ; return ; } XAvb_GetPortIdentity ( InstancePtr -> Config . BaseAddress , PtpFrameBaseAddr , XAVB_PTP_RX_PKT_REQ_PORTID_UPPER_OFFSET , & InstancePtr -> StateMachineData . respReqPortIdentity ) ; InstancePtr -> SequenceIdRecords . PDelayRespSequenceId = XAvb_ReorderWord ( XAvb_ReadPtpBuffer ( InstancePtr -> Config . BaseAddress , PtpFrameBaseAddr , XAVB_PTP_RX_PKT_SEQUENCEID_OFFSET ) ) >> 16 ; if ( ! XAvb_ComparePortIdentity ( InstancePtr -> Config . BaseAddress , InstancePtr -> portIdLocal , InstancePtr -> StateMachineData . respReqPortIdentity ) ) { xil_printf ( " \r \n " ) ; return ; } if ( ( InstancePtr -> SequenceIdRecords . PDelayReqSequenceId == InstancePtr -> SequenceIdRecords . PDelayRespSequenceId ) ) { InstancePtr -> StateMachineData . rcvdPDelayResp = 1 ; InstancePtr -> PtpRecords . PDelayTimestampT2 = XAvb_CaptureNanoSec ( InstancePtr -> Config . BaseAddress , PtpFrameBaseAddr ) ; InstancePtr -> PtpRecords . PDelayTimestampT4 = XAvb_ReadPtpBuffer ( InstancePtr -> Config . BaseAddress , PtpFrameBaseAddr , XAVB_PTP_PKT_CAPTURED_TIMESTAMP_OFFSET ) - XAVB_RX_MAC_LATENCY_IN_NS ; } else { xil_printf ( " \r \n " ) ; } }
A function to decode a received PDelayResp Packet
A function to decode a received PDelayResp Packet
/** 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 */