BasicTimerUnit Class Reference

Basic timer unit. More...

#include <hwtimer.h>

Inheritance diagram for BasicTimerUnit:
Inheritance graph
[legend]
Collaboration diagram for BasicTimerUnit:
Collaboration graph
[legend]

List of all members.

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.
 ~BasicTimerUnit ()
void Reset ()
 Perform a reset of this unit.
virtual unsigned int CpuCycle ()
 Process timer/counter unit operations by CPU cycle.

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  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...
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.
virtual void InputCapture (void)
 Supports the input capture function.
void HandleEvent (CEtype event)
 Receives count events.
void SetClockMode (int _cs)
 Set clock mode.
void SetCounter (unsigned long val)
 Set the counter itself.
void SetCompareOutputMode (int idx, COMtype mode)
 Set compare output mode.
void SetCompareOutput (int idx)
 Set compare output pins in non pwm mode.
void SetPWMCompareOutput (int idx, bool topOrDown)
 Set compare output pins in pwm mode.
bool WGMisPWM (void)
 returns true, if WGM is in one of the PWM modes
bool WGMuseICR (void)
 returns true, if WGM uses IC register for defining TOP counter value
void WGMFunc_noop (CEtype event)
 WGM noop function.
void WGMfunc_normal (CEtype event)
 WGM function for normal mode (unique for all different timers).
void WGMfunc_ctc (CEtype event)
 WGM function for ctc mode (unique for all different timers).
void WGMfunc_fastpwm (CEtype event)
 WGM function for fast pwm mode (unique for all different timers).
void WGMfunc_pcpwm (CEtype event)
 WGM function for phase correct pwm mode (unique for all different timers).
void WGMfunc_pfcpwm (CEtype event)
 WGM function for phase and frequency correct pwm mode (unique for all different timers).

Protected Attributes

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

Private Attributes

int cs
 select value for prescaler multiplexer
TraceValuecounterTrace
 TraceValue instance for counter itself.
bool captureInputState
 saved state for input capture
int icapNCcounter
 counter for input capture noise canceler
bool icapNCstate
 state for input capture noise canceler

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 41 of file hwtimer.h.


Member Typedef Documentation

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

Definition at line 89 of file hwtimer.h.


Member Enumeration Documentation

enum BasicTimerUnit::CEtype [protected]

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 74 of file hwtimer.h.

enum BasicTimerUnit::COMtype [protected]

types of compare match output modes

Enumerator:
COM_NOOP 
COM_TOGGLE 
COM_CLEAR 
COM_SET 

Definition at line 67 of file hwtimer.h.

enum BasicTimerUnit::OCRIDXtype [protected]

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 83 of file hwtimer.h.

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 47 of file hwtimer.h.


Constructor & Destructor Documentation

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

Definition at line 86 of file hwtimer.cpp.

References counterTrace.


Member Function Documentation

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().

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int BasicTimerUnit::CpuCycle ( void   )  [virtual]

Process timer/counter unit operations by CPU cycle.

Reimplemented from Hardware.

Definition at line 561 of file hwtimer.cpp.

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

Here is the call graph for this function:

