Skip to content

Commit

Permalink
Merge pull request #167 from kossnikita/write-constraint-register
Browse files Browse the repository at this point in the history
Write constraint register
  • Loading branch information
burrbull authored Oct 6, 2023
2 parents 4e12ba7 + e89942d commit 6525c97
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/html/html_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ fn parse_register(
"description": rtag.description.as_deref().map(sanitize),
"resetValue": format!("0x{:08X}", rtag.properties.reset_value.unwrap_or_default()),
"access": raccs,
"writeConstraint": rtag.write_constraint,
"fields": fields,
"table": table,
"fields_total": register_fields_total,
Expand Down
7 changes: 6 additions & 1 deletion src/html/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,15 @@ <h4>
</a>
</h4>
<p>{{ register.description }}</p>
<p>Offset: {{ register.offset }}, size: {{ register.size }}, reset: {{ register.resetValue }}, access: {{ register.access }}</p>
<p>
Offset: {{ register.offset }}, size: {{ register.size }}, reset: {{ register.resetValue }}, access: {{ register.access
}}{% if register.writeConstraint.range %}, allowed values: {{ register.writeConstraint.range.minimum }}-{{ register.writeConstraint.range.maximum }}{% endif %}
</p>
<div class="progress">

<div class="progress-bar progress-bar-success" style="width: {{ register.progress }}%"></div>
</div>
{% if register.fields_total > 0 %}
<p>
<em>
{{ register.fields_documented}}/{{ register.fields_total }}
Expand Down Expand Up @@ -215,6 +219,7 @@ <h4>
</div>
</div>
</div>
{% endif %}
<div class="container fields" id="{{ pname }}-{{ register.name }}-fields">
{% for field in register.fields %}
<div class="row">
Expand Down
28 changes: 27 additions & 1 deletion src/patch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use svd_parser::svd::{
AddressBlockUsage, ClusterInfo, ClusterInfoBuilder, Cpu, CpuBuilder, Endian, EnumeratedValue,
EnumeratedValues, EnumeratedValuesBuilder, FieldInfo, FieldInfoBuilder, Interrupt,
PeripheralInfo, PeripheralInfoBuilder, RegisterCluster, RegisterInfo, RegisterInfoBuilder,
RegisterProperties, Usage, ValidateLevel,
RegisterProperties, Usage, ValidateLevel, WriteConstraint, WriteConstraintRange,
};
use svd_parser::SVDError::DimIndexParse;
use svd_rs::{DimElement, DimElementBuilder, MaybeArray};
Expand Down Expand Up @@ -423,6 +423,32 @@ fn make_register(radd: &Hash) -> Result<RegisterInfoBuilder> {
if let Some(address_offset) = radd.get_i64("addressOffset")? {
rnew = rnew.address_offset(address_offset as u32);
}

if let Some(write_constraint) = radd
.get(&"_write_constraint".to_yaml())
.or_else(|| radd.get(&"writeConstraint".to_yaml()))
{
let wc = match write_constraint {
Yaml::String(s) if s == "none" => {
// Completely remove the existing writeConstraint
None
}
Yaml::String(s) if s == "enum" => {
// Only allow enumerated values
Some(WriteConstraint::UseEnumeratedValues(true))
}
Yaml::Array(a) => {
// Allow a certain range
Some(WriteConstraint::Range(WriteConstraintRange {
min: a[0].i64()? as u64,
max: a[1].i64()? as u64,
}))
}
_ => return Err(anyhow!("Unknown writeConstraint type {write_constraint:?}")),
};
rnew = rnew.write_constraint(wc);
}

Ok(rnew)
}

Expand Down

0 comments on commit 6525c97

Please sign in to comment.