--- nono/vm/event.h 2026/04/29 17:04:41 1.1.1.5 +++ nono/vm/event.h 2026/04/29 17:05:10 1.1.1.9 @@ -4,56 +4,61 @@ // Licensed under nono-license.txt // +// +// イベント +// + #pragma once #include "device.h" -#include // ユーザ定義リテラルを使ったサフィックス // ナノ秒 -static inline uint64 operator"" _nsec(unsigned long long ns) +static inline constexpr uint64 operator"" _nsec(unsigned long long ns) { return ns; } -static inline uint64 operator"" _nsec(long double ns) +static inline constexpr uint64 operator"" _nsec(long double ns) { return ns; } // マイクロ秒 -static inline uint64 operator"" _usec(unsigned long long us) +static inline constexpr uint64 operator"" _usec(unsigned long long us) { return us * 1000_nsec; } -static inline uint64 operator"" _usec(long double us) +static inline constexpr uint64 operator"" _usec(long double us) { return us * 1000_nsec; } // ミリ秒 -static inline uint64 operator"" _msec(unsigned long long ms) +static inline constexpr uint64 operator"" _msec(unsigned long long ms) { return ms * 1000_usec; } -static inline uint64 operator"" _msec(long double ms) +static inline constexpr uint64 operator"" _msec(long double ms) { return ms * 1000_usec; } // 秒 -static inline uint64 operator"" _sec(unsigned long long sec) +static inline constexpr uint64 operator"" _sec(unsigned long long sec) { return sec * 1000_msec; } -static inline uint64 operator"" _sec(long double sec) +static inline constexpr uint64 operator"" _sec(long double sec) { return sec * 1000_msec; } // コールバック関数の型 class Event; -using DeviceCallback_t = void (Device::*)(Event&); +using EventCallback_t = void (Device::*)(Event&); +#define ToEventCallback(f) static_cast(f) + // イベント // @@ -66,35 +71,40 @@ class Event { public: Event(); - virtual ~Event(); + Event(Device *dev_); + ~Event(); - // このイベントタイマーを開始する - void Start(); - // このイベントタイマーを停止する - void Stop(); + // このイベントを登録する + void Regist(); + // このイベントを登録する (名前を同時に設定する) + void Regist(const std::string& name_); + + // このイベントが動作中なら true を返す + bool IsRunning() const { + return active; + } // 以下はイベントを呼び出す側がセットする - // イベントを起こすまでの期間 [nsec] + // イベントを起こすまでの仮想時刻での相対時間 [nsec] // 例えば今から 1msec 後にイベントを起こしたい場合は 1000000 となる。 - // ここは MPU クロックサイクルではなく仮想時間で指定する。 uint64 time {}; Device *dev {}; // デバイス - DeviceCallback_t func {}; // コールバック関数 + EventCallback_t func {}; // コールバック関数 int code {}; // コールバック関数への引数 - std::string GetName() const { return name; } + const std::string GetName() const { return name; } void SetName(const std::string& val); // スケジューラが内部で使う bool active {}; // スケジューラにセットされていれば真 - uint64 cycle {}; // イベントを起こす仮想サイクル + uint64 vtime {}; // イベントを起こす仮想時刻 + + uint64 count {}; // コールバックを呼び出した回数 + uint64 last_count {}; // (表示用)前回表示したときの count private: // イベント名(表示用) // '\0' 含まず25文字まで。デバイス名も必要なら含めること。 std::string name {}; }; - -// 全イベントの配列 (scheduler.h にある有効イベントリストとは違うので注意) -extern std::vector gEvents;