sim_vref.h Source File

yasimavr: sim_vref.h Source File
yasimavr
Loading...
Searching...
No Matches
sim_vref.h
Go to the documentation of this file.
1/*
2 * sim_vref.h
3 *
4 * Copyright 2021-2024 Clement Savergne <csavergne@yahoo.com>
5
6 This file is part of yasim-avr.
7
8 yasim-avr is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 yasim-avr is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with yasim-avr. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22//=======================================================================================
23
24#ifndef __YASIMAVR_VREF_H__
25#define __YASIMAVR_VREF_H__
26
27#include "../core/sim_peripheral.h"
28#include "../core/sim_types.h"
29
31
32
33//=======================================================================================
51#define AVR_CTLREQ_VREF_GET (AVR_CTLREQ_BASE + 1)
52
59#define AVR_CTLREQ_VREF_SET (AVR_CTLREQ_BASE + 2)
60
63
64
65//=======================================================================================
73
74public:
75
83
100
101 explicit VREF(unsigned int ref_count);
102
103 bool active() const;
104
105 virtual bool ctlreq(ctlreq_id_t req, ctlreq_data_t* data) override;
106
107protected:
108
109 void set_reference(unsigned int index, Source source, double voltage=1.0);
110 double reference(unsigned int index) const;
111
112private:
113
114 double m_vcc;
115 double m_aref;
116 DataSignal m_signal;
117
118 struct ref_t {
119 double value;
120 bool relative;
121 };
122
123 std::vector<ref_t> m_references;
124
125};
126
127inline bool VREF::active() const
128{
129 return m_vcc;
130}
131
132
134
135#endif //__YASIMAVR_VREF_H__
Definition sim_signal.h:137
Abstract class defining a framework for MCU peripherals.
Definition sim_peripheral.h:286
virtual bool ctlreq(ctlreq_id_t req, ctlreq_data_t *data)
Definition sim_peripheral.cpp:79
Generic model for managing VREF for analog peripherals (ADC, analog comparator)
Definition sim_vref.h:72
SignalId
Definition sim_vref.h:84
@ Signal_VCCChange
Definition sim_vref.h:98
@ Signal_IntRefChange
Definition sim_vref.h:93
@ Signal_ARefChange
Definition sim_vref.h:88
Source
Enumation value for the sources of voltage references.
Definition sim_vref.h:77
@ Source_Internal
Internal reference voltage value.
Definition sim_vref.h:81
@ Source_AREF
AREF voltage value.
Definition sim_vref.h:80
@ Source_VCC
VCC voltage value.
Definition sim_vref.h:78
@ Source_AVCC
AVCC voltage value (always equal to VCC for now)
Definition sim_vref.h:79
bool active() const
Definition sim_vref.h:127
int ctlreq_id_t
Definition sim_peripheral.h:111
#define YASIMAVR_BEGIN_NAMESPACE
Definition sim_globals.h:58
#define AVR_CORE_PUBLIC_API
Definition sim_globals.h:46
#define YASIMAVR_END_NAMESPACE
Definition sim_globals.h:59
Definition sim_peripheral.h:237