simulavr  1.1.0
HWAcomp Class Reference

Analog comparator peripheral. More...

#include <hwacomp.h>

Inheritance diagram for HWAcomp:

Public Types

enum  {
  ACD = 0x80, ACBG = 0x40, ACO = 0x20, ACI = 0x10,
  ACIE = 0x08, ACIC = 0x04, ACIS1 = 0x02, ACIS0 = 0x01
}
 

Public Member Functions

 HWAcomp (AvrDevice *core, HWIrqSystem *irqsys, PinAtPort ain0, PinAtPort ain1, unsigned int irqVec, HWAd *_ad, BasicTimerUnit *_timerA, IOSpecialReg *_sfior=NULL, BasicTimerUnit *_timerB=NULL, bool _useBG=true)
 constructor to instantiate a analog comparator peripheral More...
 
 ~HWAcomp ()
 
unsigned char GetAcsr ()
 Get method for ACSR register. More...
 
void SetAcsr (unsigned char val)
 Set method for ACSR register. More...
 
void Reset ()
 Reset the unit. More...
 
void ClearIrqFlag (unsigned int vec)
 Reflect irq processing, reset interrupt source. More...
 
void PinStateHasChanged (Pin *)
 Get informed about input pin change. More...
 
float GetIn0 (void)
 Get analog value for comparator input 0. More...
 
float GetIn1 (void)
 Get analog value for comparator input 1. More...
 
bool GetACO (void)
 Return last state of analog comparator (assume, that this is correct, if unit is disabled) More...
 
void NotifySignalChanged (void)
 
- Public Member Functions inherited from Hardware
 Hardware (AvrDevice *core)
 
virtual ~Hardware ()
 
virtual unsigned int CpuCycle (void)
 
virtual bool IsLevelInterrupt (unsigned int vector)
 
virtual bool LevelInterruptPending (unsigned int vector)
 
- Public Member Functions inherited from HasPinNotifyFunction
virtual ~HasPinNotifyFunction ()
 
- 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...
 
- Public Member Functions inherited from IOSpecialRegClient
virtual ~IOSpecialRegClient ()
 
- Public Member Functions inherited from AnalogSignalChange
virtual ~AnalogSignalChange ()
 

Public Attributes

IOReg< HWAcompacsr_reg
 ACSR IO register. More...
 

Protected Member Functions

unsigned char set_from_reg (const IOSpecialReg *reg, unsigned char nv)
 
unsigned char get_from_client (const IOSpecialReg *reg, unsigned char v)
 
bool isSetACME (void)
 Check, if ACME flag is set (from ADC or SFIOR register) 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

HWIrqSystemirqSystem
 connection to IRQ controller More...
 
PinAtPort pinAin0
 port pin AIN0 More...
 
PinAtPort pinAin1
 port pin AIN1 More...
 
Pinv_bg
 get access to bandgap reference More...
 
Pinv_cc
 get access to voltage supply level More...
 
bool useBG
 has ADBG register bit and can switch In0 to bandgap ref More...
 
bool acme_sfior
 ACME flag in SFIOR register is set. More...
 
bool enabled
 analog comparator is enabled More...
 
unsigned char acsr
 ACSR register value. More...
 
unsigned int irqVec
 stores the IRQ vector number More...
 
BasicTimerUnittimerA
 connection to timerA for input capture event. NULL, if not available More...
 
BasicTimerUnittimerB
 connection to timerB for input capture event. NULL, if not available More...
 
HWAdad
 connection to ADC for analog input mux. NULL, if not available More...
 
IOSpecialRegsfior
 connection to SFIOR register, if necessary. NULL, if not used More...
 

Detailed Description

Analog comparator peripheral.

Definition at line 42 of file hwacomp.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
ACD 
ACBG 
ACO 
ACI 
ACIE 
ACIC 
ACIS1 
ACIS0 

Definition at line 71 of file hwacomp.h.

Constructor & Destructor Documentation

◆ HWAcomp()

HWAcomp::HWAcomp ( AvrDevice core,
HWIrqSystem irqsys,
PinAtPort  ain0,
PinAtPort  ain1,
unsigned int  irqVec,
HWAd _ad,
BasicTimerUnit _timerA,
IOSpecialReg _sfior = NULL,
BasicTimerUnit _timerB = NULL,
bool  _useBG = true 
)

