openMSX
I8251.hh
Go to the documentation of this file.
1// This class implements the Intel 8251 chip (UART)
2
3#ifndef I8251_HH
4#define I8251_HH
5
6#include "ClockPin.hh"
8#include "Schedulable.hh"
9#include "serialize_meta.hh"
10#include "openmsx.hh"
11#include "outer.hh"
12
13namespace openmsx {
14
16{
17public:
18 virtual void setRxRDY(bool status, EmuTime::param time) = 0;
19 virtual void setDTR(bool status, EmuTime::param time) = 0;
20 virtual void setRTS(bool status, EmuTime::param time) = 0;
21
22 [[nodiscard]] virtual bool getDSR(EmuTime::param time) = 0;
23 [[nodiscard]] virtual bool getCTS(EmuTime::param time) = 0; // TODO use this
24 virtual void signal(EmuTime::param time) = 0;
25
26protected:
27 I8251Interface() = default;
28 ~I8251Interface() = default;
29};
30
31class I8251 final : public SerialDataInterface
32{
33public:
34 I8251(Scheduler& scheduler, I8251Interface& interface, EmuTime::param time);
35
36 void reset(EmuTime::param time);
37 [[nodiscard]] byte readIO(word port, EmuTime::param time);
38 [[nodiscard]] byte peekIO(word port, EmuTime::param time) const;
39 void writeIO(word port, byte value, EmuTime::param time);
40 [[nodiscard]] ClockPin& getClockPin() { return clock; }
41 [[nodiscard]] bool isRecvReady() const { return recvReady; }
42 [[nodiscard]] bool isRecvEnabled() const;
43
44 // SerialDataInterface
45 void setDataBits(DataBits bits) override { recvDataBits = bits; }
46 void setStopBits(StopBits bits) override { recvStopBits = bits; }
47 void setParityBit(bool enable, Parity parity) override;
48 void recvByte(byte value, EmuTime::param time) override;
49
50 void execRecv(EmuTime::param time);
51 void execTrans(EmuTime::param time);
52
53 template<typename Archive>
54 void serialize(Archive& ar, unsigned version);
55
56 // public for serialize
57 enum class CmdPhase {
59 };
60
61private:
62 void setMode(byte newMode);
63 void writeCommand(byte value, EmuTime::param time);
64 [[nodiscard]] byte readStatus(EmuTime::param time);
65 [[nodiscard]] byte readTrans(EmuTime::param time);
66 void writeTrans(byte value, EmuTime::param time);
67 void send(byte value, EmuTime::param time);
68
69private:
70 // Schedulable
71 struct SyncRecv final : Schedulable {
72 friend class I8251;
73 explicit SyncRecv(Scheduler& s) : Schedulable(s) {}
74 void executeUntil(EmuTime::param time) override {
75 auto& i8251 = OUTER(I8251, syncRecv);
76 i8251.execRecv(time);
77 }
78 } syncRecv;
79 struct SyncTrans final : Schedulable {
80 friend class I8251;
81 explicit SyncTrans(Scheduler& s) : Schedulable(s) {}
82 void executeUntil(EmuTime::param time) override {
83 auto& i8251 = OUTER(I8251, syncTrans);
84 i8251.execTrans(time);
85 }
86 } syncTrans;
87
88 I8251Interface& interface;
89 ClockPin clock;
90 unsigned charLength;
91
92 CmdPhase cmdPhase;
95 SerialDataInterface::Parity recvParityBit;
96 bool recvParityEnabled;
97 byte recvBuf;
98 bool recvReady;
99
100 byte sendByte;
101 byte sendBuffer;
102
103 byte status;
104 byte command;
105 byte mode;
106 byte sync1, sync2;
107};
109
110} // namespace openmsx
111
112#endif
virtual bool getDSR(EmuTime::param time)=0
virtual void setRxRDY(bool status, EmuTime::param time)=0
virtual void setDTR(bool status, EmuTime::param time)=0
virtual bool getCTS(EmuTime::param time)=0
virtual void setRTS(bool status, EmuTime::param time)=0
virtual void signal(EmuTime::param time)=0
byte peekIO(word port, EmuTime::param time) const
Definition I8251.cc:86
void setStopBits(StopBits bits) override
Definition I8251.hh:46
bool isRecvReady() const
Definition I8251.hh:41
void recvByte(byte value, EmuTime::param time) override
Definition I8251.cc:264
ClockPin & getClockPin()
Definition I8251.hh:40
void execRecv(EmuTime::param time)
Definition I8251.cc:297
void writeIO(word port, byte value, EmuTime::param time)
Definition I8251.cc:96
void reset(EmuTime::param time)
Definition I8251.cc:55
void setDataBits(DataBits bits) override
Definition I8251.hh:45
void execTrans(EmuTime::param time)
Definition I8251.cc:304
byte readIO(word port, EmuTime::param time)
Definition I8251.cc:77
void setParityBit(bool enable, Parity parity) override
Definition I8251.cc:258
void serialize(Archive &ar, unsigned version)
Definition I8251.cc:351
bool isRecvEnabled() const
Definition I8251.cc:282
Every class that wants to get scheduled at some point must inherit from this class.
Schedulable(const Schedulable &)=delete
This file implemented 3 utility functions:
Definition Autofire.cc:11
uint16_t word
16 bit unsigned integer
Definition openmsx.hh:29
#define OUTER(type, member)
Definition outer.hh:42
#define SERIALIZE_CLASS_VERSION(CLASS, VERSION)