simulavr  1.1.0
BasicTimerUnit Class Reference

Basic timer unit. More...

#include <hwtimer.h>

Inheritance diagram for BasicTimerUnit:

Public Types

enum  CEtype {
  EVT_TOP_REACHED = 0, EVT_MAX_REACHED, EVT_BOTTOM_REACHED, EVT_COMPARE_1,
  EVT_COMPARE_2, EVT_COMPARE_3
}
 event types for timer/counter More...
 

Public Member Functions

 BasicTimerUnit (AvrDevice *core, PrescalerMultiplexer *p, int unit, IRQLine *tov, IRQLine *tcap, ICaptureSource *icapsrc, int countersize=8)
 Create a basic Timer/Counter unit. More...
 
 ~BasicTimerUnit ()
 
void Reset ()
 Perform a reset of this unit. More...
 
virtual unsigned int CpuCycle ()
 Process timer/counter unit operations by CPU cycle. More...
 
void RegisterACompForICapture (HWAcomp *acomp)
 register analog comparator unit for input capture source More...
 
void SetACIC (bool acic)
 reflect ACIC flag to input capture source More...
 
void SetTimerEventListener (TimerEventListener *listener)
 Set event listener. More...
 
- Public Member Functions inherited from Hardware
 Hardware (AvrDevice *core)
 
virtual ~Hardware ()
 
virtual void ClearIrqFlag (unsigned int vector)
 
virtual bool IsLevelInterrupt (unsigned int vector)
 
virtual bool LevelInterruptPending (unsigned int vector)
 
- Public Member Functions inherited from TraceValueRegister
 TraceValueRegister (TraceValueRegister *parent, const std::string &name)
 Create a TraceValueRegister, with a scope prefix built on parent scope + name. More...
 
 TraceValueRegister ()
 Create a TraceValueRegister, with a empty scope name, single device application. More...
 
virtual ~TraceValueRegister ()
 
const std::string GetTraceValuePrefix (void)
 Returns the scope prefix. More...
 
const std::string GetScopeName (void)
 Returns the scope name. More...
 
void RegisterTraceValue (TraceValue *t)
 Registers a TraceValue for this register. More...
 
void UnregisterTraceValue (TraceValue *t)
 Unregisters a TraceValue, remove it from register. More...
 
TraceValueRegisterGetScopeGroupByName (const std::string &name)
 Get a here registered TraceValueRegister by it's name. More...
 
virtual TraceValueGetTraceValueByName (const std::string &name)
 Get a here registered TraceValue by it's name. More...
 
TraceValueRegisterFindScopeGroupByName (const std::string &name)
 Seek for a TraceValueRegister by it's name. More...
 
TraceValueFindTraceValueByName (const std::string &name)
 Seek for a TraceValue by it's name. More...
 
TraceSetGetAllTraceValues (void)
 Get all here registered TraceValue's only (not with descending values) More...
 
TraceSetGetAllTraceValuesRecursive (void)
 Get all here registered TraceValue's with descending values. More...
 

Protected Types

enum  WGMtype {
  WGM_NORMAL = 0, WGM_PCPWM_8BIT, WGM_PCPWM_9BIT, WGM_PCPWM_10BIT,
  WGM_CTC_OCRA, WGM_FASTPWM_8BIT, WGM_FASTPWM_9BIT, WGM_FASTPWM_10BIT,
  WGM_PFCPWM_ICR, WGM_PFCPWM_OCRA, WGM_PCPWM_ICR, WGM_PCPWM_OCRA,
  WGM_CTC_ICR, WGM_RESERVED, WGM_FASTPWM_ICR, WGM_FASTPWM_OCRA,
  WGM_tablesize
}
 types of waveform generation modes More...
 
enum  COMtype { COM_NOOP = 0, COM_TOGGLE, COM_CLEAR, COM_SET }
 types of compare match output modes More...
 
enum  OCRIDXtype { OCRIDX_A = 0, OCRIDX_B, OCRIDX_C, OCRIDX_maxUnits }
 indices for OC units More...
 
