XilinxProcessorIPLib/drivers/axiethernet/examples/avb/xavb_ptp_packets.c
void XAvb_MasterSendFollowUp(XAvb * InstancePtr) {
  u32 Timestamp        = 0;
  u32 NsOffset         = 0;
  u32 CorrectionField  = 0;
  u32 BufferWord       = 0;

  /** Wait until there are no PTP frames to be transmitted */
  XAvb_WaitOnTxPtpQueue(InstancePtr);

  /** Read the current RTC offset */
  NsOffset = XAvb_ReadReg(InstancePtr->Config.BaseAddress,
                           XAVB_RTC_NANOSEC_OFFSET);

  /** Read the Timestamp and adjust it for the MAC transmit latency */
  Timestamp = XAvb_ReadPtpBuffer(InstancePtr->Config.BaseAddress,
                                  XAVB_PTP_TX_SYNC_OFFSET,
                                  XAVB_PTP_PKT_CAPTURED_TIMESTAMP_OFFSET)
              + XAVB_TX_MAC_LATENCY_IN_NS;

  /** Adjust the Timestamp with current RTC ns offset */
  Timestamp = Timestamp + NsOffset;
  if (Timestamp >= XAVB_ONE_SECOND) {
    Timestamp = Timestamp - XAVB_ONE_SECOND;
  }

  /** Calculate the Correction Field */
  CorrectionField = Timestamp - InstancePtr->PtpRecords.Nanosec;
  if (CorrectionField >= XAVB_ONE_SECOND) {
    CorrectionField = CorrectionField + XAVB_ONE_SECOND;
  }

  /** Format the Correction Field into correct byte positioning for PTP frame
   *  storage in the buffer
   */
  BufferWord = XAvb_ReorderWord(CorrectionField);

  /** Write the Correction Field to the Follow Up frame */
  XAvb_WritePtpBuffer(InstancePtr->Config.BaseAddress,
                       XAVB_PTP_TX_FOLLOW_UP_OFFSET,
                       XAVB_PTP_TX_PKT_CORRECTION_FIELD_OFFSET,
                       BufferWord);

  /** Send the Follow Up Frame! */
  XAvb_WriteReg(InstancePtr->Config.BaseAddress,
                 XAVB_PTP_TX_CONTROL_OFFSET,
                 XAVB_PTP_TX_SEND_FOLLOWUP_FRAME_MASK);

#ifdef DEBUG_XAVB_LEVEL3
  xil_printf("\r\n--------------------------------");
  xil_printf("\r\n---XAvb_MasterSendFollowUp()----");
  xil_printf("\r\n--------------------------------");
  xil_printf("\r\nTimestamp is %x", Timestamp);
  xil_printf("\r\nRTC nano seconds field is %x",
             InstancePtr->PtpRecords.Nanosec);
  xil_printf("\r\nCorrection Field %x", CorrectionField);
#endif

}
/****************************************************************************/
/**
*
* A function to format then request the transmission of a PTP Follow-Up Packet
*
* @param  InstancePtr is a pointer to the XAvb instance to be worked on
*
* @return None.  But the relevant Tx PTP Packet Buffer is written to with the
*                updated PTP fields, and then the Tx PTP Packet Buffer Control
*                Register is written to request the frame transmission.
*
* @note   None.
*
*****************************************************************************/
A function to format then request the transmission of a PTP Follow-Up Packet
A function to format then request the transmission of a PTP Follow - Up Packet
void XAvb_MasterSendFollowUp(XAvb * InstancePtr) {
  u32 Timestamp        = 0;
  u32 NsOffset         = 0;
  u32 CorrectionField  = 0;
  u32 BufferWord       = 0;
  XAvb_WaitOnTxPtpQueue(InstancePtr);
  NsOffset = XAvb_ReadReg(InstancePtr->Config.BaseAddress,
                           XAVB_RTC_NANOSEC_OFFSET);
  Timestamp = XAvb_ReadPtpBuffer(InstancePtr->Config.BaseAddress,
                                  XAVB_PTP_TX_SYNC_OFFSET,
                                  XAVB_PTP_PKT_CAPTURED_TIMESTAMP_OFFSET)
              + XAVB_TX_MAC_LATENCY_IN_NS;
  Timestamp = Timestamp + NsOffset;
  if (Timestamp >= XAVB_ONE_SECOND) {
    Timestamp = Timestamp - XAVB_ONE_SECOND;
  }
  CorrectionField = Timestamp - InstancePtr->PtpRecords.Nanosec;
  if (CorrectionField >= XAVB_ONE_SECOND) {
    CorrectionField = CorrectionField + XAVB_ONE_SECOND;
  }
  BufferWord = XAvb_ReorderWord(CorrectionField);
  XAvb_WritePtpBuffer(InstancePtr->Config.BaseAddress,
                       XAVB_PTP_TX_FOLLOW_UP_OFFSET,
                       XAVB_PTP_TX_PKT_CORRECTION_FIELD_OFFSET,
                       BufferWord);
  XAvb_WriteReg(InstancePtr->Config.BaseAddress,
                 XAVB_PTP_TX_CONTROL_OFFSET,
                 XAVB_PTP_TX_SEND_FOLLOWUP_FRAME_MASK);
#ifdef DEBUG_XAVB_LEVEL3
  xil_printf("\r\n--------------------------------");
  xil_printf("\r\n---XAvb_MasterSendFollowUp()----");
  xil_printf("\r\n--------------------------------");
  xil_printf("\r\nTimestamp is %x", Timestamp);
  xil_printf("\r\nRTC nano seconds field is %x",
             InstancePtr->PtpRecords.Nanosec);
  xil_printf("\r\nCorrection Field %x", CorrectionField);
#endif
}
void XAvb_MasterSendFollowUp ( XAvb * InstancePtr ) { u32 Timestamp = 0 ; u32 NsOffset = 0 ; u32 CorrectionField = 0 ; u32 BufferWord = 0 ; XAvb_WaitOnTxPtpQueue ( InstancePtr ) ; NsOffset = XAvb_ReadReg ( InstancePtr -> Config . BaseAddress , XAVB_RTC_NANOSEC_OFFSET ) ; Timestamp = XAvb_ReadPtpBuffer ( InstancePtr -> Config . BaseAddress , XAVB_PTP_TX_SYNC_OFFSET , XAVB_PTP_PKT_CAPTURED_TIMESTAMP_OFFSET ) + XAVB_TX_MAC_LATENCY_IN_NS ; Timestamp = Timestamp + NsOffset ; if ( Timestamp >= XAVB_ONE_SECOND ) { Timestamp = Timestamp - XAVB_ONE_SECOND ; } CorrectionField = Timestamp - InstancePtr -> PtpRecords . Nanosec ; if ( CorrectionField >= XAVB_ONE_SECOND ) { CorrectionField = CorrectionField + XAVB_ONE_SECOND ; } BufferWord = XAvb_ReorderWord ( CorrectionField ) ; XAvb_WritePtpBuffer ( InstancePtr -> Config . BaseAddress , XAVB_PTP_TX_FOLLOW_UP_OFFSET , XAVB_PTP_TX_PKT_CORRECTION_FIELD_OFFSET , BufferWord ) ; XAvb_WriteReg ( InstancePtr -> Config . BaseAddress , XAVB_PTP_TX_CONTROL_OFFSET , XAVB_PTP_TX_SEND_FOLLOWUP_FRAME_MASK ) ; #ifdef DEBUG_XAVB_LEVEL3 xil_printf ( " \r \n " ) ; xil_printf ( " \r \n " ) ; xil_printf ( " \r \n " ) ; xil_printf ( " \r \n " , Timestamp ) ; xil_printf ( " \r \n " , InstancePtr -> PtpRecords . Nanosec ) ; xil_printf ( " \r \n " , CorrectionField ) ; #endif }
A function to format then request the transmission of a PTP Follow-Up Packet
A function to format then request the transmission of a PTP Follow - Up Packet
/** Wait until there are no PTP frames to be transmitted */ /** Read the current RTC offset */ /** Read the Timestamp and adjust it for the MAC transmit latency */ /** Adjust the Timestamp with current RTC ns offset */ /** Calculate the Correction Field */ /** Format the Correction Field into correct byte positioning for PTP frame
   *  storage in the buffer
   */ /** Write the Correction Field to the Follow Up frame */ /** Send the Follow Up Frame! */