SatCat5
satcat5::ptp::SimulatedClock Class Reference

Detailed Description

Simulated clock mimics operation of "ptp_realtime.vhd".

Definition at line 18 of file ptp_simclock.h.

#include <ptp_simclock.h>

Inheritance diagram for satcat5::ptp::SimulatedClock:
[legend]
Collaboration diagram for satcat5::ptp::SimulatedClock:
[legend]

Public Member Functions

 SimulatedClock (double nominal_hz, double actual_hz)
 Constructor allows user to set nominal vs actual frequency. More...
 
bool ok () const
 Confirm initial configuration is valid.
 
unsigned num_coarse () const
 Report the number of coarse adjustments. More...
 
unsigned num_fine () const
 Report the number of fine adjustments. More...
 
double mean () const
 Mean of all inputs to clock_rate(...)
 
satcat5::ptp::Time clock_adjust (const satcat5::ptp::Time &amount) override
 Make a one-time adjustment of the specified magnitude. More...
 
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. More...
 
double clock_offset_ppm () const
 
void clock_set (const satcat5::ptp::Time &t)
 
void run (const satcat5::ptp::Time &dt)
 Run simulation for X seconds.
 
s64 get_rate () const
 Read the current clock-tuning parameter. More...
 

Static Public Attributes

static constexpr unsigned TICK_SCALE_NSEC = 40
 Convert from internal ticks to engineering units. More...
 
static constexpr u64 TICKS_PER_SUBNS
 Convert from internal ticks to engineering units. More...
 
static constexpr double TICKS_PER_SEC
 Convert from internal ticks to engineering units. More...
 

Protected Attributes

s64 m_offset
 

Private Attributes

const satcat5::ptp::RateConversion m_scale_nominal
 
const double m_rate_actual
 
const s64 m_nco_rate
 
satcat5::util::uint128_t m_nco_accum
 
unsigned m_count_coarse
 
unsigned m_count_fine
 
satcat5::ptp::Time m_rtc
 
satcat5::test::Statistics m_stats
 
satcat5::ptp::TrackingClockm_next
 

Constructor & Destructor Documentation

◆ SimulatedClock()

SimulatedClock::SimulatedClock ( double  nominal_hz,
double  actual_hz 
)

Constructor allows user to set nominal vs actual frequency.

For example, this allows simulations where the reference oscillator is running 10 ppm faster than its nominal rate.

Definition at line 16 of file ptp_simclock.cc.

Member Function Documentation

◆ clock_adjust()

Time SimulatedClock::clock_adjust ( const satcat5::ptp::Time amount)
overridevirtual

Make a one-time adjustment of the specified magnitude.

Positive quantities indicate the clock should move forward. Return value is the estimated remainder or residual error.

Implements satcat5::ptp::TrackingClock.

Definition at line 32 of file ptp_simclock.cc.

◆ clock_rate()

void SimulatedClock::clock_rate ( s64  offset)
overridevirtual

Adjust rate by a normalized frequency offset.

Positive offsets command the clock to run faster. (See discussion above, near definition of RATE_ONE_PPB.)

Implements satcat5::ptp::TrackingClock.

Definition at line 43 of file ptp_simclock.cc.

◆ get_rate()

s64 satcat5::ptp::TrackingClock::get_rate ( ) const
inlineinherited

Read the current clock-tuning parameter.

Returns
The most recent value passed to "clock_rate", above.

Definition at line 70 of file ptp_tracking.h.

◆ num_coarse()

unsigned satcat5::ptp::SimulatedClock::num_coarse ( ) const
inline

Report the number of coarse adjustments.

(Coarse adjustments are discontinuous phase jumps of any size.)

Definition at line 42 of file ptp_simclock.h.

◆ num_fine()

unsigned satcat5::ptp::SimulatedClock::num_fine ( ) const
inline

Report the number of fine adjustments.

(Fine adjustments are confined to rate changes only.)

Definition at line 46 of file ptp_simclock.h.

Member Data Documentation

◆ TICK_SCALE_NSEC

constexpr unsigned satcat5::ptp::SimulatedClock::TICK_SCALE_NSEC = 40
staticconstexpr

Convert from internal ticks to engineering units.

1 Tick = 1 LSB = 2^-40 nanoseconds = 2^-24 subns. (This matches the default for ptp_counter_gen and ptp_realtime.)

Definition at line 24 of file ptp_simclock.h.

◆ TICKS_PER_SEC

constexpr double satcat5::ptp::SimulatedClock::TICKS_PER_SEC
staticconstexpr
Initial value:
=
double(TICKS_PER_SUBNS) * double(satcat5::ptp::SUBNS_PER_SEC)
static constexpr u64 TICKS_PER_SUBNS
Convert from internal ticks to engineering units.
Definition: ptp_simclock.h:25

Convert from internal ticks to engineering units.

1 Tick = 1 LSB = 2^-40 nanoseconds = 2^-24 subns. (This matches the default for ptp_counter_gen and ptp_realtime.)

Definition at line 27 of file ptp_simclock.h.

◆ TICKS_PER_SUBNS

constexpr u64 satcat5::ptp::SimulatedClock::TICKS_PER_SUBNS
staticconstexpr
Initial value:
=
(1ull << TICK_SCALE_NSEC) / u64(satcat5::ptp::SUBNS_PER_NSEC)
static constexpr unsigned TICK_SCALE_NSEC
Convert from internal ticks to engineering units.
Definition: ptp_simclock.h:24

Convert from internal ticks to engineering units.

1 Tick = 1 LSB = 2^-40 nanoseconds = 2^-24 subns. (This matches the default for ptp_counter_gen and ptp_realtime.)

Definition at line 25 of file ptp_simclock.h.


The documentation for this class was generated from the following files: