1
1
//! mip register
2
2
3
- read_write_csr ! {
3
+ use crate :: bits:: bf_extract;
4
+ use riscv_pac:: CoreInterruptNumber ;
5
+
6
+ read_only_csr ! {
4
7
/// `mip` register
5
8
Mip : 0x344 ,
6
- mask: 0xaaa ,
9
+ mask: usize :: MAX ,
7
10
}
8
11
9
- read_write_csr_field ! {
12
+ read_only_csr_field ! {
10
13
Mip ,
11
14
/// Supervisor Software Interrupt Pending
12
15
ssoft: 1 ,
@@ -18,7 +21,7 @@ read_only_csr_field! {
18
21
msoft: 3 ,
19
22
}
20
23
21
- read_write_csr_field ! {
24
+ read_only_csr_field ! {
22
25
Mip ,
23
26
/// Supervisor Timer Interrupt Pending
24
27
stimer: 5 ,
@@ -30,7 +33,7 @@ read_only_csr_field! {
30
33
mtimer: 7 ,
31
34
}
32
35
33
- read_write_csr_field ! {
36
+ read_only_csr_field ! {
34
37
Mip ,
35
38
/// Supervisor External Interrupt Pending
36
39
sext: 9 ,
@@ -42,6 +45,14 @@ 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
+
45
56
set ! ( 0x344 ) ;
46
57
clear ! ( 0x344 ) ;
47
58
@@ -55,6 +66,18 @@ set_clear_csr!(
55
66
/// Supervisor External Interrupt Pending
56
67
, set_sext, clear_sext, 1 << 9 ) ;
57
68
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
+
58
81
#[ cfg( test) ]
59
82
mod tests {
60
83
use super :: * ;
0 commit comments