|
|
1.1 root 1: //
2: // nono
3: // Copyright (C) 2024 nono project
4: // Licensed under nono-license.txt
5: //
6:
7: //
8: // Goldfish (Qemu) RTC+Timer (の Timer のほう)
9: //
10:
11: #include "device.h"
12: #include "event.h"
13:
14: class GFRTCDevice;
15: class InterruptDevice;
16: class Syncer;
17:
18: class GFTimerDevice : public IODevice
19: {
20: using inherited = IODevice;
21:
22: public:
23: GFTimerDevice();
24: ~GFTimerDevice() override;
25:
26: bool Init() override;
27: void ResetHard(bool poweron) override;
28:
1.1.1.2 root 29: protected:
30: // BusIO インタフェース
31: static const uint32 NPORT = 0x1000 >> 2;
32: busdata ReadPort(uint32 offset);
33: busdata WritePort(uint32 offset, uint32 data);
34: busdata PeekPort(uint32 offset);
1.1 root 35:
36: private:
37: DECLARE_MONITOR_CALLBACK(MonitorUpdate);
38:
39: void CallbackVT(Event& ev);
40: void CallbackRT(Event& ev);
41: void ChangeInterrupt();
42:
43: // アラーム開始。
44: void StartAlarm();
45:
46: // 現在時刻取得
47: uint64 Now() const;
48:
49: // TIMER レジスタ読み出し値。(アラームの基準点としても使う)
50: uint64 elapsed {};
51:
52: // アラーム予定時刻 (0 ならアラームなし)
53: uint64 alarm {};
54:
55: // 先に書き込まれた上位側を一旦保持しておくところ。
56: uint64 alarm_high {};
57:
58: bool sync_rt {};
59:
60: // 実時間同期用
61: uint64 mtime_epoch {}; // 調整実時間軸の起点(仮想時刻)
1.1.1.3 ! root 62: uint64 mtime {}; // 自身の調整実時間。(mtime_epoch からの経過時間)
1.1 root 63:
64: bool intr_enable {}; // 割り込み許可
65: bool intr_assert {}; // 割り込み発生
66:
67: Event event { this };
68:
1.1.1.3 ! root 69: Monitor *monitor {};
1.1 root 70:
71: GFRTCDevice *gfrtc {};
72: InterruptDevice *interrupt {};
73: Syncer *syncer {};
74: };
75:
76: static inline GFTimerDevice *GetGFTimerDevice() {
77: return Object::GetObject<GFTimerDevice>(OBJ_GFTIMER);
78: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.