mirror of
https://github.com/panpaul/tiny_os
synced 2024-09-20 09:45:19 +08:00
feat: kernel/plat: initial irq support
This commit is contained in:
parent
871a028ecf
commit
55c27e371d
@ -102,7 +102,7 @@ impl Driver for IrqPlic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl IrqController for IrqPlic {
|
impl IrqController for IrqPlic {
|
||||||
fn enable(&self, irq: usize) {
|
fn enable(&mut self, irq: usize) {
|
||||||
if irq == 0 || irq >= self.nr_irqs {
|
if irq == 0 || irq >= self.nr_irqs {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -121,7 +121,7 @@ impl IrqController for IrqPlic {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn disable(&self, irq: usize) {
|
fn disable(&mut self, irq: usize) {
|
||||||
if irq == 0 || irq >= self.nr_irqs {
|
if irq == 0 || irq >= self.nr_irqs {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -140,7 +140,7 @@ impl IrqController for IrqPlic {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_pending(&self, irq: usize) -> bool {
|
fn is_pending(&mut self, irq: usize) -> bool {
|
||||||
if irq == 0 || irq >= self.nr_irqs {
|
if irq == 0 || irq >= self.nr_irqs {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -152,7 +152,7 @@ impl IrqController for IrqPlic {
|
|||||||
val & (1 << bit) != 0
|
val & (1 << bit) != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn claim(&self) -> Option<usize> {
|
fn claim(&mut self) -> Option<usize> {
|
||||||
let val = unsafe { self.control.as_ref().unwrap().claim.read_volatile() };
|
let val = unsafe { self.control.as_ref().unwrap().claim.read_volatile() };
|
||||||
|
|
||||||
if val > 0 {
|
if val > 0 {
|
||||||
@ -162,7 +162,7 @@ impl IrqController for IrqPlic {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn complete(&self, irq: usize) {
|
fn complete(&mut self, irq: usize) {
|
||||||
if irq == 0 || irq >= self.nr_irqs {
|
if irq == 0 || irq >= self.nr_irqs {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use super::utils::generate_driver;
|
||||||
|
use crate::drivers::irq::IrqPlic;
|
||||||
use crate::objects::*;
|
use crate::objects::*;
|
||||||
|
|
||||||
const IRQ_NUM: usize = 32;
|
const IRQ_NUM: usize = 32;
|
||||||
@ -10,13 +12,18 @@ pub enum IrqState {
|
|||||||
Reserved,
|
Reserved,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait IrqController {
|
generate_driver!(
|
||||||
fn enable(&self, irq: usize);
|
IrqDriver {
|
||||||
fn disable(&self, irq: usize);
|
(IrqPlic),
|
||||||
fn is_pending(&self, irq: usize) -> bool;
|
()
|
||||||
fn claim(&self) -> Option<usize>;
|
} : IrqController {
|
||||||
fn complete(&self, irq: usize);
|
fn enable(&mut self, irq: usize) -> ();
|
||||||
}
|
fn disable(&mut self, irq: usize) -> ();
|
||||||
|
fn is_pending(&mut self, irq: usize) -> bool;
|
||||||
|
fn claim(&mut self) -> Option<usize>;
|
||||||
|
fn complete(&mut self, irq: usize) -> ();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
pub struct IrqManager {
|
pub struct IrqManager {
|
||||||
handler: [CapEntry; IRQ_NUM],
|
handler: [CapEntry; IRQ_NUM],
|
||||||
@ -30,5 +37,4 @@ impl IrqManager {
|
|||||||
state: [IrqState::Inactive; IRQ_NUM],
|
state: [IrqState::Inactive; IRQ_NUM],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user