typedef void(BasicTimerUnit::* wgmfunc_t) (CEtype)
 

Protected Member Functions

void CountTimer (void)
 Supports the count operation, emits count events to HandleEvent method. More...
 
virtual void InputCapture (void)
 Supports the input capture function. More...
 
void HandleEvent (CEtype event)
 Receives count events. More...
 
void SetClockMode (int _cs)
 Set clock mode. More...
 
void SetCounter (unsigned long val)
 Set the counter itself. More...
 
void SetCompareOutputMode (int idx, COMtype mode)
 Set compare output mode. More...
 
void SetCompareOutput (int idx)
 Set compare output pins in non pwm mode. More...
 
void SetPWMCompareOutput (int idx, bool topOrDown)
 Set compare output pins in pwm mode. More...
 
bool WGMisPWM (void)
 returns true, if WGM is in one of the PWM modes More...
 
bool WGMuseICR (void)
 returns true, if WGM uses IC register for defining TOP counter value More...
 
void WGMFunc_noop (CEtype event)
 WGM noop function. More...
 
void WGMfunc_normal (CEtype event)
 WGM function for normal mode (unique for all different timers) More...
 
void WGMfunc_ctc (CEtype event)
 WGM function for ctc mode (unique for all different timers) More...
 
void WGMfunc_fastpwm (CEtype event)
 WGM function for fast pwm mode (unique for all different timers) More...
 
void WGMfunc_pcpwm (CEtype event)
 WGM function for phase correct pwm mode (unique for all different timers) More...
 
void WGMfunc_pfcpwm (CEtype event)
 WGM function for phase and frequency correct pwm mode (unique for all different timers) More...
 
- Protected Member Functions inherited from TraceValueRegister
virtual size_t _tvr_getValuesCount (void)
 Get the count of all TraceValues, that are registered here and descending. More...
 
virtual void _tvr_insertTraceValuesToSet (TraceSet &t)
 Insert all TraceValues into TraceSet, that registered here and descending. More...
 

Protected Attributes

AvrDevicecore
 pointer to device core More...
 
PrescalerMultiplexerpremx
 prescaler multiplexer More...
 
IRQLinetimerOverflow
 irq line for overflow interrupt More...
 
IRQLinetimerCapture
 irq line for capture interrupt More...
 
unsigned long vtcnt
 THE timercounter. More...
 
unsigned long vlast_tcnt
 timercounter BEFORE count operation More...
 
int updown_counting
 count direction control flag, true, if up/down counting More...
 
bool count_down
 counter counts down, used for precise pwm modes More...
 
unsigned long limit_bottom
 BOTTOM value for up/down counting. More...
 
unsigned long limit_top
 TOP value for counting. More...
 
unsigned long limit_max
 MAX value for counting. More...
 
unsigned long icapRegister
 Input capture register. More...
 
ICaptureSourceicapSource
 Input capture source. More...
 
bool icapRisingEdge
 Input capture on rising edge. More...
 
bool icapNoiseCanceler
 Noise canceler for input capturing enabled. More...
 
WGMtype wgm
 waveform generation mode More...
 
wgmfunc_t wgmfunc [WGM_tablesize]
 waveform generator mode function table More...
 
unsigned long compare [OCRIDX_maxUnits]
 compare values for output compare events More...
 
unsigned long compare_dbl [OCRIDX_maxUnits]
 double buffer values for compare values More...
 
bool compareEnable [OCRIDX_maxUnits]
 enables compare operation More...
 
COMtype com [OCRIDX_maxUnits]
 compare match output mode More...
 
IRQLinetimerCompare [OCRIDX_maxUnits]
 irq line for compare interrupt More...
 
PinAtPort compare_output [OCRIDX_maxUnits]
 output pins for compare units More...
 
bool compare_output_state [OCRIDX_maxUnits]
 status compare output pin More...
 

Private Attributes

int cs
 select value for prescaler multiplexer More...
 
TraceValuecounterTrace
 TraceValue instance for counter itself. More...
 
