File tree Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88## Unreleased
99
1010- Revert the ` riscv ` elements, as well as the ` unstable-riscv ` feature.
11+ - Add ` bitmask ` for ` FieldInfo ` , ` Field ` and ` RegisterInfo `
1112
1213## [ v0.14.9] - 2024-08-20
1314
@@ -143,4 +144,3 @@ Previous versions in common [changelog](../CHANGELOG.md).
143144[ v0.11.2 ] : https://github.com/rust-embedded/svd/compare/svd-rs-v0.11.1...svd-rs-v0.11.2
144145[ v0.11.1 ] : https://github.com/rust-embedded/svd/compare/v0.11.0...svd-rs-v0.11.1
145146[ v0.11.0 ] : https://github.com/rust-embedded/svd/compare/v0.10.2...v0.11.0
146-
Original file line number Diff line number Diff line change @@ -375,6 +375,12 @@ impl FieldInfo {
375375 self . bit_range . msb ( )
376376 }
377377
378+ /// Get bits which is affected by field
379+ pub fn bitmask ( & self ) -> u64 {
380+ let BitRange { offset, width, .. } = self . bit_range ;
381+ ( !0u64 >> ( 64 - width) ) << offset
382+ }
383+
378384 /// Get enumeratedValues cluster by usage
379385 pub fn get_enumerated_values ( & self , usage : Usage ) -> Option < & EnumeratedValues > {
380386 match self . enumerated_values . len ( ) {
@@ -406,6 +412,21 @@ impl Field {
406412 }
407413 self . deref ( ) . validate_all ( lvl)
408414 }
415+
416+ /// Get bits which is affected by field or field array
417+ pub fn bitmask ( & self ) -> u64 {
418+ match self {
419+ Field :: Single ( f) => f. bitmask ( ) ,
420+ Field :: Array ( f, d) => {
421+ let mask = f. bitmask ( ) ;
422+ let mut bits = 0 ;
423+ for i in 0 ..d. dim {
424+ bits |= mask << ( i * d. dim_increment ) ;
425+ }
426+ bits
427+ }
428+ }
429+ }
409430}
410431
411432impl Name for FieldInfo {
Original file line number Diff line number Diff line change @@ -420,6 +420,11 @@ impl RegisterInfo {
420420 pub fn get_mut_field ( & mut self , name : & str ) -> Option < & mut Field > {
421421 self . fields_mut ( ) . find ( |f| f. name == name)
422422 }
423+
424+ /// Get bits which is affected by register fields
425+ pub fn bitmask ( & self ) -> u64 {
426+ self . fields ( ) . fold ( 0 , |mask, f| mask | f. bitmask ( ) )
427+ }
423428}
424429
425430impl Register {
You can’t perform that action at this time.
0 commit comments