1
1
//! mip register
2
2
3
+ use crate :: bits:: { bf_extract, bf_insert} ;
4
+ use riscv_pac:: CoreInterruptNumber ;
5
+
3
6
read_write_csr ! {
4
7
/// `mip` register
5
8
Mip : 0x344 ,
6
- mask: 0xaaa ,
9
+ mask: usize :: MAX ,
7
10
}
8
11
9
12
read_write_csr_field ! {
@@ -42,6 +45,26 @@ read_only_csr_field! {
42
45
mext: 11 ,
43
46
}
44
47
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
+ /// Clear the pending state of a specific core interrupt source.
56
+ ///
57
+ /// # Safety
58
+ ///
59
+ /// Not all interrupt sources allow clearing of pending interrupts via the `mip` register.
60
+ /// Instead, it may be necessary to perform an alternative action to clear the interrupt.
61
+ /// Check the specification of your target chip for details.
62
+ #[ inline]
63
+ pub unsafe fn clear_pending < I : CoreInterruptNumber > ( & mut self , interrupt : I ) {
64
+ self . bits = bf_insert ( self . bits , interrupt. number ( ) , 1 , 0 ) ;
65
+ }
66
+ }
67
+
45
68
set ! ( 0x344 ) ;
46
69
clear ! ( 0x344 ) ;
47
70
@@ -55,6 +78,17 @@ set_clear_csr!(
55
78
/// Supervisor External Interrupt Pending
56
79
, set_sext, clear_sext, 1 << 9 ) ;
57
80
81
+ /// Clear the pending state of a specific core interrupt source.
82
+ ///
83
+ /// # Safety
84
+ ///
85
+ /// Not all interrupt sources allow clearing of pending interrupts via the `mip` register.
86
+ /// Instead, it may be necessary to perform an alternative action to clear the interrupt.
87
+ /// Check the specification of your target chip for details.
88
+ pub unsafe fn clear_pending < I : CoreInterruptNumber > ( interrupt : I ) {
89
+ _clear ( 1 << interrupt. number ( ) ) ;
90
+ }
91
+
58
92
#[ cfg( test) ]
59
93
mod tests {
60
94
use super :: * ;
0 commit comments