--- nono/vm/sysclk.h 2026/04/29 17:04:28 1.1.1.1 +++ nono/vm/sysclk.h 2026/04/29 17:05:29 1.1.1.11 @@ -1,33 +1,76 @@ // // nono -// Copyright (C) 2018 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt +// + +// +// LUNA システムクロック // #pragma once #include "device.h" -#include "scheduler.h" +#include "event.h" +#include "monitor.h" + +class InterruptDevice; -class SysClkDevice - : public IODevice +class SysClkDevice : public IODevice { - typedef IODevice inherited; + using inherited = IODevice; public: SysClkDevice(); - virtual ~SysClkDevice(); + ~SysClkDevice() override; - virtual bool PowerOn(); + bool Init() override; + void ResetHard(bool poweron) override; - virtual uint64 Read8(uint32); - virtual uint64 Write8(uint32, uint32); + uint GetFreq() const { return freq; } + + protected: + // BusIO インタフェース + static const uint32 NPORT = 1; + busdata ReadPort(uint32 offset); + busdata WritePort(uint32 offset, uint32 data); + busdata PeekPort(uint32 offset); + bool PokePort(uint32 offset, uint32 data); private: // イベントコールバック - void Callback(int); + void Callback(Event& ev); + + DECLARE_MONITOR_CALLBACK(MonitorUpdate); + + // 割り込み状態をレジスタイメージにして返す + uint8 GetInt() const; + + // 割り込み信号線の状態を変える。 + void ChangeInterrupt(); // システムクロック割り込み有りなら true。 - bool sysint = false; + bool sysint {}; // 割り込みイベント - Event event {}; + Event event { this }; + + // システムクロック周波数 [Hz] + uint freq {}; + + // 本来のイベント間隔。機種によって異なる。 + uint64 period {}; + + // システムクロックが刻んでいる時刻 + uint64 stime {}; + + // システムクロックを実時間に同期する場合 true + bool sync_rt {}; + + InterruptDevice *interrupt {}; + + Monitor monitor { this }; }; + +static inline SysClkDevice *GetSysClkDevice() { + return Object::GetObject(OBJ_SYSCLK); +}