XilinxProcessorIPLib/drivers/axiethernet/examples/avb/xavb_ptp_packets.c
void XAvb_MasterSendSync(XAvb * InstancePtr) {
  u32 Epoch       = 0;
  u32 Sec         = 0;
  u32 SequenceId  = 0;
  u32 BufferWord  = 0;

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

  /** Increment the sequenceId in the Sync frame */
  SequenceId = XAvb_IncSequenceId(InstancePtr->Config.BaseAddress,
                                  XAVB_PTP_TX_SYNC_OFFSET);

  /** Read the current RTC Offset values */
  InstancePtr->PtpRecords.Nanosec
      = XAvb_ReadReg(InstancePtr->Config.BaseAddress,
                      XAVB_RTC_NANOSEC_VALUE_OFFSET);

  Sec    = XAvb_ReadReg(InstancePtr->Config.BaseAddress,
                         XAVB_RTC_SEC_LOWER_VALUE_OFFSET);

  Epoch  = XAvb_ReadReg(InstancePtr->Config.BaseAddress,
                         XAVB_RTC_SEC_UPPER_VALUE_OFFSET);

  /** Send the Sync Frame! */
  XAvb_WriteReg(InstancePtr->Config.BaseAddress, XAVB_PTP_TX_CONTROL_OFFSET,
                 XAVB_PTP_TX_SEND_SYNC_FRAME_MASK);


  /** Now some pre-work on the Follow-Up Frame
   *-----------------------------------------
   *
   * Write the same sequenceId to the Follow-up frame */
  BufferWord =  XAvb_ReadPtpBuffer(InstancePtr->Config.BaseAddress,
                                    XAVB_PTP_TX_FOLLOW_UP_OFFSET,
                                    XAVB_PTP_TX_PKT_SEQUENCEID_OFFSET);

  BufferWord = (BufferWord & 0xFFFF0000) | (SequenceId & 0x0000FFFF);

  XAvb_WritePtpBuffer(InstancePtr->Config.BaseAddress,
                       XAVB_PTP_TX_FOLLOW_UP_OFFSET,
                       XAVB_PTP_TX_PKT_SEQUENCEID_OFFSET,
                       BufferWord);


  /** Format the Timestamp (RTC) into correct byte positioning.
   * Note: this is how the Timestamp is stored in
   * the PTP frame itself (transmitted MSB of Epoch first):
   *
   * |----------------|----------------|----------------|----------------|
   * | seconds[23:16] | seconds[31:24] |   epoch[7:0]   |   epoch[15:8]  |
   * |----------------|----------------|----------------|----------------|
   * | nanosec[23:16] | nanosec[31:24] |  seconds[7:0]  |  seconds[15:8] |
   * |----------------|----------------|----------------|----------------|
   * |      0's       |      0's       |  nanosec[7:0]  |  nanosec[15:8] |
   * |----------------|----------------|----------------|----------------|
   */

  BufferWord = XAvb_ReorderWord((Epoch<<16) | (Sec>>16));

  /** Write the Timestamp (RTC) to the Follow-up frame */
  XAvb_WritePtpBuffer(InstancePtr->Config.BaseAddress,
                       XAVB_PTP_TX_FOLLOW_UP_OFFSET,
                       XAVB_PTP_TX_PKT_TIMESTAMP_UPPER_OFFSET,
                       BufferWord);

  BufferWord = XAvb_ReorderWord((Sec<<16) |
                                (InstancePtr->PtpRecords.Nanosec>>16));

  XAvb_WritePtpBuffer(InstancePtr->Config.BaseAddress,
                       XAVB_PTP_TX_FOLLOW_UP_OFFSET,
                       XAVB_PTP_TX_PKT_TIMESTAMP_MID_OFFSET,
                       BufferWord);

  BufferWord = XAvb_ReorderWord(InstancePtr->PtpRecords.Nanosec<<16);

  XAvb_WritePtpBuffer(InstancePtr->Config.BaseAddress,
                       XAVB_PTP_TX_FOLLOW_UP_OFFSET,
                       XAVB_PTP_TX_PKT_TIMESTAMP_LOWER_OFFSET,
                       BufferWord);

#ifdef DEBUG_XAVB_LEVEL3
  xil_printf("\r\n--------------------------------");
  xil_printf("\r\n-----XAvb_MasterSendSync()------");
  xil_printf("\r\n--------------------------------");
  xil_printf("\r\n--------------RTC---------------");
  xil_printf("\r\nRTC nanosec field is %x", InstancePtr->PtpRecords.Nanosec);
  xil_printf("\r\nRTC seconds field is %x", Sec);
  xil_printf("\r\nRTC epoch   field is %x", Epoch);
  xil_printf("\r\n--------------------------------");
  xil_printf("\r\nsequenceId is %x", SequenceId);
#endif

}
/****************************************************************************/
/**
*
* A function to format then request the transmission of a PTP Sync 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 Sync Packet
A function to format then request the transmission of a PTP Sync Packet
void XAvb_MasterSendSync(XAvb * InstancePtr) {
  u32 Epoch       = 0;
  u32 Sec         = 0;
  u32 SequenceId  = 0;
  u32 BufferWord  = 0;
  XAvb_WaitOnTxPtpQueue(InstancePtr);
  SequenceId = XAvb_IncSequenceId(InstancePtr->Config.BaseAddress,
                                  XAVB_PTP_TX_SYNC_OFFSET);
  InstancePtr->PtpRecords.Nanosec
      = XAvb_ReadReg(InstancePtr->Config.BaseAddress,
                      XAVB_RTC_NANOSEC_VALUE_OFFSET);
  Sec    = XAvb_ReadReg(InstancePtr->Config.BaseAddress,
                         XAVB_RTC_SEC_LOWER_VALUE_OFFSET);
  Epoch  = XAvb_ReadReg(InstancePtr->Config.BaseAddress,
                         XAVB_RTC_SEC_UPPER_VALUE_OFFSET);
  XAvb_WriteReg(InstancePtr->Config.BaseAddress, XAVB_PTP_TX_CONTROL_OFFSET,
                 XAVB_PTP_TX_SEND_SYNC_FRAME_MASK);
  BufferWord =  XAvb_ReadPtpBuffer(InstancePtr->Config.BaseAddress,
                                    XAVB_PTP_TX_FOLLOW_UP_OFFSET,
                                    XAVB_PTP_TX_PKT_SEQUENCEID_OFFSET);
  BufferWord = (BufferWord & 0xFFFF0000) | (SequenceId & 0x0000FFFF);
  XAvb_WritePtpBuffer(InstancePtr->Config.BaseAddress,
                       XAVB_PTP_TX_FOLLOW_UP_OFFSET,
                       XAVB_PTP_TX_PKT_SEQUENCEID_OFFSET,
                       BufferWord);
  BufferWord = XAvb_ReorderWord((Epoch<<16) | (Sec>>16));
  XAvb_WritePtpBuffer(InstancePtr->Config.BaseAddress,
                       XAVB_PTP_TX_FOLLOW_UP_OFFSET,
                       XAVB_PTP_TX_PKT_TIMESTAMP_UPPER_OFFSET,
                       BufferWord);
  BufferWord = XAvb_ReorderWord((Sec<<16) |
                                (InstancePtr->PtpRecords.Nanosec>>16));
  XAvb_WritePtpBuffer(InstancePtr->Config.BaseAddress,
                       XAVB_PTP_TX_FOLLOW_UP_OFFSET,
                       XAVB_PTP_TX_PKT_TIMESTAMP_MID_OFFSET,
                       BufferWord);
  BufferWord = XAvb_ReorderWord(InstancePtr->PtpRecords.Nanosec<<16);
  XAvb_WritePtpBuffer(InstancePtr->Config.BaseAddress,
                       XAVB_PTP_TX_FOLLOW_UP_OFFSET,
                       XAVB_PTP_TX_PKT_TIMESTAMP_LOWER_OFFSET,
                       BufferWord);
#ifdef DEBUG_XAVB_LEVEL3
  xil_printf("\r\n--------------------------------");
  xil_printf("\r\n-----XAvb_MasterSendSync()------");
  xil_printf("\r\n--------------------------------");
  xil_printf("\r\n--------------RTC---------------");
  xil_printf("\r\nRTC nanosec field is %x", InstancePtr->PtpRecords.Nanosec);
  xil_printf("\r\nRTC seconds field is %x", Sec);
  xil_printf("\r\nRTC epoch   field is %x", Epoch);
  xil_printf("\r\n--------------------------------");
  xil_printf("\r\nsequenceId is %x", SequenceId);
#endif
}
void XAvb_MasterSendSync ( XAvb * InstancePtr ) { u32 Epoch = 0 ; u32 Sec = 0 ; u32 SequenceId = 0 ; u32 BufferWord = 0 ; XAvb_WaitOnTxPtpQueue ( InstancePtr ) ; SequenceId = XAvb_IncSequenceId ( InstancePtr -> Config . BaseAddress , XAVB_PTP_TX_SYNC_OFFSET ) ; InstancePtr -> PtpRecords . Nanosec = XAvb_ReadReg ( InstancePtr -> Config . BaseAddress , XAVB_RTC_NANOSEC_VALUE_OFFSET ) ; Sec = XAvb_ReadReg ( InstancePtr -> Config . BaseAddress , XAVB_RTC_SEC_LOWER_VALUE_OFFSET ) ; Epoch = XAvb_ReadReg ( InstancePtr -> Config . BaseAddress , XAVB_RTC_SEC_UPPER_VALUE_OFFSET ) ; XAvb_WriteReg ( InstancePtr -> Config . BaseAddress , XAVB_PTP_TX_CONTROL_OFFSET , XAVB_PTP_TX_SEND_SYNC_FRAME_MASK ) ; BufferWord = XAvb_ReadPtpBuffer ( InstancePtr -> Config . BaseAddress , XAVB_PTP_TX_FOLLOW_UP_OFFSET , XAVB_PTP_TX_PKT_SEQUENCEID_OFFSET ) ; BufferWord = ( BufferWord & 0xFFFF0000 ) | ( SequenceId & 0x0000FFFF ) ; XAvb_WritePtpBuffer ( InstancePtr -> Config . BaseAddress , XAVB_PTP_TX_FOLLOW_UP_OFFSET , XAVB_PTP_TX_PKT_SEQUENCEID_OFFSET , BufferWord ) ; BufferWord = XAvb_ReorderWord ( ( Epoch << 16 ) | ( Sec >> 16 ) ) ; XAvb_WritePtpBuffer ( InstancePtr -> Config . BaseAddress , XAVB_PTP_TX_FOLLOW_UP_OFFSET , XAVB_PTP_TX_PKT_TIMESTAMP_UPPER_OFFSET , BufferWord ) ; BufferWord = XAvb_ReorderWord ( ( Sec << 16 ) | ( InstancePtr -> PtpRecords . Nanosec >> 16 ) ) ; XAvb_WritePtpBuffer ( InstancePtr -> Config . BaseAddress , XAVB_PTP_TX_FOLLOW_UP_OFFSET , XAVB_PTP_TX_PKT_TIMESTAMP_MID_OFFSET , BufferWord ) ; BufferWord = XAvb_ReorderWord ( InstancePtr -> PtpRecords . Nanosec << 16 ) ; XAvb_WritePtpBuffer ( InstancePtr -> Config . BaseAddress , XAVB_PTP_TX_FOLLOW_UP_OFFSET , XAVB_PTP_TX_PKT_TIMESTAMP_LOWER_OFFSET , BufferWord ) ; #ifdef DEBUG_XAVB_LEVEL3 xil_printf ( " \r \n " ) ; xil_printf ( " \r \n " ) ; xil_printf ( " \r \n " ) ; xil_printf ( " \r \n " ) ; xil_printf ( " \r \n " , InstancePtr -> PtpRecords . Nanosec ) ; xil_printf ( " \r \n " , Sec ) ; xil_printf ( " \r \n " , Epoch ) ; xil_printf ( " \r \n " ) ; xil_printf ( " \r \n " , SequenceId ) ; #endif }
A function to format then request the transmission of a PTP Sync Packet
A function to format then request the transmission of a PTP Sync Packet
/** Wait until there are no PTP frames to be transmitted */ /** Increment the sequenceId in the Sync frame */ /** Read the current RTC Offset values */ /** Send the Sync Frame! */ /** Now some pre-work on the Follow-Up Frame
   *-----------------------------------------
   *
   * Write the same sequenceId to the Follow-up frame */ /** Format the Timestamp (RTC) into correct byte positioning.
   * Note: this is how the Timestamp is stored in
   * the PTP frame itself (transmitted MSB of Epoch first):
   *
   * |----------------|----------------|----------------|----------------|
   * | seconds[23:16] | seconds[31:24] |   epoch[7:0]   |   epoch[15:8]  |
   * |----------------|----------------|----------------|----------------|
   * | nanosec[23:16] | nanosec[31:24] |  seconds[7:0]  |  seconds[15:8] |
   * |----------------|----------------|----------------|----------------|
   * |      0's       |      0's       |  nanosec[7:0]  |  nanosec[15:8] |
   * |----------------|----------------|----------------|----------------|
   */ /** Write the Timestamp (RTC) to the Follow-up frame */