Skip to content

Commit aa56cb4

Browse files
authored
Merge pull request #140 from rust-embedded/remove-bit-field
Remove bit_field dependency
2 parents a38fb8d + 4344b03 commit aa56cb4

20 files changed

+136
-159
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ Cargo.lock
22
target/
33

44
.vscode/
5+
.DS_Store

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1616

1717
### Changed
1818

19+
- Removed `bit_field` dependency
1920
- CI actions updated. They now use `checkout@v3` and `dtolnay/rust-toolchain`.
2021
- `mcause::{Interrupt, Exception}` and `scause::{Interrupt, Exception}` now implement `From` trait for `usize`
2122
- Set safety of `asm::nop` and `asm::delay` functions to safe.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ critical-section-single-hart = ["critical-section/restore-state-bool"]
2323
plic = ["volatile-register"]
2424

2525
[dependencies]
26-
bit_field = "0.10.0"
2726
critical-section = "1.1.0"
2827
embedded-hal = "0.2.6"
2928
volatile-register = { version = "0.2.1", optional = true }

src/register/fcsr.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Floating-point control and status register
22
3-
use bit_field::BitField;
4-
53
/// Floating-point control and status register
64
#[derive(Clone, Copy, Debug)]
75
pub struct FCSR {
@@ -35,31 +33,31 @@ impl Flags {
3533
/// Inexact
3634
#[inline]
3735
pub fn nx(&self) -> bool {
38-
self.0.get_bit(0)
36+
self.0 & (1 << 0) != 0
3937
}
4038

4139
/// Underflow
4240
#[inline]
4341
pub fn uf(&self) -> bool {
44-
self.0.get_bit(1)
42+
self.0 & (1 << 1) != 0
4543
}
4644

4745
/// Overflow
4846
#[inline]
4947
pub fn of(&self) -> bool {
50-
self.0.get_bit(2)
48+
self.0 & (1 << 2) != 0
5149
}
5250

5351
/// Divide by Zero
5452
#[inline]
5553
pub fn dz(&self) -> bool {
56-
self.0.get_bit(3)
54+
self.0 & (1 << 3) != 0
5755
}
5856

5957
/// Invalid Operation
6058
#[inline]
6159
pub fn nv(&self) -> bool {
62-
self.0.get_bit(4)
60+
self.0 & (1 << 4) != 0
6361
}
6462
}
6563

@@ -84,13 +82,14 @@ impl FCSR {
8482
/// Accrued Exception Flags
8583
#[inline]
8684
pub fn fflags(&self) -> Flags {
87-
Flags(self.bits.get_bits(0..5))
85+
Flags(self.bits & 0x1F) // bits 0-4
8886
}
8987

9088
/// Rounding Mode
9189
#[inline]
9290
pub fn frm(&self) -> RoundingMode {
93-
match self.bits.get_bits(5..8) {
91+
let frm = (self.bits >> 5) & 0x7; // bits 5-7
92+
match frm {
9493
0b000 => RoundingMode::RoundToNearestEven,
9594
0b001 => RoundingMode::RoundTowardsZero,
9695
0b010 => RoundingMode::RoundDown,

src/register/macros.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,9 @@ macro_rules! set_pmp {
229229
assert!(index < 8);
230230

231231
let mut value = _read();
232+
value &= !(0xFF << (8 * index)); // clear previous value
232233
let byte = (locked as usize) << 7 | (range as usize) << 3 | (permission as usize);
233-
value.set_bits(8 * index..=8 * index + 7, byte);
234+
value |= byte << (8 * index);
234235
_write(value);
235236
}
236237
};
@@ -248,7 +249,7 @@ macro_rules! clear_pmp {
248249
assert!(index < 8);
249250

250251
let mut value = _read();
251-
value.set_bits(8 * index..=8 * index + 7, 0);
252+
value &= !(0xFF << (8 * index)); // clear previous value
252253
_write(value);
253254
}
254255
};

src/register/mcounteren.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! mcounteren register
22
3-
use bit_field::BitField;
4-
53
/// mcounteren register
64
#[derive(Clone, Copy, Debug)]
75
pub struct Mcounteren {
@@ -12,26 +10,26 @@ impl Mcounteren {
1210
/// Supervisor "cycle\[h\]" Enable
1311
#[inline]
1412
pub fn cy(&self) -> bool {
15-
self.bits.get_bit(0)
13+
self.bits & (1 << 0) != 0
1614
}
1715

1816
/// Supervisor "time\[h\]" Enable
1917
#[inline]
2018
pub fn tm(&self) -> bool {
21-
self.bits.get_bit(1)
19+
self.bits & (1 << 1) != 0
2220
}
2321

2422
/// Supervisor "instret\[h\]" Enable
2523
#[inline]
2624
pub fn ir(&self) -> bool {
27-
self.bits.get_bit(2)
25+
self.bits & (1 << 2) != 0
2826
}
2927

3028
/// Supervisor "hpm\[x\]" Enable (bits 3-31)
3129
#[inline]
3230
pub fn hpm(&self, index: usize) -> bool {
3331
assert!((3..32).contains(&index));
34-
self.bits.get_bit(index)
32+
self.bits & (1 << index) != 0
3533
}
3634
}
3735

src/register/medeleg.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! medeleg register
22
3-
use bit_field::BitField;
4-
53
/// medeleg register
64
#[derive(Clone, Copy, Debug)]
75
pub struct Medeleg {
@@ -18,85 +16,85 @@ impl Medeleg {
1816
/// Instruction Address Misaligned Delegate
1917
#[inline]
2018
pub fn instruction_misaligned(&self) -> bool {
21-
self.bits.get_bit(0)
19+
self.bits & (1 << 0) != 0
2220
}
2321

2422
/// Instruction Access Fault Delegate
2523
#[inline]
2624
pub fn instruction_fault(&self) -> bool {
27-
self.bits.get_bit(1)
25+
self.bits & (1 << 1) != 0
2826
}
2927

3028
/// Illegal Instruction Delegate
3129
#[inline]
3230
pub fn illegal_instruction(&self) -> bool {
33-
self.bits.get_bit(2)
31+
self.bits & (1 << 2) != 0
3432
}
3533

3634
/// Breakpoint Delegate
3735
#[inline]
3836
pub fn breakpoint(&self) -> bool {
39-
self.bits.get_bit(3)
37+
self.bits & (1 << 3) != 0
4038
}
4139

4240
/// Load Address Misaligned Delegate
4341
#[inline]
4442
pub fn load_misaligned(&self) -> bool {
45-
self.bits.get_bit(4)
43+
self.bits & (1 << 4) != 0
4644
}
4745

4846
/// Load Access Fault Delegate
4947
#[inline]
5048
pub fn load_fault(&self) -> bool {
51-
self.bits.get_bit(5)
49+
self.bits & (1 << 5) != 0
5250
}
5351

5452
/// Store/AMO Address Misaligned Delegate
5553
#[inline]
5654
pub fn store_misaligned(&self) -> bool {
57-
self.bits.get_bit(6)
55+
self.bits & (1 << 6) != 0
5856
}
5957

6058
/// Store/AMO Access Fault Delegate
6159
#[inline]
6260
pub fn store_fault(&self) -> bool {
63-
self.bits.get_bit(7)
61+
self.bits & (1 << 7) != 0
6462
}
6563

6664
/// Environment Call from U-mode Delegate
6765
#[inline]
6866
pub fn user_env_call(&self) -> bool {
69-
self.bits.get_bit(8)
67+
self.bits & (1 << 8) != 0
7068
}
7169

7270
/// Environment Call from S-mode Delegate
7371
#[inline]
7472
pub fn supervisor_env_call(&self) -> bool {
75-
self.bits.get_bit(9)
73+
self.bits & (1 << 9) != 0
7674
}
7775

7876
/// Environment Call from M-mode Delegate
7977
#[inline]
8078
pub fn machine_env_call(&self) -> bool {
81-
self.bits.get_bit(11)
79+
self.bits & (1 << 11) != 0
8280
}
8381

8482
/// Instruction Page Fault Delegate
8583
#[inline]
8684
pub fn instruction_page_fault(&self) -> bool {
87-
self.bits.get_bit(12)
85+
self.bits & (1 << 12) != 0
8886
}
8987

9088
/// Load Page Fault Delegate
9189
#[inline]
9290
pub fn load_page_fault(&self) -> bool {
93-
self.bits.get_bit(13)
91+
self.bits & (1 << 13) != 0
9492
}
9593

9694
/// Store/AMO Page Fault Delegate
9795
#[inline]
9896
pub fn store_page_fault(&self) -> bool {
99-
self.bits.get_bit(15)
97+
self.bits & (1 << 15) != 0
10098
}
10199
}
102100

src/register/mideleg.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! mideleg register
22
3-
use bit_field::BitField;
4-
53
/// mideleg register
64
#[derive(Clone, Copy, Debug)]
75
pub struct Mideleg {
@@ -18,37 +16,37 @@ impl Mideleg {
1816
/// User Software Interrupt Delegate
1917
#[inline]
2018
pub fn usoft(&self) -> bool {
21-
self.bits.get_bit(0)
19+
self.bits & (1 << 0) != 0
2220
}
2321

2422
/// Supervisor Software Interrupt Delegate
2523
#[inline]
2624
pub fn ssoft(&self) -> bool {
27-
self.bits.get_bit(1)
25+
self.bits & (1 << 1) != 0
2826
}
2927

3028
/// User Timer Interrupt Delegate
3129
#[inline]
3230
pub fn utimer(&self) -> bool {
33-
self.bits.get_bit(4)
31+
self.bits & (1 << 4) != 0
3432
}
3533

3634
/// Supervisor Timer Interrupt Delegate
3735
#[inline]
3836
pub fn stimer(&self) -> bool {
39-
self.bits.get_bit(5)
37+
self.bits & (1 << 5) != 0
4038
}
4139

4240
/// User External Interrupt Delegate
4341
#[inline]
4442
pub fn uext(&self) -> bool {
45-
self.bits.get_bit(8)
43+
self.bits & (1 << 8) != 0
4644
}
4745

4846
/// Supervisor External Interrupt Delegate
4947
#[inline]
5048
pub fn sext(&self) -> bool {
51-
self.bits.get_bit(9)
49+
self.bits & (1 << 9) != 0
5250
}
5351
}
5452

src/register/mie.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! mie register
22
3-
use bit_field::BitField;
4-
53
/// mie register
64
#[derive(Clone, Copy, Debug)]
75
pub struct Mie {
@@ -18,55 +16,55 @@ impl Mie {
1816
/// User Software Interrupt Enable
1917
#[inline]
2018
pub fn usoft(&self) -> bool {
21-
self.bits.get_bit(0)
19+
self.bits & (1 << 0) != 0
2220
}
2321

2422
/// Supervisor Software Interrupt Enable
2523
#[inline]
2624
pub fn ssoft(&self) -> bool {
27-
self.bits.get_bit(1)
25+
self.bits & (1 << 1) != 0
2826
}
2927

3028
/// Machine Software Interrupt Enable
3129
#[inline]
3230
pub fn msoft(&self) -> bool {
33-
self.bits.get_bit(3)
31+
self.bits & (1 << 3) != 0
3432
}
3533

3634
/// User Timer Interrupt Enable
3735
#[inline]
3836
pub fn utimer(&self) -> bool {
39-
self.bits.get_bit(4)
37+
self.bits & (1 << 4) != 0
4038
}
4139

4240
/// Supervisor Timer Interrupt Enable
4341
#[inline]
4442
pub fn stimer(&self) -> bool {
45-
self.bits.get_bit(5)
43+
self.bits & (1 << 5) != 0
4644
}
4745

4846
/// Machine Timer Interrupt Enable
4947
#[inline]
5048
pub fn mtimer(&self) -> bool {
51-
self.bits.get_bit(7)
49+
self.bits & (1 << 7) != 0
5250
}
5351

5452
/// User External Interrupt Enable
5553
#[inline]
5654
pub fn uext(&self) -> bool {
57-
self.bits.get_bit(8)
55+
self.bits & (1 << 8) != 0
5856
}
5957

6058
/// Supervisor External Interrupt Enable
6159
#[inline]
6260
pub fn sext(&self) -> bool {
63-
self.bits.get_bit(9)
61+
self.bits & (1 << 9) != 0
6462
}
6563

6664
/// Machine External Interrupt Enable
6765
#[inline]
6866
pub fn mext(&self) -> bool {
69-
self.bits.get_bit(11)
67+
self.bits & (1 << 11) != 0
7068
}
7169
}
7270

0 commit comments

Comments
 (0)