VREF Class Reference

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

Generic model for managing VREF for analog peripherals (ADC, analog comparator) More...

#include <sim_vref.h>

Inheritance diagram for VREF:
Peripheral IORegHandler ArchAVR_VREF ArchXT_VREF

Public Types

enum  Source { Source_VCC , Source_AVCC , Source_AREF , Source_Internal }
 Enumation value for the sources of voltage references. More...
 
enum  SignalId { Signal_ARefChange , Signal_IntRefChange , Signal_VCCChange }
 

Public Member Functions

 VREF (unsigned int ref_count)
 
bool active () const
 
virtual bool ctlreq (ctlreq_id_t req, ctlreq_data_t *data) override
 
- Public Member Functions inherited from Peripheral
 Peripheral (ctl_id_t id)
 
virtual ~Peripheral ()
 
ctl_id_t id () const
 Unique identifier of the peripheral.
 
std::string name () const
 The name of the peripheral.
 
virtual bool init (Device &device)
 
virtual void reset (int flags)
 
virtual uint8_t ioreg_read_handler (reg_addr_t addr, uint8_t value) override
 
virtual uint8_t ioreg_peek_handler (reg_addr_t addr, uint8_t value) override
 
virtual void ioreg_write_handler (reg_addr_t addr, const ioreg_write_t &data) override
 
virtual void sleep (bool on, SleepMode mode)
 
 Peripheral (const Peripheral &)=delete
 
Peripheraloperator= (const Peripheral &)=delete
 
- Public Member Functions inherited from IORegHandler
virtual ~IORegHandler ()=default
 

Protected Member Functions

void set_reference (unsigned int index, Source source, double voltage=1.0)
 
double reference (unsigned int index) const
 
- Protected Member Functions inherited from Peripheral
Devicedevice () const
 Access to the device. It is null before init() is called.
 
Loggerlogger ()
 Logging object associated with this peripheral.
 
bool register_interrupt (int_vect_t vector, InterruptHandler &handler) const
 
Signalget_signal (ctl_id_t ctl_id) const
 
void add_ioreg (const regmask_t &rm, IORegister::BitMode bitmode=IORegister::RW)
 
void add_ioreg (const regbit_compound_t &rbc, IORegister::BitMode bitmode=IORegister::RW)
 
void add_ioreg (reg_addr_t addr, IORegister::BitMode bitmode=IORegister::RW)
 
void add_ioreg (reg_addr_t addr, bitmask_t mask, IORegister::BitMode bitmode=IORegister::RW)
 
uint8_t read_ioreg (const regbit_t &rb) const
 
uint64_t read_ioreg (const regbit_compound_t &rbc) const
 
uint8_t read_ioreg (reg_addr_t addr) const
 
uint8_t read_ioreg (reg_addr_t addr, const bitspec_t &bs) const
 
bool test_ioreg (const regbit_t &rb) const
 
bool test_ioreg (const regbit_compound_t &rbc) const
 
bool test_ioreg (reg_addr_t addr, const bitspec_t &bs) const
 
bool test_ioreg (reg_addr_t addr, bitmask_t bm=0xFF) const
 
void write_ioreg (reg_addr_t addr, bitmask_t bm, uint8_t value)
 
void write_ioreg (const regbit_t &rb, uint8_t value)
 
void write_ioreg (const regbit_compound_t &rbc, uint64_t value)
 
void write_ioreg (reg_addr_t addr, uint8_t value)
 
void write_ioreg (reg_addr_t addr, const bitspec_t &bs, uint8_t value)
 
void set_ioreg (reg_addr_t addr, bitmask_t bm=0xFF)
 
void set_ioreg (const regbit_t &rb)
 
void set_ioreg (const regbit_compound_t &rbc)
 
void set_ioreg (reg_addr_t addr, const bitspec_t &bs)
 
void clear_ioreg (reg_addr_t addr, bitmask_t bm=0xFF)
 
void clear_ioreg (const regbit_t &rb)
 
void clear_ioreg (const regbit_compound_t &rbc)
 
void clear_ioreg (reg_addr_t addr, const bitspec_t &bs)
 

Detailed Description

Generic model for managing VREF for analog peripherals (ADC, analog comparator)

Note
Setting VCC in the firmware is required for using any analog feature of a MCU. Failing to do so will trigger a device crash.

Member Enumeration Documentation

◆ SignalId

Enumerator
Signal_ARefChange 

Raised when the AREF reference value is changed. data carries the new value (absolute)

Signal_IntRefChange 

Raised when an internal reference value is changed. data carries the new value (relative to VCC) and index the reference index.

Signal_VCCChange 

Raised when VCC value is changed. data carries the new value (absolute)

◆ Source

Enumation value for the sources of voltage references.

Enumerator
Source_VCC 

VCC voltage value.

Source_AVCC 

AVCC voltage value (always equal to VCC for now)

Source_AREF 

AREF voltage value.

Source_Internal 

Internal reference voltage value.

Constructor & Destructor Documentation

◆ VREF()

YASIMAVR_USING_NAMESPACE VREF::VREF ( unsigned int  ref_count)
explicit

Member Function Documentation

◆ active()

bool VREF::active ( ) const
inline

◆ ctlreq()

bool VREF::ctlreq ( ctlreq_id_t  req,
ctlreq_data_t data 
)
overridevirtual

Virtual method called for a CTL request. The method must return true if the request has been processed.

Reimplemented from Peripheral.

◆ reference()

double VREF::reference ( unsigned int  index) const
protected

Returns a voltage reference value.

The value returned is always relative to VCC, even if set with an absolute value.
The value is also constrained to the range [0; VCC].
If index is out of range or VCC is not set, 0.0 is returned.

◆ set_reference()

void VREF::set_reference ( unsigned int  index,
Source  source,
double  voltage = 1.0 
)
protected

Set a voltage reference value

Parameters
indexchannel index of the reference
sourcesource of the reference
voltageValue of the reference (optional, default value is 1.0)

If source is VCC or AVCC, the voltage value is ignored (it is by definition 1.0).
If source is AREF, voltage must be a value relative to VCC/AVCC.
If source is Internal, voltage must be an absolute value in Volts.


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