|
|
1.1 ! root 1: // ! 2: // nono ! 3: // Copyright (C) 2018 [email protected] ! 4: // ! 5: ! 6: #pragma once ! 7: ! 8: #include "device.h" ! 9: #include <list> ! 10: #include <vector> ! 11: ! 12: // ユーザ定義リテラルを使ったサフィックス ! 13: ! 14: // マイクロ秒 ! 15: static inline uint64 operator"" _usec(unsigned long long us) ! 16: { ! 17: return us * 1000; ! 18: } ! 19: static inline uint64 operator"" _usec(long double us) ! 20: { ! 21: return us * 1000; ! 22: } ! 23: ! 24: // ミリ秒 ! 25: static inline uint64 operator"" _msec(unsigned long long ms) ! 26: { ! 27: return ms * 1000_usec; ! 28: } ! 29: static inline uint64 operator"" _msec(long double ms) ! 30: { ! 31: return ms * 1000_usec; ! 32: } ! 33: ! 34: // 秒 ! 35: static inline uint64 operator"" _sec(unsigned long long sec) ! 36: { ! 37: return sec * 1000_msec; ! 38: } ! 39: static inline uint64 operator"" _sec(long double sec) ! 40: { ! 41: return sec * 1000_msec; ! 42: } ! 43: ! 44: // コールバック関数の型 ! 45: typedef void (Device::*DeviceCallback_t)(int); ! 46: ! 47: // イベント ! 48: // ! 49: // イベントは必要なデバイスごとに用意する。おそらく最初から個数が決まって ! 50: // いることが多いはずなので、デバイスクラス内のメンバ変数(実体) として ! 51: // 宣言し、デバイスのコンストラクタ等で初期化するという流れになるはず。 ! 52: class Event ! 53: { ! 54: public: ! 55: Event(); ! 56: virtual ~Event(); ! 57: ! 58: // 以下はイベントを呼び出す側がセットする ! 59: ! 60: // イベントを起こすまでの期間 [nsec] ! 61: // 例えば今から 1msec 後にイベントを起こしたい場合は 1000000 となる。 ! 62: // ここは MPU クロックサイクルではなく仮想時間で指定する。 ! 63: uint64 time = 0; ! 64: ! 65: Device *dev = NULL; // デバイス ! 66: DeviceCallback_t func = NULL; // コールバック関数 ! 67: int code = 0; // コールバック関数への引数 ! 68: std::string name {}; // イベント名(表示用) 最大15文字 ! 69: ! 70: // スケジューラが内部で使う ! 71: bool active = false; // スケジューラにセットされていれば真 ! 72: uint64 cycle = 0; // イベントを起こす仮想サイクル ! 73: }; ! 74: ! 75: // 全イベントの配列 (scheduler.h にある有効イベントリストとは違うので注意) ! 76: extern std::vector<Event *> gEvents;
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.