pub struct MockInterruptController {
pending: u64,
enabled: u64,
}
impl Default for MockInterruptController {
fn default() -> Self {
Self::new()
}
}
impl MockInterruptController {
pub fn new() -> Self {
Self { pending: 0, enabled: 0 }
}
pub fn raise(&mut self, irq: u32) {
assert!(irq < 64, "IRQ id must be < 64");
self.pending |= 1 << irq;
}
pub fn clear(&mut self, irq: u32) {
assert!(irq < 64, "IRQ id must be < 64");
self.pending &= !(1 << irq);
}
pub fn enable(&mut self, irq: u32) {
assert!(irq < 64, "IRQ id must be < 64");
self.enabled |= 1 << irq;
}
pub fn claim(&mut self) -> Option<u32> {
let actionable = self.pending & self.enabled;
if actionable == 0 {
return None;
}
let irq = actionable.trailing_zeros();
self.pending &= !(1 << irq);
Some(irq)
}
pub fn is_pending(&self) -> bool {
(self.pending & self.enabled) != 0
}
}