Annotation of nono/vm/event.h, revision 1.1.1.2

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: 
1.1.1.2 ! root       14: // ナノ秒
        !            15: static inline uint64 operator"" _nsec(unsigned long long ns)
        !            16: {
        !            17:        return ns;
        !            18: }
        !            19: static inline uint64 operator"" _nsec(long double ns)
        !            20: {
        !            21:        return ns;
        !            22: }
        !            23: 
1.1       root       24: // マイクロ秒
                     25: static inline uint64 operator"" _usec(unsigned long long us)
                     26: {
                     27:        return us * 1000;
                     28: }
                     29: static inline uint64 operator"" _usec(long double us)
                     30: {
                     31:        return us * 1000;
                     32: }
                     33: 
                     34: // ミリ秒
                     35: static inline uint64 operator"" _msec(unsigned long long ms)
                     36: {
                     37:        return ms * 1000_usec;
                     38: }
                     39: static inline uint64 operator"" _msec(long double ms)
                     40: {
                     41:        return ms * 1000_usec;
                     42: }
                     43: 
                     44: // 秒
                     45: static inline uint64 operator"" _sec(unsigned long long sec)
                     46: {
                     47:        return sec * 1000_msec;
                     48: }
                     49: static inline uint64 operator"" _sec(long double sec)
                     50: {
                     51:        return sec * 1000_msec;
                     52: }
                     53: 
                     54: // コールバック関数の型
                     55: typedef void (Device::*DeviceCallback_t)(int);
                     56: 
                     57: // イベント
                     58: //
                     59: // イベントは必要なデバイスごとに用意する。おそらく最初から個数が決まって
                     60: // いることが多いはずなので、デバイスクラス内のメンバ変数(実体) として
                     61: // 宣言し、デバイスのコンストラクタ等で初期化するという流れになるはず。
                     62: class Event
                     63: {
                     64:  public:
                     65:        Event();
                     66:        virtual ~Event();
                     67: 
                     68:        // 以下はイベントを呼び出す側がセットする
                     69: 
                     70:        // イベントを起こすまでの期間 [nsec]
                     71:        // 例えば今から 1msec 後にイベントを起こしたい場合は 1000000 となる。
                     72:        // ここは MPU クロックサイクルではなく仮想時間で指定する。
                     73:        uint64 time = 0;
                     74: 
                     75:        Device *dev = NULL;                             // デバイス
                     76:        DeviceCallback_t func = NULL;   // コールバック関数
                     77:        int code = 0;                                   // コールバック関数への引数
1.1.1.2 ! root       78:        std::string GetName() const { return name; }
        !            79:        void SetName(const std::string& val);
1.1       root       80: 
                     81:        // スケジューラが内部で使う
                     82:        bool active = false;                    // スケジューラにセットされていれば真
                     83:        uint64 cycle = 0;                               // イベントを起こす仮想サイクル
1.1.1.2 ! root       84: 
        !            85:  private:
        !            86:        // イベント名(表示用)
        !            87:        // '\0' 含まず25文字まで。デバイス名も必要なら含めること。
        !            88:        std::string name {};
1.1       root       89: };
                     90: 
                     91: // 全イベントの配列 (scheduler.h にある有効イベントリストとは違うので注意)
                     92: extern std::vector<Event *> gEvents;

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.