File tree 1 file changed +44
-0
lines changed
1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1
1
//! scounteren register
2
2
3
+ use crate :: result:: { Error , Result } ;
4
+
3
5
/// scounteren register
4
6
#[ derive( Clone , Copy , Debug ) ]
5
7
pub struct Scounteren {
@@ -31,6 +33,22 @@ impl Scounteren {
31
33
assert ! ( ( 3 ..32 ) . contains( & index) ) ;
32
34
self . bits & ( 1 << index) != 0
33
35
}
36
+
37
+ /// User "hpm\[x\]" Enable (bits 3-31)
38
+ ///
39
+ /// Attempts to read the "hpm\[x\]" value, and returns an error if the index is invalid.
40
+ #[ inline]
41
+ pub fn try_hpm ( & self , index : usize ) -> Result < bool > {
42
+ if ( 3 ..32 ) . contains ( & index) {
43
+ Ok ( self . bits & ( 1 << index) != 0 )
44
+ } else {
45
+ Err ( Error :: IndexOutOfBounds {
46
+ index,
47
+ min : 3 ,
48
+ max : 31 ,
49
+ } )
50
+ }
51
+ }
34
52
}
35
53
36
54
read_csr_as ! ( Scounteren , 0x106 ) ;
@@ -56,8 +74,34 @@ pub unsafe fn set_hpm(index: usize) {
56
74
_set ( 1 << index) ;
57
75
}
58
76
77
+ #[ inline]
78
+ pub unsafe fn try_set_hpm ( index : usize ) -> Result < ( ) > {
79
+ if ( 3 ..32 ) . contains ( & index) {
80
+ _try_set ( 1 << index)
81
+ } else {
82
+ Err ( Error :: IndexOutOfBounds {
83
+ index,
84
+ min : 3 ,
85
+ max : 31 ,
86
+ } )
87
+ }
88
+ }
89
+
59
90
#[ inline]
60
91
pub unsafe fn clear_hpm ( index : usize ) {
61
92
assert ! ( ( 3 ..32 ) . contains( & index) ) ;
62
93
_clear ( 1 << index) ;
63
94
}
95
+
96
+ #[ inline]
97
+ pub unsafe fn try_clear_hpm ( index : usize ) -> Result < ( ) > {
98
+ if ( 3 ..32 ) . contains ( & index) {
99
+ _try_clear ( 1 << index)
100
+ } else {
101
+ Err ( Error :: IndexOutOfBounds {
102
+ index,
103
+ min : 3 ,
104
+ max : 31 ,
105
+ } )
106
+ }
107
+ }
You can’t perform that action at this time.
0 commit comments