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, ParityBit parity) override;
48 void recvByte(byte value, EmuTime::param time) override;
49
50 // Schedulable
51 struct SyncRecv final : Schedulable {
52 friend class I8251;
53 explicit SyncRecv(Scheduler& s) : Schedulable(s) {}
54 void executeUntil(EmuTime::param time) override {
55 auto& i8251 = OUTER(I8251, syncRecv);
56 i8251.execRecv(time);
57 }
59 struct SyncTrans final : Schedulable {
60 friend class I8251;
61 explicit SyncTrans(Scheduler& s) : Schedulable(s) {}
62 void executeUntil(EmuTime::param time) override {
63 auto& i8251 = OUTER(I8251, syncTrans);
64 i8251.execTrans(time);
65 }
67 void execRecv(EmuTime::param time);
68 void execTrans(EmuTime::param time);
69
70 template<typename Archive>
71 void serialize(Archive& ar, unsigned version);
72
73 // public for serialize
77
78private:
79 void setMode(byte newMode);
80 void writeCommand(byte value, EmuTime::param time);
81 [[nodiscard]] byte readStatus(EmuTime::param time);
82 [[nodiscard]] byte readTrans(EmuTime::param time);
83 void writeTrans(byte value, EmuTime::param time);
84 void send(byte value, EmuTime::param time);
85
86private:
87 I8251Interface& interface;
88 ClockPin clock;
89 unsigned charLength;
90
91 CmdFaze cmdFaze;
95 bool recvParityEnabled;
96 byte recvBuf;
97 bool recvReady;
98
99 byte sendByte;
100 byte sendBuffer;
101
102 byte status;
103 byte command;
104 byte mode;
105 byte sync1, sync2;
106};
108
109} // namespace openmsx
110
111#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:261
ClockPin & getClockPin()
Definition I8251.hh:40
void execRecv(EmuTime::param time)
Definition I8251.cc:294
void setParityBit(bool enable, ParityBit parity) override
Definition I8251.cc:255
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
openmsx::I8251::SyncRecv syncRecv
void execTrans(EmuTime::param time)
Definition I8251.cc:301
byte readIO(word port, EmuTime::param time)
Definition I8251.cc:77
openmsx::I8251::SyncTrans syncTrans
void serialize(Archive &ar, unsigned version)
Definition I8251.cc:348
bool isRecvEnabled() const
Definition I8251.cc:279
Every class that wants to get scheduled at some point must inherit from this class.
This file implemented 3 utility functions:
Definition Autofire.cc:9
uint16_t word
16 bit unsigned integer
Definition openmsx.hh:29
#define OUTER(type, member)
Definition outer.hh:41
#define SERIALIZE_CLASS_VERSION(CLASS, VERSION)
void executeUntil(EmuTime::param time) override
When the previously registered syncPoint is reached, this method gets called.
Definition I8251.hh:54
SyncRecv(Scheduler &s)
Definition I8251.hh:53
SyncTrans(Scheduler &s)
Definition I8251.hh:61
void executeUntil(EmuTime::param time) override
When the previously registered syncPoint is reached, this method gets called.
Definition I8251.hh:62