bool captureInputState
 saved state for input capture More...
 
int icapNCcounter
 counter for input capture noise canceler More...
 
bool icapNCstate
 state for input capture noise canceler More...
 
TimerEventListenereventListener
 event listener for timer events More...
 

Detailed Description

Basic timer unit.

Provides basic timer/counter functionality. Counting clock will be taken from a prescaler unit. It provides further at max 3 compare values and one input capture unit.

Definition at line 48 of file hwtimer.h.

Member Typedef Documentation

◆ wgmfunc_t

typedef void(BasicTimerUnit::* BasicTimerUnit::wgmfunc_t) (CEtype)
protected

Definition at line 128 of file hwtimer.h.

Member Enumeration Documentation

◆ CEtype

event types for timer/counter

Enumerator
EVT_TOP_REACHED 

TOP reached for one count cycle.

EVT_MAX_REACHED 

an counter overflow occured

EVT_BOTTOM_REACHED 

BOTTOM reached for one count cycle.

EVT_COMPARE_1 

compare[0] value reached for one count cycle

EVT_COMPARE_2 

compare[1] value reached for one count cycle

EVT_COMPARE_3 

compare[2] value reached for one count cycle

Definition at line 60 of file hwtimer.h.

◆ COMtype

enum BasicTimerUnit::COMtype
protected

types of compare match output modes

Enumerator
COM_NOOP 
COM_TOGGLE 
COM_CLEAR 
COM_SET 

Definition at line 115 of file hwtimer.h.

◆ OCRIDXtype

indices for OC units

Enumerator
OCRIDX_A 

index for OCR unit A

OCRIDX_B 

index for OCR unit B

OCRIDX_C 

index for OCR unit C

OCRIDX_maxUnits 

amount of possible OC units

Definition at line 122 of file hwtimer.h.

◆ WGMtype

enum BasicTimerUnit::WGMtype
protected

types of waveform generation modes

Enumerator
WGM_NORMAL 
WGM_PCPWM_8BIT 
WGM_PCPWM_9BIT 
WGM_PCPWM_10BIT 
WGM_CTC_OCRA 
WGM_FASTPWM_8BIT 
WGM_FASTPWM_9BIT 
WGM_FASTPWM_10BIT 
WGM_PFCPWM_ICR 
WGM_PFCPWM_OCRA 
WGM_PCPWM_ICR 
WGM_PCPWM_OCRA 
WGM_CTC_ICR 
WGM_RESERVED 
WGM_FASTPWM_ICR 
WGM_FASTPWM_OCRA 
WGM_tablesize 

Definition at line 95 of file hwtimer.h.

Constructor & Destructor Documentation

◆ BasicTimerUnit()

BasicTimerUnit::BasicTimerUnit ( AvrDevice core,
PrescalerMultiplexer p,
int  unit,
IRQLine tov,
IRQLine tcap,
ICaptureSource icapsrc,
int  countersize = 8 
)

◆ ~BasicTimerUnit()

BasicTimerUnit::~BasicTimerUnit ( )
inline

Definition at line 77 of file hwtimer.h.

Member Function Documentation

◆ CountTimer()

void BasicTimerUnit::CountTimer ( void  )
protected

Supports the count operation, emits count events to HandleEvent method.

Definition at line 90 of file hwtimer.cpp.

References TraceValue::change(), compare, compareEnable, count_down, counterTrace, EVT_BOTTOM_REACHED, EVT_COMPARE_1, EVT_COMPARE_2, EVT_COMPARE_3, EVT_MAX_REACHED, EVT_TOP_REACHED, HandleEvent(), limit_bottom, limit_max, limit_top, updown_counting, vlast_tcnt, and vtcnt.

Referenced by CpuCycle().

◆ CpuCycle()

unsigned int BasicTimerUnit::CpuCycle ( void  )
virtual

Process timer/counter unit operations by CPU cycle.

Reimplemented from Hardware.

Definition at line 566 of file hwtimer.cpp.

