Skip to content

Commit 578aebe

Browse files
authored
Merge pull request #227 from simpkins/derive_from
Skip checking the derivedFrom destination if it is an absolute name
2 parents 763135a + b9de3a4 commit 578aebe

File tree

9 files changed

+401
-6
lines changed

9 files changed

+401
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ itertools = "0.12.0"
5151
phf = { version = "0.11", features = ["macros"] }
5252

5353
[dev-dependencies]
54+
similar = "2.5.0"
5455
tempfile = "3.3"

res/cluster/esp32s3.svd

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?xml version="1.0" encoding="utf-8" standalone="no"?>
2+
<device schemaVersion="1.1"
3+
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
4+
xs:noNamespaceSchemaLocation="CMSIS-SVD_Schema_1_1.xsd">
5+
<name>ESP32S3</name>
6+
<peripherals>
7+
<peripheral>
8+
<name>USB0</name>
9+
<description>USB OTG (On-The-Go)</description>
10+
<groupName>USB</groupName>
11+
<baseAddress>0x60080000</baseAddress>
12+
<addressBlock>
13+
<offset>0x0</offset>
14+
<size>0x2A0</size>
15+
<usage>registers</usage>
16+
</addressBlock>
17+
<registers>
18+
<register>
19+
<name>DIEPCTL0</name>
20+
<addressOffset>0x900</addressOffset>
21+
<size>0x20</size>
22+
<resetValue>0x00008000</resetValue>
23+
<fields>
24+
<field>
25+
<name>D_MPS0</name>
26+
<bitOffset>0</bitOffset>
27+
<bitWidth>2</bitWidth>
28+
<access>read-write</access>
29+
</field>
30+
</fields>
31+
</register>
32+
<register>
33+
<name>DIEPINT0</name>
34+
<addressOffset>0x908</addressOffset>
35+
<size>0x20</size>
36+
<fields>
37+
<field>
38+
<name>D_XFERCOMPL0</name>
39+
<bitOffset>0</bitOffset>
40+
<bitWidth>1</bitWidth>
41+
<access>read-write</access>
42+
</field>
43+
</fields>
44+
</register>
45+
<register>
46+
<name>DIEPCTL1</name>
47+
<addressOffset>0x920</addressOffset>
48+
<size>0x20</size>
49+
<resetValue>0x00008000</resetValue>
50+
<fields>
51+
<field>
52+
<name>D_MPS1</name>
53+
<bitOffset>0</bitOffset>
54+
<bitWidth>11</bitWidth>
55+
<access>read-write</access>
56+
</field>
57+
</fields>
58+
</register>
59+
<register>
60+
<name>DIEPINT1</name>
61+
<addressOffset>0x928</addressOffset>
62+
<size>0x20</size>
63+
<fields>
64+
<field>
65+
<name>D_XFERCOMPL1</name>
66+
<bitOffset>0</bitOffset>
67+
<bitWidth>1</bitWidth>
68+
<access>read-write</access>
69+
</field>
70+
</fields>
71+
</register>
72+
<register>
73+
<name>DIEPCTL2</name>
74+
<addressOffset>0x940</addressOffset>
75+
<size>0x20</size>
76+
<resetValue>0x00008000</resetValue>
77+
<fields>
78+
<field>
79+
<name>D_MPS2</name>
80+
<bitOffset>0</bitOffset>
81+
<bitWidth>11</bitWidth>
82+
<access>read-write</access>
83+
</field>
84+
</fields>
85+
</register>
86+
<register>
87+
<name>DIEPINT2</name>
88+
<addressOffset>0x948</addressOffset>
89+
<size>0x20</size>
90+
<fields>
91+
<field>
92+
<name>D_XFERCOMPL2</name>
93+
<bitOffset>0</bitOffset>
94+
<bitWidth>1</bitWidth>
95+
<access>read-write</access>
96+
</field>
97+
</fields>
98+
</register>
99+
</registers>
100+
</peripheral>
101+
</peripherals>
102+
</device>

