NeKernel dev
Loading...
Searching...
No Matches
Timer.h
Go to the documentation of this file.
1/* ========================================
2
3 Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.
4
5======================================== */
6
7#pragma once
8
9#include <ArchKit/ArchKit.h>
10#include <KernelKit/KPC.h>
11
12namespace Kernel {
13class SoftwareTimer;
14class TimerInterface;
15
16inline constexpr Int16 kTimeUnit = 1000;
17
19 public:
21 explicit TimerInterface() = default;
22 virtual ~TimerInterface() = default;
23
24 public:
26
27 public:
28 virtual BOOL Wait();
29};
30
31class SoftwareTimer final : public TimerInterface {
32 public:
33 explicit SoftwareTimer(Int64 seconds);
34 ~SoftwareTimer() override;
35
36 public:
38
39 public:
40 BOOL Wait() override;
41
42 private:
45};
46
47class HardwareTimer final : public TimerInterface {
48 public:
49 explicit HardwareTimer(UInt64 seconds);
50 ~HardwareTimer() override;
51
52 public:
54
55 public:
56 BOOL Wait() override;
57
58 private:
59 volatile UInt8* fDigitalTimer{nullptr};
61};
62
64 if (time < 1) return 0;
65
66 // TODO: nanoseconds maybe?
67 return time / kTimeUnit;
68}
69
71 if (time < 1) return 0;
72
73 return time;
74}
75} // namespace Kernel
#define NE_COPY_DEFAULT(KLASS)
Definition Detail.h:17
#define BOOL
Kernel Procedure Code.
volatile UInt8 * fDigitalTimer
Definition Timer.h:59
BOOL Wait() override
Wait for the timer to stop spinning.
Definition HalTimer.cc:82
HardwareTimer(UInt64 seconds)
Definition HalTimer.cc:52
Int64 fWaitFor
Definition Timer.h:60
~HardwareTimer() override
Definition HalTimer.cc:73
Definition Timer.h:31
SoftwareTimer(Int64 seconds)
Definition SoftwareTimer.cc:16
BOOL Wait() override
Unimplemented as it is an interface.
Definition SoftwareTimer.cc:28
~SoftwareTimer() override
Definition SoftwareTimer.cc:21
UIntPtr * fDigitalTimer
Definition Timer.h:43
Int64 fWaitFor
Definition Timer.h:44
Definition Timer.h:18
virtual ~TimerInterface()=default
virtual BOOL Wait()
Unimplemented as it is an interface.
Definition Timer.cc:17
TimerInterface()=default
Default constructor.
UPS inline definitions.
Definition Device.h:12
constexpr Int16 kTimeUnit
Definition Timer.h:16
__INT64_TYPE__ Int64
Definition Config.h:46
UInt64 rtl_microseconds(UInt64 time)
Definition Timer.h:63
__UINT8_TYPE__ UInt8
Definition Config.h:55
__INT16_TYPE__ Int16
Definition Config.h:42
UInt64 rtl_milliseconds(UInt64 time)
Definition Timer.h:70
__UINTPTR_TYPE__ UIntPtr
Definition Config.h:62
__UINT64_TYPE__ UInt64
Definition Config.h:48