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

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

unix.superglobalmegacorp.com

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