-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtime.c
48 lines (40 loc) · 966 Bytes
/
time.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <efi.h>
#include <efilib.h>
#include "time.h"
timer make_timer(int * ok, uint32_t duration_ms) {
timer timer = {
.duration_ms = duration_ms
};
*ok = !EFI_ERROR(
BS->CreateEvent(
EVT_TIMER,
TPL_APPLICATION,
NULL,
NULL,
&(timer.event)));
return timer;
}
int await_timer(timer * const timer) {
EFI_STATUS status;
UINTN event_index;
// 10000 is the number of times 100ns fits into 1ms.
// SetTimer expects a time in units of 100ns bundles.
// wtf.
// Correction: an extra factor of 100 was added by experiment.
if(EFI_ERROR(
(status =
BS->SetTimer(
timer->event,
TimerRelative,
timer->duration_ms * 10000)))) {
Print(L"Failed to set timer.\n");
return status;
}
if(EFI_ERROR(
(status =
BS->WaitForEvent(1, &(timer->event), &event_index)))) {
Print(L"Failed to await event.\n");
return status;
}
return 1;
}