Class TimerCounter

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.

enum SlopeMode

Counter direction mode.

Values:

enumerator Slope_Up

Up-counting.

enumerator Slope_Down

Down-counting.

enumerator Slope_Double

Dual-slope counting.

enum EventType

Event type flags used when signaling.

See also

Signal_Event

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.

enum SignalId

Signal Ids raised by this object.

Values:

enumerator Signal_Event

Signal raised on a overflow event, the data is a combination of EventType flags, indicating the type(s) of event.

enumerator Signal_CompMatch

Signal raised on a Compare Match event. The index indicates which channel. No data is carried.

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_slope_mode(SlopeMode mode)

Change the slope mode

inline SlopeMode slope_mode() const

Getter for the slope mode.

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 Signal &signal()

Getter for the counting signal.

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.

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.