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

   XAvb_PortIdentity portId;

  /** Has a valid PDelayResp packet been received since the
   *  last PDelayReq packet was sent? */
  if( !InstancePtr->StateMachineData.rcvdPDelayResp ) {
    /*xil_printf("Error: Received a PDelayRespFollowUp before receiving a PDelayResp\r\n");*/
    return;
  }

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

  /** Get the sourcePortIdentity of the sender */
  XAvb_GetPortIdentity(InstancePtr->Config.BaseAddress, PtpFrameBaseAddr,
                       XAVB_PTP_RX_PKT_PORTID_UPPER_OFFSET,
                       &portId);

  /** The sourcePortIdentity of the PDelayRespFollowUp should
   *  match that of the last PDelayResp packet received */
  if( !XAvb_ComparePortIdentity(InstancePtr->Config.BaseAddress,
                                portId,
                                InstancePtr->StateMachineData.respPortIdentity) ) {
    xil_printf("Error: sourcePortIdentity of PDelayRespFollowUp doesn't match PDelayResp\r\n");
    return;
  }

  /** Get the requestingPortIdentity of the sender */
  XAvb_GetPortIdentity(InstancePtr->Config.BaseAddress, PtpFrameBaseAddr,
                       XAVB_PTP_RX_PKT_REQ_PORTID_UPPER_OFFSET,
                       &portId);

  /** The requestingPortIdentity of the PDelayRespFollowUp should
   *  match that of the last PDelayResp packet received */
  if( !XAvb_ComparePortIdentity(InstancePtr->Config.BaseAddress,
                                portId,
                                InstancePtr->StateMachineData.respReqPortIdentity) ) {
    xil_printf("Error: reqPortID of PDelayRespFollowUp doesn't match PDelayResp\r\n");
    return;
  }

  /** SequenceID of PDelayRespFollowUp Frame should always match that of
   * the PDelayResp Frame and the original PDelayReq Frame. */
  if (InstancePtr->SequenceIdRecords.PDelayFollowUpSequenceId ==
      InstancePtr->SequenceIdRecords.PDelayRespSequenceId) {

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

    /** Capture the timestamp for transmit time of PDelayResp at Master
     * (t3) */
    InstancePtr->PtpRecords.PDelayTimestampT3 =
        XAvb_CaptureNanoSec(InstancePtr->Config.BaseAddress, PtpFrameBaseAddr);

    /** Now we know t1, t2, t3 and t4, calculate the link delay */
    XAvb_CalcDelay(InstancePtr);

  } else {
    xil_printf("Error: seqID of PDelayRespFollowUp doesn't match PDelayResp\r\n");
  }
}
/****************************************************************************/
/**
*
* A function to decode a received PDelayRespFollowUp 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 PDelayRespFollowUp Packet
A function to decode a received PDelayRespFollowUp Packet
void XAvb_DecodeRxPDelayRespFollowUp(XAvb * InstancePtr,
                                     u32    PtpFrameBaseAddr) {
   XAvb_PortIdentity portId;
  if( !InstancePtr->StateMachineData.rcvdPDelayResp ) {
    return;
  }
  InstancePtr->SequenceIdRecords.PDelayFollowUpSequenceId =
      XAvb_ReorderWord(XAvb_ReadPtpBuffer(InstancePtr->Config.BaseAddress,
                                           PtpFrameBaseAddr,
                                           XAVB_PTP_RX_PKT_SEQUENCEID_OFFSET)) >> 16;
  XAvb_GetPortIdentity(InstancePtr->Config.BaseAddress, PtpFrameBaseAddr,
                       XAVB_PTP_RX_PKT_PORTID_UPPER_OFFSET,
                       &portId);
  if( !XAvb_ComparePortIdentity(InstancePtr->Config.BaseAddress,
                                portId,
                                InstancePtr->StateMachineData.respPortIdentity) ) {
    xil_printf("Error: sourcePortIdentity of PDelayRespFollowUp doesn't match PDelayResp\r\n");
    return;
  }
  XAvb_GetPortIdentity(InstancePtr->Config.BaseAddress, PtpFrameBaseAddr,
                       XAVB_PTP_RX_PKT_REQ_PORTID_UPPER_OFFSET,
                       &portId);
  if( !XAvb_ComparePortIdentity(InstancePtr->Config.BaseAddress,
                                portId,
                                InstancePtr->StateMachineData.respReqPortIdentity) ) {
    xil_printf("Error: reqPortID of PDelayRespFollowUp doesn't match PDelayResp\r\n");
    return;
  }
  if (InstancePtr->SequenceIdRecords.PDelayFollowUpSequenceId ==
      InstancePtr->SequenceIdRecords.PDelayRespSequenceId) {
    InstancePtr->StateMachineData.rcvdPDelayRespFollowUp = 1;
    InstancePtr->PtpRecords.PDelayTimestampT3 =
        XAvb_CaptureNanoSec(InstancePtr->Config.BaseAddress, PtpFrameBaseAddr);
    XAvb_CalcDelay(InstancePtr);
  } else {
    xil_printf("Error: seqID of PDelayRespFollowUp doesn't match PDelayResp\r\n");
  }
}
void XAvb_DecodeRxPDelayRespFollowUp ( XAvb * InstancePtr , u32 PtpFrameBaseAddr ) { XAvb_PortIdentity portId ; if ( ! InstancePtr -> StateMachineData . rcvdPDelayResp ) { return ; } InstancePtr -> SequenceIdRecords . PDelayFollowUpSequenceId = XAvb_ReorderWord ( XAvb_ReadPtpBuffer ( InstancePtr -> Config . BaseAddress , PtpFrameBaseAddr , XAVB_PTP_RX_PKT_SEQUENCEID_OFFSET ) ) >> 16 ; XAvb_GetPortIdentity ( InstancePtr -> Config . BaseAddress , PtpFrameBaseAddr , XAVB_PTP_RX_PKT_PORTID_UPPER_OFFSET , & portId ) ; if ( ! XAvb_ComparePortIdentity ( InstancePtr -> Config . BaseAddress , portId , InstancePtr -> StateMachineData . respPortIdentity ) ) { xil_printf ( " \r \n " ) ; return ; } XAvb_GetPortIdentity ( InstancePtr -> Config . BaseAddress , PtpFrameBaseAddr , XAVB_PTP_RX_PKT_REQ_PORTID_UPPER_OFFSET , & portId ) ; if ( ! XAvb_ComparePortIdentity ( InstancePtr -> Config . BaseAddress , portId , InstancePtr -> StateMachineData . respReqPortIdentity ) ) { xil_printf ( " \r \n " ) ; return ; } if ( InstancePtr -> SequenceIdRecords . PDelayFollowUpSequenceId == InstancePtr -> SequenceIdRecords . PDelayRespSequenceId ) { InstancePtr -> StateMachineData . rcvdPDelayRespFollowUp = 1 ; InstancePtr -> PtpRecords . PDelayTimestampT3 = XAvb_CaptureNanoSec ( InstancePtr -> Config . BaseAddress , PtpFrameBaseAddr ) ; XAvb_CalcDelay ( InstancePtr ) ; } else { xil_printf ( " \r \n " ) ; } }
A function to decode a received PDelayRespFollowUp Packet
A function to decode a received PDelayRespFollowUp Packet
/** Has a valid PDelayResp packet been received since the
   *  last PDelayReq packet was sent? */ /*xil_printf("Error: Received a PDelayRespFollowUp before receiving a PDelayResp\r\n");*/ /** 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 */