Skip to content

Commit 8fd4016

Browse files
bors[bot]burrbull
andauthored
Merge #661
661: fix max_cluster_size end _reserved r=Emilgardis a=burrbull Co-authored-by: Andrey Zgarbul <[email protected]>
2 parents 336314f + 1d53785 commit 8fd4016

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

CHANGELOG.md

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

88
## [Unreleased]
99

10+
- Fix adding ending reserved field when `max_cluster_size` option enabled
1011
- Add `Eq` autoimplementation for enums
1112
- Use `critical_section::with` instead of `interrupt::free` for `Peripherals::take`.
1213
- Bring documentation on how to generate MSP430 PACs up to date (in line with

src/generate/peripheral.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
201201
"Pushing {} register or cluster blocks into output",
202202
ercs.len()
203203
);
204-
let reg_block = register_or_cluster_block(&ercs, None, config)?;
204+
let reg_block = register_or_cluster_block(&ercs, None, None, config)?;
205205

206206
let open = Punct::new('{', Spacing::Alone);
207207
let close = Punct::new('}', Spacing::Alone);
@@ -485,6 +485,7 @@ fn make_comment(size: u32, offset: u32, description: &str) -> String {
485485
fn register_or_cluster_block(
486486
ercs: &[RegisterCluster],
487487
name: Option<&str>,
488+
size: Option<u32>,
488489
config: &Config,
489490
) -> Result<TokenStream> {
490491
let mut rbfs = TokenStream::new();
@@ -588,6 +589,19 @@ fn register_or_cluster_block(
588589
last_end = region.end;
589590
}
590591

592+
if let Some(size) = size {
593+
let pad = size
594+
.checked_sub(last_end)
595+
.ok_or_else(|| anyhow!("Incorrect block size"))?;
596+
if pad > 0 {
597+
let name = Ident::new("_reserved_end", span);
598+
let pad = util::hex(pad as u64);
599+
rbfs.extend(quote! {
600+
#name : [u8; #pad],
601+
});
602+
}
603+
}
604+
591605
let name = if let Some(name) = name {
592606
name.to_constant_case_ident(span)
593607
} else {
@@ -1022,7 +1036,14 @@ fn cluster_block(
10221036
let mod_items = render_ercs(&mut c.children, &cpath, index, config)?;
10231037

10241038
// Generate the register block.
1025-
let reg_block = register_or_cluster_block(&c.children, Some(&mod_name), config)?;
1039+
let cluster_size = match c {
1040+
Cluster::Array(_, array_info) if config.max_cluster_size => {
1041+
Some(array_info.dim_increment)
1042+
}
1043+
_ => None,
1044+
};
1045+
let reg_block =
1046+
register_or_cluster_block(&c.children, Some(&mod_name), cluster_size, config)?;
10261047

10271048
let mod_items = quote! {
10281049
#reg_block

0 commit comments

Comments
 (0)