Skip to content

Commit 5479937

Browse files
committed
ignore derived peripheral
1 parent b8d3f7d commit 5479937

File tree

1 file changed

+43
-11
lines changed

1 file changed

+43
-11
lines changed

src/mmap/mmap_cli.rs

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,15 @@ fn to_text(peripherals: &[Peripheral]) -> String {
6666
&mut rmmap,
6767
&mut pcov,
6868
);
69-
get_peripheral(p, &mut mmap, pcov);
69+
get_peripheral(
70+
p,
71+
&mut mmap,
72+
if p.derived_from.is_some() {
73+
CoveredFields::default()
74+
} else {
75+
pcov
76+
},
77+
);
7078
get_interrupts(p, &mut mmap);
7179
mmap.extend(rmmap);
7280
coverage += pcov;
@@ -83,7 +91,15 @@ fn to_text(peripherals: &[Peripheral]) -> String {
8391
&mut rmmap,
8492
&mut pcov,
8593
);
86-
get_peripheral(&pi, &mut mmap, pcov);
94+
get_peripheral(
95+
&pi,
96+
&mut mmap,
97+
if pi.derived_from.is_some() {
98+
CoveredFields::default()
99+
} else {
100+
pcov
101+
},
102+
);
87103
get_interrupts(&pi, &mut mmap);
88104
mmap.extend(rmmap);
89105
coverage += pcov;
@@ -116,13 +132,21 @@ fn get_periph_registers<'a>(
116132
}
117133

118134
fn get_peripheral(peripheral: &PeripheralInfo, mmap: &mut Vec<String>, coverage: CoveredFields) {
119-
let text = format!(
120-
"{} A PERIPHERAL {} ({}/{} fields covered)",
121-
str_utils::format_address(peripheral.base_address),
122-
peripheral.name,
123-
coverage.covered,
124-
coverage.all,
125-
);
135+
let text = if coverage.all > 0 {
136+
format!(
137+
"{} A PERIPHERAL {} ({}/{} fields covered)",
138+
str_utils::format_address(peripheral.base_address),
139+
peripheral.name,
140+
coverage.covered,
141+
coverage.all,
142+
)
143+
} else {
144+
format!(
145+
"{} A PERIPHERAL {}",
146+
str_utils::format_address(peripheral.base_address),
147+
peripheral.name,
148+
)
149+
};
126150
mmap.push(text);
127151
}
128152

@@ -277,7 +301,7 @@ fn is_covered(f: &FieldInfo) -> bool {
277301
mod tests {
278302
use super::*;
279303

280-
static SVD: &str = r"
304+
static SVD: &str = r##"
281305
<device>
282306
<name>dev</name>
283307
<peripherals>
@@ -361,8 +385,13 @@ mod tests {
361385
</register>
362386
</registers>
363387
</peripheral>
388+
<peripheral derivedFrom="PeriphB">
389+
<name>PeriphC</name>
390+
<description>Peripheral C</description>
391+
<baseAddress>0x10020000</baseAddress>
392+
</peripheral>
364393
</peripherals>
365-
</device>";
394+
</device>"##;
366395

367396
static EXPECTED_MMAP: &str = r"0x10000000 A PERIPHERAL PeriphA (1/2 fields covered)
368397
0x10000010 B REGISTER REG1: Register A1
@@ -372,6 +401,9 @@ mod tests {
372401
0x10010000 A PERIPHERAL PeriphB (1/1 fields covered)
373402
0x10010010 B REGISTER REG1: Register B1
374403
0x10010010 C FIELD 10w01 F3: Field 3
404+
0x10020000 A PERIPHERAL PeriphC
405+
0x10020010 B REGISTER REG1: Register B1
406+
0x10020010 C FIELD 10w01 F3: Field 3
375407
INTERRUPT 001: INT_A1 (PeriphA): Interrupt A1
376408
INTERRUPT 002: INT_B2 (PeriphB): Interrupt B2";
377409

0 commit comments

Comments
 (0)