summaryrefslogtreecommitdiffhomepage
path: root/dev/Kernel/KernelKit/Timer.h
diff options
context:
space:
mode:
authorAmlal <amlal.elmahrouss@icloud.com>2025-01-24 10:38:36 +0100
committerAmlal <amlal.elmahrouss@icloud.com>2025-01-24 10:38:36 +0100
commit7b4bd3577a31d0f0adc7371840642791ae1567f4 (patch)
tree1a8afc973aaa739d0d763315cad2fd376d1cea9c /dev/Kernel/KernelKit/Timer.h
ADD: Open version, with important changes kept out.
Signed-off-by: Amlal <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/KernelKit/Timer.h')
-rw-r--r--dev/Kernel/KernelKit/Timer.h81
1 files changed, 81 insertions, 0 deletions
diff --git a/dev/Kernel/KernelKit/Timer.h b/dev/Kernel/KernelKit/Timer.h
new file mode 100644
index 00000000..2fa2dfa6
--- /dev/null
+++ b/dev/Kernel/KernelKit/Timer.h
@@ -0,0 +1,81 @@
+/* -------------------------------------------
+
+ Copyright (C) 2024, Amlal EL Mahrouss, all rights reserved.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <ArchKit/ArchKit.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 BOOL Wait() noexcept;
+ };
+
+ class SoftwareTimer final : public TimerInterface
+ {
+ public:
+ explicit SoftwareTimer(Int64 seconds);
+ ~SoftwareTimer() override;
+
+ public:
+ ZKA_COPY_DEFAULT(SoftwareTimer);
+
+ public:
+ BOOL 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:
+ BOOL 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