References CountTimer(), cs, InputCapture(), PrescalerMultiplexer::isClock(), and premx.

◆ HandleEvent()

void BasicTimerUnit::HandleEvent ( CEtype  event)
protected

Receives count events.

CountTimer method counts internal counter depending on count mode (updown_counting) and generate events, if special count values are reached for at least one counting cycle. It can happen, that more than one event could occur in the same count cycle!

Definition at line 484 of file hwtimer.cpp.

References eventListener, TimerEventListener::fireEvent(), wgm, and wgmfunc.

Referenced by CountTimer().

◆ InputCapture()

void BasicTimerUnit::InputCapture ( void  )
protectedvirtual

◆ RegisterACompForICapture()

void BasicTimerUnit::RegisterACompForICapture ( HWAcomp acomp)

register analog comparator unit for input capture source

Definition at line 573 of file hwtimer.cpp.

References icapSource, and ICaptureSource::RegisterAComp().

Referenced by HWAcomp::HWAcomp().

◆ Reset()

◆ SetACIC()

void BasicTimerUnit::SetACIC ( bool  acic)
inline

reflect ACIC flag to input capture source

Definition at line 88 of file hwtimer.h.

Referenced by HWAcomp::SetAcsr().

◆ SetClockMode()

◆ SetCompareOutput()

void BasicTimerUnit::SetCompareOutput ( int  idx)
protected

◆ SetCompareOutputMode()

◆ SetCounter()

void BasicTimerUnit::SetCounter ( unsigned long  val)
protected

Set the counter itself.

Definition at line 202 of file hwtimer.cpp.

References TraceValue::change(), counterTrace, vlast_tcnt, and vtcnt.

Referenced by HWTimer16::SetComplexRegister().

◆ SetPWMCompareOutput()

void BasicTimerUnit::SetPWMCompareOutput ( int  idx,
bool  topOrDown 
)
protected

◆ SetTimerEventListener()

void BasicTimerUnit::SetTimerEventListener ( TimerEventListener listener)
inline

Set event listener.

Definition at line 91 of file hwtimer.h.

Referenced by AvrDevice_attinyX5::AvrDevice_attinyX5().

◆ WGMfunc_ctc()

void BasicTimerUnit::WGMfunc_ctc ( CEtype  event)
protected

WGM function for ctc mode (unique for all different timers)

Definition at line 312 of file hwtimer.cpp.

References EVT_COMPARE_1, EVT_COMPARE_2, EVT_COMPARE_3, EVT_MAX_REACHED, EVT_TOP_REACHED, IRQLine::fireInterrupt(), limit_bottom, SetCompareOutput(), timerCompare, timerOverflow, and vtcnt.

Referenced by HWTimer16::HWTimer16(), and HWTimer8::HWTimer8().

◆ WGMfunc_fastpwm()

◆ WGMFunc_noop()

void BasicTimerUnit::WGMFunc_noop ( CEtype  event)
inlineprotected

WGM noop function.

Definition at line 187 of file hwtimer.h.

Referenced by BasicTimerUnit().

◆ WGMfunc_normal()

void BasicTimerUnit::WGMfunc_normal ( CEtype  event)
protected

WGM function for normal mode (unique for all different timers)

Definition at line 280 of file hwtimer.cpp.

References EVT_COMPARE_1, EVT_COMPARE_2, EVT_COMPARE_3, EVT_MAX_REACHED, IRQLine::fireInterrupt(), SetCompareOutput(), timerCompare, and timerOverflow.

Referenced by HWTimer16::HWTimer16(), and HWTimer8::HWTimer8().

◆ WGMfunc_pcpwm()

void BasicTimerUnit::WGMfunc_pcpwm ( CEtype  event)
protected

◆ WGMfunc_pfcpwm()

void BasicTimerUnit::WGMfunc_pfcpwm ( CEtype  event)
protected

WGM function for phase and frequency correct pwm mode (unique for all different timers)

Definition at line 489 of file hwtimer.cpp.

