Skip to content

Commit e89942d

Browse files
committed
move WriteConstraint to make_register
1 parent cb407d0 commit e89942d

File tree

2 files changed

+28
-50
lines changed

2 files changed

+28
-50
lines changed

src/patch/mod.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use svd_parser::svd::{
99
AddressBlockUsage, ClusterInfo, ClusterInfoBuilder, Cpu, CpuBuilder, Endian, EnumeratedValue,
1010
EnumeratedValues, EnumeratedValuesBuilder, FieldInfo, FieldInfoBuilder, Interrupt,
1111
PeripheralInfo, PeripheralInfoBuilder, RegisterCluster, RegisterInfo, RegisterInfoBuilder,
12-
RegisterProperties, Usage, ValidateLevel,
12+
RegisterProperties, Usage, ValidateLevel, WriteConstraint, WriteConstraintRange,
1313
};
1414
use svd_parser::SVDError::DimIndexParse;
1515
use svd_rs::{DimElement, DimElementBuilder, MaybeArray};
@@ -423,6 +423,32 @@ fn make_register(radd: &Hash) -> Result<RegisterInfoBuilder> {
423423
if let Some(address_offset) = radd.get_i64("addressOffset")? {
424424
rnew = rnew.address_offset(address_offset as u32);
425425
}
426+
427+
if let Some(write_constraint) = radd
428+
.get(&"_write_constraint".to_yaml())
429+
.or_else(|| radd.get(&"writeConstraint".to_yaml()))
430+
{
431+
let wc = match write_constraint {
432+
Yaml::String(s) if s == "none" => {
433+
// Completely remove the existing writeConstraint
434+
None
435+
}
436+
Yaml::String(s) if s == "enum" => {
437+
// Only allow enumerated values
438+
Some(WriteConstraint::UseEnumeratedValues(true))
439+
}
440+
Yaml::Array(a) => {
441+
// Allow a certain range
442+
Some(WriteConstraint::Range(WriteConstraintRange {
443+
min: a[0].i64()? as u64,
444+
max: a[1].i64()? as u64,
445+
}))
446+
}
447+
_ => return Err(anyhow!("Unknown writeConstraint type {write_constraint:?}")),
448+
};
449+
rnew = rnew.write_constraint(wc);
450+
}
451+
426452
Ok(rnew)
427453
}
428454

src/patch/peripheral.rs

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::{anyhow, Context};
22
use svd_parser::svd::{
33
self, Cluster, ClusterInfo, DimElement, Interrupt, Peripheral, Register, RegisterCluster,
4-
RegisterInfo, WriteConstraint, WriteConstraintRange,
4+
RegisterInfo,
55
};
66
use yaml_rust::{yaml::Hash, Yaml};
77

@@ -417,30 +417,6 @@ impl RegisterBlockExt for Peripheral {
417417
let dim = make_dim_element(rmod)?;
418418
for rtag in rtags {
419419
modify_dim_element(rtag, &dim)?;
420-
if let Some(value) = rmod
421-
.get(&"_write_constraint".to_yaml())
422-
.or_else(|| rmod.get(&"writeConstraint".to_yaml()))
423-
{
424-
let wc = match value {
425-
Yaml::String(s) if s == "none" => {
426-
// Completely remove the existing writeConstraint
427-
None
428-
}
429-
Yaml::String(s) if s == "enum" => {
430-
// Only allow enumerated values
431-
Some(WriteConstraint::UseEnumeratedValues(true))
432-
}
433-
Yaml::Array(a) => {
434-
// Allow a certain range
435-
Some(WriteConstraint::Range(WriteConstraintRange {
436-
min: a[0].i64()? as u64,
437-
max: a[1].i64()? as u64,
438-
}))
439-
}
440-
_ => return Err(anyhow!("Unknown writeConstraint type {value:?}")),
441-
};
442-
rtag.write_constraint = wc;
443-
}
444420
rtag.modify_from(register_builder.clone(), VAL_LVL)?;
445421
if let Some("") = rmod.get_str("access")? {
446422
rtag.properties.access = None;
@@ -905,30 +881,6 @@ impl RegisterBlockExt for Cluster {
905881
let dim = make_dim_element(rmod)?;
906882
for rtag in rtags {
907883
modify_dim_element(rtag, &dim)?;
908-
if let Some(value) = rmod
909-
.get(&"_write_constraint".to_yaml())
910-
.or_else(|| rmod.get(&"writeConstraint".to_yaml()))
911-
{
912-
let wc = match value {
913-
Yaml::String(s) if s == "none" => {
914-
// Completely remove the existing writeConstraint
915-
None
916-
}
917-
Yaml::String(s) if s == "enum" => {
918-
// Only allow enumerated values
919-
Some(WriteConstraint::UseEnumeratedValues(true))
920-
}
921-
Yaml::Array(a) => {
922-
// Allow a certain range
923-
Some(WriteConstraint::Range(WriteConstraintRange {
924-
min: a[0].i64()? as u64,
925-
max: a[1].i64()? as u64,
926-
}))
927-
}
928-
_ => return Err(anyhow!("Unknown writeConstraint type {value:?}")),
929-
};
930-
rtag.write_constraint = wc;
931-
}
932884
rtag.modify_from(register_builder.clone(), VAL_LVL)?;
933885
if let Some("") = rmod.get_str("access")? {
934886
rtag.properties.access = None;

0 commit comments

Comments
 (0)