diff --git a/src/hulk/pit.d b/src/hulk/pit.d index 33184e8..df03017 100644 --- a/src/hulk/pit.d +++ b/src/hulk/pit.d @@ -6,6 +6,7 @@ module hulk.pit; import hulk.cpu; import hulk.klog; import hulk.console; +import hulk.time; struct Pit { @@ -29,8 +30,6 @@ struct Pit private enum ubyte MC_RATE_GENERATOR = 0x04u; private enum ubyte MC_BINARY = 0x00u; - private static __gshared ulong milliseconds; - public static void initialize() { Klog.writefln("\a3Initializing PIT"); @@ -41,6 +40,6 @@ struct Pit public static void isr() { - milliseconds++; + Time.ms_isr(); } } diff --git a/src/hulk/time.d b/src/hulk/time.d new file mode 100644 index 0000000..4acf673 --- /dev/null +++ b/src/hulk/time.d @@ -0,0 +1,42 @@ +/** + * Time functionality. + */ +module hulk.time; + +import core.volatile; + +struct Time +{ + /** System uptime (ms). */ + private static __gshared ulong s_uptime; + + /** + * Millisecond ISR. + */ + public static void ms_isr() + { + s_uptime++; + } + + /** + * Get system uptime (ms). + */ + public static @property ulong uptime() + { + return s_uptime; + } + + /** + * Sleep for the given amount of time (ms). + * + * @param count + * Number of milliseconds to sleep for. + */ + public static void msleep(ulong count) + { + ulong wait_for = s_uptime + count + 1; + while (volatileLoad(&s_uptime) < wait_for) + { + } + } +}