Add hulk.time and msleep()

This commit is contained in:
josh committed 2023-10-26 16:18:26 -04:00
1 parent 6251fee3ff
commit 9f8a4ea100
2 files changed
+44 -3

No files matched your search

+42
View File
@@ -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)
{
}
}
}