43 lines
703 B
D
43 lines
703 B
D
/**
|
|
* Time functionality.
|
|
*/
|
|
module hulk.time;
|
|
|
|
import hulk.volatile;
|
|
|
|
struct Time
|
|
{
|
|
/** System uptime (ms). */
|
|
private static __gshared Volatile!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 = uptime() + count + 1;
|
|
while (uptime() < wait_for)
|
|
{
|
|
}
|
|
}
|
|
}
|