|
SatCat5
|
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>
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::OnDemand * | m_callback |
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::Interrupt * | m_next |
|
inline |
Auto-configuration constructor.
This constructor reads frequency parameters at runtime.
Definition at line 29 of file cfgbus_timer.h.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
overrideprotectedvirtual |
Interrupt service routine.
(Child class must override this method.)
Implements satcat5::cfg::Interrupt.
Definition at line 36 of file cfgbus_timer.cc.
| 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.
|
overridevirtual |
Read the current time.
This method is required for the TimeRef API.
Implements satcat5::util::TimeRef.
Definition at line 12 of file cfgbus_timer.cc.
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
| 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.
| 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.
| 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.
| 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.