diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-05-09 00:42:44 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-05-09 00:42:44 +0200 |
| commit | af8a516fc22865abd80d6e26f1541fa3d6bebfdc (patch) | |
| tree | 96d42a10945fc03df022389aef54708383c1d616 /Kernel/KernelKit/Timer.hpp | |
| parent | a874e9cc98df994178d55996943fe81799c61d2f (diff) | |
MHR-23: :boom:, refactors.
- Move NewBoot to /Boot, thus making Kernel directory only containing the kernel.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
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 |
