diff options
| author | Amlal <amlalelmahrouss@icloud.com> | 2024-12-21 21:59:13 +0100 |
|---|---|---|
| committer | Amlal <amlalelmahrouss@icloud.com> | 2024-12-21 21:59:45 +0100 |
| commit | 610f91d87152cbe48d3054fcf437d8239da6ef35 (patch) | |
| tree | a386f7047ab73d088169ab2371ddc6ffe8020f1c /dev/Kernel/KernelKit/Timer.h | |
| parent | 509fcca5986651c8ba712fb395f8498f2dea4109 (diff) | |
IMP: :boom: Breaking changes some checks are needed to be done.
Signed-off-by: Amlal <amlalelmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/KernelKit/Timer.h')
| -rw-r--r-- | dev/Kernel/KernelKit/Timer.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/dev/Kernel/KernelKit/Timer.h b/dev/Kernel/KernelKit/Timer.h new file mode 100644 index 00000000..bbeb1ab6 --- /dev/null +++ b/dev/Kernel/KernelKit/Timer.h @@ -0,0 +1,82 @@ +/* ------------------------------------------- + + Copyright (C) 2024, TQ B.V, all rights reserved. + +------------------------------------------- */ + +#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 |
