Skip to content

Commit 9e62f55

Browse files
committed
max cluster size
1 parent db301c5 commit 9e62f55

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
- Check cluster size, add `max_cluster_size` option
11+
1012
## [v0.25.0] - 2022-08-02
1113

1214
- Add `feature_peripheral` option which generates cfg features for each peripheral

src/generate/peripheral.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ fn expand_cluster(cluster: &Cluster, config: &Config) -> Result<Vec<RegisterBloc
670670
let mut cluster_expanded = vec![];
671671

672672
let cluster_size = cluster_info_size_in_bits(cluster, config)
673-
.with_context(|| format!("Cluster {} has no determinable `size` field", cluster.name))?;
673+
.with_context(|| format!("Can't calculate cluster {} size", cluster.name))?;
674674
let description = cluster
675675
.description
676676
.as_ref()
@@ -696,8 +696,17 @@ fn expand_cluster(cluster: &Cluster, config: &Config) -> Result<Vec<RegisterBloc
696696
})
697697
}
698698
Cluster::Array(info, array_info) => {
699-
let sequential_addresses =
700-
(array_info.dim == 1) || (cluster_size == array_info.dim_increment * BITS_PER_BYTE);
699+
let increment_bits = array_info.dim_increment * BITS_PER_BYTE;
700+
if cluster_size > increment_bits {
701+
let cname = &cluster.name;
702+
return Err(anyhow!("Cluster {cname} has size {cluster_size} bits that is more then array increment {increment_bits} bits"));
703+
}
704+
let cluster_size = if config.max_cluster_size {
705+
increment_bits
706+
} else {
707+
cluster_size
708+
};
709+
let sequential_addresses = (array_info.dim == 1) || (cluster_size == increment_bits);
701710

702711
// if dimIndex exists, test if it is a sequence of numbers from 0 to dim
703712
let sequential_indexes_from0 = array_info

src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ fn run() -> Result<()> {
8585
.long("feature_peripheral")
8686
.help("Use independent cfg feature flags for each peripheral"),
8787
)
88+
.arg(
89+
Arg::with_name("max_cluster_size")
90+
.long("max_cluster_size")
91+
.help("Use array increment for cluster size"),
92+
)
8893
.arg(
8994
Arg::with_name("make_mod")
9095
.long("make_mod")
@@ -183,6 +188,8 @@ fn run() -> Result<()> {
183188
cfg.bool_flag("feature_group", Filter::Arg) || cfg.bool_flag("feature_group", Filter::Conf);
184189
let feature_peripheral = cfg.bool_flag("feature_peripheral", Filter::Arg)
185190
|| cfg.bool_flag("feature_peripheral", Filter::Conf);
191+
let max_cluster_size = cfg.bool_flag("max_cluster_size", Filter::Arg)
192+
|| cfg.bool_flag("max_cluster_size", Filter::Conf);
186193

187194
let mut source_type = cfg
188195
.grab()
@@ -209,6 +216,7 @@ fn run() -> Result<()> {
209216
derive_more,
210217
feature_group,
211218
feature_peripheral,
219+
max_cluster_size,
212220
output_dir: path.clone(),
213221
source_type,
214222
};

src/util.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub const BITS_PER_BYTE: u32 = 8;
2222
/// that are not valid in Rust ident
2323
const BLACKLIST_CHARS: &[char] = &['(', ')', '[', ']', '/', ' ', '-'];
2424

25-
#[derive(Clone, PartialEq, Debug)]
25+
#[derive(Clone, PartialEq, Eq, Debug)]
2626
pub struct Config {
2727
pub target: Target,
2828
pub nightly: bool,
@@ -36,6 +36,7 @@ pub struct Config {
3636
pub derive_more: bool,
3737
pub feature_group: bool,
3838
pub feature_peripheral: bool,
39+
pub max_cluster_size: bool,
3940
pub output_dir: PathBuf,
4041
pub source_type: SourceType,
4142
}
@@ -55,6 +56,7 @@ impl Default for Config {
5556
derive_more: false,
5657
feature_group: false,
5758
feature_peripheral: false,
59+
max_cluster_size: false,
5860
output_dir: PathBuf::from("."),
5961
source_type: SourceType::default(),
6062
}
@@ -63,7 +65,7 @@ impl Default for Config {
6365

6466
#[allow(clippy::upper_case_acronyms)]
6567
#[allow(non_camel_case_types)]
66-
#[derive(Clone, Copy, PartialEq, Debug)]
68+
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
6769
pub enum Target {
6870
CortexM,
6971
Msp430,
@@ -93,7 +95,7 @@ impl Default for Target {
9395
}
9496
}
9597

96-
#[derive(Clone, Copy, PartialEq, Debug)]
98+
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
9799
pub enum SourceType {
98100
Xml,
99101
#[cfg(feature = "yaml")]

0 commit comments

Comments
 (0)