|
|
1.1 root 1: //
2: // nono
1.1.1.4 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"
10: #include <vector>
11:
12: // ユーザ定義リテラルを使ったサフィックス
13:
1.1.1.2 root 14: // ナノ秒
1.1.1.7 ! root 15: static inline constexpr uint64 operator"" _nsec(unsigned long long ns)
1.1.1.2 root 16: {
17: return ns;
18: }
1.1.1.7 ! root 19: static inline constexpr uint64 operator"" _nsec(long double ns)
1.1.1.2 root 20: {
21: return ns;
22: }
23:
1.1 root 24: // マイクロ秒
1.1.1.7 ! root 25: static inline constexpr uint64 operator"" _usec(unsigned long long us)
1.1 root 26: {
1.1.1.5 root 27: return us * 1000_nsec;
1.1 root 28: }
1.1.1.7 ! root 29: static inline constexpr uint64 operator"" _usec(long double us)
1.1 root 30: {
1.1.1.5 root 31: return us * 1000_nsec;
1.1 root 32: }
33:
34: // ミリ秒
1.1.1.7 ! root 35: static inline constexpr uint64 operator"" _msec(unsigned long long ms)
1.1 root 36: {
37: return ms * 1000_usec;
38: }
1.1.1.7 ! root 39: static inline constexpr uint64 operator"" _msec(long double ms)
1.1 root 40: {
41: return ms * 1000_usec;
42: }
43:
44: // 秒
1.1.1.7 ! root 45: static inline constexpr uint64 operator"" _sec(unsigned long long sec)
1.1 root 46: {
47: return sec * 1000_msec;
48: }
1.1.1.7 ! root 49: static inline constexpr uint64 operator"" _sec(long double sec)
1.1 root 50: {
51: return sec * 1000_msec;
52: }
53:
54: // コールバック関数の型
1.1.1.5 root 55: class Event;
56: using DeviceCallback_t = void (Device::*)(Event&);
1.1 root 57:
58: // イベント
59: //
60: // イベントは必要なデバイスごとに用意する。おそらく最初から個数が決まって
61: // いることが多いはずなので、デバイスクラス内のメンバ変数(実体) として
62: // 宣言し、デバイスのコンストラクタ等で初期化するという流れになるはず。
1.1.1.5 root 63: //
64: // VM リセットによるイベントタイマーの停止処理は各デバイスの責任で行うこと。
1.1 root 65: class Event
66: {
67: public:
68: Event();
69: virtual ~Event();
70:
1.1.1.3 root 71: // このイベントタイマーを開始する
72: void Start();
73: // このイベントタイマーを停止する
74: void Stop();
75:
1.1.1.7 ! root 76: // このイベントが動作中なら true を返す
! 77: bool IsRunning() const {
! 78: return active;
! 79: }
! 80:
1.1 root 81: // 以下はイベントを呼び出す側がセットする
82:
1.1.1.6 root 83: // イベントを起こすまでの仮想時刻での相対時間 [nsec]
1.1 root 84: // 例えば今から 1msec 後にイベントを起こしたい場合は 1000000 となる。
1.1.1.5 root 85: uint64 time {};
1.1 root 86:
1.1.1.5 root 87: Device *dev {}; // デバイス
88: DeviceCallback_t func {}; // コールバック関数
89: int code {}; // コールバック関数への引数
1.1.1.2 root 90: std::string GetName() const { return name; }
91: void SetName(const std::string& val);
1.1 root 92:
93: // スケジューラが内部で使う
1.1.1.5 root 94: bool active {}; // スケジューラにセットされていれば真
1.1.1.6 root 95: uint64 vtime {}; // イベントを起こす仮想時刻
1.1.1.2 root 96:
97: private:
98: // イベント名(表示用)
99: // '\0' 含まず25文字まで。デバイス名も必要なら含めること。
100: std::string name {};
1.1 root 101: };
102:
103: // 全イベントの配列 (scheduler.h にある有効イベントリストとは違うので注意)
104: extern std::vector<Event *> gEvents;
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.