XilinxProcessorIPLib/drivers/axiethernet/examples/avb/xavb.c
void XAvb_PtpTimerInterruptHandler(XAvb * InstancePtr) {

  /** Clear Interrupt */
  XAvb_WriteReg(InstancePtr->Config.BaseAddress,
                 XAVB_RTC_CLEAR_INT_OFFSET,
                 XAVB_RTC_CLEAR_INT_MASK);

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

    /** If the Link Partner is not AS capable, then take no further action */
    if (InstancePtr->PeerASCapable == 1) {


      /** If a Master, then initiate Sync Frames and Announce frames at the
       *  correct intervals
       */
      if (InstancePtr->CurrentBmc.IAmTheRtcMaster == 1) {

         /** Master will initiate a Sync Frame when the SyncIntervalDuration
          *  expires (SyncIntervalDuration is used to count/time the duration)
          * - unless a Signalling frame has told us not to send Sync Frames
          */
         if ((InstancePtr->SignallingFrameData.SyncIntervalDuration != XAVB_PKT_TYPE_DISABLED) &&
             (InstancePtr->PtpCounters.CounterSyncInterval >=
            (InstancePtr->SignallingFrameData.SyncIntervalDuration-1))) {

           XAvb_MasterSendSync(InstancePtr);
           InstancePtr->PtpCounters.CounterSyncInterval = 0;

           /** Following a Sync Frame, a Follow Up frame should always be sent
            */
           XAvb_MasterSendFollowUp(InstancePtr);


         } else {
           InstancePtr->PtpCounters.CounterSyncInterval
               = InstancePtr->PtpCounters.CounterSyncInterval + 1;
         }

         /** Master will initiate an Announce Frame when the
          *  AnnounceIntervalDuration expires (CounterAnnounceInterval is used
          *  to count/time the duration)
          * - unless a Signalling frame has told us not to send Announce Frames
          */
         if ((InstancePtr->SignallingFrameData.AnnounceIntervalDuration != XAVB_PKT_TYPE_DISABLED) &&
             (InstancePtr->PtpCounters.CounterAnnounceInterval >=
              (InstancePtr->SignallingFrameData.AnnounceIntervalDuration-1))) {

           XAvb_MasterSendAnnounce(InstancePtr);
           InstancePtr->PtpCounters.CounterAnnounceInterval = 0;

         } else {
           InstancePtr->PtpCounters.CounterAnnounceInterval
               = InstancePtr->PtpCounters.CounterAnnounceInterval + 1;
         }

      /** If a Slave, monitor Announce/Sync Packet reception from the Master */
      } else {

        /** Timeout for Announce Packet reception: XAVB_ANNOUNCE_RECEIPT_TIMEOUT
         *  The AnnounceIntervalDuration is stored with the GrandMaster BMCA data
         *  as it is captured from the last Announce frame that was received.
         */
        if (InstancePtr->PtpCounters.CounterAnnounceInterval >=
            ((InstancePtr->CurrentBmc.AnnounceIntervalDuration-1) *
             XAVB_ANNOUNCE_RECEIPT_TIMEOUT) ) {

#ifdef XAVB_DEBUG_LEVEL1
          xil_printf("XAVB_ANNOUNCE_RECEIPT_TIMEOUT: Becoming GM! CounterAnnounceInterval = %d\r\n", InstancePtr->PtpCounters.CounterAnnounceInterval);
#endif

          InstancePtr->PtpCounters.CounterAnnounceInterval = 0;

          /** No Announce received from GM for timeout interval: we become the master */
          xil_printf("\r\n*** Announce timeout : Call XAvb_BecomeRtcMaster() *** \r\n");
          XAvb_BecomeRtcMaster(InstancePtr,0);

        } else {
          InstancePtr->PtpCounters.CounterAnnounceInterval
              = InstancePtr->PtpCounters.CounterAnnounceInterval + 1;
        }

        /** Timeout for Sync Packet reception: XAVB_SYNC_RECEIPT_TIMEOUT *
         *  The SyncIntervalDuration is stored with the Received Sync data
         *  as it is captured from the last Sync frame that was received.
         */
        if( InstancePtr->PtpCounters.CounterSyncInterval >=
            ((InstancePtr->latestMDSyncReceive.SyncIntervalDuration-1) *
             XAVB_SYNC_RECEIPT_TIMEOUT) ) {

#ifdef XAVB_DEBUG_LEVEL1
          xil_printf("\r\nXAVB_SYNC_RECEIPT_TIMEOUT: Becoming GM! CounterSyncInterval = %d\r\n", InstancePtr->PtpCounters.CounterSyncInterval);
          xil_printf("\r\nXAVB_SYNC_RECEIPT_TIMEOUT: SyncIntervalDuration = %d\r\n", InstancePtr->SignallingFrameData.SyncIntervalDuration);
#endif

          InstancePtr->PtpCounters.CounterSyncInterval = 0;


          /** No Syncs received from GM for timeout interval: we become
           *  the master */
          xil_printf("\r\n*** Sync Timeout : Call XAvb_BecomeRtcMaster() *** \r\n");
          XAvb_BecomeRtcMaster(InstancePtr,0);

        } else {
          InstancePtr->PtpCounters.CounterSyncInterval
              = InstancePtr->PtpCounters.CounterSyncInterval + 1;
        }
      }
    }

    /** Both Master and Slave will initiate a link delay measurement when the
     *  LinkDelayIntervalDuration expires (LinkDelayIntervalDuration is used to
     *  count/time the duration)
     * - unless a Signalling frame has told us not to send PdelayReq Frames
     */
    if ((InstancePtr->SignallingFrameData.LinkDelayIntervalDuration != XAVB_PKT_TYPE_DISABLED) &&
        (InstancePtr->PtpCounters.CounterLinkDelayInterval >=
         (InstancePtr->SignallingFrameData.LinkDelayIntervalDuration-1))) {

      /** Check to see if we've received PDelayResp and
       *  PDelayRespFollowUp messages since the last PDelayReq was
       *  sent */
      if( InstancePtr->StateMachineData.rcvdPDelayResp &&
          InstancePtr->StateMachineData.rcvdPDelayRespFollowUp ) {

        InstancePtr->StateMachineData.lostResponses = 0;
      } else {
        InstancePtr->StateMachineData.lostResponses++;
      }

      if( InstancePtr->StateMachineData.lostResponses >= XAVB_ALLOWED_LOST_RESPONSES ) {
        /** the peer is no longer ASCapable */
        XAvb_ChangePeerASCapability(InstancePtr, 0);

        xil_printf("\r\n** XAvb_PtpTimerInterruptHandler(): The peer is no longer ASCapable **");
        xil_printf("\r\n** XAvb_PtpTimerInterruptHandler(): StateMachineData.lostResponses >= %d **",
                   XAVB_ALLOWED_LOST_RESPONSES);

        /** avoid potential overflow */
        InstancePtr->StateMachineData.lostResponses = XAVB_ALLOWED_LOST_RESPONSES;
      }

      XAvb_SendPDelayReq(InstancePtr);

      InstancePtr->StateMachineData.rcvdPDelayResp         = 0;
      InstancePtr->StateMachineData.rcvdPDelayRespFollowUp = 0;
      InstancePtr->PtpCounters.CounterLinkDelayInterval    = 0;

    } else {
      InstancePtr->PtpCounters.CounterLinkDelayInterval
          = InstancePtr->PtpCounters.CounterLinkDelayInterval + 1;
    }

  } /** end of 'if (InstancePtr->PtpIsRunning == 1)' */

}
/****************************************************************************/
/**
*
* The Interrupt subroutine for the "interruptPtpTimer" signal.  This interrupt
* fires regularly on a 1/128 second period (based on the RTC).
*
* @param  InstancePtr is a pointer to the XAvb instance to be worked on
*
* @return None.
*
* @note   None.
*
*****************************************************************************/
The Interrupt subroutine for the "interruptPtpTimer" signal.  This interrupt
fires regularly on a 1/128 second period (based on the RTC).
The Interrupt subroutine for the " interruptPtpTimer " signal . This interrupt fires regularly on a 1 / 128 second period ( based on the RTC ) .
void XAvb_PtpTimerInterruptHandler(XAvb * InstancePtr) {
  XAvb_WriteReg(InstancePtr->Config.BaseAddress,
                 XAVB_RTC_CLEAR_INT_OFFSET,
                 XAVB_RTC_CLEAR_INT_MASK);
  if (InstancePtr->PtpIsRunning == 1) {
    if (InstancePtr->PeerASCapable == 1) {
      if (InstancePtr->CurrentBmc.IAmTheRtcMaster == 1) {
         if ((InstancePtr->SignallingFrameData.SyncIntervalDuration != XAVB_PKT_TYPE_DISABLED) &&
             (InstancePtr->PtpCounters.CounterSyncInterval >=
            (InstancePtr->SignallingFrameData.SyncIntervalDuration-1))) {
           XAvb_MasterSendSync(InstancePtr);
           InstancePtr->PtpCounters.CounterSyncInterval = 0;
           XAvb_MasterSendFollowUp(InstancePtr);
         } else {
           InstancePtr->PtpCounters.CounterSyncInterval
               = InstancePtr->PtpCounters.CounterSyncInterval + 1;
         }
         if ((InstancePtr->SignallingFrameData.AnnounceIntervalDuration != XAVB_PKT_TYPE_DISABLED) &&
             (InstancePtr->PtpCounters.CounterAnnounceInterval >=
              (InstancePtr->SignallingFrameData.AnnounceIntervalDuration-1))) {
           XAvb_MasterSendAnnounce(InstancePtr);
           InstancePtr->PtpCounters.CounterAnnounceInterval = 0;
         } else {
           InstancePtr->PtpCounters.CounterAnnounceInterval
               = InstancePtr->PtpCounters.CounterAnnounceInterval + 1;
         }
      } else {
        if (InstancePtr->PtpCounters.CounterAnnounceInterval >=
            ((InstancePtr->CurrentBmc.AnnounceIntervalDuration-1) *
             XAVB_ANNOUNCE_RECEIPT_TIMEOUT) ) {
#ifdef XAVB_DEBUG_LEVEL1
          xil_printf("XAVB_ANNOUNCE_RECEIPT_TIMEOUT: Becoming GM! CounterAnnounceInterval = %d\r\n", InstancePtr->PtpCounters.CounterAnnounceInterval);
#endif
          InstancePtr->PtpCounters.CounterAnnounceInterval = 0;
          xil_printf("\r\n*** Announce timeout : Call XAvb_BecomeRtcMaster() *** \r\n");
          XAvb_BecomeRtcMaster(InstancePtr,0);
        } else {
          InstancePtr->PtpCounters.CounterAnnounceInterval
              = InstancePtr->PtpCounters.CounterAnnounceInterval + 1;
        }
        if( InstancePtr->PtpCounters.CounterSyncInterval >=
            ((InstancePtr->latestMDSyncReceive.SyncIntervalDuration-1) *
             XAVB_SYNC_RECEIPT_TIMEOUT) ) {
#ifdef XAVB_DEBUG_LEVEL1
          xil_printf("\r\nXAVB_SYNC_RECEIPT_TIMEOUT: Becoming GM! CounterSyncInterval = %d\r\n", InstancePtr->PtpCounters.CounterSyncInterval);
          xil_printf("\r\nXAVB_SYNC_RECEIPT_TIMEOUT: SyncIntervalDuration = %d\r\n", InstancePtr->SignallingFrameData.SyncIntervalDuration);
#endif
          InstancePtr->PtpCounters.CounterSyncInterval = 0;
          xil_printf("\r\n*** Sync Timeout : Call XAvb_BecomeRtcMaster() *** \r\n");
          XAvb_BecomeRtcMaster(InstancePtr,0);
        } else {
          InstancePtr->PtpCounters.CounterSyncInterval
              = InstancePtr->PtpCounters.CounterSyncInterval + 1;
        }
      }
    }
    if ((InstancePtr->SignallingFrameData.LinkDelayIntervalDuration != XAVB_PKT_TYPE_DISABLED) &&
        (InstancePtr->PtpCounters.CounterLinkDelayInterval >=
         (InstancePtr->SignallingFrameData.LinkDelayIntervalDuration-1))) {
      if( InstancePtr->StateMachineData.rcvdPDelayResp &&
          InstancePtr->StateMachineData.rcvdPDelayRespFollowUp ) {
        InstancePtr->StateMachineData.lostResponses = 0;
      } else {
        InstancePtr->StateMachineData.lostResponses++;
      }
      if( InstancePtr->StateMachineData.lostResponses >= XAVB_ALLOWED_LOST_RESPONSES ) {
        XAvb_ChangePeerASCapability(InstancePtr, 0);
        xil_printf("\r\n** XAvb_PtpTimerInterruptHandler(): The peer is no longer ASCapable **");
        xil_printf("\r\n** XAvb_PtpTimerInterruptHandler(): StateMachineData.lostResponses >= %d **",
                   XAVB_ALLOWED_LOST_RESPONSES);
        InstancePtr->StateMachineData.lostResponses = XAVB_ALLOWED_LOST_RESPONSES;
      }
      XAvb_SendPDelayReq(InstancePtr);
      InstancePtr->StateMachineData.rcvdPDelayResp         = 0;
      InstancePtr->StateMachineData.rcvdPDelayRespFollowUp = 0;
      InstancePtr->PtpCounters.CounterLinkDelayInterval    = 0;
    } else {
      InstancePtr->PtpCounters.CounterLinkDelayInterval
          = InstancePtr->PtpCounters.CounterLinkDelayInterval + 1;
    }
  } 
}
void XAvb_PtpTimerInterruptHandler ( XAvb * InstancePtr ) { XAvb_WriteReg ( InstancePtr -> Config . BaseAddress , XAVB_RTC_CLEAR_INT_OFFSET , XAVB_RTC_CLEAR_INT_MASK ) ; if ( InstancePtr -> PtpIsRunning == 1 ) { if ( InstancePtr -> PeerASCapable == 1 ) { if ( InstancePtr -> CurrentBmc . IAmTheRtcMaster == 1 ) { if ( ( InstancePtr -> SignallingFrameData . SyncIntervalDuration != XAVB_PKT_TYPE_DISABLED ) && ( InstancePtr -> PtpCounters . CounterSyncInterval >= ( InstancePtr -> SignallingFrameData . SyncIntervalDuration - 1 ) ) ) { XAvb_MasterSendSync ( InstancePtr ) ; InstancePtr -> PtpCounters . CounterSyncInterval = 0 ; XAvb_MasterSendFollowUp ( InstancePtr ) ; } else { InstancePtr -> PtpCounters . CounterSyncInterval = InstancePtr -> PtpCounters . CounterSyncInterval + 1 ; } if ( ( InstancePtr -> SignallingFrameData . AnnounceIntervalDuration != XAVB_PKT_TYPE_DISABLED ) && ( InstancePtr -> PtpCounters . CounterAnnounceInterval >= ( InstancePtr -> SignallingFrameData . AnnounceIntervalDuration - 1 ) ) ) { XAvb_MasterSendAnnounce ( InstancePtr ) ; InstancePtr -> PtpCounters . CounterAnnounceInterval = 0 ; } else { InstancePtr -> PtpCounters . CounterAnnounceInterval = InstancePtr -> PtpCounters . CounterAnnounceInterval + 1 ; } } else { if ( InstancePtr -> PtpCounters . CounterAnnounceInterval >= ( ( InstancePtr -> CurrentBmc . AnnounceIntervalDuration - 1 ) * XAVB_ANNOUNCE_RECEIPT_TIMEOUT ) ) { #ifdef XAVB_DEBUG_LEVEL1 xil_printf ( " \r \n " , InstancePtr -> PtpCounters . CounterAnnounceInterval ) ; #endif InstancePtr -> PtpCounters . CounterAnnounceInterval = 0 ; xil_printf ( " \r \n \r \n " ) ; XAvb_BecomeRtcMaster ( InstancePtr , 0 ) ; } else { InstancePtr -> PtpCounters . CounterAnnounceInterval = InstancePtr -> PtpCounters . CounterAnnounceInterval + 1 ; } if ( InstancePtr -> PtpCounters . CounterSyncInterval >= ( ( InstancePtr -> latestMDSyncReceive . SyncIntervalDuration - 1 ) * XAVB_SYNC_RECEIPT_TIMEOUT ) ) { #ifdef XAVB_DEBUG_LEVEL1 xil_printf ( " \r \n \r \n " , InstancePtr -> PtpCounters . CounterSyncInterval ) ; xil_printf ( " \r \n \r \n " , InstancePtr -> SignallingFrameData . SyncIntervalDuration ) ; #endif InstancePtr -> PtpCounters . CounterSyncInterval = 0 ; xil_printf ( " \r \n \r \n " ) ; XAvb_BecomeRtcMaster ( InstancePtr , 0 ) ; } else { InstancePtr -> PtpCounters . CounterSyncInterval = InstancePtr -> PtpCounters . CounterSyncInterval + 1 ; } } } if ( ( InstancePtr -> SignallingFrameData . LinkDelayIntervalDuration != XAVB_PKT_TYPE_DISABLED ) && ( InstancePtr -> PtpCounters . CounterLinkDelayInterval >= ( InstancePtr -> SignallingFrameData . LinkDelayIntervalDuration - 1 ) ) ) { if ( InstancePtr -> StateMachineData . rcvdPDelayResp && InstancePtr -> StateMachineData . rcvdPDelayRespFollowUp ) { InstancePtr -> StateMachineData . lostResponses = 0 ; } else { InstancePtr -> StateMachineData . lostResponses ++ ; } if ( InstancePtr -> StateMachineData . lostResponses >= XAVB_ALLOWED_LOST_RESPONSES ) { XAvb_ChangePeerASCapability ( InstancePtr , 0 ) ; xil_printf ( " \r \n " ) ; xil_printf ( " \r \n " , XAVB_ALLOWED_LOST_RESPONSES ) ; InstancePtr -> StateMachineData . lostResponses = XAVB_ALLOWED_LOST_RESPONSES ; } XAvb_SendPDelayReq ( InstancePtr ) ; InstancePtr -> StateMachineData . rcvdPDelayResp = 0 ; InstancePtr -> StateMachineData . rcvdPDelayRespFollowUp = 0 ; InstancePtr -> PtpCounters . CounterLinkDelayInterval = 0 ; } else { InstancePtr -> PtpCounters . CounterLinkDelayInterval = InstancePtr -> PtpCounters . CounterLinkDelayInterval + 1 ; } } }
The Interrupt subroutine for the "interruptPtpTimer" signal.
The Interrupt subroutine for the " interruptPtpTimer " signal .
/** Clear Interrupt */ /** If PTP functions are marked as not running, then take no further action */ /** If the Link Partner is not AS capable, then take no further action */ /** If a Master, then initiate Sync Frames and Announce frames at the
       *  correct intervals
       */ /** Master will initiate a Sync Frame when the SyncIntervalDuration
          *  expires (SyncIntervalDuration is used to count/time the duration)
          * - unless a Signalling frame has told us not to send Sync Frames
          */ /** Following a Sync Frame, a Follow Up frame should always be sent
            */ /** Master will initiate an Announce Frame when the
          *  AnnounceIntervalDuration expires (CounterAnnounceInterval is used
          *  to count/time the duration)
          * - unless a Signalling frame has told us not to send Announce Frames
          */ /** If a Slave, monitor Announce/Sync Packet reception from the Master */ /** Timeout for Announce Packet reception: XAVB_ANNOUNCE_RECEIPT_TIMEOUT
         *  The AnnounceIntervalDuration is stored with the GrandMaster BMCA data
         *  as it is captured from the last Announce frame that was received.
         */ /** No Announce received from GM for timeout interval: we become the master */ /** Timeout for Sync Packet reception: XAVB_SYNC_RECEIPT_TIMEOUT *
         *  The SyncIntervalDuration is stored with the Received Sync data
         *  as it is captured from the last Sync frame that was received.
         */ /** No Syncs received from GM for timeout interval: we become
           *  the master */ /** Both Master and Slave will initiate a link delay measurement when the
     *  LinkDelayIntervalDuration expires (LinkDelayIntervalDuration is used to
     *  count/time the duration)
     * - unless a Signalling frame has told us not to send PdelayReq Frames
     */ /** Check to see if we've received PDelayResp and
       *  PDelayRespFollowUp messages since the last PDelayReq was
       *  sent */ /** the peer is no longer ASCapable */ /** avoid potential overflow */ /** end of 'if (InstancePtr->PtpIsRunning == 1)' */