sim_port.h Source File

yasimavr: sim_port.h Source File
yasimavr
Loading...
Searching...
No Matches
sim_port.h
Go to the documentation of this file.
1/*
2 * sim_port.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_IO_PORT_H__
25#define __YASIMAVR_IO_PORT_H__
26
27#include "../core/sim_peripheral.h"
28#include "../core/sim_types.h"
29#include "../core/sim_pin.h"
30
32
33
34//=======================================================================================
53
54public:
55
56 explicit Port(char name);
57
58 virtual bool init(Device& device) override;
59 virtual void reset(int flags) override;
60 virtual bool ctlreq(ctlreq_id_t req, ctlreq_data_t* data) override;
61
62protected:
63
64 bitmask_t pin_mask() const;
65 Pin* pin(uint8_t num) const;
66 void set_pin_internal_state(uint8_t num, const Pin::controls_t& controls);
67
68 virtual void pin_state_changed(uint8_t num, Wire::StateEnum state);
69
70private:
71
72 const char m_name;
73 bitmask_t m_pinmask;
74 BoundFunctionSignalHook<Port> m_pin_signal_hook;
75 Signal m_signal;
76 Pin* m_pins[8];
77 uint8_t m_port_value;
78
79 void pin_signal_raised(const signal_data_t& sigdata, int hooktag);
80
81};
82
85{
86 return m_pinmask;
87}
88
89
90inline Pin* Port::pin(uint8_t num) const
91{
92 return m_pins[num];
93}
94
95
97
98#endif //__YASIMAVR_IO_PORT_H__
Definition sim_signal.h:227
Basic AVR device model.
Definition sim_device.h:61
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 reset(int flags)
Definition sim_peripheral.cpp:72
MCU pin model.
Definition sim_pin.h:49
Generic model for a GPIO port controller.
Definition sim_port.h:52
Pin * pin(uint8_t num) const
Definition sim_port.h:90
bitmask_t pin_mask() const
Returns the pin mask, containing a '1' for each existing pin.
Definition sim_port.h:84
Signalling framework class.
Definition sim_signal.h:97
StateEnum
Definition sim_wire.h:63
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_pin.h:56
Bit mask structure for bitwise operations on 8-bits registers.
Definition sim_types.h:86
Definition sim_peripheral.h:237
Definition sim_signal.h:39