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
use crate::util::OnceFatBox;
use alloc::boxed::Box;
pub trait Timer: Send {
fn set_timer(&self, stime_value: u64);
}
static TIMER: OnceFatBox<dyn Timer + Sync + 'static> = OnceFatBox::new();
#[doc(hidden)]
pub fn init_timer<T: Timer + Sync + 'static>(timer: T) {
let result = TIMER.set(Box::new(timer));
if result.is_err() {
panic!("load sbi module when already loaded")
}
}
#[inline]
pub(crate) fn probe_timer() -> bool {
TIMER.get().is_some()
}
#[inline]
pub(crate) fn set_timer(time_value: u64) -> bool {
if let Some(timer) = TIMER.get() {
timer.set_timer(time_value);
true
} else {
false
}
}