XilinxProcessorIPLib/drivers/axiethernet/examples/avb/xavb_ptp_packets.c
void XAvb_SetupSourcePortIdentity(XAvb * InstancePtr,
                                  XAvb_PortIdentity systemIdentity)
{
  u32 BufferWord;
  u8  BufferEnable;
  u32 DataBitEnable;
  u32 ReadWord;

  /* Set up our local copy of the sourcePortIdentity */
  InstancePtr->portIdLocal = systemIdentity;

  /** Write the sourcePortIdentity into the header for all TX PTP buffers
   *  except the empty default buffer AND write the GMID for TX announce AND
   *  Write the ClockIdentity into the TX Announce TLV */
  BufferEnable =  0x7F;

  /** (a) Write the upper 2 bytes of the ClockIdentityUpper
   *   - REM: Swap back the byte order into frame storage order */
  DataBitEnable = 0xFFFF0000;
  BufferWord = (systemIdentity.ClockIdentityUpper >> 16);
  BufferWord = XAvb_ReorderWord(BufferWord);

  XAvb_WriteToMultipleTxPtpFrames(InstancePtr->Config.BaseAddress,
                                  XAVB_PTP_TX_PKT_PORTID_UPPER_OFFSET,
                                  BufferWord,
                                  DataBitEnable,
                                  BufferEnable);

  ReadWord = XAvb_ReadPtpBuffer(InstancePtr->Config.BaseAddress,
                                   XAVB_PTP_TX_ANNOUNCE_OFFSET,
                                   XAVB_PTP_TX_PKT_ANNOUNCE_TLVLEN_PATHSEQ_START_OFFSET);

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

  XAvb_WritePtpBuffer(InstancePtr->Config.BaseAddress,
                       XAVB_PTP_TX_ANNOUNCE_OFFSET,
                       XAVB_PTP_TX_PKT_ANNOUNCE_TLVLEN_PATHSEQ_START_OFFSET,
                       BufferWord);

  /** (b) Write the lower 2 bytes of the ClockIdentityUpper and upper
   *   2 bytes of the ClockIdentityLower.
   *   - REM: Swap back the byte order into frame storage order*/
  BufferWord = ((systemIdentity.ClockIdentityUpper << 16) & 0xFFFF0000) | ((systemIdentity.ClockIdentityLower >> 16) & 0x0000FFFF);
  BufferWord = XAvb_ReorderWord(BufferWord);
  DataBitEnable = 0xFFFFFFFF;

  XAvb_WriteToMultipleTxPtpFrames(InstancePtr->Config.BaseAddress,
                                  XAVB_PTP_TX_PKT_PORTID_MID_OFFSET,
                                  BufferWord,
                                  DataBitEnable,
                                  BufferEnable);


  XAvb_WritePtpBuffer(InstancePtr->Config.BaseAddress,
                       XAVB_PTP_TX_ANNOUNCE_OFFSET,
                       (XAVB_PTP_TX_PKT_ANNOUNCE_TLVLEN_PATHSEQ_START_OFFSET + 4),
                       BufferWord);

  /** (c) Write the lower 2 bytes of the ClockIdentityLower and the portNumber
   *   - REM: Swap back the byte order into frame storage order*/
  BufferWord = ((systemIdentity.ClockIdentityLower << 16) & 0xFFFF0000) | (systemIdentity.PortNumber & 0x0000FFFF);
  BufferWord = XAvb_ReorderWord(BufferWord);

  XAvb_WriteToMultipleTxPtpFrames(InstancePtr->Config.BaseAddress,
                                  XAVB_PTP_TX_PKT_PORTID_LOWER_OFFSET,
                                  BufferWord,
                                  DataBitEnable,
                                  BufferEnable);

  BufferWord = (systemIdentity.ClockIdentityLower << 16) & 0xFFFF0000;
  BufferWord = XAvb_ReorderWord(BufferWord);
  XAvb_WritePtpBuffer(InstancePtr->Config.BaseAddress,
                       XAVB_PTP_TX_ANNOUNCE_OFFSET,
                       (XAVB_PTP_TX_PKT_ANNOUNCE_TLVLEN_PATHSEQ_START_OFFSET + 8),
                       BufferWord);



  /** Write the grandmasterIdentity into the header for the TX Announce PTP buffer */
  /** (a) Write 1 byte of GMID (Upper)*/
  BufferWord = XAvb_ReadPtpBuffer(InstancePtr->Config.BaseAddress,
                                   XAVB_PTP_TX_ANNOUNCE_OFFSET,
                                   XAVB_PTP_TX_PKT_ANNOUNCE_QUAL_LOW_PRI2_GMID_HI_OFFSET);

  BufferWord =  (BufferWord & 0x00FFFFFF) | (systemIdentity.ClockIdentityUpper & 0xFF000000);

  XAvb_WritePtpBuffer(InstancePtr->Config.BaseAddress,
                       XAVB_PTP_TX_ANNOUNCE_OFFSET,
                       XAVB_PTP_TX_PKT_ANNOUNCE_QUAL_LOW_PRI2_GMID_HI_OFFSET,
                       BufferWord);

  /** (b) Write 3 bytes of GMID (Upper) and 1 byte of GMID (Lower)**/
  BufferWord =  (systemIdentity.ClockIdentityUpper << 8) | ((systemIdentity.ClockIdentityLower >> 24) & 0x000000FF);
  BufferWord = XAvb_ReorderWord(BufferWord);
  XAvb_WritePtpBuffer(InstancePtr->Config.BaseAddress,
                       XAVB_PTP_TX_ANNOUNCE_OFFSET,
                       XAVB_PTP_TX_PKT_ANNOUNCE_GMID_MID_OFFSET,
                       BufferWord);

  /** (c) Write 3 bytes of GMID (Lower) */
  BufferWord = XAvb_ReadPtpBuffer(InstancePtr->Config.BaseAddress,
                                   XAVB_PTP_TX_ANNOUNCE_OFFSET,
                                   XAVB_PTP_TX_PKT_ANNOUNCE_GMID_LOW_STEPSREMOVED_HI_OFFSET);

  BufferWord = ((BufferWord >> 24) & 0x000000FF) | ((systemIdentity.ClockIdentityLower << 8) & 0xFFFFFF00);
  BufferWord = XAvb_ReorderWord(BufferWord);
  XAvb_WritePtpBuffer(InstancePtr->Config.BaseAddress,
                       XAVB_PTP_TX_ANNOUNCE_OFFSET,
                       XAVB_PTP_TX_PKT_ANNOUNCE_GMID_LOW_STEPSREMOVED_HI_OFFSET,
                       BufferWord);


#ifdef DEBUG_XAVB_LEVEL2
    xil_printf("\r\n setupSourcePortIdentity: Writing systemIdentity to buffers %08x", BufferEnable);
    xil_printf("\r\n setupSourcePortIdentity: ClockIdentityUpper --> 0x%08x, ClockIdentityLower --> 0x%08x, PortNumber --> 0x%08x",
                                 InstancePtr->portIdLocal.ClockIdentityUpper,
                                 InstancePtr->portIdLocal.ClockIdentityLower,
                                 InstancePtr->portIdLocal.PortNumber);
#endif
}
/****************************************************************************/
/**
*
* This function updates the portIdLocal local copy of the sourcePortIdentity
* and writes this value into the TX PTP frame buffer templates. The fields
* that are written are:
* o sourcePortIdentity for all default PTP frames
* o Announce:: grandmasterIdentity
* o Announce:: TLV clockIdentity
*
* @param  InstancePtr is a pointer to the XAvb instance to be worked on
* @param  systemIdentity is the clockIdentity and portNumber for this endpoint
*
* @return None.
*
* @note   Announce::TLV. By default the tlvType and length field are set
*         up in the BRAM, assuming that N = 1.
*
****************************************************************************/
This function updates the portIdLocal local copy of the sourcePortIdentity
and writes this value into the TX PTP frame buffer templates.
This function updates the portIdLocal local copy of the sourcePortIdentity and writes this value into the TX PTP frame buffer templates .
void XAvb_SetupSourcePortIdentity(XAvb * InstancePtr,
                                  XAvb_PortIdentity systemIdentity)
{
  u32 BufferWord;
  u8  BufferEnable;
  u32 DataBitEnable;
  u32 ReadWord;
  InstancePtr->portIdLocal = systemIdentity;
  BufferEnable =  0x7F;
  DataBitEnable = 0xFFFF0000;
  BufferWord = (systemIdentity.ClockIdentityUpper >> 16);
  BufferWord = XAvb_ReorderWord(BufferWord);
  XAvb_WriteToMultipleTxPtpFrames(InstancePtr->Config.BaseAddress,
                                  XAVB_PTP_TX_PKT_PORTID_UPPER_OFFSET,
                                  BufferWord,
                                  DataBitEnable,
                                  BufferEnable);
  ReadWord = XAvb_ReadPtpBuffer(InstancePtr->Config.BaseAddress,
                                   XAVB_PTP_TX_ANNOUNCE_OFFSET,
                                   XAVB_PTP_TX_PKT_ANNOUNCE_TLVLEN_PATHSEQ_START_OFFSET);
  BufferWord =  (ReadWord & 0x0000FFFF) | (BufferWord & 0xFFFF0000);
  XAvb_WritePtpBuffer(InstancePtr->Config.BaseAddress,
                       XAVB_PTP_TX_ANNOUNCE_OFFSET,
                       XAVB_PTP_TX_PKT_ANNOUNCE_TLVLEN_PATHSEQ_START_OFFSET,
                       BufferWord);
  BufferWord = ((systemIdentity.ClockIdentityUpper << 16) & 0xFFFF0000) | ((systemIdentity.ClockIdentityLower >> 16) & 0x0000FFFF);
  BufferWord = XAvb_ReorderWord(BufferWord);
  DataBitEnable = 0xFFFFFFFF;
  XAvb_WriteToMultipleTxPtpFrames(InstancePtr->Config.BaseAddress,
                                  XAVB_PTP_TX_PKT_PORTID_MID_OFFSET,
                                  BufferWord,
                                  DataBitEnable,
                                  BufferEnable);
  XAvb_WritePtpBuffer(InstancePtr->Config.BaseAddress,
                       XAVB_PTP_TX_ANNOUNCE_OFFSET,
                       (XAVB_PTP_TX_PKT_ANNOUNCE_TLVLEN_PATHSEQ_START_OFFSET + 4),
                       BufferWord);
  BufferWord = ((systemIdentity.ClockIdentityLower << 16) & 0xFFFF0000) | (systemIdentity.PortNumber & 0x0000FFFF);
  BufferWord = XAvb_ReorderWord(BufferWord);
  XAvb_WriteToMultipleTxPtpFrames(InstancePtr->Config.BaseAddress,
                                  XAVB_PTP_TX_PKT_PORTID_LOWER_OFFSET,
                                  BufferWord,
                                  DataBitEnable,
                                  BufferEnable);
  BufferWord = (systemIdentity.ClockIdentityLower << 16) & 0xFFFF0000;
  BufferWord = XAvb_ReorderWord(BufferWord);
  XAvb_WritePtpBuffer(InstancePtr->Config.BaseAddress,
                       XAVB_PTP_TX_ANNOUNCE_OFFSET,
                       (XAVB_PTP_TX_PKT_ANNOUNCE_TLVLEN_PATHSEQ_START_OFFSET + 8),
                       BufferWord);
  BufferWord = XAvb_ReadPtpBuffer(InstancePtr->Config.BaseAddress,
                                   XAVB_PTP_TX_ANNOUNCE_OFFSET,
                                   XAVB_PTP_TX_PKT_ANNOUNCE_QUAL_LOW_PRI2_GMID_HI_OFFSET);
  BufferWord =  (BufferWord & 0x00FFFFFF) | (systemIdentity.ClockIdentityUpper & 0xFF000000);
  XAvb_WritePtpBuffer(InstancePtr->Config.BaseAddress,
                       XAVB_PTP_TX_ANNOUNCE_OFFSET,
                       XAVB_PTP_TX_PKT_ANNOUNCE_QUAL_LOW_PRI2_GMID_HI_OFFSET,
                       BufferWord);
  BufferWord =  (systemIdentity.ClockIdentityUpper << 8) | ((systemIdentity.ClockIdentityLower >> 24) & 0x000000FF);
  BufferWord = XAvb_ReorderWord(BufferWord);
  XAvb_WritePtpBuffer(InstancePtr->Config.BaseAddress,
                       XAVB_PTP_TX_ANNOUNCE_OFFSET,
                       XAVB_PTP_TX_PKT_ANNOUNCE_GMID_MID_OFFSET,
                       BufferWord);
  BufferWord = XAvb_ReadPtpBuffer(InstancePtr->Config.BaseAddress,
                                   XAVB_PTP_TX_ANNOUNCE_OFFSET,
                                   XAVB_PTP_TX_PKT_ANNOUNCE_GMID_LOW_STEPSREMOVED_HI_OFFSET);
  BufferWord = ((BufferWord >> 24) & 0x000000FF) | ((systemIdentity.ClockIdentityLower << 8) & 0xFFFFFF00);
  BufferWord = XAvb_ReorderWord(BufferWord);
  XAvb_WritePtpBuffer(InstancePtr->Config.BaseAddress,
                       XAVB_PTP_TX_ANNOUNCE_OFFSET,
                       XAVB_PTP_TX_PKT_ANNOUNCE_GMID_LOW_STEPSREMOVED_HI_OFFSET,
                       BufferWord);
#ifdef DEBUG_XAVB_LEVEL2
    xil_printf("\r\n setupSourcePortIdentity: Writing systemIdentity to buffers %08x", BufferEnable);
    xil_printf("\r\n setupSourcePortIdentity: ClockIdentityUpper --> 0x%08x, ClockIdentityLower --> 0x%08x, PortNumber --> 0x%08x",
                                 InstancePtr->portIdLocal.ClockIdentityUpper,
                                 InstancePtr->portIdLocal.ClockIdentityLower,
                                 InstancePtr->portIdLocal.PortNumber);
#endif
}
void XAvb_SetupSourcePortIdentity ( XAvb * InstancePtr , XAvb_PortIdentity systemIdentity ) { u32 BufferWord ; u8 BufferEnable ; u32 DataBitEnable ; u32 ReadWord ; InstancePtr -> portIdLocal = systemIdentity ; BufferEnable = 0x7F ; DataBitEnable = 0xFFFF0000 ; BufferWord = ( systemIdentity . ClockIdentityUpper >> 16 ) ; BufferWord = XAvb_ReorderWord ( BufferWord ) ; XAvb_WriteToMultipleTxPtpFrames ( InstancePtr -> Config . BaseAddress , XAVB_PTP_TX_PKT_PORTID_UPPER_OFFSET , BufferWord , DataBitEnable , BufferEnable ) ; ReadWord = XAvb_ReadPtpBuffer ( InstancePtr -> Config . BaseAddress , XAVB_PTP_TX_ANNOUNCE_OFFSET , XAVB_PTP_TX_PKT_ANNOUNCE_TLVLEN_PATHSEQ_START_OFFSET ) ; BufferWord = ( ReadWord & 0x0000FFFF ) | ( BufferWord & 0xFFFF0000 ) ; XAvb_WritePtpBuffer ( InstancePtr -> Config . BaseAddress , XAVB_PTP_TX_ANNOUNCE_OFFSET , XAVB_PTP_TX_PKT_ANNOUNCE_TLVLEN_PATHSEQ_START_OFFSET , BufferWord ) ; BufferWord = ( ( systemIdentity . ClockIdentityUpper << 16 ) & 0xFFFF0000 ) | ( ( systemIdentity . ClockIdentityLower >> 16 ) & 0x0000FFFF ) ; BufferWord = XAvb_ReorderWord ( BufferWord ) ; DataBitEnable = 0xFFFFFFFF ; XAvb_WriteToMultipleTxPtpFrames ( InstancePtr -> Config . BaseAddress , XAVB_PTP_TX_PKT_PORTID_MID_OFFSET , BufferWord , DataBitEnable , BufferEnable ) ; XAvb_WritePtpBuffer ( InstancePtr -> Config . BaseAddress , XAVB_PTP_TX_ANNOUNCE_OFFSET , ( XAVB_PTP_TX_PKT_ANNOUNCE_TLVLEN_PATHSEQ_START_OFFSET + 4 ) , BufferWord ) ; BufferWord = ( ( systemIdentity . ClockIdentityLower << 16 ) & 0xFFFF0000 ) | ( systemIdentity . PortNumber & 0x0000FFFF ) ; BufferWord = XAvb_ReorderWord ( BufferWord ) ; XAvb_WriteToMultipleTxPtpFrames ( InstancePtr -> Config . BaseAddress , XAVB_PTP_TX_PKT_PORTID_LOWER_OFFSET , BufferWord , DataBitEnable , BufferEnable ) ; BufferWord = ( systemIdentity . ClockIdentityLower << 16 ) & 0xFFFF0000 ; BufferWord = XAvb_ReorderWord ( BufferWord ) ; XAvb_WritePtpBuffer ( InstancePtr -> Config . BaseAddress , XAVB_PTP_TX_ANNOUNCE_OFFSET , ( XAVB_PTP_TX_PKT_ANNOUNCE_TLVLEN_PATHSEQ_START_OFFSET + 8 ) , BufferWord ) ; BufferWord = XAvb_ReadPtpBuffer ( InstancePtr -> Config . BaseAddress , XAVB_PTP_TX_ANNOUNCE_OFFSET , XAVB_PTP_TX_PKT_ANNOUNCE_QUAL_LOW_PRI2_GMID_HI_OFFSET ) ; BufferWord = ( BufferWord & 0x00FFFFFF ) | ( systemIdentity . ClockIdentityUpper & 0xFF000000 ) ; XAvb_WritePtpBuffer ( InstancePtr -> Config . BaseAddress , XAVB_PTP_TX_ANNOUNCE_OFFSET , XAVB_PTP_TX_PKT_ANNOUNCE_QUAL_LOW_PRI2_GMID_HI_OFFSET , BufferWord ) ; BufferWord = ( systemIdentity . ClockIdentityUpper << 8 ) | ( ( systemIdentity . ClockIdentityLower >> 24 ) & 0x000000FF ) ; BufferWord = XAvb_ReorderWord ( BufferWord ) ; XAvb_WritePtpBuffer ( InstancePtr -> Config . BaseAddress , XAVB_PTP_TX_ANNOUNCE_OFFSET , XAVB_PTP_TX_PKT_ANNOUNCE_GMID_MID_OFFSET , BufferWord ) ; BufferWord = XAvb_ReadPtpBuffer ( InstancePtr -> Config . BaseAddress , XAVB_PTP_TX_ANNOUNCE_OFFSET , XAVB_PTP_TX_PKT_ANNOUNCE_GMID_LOW_STEPSREMOVED_HI_OFFSET ) ; BufferWord = ( ( BufferWord >> 24 ) & 0x000000FF ) | ( ( systemIdentity . ClockIdentityLower << 8 ) & 0xFFFFFF00 ) ; BufferWord = XAvb_ReorderWord ( BufferWord ) ; XAvb_WritePtpBuffer ( InstancePtr -> Config . BaseAddress , XAVB_PTP_TX_ANNOUNCE_OFFSET , XAVB_PTP_TX_PKT_ANNOUNCE_GMID_LOW_STEPSREMOVED_HI_OFFSET , BufferWord ) ; #ifdef DEBUG_XAVB_LEVEL2 xil_printf ( " \r \n " , BufferEnable ) ; xil_printf ( " \r \n " , InstancePtr -> portIdLocal . ClockIdentityUpper , InstancePtr -> portIdLocal . ClockIdentityLower , InstancePtr -> portIdLocal . PortNumber ) ; #endif }
This function updates the portIdLocal local copy of the sourcePortIdentity
and writes this value into the TX PTP frame buffer templates.
This function updates the portIdLocal local copy of the sourcePortIdentity and writes this value into the TX PTP frame buffer templates .
/* Set up our local copy of the sourcePortIdentity */ /** Write the sourcePortIdentity into the header for all TX PTP buffers
   *  except the empty default buffer AND write the GMID for TX announce AND
   *  Write the ClockIdentity into the TX Announce TLV */ /** (a) Write the upper 2 bytes of the ClockIdentityUpper
   *   - REM: Swap back the byte order into frame storage order */ /** (b) Write the lower 2 bytes of the ClockIdentityUpper and upper
   *   2 bytes of the ClockIdentityLower.
   *   - REM: Swap back the byte order into frame storage order*/ /** (c) Write the lower 2 bytes of the ClockIdentityLower and the portNumber
   *   - REM: Swap back the byte order into frame storage order*/ /** Write the grandmasterIdentity into the header for the TX Announce PTP buffer */ /** (a) Write 1 byte of GMID (Upper)*/ /** (b) Write 3 bytes of GMID (Upper) and 1 byte of GMID (Lower)**/ /** (c) Write 3 bytes of GMID (Lower) */