File tree Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77
88## [ Unreleased]
99
10+ ### Added
11+
12+ - New convenience ` try_new ` and ` new ` associated functions for ` Mtvec ` and ` Stvec ` .
13+
1014### Changed
1115
1216- Use ` cfg(any(target_arch = "riscv32", target_arch = "riscv64")) ` instead of ` cfg(riscv) ` .
Original file line number Diff line number Diff line change @@ -28,6 +28,25 @@ read_write_csr_field! {
2828}
2929
3030impl Mtvec {
31+ /// Creates a new `Mtvec` with the given address and trap mode.
32+ ///
33+ /// # Note
34+ ///
35+ /// Panics if the address is not aligned to 4-bytes.
36+ #[ inline]
37+ pub fn new ( address : usize , trap_mode : TrapMode ) -> Self {
38+ Self :: try_new ( address, trap_mode) . unwrap ( )
39+ }
40+
41+ /// Attempts to create a new `Mtvec` with the given address and trap mode.
42+ #[ inline]
43+ pub fn try_new ( address : usize , trap_mode : TrapMode ) -> Result < Self > {
44+ let mut mtvec = Self :: from_bits ( 0 ) ;
45+ mtvec. try_set_address ( address) ?;
46+ mtvec. set_trap_mode ( trap_mode) ;
47+ Ok ( mtvec)
48+ }
49+
3150 /// Returns the trap-vector base-address
3251 #[ inline]
3352 pub const fn address ( & self ) -> usize {
Original file line number Diff line number Diff line change @@ -19,6 +19,25 @@ read_write_csr_field! {
1919}
2020
2121impl Stvec {
22+ /// Creates a new `Stvec` with the given address and trap mode.
23+ ///
24+ /// # Note
25+ ///
26+ /// Panics if the address is not aligned to 4-bytes.
27+ #[ inline]
28+ pub fn new ( address : usize , trap_mode : TrapMode ) -> Self {
29+ Self :: try_new ( address, trap_mode) . unwrap ( )
30+ }
31+
32+ /// Attempts to create a new `Stvec` with the given address and trap mode.
33+ #[ inline]
34+ pub fn try_new ( address : usize , trap_mode : TrapMode ) -> Result < Self > {
35+ let mut stvec = Stvec :: from_bits ( 0 ) ;
36+ stvec. try_set_address ( address) ?;
37+ stvec. set_trap_mode ( trap_mode) ;
38+ Ok ( stvec)
39+ }
40+
2241 /// Returns the trap-vector base-address
2342 #[ inline]
2443 pub const fn address ( & self ) -> usize {
You can’t perform that action at this time.
0 commit comments