Annotation of nono/hd64180/hd647180asci.h, revision 1.1.1.1

1.1       root        1: //
                      2: // nono
                      3: // Copyright (C) 2025 nono project
                      4: // Licensed under nono-license.txt
                      5: //
                      6: 
                      7: //
                      8: // HD647180 ASCI (非同期シリアル)
                      9: //
                     10: 
                     11: #pragma once
                     12: 
                     13: #include "device.h"
                     14: #include "event.h"
                     15: #include "message.h"
                     16: #include <array>
                     17: 
                     18: class HostCOMDevice;
                     19: class MPU64180Device;
                     20: 
                     21: class HD647180ASCIDevice : public Device
                     22: {
                     23:        using inherited = Device;
                     24: 
                     25:        // CNTLA0, CNTLA1
                     26:        static constexpr uint32 CNTL_MPE        = 0x80; // Multi Processor Enable
                     27:        static constexpr uint32 CNTL_RE         = 0x40; // Receive Enable
                     28:        static constexpr uint32 CNTL_TE         = 0x20; // Transmit Enable
                     29:        static constexpr uint32 CNTL_nRTS0      = 0x10; // !RequestToSend
                     30:        static constexpr uint32 CNTL_CKA1D      = 0x10; // CKA1 Disable
                     31:        static constexpr uint32 CNTL_EFR        = 0x08; // Error Flag Reset
                     32:        static constexpr uint32 CNTL_DATA8      = 0x04; // MODE2 (Data bits)
                     33:        static constexpr uint32 CNTL_PAREN      = 0x02; // MODE1 (Parity Enable)
                     34:        static constexpr uint32 CNTL_STOP2      = 0x01; // MODE0 (Stop bits)
                     35: 
                     36:        // CNTLB0, CNTLB1
                     37:        static constexpr uint32 CNTL_MPBT       = 0x80; // Multi Processor Bit Transmit
                     38:        static constexpr uint32 CNTL_MP         = 0x40; // Multi Processor
                     39:        static constexpr uint32 CNTL_nCTS       = 0x20; // R: !CTS
                     40:        static constexpr uint32 CNTL_PS         = 0x20; // W: PreScaler
                     41:        static constexpr uint32 CNTL_PEO        = 0x10; // Parity Even or Odd
                     42:        static constexpr uint32 CNTL_DR         = 0x08; // Divide Ratio
                     43:        static constexpr uint32 CNTL_SS         = 0x07; // Clock Source and Speed Select
                     44: 
                     45:        // STAT0, STAT1
                     46:        static constexpr uint32 STAT_RDRF       = 0x80; // Receive Data Register Full
                     47:        static constexpr uint32 STAT_OVRN       = 0x40; // Over Run Error
                     48:        static constexpr uint32 STAT_PE         = 0x20; // Parity Error
                     49:        static constexpr uint32 STAT_FE         = 0x10; // Framing Error
                     50:        static constexpr uint32 STAT_RIE        = 0x08; // Receive Interrupt Enable
                     51:        static constexpr uint32 STAT_nDCD0      = 0x04; // R: Data Carrier Detect
                     52:        static constexpr uint32 STAT_CTS1E      = 0x04; // W: !CTS Enable
                     53:        static constexpr uint32 STAT_TDRE       = 0x02; // Transmit Data Register Empty
                     54:        static constexpr uint32 STAT_TIE        = 0x01; // Transmit Interrupt Enable
                     55: 
                     56:        // 非同期シリアル1個分
                     57:        struct Channel {
                     58:                uint id;                // 0 or 1
                     59: 
                     60:                bool rx_enable;
                     61:                bool tx_enable;
                     62:                bool rx_intr_enable;
                     63:                bool tx_intr_enable;
                     64:                bool data8bit;  // MOD2
                     65:                bool parity_en; // MOD1
                     66:                bool stop2bit;  // MOD0
                     67:                bool parity_odd;
                     68:                bool prescale;
                     69:                bool divratio;
                     70:                uint8 ss;
                     71:                bool nCTS;
                     72:                bool overrun;
                     73: 
                     74:                uint8 tdr;
                     75:                bool tdr_empty;
                     76:                uint8 rdr;
                     77:                bool rdr_full;
                     78:                int32 tsr;              // 負数なら Empty。
                     79:                int32 rsr;              // 負数なら Empty。
                     80: 
                     81:                uint64 bit12_ns;
                     82:                uint32 baudrate;
                     83:        };
                     84: 
                     85:  public:
                     86:        HD647180ASCIDevice();
                     87:        ~HD647180ASCIDevice() override;
                     88: 
                     89:        bool Create() override;
                     90:        bool Init() override;
                     91:        void ResetHard(bool poweron) override;
                     92: 
                     93:        uint32 ReadCNTLA(uint n);
                     94:        uint32 ReadCNTLB(uint n);
                     95:        uint32 ReadSTAT(uint n);
                     96:        uint32 ReadTDR(uint n);
                     97:        uint32 ReadRDR(uint n);
                     98:        uint32 WriteCNTLA(uint n, uint32 data);
                     99:        uint32 WriteCNTLB(uint n, uint32 data);
                    100:        uint32 WriteSTAT(uint n, uint32 data);
                    101:        uint32 WriteTDR(uint n, uint32 data);
                    102:        uint32 WriteRDR(uint n, uint32 data);
                    103:        uint32 PeekCNTLA(uint n) const;
                    104:        uint32 PeekCNTLB(uint n) const;
                    105:        uint32 PeekSTAT(uint n) const;
                    106:        uint32 PeekTDR(uint n) const;
                    107:        uint32 PeekRDR(uint n) const;
                    108: 
                    109:  private:
                    110:        DECLARE_MONITOR_CALLBACK(MonitorUpdate);
                    111:        void MonitorUpdateChan(TextScreen&, int y, int n) const;
                    112: 
                    113:        void ChangeInterrupt(uint n);
                    114:        void ChangeBaudRate(uint n);
                    115: 
                    116:        void TxCallback(Event&);
                    117: 
                    118:        // 受信側
                    119:        void HostRxCallback(uint32);
                    120:        void RxMessage(MessageID, uint32);
                    121:        void RxCallback(Event&);
                    122:        bool Rx(uint n, uint32 data);
                    123: 
                    124:        // 入力クロックを 160分周した基本周波数とでもいうべきもの、
                    125:        // の 12ビット分を [nsec] にしたもの。
                    126:        uint64 xc12_ns {};
                    127: 
                    128:        std::array<Channel, 2> channels {};
                    129:        bool cts1_enable {};
                    130:        bool cka1_disable {};
                    131: 
                    132:        bool nRTS0 {};
                    133:        bool nDCD0 {};
                    134: 
                    135:        std::array<Event, 2> txevent {};
                    136:        std::array<Event, 2> rxevent {};
                    137: 
                    138:        std::array<std::unique_ptr<HostCOMDevice>, 2> hostcom /*{}*/;
                    139: 
                    140:        Monitor *monitor {};
                    141: 
                    142:        MPU64180Device *xp {};
                    143: };

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.