@@ -33,7 +33,7 @@ pub fn render(
33
33
let rty = rsize. to_ty ( ) ?;
34
34
let description = util:: respace ( & register. description ) ;
35
35
36
- let unsafety = :: generate :: unsafety ( register. write_constraint . as_ref ( ) , rsize) ;
36
+ let unsafety = unsafety ( register. write_constraint . as_ref ( ) , rsize) ;
37
37
38
38
let mut mod_items = vec ! [ ] ;
39
39
let mut reg_impl_items = vec ! [ ] ;
@@ -577,7 +577,7 @@ pub fn fields(
577
577
578
578
let mut proxy_items = vec ! [ ] ;
579
579
580
- let mut unsafety = :: generate :: unsafety ( f. write_constraint , f. width ) ;
580
+ let mut unsafety = unsafety ( f. write_constraint , f. width ) ;
581
581
let bits = & f. bits ;
582
582
let fty = & f. ty ;
583
583
let offset = & f. offset ;
@@ -804,6 +804,25 @@ pub fn fields(
804
804
Ok ( ( ) )
805
805
}
806
806
807
+ fn unsafety ( write_constraint : Option < & WriteConstraint > , width : u32 ) -> Option < Ident > {
808
+ match write_constraint {
809
+ Some ( & WriteConstraint :: Range ( ref range) )
810
+ if range. min as u64 == 0 && range. max as u64 == ( 1u64 << width) - 1 =>
811
+ {
812
+ // the SVD has acknowledged that it's safe to write
813
+ // any value that can fit in the field
814
+ None
815
+ }
816
+ None if width == 1 => {
817
+ // the field is one bit wide, so we assume it's legal to write
818
+ // either value into it or it wouldn't exist; despite that
819
+ // if a writeConstraint exists then respect it
820
+ None
821
+ }
822
+ _ => Some ( Ident :: new ( "unsafe" ) ) ,
823
+ }
824
+ }
825
+
807
826
#[ derive( Clone , Debug ) ]
808
827
pub struct Base < ' a > {
809
828
pub peripheral : Option < & ' a str > ,
0 commit comments