XilinxProcessorIPLib/drivers/axiethernet/examples/avb/xavb.c
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 */

    /** PTP is not running so just consume the packets so they are not left in the
     * queue and cause problems when we actually start */

    /** 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;
    }
  }

}
/****************************************************************************/
/**
*
* 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.
*
*****************************************************************************/
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.
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 .
void XAvb_PtpRxInterruptHandler(XAvb * InstancePtr) {
#ifdef DEBUG_XAVB_LEVEL1
  u32 x                = 0;
#endif
  u32 MessageType      = 0;
  u32 PtpFrameBaseAddr = 0;
  InstancePtr->PtpCounters.RxPtpHardPointer
      = (XAvb_ReadReg(InstancePtr->Config.BaseAddress,
                       XAVB_PTP_RX_CONTROL_OFFSET)
        & XAVB_PTP_RX_PACKET_FIELD_MASK) >> 8;
  if (InstancePtr->PtpIsRunning == 1) {
    while (   (InstancePtr->PtpCounters.RxPtpSoftPointer & 0xF)
           != (InstancePtr->PtpCounters.RxPtpHardPointer & 0xF) ) {
      InstancePtr->PtpCounters.RxPtpSoftPointer
          = InstancePtr->PtpCounters.RxPtpSoftPointer + 1;
      PtpFrameBaseAddr = XAVB_PTP_RX_BASE_OFFSET
                         + ((InstancePtr->PtpCounters.RxPtpSoftPointer & 0xF)
                         << 8);
      if (XAvb_IsRxFramePTP(InstancePtr, PtpFrameBaseAddr) == 1) {
        MessageType = (XAvb_ReadPtpBuffer(InstancePtr->Config.BaseAddress,
                                           PtpFrameBaseAddr,
                                           XAVB_PTP_RX_PKT_TYPE_OFFSET)
                       & 0x000F0000 ) >> 16;
        switch (MessageType) {
          case XAVB_PTP_TYPE_SYNC:
            XAvb_DecodeRxSync(InstancePtr, PtpFrameBaseAddr);
          break;
          case XAVB_PTP_TYPE_FOLLOW_UP:
            XAvb_DecodeRxFollowUp(InstancePtr, PtpFrameBaseAddr);
          break;
          case XAVB_PTP_TYPE_PDELAYREQ:
            XAvb_SendPDelayResp(InstancePtr, PtpFrameBaseAddr);
            XAvb_SendPDelayRespFollowUp(InstancePtr);
          break;
          case XAVB_PTP_TYPE_PDELAYRESP:
            XAvb_DecodeRxPDelayResp(InstancePtr, PtpFrameBaseAddr);
          break;
          case XAVB_PTP_TYPE_PDELAYRESP_FOLLOW_UP:
            EchoPTPFramesReceived = 1;
            XAvb_DecodeRxPDelayRespFollowUp(InstancePtr, PtpFrameBaseAddr);
          break;
          case XAVB_PTP_TYPE_ANNOUNCE:
            XAvb_DecodeRxAnnounceFrame(InstancePtr,
                                       PtpFrameBaseAddr);
          break;
          case XAVB_PTP_TYPE_SIGNALING:
            XAvb_DecodeRxSignaling(InstancePtr, PtpFrameBaseAddr);
          break;
          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 {  
    while (   (InstancePtr->PtpCounters.RxPtpSoftPointer & 0xF)
           != (InstancePtr->PtpCounters.RxPtpHardPointer & 0xF) ) {
      InstancePtr->PtpCounters.RxPtpSoftPointer
          = InstancePtr->PtpCounters.RxPtpSoftPointer + 1;
    }
  }
}
void XAvb_PtpRxInterruptHandler ( XAvb * InstancePtr ) { #ifdef DEBUG_XAVB_LEVEL1 u32 x = 0 ; #endif u32 MessageType = 0 ; u32 PtpFrameBaseAddr = 0 ; InstancePtr -> PtpCounters . RxPtpHardPointer = ( XAvb_ReadReg ( InstancePtr -> Config . BaseAddress , XAVB_PTP_RX_CONTROL_OFFSET ) & XAVB_PTP_RX_PACKET_FIELD_MASK ) >> 8 ; if ( InstancePtr -> PtpIsRunning == 1 ) { while ( ( InstancePtr -> PtpCounters . RxPtpSoftPointer & 0xF ) != ( InstancePtr -> PtpCounters . RxPtpHardPointer & 0xF ) ) { InstancePtr -> PtpCounters . RxPtpSoftPointer = InstancePtr -> PtpCounters . RxPtpSoftPointer + 1 ; PtpFrameBaseAddr = XAVB_PTP_RX_BASE_OFFSET + ( ( InstancePtr -> PtpCounters . RxPtpSoftPointer & 0xF ) << 8 ) ; if ( XAvb_IsRxFramePTP ( InstancePtr , PtpFrameBaseAddr ) == 1 ) { MessageType = ( XAvb_ReadPtpBuffer ( InstancePtr -> Config . BaseAddress , PtpFrameBaseAddr , XAVB_PTP_RX_PKT_TYPE_OFFSET ) & 0x000F0000 ) >> 16 ; switch ( MessageType ) { case XAVB_PTP_TYPE_SYNC : XAvb_DecodeRxSync ( InstancePtr , PtpFrameBaseAddr ) ; break ; case XAVB_PTP_TYPE_FOLLOW_UP : XAvb_DecodeRxFollowUp ( InstancePtr , PtpFrameBaseAddr ) ; break ; case XAVB_PTP_TYPE_PDELAYREQ : XAvb_SendPDelayResp ( InstancePtr , PtpFrameBaseAddr ) ; XAvb_SendPDelayRespFollowUp ( InstancePtr ) ; break ; case XAVB_PTP_TYPE_PDELAYRESP : XAvb_DecodeRxPDelayResp ( InstancePtr , PtpFrameBaseAddr ) ; break ; case XAVB_PTP_TYPE_PDELAYRESP_FOLLOW_UP : EchoPTPFramesReceived = 1 ; XAvb_DecodeRxPDelayRespFollowUp ( InstancePtr , PtpFrameBaseAddr ) ; break ; case XAVB_PTP_TYPE_ANNOUNCE : XAvb_DecodeRxAnnounceFrame ( InstancePtr , PtpFrameBaseAddr ) ; break ; case XAVB_PTP_TYPE_SIGNALING : XAvb_DecodeRxSignaling ( InstancePtr , PtpFrameBaseAddr ) ; break ; default : #ifdef DEBUG_XAVB_LEVEL1 xil_printf ( " \r \n " ) ; xil_printf ( " \r \n " ) ; xil_printf ( " \r \n " , MessageType ) ; xil_printf ( " \r \n " ) ; for ( x = 0 ; x < 0x100 ; x = x + 4 ) { xil_printf ( " \r \n " , x , ( XAvb_ReadPtpBuffer ( InstancePtr -> Config . BaseAddress , PtpFrameBaseAddr , x ) ) ) ; } #endif break ; } } } } else { while ( ( InstancePtr -> PtpCounters . RxPtpSoftPointer & 0xF ) != ( InstancePtr -> PtpCounters . RxPtpHardPointer & 0xF ) ) { InstancePtr -> PtpCounters . RxPtpSoftPointer = InstancePtr -> PtpCounters . RxPtpSoftPointer + 1 ; } } }
The Interrupt subroutine for the "interrupt_ptp_rx" signal.
The Interrupt subroutine for the " interrupt_ptp_rx " signal .
/** 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.*/ /** If PTP functions are marked as not running, then take no further action */ /** RxPtpSoftPointer indicates the bin location of the last frame to be
     * processed in software. */ /** decode the rx'd frames until RxPtpHardPointer = RxPtpSoftPointer */ /** Set the base address of the current PTP frame in the Buffer */ /** Perform very basic sanity checking of the frame : is it a PTP? */ /** Determine which PTP frame was received. */ /** Now act on the received frame */ /** Sync Frame
           * ---------- */ /** Follow Up Frame
           * --------------- */ /** PDelayReq Frame
           * --------------- */ /** Send a send PDelayResp frame after receiving a PDelayReq Frame */ /** Send a send PDelayRespFollowUp frame after a PDelayResp Frame */ /** PDelayResp Frame
           * ---------------- */ /** PDelayRespFollowUp Frame
           * ------------------------ */ /** Announce Frame
           * -------------- */ /** Signaling Frame
           * -------------- */ /** Unknown Frame
           * -------------- */ /* InstancePtr->PtpIsRunning != 1 */ /** PTP is not running so just consume the packets so they are not left in the
     * queue and cause problems when we actually start */ /** RxPtpSoftPointer indicates the bin location of the last frame to be
     * processed in software. */ /** decode the rx'd frames until RxPtpHardPointer = RxPtpSoftPointer */