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

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

unix.superglobalmegacorp.com

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