TimerCounter Class Reference

yasimavr: TimerCounter Class Reference
yasimavr
Loading...
Searching...
No Matches

Generic model of a Counter. More...

#include <sim_timer.h>

Public Types

enum  TickSource { Tick_Stopped = 0 , Tick_Timer , Tick_External }
 Tick source mode. More...
 
enum  SlopeMode { Slope_Up = 0 , Slope_Down , Slope_Double }
 Counter direction mode. More...
 
enum  EventType { Event_Max = 0x01 , Event_Top = 0x02 , Event_Bottom = 0x04 , Event_Compare = 0x08 }
 Event type flags used when signaling. More...
 
enum  SignalId { Signal_Event , Signal_CompMatch }
 Signal Ids raised by this object. More...
 

Public Member Functions

 TimerCounter (long wrap, size_t comp_count)
 
void init (CycleManager &cycle_manager, Logger &logger)
 
void reset ()
 
void reschedule ()
 
void update ()
 Force update of the internal prescaler.
 
long wrap () const
 Getter for the wrapping value.
 
void set_tick_source (TickSource src)
 
TickSource tick_source () const
 Getter for the tick source mode.
 
void tick ()
 
void set_top (long top)
 
long top () const
 Getter for the TOP value.
 
void set_slope_mode (SlopeMode mode)
 
SlopeMode slope_mode () const
 Getter for the slope mode.
 
void set_counter (long value)
 
long counter () const
 Getter for the current counter value.
 
void set_comp_value (size_t index, long value)
 
long comp_value (size_t index) const
 Getter for a compare value.
 
void set_comp_enabled (size_t index, bool enable)
 
bool comp_enabled (size_t index) const
 Getter for a compare value enable.
 
bool countdown () const
 Getter for the current counting direction.
 
void set_countdown (bool down)
 
Signalsignal ()
 Getter for the counting signal.
 
SignalHookext_tick_hook ()
 Getter for the external signal hook used for tick source.
 
PrescaledTimerprescaler ()
 Getter for the internal prescaler.
 

Detailed Description

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

Member Enumeration Documentation

◆ EventType

Event type flags used when signaling.

See also
Signal_Event
Enumerator
Event_Max 

The counter is wrapping.

Event_Top 

The counter has reached the TOP value.

Event_Bottom 

The counter has reached the BOTTOM value (zero)

Event_Compare 

The counter has reached one of the Compare channel values.

◆ SignalId

Signal Ids raised by this object.

Enumerator
Signal_Event 

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

Signal_CompMatch 

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

◆ SlopeMode

Counter direction mode.

Enumerator
Slope_Up 

Up-counting.

Slope_Down 

Down-counting.

Slope_Double 

Dual-slope counting.

◆ TickSource

Tick source mode.

Enumerator
Tick_Stopped 

Counter stopped.

Tick_Timer 

Internal prescaled timer used as tick source.

Tick_External 

External signal hook used as tick source.

Constructor & Destructor Documentation

◆ TimerCounter()

TimerCounter::TimerCounter ( long  wrap,
size_t  comp_count 
)

Constructor

Parameters
wrapWrapping value for the counter. For example, a 16-bits counter wrap is 0x10000.
comp_countnumber of compare channels

Member Function Documentation

◆ comp_enabled()

bool TimerCounter::comp_enabled ( size_t  index) const
inline

Getter for a compare value enable.

◆ comp_value()

long TimerCounter::comp_value ( size_t  index) const
inline

Getter for a compare value.

◆ countdown()

bool TimerCounter::countdown ( ) const
inline

Getter for the current counting direction.

◆ counter()

long TimerCounter::counter ( ) const
inline

Getter for the current counter value.

◆ ext_tick_hook()

SignalHook & TimerCounter::ext_tick_hook ( )
inline

Getter for the external signal hook used for tick source.

◆ init()

void TimerCounter::init ( CycleManager cycle_manager,
Logger logger 
)

Initialise the counter

◆ prescaler()

PrescaledTimer & TimerCounter::prescaler ( )
inline

Getter for the internal prescaler.

◆ reschedule()

void TimerCounter::reschedule ( )

Reschedule the counter, this should be called after changing the configuration

◆ reset()

void TimerCounter::reset ( )

Reset the counter

◆ set_comp_enabled()

void TimerCounter::set_comp_enabled ( size_t  index,
bool  enable 
)

Enable or disable a compare channel

◆ set_comp_value()

void TimerCounter::set_comp_value ( size_t  index,
long  value 
)

Change a compare channel value

◆ set_countdown()

void TimerCounter::set_countdown ( bool  down)

Set the counting up or down. Changes the slope mode accordingly except if the slope mode is Dual.

◆ set_counter()

void TimerCounter::set_counter ( long  value)

Change the counter current value

◆ set_slope_mode()

void TimerCounter::set_slope_mode ( SlopeMode  mode)

Change the slope mode

◆ set_tick_source()

void TimerCounter::set_tick_source ( TickSource  src)

Change the tick source

◆ set_top()

void TimerCounter::set_top ( long  top)

Change the TOP value

◆ signal()

Signal & TimerCounter::signal ( )
inline

Getter for the counting signal.

◆ slope_mode()

TimerCounter::SlopeMode TimerCounter::slope_mode ( ) const
inline

Getter for the slope mode.

◆ tick()

void TimerCounter::tick ( )

Progress the counter by one unit. Has no effect if if the source is set to Stopped.

◆ tick_source()

TimerCounter::TickSource TimerCounter::tick_source ( ) const
inline

Getter for the tick source mode.

◆ top()

long TimerCounter::top ( ) const
inline

Getter for the TOP value.

◆ update()

void TimerCounter::update ( )
inline

Force update of the internal prescaler.

◆ wrap()

long TimerCounter::wrap ( ) const
inline

Getter for the wrapping value.


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