Skip to main content

sparreal_kernel/os/irq/
mod.rs

1mod guard;
2
3use alloc::{boxed::Box, collections::btree_map::BTreeMap};
4pub use guard::*;
5
6use crate::{hal::al::IrqId, os::sync::IrqSpinlock};
7
8static IRQ_VEC: IrqSpinlock<BTreeMap<IrqId, Box<dyn Fn() + Send + Sync>>> =
9    IrqSpinlock::new(BTreeMap::new());
10
11pub fn register_handler<F>(irq: IrqId, handler: F)
12where
13    F: Fn() + Send + Sync + 'static,
14{
15    {
16        let mut guard = IRQ_VEC.lock();
17        guard.insert(irq, Box::new(handler));
18    }
19    crate::hal::al::platform::irq_set_enabled(irq, true);
20}
21
22pub(crate) fn handle_irq(irq: IrqId) {
23    let guard = IRQ_VEC.lock();
24    if let Some(handler) = guard.get(&irq) {
25        handler();
26    }
27}