|
1 | 1 | use anyhow::{anyhow, Context};
|
2 | 2 | use svd_parser::svd::{
|
3 | 3 | self, Cluster, ClusterInfo, DimElement, Interrupt, Peripheral, Register, RegisterCluster,
|
4 |
| - RegisterInfo, |
| 4 | + RegisterInfo, WriteConstraint, WriteConstraintRange, |
5 | 5 | };
|
6 | 6 | use yaml_rust::{yaml::Hash, Yaml};
|
7 | 7 |
|
@@ -417,6 +417,30 @@ impl RegisterBlockExt for Peripheral {
|
417 | 417 | let dim = make_dim_element(rmod)?;
|
418 | 418 | for rtag in rtags {
|
419 | 419 | 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 | + } |
420 | 444 | rtag.modify_from(register_builder.clone(), VAL_LVL)?;
|
421 | 445 | if let Some("") = rmod.get_str("access")? {
|
422 | 446 | rtag.properties.access = None;
|
@@ -881,6 +905,30 @@ impl RegisterBlockExt for Cluster {
|
881 | 905 | let dim = make_dim_element(rmod)?;
|
882 | 906 | for rtag in rtags {
|
883 | 907 | 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 | + } |
884 | 932 | rtag.modify_from(register_builder.clone(), VAL_LVL)?;
|
885 | 933 | if let Some("") = rmod.get_str("access")? {
|
886 | 934 | rtag.properties.access = None;
|
|
0 commit comments