Skip to content

Commit 2366617

Browse files
committed
use modular_bitfield in cmse.rs
1 parent fd6a9db commit 2366617

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ links = "cortex-m" # prevent multiple versions of this crate to be linked toget
1919
bare-metal = { version = "0.2.0", features = ["const-fn"] }
2020
volatile-register = "0.2.0"
2121
bitfield = "0.13.2"
22+
modular-bitfield = "0.10"
2223
embedded-hal = "0.2.4"
2324

2425
[features]

src/cmse.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
//! ```
3434
3535
use crate::asm::{tt, tta, ttat, ttt};
36-
use bitfield::bitfield;
36+
use modular_bitfield::bitfield;
3737

3838
/// Memory access behaviour: determine which privilege execution mode is used and which Memory
3939
/// Protection Unit (MPU) is used.
@@ -62,35 +62,35 @@ pub struct TestTarget {
6262
access_type: AccessType,
6363
}
6464

65-
bitfield! {
66-
/// Test Target Response Payload
67-
///
68-
/// Provides the response payload from a TT, TTA, TTT or TTAT instruction.
69-
#[derive(PartialEq, Copy, Clone)]
70-
struct TtResp(u32);
71-
impl Debug;
72-
mregion, _: 7, 0;
73-
sregion, _: 15, 8;
74-
mrvalid, _: 16;
75-
srvalid, _: 17;
76-
r, _: 18;
77-
rw, _: 19;
78-
nsr, _: 20;
79-
nsrw, _: 21;
80-
s, _: 22;
81-
irvalid, _: 23;
82-
iregion, _: 31, 24;
65+
/// Test Target Response Payload
66+
///
67+
/// Provides the response payload from a TT, TTA, TTT or TTAT instruction.
68+
#[bitfield]
69+
#[repr(u32)]
70+
#[derive(Debug, Copy, Clone, PartialEq)]
71+
pub struct TtResp {
72+
mregion: u8,
73+
sregion: u8,
74+
mrvalid: bool,
75+
srvalid: bool,
76+
r: bool,
77+
rw: bool,
78+
nsr: bool,
79+
nsrw: bool,
80+
s: bool,
81+
irvalid: bool,
82+
iregion: u8,
8383
}
8484

8585
impl TestTarget {
8686
/// Creates a Test Target Response Payload by testing addr using access_type.
8787
#[inline]
8888
pub fn check(addr: *mut u32, access_type: AccessType) -> Self {
8989
let tt_resp = match access_type {
90-
AccessType::Current => TtResp(tt(addr)),
91-
AccessType::Unprivileged => TtResp(ttt(addr)),
92-
AccessType::NonSecure => TtResp(tta(addr)),
93-
AccessType::NonSecureUnprivileged => TtResp(ttat(addr)),
90+
AccessType::Current => TtResp::from(tt(addr)),
91+
AccessType::Unprivileged => TtResp::from(ttt(addr)),
92+
AccessType::NonSecure => TtResp::from(tta(addr)),
93+
AccessType::NonSecureUnprivileged => TtResp::from(ttat(addr)),
9494
};
9595

9696
TestTarget {
@@ -140,7 +140,7 @@ impl TestTarget {
140140
/// Get the raw u32 value returned by the TT instruction used.
141141
#[inline]
142142
pub fn as_u32(self) -> u32 {
143-
self.tt_resp.0
143+
u32::from(self.tt_resp)
144144
}
145145

146146
/// Read accessibility of the target address. Only returns the MPU settings without checking

0 commit comments

Comments
 (0)