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