arch_xt_acp.h Source File

yasimavr: arch_xt_acp.h Source File
yasimavr
Loading...
Searching...
No Matches
arch_xt_acp.h
Go to the documentation of this file.
1/*
2 * arch_xt_acp.h
3 *
4 * Copyright 2022-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_ACOMP_H__
26#define __YASIMAVR_XT_ACOMP_H__
27
28#include "arch_xt_globals.h"
31#include "core/sim_interrupt.h"
32#include "core/sim_pin.h"
33
35
36
37//=======================================================================================
42//Request to obtain the DAC output value
43#define AVR_CTLREQ_ACP_GET_DAC (AVR_CTLREQ_BASE + 1)
44
45
46//=======================================================================================
47
52
54 std::vector<ACP::channel_config_t> pos_channels;
56 std::vector<ACP::channel_config_t> neg_channels;
58 unsigned int vref_channel;
63
64};
65
80
81public:
82
83 ArchXT_ACP(int num, const ArchXT_ACPConfig& config);
84
85 virtual bool init(Device& device) override;
86 virtual void reset(int flags) override;
87 virtual bool ctlreq(ctlreq_id_t req, ctlreq_data_t* data) override;
88 virtual void ioreg_write_handler(reg_addr_t addr, const ioreg_write_t& data) override;
89 virtual void sleep(bool on, SleepMode mode) override;
90
91private:
92
93 const ArchXT_ACPConfig& m_config;
94 InterruptFlag m_intflag;
95 DataSignal m_signal;
96 //Pointer to the VREF signal to obtain ACP voltage reference updates
97 DataSignal* m_vref_signal;
98 DataSignalMux m_pos_mux;
99 DataSignalMux m_neg_mux;
101 //Boolean indicating if the peripheral is disabled by the current sleep mode
102 bool m_sleeping;
103 //Hysteresis value
104 double m_hysteresis;
105
106 bool register_channels(DataSignalMux& mux, const std::vector<ACP::channel_config_t>& channels);
107 void input_raised(const signal_data_t& sigdata, int hooktag);
108 void update_DAC();
109 void update_hysteresis();
110 void update_output();
111
112};
113
114
116
117#endif //__YASIMAVR_XT_ACOMP_H__
#define AVR_ARCHXT_PUBLIC_API
Definition arch_xt_globals.h:46
Implementation of an Analog Comparator for XT core series.
Definition arch_xt_acp.h:79
Definition sim_signal.h:227
Definition sim_signal.h:137
Definition sim_signal.h:169
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 void reset(int flags)
Definition sim_peripheral.cpp:72
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
Configuration structure for ArchXT_ACP.
Definition arch_xt_acp.h:51
unsigned int vref_channel
Channel index for the internal voltage reference.
Definition arch_xt_acp.h:58
std::vector< ACP::channel_config_t > pos_channels
List of the channels for the positive input.
Definition arch_xt_acp.h:54
std::vector< ACP::channel_config_t > neg_channels
List of the channels for the negative input.
Definition arch_xt_acp.h:56
int_vect_t iv_cmp
Interrupt vector index for the comparator output.
Definition arch_xt_acp.h:62
reg_addr_t reg_base
Base address for the peripheral I/O registers.
Definition arch_xt_acp.h:60
Definition sim_peripheral.h:237
Definition sim_ioreg.h:39
Definition sim_signal.h:39