17 static constexpr
unsigned RTC_SEC_MSB = 0;
18 static constexpr
unsigned RTC_SEC_LSB = 1;
19 static constexpr
unsigned RTC_NSEC = 2;
20 static constexpr
unsigned RTC_SUBNS = 3;
21 static constexpr
unsigned RTC_COMMAND = 4;
22 static constexpr
unsigned RTC_RATE = 5;
23 static constexpr u32 OPCODE_READ = 0x01000000u;
24 static constexpr u32 OPCODE_WRITE = 0x02000000u;
25 static constexpr u32 OPCODE_INCR = 0x04000000u;
28 static inline u32 wide_write(Register& reg, s64 offset) {
29 u64 tmp = (u64)offset;
30 *reg = u32(tmp >> 32);
35 Time PtpReference::clock_adjust(
const Time& amount) {
43 (void)wide_write(m_reg, m_rate.
convert(offset));
48 return satcat5::ptp::TIME_ZERO;
53 (void)wide_write(m_reg, rate);
54 m_offset = m_rate.
invert(rate);
60 m_reg[RTC_COMMAND] = OPCODE_INCR;
67 (void)wide_write(tmp, m_rate.
convert(offset));
74 (void)wide_write(tmp, rate);
75 m_offset = m_rate.
invert(rate);
79 u64 sec_msb = m_reg[RTC_SEC_MSB];
80 u64 sec_lsb = m_reg[RTC_SEC_LSB];
81 u32 nsec = m_reg[RTC_NSEC];
82 u32 subns = m_reg[RTC_SUBNS];
83 u64 sec = (sec_msb << 32) + sec_lsb;
84 return Time(sec, nsec, (u16)subns);
88 m_reg[RTC_COMMAND] = OPCODE_READ;
94 m_reg[RTC_COMMAND] = OPCODE_WRITE;
97 void PtpRealtime::load(
const Time& time) {
100 m_reg[RTC_SEC_MSB] = (u32)(sec >> 32);
101 m_reg[RTC_SEC_LSB] = (u32)(sec >> 0);
102 m_reg[RTC_NSEC] = (u32)(sub / SUBNS_PER_NSEC);
103 m_reg[RTC_SUBNS] = (u32)(sub % SUBNS_PER_NSEC);
ConfigBus-controlled PTP reference counter (ptp_counter_gen.vhd).
PTP reference with rate-control and coarse-adjust command.
void clock_set(const satcat5::ptp::Time &new_time)
Coarse adjustment of the current time.
satcat5::ptp::Time clock_adjust(const satcat5::ptp::Time &amount) override
Make a one-time adjustment of the specified magnitude.
void clock_rate_raw(s64 rate)
Legacy API for rate-control without additional scaling.
satcat5::ptp::Time clock_ext()
Read timestamp of external rising-edge signal.
satcat5::ptp::Time clock_now() override
Return the current time if available, TIME_ZERO otherwise.
void clock_rate(s64 offset) override
Adjust rate by a normalized frequency offset.
PTP reference counter with rate-control only.
satcat5::ptp::Time clock_now() override
Return the current time if available, TIME_ZERO otherwise.
void clock_rate_raw(s64 rate)
Legacy API for rate-control without additional scaling.
void clock_rate(s64 offset) override
Adjust rate by a normalized frequency offset.
Pointer-like wrapper for one or more ConfigBus registers.
s64 invert(s64 rate) const
Inverse conversion (ticks-per-clock ==> normalized rate)
s64 convert(s64 offset) const
Forward conversion (normalized rate ==> ticks-per-clock)
High-precision timestamp for use with PTP / IEEE1588.
s64 field_secs() const
Read the "seconds" field without intermediate rounding.
u64 field_subns() const
Read the raw "subnanoseconds" field.
High-precision "Time" object for use with PTP / IEEE1588.
constexpr s64 SUBNS_PER_NSEC
Define commonly used scaling factors.