|
|
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 root 114: // 32Hz クロック入力
1.1.1.3 root 115: void ClockIn() override;
1.1 root 116:
1.1.1.3 root 117: protected:
118: // BusIO インタフェース
119: static const uint32 NPORT = 16;
1.1.1.7 root 120: uint64 Read(uint32 offset);
121: uint64 Write(uint32 offset, uint32 data);
122: uint64 Peek(uint32 offset);
1.1.1.2 root 123:
1.1.1.3 root 124: private:
1.1 root 125: // レジスタを更新
126: void UpdateReg(uint32);
127:
1.1.1.9 ! root 128: DECLARE_MONITOR_CALLBACK(MonitorUpdate);
! 129:
1.1 root 130: // レジスタ
131: RP5C15 reg {};
132:
133: // 現在のバンク
134: // MODE レジスタの BANK ビットが変更された時にこの値も更新すること。
1.1.1.5 root 135: int bank {};
1.1 root 136:
137: // CLKOUT 端子の状態 (true なら 'H')
1.1.1.5 root 138: bool clkout {};
1.1 root 139: // ALARM 端子の状態 (true なら 'H')
1.1.1.5 root 140: bool alarmout {};
1.1.1.9 ! root 141:
! 142: Monitor monitor { this };
1.1 root 143: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.