SatCat5
satcat5::cfg::Timer Class Reference

Detailed Description

ConfigBus Timer driver.

Device driver for the timer system defined in "cfgbus_timer.vhd". The primary purpose of this device is to act as a cycle-counting TimeRef (typically operating at 10 to 100 MHz), and an interrupt source at a programmable interval (typically at 1 kHz). In some designs, it may also act as a watchdog timer that resets the system if it has not been updated after some interval.

Definition at line 22 of file cfgbus_timer.h.

#include <cfgbus_timer.h>

Inheritance diagram for satcat5::cfg::Timer:
[legend]
Collaboration diagram for satcat5::cfg::Timer:
[legend]

Public Member Functions

 Timer (satcat5::cfg::ConfigBus *cfg, unsigned devaddr)
 Auto-configuration constructor. More...
 
 Timer (satcat5::cfg::ConfigBus *cfg, unsigned devaddr, u32 refclk_hz)
 Manual-configuration constructor. More...
 
u32 raw () override
 Read the current time. More...
 
satcat5::util::TimeVal last_event ()
 Read timestamp of the last external event signal. More...
 
void timer_interval (unsigned usec)
 Change the timer-interrupt interval. More...
 
void timer_callback (satcat5::poll::OnDemand *callback)
 Set the callback for timer-interrupt notifications. More...
 
void wdog_disable ()
 Disable the hardware watchdog function. More...
 
void wdog_update (u32 usec)
 Resume or reset the watchdog countdown. More...
 
TimeVal now ()
 Create a TimeVal object using the tick-count from raw().
 
TimeVal checkpoint_usec (unsigned usec)
 Create an oven-timer, set N microseconds from now. More...
 
TimeVal checkpoint_msec (unsigned msec)
 Create an oven-timer, set N milliseconds from now. More...
 
void busywait_usec (unsigned usec)
 If timer resolution allows, busywait for X microseconds. More...
 
u32 ticks_per_sec () const
 Stable accessors for unit conversion. More...
 
u32 ticks_per_msec () const
 Stable accessors for unit conversion. More...
 
u32 ticks_per_usec () const
 Stable accessors for unit conversion. More...
 

Protected Member Functions

void irq_event () override
 Interrupt service routine. More...
 
void irq_check ()
 Check if this interrupt may need service. More...
 
void irq_enable ()
 Enable this interrupt. More...
 
void irq_disable ()
 Temporarily disable this interrupt. More...
 

Static Protected Member Functions

static u32 hw_ticks_per_sec (satcat5::cfg::ConfigBus *cfg, unsigned devaddr)
 

Protected Attributes

satcat5::cfg::Register m_ctrl
 
satcat5::poll::OnDemandm_callback
 

Static Protected Attributes

static constexpr u32 WDOG_PAUSE = (u32)(-1)
 
static constexpr unsigned REGADDR_WDOG = 0
 
static constexpr unsigned REGADDR_CPU_HZ = 1
 
static constexpr unsigned REGADDR_PERF_CTR = 2
 
static constexpr unsigned REGADDR_LAST_EVT = 3
 
static constexpr unsigned REGADDR_TIMER_LEN = 4
 
static constexpr unsigned REGADDR_TIMER_IRQ = 5
 

Private Attributes

u64 const m_msec_per_tick
 
u64 const m_usec_per_tick
 
u64 const m_tick_per_msec
 
u64 const m_tick_per_usec
 
satcat5::cfg::ConfigBus *const m_cfg
 
satcat5::cfg::Interruptm_next
 

Constructor & Destructor Documentation

◆ Timer() [1/2]

satcat5::cfg::Timer::Timer ( satcat5::cfg::ConfigBus cfg,
unsigned  devaddr 
)
inline

Auto-configuration constructor.

This constructor reads frequency parameters at runtime.

Definition at line 29 of file cfgbus_timer.h.

◆ Timer() [2/2]

satcat5::cfg::Timer::Timer ( satcat5::cfg::ConfigBus cfg,
unsigned  devaddr,
u32  refclk_hz 
)
inline

Manual-configuration constructor.

If the timer's clock frequency is known at build time, this alternate constructor can avoid runtime division calls.

Definition at line 35 of file cfgbus_timer.h.

Member Function Documentation

◆ busywait_usec()

void TimeRef::busywait_usec ( unsigned  usec)
inherited

If timer resolution allows, busywait for X microseconds.

(May return immediately if backing reference is too coarse.)

