diff options
Diffstat (limited to 'Kernel/KernelKit/Timer.hpp')
| -rw-r--r-- | Kernel/KernelKit/Timer.hpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/Kernel/KernelKit/Timer.hpp b/Kernel/KernelKit/Timer.hpp new file mode 100644 index 00000000..8b0642c7 --- /dev/null +++ b/Kernel/KernelKit/Timer.hpp @@ -0,0 +1,64 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#include <ArchKit/ArchKit.hpp> +#include <CompilerKit/CompilerKit.hxx> +#include <KernelKit/HError.hpp> + +namespace NewOS +{ + class HardwareTimer; + class HardwareTimerInterface; + + class HardwareTimerInterface + { + public: + /// @brief Default constructor + explicit HardwareTimerInterface() = default; + virtual ~HardwareTimerInterface() = default; + + public: + NEWOS_COPY_DEFAULT(HardwareTimerInterface); + + public: + virtual Int32 Wait() noexcept; + }; + + class HardwareTimer final : public HardwareTimerInterface + { + public: + explicit HardwareTimer(Int64 seconds); + ~HardwareTimer() override; + + public: + NEWOS_COPY_DEFAULT(HardwareTimer); + + public: + Int32 Wait() noexcept override; + + public: + IntPtr* fDigitalTimer{nullptr}; + Int64 fWaitFor{0}; + }; + + inline Int64 Seconds(Int64 time) + { + if (time < 0) + return 0; + + return 1000 / time; + } + + inline Int64 Milliseconds(Int64 time) + { + if (time < 0) + return 0; + + return 1000 / Seconds(time); + } +} // namespace NewOS |