void BasicTimerUnit::HandleEvent ( CEtype  event  )  [inline, 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 131 of file hwtimer.h.

Referenced by CountTimer().

Here is the caller graph for this function:

void BasicTimerUnit::InputCapture ( void   )  [protected, virtual]

Supports the input capture function.

Definition at line 160 of file hwtimer.cpp.

References captureInputState, IRQLine::fireInterrupt(), ICaptureSource::GetSourceState(), icapNCcounter, icapNCstate, icapNoiseCanceler, icapRegister, icapRisingEdge, icapSource, timerCapture, vtcnt, and WGMuseICR().

Referenced by CpuCycle().

Here is the call graph for this function:

Here is the caller graph for this function:

void BasicTimerUnit::Reset ( void   )  [virtual]

Perform a reset of this unit.

Reimplemented from Hardware.

Reimplemented in HWTimer8, HWTimer16, HWTimer8_0C, HWTimer8_1C, HWTimer8_2C, HWTimer16_1C, HWTimer16_2C2, HWTimer16_2C3, and HWTimer16_3C.

Definition at line 542 of file hwtimer.cpp.

References COM_NOOP, compare, compare_dbl, compare_output_state, count_down, icapNoiseCanceler, icapRisingEdge, limit_bottom, limit_max, limit_top, OCRIDX_maxUnits, SetClockMode(), SetCompareOutputMode(), updown_counting, vlast_tcnt, vtcnt, wgm, and WGM_NORMAL.

Referenced by BasicTimerUnit().

Here is the call graph for this function:

Here is the caller graph for this function:

void BasicTimerUnit::SetClockMode ( int  _cs  )  [protected]

Set clock mode.

Definition at line 193 of file hwtimer.cpp.

References AvrDevice::AddToCycleList(), core, cs, and AvrDevice::RemoveFromCycleList().

Referenced by Reset(), HWTimer8_1C::Set_TCCR(), HWTimer8_0C::Set_TCCR(), HWTimer16_3C::Set_TCCRB(), HWTimer16_2C3::Set_TCCRB(), HWTimer16_2C2::Set_TCCRB(), HWTimer16_1C::Set_TCCRB(), and HWTimer8_2C::Set_TCCRB().

Here is the call graph for this function:

Here is the caller graph for this function:

void BasicTimerUnit::SetCompareOutput ( int  idx  )  [protected]

Set compare output pins in non pwm mode.

Definition at line 220 of file hwtimer.cpp.

References com, COM_CLEAR, COM_NOOP, COM_SET, COM_TOGGLE, compare_output, compare_output_state, and PinAtPort::SetAlternatePort().

Referenced by HWTimer8_1C::Set_TCCR(), HWTimer16_2C2::Set_TCCRA(), HWTimer8_2C::Set_TCCRB(), HWTimer16_3C::Set_TCCRC(), HWTimer16_2C3::Set_TCCRC(), SetPWMCompareOutput(), WGMfunc_ctc(), and WGMfunc_normal().

Here is the call graph for this function:

Here is the caller graph for this function:

void BasicTimerUnit::SetCompareOutputMode ( int  idx,
COMtype  mode 
) [protected]

Set compare output mode.

Definition at line 208 of file hwtimer.cpp.

References com, COM_NOOP, compare_output, compare_output_state, PinAtPort::SetAlternatePort(), and PinAtPort::SetUseAlternatePortIfDdrSet().

Referenced by Reset(), HWTimer8_1C::Set_TCCR(), HWTimer16_3C::Set_TCCRA(), HWTimer16_2C3::Set_TCCRA(), HWTimer16_2C2::Set_TCCRA(), HWTimer16_1C::Set_TCCRA(), and HWTimer8_2C::Set_TCCRA().

Here is the call graph for this function:

Here is the caller graph for this function:

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 HWTimer8::Set_TCNT(), and HWTimer16::SetComplexRegister().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Set compare output pins in pwm mode.

Definition at line 244 of file hwtimer.cpp.

References avr_warning, com, COM_CLEAR, COM_NOOP, COM_SET, COM_TOGGLE, compare_output, compare_output_state, OCRIDX_A, PinAtPort::SetAlternatePort(), SetCompareOutput(), wgm, WGM_FASTPWM_OCRA, WGM_PCPWM_OCRA, and WGM_PFCPWM_OCRA.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

void BasicTimerUnit::WGMfunc_fastpwm ( CEtype  event  )  [protected]

WGM function for fast pwm mode (unique for all different timers).

Definition at line 348 of file hwtimer.cpp.

References compare, compare_dbl, EVT_BOTTOM_REACHED, EVT_COMPARE_1, EVT_COMPARE_2, EVT_COMPARE_3, EVT_TOP_REACHED, IRQLine::fireInterrupt(), limit_bottom, limit_top, OCRIDX_A, OCRIDX_maxUnits, SetPWMCompareOutput(), timerCapture, timerCompare, timerOverflow, vtcnt, wgm, WGM_FASTPWM_10BIT, WGM_FASTPWM_8BIT, WGM_FASTPWM_9BIT, WGM_FASTPWM_ICR, and WGM_FASTPWM_OCRA.

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

Here is the call graph for this function:

Here is the caller graph for this function:

void BasicTimerUnit::WGMFunc_noop ( CEtype  event  )  [inline, protected]

WGM noop function.

Definition at line 148 of file hwtimer.h.

Referenced by BasicTimerUnit().

Here is the caller graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

void BasicTimerUnit::WGMfunc_pcpwm ( CEtype  event  )  [protected]

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

Definition at line 417 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_PCPWM_10BIT, WGM_PCPWM_8BIT, WGM_PCPWM_9BIT, WGM_PCPWM_ICR, and WGM_PCPWM_OCRA.

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

Here is the call graph for this function:

Here is the caller graph for this function:

void BasicTimerUnit::WGMfunc_pfcpwm ( CEtype  event  )  [protected]

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

Definition at line 484 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().

Here is the call graph for this function:

Here is the caller graph for this function:

bool BasicTimerUnit::WGMisPWM ( void   )  [inline, protected]
bool BasicTimerUnit::WGMuseICR ( void   )  [inline, protected]

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

Definition at line 146 of file hwtimer.h.

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

Here is the caller graph for this function:


Member Data Documentation

saved state for input capture

Definition at line 41 of file hwtimer.h.

Referenced by BasicTimerUnit(), and InputCapture().

COMtype BasicTimerUnit::com[OCRIDX_maxUnits] [protected]

compare match output mode

Definition at line 117 of file hwtimer.h.

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

unsigned long BasicTimerUnit::compare[OCRIDX_maxUnits] [protected]
unsigned long BasicTimerUnit::compare_dbl[OCRIDX_maxUnits] [protected]
PinAtPort* BasicTimerUnit::compare_output[OCRIDX_maxUnits] [protected]

output pins for compare units

Definition at line 119 of file hwtimer.h.

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

bool BasicTimerUnit::compare_output_state[OCRIDX_maxUnits] [protected]

status compare output pin

Definition at line 120 of file hwtimer.h.

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

bool BasicTimerUnit::compareEnable[OCRIDX_maxUnits] [protected]

enables compare operation

Definition at line 116 of file hwtimer.h.

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

pointer to device core

Definition at line 91 of file hwtimer.h.

Referenced by SetClockMode().

bool BasicTimerUnit::count_down [protected]

counter counts down, used for precise pwm modes

Definition at line 102 of file hwtimer.h.

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

TraceValue instance for counter itself.

Definition at line 40 of file hwtimer.h.

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

int BasicTimerUnit::cs [private]

select value for prescaler multiplexer

Definition at line 39 of file hwtimer.h.

Referenced by CpuCycle(), and SetClockMode().

counter for input capture noise canceler

Definition at line 42 of file hwtimer.h.

Referenced by BasicTimerUnit(), and InputCapture().

state for input capture noise canceler

Definition at line 43 of file hwtimer.h.

Referenced by BasicTimerUnit(), and InputCapture().

Noise canceler for input capturing enabled.

Definition at line 110 of file hwtimer.h.

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

unsigned long BasicTimerUnit::icapRegister [protected]

Input capture on rising edge.

Definition at line 109 of file hwtimer.h.

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

Input capture source.

Definition at line 108 of file hwtimer.h.

Referenced by InputCapture().

unsigned long BasicTimerUnit::limit_bottom [protected]

BOTTOM value for up/down counting.

Definition at line 103 of file hwtimer.h.

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

unsigned long BasicTimerUnit::limit_max [protected]

MAX value for counting.

Definition at line 105 of file hwtimer.h.

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

unsigned long BasicTimerUnit::limit_top [protected]

prescaler multiplexer

Definition at line 92 of file hwtimer.h.

Referenced by CpuCycle().

irq line for capture interrupt

Definition at line 94 of file hwtimer.h.

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

IRQLine* BasicTimerUnit::timerCompare[OCRIDX_maxUnits] [protected]

irq line for overflow interrupt

Definition at line 93 of file hwtimer.h.

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

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

Definition at line 101 of file hwtimer.h.

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

unsigned long BasicTimerUnit::vlast_tcnt [protected]

timercounter BEFORE count operation

Definition at line 97 of file hwtimer.h.

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

unsigned long BasicTimerUnit::vtcnt [protected]
wgmfunc_t BasicTimerUnit::wgmfunc[WGM_tablesize] [protected]

waveform generator mode function table

Definition at line 113 of file hwtimer.h.

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


The documentation for this class was generated from the following files:
Generated on Sun Feb 12 16:50:44 2012 for Simulavr by  doxygen 1.6.3