summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Cemin <david.cemin@coveloz.com>2016-01-22 14:13:08 -0500
committerDavid Cemin <david.cemin@coveloz.com>2016-01-22 14:13:08 -0500
commit822937670c6c8987bef08bdcca5f031e64d0a09e (patch)
treefdf59da9bc7f7ae6d568e65cd44398ce3fe15427
parentf063c1c6d63249a6aebae9c3b00439fc18417738 (diff)
downloadOpen-AVB-822937670c6c8987bef08bdcca5f031e64d0a09e.tar.gz
Updating TimeBaseIndicator when becoming master/slave
There are probably other places that the info should be updated. This is just the first approach to get that information in place. Later it needs to be implemented the phaseChange calculation and call the method that updates the TBI in other necessary places as well
-rw-r--r--daemons/gptp/common/avbts_clock.hpp48
-rw-r--r--daemons/gptp/common/avbts_message.hpp113
-rw-r--r--daemons/gptp/common/ieee1588clock.cpp3
-rw-r--r--daemons/gptp/common/ieee1588port.cpp12
-rw-r--r--daemons/gptp/common/ptp_message.cpp15
5 files changed, 146 insertions, 45 deletions
diff --git a/daemons/gptp/common/avbts_clock.hpp b/daemons/gptp/common/avbts_clock.hpp
index f9611059..1a10b999 100644
--- a/daemons/gptp/common/avbts_clock.hpp
+++ b/daemons/gptp/common/avbts_clock.hpp
@@ -130,7 +130,21 @@ private:
FrequencyRatio _master_local_freq_offset;
FrequencyRatio _local_system_freq_offset;
- OSLock *timerq_lock;
+ /**
+ * fup info stores information of the last time
+ * the base time has changed. When that happens
+ * the information from fup_status is copied over
+ * fup_info. The follow-up sendPort method is
+ * supposed to get the information from fup_info
+ * prior to sending a message out.
+ */
+ FollowUpTLV *fup_info;
+
+ /**
+ * fup status has the instantaneous info*/
+ FollowUpTLV *fup_status;
+
+ OSLock *timerq_lock;
public:
/**
* @brief Instantiates a IEEE 1588 Clock
@@ -361,6 +375,33 @@ public:
return (number_ports++ % (MAX_PORTS + 1)) + 1;
}
+ void setFUPInfo(FollowUpTLV *fup)
+ {
+ fup_info = fup;
+ }
+
+ FollowUpTLV *getFUPInfo(void)
+ {
+ return fup_info;
+ }
+
+ void updateFUPInfo(void)
+ {
+ fup_info->incrementGMTimeBaseIndicator();
+ fup_info->setScaledLastGmFreqChange(fup_status->getScaledLastGmFreqChange());
+ fup_info->setScaledLastGmPhaseChange(fup_status->getScaledLastGmPhaseChange());
+ }
+
+ void setFUPStatus(FollowUpTLV *fup)
+ {
+ fup_status = fup;
+ }
+
+ FollowUpTLV *getFUPStatus(void)
+ {
+ return fup_status;
+ }
+
/**
* @brief Registers a new IEEE1588 port
* @param port [in] IEEE1588port instance
@@ -485,6 +526,11 @@ public:
_new_syntonization_set_point = true;
}
+ FrequencyRatio getMLFreqOffset(void)
+ {
+ return _master_local_freq_offset;
+ }
+
/**
* @brief Gets all TX locks
* @return void
diff --git a/daemons/gptp/common/avbts_message.hpp b/daemons/gptp/common/avbts_message.hpp
index 858a8f5a..289bcb81 100644
--- a/daemons/gptp/common/avbts_message.hpp
+++ b/daemons/gptp/common/avbts_message.hpp
@@ -1,31 +1,31 @@
/******************************************************************************
- Copyright (c) 2009-2012, Intel Corporation
+ Copyright (c) 2009-2012, Intel Corporation
All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
+
+ Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
+
+ 1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
-
- 3. Neither the name of the Intel Corporation nor the names of its
- contributors may be used to endorse or promote products derived from
+
+ 3. Neither the name of the Intel Corporation nor the names of its
+ contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
@@ -169,22 +169,22 @@ protected:
unsigned char versionPTP; /*!< PTP version */
uint16_t versionNetwork; /*!< Network version */
MessageType messageType; /*!< MessageType to be built */
-
+
PortIdentity *sourcePortIdentity; /*!< PortIdentity from source*/
-
+
uint16_t sequenceId; /*!< PTP message sequence ID*/
LegacyMessageType control; /*!< Control message type of LegacyMessageType */
unsigned char flags[2]; /*!< PTP flags field */
-
+
uint16_t messageLength; /*!< PTP message length */
char logMeanMessageInterval; /*!< LogMessageInterval (IEEE 1588-2008 table 24)*/
long long correctionField; /*!< Correction Field (IEEE 1588-2008 table 21) */
unsigned char domainNumber; /*!< PTP domain number */
-
+
Timestamp _timestamp; /*!< PTP message timestamp */
unsigned _timestamp_counter_value; /*!< PTP timestamp counter value */
bool _gc; /*!< Garbage collection flag */
-
+
/**
* Default constructor
*/
@@ -542,7 +542,7 @@ class PTPMessageSync : public PTPMessageCommon {
PTPMessageSync();
public:
/**
- * @brief Default constructor. Creates PTPMessageSync
+ * @brief Default constructor. Creates PTPMessageSync
* @param port IEEE1588Port
*/
PTPMessageSync(IEEE1588Port * port);
@@ -622,7 +622,7 @@ class FollowUpTLV {
int32_t cumulativeScaledRateOffset;
uint16_t gmTimeBaseIndicator;
scaledNs scaledLastGmPhaseChange;
- int32_t scaledLastGmFreqChange;
+ int32_t scaledLastGmFreqChange;
public:
/**
* Builds the FollowUpTLV interface
@@ -655,6 +655,38 @@ class FollowUpTLV {
int32_t getRateOffset() {
return cumulativeScaledRateOffset;
}
+
+ void setScaledLastGmFreqChange(int32_t val)
+ {
+ scaledLastGmFreqChange = PLAT_htonl(val);
+ }
+ int32_t getScaledLastGmFreqChange(void)
+ {
+ return scaledLastGmFreqChange;
+ }
+
+ void setGMTimeBaseIndicator(uint16_t tbi)
+ {
+ gmTimeBaseIndicator = tbi;
+ }
+ void incrementGMTimeBaseIndicator(void)
+ {
+ ++gmTimeBaseIndicator;
+ printf("New TimebaseIndicator: %x\n", gmTimeBaseIndicator);
+ }
+ uint16_t getGMTimeBaseIndicator(void)
+ {
+ return gmTimeBaseIndicator;
+ }
+
+ void setScaledLastGmPhaseChange(scaledNs pc)
+ {
+ /*TODO*/
+ }
+ scaledNs getScaledLastGmPhaseChange(void)
+ {
+ return scaledLastGmPhaseChange;
+ }
};
/* back to whatever the previous packing mode was */
@@ -666,9 +698,9 @@ class FollowUpTLV {
class PTPMessageFollowUp:public PTPMessageCommon {
private:
Timestamp preciseOriginTimestamp;
-
+
FollowUpTLV tlv;
-
+
PTPMessageFollowUp(void) { }
public:
/**
@@ -689,7 +721,7 @@ public:
* @param port [in] IEEE1588Port
* @return void
*/
- void processMessage(IEEE1588Port * port);
+ void processMessage(IEEE1588Port * port);
/**
* @brief Gets the precise origin timestamp value
* @return preciseOriginTimestamp value
@@ -706,7 +738,14 @@ public:
void setPreciseOriginTimestamp(Timestamp & timestamp) {
preciseOriginTimestamp = timestamp;
}
-
+
+ void setClockSourceTime(FollowUpTLV *fup)
+ {
+ tlv.setGMTimeBaseIndicator(fup->getGMTimeBaseIndicator());
+ tlv.setScaledLastGmFreqChange(fup->getScaledLastGmFreqChange());
+ tlv.setScaledLastGmPhaseChange(fup->getScaledLastGmPhaseChange());
+ }
+
friend PTPMessageCommon *buildPTPMessage
(char *buf, int size, LinkLayerAddress * remote, IEEE1588Port * port);
};
@@ -755,7 +794,7 @@ class PTPMessagePathDelayReq : public PTPMessageCommon {
Timestamp getOriginTimestamp(void) {
return originTimestamp;
}
-
+
friend PTPMessageCommon *buildPTPMessage
(char *buf, int size, LinkLayerAddress * remote, IEEE1588Port * port);
};
@@ -767,8 +806,8 @@ class PTPMessagePathDelayResp:public PTPMessageCommon {
private:
PortIdentity * requestingPortIdentity;
Timestamp requestReceiptTimestamp;
-
- PTPMessagePathDelayResp(void) {
+
+ PTPMessagePathDelayResp(void) {
}
public:
/**
@@ -794,7 +833,7 @@ public:
* @return void
*/
void processMessage(IEEE1588Port * port);
-
+
/**
* @brief Sets the request receipt timestamp
* @param timestamp Timestamp to be set
@@ -803,7 +842,7 @@ public:
void setRequestReceiptTimestamp(Timestamp timestamp) {
requestReceiptTimestamp = timestamp;
}
-
+
/**
* @brief Sets requesting port identity
* @param identity [in] PortIdentity to be set
@@ -816,7 +855,7 @@ public:
* @return void
*/
void getRequestingPortIdentity(PortIdentity * identity);
-
+
/**
* @brief Gets the request receipt timestamp
* @return requestReceiptTimestamp
diff --git a/daemons/gptp/common/ieee1588clock.cpp b/daemons/gptp/common/ieee1588clock.cpp
index 6e090880..11ef6550 100644
--- a/daemons/gptp/common/ieee1588clock.cpp
+++ b/daemons/gptp/common/ieee1588clock.cpp
@@ -113,6 +113,9 @@ IEEE1588Clock::IEEE1588Clock
// This should be done LAST!! to pass fully initialized clock object
timerq = timerq_factory->createOSTimerQueue( this );
+ fup_info = new FollowUpTLV();
+ fup_status = new FollowUpTLV();
+
return;
}
diff --git a/daemons/gptp/common/ieee1588port.cpp b/daemons/gptp/common/ieee1588port.cpp
index 805c252a..72353723 100644
--- a/daemons/gptp/common/ieee1588port.cpp
+++ b/daemons/gptp/common/ieee1588port.cpp
@@ -445,8 +445,6 @@ void IEEE1588Port::processEvent(Event e)
IEEE1588Port **ports;
clock->getPortList(number_ports, ports);
-
-
/* Find EBest for all ports */
j = 0;
for (int i = 0; i < number_ports; ++i) {
@@ -789,10 +787,13 @@ void IEEE1588Port::processEvent(Event e)
PTPMessageFollowUp *follow_up;
if (ts_good == GPTP_EC_SUCCESS) {
+
follow_up =
new PTPMessageFollowUp(this);
PortIdentity dest_id;
getPortIdentity(dest_id);
+
+ follow_up->setClockSourceTime(getClock()->getFUPInfo());
follow_up->setPortIdentity(&dest_id);
follow_up->setSequenceId(sync->getSequenceId());
follow_up->setPreciseOriginTimestamp(sync_timestamp);
@@ -938,6 +939,8 @@ void IEEE1588Port::becomeMaster( bool annc ) {
clock->addEventTimer( this, SYNC_INTERVAL_TIMEOUT_EXPIRES, 16000000 );
fprintf( stderr, "Switching to Master\n" );
+ clock->updateFUPInfo();
+
return;
}
@@ -945,7 +948,7 @@ void IEEE1588Port::becomeSlave( bool restart_syntonization ) {
clock->deleteEventTimer( this, ANNOUNCE_INTERVAL_TIMEOUT_EXPIRES );
clock->deleteEventTimer( this, SYNC_INTERVAL_TIMEOUT_EXPIRES );
- port_state = PTP_SLAVE;
+ port_state = PTP_SLAVE;
/*clock->addEventTimer
( this, SYNC_RECEIPT_TIMEOUT_EXPIRES,
@@ -959,6 +962,8 @@ void IEEE1588Port::becomeSlave( bool restart_syntonization ) {
fprintf( stderr, "Switching to Slave\n" );
if( restart_syntonization ) clock->newSyntonizationSetPoint();
+ getClock()->updateFUPInfo();
+
return;
}
@@ -984,6 +989,7 @@ void IEEE1588Port::recommendState
if( changed_external_master ) {
fprintf( stderr, "Changed master!\n" );
clock->newSyntonizationSetPoint();
+ getClock()->updateFUPInfo();
reset_sync = true;
}
}
diff --git a/daemons/gptp/common/ptp_message.cpp b/daemons/gptp/common/ptp_message.cpp
index ec2bc702..52bbf4b0 100644
--- a/daemons/gptp/common/ptp_message.cpp
+++ b/daemons/gptp/common/ptp_message.cpp
@@ -179,7 +179,7 @@ PTPMessageCommon *buildPTPMessage
buf + PTP_SYNC_NSEC(PTP_SYNC_OFFSET),
sizeof(sync_msg->originTimestamp.nanoseconds));
msg = sync_msg;
- }
+ }
break;
case FOLLOWUP_MESSAGE:
@@ -226,7 +226,8 @@ PTPMessageCommon *buildPTPMessage
memcpy( &(followup_msg->tlv), buf+PTP_FOLLOWUP_LENGTH, sizeof(followup_msg->tlv) );
msg = followup_msg;
- }
+ }
+
break;
case PATH_DELAY_REQ_MESSAGE:
@@ -800,6 +801,7 @@ void PTPMessageSync::processMessage(IEEE1588Port * port)
if( flags[PTP_ASSIST_BYTE] & (0x1<<PTP_ASSIST_BIT)) {
PTPMessageSync *old_sync = port->getLastSync();
+
if (old_sync != NULL) {
delete old_sync;
}
@@ -873,7 +875,7 @@ void PTPMessageFollowUp::sendPort(IEEE1588Port * port,
XPTPD_INFO("Follow-up Dump:\n");
#ifdef DEBUG
for (int i = 0; i < messageLength; ++i) {
- fprintf(stderr, "%d:%02x ", i, (unsigned char)buf[i]);
+ fprintf(stderr, "%d:%02x ", i, (unsigned char)buf_t[i]);
}
fprintf(stderr, "\n");
#endif
@@ -898,6 +900,7 @@ void PTPMessageFollowUp::processMessage(IEEE1588Port * port)
FrequencyRatio local_system_freq_offset;
FrequencyRatio master_local_freq_offset;
int correction;
+ int32_t scaledLastGmFreqChange = 0;
XPTPD_INFO("Processing a follow-up message");
@@ -933,7 +936,7 @@ void PTPMessageFollowUp::processMessage(IEEE1588Port * port)
sync_arrival = sync->getTimestamp();
delay = port->getLinkDelay();
- if ((delay = port->getLinkDelay()) == 3600000000000) {
+ if ((delay = port->getLinkDelay()) == 3600000000000) { /*TODO: ONE_WAY_DELAY_DEFAULT*/
goto done;
}
@@ -983,6 +986,10 @@ void PTPMessageFollowUp::processMessage(IEEE1588Port * port)
calcMasterLocalClockRateDifference
( preciseOriginTimestamp, sync_arrival );
+ /*Update LastGmFreqChange on local status structure.*/
+ scaledLastGmFreqChange = (int32_t)((1.0/local_clock_adjustment -1.0) * (1ULL << 41));
+ port->getClock()->getFUPStatus()->setScaledLastGmFreqChange(local_clock_adjustment);
+
if( port->getPortState() != PTP_MASTER ) {
port->incSyncCount();
/* Do not call calcLocalSystemClockRateDifference it updates state