void EtherPort::becomeMaster( bool annc ) { setPortState( PTP_MASTER ); // Stop announce receipt timeout timer clock->deleteEventTimerLocked( this, ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES ); // Stop sync receipt timeout timer stopSyncReceiptTimer(); if( annc ) { if (!automotive_profile) { startAnnounce(); } } startSyncIntervalTimer(16000000); GPTP_LOG_STATUS("Switching to Master" ); clock->updateFUPInfo(); return; }
void EtherPort::becomeSlave( bool restart_syntonization ) { clock->deleteEventTimerLocked( this, ANNOUNCE_INTERVAL_TIMEOUT_EXPIRES ); clock->deleteEventTimerLocked( this, SYNC_INTERVAL_TIMEOUT_EXPIRES ); setPortState( PTP_SLAVE ); if (!automotive_profile) { clock->addEventTimerLocked (this, ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES, (ANNOUNCE_RECEIPT_TIMEOUT_MULTIPLIER* (unsigned long long) (pow((double)2,getAnnounceInterval())*1000000000.0))); } GPTP_LOG_STATUS("Switching to Slave" ); if( restart_syntonization ) clock->newSyntonizationSetPoint(); getClock()->updateFUPInfo(); return; }
void CommonPort::recommendState ( PortState state, bool changed_external_master ) { bool reset_sync = false; switch (state) { case PTP_MASTER: if ( getPortState() != PTP_MASTER ) { setPortState( PTP_MASTER ); // Start announce receipt timeout timer // Start sync receipt timeout timer becomeMaster( true ); reset_sync = true; } break; case PTP_SLAVE: if ( getPortState() != PTP_SLAVE ) { becomeSlave( true ); reset_sync = true; } else { if( changed_external_master ) { GPTP_LOG_STATUS("Changed master!" ); clock->newSyntonizationSetPoint(); clock->updateFUPInfo(); reset_sync = true; } } break; default: GPTP_LOG_ERROR ("Invalid state change requested by call to " "1588Port::recommendState()"); break; } if( reset_sync ) sync_count = 0; return; }
bool CommonPort::processSyncAnnounceTimeout( Event e ) { // We're Grandmaster, set grandmaster info to me ClockIdentity clock_identity; unsigned char priority1; unsigned char priority2; ClockQuality clock_quality; Timestamp system_time; Timestamp device_time; uint32_t local_clock, nominal_clock_rate; // Nothing to do if( clock->getPriority1() == 255 ) return true; // Restart timer if( e == ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES ) { clock->addEventTimerLocked (this, ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES, (ANNOUNCE_RECEIPT_TIMEOUT_MULTIPLIER* (unsigned long long) (pow((double)2,getAnnounceInterval())* 1000000000.0))); } else { startSyncReceiptTimer ((unsigned long long) (SYNC_RECEIPT_TIMEOUT_MULTIPLIER * ((double) pow((double)2, getSyncInterval()) * 1000000000.0))); } if( getPortState() == PTP_MASTER ) return true; GPTP_LOG_STATUS( "*** %s Timeout Expired - Becoming Master", e == ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES ? "Announce" : "Sync" ); clock_identity = getClock()->getClockIdentity(); getClock()->setGrandmasterClockIdentity( clock_identity ); priority1 = getClock()->getPriority1(); getClock()->setGrandmasterPriority1( priority1 ); priority2 = getClock()->getPriority2(); getClock()->setGrandmasterPriority2( priority2 ); clock_quality = getClock()->getClockQuality(); getClock()->setGrandmasterClockQuality( clock_quality ); setPortState( PTP_MASTER ); getDeviceTime( system_time, device_time, local_clock, nominal_clock_rate ); (void) clock->calcLocalSystemClockRateDifference ( device_time, system_time ); setQualifiedAnnounce( NULL ); clock->addEventTimerLocked ( this, SYNC_INTERVAL_TIMEOUT_EXPIRES, 16000000 ); startAnnounce(); return true; }