pub trait GenericTimer {
fn frequency() -> u32 {
crate::asm::timer_frequency()
}
fn counter() -> u64;
fn set_enable(enabled: bool);
fn set_countdown(ticks: u32);
}
pub struct PhysicalTimer;
pub struct VirtualTimer;
impl GenericTimer for PhysicalTimer {
fn counter() -> u64 {
crate::asm::phys_timer_counter()
}
fn set_enable(enabled: bool) {
crate::asm::phys_timer_enable(enabled);
}
fn set_countdown(ticks: u32) {
crate::asm::phys_timer_set_countdown(ticks);
}
}
impl GenericTimer for VirtualTimer {
fn counter() -> u64 {
crate::asm::virt_timer_counter()
}
fn set_enable(enabled: bool) {
crate::asm::virt_timer_enable(enabled);
}
fn set_countdown(ticks: u32) {
crate::asm::virt_timer_set_countdown(ticks);
}
}