refactor(domain): move irq tests to separate file, fix MemoryRegion import in platform
This commit is contained in:
38
crates/domain/src/irq/mod.rs
Normal file
38
crates/domain/src/irq/mod.rs
Normal file
@@ -0,0 +1,38 @@
|
||||
use types::id::{IrqId, ThreadId};
|
||||
|
||||
use crate::error::KernelError;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "tests.rs"]
|
||||
mod tests;
|
||||
|
||||
const MAX_IRQS: usize = 256;
|
||||
|
||||
pub struct IrqRoutingTable {
|
||||
owners: [Option<ThreadId>; MAX_IRQS],
|
||||
}
|
||||
|
||||
impl IrqRoutingTable {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
owners: [None; MAX_IRQS],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn register(&mut self, irq: IrqId, thread: ThreadId) -> Result<(), KernelError> {
|
||||
let idx = irq.raw() as usize;
|
||||
if self.owners[idx].is_some() {
|
||||
return Err(KernelError::IrqAlreadyOwned(irq));
|
||||
}
|
||||
self.owners[idx] = Some(thread);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn unregister(&mut self, irq: IrqId) {
|
||||
self.owners[irq.raw() as usize] = None;
|
||||
}
|
||||
|
||||
pub fn owner(&self, irq: IrqId) -> Option<ThreadId> {
|
||||
self.owners[irq.raw() as usize]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user