Definition at line 93 of file timeref.cc.

◆ checkpoint_msec()

TimeVal TimeRef::checkpoint_msec ( unsigned  msec)
inherited

Create an oven-timer, set N milliseconds from now.

An over-timer TimeVal is a timestamp a short time in the future. To use it, create the TimeVal and then poll checkpoint_elapsed(). (The returned TimeVal is intended to be used exactly once.)

Definition at line 73 of file timeref.cc.

◆ checkpoint_usec()

TimeVal TimeRef::checkpoint_usec ( unsigned  usec)
inherited

Create an oven-timer, set N microseconds from now.

An over-timer TimeVal is a timestamp a short time in the future. To use it, create the TimeVal and then poll checkpoint_elapsed(). (The returned TimeVal is intended to be used exactly once.)

Definition at line 69 of file timeref.cc.

◆ irq_check()

void Interrupt::irq_check ( )
inherited

Check if this interrupt may need service.

If the interrupt needs service, this calls irq_event.

Definition at line 46 of file cfgbus_interrupt.cc.

◆ irq_disable()

void Interrupt::irq_disable ( )
inherited

Temporarily disable this interrupt.

Interrupts are enabled by default, but some peripherals may wish to temporary toggle this setting. For use with standard "cfgbus_interrupt" only.

Definition at line 63 of file cfgbus_interrupt.cc.

◆ irq_enable()

void Interrupt::irq_enable ( )
inherited

Enable this interrupt.

Interrupts are enabled by default, but some peripherals may wish to temporary toggle this setting. For use with standard "cfgbus_interrupt" only.

Definition at line 58 of file cfgbus_interrupt.cc.

◆ irq_event()

void Timer::irq_event ( )
overrideprotectedvirtual

Interrupt service routine.

(Child class must override this method.)

Implements satcat5::cfg::Interrupt.

Definition at line 36 of file cfgbus_timer.cc.

◆ last_event()

TimeVal Timer::last_event ( )

Read timestamp of the last external event signal.

If enabled at build time, the Timer can note the timestamp of the most recent rising edge of a discrete "event" signal. For a more precise equivalent, see satcat5::ptp::PpsInput.

Definition at line 16 of file cfgbus_timer.cc.

◆ raw()

u32 Timer::raw ( )
overridevirtual

Read the current time.

This method is required for the TimeRef API.

Returns
Clock-cycle counter, modulo 2^32.

Implements satcat5::util::TimeRef.

Definition at line 12 of file cfgbus_timer.cc.

◆ ticks_per_msec()

u32 satcat5::util::TimeRef::ticks_per_msec ( ) const
inlineinherited

Stable accessors for unit conversion.

If the tick rate is low, these may return zero.

Definition at line 179 of file timeref.h.

◆ ticks_per_sec()

u32 satcat5::util::TimeRef::ticks_per_sec ( ) const
inlineinherited

Stable accessors for unit conversion.

If the tick rate is low, these may return zero.

Definition at line 177 of file timeref.h.

◆ ticks_per_usec()

u32 satcat5::util::TimeRef::ticks_per_usec ( ) const
inlineinherited

Stable accessors for unit conversion.

If the tick rate is low, these may return zero.

Definition at line 181 of file timeref.h.

◆ timer_callback()

void Timer::timer_callback ( satcat5::poll::OnDemand callback)

Set the callback for timer-interrupt notifications.

In most designs, this should be linked to satcat5::poll::timekeeper.

Definition at line 24 of file cfgbus_timer.cc.

◆ timer_interval()

void Timer::timer_interval ( unsigned  usec)

Change the timer-interrupt interval.

On startup/reset, the default interval is 1 millisecond. This method sets a new interval, measured in microseconds.

Definition at line 20 of file cfgbus_timer.cc.

◆ wdog_disable()

void Timer::wdog_disable ( )

Disable the hardware watchdog function.

A disabled watchdog returns to its default idle state, which stops the countdown and never requests a hardware reset. To start or resume the countdown, call wdog_update.

Definition at line 28 of file cfgbus_timer.cc.

◆ wdog_update()

void Timer::wdog_update ( u32  usec)

Resume or reset the watchdog countdown.

Enables the watchdog function and set the countdown timer to the designated interval, in microseconds. Within that interval, the user should call wdog_update again to prevent a reset request, or call wdog_disable to stop the countdown.

Definition at line 32 of file cfgbus_timer.cc.


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