res/cluster/expected.svd

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?xml version="1.0" encoding="utf-8" standalone="no"?>
2+
<device schemaVersion="1.1"
3+
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
4+
xs:noNamespaceSchemaLocation="CMSIS-SVD_Schema_1_1.xsd">
5+
<name>ESP32S3</name>
6+
<peripherals>
7+
<peripheral>
8+
<name>USB0</name>
9+
<description>USB OTG (On-The-Go)</description>
10+
<groupName>USB</groupName>
11+
<baseAddress>0x60080000</baseAddress>
12+
<addressBlock>
13+
<offset>0x0</offset>
14+
<size>0x2A0</size>
15+
<usage>registers</usage>
16+
</addressBlock>
17+
<registers>
18+
<cluster>
19+
<name>IN_EP0</name>
20+
<description>Device IN Endpoint 0</description>
21+
<addressOffset>0x900</addressOffset>
22+
<register>
23+
<name>DIEPCTL</name>
24+
<addressOffset>0x0</addressOffset>
25+
<size>0x20</size>
26+
<resetValue>0x00008000</resetValue>
27+
<fields>
28+
<field>
29+
<name>MPS</name>
30+
<bitOffset>0</bitOffset>
31+
<bitWidth>2</bitWidth>
32+
<access>read-write</access>
33+
</field>
34+
</fields>
35+
</register>
36+
<register>
37+
<name>DIEPINT</name>
38+
<addressOffset>0x8</addressOffset>
39+
<size>0x20</size>
40+
<fields>
41+
<field>
42+
<name>XFERCOMPL</name>
43+
<bitOffset>0</bitOffset>
44+
<bitWidth>1</bitWidth>
45+
<access>read-write</access>
46+
</field>
47+
</fields>
48+
</register>
49+
</cluster>
50+
<cluster>
51+
<dim>2</dim>
52+
<dimIncrement>0x20</dimIncrement>
53+
<dimIndex>1-2</dimIndex>
54+
<name>IN_EP%s</name>
55+
<description>Device IN Endpoints 1-6</description>
56+
<addressOffset>0x920</addressOffset>
57+
<register>
58+
<name>DIEPCTL</name>
59+
<addressOffset>0x0</addressOffset>
60+
<size>0x20</size>
61+
<resetValue>0x00008000</resetValue>
62+
<fields>
63+
<field>
64+
<name>MPS</name>
65+
<bitOffset>0</bitOffset>
66+
<bitWidth>11</bitWidth>
67+
<access>read-write</access>
68+
</field>
69+
</fields>
70+
</register>
71+
<register>
72+
<name>DIEPINT</name>
73+
<addressOffset>0x8</addressOffset>
74+
<size>0x20</size>
75+
<fields>
76+
<field>
77+
<name>XFERCOMPL</name>
78+
<bitOffset>0</bitOffset>
79+
<bitWidth>1</bitWidth>
80+
<access>read-write</access>
81+
</field>
82+
</fields>
83+
</register>
84+
</cluster>
85+
</registers>
86+
</peripheral>
87+
</peripherals>
88+
</device>

res/cluster/patch.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
_svd: esp32s3.svd
2+
3+
USB0:
4+
_cluster:
5+
IN_EP0:
6+
description: "Device IN Endpoint 0"
7+
DIEPCTL0:
8+
name: DIEPCTL
9+
_modify:
10+
D_MPS0:
11+
name: MPS
12+
DIEPINT0:
13+
name: DIEPINT
14+
_modify:
15+
D_XFERCOMPL0:
16+
name: XFERCOMPL
17+
IN_EP%s:
18+
description: "Device IN Endpoints 1-6"
19+
DIEPCTL[1-6]:
20+
name: DIEPCTL
21+
_modify:
22+
D_MPS1:
23+
name: MPS
24+
DIEPINT[1-6]:
25+
name: DIEPINT
26+
_modify:
27+
D_XFERCOMPL1:
28+
name: XFERCOMPL

res/cross_cluster_derive/expected.svd

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?xml version="1.0" encoding="utf-8" standalone="no"?>
2+
<device schemaVersion="1.1"
3+
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
4+
xs:noNamespaceSchemaLocation="CMSIS-SVD_Schema_1_1.xsd">
5+
<name>ESP32S3</name>
6+
<peripherals>
7+
<peripheral>
8+
<name>USB0</name>
9+
<description>USB OTG (On-The-Go)</description>
10+
<groupName>USB</groupName>
11+
<baseAddress>0x60080000</baseAddress>
12+
<addressBlock>
13+
<offset>0x0</offset>
14+
<size>0x2A0</size>
15+
<usage>registers</usage>
16+
</addressBlock>
17+
<registers>
18+
<cluster>
19+
<name>IN_EP0</name>
20+
<description>Device IN Endpoint 0</description>
21+
<addressOffset>0x900</addressOffset>
22+
<register>
23+
<name>DIEPCTL</name>
24+
<addressOffset>0x0</addressOffset>
25+
<size>0x20</size>
26+
<resetValue>0x00008000</resetValue>
27+
<fields>
28+
<field>
29+
<name>MPS</name>
30+
<bitOffset>0</bitOffset>
31+
<bitWidth>2</bitWidth>
32+
<access>read-write</access>
33+
</field>
34+
</fields>
35+
</register>
36+
<register>
37+
<name>DIEPINT</name>
38+
<addressOffset>0x8</addressOffset>
39+
<size>0x20</size>
40+
<fields>
41+
<field>
42+
<name>XFERCOMPL</name>
43+
<bitOffset>0</bitOffset>
44+
<bitWidth>1</bitWidth>
45+
<access>read-write</access>
46+
</field>
47+
</fields>
48+
</register>
49+
</cluster>
50+
<cluster>
51+
<dim>2</dim>
52+
<dimIncrement>0x20</dimIncrement>
53+
<dimIndex>1-2</dimIndex>
54+
<name>IN_EP%s</name>
55+
<description>Device IN Endpoints 1-6</description>
56+
<addressOffset>0x920</addressOffset>
57+
<register>
58+
<name>DIEPCTL</name>
59+
<addressOffset>0x0</addressOffset>
60+
<size>0x20</size>
61+
<resetValue>0x00008000</resetValue>
62+
<fields>
63+
<field>
64+
<name>MPS</name>
65+
<bitOffset>0</bitOffset>
66+
<bitWidth>11</bitWidth>
67+
<access>read-write</access>
68+
</field>
69+
</fields>
70+
</register>
71+
<register derivedFrom="USB0.IN_EP0.DIEPINT">
72+
<name>DIEPINT</name>
73+
<addressOffset>0x8</addressOffset>
74+
</register>
75+
</cluster>
76+
</registers>
77+
</peripheral>
78+
</peripherals>
79+
</device>