References compare, compare_dbl, count_down, EVT_BOTTOM_REACHED, EVT_COMPARE_1, EVT_COMPARE_2, EVT_COMPARE_3, EVT_TOP_REACHED, IRQLine::fireInterrupt(), limit_top, OCRIDX_A, OCRIDX_maxUnits, SetPWMCompareOutput(), timerCapture, timerCompare, timerOverflow, wgm, WGM_PFCPWM_ICR, and WGM_PFCPWM_OCRA.

Referenced by HWTimer16::HWTimer16().

◆ WGMisPWM()

bool BasicTimerUnit::WGMisPWM ( void  )
inlineprotected

◆ WGMuseICR()

bool BasicTimerUnit::WGMuseICR ( void  )
inlineprotected

returns true, if WGM uses IC register for defining TOP counter value

Definition at line 185 of file hwtimer.h.

Referenced by InputCapture(), and HWTimer16::SetComplexRegister().

Member Data Documentation

◆ captureInputState

bool BasicTimerUnit::captureInputState
private

saved state for input capture

Definition at line 53 of file hwtimer.h.

Referenced by BasicTimerUnit(), and InputCapture().

◆ com

COMtype BasicTimerUnit::com[OCRIDX_maxUnits]
protected

compare match output mode

Definition at line 156 of file hwtimer.h.

Referenced by SetCompareOutput(), SetCompareOutputMode(), and SetPWMCompareOutput().

◆ compare

◆ compare_dbl

unsigned long BasicTimerUnit::compare_dbl[OCRIDX_maxUnits]
protected

◆ compare_output

PinAtPort BasicTimerUnit::compare_output[OCRIDX_maxUnits]
protected

output pins for compare units

Definition at line 158 of file hwtimer.h.

Referenced by HWTimer16::HWTimer16(), HWTimer8::HWTimer8(), SetCompareOutput(), SetCompareOutputMode(), and SetPWMCompareOutput().

◆ compare_output_state

bool BasicTimerUnit::compare_output_state[OCRIDX_maxUnits]
protected

status compare output pin

Definition at line 159 of file hwtimer.h.

Referenced by Reset(), SetCompareOutput(), SetCompareOutputMode(), and SetPWMCompareOutput().

◆ compareEnable

bool BasicTimerUnit::compareEnable[OCRIDX_maxUnits]
protected

enables compare operation

Definition at line 155 of file hwtimer.h.

Referenced by BasicTimerUnit(), CountTimer(), HWTimer16::HWTimer16(), and HWTimer8::HWTimer8().

◆ core

AvrDevice* BasicTimerUnit::core
protected

pointer to device core

Definition at line 130 of file hwtimer.h.

Referenced by SetClockMode().

◆ count_down

bool BasicTimerUnit::count_down
protected

counter counts down, used for precise pwm modes

Definition at line 141 of file hwtimer.h.

Referenced by HWTimer8::ChangeWGM(), HWTimer16::ChangeWGM(), CountTimer(), Reset(), WGMfunc_pcpwm(), and WGMfunc_pfcpwm().

◆ counterTrace

TraceValue* BasicTimerUnit::counterTrace
private

TraceValue instance for counter itself.

Definition at line 52 of file hwtimer.h.

Referenced by BasicTimerUnit(), CountTimer(), and SetCounter().

◆ cs

int BasicTimerUnit::cs
private

select value for prescaler multiplexer

Definition at line 51 of file hwtimer.h.

Referenced by CpuCycle(), and SetClockMode().

◆ eventListener

TimerEventListener* BasicTimerUnit::eventListener
private

event listener for timer events

Definition at line 56 of file hwtimer.h.

Referenced by HandleEvent().

◆ icapNCcounter

int BasicTimerUnit::icapNCcounter
private

counter for input capture noise canceler

Definition at line 54 of file hwtimer.h.

Referenced by BasicTimerUnit(), and InputCapture().

◆ icapNCstate

bool BasicTimerUnit::icapNCstate
private

state for input capture noise canceler

Definition at line 55 of file hwtimer.h.

Referenced by BasicTimerUnit(), and InputCapture().

