55 if(countersize != 8 && countersize != 16)
56 avr_error(
"wrong parameter: countersize=%d", countersize);
228 new_state = old_state ? false :
true;
587 tcnt_reg(this,
"TCNT",
589 ocra_reg(this,
"OCRA",
591 ocrb_reg(this,
"OCRB",
696 tcnt_h_reg(this,
"TCNTH",
698 tcnt_l_reg(this,
"TCNTL",
700 ocra_h_reg(this,
"OCRAH",
702 ocra_l_reg(this,
"OCRAL",
704 ocrb_h_reg(this,
"OCRBH",
706 ocrb_l_reg(this,
"OCRBL",
708 ocrc_h_reg(this,
"OCRCH",
710 ocrc_l_reg(this,
"OCRCL",
712 icr_h_reg(this,
"ICRH",
714 icr_l_reg(this,
"ICRL",
796 return (temp >> 8) & 0xff;
804 avr_warning(
"ICRxH isn't writable in a non-ICR WGM mode");
814 avr_warning(
"ICRxL isn't writable in a non-ICR WGM mode");
920 tccr_reg(this,
"TCCR",
948 int raw_wgm = ((val & 0x8) >> 2) + ((val & 0x40) >> 6);
979 HWTimer8(core, p, unit, tov, tcompA, outA, tcompB, outB),
980 tccra_reg(this,
"TCCRA",
982 tccrb_reg(this,
"TCCRB",
1019 temp += (val >> 1) & 0x4;
1049 HWTimer16(core, p, unit, tov, tcompA, outA, NULL,
PinAtPort(), NULL,
PinAtPort(), ticap, icapsrc),
1088 temp += (val >> 1) & 0x4;
1115 HWTimer16(core, p, unit, tov, tcompA, outA, tcompB, outB, NULL,
PinAtPort(), ticap, icapsrc),
1116 at8515_mode(is_at8515),
1169 temp += (val >> 1) & mask;
1195 HWTimer16(core, p, unit, tov, tcompA, outA, tcompB, outB, NULL,
PinAtPort(), ticap, icapsrc),
1200 tccrc_reg(this,
"TCCRC",
1204 int temp = (int)
wgm;
1216 int temp = (int)
wgm;
1218 temp += (val >> 1) & 0xc;
1257 HWTimer16(core, p, unit, tov, tcompA, outA, tcompB, outB, tcompC, outC, ticap, icapsrc),
1266 int temp = (int)
wgm;
1279 int temp = (int)
wgm;
1281 temp += (val >> 1) & 0xc;
1331 ocra_unit(ocra_out, ocra_outinv),
1332 ocrb_unit(ocrb_out, ocrb_outinv),
1334 timerOverflowInt(tov),
1335 timerOCRAInt(tocra),
1336 timerOCRBInt(tocrb),
1337 tccr_reg(this,
"TCCR1",
1339 tcnt_reg(this,
"TCNT1",
1341 tocra_reg(this,
"OCR1A",
1343 tocrb_reg(this,
"OCR1B",
1345 tocrc_reg(this,
"OCR1C",
1347 dtps1_reg(this,
"DTPS1",
1349 dt1a_reg(this,
"DT1A",
1351 dt1b_reg(this,
"DT1B",
1429 *nextStepIn_ns = -1;
1555 return (
bool)((
prescaler % 16384) == 0);
1589 if((nv & 0x02) == 0x02) {
1596 bool pll = (nv & 0x02) == 0x02;
1611 unsigned long delay = 100000 + rand() % 2000 - 1000;
1747 outPinInv = pinOutInv;
1764 if(dtCounter == 0) {
1767 outPin.SetAlternatePort(ocrOut);
1769 outPinInv.SetAlternatePort(!ocrOut);
1776 if((ocrComMode == 0) && (comMode != 0)) {
1777 ocrOut = outPin.GetPort();
1780 if(ocrComMode != comMode) {
1783 outPin.SetUseAlternatePortIfDdrSet(
true);
1784 outPin.SetAlternatePort(ocrOut);
1785 if(isPWM && comMode == 1) {
1787 outPinInv.SetUseAlternatePortIfDdrSet(
true);
1788 outPinInv.SetAlternatePort(!ocrOut);
1792 outPin.SetUseAlternatePortIfDdrSet(
false);
1793 outPinInv.SetUseAlternatePortIfDdrSet(
false);
1797 ocrComMode = comMode;
1805 if(isCompareEvent) {
1806 switch(ocrComMode) {
1823 switch(ocrComMode) {
1843 if(isCompareEvent) {
1844 switch(ocrComMode) {
1873 if((ocrComMode == 1) && ocrPWM) {
1875 if(pwmValue && !ocrOut) {
1878 dtCounter = dtHigh + 1;
1881 outPin.SetAlternatePort(pwmValue);
1883 outPinInv.SetAlternatePort(!pwmValue);
1884 }
else if(!pwmValue && ocrOut) {
1887 dtCounter = dtLow + 1;
1890 outPinInv.SetAlternatePort(!pwmValue);
1892 outPin.SetAlternatePort(pwmValue);
1896 outPin.SetAlternatePort(pwmValue);
TraceValue * counterTrace
TraceValue instance for counter itself.
COMtype
types of compare match output modes
TimerEventListener * eventListener
event listener for timer events
int cfg_com_b
internal (async) setting for compare output modul B
void Add(SimulationMember *dev)
Add a simulation member (normally a device)
void WGMfunc_pfcpwm(CEtype event)
WGM function for phase and frequency correct pwm mode (unique for all different timers) ...
bool WGMisPWM(void)
returns true, if WGM is in one of the PWM modes
int Step(bool &untilCoreStepFinished, SystemClockOffset *nextStepIn_ns)
Performs the async clocking, if necessary.
unsigned char Get_TCCRA()
Register access to read control register A.
Basic AVR device, contains the core functionality.
unsigned long vlast_tcnt
timercounter BEFORE count operation
bool asyncClock_plllock
pll frequency is locked
void MaskOutSync(unsigned char mask)
Mask out a value inside sync area and do not force a change event.
int asyncClock_step
step counter for step delays. -1, if not in async mode
bool tocrb_internal_flag
OCFxB flag is set, have to be delayed by 1 CK.
unsigned char GetComplexRegister(bool is_icr, bool high)
Getter method for TCNT and ICR register.
int icapNCcounter
counter for input capture noise canceler
void SetPWM(bool isCompareEvent)
Calculate output pin value (before dead time generator)
timer in PWM mode, upcounting from 0 to OCRC, PWM A active
void SetPWMCompareOutput(int idx, bool topOrDown)
Set compare output pins in pwm mode.
IOSpecialReg * gtccrRegister
instance of GTCCR register
unsigned long counter
THE timer counter.
unsigned char dtprescaler
dead time prescaler counter
IOReg< HWTimer16 > ocrc_h_reg
output compare C register, high byte
void AddToCycleList(Hardware *hw)
int wgm_raw
this is the wgm raw value from register
timer in PWM mode, upcounting from 0 to OCRC, PWM B active
SystemClockOffset GetCurrentTime() const
Returns the current simulation time.
compare[0] value reached for one count cycle
int cfg_com_a
internal (async) setting for compare output modul A
IRQLine * timerOCRBInt
irq line for output compare B interrupt
unsigned char Get_TCCRB()
Register access to read control register B.
void WGMFunc_noop(CEtype event)
WGM noop function.
void Reset(void)
Perform a reset of this unit.
TraceValue * counterTrace
TraceValue instance for counter itself.
bool icapNCstate
state for input capture noise canceler
void Set_WGM(int val)
Handle special WGM setting, translate wgm raw value to wgm value.
unsigned char tccrb_val
register value TCCRB
unsigned char Get_TCCRB()
Register access to read control register B.
virtual void InputCapture(void)
Supports the input capture function.
HWTimerTinyX5_SyncReg tccr_inout_val
register value TCCR1
IOReg< HWTimer16 > ocra_h_reg
output compare A register, high byte
Timer unit with 8Bit counter and one output compare unit.
int cfg_mode
internal (async) timer mode setting
Extends BasicTimerUnit to provide common support to all types of 8Bit timer units.
unsigned long limit_top
TOP value for counting.
void Set_TCCRA(unsigned char val)
Register access to set control register.
unsigned char tccra_val
register value TCCRA
TOP reached for one count cycle.
IOReg< HWTimer16 > ocra_l_reg
output compare A register, low byte
void Set_TCCRA(unsigned char val)
Register access to set control register A.
bool WGMuseICR(void)
returns true, if WGM uses IC register for defining TOP counter value
void Set_TCCR(unsigned char val)
Register access to set control register.
HWTimerTinyX5_SyncReg ocrb_inout_val
register value OCRB
void Reset(void)
Perform a reset of this unit.
virtual bool GetSourceState(void)
Returns the digital input state of input capture source(s)
unsigned char ocra_internal_val
internal (async) register value for OCRA1
IOReg< HWTimer16 > ocrc_l_reg
output compare C register, low byte
unsigned char tccrb_val
register value TCCRB
void Reset()
Perform a reset of this unit.
unsigned char accessTempRegister
the high byte temporary register for read/write access to TCNT and ICR
Represents a timer interrupt line, Frontend for timer interrupts.
void WGMfunc_pcpwm(CEtype event)
WGM function for phase correct pwm mode (unique for all different timers)
BOTTOM reached for one count cycle.
virtual bool isClock(unsigned int cs)
bool count_down
counter counts down, used for precise pwm modes
unsigned char tccra_val
register value TCCRA
void SetOCRMode(bool isPWM, int comMode)
Configure OCR mode.
unsigned long ocra_compare
active compare value for OCR A unit
unsigned long limit_bottom
BOTTOM value for up/down counting.
const int HWTimerTinyX5_nextdelay[8]
Step time in ns for async clock by pll.
unsigned char tccrb_val
register value TCCRB
unsigned char tccr_val
register value TCCR
unsigned char Get_TCCRC()
Register access to read control register C.
void Set_TCCRB(unsigned char val)
Register access to set control register B.
amount of possible OC units
bool DeadTimePrescalerMux(void)
Dead time prescaler multiplex function, returns true, if a count pulse is happen. ...
void connectSRegClient(IOSpecialRegClient *c)
Registers a client to this IO register to inform this client on read or write access.
void CountTimer(void)
Supports the count operation, emits count events to HandleEvent method.
unsigned char dtps1_inout_val
register value DTPS1
unsigned char get_from_client(const IOSpecialReg *reg, unsigned char v)
IO register interface get method, see IOSpecialRegClient.
IOReg< HWTimer16_2C3 > tccra_reg
control register A
COMtype com[OCRIDX_maxUnits]
compare match output mode
IOReg< HWTimer8_2C > tccrb_reg
control register B
int cfg_prescaler
internal (async) prescaler setting
bool asyncClock_pll
pll is switched on
void WGMfunc_normal(CEtype event)
WGM function for normal mode (unique for all different timers)
void Reset()
Perform a reset of this unit.
void Reset(void)
Perform a reset of this unit.
void SetUseAlternatePortIfDdrSet(bool val)
unsigned long prescaler
THE prescaler counter.
IOReg< HWTimer16_2C3 > tccrb_reg
control register B
bool captureInputState
saved state for input capture
void Set_TCCRB(unsigned char val)
Register access to set control register B.
bool asyncClock_lsm
mode switch for lsm mode (32MHz clock)
an counter overflow occured
void Set_TCCRA(unsigned char val)
Register access to set control register A.
IOReg< HWTimer8_2C > tccra_reg
control register A
HWTimer16_2C3(AvrDevice *core, PrescalerMultiplexer *p, int unit, IRQLine *tov, IRQLine *tcompA, const PinAtPort &outA, IRQLine *tcompB, const PinAtPort &outB, IRQLine *ticap, ICaptureSource *icapsrc)
BasicTimerUnit(AvrDevice *core, PrescalerMultiplexer *p, int unit, IRQLine *tov, IRQLine *tcap, ICaptureSource *icapsrc, int countersize=8)
Create a basic Timer/Counter unit.
timer in normal mode, upcounting from 0x0 to 0xff or 0 to OCRC (CTC mode)
HWTimer16_1C(AvrDevice *core, PrescalerMultiplexer *p, int unit, IRQLine *tov, IRQLine *tcompA, const PinAtPort &outA, IRQLine *ticap, ICaptureSource *icapsrc)
void SetPrescalerClock(bool pcke)
Set clock source for prescaler.
TraceValue * dTPrescalerTrace
TraceValue instance for dead time prescaler.
TimerTinyX5_OCR ocra_unit
OCR control unit for OCR channel A.
PrescalerMultiplexer * premx
prescaler multiplexer
void WGMfunc_fastpwm(CEtype event)
WGM function for fast pwm mode (unique for all different timers)
void SetAlternatePort(bool val)
Timer unit with 16Bit counter and 2 output compare units, but 3 config registers. ...
void TransferInputValues(void)
Transfer register input to internal register set.
void WGMfunc_ctc(CEtype event)
WGM function for ctc mode (unique for all different timers)
IRQLine * timerOCRAInt
irq line for output compare A interrupt
virtual unsigned int CpuCycle()
Process timer/counter unit operations by CPU cycle.
Build a register for TraceValue's.
HWTimer8(AvrDevice *core, PrescalerMultiplexer *p, int unit, IRQLine *tov, IRQLine *tcompA, const PinAtPort &outA, IRQLine *tcompB, const PinAtPort &outB)
void SetCompareOutputMode(int idx, COMtype mode)
Set compare output mode.
TimerTinyX5_OCR(const PinAtPort &pinOut, const PinAtPort &pinOutInv)
void SetCompareRegister(int idx, unsigned char val)
Setter method for compare register.
void Reset(void)
Perform a reset of this unit.
void RegisterTraceValue(TraceValue *t)
Registers a TraceValue for this register.
unsigned char tccrb_val
register value TCCRB
compare[1] value reached for one count cycle
static SystemClock & Instance()
Returns the central SystemClock instance for the application.
void Reset(void)
Perform a reset of this unit.
timer unit for timer 1 on ATtiny25/45/85
void Set_TCCRB(unsigned char val)
Register access to set control register B.
void SetCompareRegister(int idx, bool high, unsigned char val)
Setter method for compare register.
unsigned char tcnt_in_val
input register value for TCNT
unsigned char tcnt_out_val
output register value for TCNT
void TimerCounter(void)
Count function, contains prescaler, multiplexer and counter functionality.
unsigned long compare[OCRIDX_maxUnits]
compare values for output compare events
unsigned char Get_TCCRA()
Register access to read control register.
Timer unit with 16Bit counter and 2 output compare units and 2 config registers.
int cs
select value for prescaler multiplexer
HWTimerTinyX5_SyncReg dt1a_inout_val
register value DT1A
HWTimerTinyX5(AvrDevice *core, IOSpecialReg *gtccr, IOSpecialReg *pllcsr, IRQLine *tov, IRQLine *tocra, const PinAtPort &ocra_out, const PinAtPort &ocra_outinv, IRQLine *tocrb, const PinAtPort &ocrb_out, const PinAtPort &ocrb_outinv)
bool icapRisingEdge
Input capture on rising edge.
void TimerEvent(bool isCompareEvent)
OCR event.
void Reset(void)
Perform a reset of this unit.
void Reset()
Perform a reset of this unit.
TimerTinyX5_OCR ocrb_unit
OCR control unit for OCR channel B.
void ChangeWGM(WGMtype mode)
Change WGM mode, set counter limits.
bool icapNoiseCanceler
Noise canceler for input capturing enabled.
void RegisterAComp(HWAcomp *_acomp)
Register analog comparator.
void fireInterrupt(void)
inform interrupt system, that an interrupt occured
void SetCounter(unsigned long val)
Set the counter itself.
unsigned long compare_dbl[OCRIDX_maxUnits]
double buffer values for compare values
unsigned char tccr_val
register value TCCR
long long SystemClockOffset
unsigned char Get_TCCR()
Register access to read control register.
bool tocra_internal_flag
OCFxA flag is set, have to be delayed by 1 CK.
TraceValue * prescalerTrace
TraceValue instance for prescaler.
bool ClockAndChanged(void)
check after one clock, if register value has changed
std::string int2str(int i)
Convert an int into a string.
HWTimerTinyX5_SyncReg dt1b_inout_val
register value DT1B
IOReg< HWTimer16_1C > tccrb_reg
control register B
HWTimer8_2C(AvrDevice *core, PrescalerMultiplexer *p, int unit, IRQLine *tov, IRQLine *tcompA, const PinAtPort &outA, IRQLine *tcompB, const PinAtPort &outB)
void Set_TCCRC(unsigned char val)
Register access to set control register C.
IOReg< HWTimer16 > ocrb_l_reg
output compare B register, low byte
WGMtype
types of waveform generation modes
compare[2] value reached for one count cycle
Timer unit with 16Bit counter and 3 output compare units.
HWTimerTinyX5_SyncReg ocra_inout_val
register value OCRA
wgmfunc_t wgmfunc[WGM_tablesize]
waveform generator mode function table
unsigned long icapRegister
Input capture register.
unsigned long limit_max
MAX value for counting.
int wgm_raw
this is the wgm raw value from register
unsigned char ocrb_internal_val
internal (async) register value for OCRB1
virtual void fireEvent(int event)=0
void SetCompareOutput(int idx)
Set compare output pins in non pwm mode.
AvrDevice * core
pointer to device core
unsigned char tccra_val
register value TCCRA
void Reset()
Reset internal states on device reset.
void Reset(void)
Perform a reset of this unit.
unsigned char Get_TCCRB()
Register access to read control register.
void RegisterACompForICapture(HWAcomp *acomp)
register analog comparator unit for input capture source
HWTimer8_0C(AvrDevice *core, PrescalerMultiplexer *p, int unit, IRQLine *tov)
int updown_counting
count direction control flag, true, if up/down counting
void Set_TCCRC(unsigned char val)
Register access to set control register C.
unsigned char GetCompareRegister(int idx)
Getter method for compare register.
Timer unit with 16Bit counter and one output compare unit.
void Set_TCCRA(unsigned char val)
Register access to set control register A.
HWTimerTinyX5_SyncReg ocrc_inout_val
register value OCRC
IRQLine * timerOverflow
irq line for overflow interrupt
void RemoveFromCycleList(Hardware *hw)
Removes from the cycle list, if possible.
IOReg< HWTimer16_1C > tccra_reg
control register A
void TransferOutputValues(void)
Transfer internal register values (if needed) to by core readable register.
unsigned long vtcnt
THE timercounter.
Timer unit with 8Bit counter and no output compare unit.
unsigned char set_from_reg(const IOSpecialReg *reg, unsigned char nv)
IO register interface set method, see IOSpecialRegClient.
HWTimer16_2C2(AvrDevice *core, PrescalerMultiplexer *p, int unit, IRQLine *tov, IRQLine *tcompA, const PinAtPort &outA, IRQLine *tcompB, const PinAtPort &outB, IRQLine *ticap, ICaptureSource *icapsrc, bool is_at8515)
void Set_TCCR(unsigned char val)
Register access to set control register.
const std::string GetTraceValuePrefix(void)
Returns the scope prefix.
void HandleEvent(CEtype event)
Receives count events.
bool PrescalerMux(void)
Prescaler multiplex function, returns true, if a count pulse is happen.
IOReg< HWTimer8_0C > tccr_reg
control register
void Set_TCCRA(unsigned char val)
Register access to set control register A.
IOReg< HWTimer16 > ocrb_h_reg
output compare B register, high byte
int wgm_raw
this is the wgm raw value from register
void ForceEvent()
Manual change of OCR unit by force bit.
int cfg_dtprescaler
internal (async) dead time prescaler setting
void Reset(unsigned char v)
perform a reset to set valid reset values without clock
IOReg< HWTimer16_2C3 > tccrc_reg
control register C
PrescalerMultiplexer without external count pin.
bool compare_output_state[OCRIDX_maxUnits]
status compare output pin
HWTimer16(AvrDevice *core, PrescalerMultiplexer *p, int unit, IRQLine *tov, IRQLine *tcompA, const PinAtPort &outA, IRQLine *tcompB, const PinAtPort &outB, IRQLine *tcompC, const PinAtPort &outC, IRQLine *ticap, ICaptureSource *icapsrc)
bool at8515_mode
signals, that this timer units is used in AT90S8515
IOReg< HWTimer8 > ocra_reg
output compare A register
unsigned char tccra_val
register value TCCRA
unsigned char tccrb_val
register value TCCRB
void Set_WGM(int val)
Handle special WGM setting, translate wgm raw value to wgm value.
PinAtPort compare_output[OCRIDX_maxUnits]
output pins for compare units
IRQLine * timerCompare[OCRIDX_maxUnits]
irq line for compare interrupt
Class, which provides input capture source for 16bit timers.
IRQLine * timerCapture
irq line for capture interrupt
bool tcnt_set_flag
flag to signal, that a new counter value was set
unsigned char Get_TCCRA()
Register access to read control register A.
unsigned char tccra_val
register value TCCRA
Timer unit with 8Bit counter and 2 output compare unit.
ICaptureSource * icapSource
Input capture source.
static DumpManager * Instance(void)
Singleton class access.
bool compareEnable[OCRIDX_maxUnits]
enables compare operation
unsigned char Get_TCCRB()
Register access to read control register B.
void Set_TCCRB(unsigned char val)
Register access to set control register.
void change(unsigned val)
Log a change on this value.
unsigned char Get_TCCRA()
Register access to read control register A.
CEtype
event types for timer/counter
void Set_WGM(int val)
Handle special WGM setting, translate wgm raw value to wgm value.
IOReg< HWTimer16_2C2 > tccrb_reg
control register B
void SetDeadTime(bool pwmValue)
Calculate output pin value after dead time generator.
unsigned long ocrb_compare
active compare value for OCR B unit
bool cfg_ctc
internal (async) flag for clear timer counter
HWTimer16_3C(AvrDevice *core, PrescalerMultiplexer *p, int unit, IRQLine *tov, IRQLine *tcompA, const PinAtPort &outA, IRQLine *tcompB, const PinAtPort &outB, IRQLine *tcompC, const PinAtPort &outC, IRQLine *ticap, ICaptureSource *icapsrc)
void ChangeWGM(WGMtype mode)
Change WGM mode, set counter limits.
Extends BasicTimerUnit to provide common support to all types of 16Bit timer units.
SystemClockOffset asyncClock_locktime
time, when pll is locked
unsigned char GetCompareRegister(int idx, bool high)
Getter method for compare register.
void SetClockMode(int _cs)
Set clock mode.
bool tov_internal_flag
TOV flag is set, have to be delayed by 1 CK.
IOReg< HWTimer8 > ocrb_reg
output compare B register
void Set_TCCRB(unsigned char val)
Register access to set control register B.
HWTimerTinyX5_SyncReg gtccr_in_val
input register value GTCCR
void Reset(void)
Perform a reset of this unit.
void DTClockCycle()
Run one clock cycle from dead time prescaler.
unsigned char tcnt_out_async_tmp
temporary register value for TCNT in async mode
IOSpecialReg * pllcsrRegister
instance of PLLCSR register
Analog comparator peripheral.
void SetComplexRegister(bool is_icr, bool high, unsigned char val)
Setter method for TCNT and ICR register.
IRQLine * timerOverflowInt
irq line for overflow interrupt
HWTimer8_1C(AvrDevice *core, PrescalerMultiplexer *p, int unit, IRQLine *tov, IRQLine *tcompA, const PinAtPort &outA)
void releaseTraceValue(void)
IOReg< HWTimer16_2C2 > tccra_reg
control register A
WGMtype wgm
waveform generation mode
bool asyncClock_async
mode switch for async mode
unsigned int CpuCycle()
Process timer/counter unit operations by CPU cycle.