#ifndef CLOCK_MODEL_HPP #define CLOCK_MODEL_HPP #include #include #include #include #include namespace clockmodel { using Arg = std::int64_t; using Word = std::uint32_t; struct Reply { std::string status; std::vector values; }; struct Event { Word reg; Word value; }; struct Device { std::array regs{}; std::deque fifo; std::deque events; }; class Bus { public: Bus(); Reply read(Arg id, Arg reg) const; Reply write(Arg id, Arg reg, Arg value); Reply configure(Arg id, Arg clock, Arg reset, Arg enable, Arg data); Reply burst(Arg id, const std::vector& values); Reply drain(Arg id, Arg count); Reply snapshot(Arg id) const; Reply history(Arg id, Arg count) const; Reply clear(Arg id); private: std::array devices_; static bool valid_id(Arg id); static bool valid_reg(Arg reg); static bool valid_word(Arg value); static bool valid_count(Arg count, Arg maximum); static bool clock_on(const Device& device); static bool reset_released(const Device& device); static bool enabled(const Device& device); static Reply error(const std::string& code); static Reply success(); static Reply single(Word value); static void record(Device& device, Word reg, Word value); static std::string data_permission(const Device& device); static std::string apply(Device& device, Word reg, Word value); static std::string set_clock(Device& device, Word value); static std::string set_reset(Device& device, Word value); static std::string set_enable(Device& device, Word value); static std::string set_data(Device& device, Word value); static std::vector export_snapshot(const Device& device); static std::vector export_history(const Device& device, std::size_t count); }; } #endif