Skip to content

Commit d4c2c9a

Browse files
committed
Alternative cluster size computation
I believe that this computes the correct size for a cluster that contains overlapping registers (such as the ATSAMD21G that I've added to the tests in this commit). It comes at the cost of not recognizing the overlapping registers at that stage.
1 parent 64fb696 commit d4c2c9a

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

src/generate/peripheral.rs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -197,40 +197,27 @@ fn expand(
197197
Ok(ercs_expanded)
198198
}
199199

200-
/// Recursively calculate the size of a cluster. A cluster's size is the sum of
201-
/// all of its children clusters and registers
200+
/// Recursively calculate the size of a cluster. A cluster's size is the maximum
201+
/// end position of its recursive children.
202202
fn cluster_size_in_bits(info: &ClusterInfo, defs: &Defaults) -> Result<u32> {
203-
// Cluster size is the summation of the size of each of the cluster's children.
204-
let mut offset = 0;
205203
let mut size = 0;
206204

207205
for c in &info.children {
208-
size += match *c {
206+
let end = match *c {
209207
Either::Left(ref reg) => {
210-
let pad = reg.address_offset.checked_sub(offset)
211-
.ok_or_else(||
212-
format!("Warning! overlap while calculating Register Size within a Cluster! Cluster contents may be incorrectly aligned!"))?
213-
* BITS_PER_BYTE;
214-
215-
216208
let reg_size: u32 = expand_register(reg, defs, None)?
217209
.iter()
218210
.map(|rbf| rbf.size)
219211
.sum();
220212

221-
pad + reg_size
213+
(reg.address_offset * BITS_PER_BYTE) + reg_size
222214
}
223215
Either::Right(ref clust) => {
224-
let pad = clust.address_offset.checked_sub(offset)
225-
.ok_or_else(||
226-
format!("Warning! overlap while calculating Cluster Size within a Cluster! Cluster contents may be incorrectly aligned!"))?
227-
* BITS_PER_BYTE;
228-
229-
pad + cluster_size_in_bits(clust, defs)?
216+
(clust.address_offset * BITS_PER_BYTE) + cluster_size_in_bits(clust, defs)?
230217
}
231218
};
232219

233-
offset = size / BITS_PER_BYTE;
220+
size = size.max(end);
234221
}
235222
Ok(size)
236223
}

0 commit comments

Comments
 (0)