◆ icapNoiseCanceler

bool BasicTimerUnit::icapNoiseCanceler
protected

Noise canceler for input capturing enabled.

Definition at line 149 of file hwtimer.h.

Referenced by InputCapture(), Reset(), HWTimer16_1C::Set_TCCRB(), HWTimer16_2C2::Set_TCCRB(), HWTimer16_2C3::Set_TCCRB(), and HWTimer16_3C::Set_TCCRB().

◆ icapRegister

unsigned long BasicTimerUnit::icapRegister
protected

◆ icapRisingEdge

bool BasicTimerUnit::icapRisingEdge
protected

Input capture on rising edge.

Definition at line 148 of file hwtimer.h.

Referenced by InputCapture(), Reset(), HWTimer16_1C::Set_TCCRB(), HWTimer16_2C2::Set_TCCRB(), HWTimer16_2C3::Set_TCCRB(), and HWTimer16_3C::Set_TCCRB().

◆ icapSource

ICaptureSource* BasicTimerUnit::icapSource
protected

Input capture source.

Definition at line 147 of file hwtimer.h.

Referenced by InputCapture(), and RegisterACompForICapture().

◆ limit_bottom

unsigned long BasicTimerUnit::limit_bottom
protected

BOTTOM value for up/down counting.

Definition at line 142 of file hwtimer.h.

Referenced by CountTimer(), Reset(), WGMfunc_ctc(), and WGMfunc_fastpwm().

◆ limit_max

unsigned long BasicTimerUnit::limit_max
protected

MAX value for counting.

Definition at line 144 of file hwtimer.h.

Referenced by BasicTimerUnit(), HWTimer8::ChangeWGM(), HWTimer16::ChangeWGM(), CountTimer(), and Reset().

◆ limit_top

unsigned long BasicTimerUnit::limit_top
protected

◆ premx

PrescalerMultiplexer* BasicTimerUnit::premx
protected

prescaler multiplexer

Definition at line 131 of file hwtimer.h.

Referenced by CpuCycle().

◆ timerCapture

IRQLine* BasicTimerUnit::timerCapture
protected

irq line for capture interrupt

Definition at line 133 of file hwtimer.h.

Referenced by InputCapture(), WGMfunc_fastpwm(), WGMfunc_pcpwm(), and WGMfunc_pfcpwm().

◆ timerCompare

IRQLine* BasicTimerUnit::timerCompare[OCRIDX_maxUnits]
protected

◆ timerOverflow

IRQLine* BasicTimerUnit::timerOverflow
protected

irq line for overflow interrupt

Definition at line 132 of file hwtimer.h.

Referenced by WGMfunc_ctc(), WGMfunc_fastpwm(), WGMfunc_normal(), WGMfunc_pcpwm(), and WGMfunc_pfcpwm().

◆ updown_counting

int BasicTimerUnit::updown_counting
protected

count direction control flag, true, if up/down counting

Definition at line 140 of file hwtimer.h.

Referenced by HWTimer8::ChangeWGM(), HWTimer16::ChangeWGM(), CountTimer(), and Reset().

◆ vlast_tcnt

unsigned long BasicTimerUnit::vlast_tcnt
protected

timercounter BEFORE count operation

Definition at line 136 of file hwtimer.h.

Referenced by CountTimer(), Reset(), and SetCounter().

◆ vtcnt

unsigned long BasicTimerUnit::vtcnt
protected

THE timercounter.

Definition at line 135 of file hwtimer.h.

Referenced by CountTimer(), HWTimer16::GetComplexRegister(), InputCapture(), Reset(), SetCounter(), WGMfunc_ctc(), and WGMfunc_fastpwm().

◆ wgm

◆ wgmfunc

wgmfunc_t BasicTimerUnit::wgmfunc[WGM_tablesize]
protected

waveform generator mode function table

Definition at line 152 of file hwtimer.h.

Referenced by BasicTimerUnit(), HandleEvent(), HWTimer16::HWTimer16(), and HWTimer8::HWTimer8().


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