arch_avr_twi.h Source File

yasimavr: arch_avr_twi.h Source File
yasimavr
Loading...
Searching...
No Matches
arch_avr_twi.h
Go to the documentation of this file.
1/*
2 * arch_avr_twi.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#ifndef __YASIMAVR_AVR_TWI_H__
25#define __YASIMAVR_AVR_TWI_H__
26
27#include "arch_avr_globals.h"
28#include "core/sim_peripheral.h"
29#include "core/sim_interrupt.h"
30
32
33
34//=======================================================================================
61
67
68public:
69
70 ArchAVR_TWI(uint8_t num, const ArchAVR_TWIConfig& config);
71 virtual ~ArchAVR_TWI();
72
73 virtual bool init(Device& device) override;
74 virtual void reset(int flags) override;
75 virtual bool ctlreq(ctlreq_id_t req, ctlreq_data_t *data) override;
76 virtual void ioreg_write_handler(reg_addr_t addr, const ioreg_write_t& data) override;
77
78private:
79
80 class _Client;
81 friend class _Client;
82 class _Host;
83 friend class _Host;
84 class _PinDriver;
85 friend class _PinDriver;
86
87 const ArchAVR_TWIConfig& m_config;
88
89 _Client* m_client;
90 _Host* m_host;
91 _PinDriver* m_driver;
94 bool m_gencall;
95 bool m_latched_ack;
96
97 InterruptFlag m_intflag;
98
99 void host_signal_raised(const signal_data_t& sigdata, int hooktag);
100 void client_signal_raised(const signal_data_t& sigdata, int hooktag);
101 void execute_command(bool sta, bool sto);
102 void raise_flag_and_status(uint8_t status);
103 void clear_flag_and_status();
104 bool address_match(uint8_t addr_rw);
105
106};
107
108
110
111#endif //__YASIMAVR_AVR_TWI_H__
#define AVR_ARCHAVR_PUBLIC_API
Definition arch_avr_globals.h:46
Definition arch_avr_twi.cpp:129
Definition arch_avr_twi.cpp:107
Definition arch_avr_twi.cpp:80
Implementation of a TWI model for the AVR series.
Definition arch_avr_twi.h:66
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 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
bit spec structure. Represent a field in a I/O register. It works the same as bitmask_t except used b...
Definition sim_types.h:287
Representation of a I/O register address, with validity state.
Definition sim_types.h:60
Represents a field in a I/O register with address.
Definition sim_types.h:348
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
short int_vect_t
Definition sim_types.h:43
Configuration structure for ArchAVR_TWI.
Definition arch_avr_twi.h:39
bitspec_t bs_stop
Definition arch_avr_twi.h:46
regbit_t rb_status
Definition arch_avr_twi.h:52
regbit_t rb_addr_mask
Definition arch_avr_twi.h:57
bitspec_t bs_start
Definition arch_avr_twi.h:45
bitspec_t bs_ack_enable
Definition arch_avr_twi.h:49
bitspec_t bs_enable
Definition arch_avr_twi.h:44
bitspec_t bs_int_enable
Definition arch_avr_twi.h:47
regbit_t rb_gencall_enable
Definition arch_avr_twi.h:56
regbit_t rb_addr
Definition arch_avr_twi.h:55
reg_addr_t reg_data
Definition arch_avr_twi.h:54
regbit_t rb_prescaler
Definition arch_avr_twi.h:53
std::vector< unsigned long > ps_factors
Definition arch_avr_twi.h:41
bitspec_t bs_int_flag
Definition arch_avr_twi.h:48
reg_addr_t reg_ctrl
Definition arch_avr_twi.h:43
int_vect_t iv_twi
Definition arch_avr_twi.h:58
reg_addr_t reg_bitrate
Definition arch_avr_twi.h:51
Definition sim_peripheral.h:237
Definition sim_ioreg.h:39
Definition sim_signal.h:39