arch_avr_usi.h Source File

yasimavr: arch_avr_usi.h Source File
yasimavr
Loading...
Searching...
No Matches
arch_avr_usi.h
Go to the documentation of this file.
1/*
2 * arch_avr_usi.h
3 *
4 * Copyright 2025-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_USI_H__
25#define __YASIMAVR_AVR_USI_H__
26
27#include "arch_avr_globals.h"
28#include "core/sim_interrupt.h"
29
31
32
33//=======================================================================================
34
58
59
67
68public:
69
70 explicit ArchAVR_USI(const ArchAVR_USIConfig& config);
71 virtual ~ArchAVR_USI();
72
73 virtual bool init(Device& device) override;
74 virtual void reset(int flags) override;
75 virtual void ioreg_write_handler(reg_addr_t addr, const ioreg_write_t& data) override;
76
77private:
78
79 class _PinDriver;
80 friend class _PinDriver;
81
82 const ArchAVR_USIConfig& m_config;
83
84 _PinDriver* m_driver;
85 int m_clk_mode;
86 int m_wire_mode;
87 bool m_start_detected;
88
89 InterruptFlag m_ovf_intflag;
90 InterruptFlag m_start_intflag;
91
92 DataSignal m_signal;
93
95
96 void timer_raised(const signal_data_t& sigdata, int hooktag);
97 void set_wire_mode(int new_mode, bool force);
98 bool output_latched() const;
99 void shift_data();
100 void update_data_output();
101 void inc_counter();
102 void clock_state_changed(bool dig_state);
103 void data_state_changed(bool dig_state);
104
105};
106
107
109
110#endif //__YASIMAVR_AVR_USI_H__
#define AVR_ARCHAVR_PUBLIC_API
Definition arch_avr_globals.h:46
Definition arch_avr_usi.cpp:61
Implementation of a Universal Serial Interface for AVR series.
Definition arch_avr_usi.h:66
Definition sim_signal.h:227
Definition sim_signal.h:137
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 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
Represents a field in a I/O register with address.
Definition sim_types.h:348
#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_USI.
Definition arch_avr_usi.h:39
regbit_t rb_start_inten
Start condition interrupt enable.
Definition arch_avr_usi.h:51
reg_addr_t reg_buffer
Data buffer register.
Definition arch_avr_usi.h:46
reg_addr_t reg_data
Data register.
Definition arch_avr_usi.h:45
regbit_t rb_clk_toggle
Clock toggle.
Definition arch_avr_usi.h:44
regbit_t rb_ovf_inten
Overflow interrupt enable.
Definition arch_avr_usi.h:49
regbit_t rb_clk_sel
Clock mode selection.
Definition arch_avr_usi.h:42
regbit_t rb_stop_flag
Stop condition flag.
Definition arch_avr_usi.h:52
regbit_t rb_clk_strobe
Clock strobe.
Definition arch_avr_usi.h:43
regbit_t rb_ovf_flag
Overflow flag.
Definition arch_avr_usi.h:48
regbit_t rb_counter
4-bits counter
Definition arch_avr_usi.h:47
int_vect_t iv_ovf
Overflow interrupt vector index.
Definition arch_avr_usi.h:54
regbit_t rb_start_flag
Start condition flag.
Definition arch_avr_usi.h:50
int_vect_t iv_start
Start condition interrupt vector index.
Definition arch_avr_usi.h:55
regbit_t rb_wiremode
Wire mode selection.
Definition arch_avr_usi.h:41
Definition sim_ioreg.h:39
Definition sim_signal.h:39