Class TimerCounter
Defined in File sim_timer.h
Nested Relationships
Nested Types
Class Documentation
-
class TimerCounter
Generic model of a Counter.
Implementation of a clock cycle counter, used by peripherals such as TCx, WDT, RTC. Features :
2 ‘tick’ sources: internal (using a PrescaledTimer object) or external via a signal hook
Up/down counting and dual slope
Arbitrary number of compare channels
Signalling on top, bottom, max and compare value
Public Types
-
enum TickSource
Tick source mode.
Values:
-
enumerator Tick_Stopped
Counter stopped.
-
enumerator Tick_Timer
Internal prescaled timer used as tick source.
-
enumerator Tick_External
External signal hook used as tick source.
-
enumerator Tick_Stopped
-
enum SlopeMode
Counter direction mode.
Values:
-
enumerator Slope_Up
Up-counting.
-
enumerator Slope_Down
Down-counting.
-
enumerator Slope_Double
Dual-slope counting.
-
enumerator Slope_Up
-
enum EventType
Event type flags used when signaling.
See also
Values:
-
enumerator Event_Max
The counter is wrapping.
-
enumerator Event_Top
The counter has reached the TOP value.
-
enumerator Event_Bottom
The counter has reached the BOTTOM value (zero)
-
enumerator Event_Compare
The counter has reached one of the Compare channel values.
-
enumerator Event_Max
Public Functions
-
TimerCounter(long wrap, size_t comp_count)
Constructor
- Parameters:
wrap – Wrapping value for the counter. For example, a 16-bits counter wrap is 0x10000.
comp_count – number of compare channels
-
~TimerCounter()
-
void init(CycleManager &cycle_manager, Logger &logger)
Initialise the counter
-
void reset()
Reset the counter
-
void reschedule()
Reschedule the counter, this should be called after changing the configuration
-
inline void update()
Force update of the internal prescaler.
-
inline long wrap() const
Getter for the wrapping value.
-
void set_tick_source(TickSource src)
Change the tick source
-
inline TickSource tick_source() const
Getter for the tick source mode.
-
void tick()
Progress the counter by one unit. Has no effect if if the source is set to Stopped.
-
void set_top(long top)
Change the TOP value
-
inline long top() const
Getter for the TOP value.
-
void set_counter(long value)
Change the counter current value
-
inline long counter() const
Getter for the current counter value.
-
void set_comp_value(size_t index, long value)
Change a compare channel value
-
inline long comp_value(size_t index) const
Getter for a compare value.
-
void set_comp_enabled(size_t index, bool enable)
Enable or disable a compare channel
-
inline bool comp_enabled(size_t index) const
Getter for a compare value enable.
-
inline bool countdown() const
Getter for the current counting direction.
-
void set_countdown(bool down)
Set the counting up or down. Changes the slope mode accordingly except if the slope mode is Dual.
-
inline SignalHook &ext_tick_hook()
Getter for the external signal hook used for tick source.
-
inline PrescaledTimer &prescaler()
Getter for the internal prescaler.
-
class ExtTickHook : public SignalHook
Public Functions
-
inline ExtTickHook(TimerCounter &timer)
-
inline virtual void raised(const signal_data_t&, int) override
Pure virtual callback called during signal raises.
- Parameters:
sigdata – Data structure passed on when raising a signal
hooktag – integer passed on when connecting a hook to a signal. For hooks connected to several signals, it provides a mean to identify the caller.
-
inline ExtTickHook(TimerCounter &timer)
-
class TimerHook : public SignalHook
Public Functions
-
inline TimerHook(TimerCounter &timer)
-
inline virtual void raised(const signal_data_t &sigdata, int) override
Pure virtual callback called during signal raises.
- Parameters:
sigdata – Data structure passed on when raising a signal
hooktag – integer passed on when connecting a hook to a signal. For hooks connected to several signals, it provides a mean to identify the caller.
-
inline TimerHook(TimerCounter &timer)