◆ ~HWAcomp()

HWAcomp::~HWAcomp ( )

Definition at line 80 of file hwacomp.cpp.

References ad, and HWAd::UnregisterNotifyClient().

Member Function Documentation

◆ ClearIrqFlag()

void HWAcomp::ClearIrqFlag ( unsigned int  vec)
virtual

Reflect irq processing, reset interrupt source.

Reimplemented from Hardware.

Definition at line 182 of file hwacomp.cpp.

References ACI, acsr, HWIrqSystem::ClearIrqFlag(), irqSystem, and irqVec.

Referenced by GetAcsr().

◆ get_from_client()

unsigned char HWAcomp::get_from_client ( const IOSpecialReg reg,
unsigned char  v 
)
inlineprotectedvirtual

Informs your class, that a read access from IO register happens

Parameters
vthe internal saved register value (but maybe changed by other clients)
Returns
v, if nothing is changed or your changed value

Implements IOSpecialRegClient.

Definition at line 65 of file hwacomp.h.

References isSetACME().

◆ GetACO()

bool HWAcomp::GetACO ( void  )
inline

Return last state of analog comparator (assume, that this is correct, if unit is disabled)

Definition at line 112 of file hwacomp.h.

References ACO, and NotifySignalChanged().

Referenced by ICaptureSource::GetSourceState().

◆ GetAcsr()

unsigned char HWAcomp::GetAcsr ( )
inline

Get method for ACSR register.

Definition at line 98 of file hwacomp.h.

References acsr, ClearIrqFlag(), GetIn0(), GetIn1(), PinStateHasChanged(), Reset(), and SetAcsr().

◆ GetIn0()

float HWAcomp::GetIn0 ( void  )

Get analog value for comparator input 0.

Definition at line 126 of file hwacomp.cpp.

References ACBG, acsr, PinAtPort::GetAnalogValue(), Pin::GetRawAnalog(), pinAin0, useBG, v_bg, and v_cc.

Referenced by GetAcsr(), PinStateHasChanged(), and Reset().

◆ GetIn1()

float HWAcomp::GetIn1 ( void  )

Get analog value for comparator input 1.

Definition at line 133 of file hwacomp.cpp.

References ad, HWAd::GetADMuxValue(), PinAtPort::GetAnalogValue(), Pin::GetRawAnalog(), isSetACME(), pinAin1, and v_cc.

Referenced by GetAcsr(), PinStateHasChanged(), and Reset().

◆ isSetACME()

bool HWAcomp::isSetACME ( void  )
protected

Check, if ACME flag is set (from ADC or SFIOR register)

Definition at line 197 of file hwacomp.cpp.

References acme_sfior, ad, HWAd::IsADEnabled(), HWAd::IsSetACME(), and sfior.

Referenced by get_from_client(), GetIn1(), and NotifySignalChanged().

◆ NotifySignalChanged()

void HWAcomp::NotifySignalChanged ( void  )
virtual

Implements AnalogSignalChange.

Definition at line 176 of file hwacomp.cpp.

References isSetACME(), and PinStateHasChanged().

Referenced by GetACO().

◆ PinStateHasChanged()

void HWAcomp::PinStateHasChanged ( Pin p)
virtual

Get informed about input pin change.

Implements HasPinNotifyFunction.

Definition at line 141 of file hwacomp.cpp.

References ACI, ACIE, ACIS0, ACIS1, ACO, acsr, enabled, GetIn0(), GetIn1(), irqSystem, irqVec, and HWIrqSystem::SetIrqFlag().

Referenced by GetAcsr(), NotifySignalChanged(), set_from_reg(), and SetAcsr().

◆ Reset()

void HWAcomp::Reset ( void  )
virtual

Reset the unit.

Reimplemented from Hardware.

Definition at line 85 of file hwacomp.cpp.

References acme_sfior, ACO, acsr, enabled, GetIn0(), and GetIn1().

Referenced by GetAcsr(), and HWAcomp().

◆ set_from_reg()

