diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-10-21 20:23:36 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-10-21 20:23:36 +0200 |
| commit | d48cbe75ef29a9c67c9d176bf58e56ea6448fb9e (patch) | |
| tree | 89cbd6b7e23802f92bf3158868f4dc33c088e516 /dev/zka/KernelKit/Timer.h | |
| parent | 21b3da78f806d6765f9dffa6a84c21346f171cee (diff) | |
IMP: Major refactor of header and source files extensions.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/zka/KernelKit/Timer.h')
| -rw-r--r-- | dev/zka/KernelKit/Timer.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/dev/zka/KernelKit/Timer.h b/dev/zka/KernelKit/Timer.h new file mode 100644 index 00000000..cd0b6c4c --- /dev/null +++ b/dev/zka/KernelKit/Timer.h @@ -0,0 +1,82 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#pragma once + +#include <ArchKit/ArchKit.h> +#include <CompilerKit/CompilerKit.h> +#include <KernelKit/LPC.h> + +namespace Kernel +{ + class SoftwareTimer; + class TimerInterface; + + class TimerInterface + { + public: + /// @brief Default constructor + explicit TimerInterface() = default; + virtual ~TimerInterface() = default; + + public: + ZKA_COPY_DEFAULT(TimerInterface); + + public: + virtual Int32 Wait() noexcept; + }; + + class SoftwareTimer final : public TimerInterface + { + public: + explicit SoftwareTimer(Int64 seconds); + ~SoftwareTimer() override; + + public: + ZKA_COPY_DEFAULT(SoftwareTimer); + + public: + Int32 Wait() noexcept override; + + private: + IntPtr* fDigitalTimer{nullptr}; + Int64 fWaitFor{0}; + }; + + class HardwareTimer final : public TimerInterface + { + public: + explicit HardwareTimer(Int64 seconds); + ~HardwareTimer() override; + + public: + ZKA_COPY_DEFAULT(HardwareTimer); + + public: + Int32 Wait() noexcept override; + + private: + IntPtr* fDigitalTimer{nullptr}; + Int64 fWaitFor{0}; + }; + + inline Int64 Milliseconds(Int64 time) + { + if (time < 0) + return 0; + + // TODO: nanoseconds maybe? + return 1000 * 1000 * time; + } + + inline Int64 Seconds(Int64 time) + { + if (time < 0) + return 0; + + return 1000 * Milliseconds(time); + } +} // namespace Kernel |
