32 m_period = satcat5::ptp::SUBNS_PER_SEC;
33 if (mode == Edge::BOTH) m_period /= 2;
36 bool PpsInput::read_pulse() {
38 constexpr u32 REG_LAST = (1u << 31);
39 constexpr u32 REG_VALID = (1u << 30);
41 constexpr u32 REG_DATA = (1u << 24) - 1;
46 if (reg0 & REG_VALID) {
53 ok = (reg1 & REG_VALID) && (reg2 & REG_VALID) && (reg3 & REG_LAST);
57 u64 secs = u64(reg0 & REG_DATA) << 24 | u64(reg1 & REG_DATA);
58 u64 subns = u64(reg2 & REG_DATA) << 24 | u64(reg3 & REG_DATA);
67 s64 phase = s64(subns) - m_offset;
73 while (phase > m_period/2) phase -= m_period;
79 if (m_callback) m_callback->pps_event(m_pps_time, delta);
88 while (read_pulse()) {}
114 static inline u32 wide_write(
Register& reg, u64 val) {
115 *reg = u32(val >> 32);
116 *reg = u32(val >> 0);
120 void PpsOutput::configure() {
121 constexpr u64 REG_RISING = (1ull << 63);
122 constexpr u64 REG_OFFSET = (1ull << 48) - 1;
125 u64 cfg = u64(m_offset) & REG_OFFSET;
126 if (m_rising) cfg |= REG_RISING;
130 (void)wide_write(m_reg, cfg);
135 , m_reg_period(reg_period)
143 u64 subns = satcat5::util::div_round<u64>(
144 u64(satcat5::ptp::SUBNS_PER_SEC), u64(freq_hz));
145 (void)wide_write(m_reg_period, subns);
Pulse-per-second (PPS) input and output.
Driver for the PPS output block (ptp_pps_out.vhd).
void set_polarity(bool rising)
Set the rising- or falling-edge polarity of this output.
PpsOutput(satcat5::cfg::Register reg, bool rising=true)
Link this driver to the hardware control register.
void set_offset(s64 offset)
Adjust the phase-offset for this output.
void timer_event() override
Child class MUST override this method.
Variant of PpsOutput with frequency-control enabled.
RefOutput(satcat5::cfg::Register reg_phase, satcat5::cfg::Register reg_period, bool rising=true)
Link this driver to the hardware control register.
void set_frequency(u32 freq_hz)
Adjust the frequency for this output.
Pointer-like wrapper for one or more ConfigBus registers.
void timer_once(unsigned msec)
Configure a one-time notification after X milliseconds.
void timer_every(unsigned msec)
Configure a repeating notification every X milliseconds.
High-precision timestamp for use with PTP / IEEE1588.
Closed-loop time-tracking clocks and tracking control.