unsigned char HWAcomp::set_from_reg ( const IOSpecialReg reg,
unsigned char  nv 
)
protectedvirtual

Informs your class, that a write access to IO register is happen

Parameters
regcaller register instance
nvthe value, which is written to IO register (but maybe changed by other clients)
Returns
nv, if nothing is changed or your changed value

Implements IOSpecialRegClient.

Definition at line 189 of file hwacomp.cpp.

References acme_sfior, and PinStateHasChanged().

◆ SetAcsr()

void HWAcomp::SetAcsr ( unsigned char  val)

Set method for ACSR register.

Definition at line 93 of file hwacomp.cpp.

References ACBG, ACD, ACI, ACIC, ACIE, ACO, acsr, HWIrqSystem::ClearIrqFlag(), enabled, irqSystem, irqVec, PinStateHasChanged(), BasicTimerUnit::SetACIC(), HWIrqSystem::SetIrqFlag(), timerA, timerB, and useBG.

Referenced by GetAcsr().

Member Data Documentation

◆ acme_sfior

bool HWAcomp::acme_sfior
protected

ACME flag in SFIOR register is set.

Definition at line 55 of file hwacomp.h.

Referenced by isSetACME(), Reset(), and set_from_reg().

◆ acsr

unsigned char HWAcomp::acsr
protected

ACSR register value.

Definition at line 57 of file hwacomp.h.

Referenced by ClearIrqFlag(), GetAcsr(), GetIn0(), PinStateHasChanged(), Reset(), and SetAcsr().

◆ acsr_reg

◆ ad

HWAd* HWAcomp::ad
protected

connection to ADC for analog input mux. NULL, if not available

Definition at line 61 of file hwacomp.h.

Referenced by GetIn1(), HWAcomp(), isSetACME(), and ~HWAcomp().

◆ enabled

bool HWAcomp::enabled
protected

analog comparator is enabled

Definition at line 56 of file hwacomp.h.

Referenced by PinStateHasChanged(), Reset(), and SetAcsr().

◆ irqSystem

HWIrqSystem* HWAcomp::irqSystem
protected

connection to IRQ controller

Definition at line 49 of file hwacomp.h.

Referenced by ClearIrqFlag(), HWAcomp(), PinStateHasChanged(), and SetAcsr().

◆ irqVec

unsigned int HWAcomp::irqVec
protected

stores the IRQ vector number

Definition at line 58 of file hwacomp.h.

Referenced by ClearIrqFlag(), HWAcomp(), PinStateHasChanged(), and SetAcsr().

◆ pinAin0

PinAtPort HWAcomp::pinAin0
protected

port pin AIN0

Definition at line 50 of file hwacomp.h.

Referenced by GetIn0().

◆ pinAin1

PinAtPort HWAcomp::pinAin1
protected

port pin AIN1

Definition at line 51 of file hwacomp.h.

Referenced by GetIn1().

◆ sfior

IOSpecialReg* HWAcomp::sfior
protected

connection to SFIOR register, if necessary. NULL, if not used

Definition at line 62 of file hwacomp.h.

Referenced by HWAcomp(), and isSetACME().

◆ timerA

BasicTimerUnit* HWAcomp::timerA
protected

connection to timerA for input capture event. NULL, if not available

Definition at line 59 of file hwacomp.h.

Referenced by HWAcomp(), and SetAcsr().

◆ timerB

BasicTimerUnit* HWAcomp::timerB
protected

connection to timerB for input capture event. NULL, if not available

Definition at line 60 of file hwacomp.h.

Referenced by HWAcomp(), and SetAcsr().

◆ useBG

bool HWAcomp::useBG
protected

has ADBG register bit and can switch In0 to bandgap ref

Definition at line 54 of file hwacomp.h.

Referenced by GetIn0(), and SetAcsr().

◆ v_bg

Pin* HWAcomp::v_bg
protected

get access to bandgap reference

Definition at line 52 of file hwacomp.h.

Referenced by GetIn0(), and HWAcomp().

◆ v_cc

Pin* HWAcomp::v_cc
protected

get access to voltage supply level

Definition at line 53 of file hwacomp.h.

Referenced by GetIn0(), GetIn1(), and HWAcomp().


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