11//! mip register
22
3- read_write_csr ! {
3+ use crate :: bits:: bf_extract;
4+ use riscv_pac:: CoreInterruptNumber ;
5+
6+ read_only_csr ! {
47 /// `mip` register
58 Mip : 0x344 ,
6- mask: 0xaaa ,
9+ mask: usize :: MAX ,
710}
811
9- read_write_csr_field ! {
12+ read_only_csr_field ! {
1013 Mip ,
1114 /// Supervisor Software Interrupt Pending
1215 ssoft: 1 ,
@@ -18,7 +21,7 @@ read_only_csr_field! {
1821 msoft: 3 ,
1922}
2023
21- read_write_csr_field ! {
24+ read_only_csr_field ! {
2225 Mip ,
2326 /// Supervisor Timer Interrupt Pending
2427 stimer: 5 ,
@@ -30,7 +33,7 @@ read_only_csr_field! {
3033 mtimer: 7 ,
3134}
3235
33- read_write_csr_field ! {
36+ read_only_csr_field ! {
3437 Mip ,
3538 /// Supervisor External Interrupt Pending
3639 sext: 9 ,
@@ -42,6 +45,14 @@ read_only_csr_field! {
4245 mext: 11 ,
4346}
4447
48+ impl Mip {
49+ /// Returns true when a given interrupt is pending.
50+ #[ inline]
51+ pub fn is_pending < I : CoreInterruptNumber > ( & self , interrupt : I ) -> bool {
52+ bf_extract ( self . bits , interrupt. number ( ) , 1 ) != 0
53+ }
54+ }
55+
4556set ! ( 0x344 ) ;
4657clear ! ( 0x344 ) ;
4758
@@ -55,6 +66,18 @@ set_clear_csr!(
5566 /// Supervisor External Interrupt Pending
5667 , set_sext, clear_sext, 1 << 9 ) ;
5768
69+ /// Clear the pending state of a specific core interrupt source.
70+ ///
71+ /// # Safety
72+ ///
73+ /// Not all interrupt sources allow clearing of pending interrupts via the `mip` register.
74+ /// Instead, it may be necessary to perform an alternative action to clear the interrupt.
75+ /// Check the specification of your target chip for details.
76+ #[ inline]
77+ pub unsafe fn clear_pending < I : CoreInterruptNumber > ( interrupt : I ) {
78+ _clear ( 1 << interrupt. number ( ) ) ;
79+ }
80+
5881#[ cfg( test) ]
5982mod tests {
6083 use super :: * ;
0 commit comments