res/cross_cluster_derive/patch.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
_svd: ../cluster/esp32s3.svd
2+
3+
USB0:
4+
_cluster:
5+
# Endpoint 0 is different than the other endpoints, and does not have
6+
# quite the same register definitions. We therefore have to cluster it
7+
# by itself.
8+
IN_EP0:
9+
description: "Device IN Endpoint 0"
10+
DIEPCTL0:
11+
name: DIEPCTL
12+
_modify:
13+
D_MPS0:
14+
name: MPS
15+
DIEPINT0:
16+
name: DIEPINT
17+
_modify:
18+
D_XFERCOMPL0:
19+
name: XFERCOMPL
20+
# The remaining endpoints are all the same.
21+
IN_EP%s:
22+
description: "Device IN Endpoints 1-6"
23+
DIEPCTL[1-6]:
24+
name: DIEPCTL
25+
_modify:
26+
D_MPS1:
27+
name: MPS
28+
DIEPINT[1-6]:
29+
name: DIEPINT
30+
_modify:
31+
D_XFERCOMPL1:
32+
name: XFERCOMPL
33+
_derive:
34+
# The DIEPINT registers for endpoints 1-N are the same as endpoint 0,
35+
# so use the same type definition.
36+
DIEPINT: USB0.IN_EP0.DIEPINT

src/patch/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use yaml_rust::{yaml::Hash, Yaml, YamlLoader};
2020
use anyhow::{anyhow, Context, Result};
2121
pub type PatchResult = anyhow::Result<()>;
2222

23-
mod device;
23+
pub(crate) mod device;
2424
use device::DeviceExt;
2525
mod iterators;
2626
mod peripheral;

src/patch/peripheral.rs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,18 @@ pub(crate) trait RegisterBlockExt: Name {
255255
return Err(anyhow!("derive: incorrect syntax for {rname}"));
256256
};
257257

258-
self.get_reg(rderive).ok_or_else(|| {
259-
let present = self.present_registers();
260-
anyhow!("Could not find `{bpath}:{rderive}. Present registers: {present}.")
261-
})?;
258+
// Attempt to verify that the destination register name is correct.
259+
if rderive.contains('.') {
260+
// This is an absolute identifier name
261+
// TODO: at the moment we cannot verify absolute names. We don't have a reference
262+
// to the Device in order to try and look up the name. Since we are mutating a member
263+
// of the device, we cannot get a reference to it.
264+
} else {
265+
self.get_reg(rderive).ok_or_else(|| {
266+
let present = self.present_registers();
267+
anyhow!("Could not find `{bpath}:{rderive}. Present registers: {present}.")
268+
})?;
269+
}
262270

263271
match self.get_mut_reg(rname) {
264272
Some(register) => register.modify_from(info, VAL_LVL)?,
@@ -1498,3 +1506,20 @@ fn collect_in_cluster(
14981506
regs.insert(place, RegisterCluster::Cluster(cluster));
14991507
Ok(())
15001508
}
1509+
1510+
#[cfg(test)]
1511+
mod tests {
1512+
use crate::test_utils;
1513+
use anyhow::Result;
1514+
use std::path::Path;
1515+
1516+
#[test]
1517+
fn cluster() -> Result<()> {
1518+
test_utils::test_expected(Path::new("cluster"))
1519+
}
1520+
1521+
#[test]
1522+
fn cross_cluster_derive() -> Result<()> {
1523+
test_utils::test_expected(Path::new("cross_cluster_derive"))
1524+
}
1525+
}

0 commit comments

Comments
 (0)