Skip to content

Commit 4ee6feb

Browse files
committed
feat(kernel): add Port::{enable, disable}_interrupt_line
1 parent e9aa74d commit 4ee6feb

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

src/constance/src/kernel.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ pub unsafe trait Port: KernelCfg1 {
295295
///
296296
/// [an interrupt context]: crate#contexts
297297
fn is_interrupt_context() -> bool;
298+
299+
/// Enable the specified interrupt line.
300+
unsafe fn enable_interrupt_line(line: InterruptNum) -> Result<(), EnableInterruptLineError>;
301+
302+
/// Disable the specified interrupt line.
303+
unsafe fn disable_interrupt_line(line: InterruptNum) -> Result<(), EnableInterruptLineError>;
298304
}
299305

300306
/// Methods intended to be called by a port.

src/constance/src/kernel/interrupt.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,14 @@ impl<System: Kernel> InterruptLine<System> {
103103

104104
/// Enable the interrupt line.
105105
pub fn enable(self) -> Result<(), EnableInterruptLineError> {
106-
todo!()
106+
// Safety: We are the kernel, so it's okay to call `Port`'s methods
107+
unsafe { System::enable_interrupt_line(self.0) }
107108
}
108109

109110
/// Disable the interrupt line.
110111
pub fn disable(self) -> Result<(), EnableInterruptLineError> {
111-
todo!()
112+
// Safety: We are the kernel, so it's okay to call `Port`'s methods
113+
unsafe { System::disable_interrupt_line(self.0) }
112114
}
113115

114116
// TODO: port-specific attributes

src/constance_port_std/src/lib.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::{
1414
mod threading;
1515

1616
#[doc(hidden)]
17-
pub use constance::kernel::{Port, PortToKernel, TaskCb};
17+
pub use constance::kernel::{EnableInterruptLineError, InterruptNum, Port, PortToKernel, TaskCb};
1818
/// Used by `use_port!`
1919
#[doc(hidden)]
2020
pub use std::sync::atomic::{AtomicBool, Ordering};
@@ -307,6 +307,20 @@ impl State {
307307
pub fn is_interrupt_context(&self) -> bool {
308308
false
309309
}
310+
311+
pub fn enable_interrupt_line(
312+
&self,
313+
_line: InterruptNum,
314+
) -> Result<(), EnableInterruptLineError> {
315+
todo!()
316+
}
317+
318+
pub fn disable_interrupt_line(
319+
&self,
320+
_line: InterruptNum,
321+
) -> Result<(), EnableInterruptLineError> {
322+
todo!()
323+
}
310324
}
311325

312326
#[macro_export]
@@ -352,6 +366,14 @@ macro_rules! use_port {
352366
fn is_interrupt_context() -> bool {
353367
PORT_STATE.is_interrupt_context()
354368
}
369+
370+
unsafe fn enable_interrupt_line(line: $crate::InterruptNum) -> Result<(), $crate::EnableInterruptLineError> {
371+
PORT_STATE.enable_interrupt_line(line)
372+
}
373+
374+
unsafe fn disable_interrupt_line(line: $crate::InterruptNum) -> Result<(), $crate::EnableInterruptLineError> {
375+
PORT_STATE.disable_interrupt_line(line)
376+
}
355377
}
356378

357379
fn main() {

0 commit comments

Comments
 (0)