|
|
1.1 root 1: //
2: // nono
3: // Copyright (C) 2018 [email protected]
4: //
5:
6: #pragma once
7:
8: #include "device.h"
9: #include "rtc.h"
10:
11: struct RP5C15
12: {
13: // レジスタ 13, 14, 15 は Bank0/Bank1 どちらも同じものが見える。
14: // これらのレジスタは Bank1 だったら Bank0 を見せる。
15: //
16: // RTC の未使用ビットは、RTC への書き込み時に未使用ビットを
17: // mask[] で '0' にマスクしてから変数に書き込むこと。
18: union {
19: uint8 r[16 + 13];
20: struct {
21: uint8 sec1;
22: uint8 sec10;
23: uint8 min1;
24: uint8 min10;
25: uint8 hour1;
26: uint8 hour10;
27: uint8 wday;
28: uint8 day1;
29: uint8 day10;
30: uint8 mon1;
31: uint8 mon10;
32: uint8 year1;
33: uint8 year10;
34: uint8 mode;
35: uint8 test;
36: uint8 reset;
37:
38: uint8 clksel;
39: uint8 adjust;
40: uint8 alarm_min1;
41: uint8 alarm_min10;
42: uint8 alarm_hour1;
43: uint8 alarm_hour10;
44: uint8 alarm_wday;
45: uint8 alarm_day1;
46: uint8 alarm_day10;
47: uint8 padding1;
48: uint8 sel24;
49: uint8 leap;
50: uint8 padding2;
51: } __packed;
52: };
53:
54: // レジスタマスク (有効ビットを '1' としたもの)
55: static const uint8 mask[16 + 13];
56:
57: // バンク0
58: static const int SEC1 = 0x00; // $E8A001
59: static const int SEC10 = 0x01; // $E8A003
60: static const int MIN1 = 0x02; // $E8A005
61: static const int MIN10 = 0x03; // $E8A007
62: static const int HOUR1 = 0x04; // $E8A009
63: static const int HOUR10 = 0x05; // $E8A00B
64: static const int WDAY = 0x06; // $E8A00D
65: static const int DAY1 = 0x07; // $E8A00F
66: static const int DAY10 = 0x08; // $E8A011
67: static const int MON1 = 0x09; // $E8A013
68: static const int MON10 = 0x0a; // $E8A015
69: static const int YEAR1 = 0x0b; // $E8A017
70: static const int YEAR10 = 0x0c; // $E8A019
71: static const int MODE = 0x0d; // $E8A01B
72: static const int TEST = 0x0e; // $E8A01D
73: static const int RESET = 0x0f; // $E8A01F
74: // バンク1
75: static const int CLKSEL = 0x10; // $E8A001
76: static const int ADJUST = 0x11; // $E8A003
77: static const int ALARM_MIN1 = 0x12; // $E8A005
78: static const int ALARM_MIN10 = 0x13; // $E8A007
79: static const int ALARM_HOUR1 = 0x14; // $E8A009
80: static const int ALARM_HOUR10 = 0x15; // $E8A00B
81: static const int ALARM_WDAY = 0x16; // $E8A00D
82: static const int ALARM_DAY1 = 0x17; // $E8A00F
83: static const int ALARM_DAY10 = 0x18; // $E8A011
84: static const int notused1 = 0x19; // $E8A013
85: static const int SEL24 = 0x1a; // $E8A015
86: static const int LEAP = 0x1b; // $E8A017
87: static const int notused2 = 0x1c; // $E8A019
88: // バンク1 の 13, 14, 15 はバンク0 と共通
89: static const int MODE_BANK1 = 0x1d; // $E8A01B
90: static const int TEST_BANK1 = 0x1e; // $E8A01D
91: static const int RESET_BANK1 = 0x1f; // $E8A01F
92:
93: static const int MODE_TIMER_EN = 0x08;
94: static const int MODE_ALARM_EN = 0x04;
95: static const int MODE_BANK = 0x01;
96:
97: static const int RESET_1Hz = 0x08;
98: static const int RESET_16Hz = 0x04;
99: static const int RESET_TIMER = 0x02;
100: static const int RESET_ALARM = 0x01;
101: };
102:
103: class RP5C15Device : public RTCDevice
104: {
105: typedef RTCDevice inherited;
106: public:
107: RP5C15Device();
108: virtual ~RP5C15Device();
109:
110: virtual bool InitRTC();
111:
112: virtual uint64 Read8(uint32 addr);
113: virtual uint64 Read16(uint32 addr);
114: virtual uint64 Write8(uint32 addr, uint32 data);
115: virtual uint64 Write16(uint32 addr, uint32 data);
116: virtual uint64 Peek8(uint32 addr);
117: virtual bool MonitorUpdate();
118:
119: // 32Hz クロック入力
120: virtual void ClockIn();
121:
122: private:
1.1.1.2 ! root 123: // アドレスデコーダ
! 124: uint64 Decoder(uint32 addr) const;
! 125:
1.1 root 126: // レジスタを更新
127: void UpdateReg(uint32);
128:
129: // レジスタ
130: RP5C15 reg {};
131:
132: // 現在のバンク
133: // MODE レジスタの BANK ビットが変更された時にこの値も更新すること。
134: int bank = 0;
135:
136: // CLKOUT 端子の状態 (true なら 'H')
137: bool clkout = false;
138: // ALARM 端子の状態 (true なら 'H')
139: bool alarmout = false;
140: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.