Skip to content

Commit 72c6782

Browse files
committed
make W.bits safe if WriteConstraint indicates so
i.e. if WriteConstraint::Range covers the whole range of values that the bitfield can take
1 parent c3de973 commit 72c6782

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,9 @@ either = "1.0.3"
1616
error-chain = "0.10.0"
1717
inflections = "1.0.0"
1818
quote = "0.3.15"
19-
svd-parser = "0.4.0"
20-
syn = "0.11.9"
19+
# svd-parser = "0.4.0"
20+
syn = "0.11.9"
21+
22+
[dependencies.svd-parser]
23+
git = "https://github.com/japaric/svd"
24+
branch = "follow-up"

src/generate.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use cast::u64;
55
use either::Either;
66
use quote::Tokens;
77
use svd::{Access, BitRange, Defaults, Device, EnumeratedValues, Field,
8-
Peripheral, Register, Usage};
8+
Peripheral, Register, Usage, WriteConstraint};
99
use syn::{Ident, Lit};
1010

1111
use errors::*;
@@ -504,6 +504,7 @@ pub fn fields(
504504
sc: Ident,
505505
ty: Ident,
506506
width: u32,
507+
write_constraint: Option<&'a WriteConstraint>,
507508
}
508509

509510
impl<'a> F<'a> {
@@ -538,6 +539,7 @@ pub fn fields(
538539
name: &f.name,
539540
offset: util::unsuffixed(u64(f.bit_range.offset)),
540541
ty: width.to_ty()?,
542+
write_constraint: f.write_constraint.as_ref(),
541543
})
542544
}
543545
}
@@ -793,6 +795,19 @@ pub fn fields(
793795
let mut proxy_items = vec![];
794796

795797
let mut safety = Some(Ident::new("unsafe"));
798+
if let Some(write_constraint) = f.write_constraint {
799+
match *write_constraint {
800+
WriteConstraint::Range(ref range) => {
801+
if range.min == 0 &&
802+
range.max == (1 << f.width) - 1 {
803+
// the SVD has acknowledged that it's safe to write
804+
// any value that can fit in the bitfield
805+
safety = None;
806+
}
807+
},
808+
_ => {}
809+
}
810+
}
796811
let fty = &f.ty;
797812
let offset = &f.offset;
798813
let mask = &f.mask;

0 commit comments

Comments
 (0)