Skip to content

Commit 90a4035

Browse files
committed
Added new functions
1 parent 1509de2 commit 90a4035

File tree

6 files changed

+101
-23
lines changed

6 files changed

+101
-23
lines changed

src/aclint.rs

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,45 +65,77 @@ impl<C: Clint> CLINT<C> {
6565

6666
const MTIME_OFFSET: usize = 0xBFF8;
6767

68+
/// Returns `true` if any CLINT-related interrupt is pending.
69+
#[inline]
70+
pub fn is_interrupting() -> bool {
71+
Self::mswi_is_interrupting() || Self::mtimer_is_interrupting()
72+
}
73+
74+
/// Returns `true` if a machine software interrupt is pending.
75+
#[inline]
76+
pub fn mswi_is_interrupting() -> bool {
77+
mswi::MSWI::is_interrupting()
78+
}
79+
80+
/// Returns `true` if Machine Software Interrupts are enabled.
81+
/// This bit must be set for the `MSWI` to trigger machine software interrupts.
82+
#[inline]
83+
pub fn mswi_is_enabled() -> bool {
84+
mswi::MSWI::is_enabled()
85+
}
86+
6887
/// Enables machine software interrupts to let the `MSWI` peripheral trigger interrupts.
6988
///
7089
/// # Safety
7190
///
7291
/// Enabling the `MSWI` may break mask-based critical sections.
7392
#[inline]
74-
pub unsafe fn enable_mswi() {
93+
pub unsafe fn mswi_enable() {
7594
mswi::MSWI::enable();
7695
}
7796

7897
/// Disables machine software interrupts to prevent the `MSWI` peripheral from triggering interrupts.
7998
#[inline]
80-
pub fn disable_mswi() {
99+
pub fn mswi_disable() {
81100
mswi::MSWI::disable();
82101
}
83102

103+
/// Returns the `MSWI` peripheral.
104+
#[inline]
105+
pub const fn mswi() -> mswi::MSWI {
106+
// SAFETY: valid base address
107+
unsafe { mswi::MSWI::new(C::BASE) }
108+
}
109+
110+
/// Returns `true` if a machine timer interrupt is pending.
111+
#[inline]
112+
pub fn mtimer_is_interrupting() -> bool {
113+
mtimer::MTIMER::is_interrupting()
114+
}
115+
116+
/// Returns `true` if Machine Timer Interrupts are enabled.
117+
/// This bit must be set for the `MTIMER` to trigger machine timer interrupts.
118+
#[inline]
119+
pub fn mtimer_is_enabled() -> bool {
120+
mtimer::MTIMER::is_enabled()
121+
}
122+
84123
/// Enables machine timer interrupts to let the `MTIMER` peripheral trigger interrupts.
85124
///
86125
/// # Safety
87126
///
88127
/// Enabling the `MTIMER` may break mask-based critical sections.
89128
#[inline]
90-
pub unsafe fn enable_mtimer() {
129+
pub unsafe fn mtimer_enable() {
91130
mtimer::MTIMER::enable();
92131
}
93132

94133
/// Disables machine timer interrupts to prevent the `MTIMER` peripheral from triggering interrupts.
95134
#[inline]
96-
pub fn disable_mtimer() {
135+
pub fn mtimer_disable() {
97136
mtimer::MTIMER::disable();
98137
}
99138

100-
/// Returns the `MSWI` peripheral.
101-
#[inline]
102-
pub const fn mswi() -> mswi::MSWI {
103-
// SAFETY: valid base address
104-
unsafe { mswi::MSWI::new(C::BASE) }
105-
}
106-
107139
/// Returns the `MTIMER` peripheral.
108140
#[inline]
109141
pub const fn mtimer() -> mtimer::MTIMER {

src/aclint/mswi.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ impl MSWI {
2525
}
2626
}
2727

28+
/// Returns `true` if a machine software interrupt is pending.
29+
#[inline]
30+
pub fn is_interrupting() -> bool {
31+
riscv::register::mip::read().msoft()
32+
}
33+
34+
/// Returns `true` if Machine Software Interrupts are enabled.
35+
#[inline]
36+
pub fn is_enabled() -> bool {
37+
riscv::register::mie::read().msoft()
38+
}
39+
2840
/// Sets the Machine Software Interrupt bit of the `mie` CSR.
2941
/// This bit must be set for the `MSWI` to trigger machine software interrupts.
3042
///

src/aclint/mtimer.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ impl MTIMER {
2727
}
2828
}
2929

30+
/// Returns `true` if a machine timer interrupt is pending.
31+
#[inline]
32+
pub fn is_interrupting() -> bool {
33+
riscv::register::mip::read().mtimer()
34+
}
35+
36+
/// Returns `true` if Machine Timer Interrupts are enabled.
37+
#[inline]
38+
pub fn is_enabled() -> bool {
39+
riscv::register::mie::read().mtimer()
40+
}
41+
3042
/// Sets the Machine Timer Interrupt bit of the `mie` CSR.
3143
/// This bit must be set for the `MTIMER` to trigger machine timer interrupts.
3244
///
@@ -46,7 +58,7 @@ impl MTIMER {
4658
unsafe { riscv::register::mie::clear_mtimer() };
4759
}
4860

49-
/// Returns the `MTIME` register for the HART which ID is `hart_id`.
61+
/// Returns the `MTIMECMP` register for the HART which ID is `hart_id`.
5062
///
5163
/// # Note
5264
///

src/aclint/sswi.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ impl SSWI {
2525
}
2626
}
2727

28+
/// Returns `true` if a supervisor software interrupt is pending.
29+
#[inline]
30+
pub fn is_interrupting() -> bool {
31+
riscv::register::sip::read().ssoft()
32+
}
33+
34+
/// Returns `true` if Supervisor Software Interrupts are enabled.
35+
#[inline]
36+
pub fn is_enabled() -> bool {
37+
riscv::register::mie::read().ssoft()
38+
}
39+
2840
/// Sets the Supervisor Software Interrupt bit of the `mie` CSR.
2941
/// This bit must be set for the `SSWI` to trigger supervisor software interrupts.
3042
///

src/macros.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ macro_rules! clint_codegen {
8181
///
8282
/// Enabling the `MSWI` may break mask-based critical sections.
8383
#[inline]
84-
pub unsafe fn enable_mswi() {
85-
$crate::aclint::CLINT::<CLINT>::enable_mswi();
84+
pub unsafe fn mswi_enable() {
85+
$crate::aclint::CLINT::<CLINT>::mswi_enable();
8686
}
8787

8888
/// Disables the `MSWI` peripheral.
8989
#[inline]
90-
pub fn disable_mswi() {
91-
$crate::aclint::CLINT::<CLINT>::disable_mswi();
90+
pub fn mswi_disable() {
91+
$crate::aclint::CLINT::<CLINT>::mswi_disable();
9292
}
9393

9494
/// Enables the `MTIMER` peripheral.
@@ -97,14 +97,14 @@ macro_rules! clint_codegen {
9797
///
9898
/// Enabling the `MTIMER` may break mask-based critical sections.
9999
#[inline]
100-
pub unsafe fn enable_mtimer() {
101-
$crate::aclint::CLINT::<CLINT>::enable_mtimer();
100+
pub unsafe fn mtimer_enable() {
101+
$crate::aclint::CLINT::<CLINT>::mtimer_enable();
102102
}
103103

104104
/// Disables the `MTIMER` peripheral.
105105
#[inline]
106106
pub fn disable_mtimer() {
107-
$crate::aclint::CLINT::<CLINT>::disable_mtimer();
107+
$crate::aclint::CLINT::<CLINT>::mtimer_disable();
108108
}
109109

110110
/// Returns the `MSWI` peripheral.

src/plic.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,18 @@ impl<P: Plic> PLIC<P> {
127127

128128
const PENDINGS_OFFSET: usize = 0x1000;
129129

130+
/// Returns `true` if a machine external interrupt is pending.
131+
#[inline]
132+
pub fn is_interrupting() -> bool {
133+
riscv::register::mip::read().mext()
134+
}
135+
136+
/// Returns true if Machine External Interrupts are enabled.
137+
#[inline]
138+
pub fn is_enabled() -> bool {
139+
riscv::register::mie::read().mext()
140+
}
141+
130142
/// Sets the Machine External Interrupt bit of the `mie` CSR.
131143
/// This bit must be set for the PLIC to trigger machine external interrupts.
132144
///
@@ -156,16 +168,14 @@ impl<P: Plic> PLIC<P> {
156168
}
157169

158170
/// Returns the pendings register of the PLIC.
159-
/// This register allows to check if an interrupt source is pending.
160-
/// This register is shared among all the contexts.
171+
/// This register allows to check if a particular interrupt source is pending.
161172
#[inline]
162173
pub fn pendings() -> pendings::PENDINGS {
163174
// SAFETY: valid address
164175
unsafe { pendings::PENDINGS::new(P::BASE + Self::PENDINGS_OFFSET) }
165176
}
166177

167-
/// Returns the context proxy of a given context.
168-
/// This proxy provides access to the PLIC registers of the given context.
178+
/// Returns a proxy to access to all the PLIC registers of a given context.
169179
#[inline]
170180
pub fn ctx<C: ContextNumber>(context: C) -> CTX<P> {
171181
// SAFETY: valid context number

0 commit comments

Comments
 (0)