arch_xt_adc.h Source File

yasimavr: arch_xt_adc.h Source File
yasimavr
Loading...
Searching...
No Matches
arch_xt_adc.h
Go to the documentation of this file.
1/*
2 * arch_xt_adc.h
3 *
4 * Copyright 2021-2026 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
25#ifndef __YASIMAVR_XT_ADC_H__
26#define __YASIMAVR_XT_ADC_H__
27
28#include "arch_xt_globals.h"
29#include "core/sim_interrupt.h"
33
35
36
37//=======================================================================================
38
44
48
50 std::vector<ADC::channel_config_t> channels;
52 std::vector<reference_config_t> references;
54 unsigned int vref_channel;
56 std::vector<unsigned long> clk_ps_factors;
58 unsigned long clk_ps_max;
60 std::vector<unsigned long> init_delays;
71
72};
73
90
91public:
92
93 ArchXT_ADC(int num, const ArchXT_ADCConfig& config);
94
95 virtual bool init(Device& device) override;
96 virtual void reset(int flags) override;
97 virtual bool ctlreq(ctlreq_id_t req, ctlreq_data_t* data) override;
98 virtual uint8_t ioreg_read_handler(reg_addr_t addr, uint8_t value) override;
99 virtual void ioreg_write_handler(reg_addr_t addr, const ioreg_write_t& data) override;
100 virtual void sleep(bool on, SleepMode mode) override;
101
102private:
103
104 enum State {
105 ADC_Disabled,
106 ADC_Idle,
107 ADC_Starting,
108 ADC_PendingConversion,
109 ADC_PendingRaise,
110 };
111
112 const ArchXT_ADCConfig& m_config;
113 State m_state;
114 bool m_first;
115 PrescaledTimer m_timer;
117 double m_temperature;
118 uint8_t m_latched_ch_mux;
119 uint8_t m_latched_ref_mux;
120 uint8_t m_accum_counter;
121 uint16_t m_result;
122 uint16_t m_win_lothres;
123 uint16_t m_win_hithres;
124 InterruptFlag m_res_intflag;
125 InterruptFlag m_cmp_intflag;
126 Signal m_signal;
127
128 void start_conversion_cycle();
129 void read_analog_value();
130 void timer_raised(const signal_data_t& sigdata, int hooktag);
131
132};
133
134
136
137#endif //__YASIMAVR_XT_ADC_H__
#define AVR_ARCHXT_PUBLIC_API
Definition arch_xt_globals.h:46
Implementation of an ADC for XT series.
Definition arch_xt_adc.h:89
Definition sim_signal.h:227
Basic AVR device model.
Definition sim_device.h:61
Generic helper to manage a typical Interrupt Flag/Enable in a I/O register.
Definition sim_interrupt.h:324
Abstract class defining a framework for MCU peripherals.
Definition sim_peripheral.h:286
virtual bool init(Device &device)
Definition sim_peripheral.cpp:60
virtual bool ctlreq(ctlreq_id_t req, ctlreq_data_t *data)
Definition sim_peripheral.cpp:79
virtual void sleep(bool on, SleepMode mode)
Definition sim_peripheral.cpp:125
virtual void ioreg_write_handler(reg_addr_t addr, const ioreg_write_t &data) override
Definition sim_peripheral.cpp:117
virtual uint8_t ioreg_read_handler(reg_addr_t addr, uint8_t value) override
Definition sim_peripheral.cpp:91
virtual void reset(int flags)
Definition sim_peripheral.cpp:72
Generic model of a Timer with prescaling.
Definition sim_timer.h:63
Signalling framework class.
Definition sim_signal.h:97
Source
Enumation value for the sources of voltage references.
Definition sim_vref.h:77
Representation of a I/O register address, with validity state.
Definition sim_types.h:60
int ctlreq_id_t
Definition sim_peripheral.h:111
#define YASIMAVR_BEGIN_NAMESPACE
Definition sim_globals.h:58
#define YASIMAVR_END_NAMESPACE
Definition sim_globals.h:59
SleepMode
Definition sim_sleep.h:49
short int_vect_t
Definition sim_types.h:43
Definition arch_xt_adc.h:45
VREF::Source source
Definition arch_xt_adc.h:46
Configuration structure for ArchXT_ADC.
Definition arch_xt_adc.h:43
int_vect_t iv_resready
Interrupt vector index for ADC_RESREADY.
Definition arch_xt_adc.h:64
std::vector< unsigned long > clk_ps_factors
List of the clock prescaler factors.
Definition arch_xt_adc.h:56
reg_addr_t reg_base
Base address for the peripheral I/O registers.
Definition arch_xt_adc.h:62
unsigned long clk_ps_max
Wrapping value for the ADC clock prescaler.
Definition arch_xt_adc.h:58
std::vector< ADC::channel_config_t > channels
List of the ADC channels.
Definition arch_xt_adc.h:50
int_vect_t iv_wincmp
Interrupt vector index for ADC_WINCMP.
Definition arch_xt_adc.h:66
std::vector< unsigned long > init_delays
List of conversion delay values.
Definition arch_xt_adc.h:60
std::vector< reference_config_t > references
List of the voltage references.
Definition arch_xt_adc.h:52
double temp_cal_25C
Temperature sensor calibration offset (in V at +25°C)
Definition arch_xt_adc.h:68
double temp_cal_coef
Temperature sensor calibration linear coef (in V/°C)
Definition arch_xt_adc.h:70
unsigned int vref_channel
Channel index for the voltage reference.
Definition arch_xt_adc.h:54
Definition sim_peripheral.h:252
Definition sim_peripheral.h:237
Definition sim_ioreg.h:39
Definition sim_signal.h:39