47 #include <platform.hpp>
54 #define PTP_CLOCK_IDENTITY_LENGTH 8
56 class LinkLayerAddress;
136 return memcmp(this->
id, cmp.id,
155 return memcmp(this->
id, cmp.id,
165 return memcmp(this->
id, cmp.id,
210 (
"Clock Identity(%s): %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx\n",
211 str,
id[0],
id[1],
id[2],
id[3],
id[4],
id[5],
id[6],
id[7] );
215 #define INVALID_TIMESTAMP_VERSION 0xFF
216 #define MAX_NANOSECONDS 1000000000
217 #define MAX_TIMESTAMP_STRLEN 28
234 (uint32_t ns, uint32_t s_l, uint16_t s_m,
246 output_string[0] =
'\0';
260 ( output_string, 28,
"%hu %u %u", seconds_ms, seconds_ls
263 return output_string;
272 uint32_t nanoseconds;
278 nanoseconds = this->nanoseconds;
281 nanoseconds < this->nanoseconds ||
285 seconds_ls = this->seconds_ls;
287 seconds_ls += carry ? 1 : 0;
288 carry = seconds_ls < this->seconds_ls ?
true :
false;
290 seconds_ms = this->seconds_ms;
292 seconds_ms += carry ? 1 : 0;
293 carry = seconds_ms < this->seconds_ms ?
true :
false;
295 version = this->_version == o.
_version ? this->_version :
297 return Timestamp( nanoseconds, seconds_ls, seconds_ms, version );
306 uint32_t nanoseconds;
310 bool carry, borrow_this;
311 unsigned borrow_total = 0;
318 nanoseconds -= carry ? MAX_NANOSECONDS : 0;
319 borrow_total += borrow_this ? 1 : 0;
321 seconds_ls = carry ? 1 : 0;
322 seconds_ls += this->seconds_ls;
324 borrow_total > seconds_ls ||
327 borrow_this ? seconds_ls - o.
seconds_ls + (uint32_t)-1 :
329 borrow_total = borrow_this ? borrow_total + 1 : 0;
331 seconds_ms = carry ? 1 : 0;
332 seconds_ms += this->seconds_ms;
334 borrow_total > seconds_ms ||
337 borrow_this ? seconds_ms - o.
seconds_ms + (uint32_t)-1 :
339 borrow_total = borrow_this ? borrow_total + 1 : 0;
341 version = this->_version == o.
_version ? this->_version :
343 return Timestamp( nanoseconds, seconds_ls, seconds_ms, version );
352 nanoseconds = value % 1000000000;
353 seconds_ls = (uint32_t) (value / 1000000000);
354 seconds_ms = (uint16_t)((value / 1000000000) >> 32);
358 #define INVALID_TIMESTAMP (Timestamp( 0xC0000000, 0, 0 ))
359 #define PDELAY_PENDING_TIMESTAMP (Timestamp( 0xC0000001, 0, 0 ))
361 #define TIMESTAMP_TO_NS(ts) (((static_cast<long long int>((ts).seconds_ms) \
362 << sizeof((ts).seconds_ls)*8) + \
363 (ts).seconds_ls)*1000000000LL + (ts).nanoseconds)
370 static inline uint64_t byte_swap64(uint64_t in)
372 uint8_t *s = (uint8_t *) & in;
385 #define NS_PER_SECOND 1000000000
386 #define LS_SEC_MAX 0xFFFFFFFFull
394 static inline void TIMESTAMP_SUB_NS( Timestamp &ts, uint64_t ns ) {
395 uint64_t secs = (uint64_t)ts.seconds_ls | ((uint64_t)ts.seconds_ms) << 32;
396 uint64_t nanos = (uint64_t)ts.nanoseconds;
409 ts.seconds_ms = (uint16_t)(secs >> 32);
410 ts.seconds_ls = (uint32_t)(secs &
LS_SEC_MAX);
411 ts.nanoseconds = (uint32_t)nanos;
420 static inline void TIMESTAMP_ADD_NS(
Timestamp &ts, uint64_t ns ) {
438 #define HWTIMESTAMPER_EXTENDED_MESSAGE_SIZE 4096
443 class HWTimestamper {
453 virtual bool HWTimestamper_init
461 virtual void HWTimestamper_final(
void) {
469 virtual bool HWTimestamper_adjclockrate(
float frequency_offset )
477 virtual bool HWTimestamper_adjclockphase( int64_t phase_adjust )
493 virtual bool HWTimestamper_gettime(
Timestamp * system_time,
495 uint32_t * local_clock,
496 uint32_t * nominal_clock_rate) = 0;
507 virtual int HWTimestamper_txtimestamp(
PortIdentity * identity,
510 unsigned &clock_value,
522 virtual int HWTimestamper_rxtimestamp(
PortIdentity * identity,
525 unsigned &clock_value,
537 virtual bool HWTimestamper_get_extclk_offset(
Timestamp * local_time,
538 int64_t * clk_offset,
550 virtual void HWTimestamper_get_extderror(
char *msg) {
558 virtual bool HWTimestamper_PPS_start() {
return false; };
564 virtual bool HWTimestamper_PPS_stop() {
return true; };
Power Up. Initialize state machines.
Definition: ieee1588.hpp:76
Pdelay response message timeout.
Definition: ieee1588.hpp:87
Definition: avbts_message.hpp:542
void set64(uint64_t value)
Sets a 64bit value to the object's timestamp.
Definition: ieee1588.hpp:351
Definition: ieee1588.hpp:101
Definition: ieee1588.hpp:445
Definition: avbts_message.hpp:434
PDELAY interval expired. Its time to send pdelay_req message.
Definition: ieee1588.hpp:80
void getIdentityString(uint8_t *id)
Gets the identity string from the ClockIdentity object.
Definition: ieee1588.hpp:180
PTPMessageCommon * buildPTPMessage(char *buf, int size, LinkLayerAddress *remote, IEEE1588Port *port)
Builds a PTP message.
Definition: avbts_message.hpp:839
#define MAX_TIMESTAMP_STRLEN
Definition: ieee1588.hpp:217
Announce receipt timeout. Same as SYNC_RECEIPT_TIMEOUT_EXPIRES.
Definition: ieee1588.hpp:83
ClockIdentity()
Definition: ieee1588.hpp:118
Same as POWERUP.
Definition: ieee1588.hpp:77
Definition: avbts_port.hpp:76
#define XPTPD_INFO(fmt,...)
Definition: debugout.hpp:45
#define INVALID_TIMESTAMP_VERSION
Definition: ieee1588.hpp:215
bool operator>(const ClockIdentity &cmp) const
Implements the operator '>' overloading method.
Definition: ieee1588.hpp:164
ClockIdentity(uint8_t *id)
Constructs the object and sets its ID.
Definition: ieee1588.hpp:126
Definition: avbts_clock.hpp:77
Definition: ieee1588.hpp:93
Definition: ieee1588.hpp:111
Event
Definition: ieee1588.hpp:74
A fault was detected.
Definition: ieee1588.hpp:85
#define PTP_CLOCK_IDENTITY_LENGTH
Definition: ieee1588.hpp:54
uint8_t _version
8 bit version value
Definition: ieee1588.hpp:251
#define LS_SEC_MAX
Definition: ieee1588.hpp:388
Timestamp operator-(const Timestamp &o)
Implements the operator '-' overloading method.
Definition: ieee1588.hpp:305
Definition: avbts_message.hpp:770
Null Event. Used to initialize events.
Definition: ieee1588.hpp:75
#define NS_PER_SECOND
Definition: ieee1588.hpp:387
Definition: avbts_message.hpp:167
bool operator<(const ClockIdentity &cmp) const
Implements the operator '<' overloading method.
Definition: ieee1588.hpp:154
Definition: avbts_clock.hpp:58
Sync interval expired. Its time to send a sync message.
Definition: ieee1588.hpp:79
void print(const char *str)
This method is only enabled at compiling time. When enabled, it prints on the stderr output the clock...
Definition: ieee1588.hpp:208
Definition: avbts_osnet.hpp:52
bool operator!=(const ClockIdentity &cmp) const
Implements the operator '!=' overloading method.
Definition: ieee1588.hpp:145
Announce interval timout. Its time to send an announce message if asCapable is true.
Definition: ieee1588.hpp:84
std::string getIdentityString()
Gets the identity string from the ClockIdentity object.
uint16_t seconds_ms
32 bit seconds MSB value
Definition: ieee1588.hpp:250
Definition: avbts_osnet.hpp:277
Definition: avbts_port.hpp:207
bool operator==(const ClockIdentity &cmp) const
Implements the operator '==' overloading method.
Definition: ieee1588.hpp:135
Signalizes that something has changed. Recalculates best master.
Definition: ieee1588.hpp:78
Sync receipt timeout. Restart timers and take actions based on port's state.
Definition: ieee1588.hpp:81
Timestamp operator+(const Timestamp &o)
Implements the operator '+' overloading method.
Definition: ieee1588.hpp:271
Event event
Event enumeration.
Definition: ieee1588.hpp:95
#define MAX_NANOSECONDS
Definition: ieee1588.hpp:216
char * toString()
Copies the timestamp to the internal string in the following format: seconds_ms seconds_ls nanosecond...
Definition: ieee1588.hpp:258
Qualification timeout. Event not currently used.
Definition: ieee1588.hpp:82
Defers pdelay processing.
Definition: ieee1588.hpp:86
Definition: avbts_message.hpp:721
uint32_t seconds_ls
32 bit seconds LSB value
Definition: ieee1588.hpp:249
IEEE1588Port * port
IEEE 1588 Port.
Definition: ieee1588.hpp:94
Definition: ieee1588.hpp:222
void set(uint8_t *id)
Set the clock id to the object.
Definition: ieee1588.hpp:189
uint32_t nanoseconds
32 bit nanoseconds value
Definition: ieee1588.hpp:248