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/).
8
8
## Unreleased
9
9
10
10
- Revert the ` riscv ` elements, as well as the ` unstable-riscv ` feature.
11
+ - Add ` bitmask ` for ` FieldInfo ` , ` Field ` and ` RegisterInfo `
11
12
12
13
## [ v0.14.9] - 2024-08-20
13
14
@@ -143,4 +144,3 @@ Previous versions in common [changelog](../CHANGELOG.md).
143
144
[ v0.11.2 ] : https://github.com/rust-embedded/svd/compare/svd-rs-v0.11.1...svd-rs-v0.11.2
144
145
[ v0.11.1 ] : https://github.com/rust-embedded/svd/compare/v0.11.0...svd-rs-v0.11.1
145
146
[ 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 {
375
375
self . bit_range . msb ( )
376
376
}
377
377
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
+
378
384
/// Get enumeratedValues cluster by usage
379
385
pub fn get_enumerated_values ( & self , usage : Usage ) -> Option < & EnumeratedValues > {
380
386
match self . enumerated_values . len ( ) {
@@ -406,6 +412,21 @@ impl Field {
406
412
}
407
413
self . deref ( ) . validate_all ( lvl)
408
414
}
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
+ }
409
430
}
410
431
411
432
impl Name for FieldInfo {
Original file line number Diff line number Diff line change @@ -420,6 +420,11 @@ impl RegisterInfo {
420
420
pub fn get_mut_field ( & mut self , name : & str ) -> Option < & mut Field > {
421
421
self . fields_mut ( ) . find ( |f| f. name == name)
422
422
}
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
+ }
423
428
}
424
429
425
430
impl Register {
You can’t perform that action at this time.
0 commit comments