Annotation of nono/vm/rp5c15.h, revision 1.1.1.15

1.1       root        1: //
                      2: // nono
1.1.1.3   root        3: // Copyright (C) 2020 nono project
                      4: // Licensed under nono-license.txt
1.1       root        5: //
                      6: 
1.1.1.11  root        7: //
                      8: // RTC (RP5C15)
                      9: //
                     10: 
1.1       root       11: #pragma once
                     12: 
                     13: #include "rtc.h"
1.1.1.14  root       14: #include "monitor.h"
1.1       root       15: 
1.1.1.13  root       16: class MFPDevice;
1.1.1.14  root       17: class X68030PowerDevice;
1.1.1.13  root       18: 
1.1       root       19: struct RP5C15
                     20: {
                     21:        // レジスタ 13, 14, 15 は Bank0/Bank1 どちらも同じものが見える。
                     22:        // これらのレジスタは Bank1 だったら Bank0 を見せる。
                     23:        //
                     24:        // RTC の未使用ビットは、RTC への書き込み時に未使用ビットを
                     25:        // mask[] で '0' にマスクしてから変数に書き込むこと。
                     26:        union {
                     27:                uint8 r[16 + 13];
                     28:                struct {
                     29:                        uint8 sec1;
                     30:                        uint8 sec10;
                     31:                        uint8 min1;
                     32:                        uint8 min10;
                     33:                        uint8 hour1;
                     34:                        uint8 hour10;
                     35:                        uint8 wday;
                     36:                        uint8 day1;
                     37:                        uint8 day10;
                     38:                        uint8 mon1;
                     39:                        uint8 mon10;
                     40:                        uint8 year1;
                     41:                        uint8 year10;
                     42:                        uint8 mode;
                     43:                        uint8 test;
                     44:                        uint8 reset;
                     45: 
                     46:                        uint8 clksel;
                     47:                        uint8 adjust;
                     48:                        uint8 alarm_min1;
                     49:                        uint8 alarm_min10;
                     50:                        uint8 alarm_hour1;
                     51:                        uint8 alarm_hour10;
                     52:                        uint8 alarm_wday;
                     53:                        uint8 alarm_day1;
                     54:                        uint8 alarm_day10;
                     55:                        uint8 padding1;
                     56:                        uint8 sel24;
                     57:                        uint8 leap;
                     58:                        uint8 padding2;
                     59:                } __packed;
                     60:        };
                     61: 
                     62:        // レジスタマスク (有効ビットを '1' としたもの)
                     63:        static const uint8 mask[16 + 13];
                     64: 
                     65:        // バンク0
1.1.1.15! root       66:        static const uint SEC1                  = 0x00; // $E8A001
        !            67:        static const uint SEC10                 = 0x01; // $E8A003
        !            68:        static const uint MIN1                  = 0x02; // $E8A005
        !            69:        static const uint MIN10                 = 0x03; // $E8A007
        !            70:        static const uint HOUR1                 = 0x04; // $E8A009
        !            71:        static const uint HOUR10                = 0x05; // $E8A00B
        !            72:        static const uint WDAY                  = 0x06; // $E8A00D
        !            73:        static const uint DAY1                  = 0x07; // $E8A00F
        !            74:        static const uint DAY10                 = 0x08; // $E8A011
        !            75:        static const uint MON1                  = 0x09; // $E8A013
        !            76:        static const uint MON10                 = 0x0a; // $E8A015
        !            77:        static const uint YEAR1                 = 0x0b; // $E8A017
        !            78:        static const uint YEAR10                = 0x0c; // $E8A019
        !            79:        static const uint MODE                  = 0x0d; // $E8A01B
        !            80:        static const uint TEST                  = 0x0e; // $E8A01D
        !            81:        static const uint RESET                 = 0x0f; // $E8A01F
1.1       root       82:        // バンク1
1.1.1.15! root       83:        static const uint CLKSEL                = 0x10; // $E8A001
        !            84:        static const uint ADJUST                = 0x11; // $E8A003
        !            85:        static const uint ALARM_MIN1    = 0x12; // $E8A005
        !            86:        static const uint ALARM_MIN10   = 0x13; // $E8A007
        !            87:        static const uint ALARM_HOUR1   = 0x14; // $E8A009
        !            88:        static const uint ALARM_HOUR10  = 0x15; // $E8A00B
        !            89:        static const uint ALARM_WDAY    = 0x16; // $E8A00D
        !            90:        static const uint ALARM_DAY1    = 0x17; // $E8A00F
        !            91:        static const uint ALARM_DAY10   = 0x18; // $E8A011
        !            92:        static const uint notused1              = 0x19; // $E8A013
        !            93:        static const uint SEL24                 = 0x1a; // $E8A015
        !            94:        static const uint LEAP                  = 0x1b; // $E8A017
        !            95:        static const uint notused2              = 0x1c; // $E8A019
1.1       root       96:        // バンク1 の 13, 14, 15 はバンク0 と共通
1.1.1.15! root       97:        static const uint MODE_BANK1    = 0x1d; // $E8A01B
        !            98:        static const uint TEST_BANK1    = 0x1e; // $E8A01D
        !            99:        static const uint RESET_BANK1   = 0x1f; // $E8A01F
        !           100: 
        !           101:        static const uint MODE_TIMER_EN = 0x08;
        !           102:        static const uint MODE_ALARM_EN = 0x04;
        !           103:        static const uint MODE_BANK             = 0x01;
        !           104: 
        !           105:        static const uint RESET_1Hz             = 0x08;
        !           106:        static const uint RESET_16Hz    = 0x04;
        !           107:        static const uint RESET_TIMER   = 0x02;
        !           108:        static const uint RESET_ALARM   = 0x01;
1.1       root      109: };
                    110: 
                    111: class RP5C15Device : public RTCDevice
                    112: {
1.1.1.3   root      113:        using inherited = RTCDevice;
1.1       root      114:  public:
                    115:        RP5C15Device();
1.1.1.14  root      116:        ~RP5C15Device() override;
1.1       root      117: 
1.1.1.8   root      118:        bool Init() override;
1.1.1.4   root      119: 
1.1.1.10  root      120:        uint GetSec() const override;   // 秒(0-59)
                    121:        uint GetMin() const override;   // 分(0-59)
                    122:        uint GetHour() const override;  // 時(0-23)
                    123:        uint GetWday() const override;  // 曜日(0が日曜)
                    124:        uint GetMday() const override;  // 日(1-31)
                    125:        uint GetMon() const override;   // 月(1-12)
                    126:        uint GetYear() const override;  // 年(西暦)
                    127:        uint GetLeap() const override;  // うるう年カウンタ(0..3)
1.1       root      128: 
1.1.1.3   root      129:  protected:
                    130:        // BusIO インタフェース
                    131:        static const uint32 NPORT = 16;
1.1.1.15! root      132:        busdata ReadPort(uint32 offset);
        !           133:        busdata WritePort(uint32 offset, uint32 data);
        !           134:        busdata PeekPort(uint32 offset);
        !           135:        bool PokePort(uint32 offset, uint32 data);
1.1.1.2   root      136: 
1.1.1.10  root      137:        // 仮想 RTC からのクロック
                    138:        void Tick32Hz() override;
                    139:        void Tick2Hz() override;
                    140:        void Tick1Hz() override;
                    141: 
                    142:        void SetSec(uint v) override;
                    143:        void SetMin(uint v) override;
                    144:        void SetHour(uint v) override;
                    145:        void SetWday(uint v) override;
                    146:        void SetMday(uint v) override;
                    147:        void SetMon(uint v) override;
                    148:        void SetYear(uint v) override;
                    149:        void SetLeap(uint v) override;
                    150: 
1.1.1.3   root      151:  private:
1.1.1.12  root      152:        void ChangeAlarmOut();
1.1       root      153: 
1.1.1.9   root      154:        DECLARE_MONITOR_CALLBACK(MonitorUpdate);
                    155: 
1.1       root      156:        // レジスタ
                    157:        RP5C15 reg {};
                    158: 
                    159:        // CLKOUT 端子の状態 (true なら 'H')
1.1.1.5   root      160:        bool clkout {};
1.1.1.10  root      161: 
                    162:        // 分周段から秒カウンタへのカウントアップホールド内部信号。
                    163:        bool clock_hold {};
                    164: 
                    165:        // CLKOUT 1/60Hz 用の 60秒カウンタ。カレンダとは独立。
                    166:        uint32 cnt_60sec {};
                    167: 
1.1.1.12  root      168:        // アラーム端子出力。
                    169:        // ALARM 端子は負論理(Low active) だが、ここでは
                    170:        // アサート(L) のとき true とする。
                    171:        bool alarm_out {};
                    172: 
1.1.1.10  root      173:        // 内部アラーム 16Hz 信号。CLKOUT、alarm_1Hz とは独立。
                    174:        bool alarm_16Hz {};
                    175:        // 内部アラーム 1Hz 信号。CLKOUT、alarm_16Hz とは独立。
                    176:        bool alarm_1Hz {};
                    177:        // アラーム時刻一致信号。
                    178:        // XXX アラーム機能自体は未実装。
                    179:        bool alarm_on {};
1.1.1.9   root      180: 
1.1.1.13  root      181:        MFPDevice *mfp {};
1.1.1.14  root      182:        X68030PowerDevice *power {};
1.1.1.13  root      183: 
1.1.1.9   root      184:        Monitor monitor { this };
1.1       root      185: };

unix.superglobalmegacorp.com

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