Exemplo n.º 1
0
/**
*
* A New Announce Packet is to be analyzed.  This function will read in the
* packet, decode it, and extract the relevent information fields to the
* "AnnounceFrame" data pointer.
*
* @param  BaseAddress is the base address of the device
* @param  PtpFrameBaseAddr is the base address of the received Announce Packet
*         in the Rx PTP Packet Buffer
* @param  AnnounceFrame is a pointer to a suitable data structure, designed to
*         record the useful fields from the received Announce Packet
*
* @return The AnnounceFrame data structure is updated.
*
* @note   None.
*
*****************************************************************************/
void XAvb_ReadAnnounceFrame(u32 BaseAddress,
                            u32 PtpFrameBaseAddr,
                            XAvb_BmcData * AnnounceFrame) {

  u32 ReadWord;

  AnnounceFrame->SourcePortIdentity.ClockIdentityLower = 0;
  AnnounceFrame->SourcePortIdentity.ClockIdentityUpper = 0;

  /** Get the Source Port Identity of the port sending the Announce Packet */
  XAvb_GetPortIdentity(BaseAddress, PtpFrameBaseAddr,
                       XAVB_PTP_RX_PKT_PORTID_UPPER_OFFSET, &AnnounceFrame->SourcePortIdentity);


  /** Read priority1 and top half of ClockQuality */
  ReadWord = XAvb_ReorderWord(XAvb_ReadPtpBuffer(BaseAddress, PtpFrameBaseAddr,
                                                  XAVB_PTP_RX_PKT_ANNOUNCE_PRI1_QUAL_HI_OFFSET));
  AnnounceFrame->GrandmasterPriority1       = (ReadWord >> 16);
  AnnounceFrame->ClockQuality.clockClass    = (ReadWord >> 8);
  AnnounceFrame->ClockQuality.clockAccuracy =  ReadWord;


  /** Read bottom half of ClockQuality, priority2, and top byte of GMID */
  ReadWord = XAvb_ReorderWord(XAvb_ReadPtpBuffer(BaseAddress, PtpFrameBaseAddr,
                                                  XAVB_PTP_RX_PKT_ANNOUNCE_QUAL_LOW_PRI2_GMID_HI_OFFSET));
  AnnounceFrame->ClockQuality.offsetScaledLogVariance   = (ReadWord >> 16);
  AnnounceFrame->GrandmasterPriority2                   = (ReadWord >> 8);
  AnnounceFrame->GrandmasterIdentity.ClockIdentityUpper = (ReadWord << 24);

  /** Read bytes 4-7 of GMID */
  ReadWord = XAvb_ReorderWord(XAvb_ReadPtpBuffer(BaseAddress, PtpFrameBaseAddr,
                                                  XAVB_PTP_RX_PKT_ANNOUNCE_GMID_MID_OFFSET));
  AnnounceFrame->GrandmasterIdentity.ClockIdentityUpper |= (ReadWord >> 8);
  AnnounceFrame->GrandmasterIdentity.ClockIdentityLower  = (ReadWord << 24);

  /** Read bytes 1-3 of GMID and high byte of stepsRemoved */
  ReadWord = XAvb_ReorderWord(XAvb_ReadPtpBuffer(BaseAddress, PtpFrameBaseAddr,
                                                  XAVB_PTP_RX_PKT_ANNOUNCE_GMID_LOW_STEPSREMOVED_HI_OFFSET));
  AnnounceFrame->GrandmasterIdentity.ClockIdentityLower |= (ReadWord >> 8);
  AnnounceFrame->stepsRemoved                            = (ReadWord << 8);

  /** Read low byte of stepsRemoved */
  ReadWord = XAvb_ReorderWord(XAvb_ReadPtpBuffer(BaseAddress, PtpFrameBaseAddr,
                                                  XAVB_PTP_RX_PKT_ANNOUNCE_STEPSREMOVED_LOW_TIMESRC_OFFSET));
  AnnounceFrame->stepsRemoved                           |= (ReadWord >> 24);

}
Exemplo n.º 2
0
/**
*
* This function reads the logMessageinteval from an RX PTP Buffer and updates
* the AnnounceFrame struct with the value read.
*
* @param  BaseAddress is the base address of the device
* @param  PtpFrameBaseAddr is the base address of the received Announce Packet
*         in the Rx PTP Packet Buffer
* @param  AnnounceFrame is a pointer to a suitable data structure, designed to
*         record the useful fields from the received Announce Packet
*
* @return The AnnounceFrame data structure is updated.
*
* @note   None.
*
*****************************************************************************/
void XAvb_ReadAnnounceReceiptTimeout(u32 BaseAddress,
                                     u32 PtpFrameBaseAddr,
                                     XAvb_BmcData * AnnounceFrame) {

  u32 ReadWord;
  u8  logMessageInterval;

  ReadWord = XAvb_ReorderWord((XAvb_ReadPtpBuffer(BaseAddress,
                                                   PtpFrameBaseAddr,
                                                   XAVB_PTP_RX_PKT_SEQUENCEID_OFFSET)) &
                               0xFF000000);

  logMessageInterval = ReadWord;

  /* Implicit convert from unsigned (u8) to signed (char) */
  AnnounceFrame->logMessageInterval = logMessageInterval;

}
Exemplo n.º 3
0
/**
*
* The Interrupt subroutine for the "interrupt_ptp_rx" signal.  This interrupt
* fires whenever a PTP frame has been received.  The main function is to
* identify, decode, and act on the type of PTP frame received.
*
* @param  InstancePtr is a pointer to the XAvb instance to be worked on
*
* @return None.
*
* @note   None.
*
*****************************************************************************/
void XAvb_PtpRxInterruptHandler(XAvb * InstancePtr) {
#ifdef DEBUG_XAVB_LEVEL1
  u32 x                = 0;
#endif
  u32 MessageType      = 0;
  u32 PtpFrameBaseAddr = 0;

  /** RxPtpHardPointer indicates the bin location of the last frame to be
   * received and written into the Rx PTP buffer in hardware.  This read will
   * also clear the interrupt.*/
  InstancePtr->PtpCounters.RxPtpHardPointer
      = (XAvb_ReadReg(InstancePtr->Config.BaseAddress,
                       XAVB_PTP_RX_CONTROL_OFFSET)
        & XAVB_PTP_RX_PACKET_FIELD_MASK) >> 8;

  /** If PTP functions are marked as not running, then take no further action */
  if (InstancePtr->PtpIsRunning == 1) {


    /** RxPtpSoftPointer indicates the bin location of the last frame to be
     * processed in software. */
    while (   (InstancePtr->PtpCounters.RxPtpSoftPointer & 0xF)
           != (InstancePtr->PtpCounters.RxPtpHardPointer & 0xF) ) {

      /** decode the rx'd frames until RxPtpHardPointer = RxPtpSoftPointer */
      InstancePtr->PtpCounters.RxPtpSoftPointer
          = InstancePtr->PtpCounters.RxPtpSoftPointer + 1;

      /** Set the base address of the current PTP frame in the Buffer */
      PtpFrameBaseAddr = XAVB_PTP_RX_BASE_OFFSET
                         + ((InstancePtr->PtpCounters.RxPtpSoftPointer & 0xF)
                         << 8);


      /** Perform very basic sanity checking of the frame : is it a PTP? */
      if (XAvb_IsRxFramePTP(InstancePtr, PtpFrameBaseAddr) == 1) {


        /** Determine which PTP frame was received. */
        MessageType = (XAvb_ReadPtpBuffer(InstancePtr->Config.BaseAddress,
                                           PtpFrameBaseAddr,
                                           XAVB_PTP_RX_PKT_TYPE_OFFSET)
                       & 0x000F0000 ) >> 16;


        /** Now act on the received frame */
        switch (MessageType) {

          /** Sync Frame
           * ---------- */
          case XAVB_PTP_TYPE_SYNC:
            XAvb_DecodeRxSync(InstancePtr, PtpFrameBaseAddr);
          break;

          /** Follow Up Frame
           * --------------- */
          case XAVB_PTP_TYPE_FOLLOW_UP:
            XAvb_DecodeRxFollowUp(InstancePtr, PtpFrameBaseAddr);
          break;

          /** PDelayReq Frame
           * --------------- */
          case XAVB_PTP_TYPE_PDELAYREQ:
            /** Send a send PDelayResp frame after receiving a PDelayReq Frame */
            XAvb_SendPDelayResp(InstancePtr, PtpFrameBaseAddr);

            /** Send a send PDelayRespFollowUp frame after a PDelayResp Frame */
            XAvb_SendPDelayRespFollowUp(InstancePtr);

          break;

          /** PDelayResp Frame
           * ---------------- */
          case XAVB_PTP_TYPE_PDELAYRESP:
            XAvb_DecodeRxPDelayResp(InstancePtr, PtpFrameBaseAddr);
          break;

          /** PDelayRespFollowUp Frame
           * ------------------------ */
          case XAVB_PTP_TYPE_PDELAYRESP_FOLLOW_UP:
            EchoPTPFramesReceived = 1;
            XAvb_DecodeRxPDelayRespFollowUp(InstancePtr, PtpFrameBaseAddr);
          break;

          /** Announce Frame
           * -------------- */
          case XAVB_PTP_TYPE_ANNOUNCE:
            XAvb_DecodeRxAnnounceFrame(InstancePtr,
                                       PtpFrameBaseAddr);
          break;

          /** Signaling Frame
           * -------------- */
          case XAVB_PTP_TYPE_SIGNALING:
            XAvb_DecodeRxSignaling(InstancePtr, PtpFrameBaseAddr);
          break;

          /** Unknown Frame
           * -------------- */
          default:
#ifdef DEBUG_XAVB_LEVEL1
            xil_printf("\r\nXAvb_PtpRxInterruptHandler()");
            xil_printf("\r\n** Unknown PTP Frame Rx'd **");
            xil_printf("\r\nMessage Type is      %x", MessageType);
            xil_printf("\r\n-------Unknown Frame -------");
            for (x = 0; x < 0x100; x = x + 4) {
              xil_printf("\r\n %x %x", x,
                  (XAvb_ReadPtpBuffer(InstancePtr->Config.BaseAddress,
                                       PtpFrameBaseAddr,
                                       x)));
            }
#endif
          break;
        }
      }
    }

  } else {  /* InstancePtr->PtpIsRunning != 1 */