Skip to content

Commit d40059c

Browse files
bors[bot]burrbull
andauthored
Merge #171
171: add missing entries to Cpu r=Emilgardis a=burrbull except `sauRegionsConfig` Co-authored-by: Andrey Zgarbul <[email protected]>
2 parents 376727e + 8e6ecba commit d40059c

File tree

4 files changed

+181
-6
lines changed

4 files changed

+181
-6
lines changed

svd-encoder/src/cpu.rs

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,50 @@ impl Encode for Cpu {
55
type Error = EncodeError;
66

77
fn encode(&self) -> Result<Element, EncodeError> {
8-
let children = vec![
8+
let mut children = vec![
99
new_node("name", self.name.clone()),
1010
new_node("revision", self.revision.clone()),
1111
self.endian.encode_node()?,
1212
new_node("mpuPresent", format!("{}", self.mpu_present)),
1313
new_node("fpuPresent", format!("{}", self.fpu_present)),
14-
new_node("nvicPrioBits", format!("{}", self.nvic_priority_bits)),
15-
new_node(
16-
"vendorSystickConfig",
17-
format!("{}", self.has_vendor_systick),
18-
),
1914
];
15+
if let Some(v) = &self.fpu_double_precision {
16+
children.push(new_node("fpuDP", format!("{}", v)));
17+
}
18+
if let Some(v) = &self.dsp_present {
19+
children.push(new_node("dspPresent", format!("{}", v)));
20+
}
21+
if let Some(v) = &self.icache_present {
22+
children.push(new_node("icachePresent", format!("{}", v)));
23+
}
24+
if let Some(v) = &self.dcache_present {
25+
children.push(new_node("dcachePresent", format!("{}", v)));
26+
}
27+
if let Some(v) = &self.itcm_present {
28+
children.push(new_node("itcmPresent", format!("{}", v)));
29+
}
30+
if let Some(v) = &self.dtcm_present {
31+
children.push(new_node("dtcmPresent", format!("{}", v)));
32+
}
33+
if let Some(v) = &self.vtor_present {
34+
children.push(new_node("vtorPresent", format!("{}", v)));
35+
}
36+
children.push(new_node(
37+
"nvicPrioBits",
38+
format!("{}", self.nvic_priority_bits),
39+
));
40+
children.push(new_node(
41+
"vendorSystickConfig",
42+
format!("{}", self.has_vendor_systick),
43+
));
44+
45+
if let Some(v) = &self.device_num_interrupts {
46+
children.push(new_node("deviceNumInterrupts", format!("{}", v)));
47+
}
48+
if let Some(v) = &self.sau_num_regions {
49+
children.push(new_node("sauNumRegions", format!("{}", v)));
50+
}
51+
2052
let mut elem = Element::new("cpu");
2153
elem.children = children;
2254
Ok(elem)

svd-parser/src/cpu.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::*;
22
use crate::svd::{Cpu, Endian};
3+
use crate::types::BoolParse;
34

45
impl Parse for Cpu {
56
type Object = Self;
@@ -17,8 +18,17 @@ impl Parse for Cpu {
1718
.endian(Endian::parse(&tree.get_child_elem("endian")?, config)?)
1819
.mpu_present(tree.get_child_bool("mpuPresent")?)
1920
.fpu_present(tree.get_child_bool("fpuPresent")?)
21+
.fpu_double_precision(optional::<BoolParse>("fpuDP", tree, &())?)
22+
.dsp_present(optional::<BoolParse>("dspPresent", tree, &())?)
23+
.icache_present(optional::<BoolParse>("icachePresent", tree, &())?)
24+
.dcache_present(optional::<BoolParse>("dcachePresent", tree, &())?)
25+
.itcm_present(optional::<BoolParse>("itcmPresent", tree, &())?)
26+
.dtcm_present(optional::<BoolParse>("dtcmPresent", tree, &())?)
27+
.vtor_present(optional::<BoolParse>("vtorPresent", tree, &())?)
2028
.nvic_priority_bits(tree.get_child_u32("nvicPrioBits")?)
2129
.has_vendor_systick(tree.get_child_bool("vendorSystickConfig")?)
30+
.device_num_interrupts(optional::<u32>("deviceNumInterrupts", tree, &())?)
31+
.sau_num_regions(optional::<u32>("sauNumRegions", tree, &())?)
2232
.build(config.validate_level)
2333
.map_err(|e| SVDError::from(e).at(tree.id()))
2434
}

svd-rs/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+
- Add optional entries to `Cpu`
1011
- `AddressBlock` now uses builder
1112
- Add `dim_name` and `dim_array_index` to `DimElement`
1213
- Add `alternate_peripheral`, `prepend_to_name`, `append_to_name`,

svd-rs/src/cpu.rs

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,44 @@ pub struct Cpu {
2323
/// Indicate whether the processor is equipped with a hardware floating point unit (FPU)
2424
pub fpu_present: bool,
2525

26+
/// Indicate whether the processor is equipped with a double precision floating point unit.
27+
/// This element is valid only when `fpu_present` is set to `true`
28+
#[cfg_attr(feature = "serde", serde(rename = "fpuDP"))]
29+
pub fpu_double_precision: Option<bool>,
30+
31+
/// Indicates whether the processor implements the optional SIMD DSP extensions (DSP)
32+
pub dsp_present: Option<bool>,
33+
34+
/// Indicate whether the processor has an instruction cache
35+
pub icache_present: Option<bool>,
36+
37+
/// Indicate whether the processor has a data cache
38+
pub dcache_present: Option<bool>,
39+
40+
/// Indicate whether the processor has an instruction tightly coupled memory
41+
pub itcm_present: Option<bool>,
42+
43+
/// Indicate whether the processor has a data tightly coupled memory
44+
pub dtcm_present: Option<bool>,
45+
46+
/// Indicate whether the Vector Table Offset Register (VTOR) is implemented.
47+
/// If not specified, then VTOR is assumed to be present
48+
pub vtor_present: Option<bool>,
49+
2650
/// Define the number of bits available in the Nested Vectored Interrupt Controller (NVIC) for configuring priority
51+
#[cfg_attr(feature = "serde", serde(rename = "nvicPrioBits"))]
2752
pub nvic_priority_bits: u32,
2853

2954
/// Indicate whether the processor implements a vendor-specific System Tick Timer
55+
#[cfg_attr(feature = "serde", serde(rename = "vendorSystickConfig"))]
3056
pub has_vendor_systick: bool,
57+
58+
/// Add 1 to the highest interrupt number and specify this number in here
59+
pub device_num_interrupts: Option<u32>,
60+
61+
/// Indicate the amount of regions in the Security Attribution Unit (SAU)
62+
pub sau_num_regions: Option<u32>,
63+
// sauRegionsConfig
3164
}
3265

3366
/// Builder for [`Cpu`]
@@ -38,8 +71,17 @@ pub struct CpuBuilder {
3871
endian: Option<Endian>,
3972
mpu_present: Option<bool>,
4073
fpu_present: Option<bool>,
74+
fpu_double_precision: Option<bool>,
75+
dsp_present: Option<bool>,
76+
icache_present: Option<bool>,
77+
dcache_present: Option<bool>,
78+
itcm_present: Option<bool>,
79+
dtcm_present: Option<bool>,
80+
vtor_present: Option<bool>,
4181
nvic_priority_bits: Option<u32>,
4282
has_vendor_systick: Option<bool>,
83+
device_num_interrupts: Option<u32>,
84+
sau_num_regions: Option<u32>,
4385
}
4486

4587
impl From<Cpu> for CpuBuilder {
@@ -50,8 +92,17 @@ impl From<Cpu> for CpuBuilder {
5092
endian: Some(c.endian),
5193
mpu_present: Some(c.mpu_present),
5294
fpu_present: Some(c.fpu_present),
95+
fpu_double_precision: c.fpu_double_precision,
96+
dsp_present: c.dsp_present,
97+
icache_present: c.icache_present,
98+
dcache_present: c.dcache_present,
99+
itcm_present: c.itcm_present,
100+
dtcm_present: c.dtcm_present,
101+
vtor_present: c.vtor_present,
53102
nvic_priority_bits: Some(c.nvic_priority_bits),
54103
has_vendor_systick: Some(c.has_vendor_systick),
104+
device_num_interrupts: c.device_num_interrupts,
105+
sau_num_regions: c.sau_num_regions,
55106
}
56107
}
57108
}
@@ -82,6 +133,41 @@ impl CpuBuilder {
82133
self.fpu_present = Some(value);
83134
self
84135
}
136+
/// Set the fpu_double_precision of the cpu.
137+
pub fn fpu_double_precision(mut self, value: Option<bool>) -> Self {
138+
self.fpu_double_precision = value;
139+
self
140+
}
141+
/// Set the dsp_present of the cpu.
142+
pub fn dsp_present(mut self, value: Option<bool>) -> Self {
143+
self.dsp_present = value;
144+
self
145+
}
146+
/// Set the icache_present of the cpu.
147+
pub fn icache_present(mut self, value: Option<bool>) -> Self {
148+
self.icache_present = value;
149+
self
150+
}
151+
/// Set the dcache_present of the cpu.
152+
pub fn dcache_present(mut self, value: Option<bool>) -> Self {
153+
self.dcache_present = value;
154+
self
155+
}
156+
/// Set the itcm_present of the cpu.
157+
pub fn itcm_present(mut self, value: Option<bool>) -> Self {
158+
self.itcm_present = value;
159+
self
160+
}
161+
/// Set the dtcm_present of the cpu.
162+
pub fn dtcm_present(mut self, value: Option<bool>) -> Self {
163+
self.dtcm_present = value;
164+
self
165+
}
166+
/// Set the vtor_present of the cpu.
167+
pub fn vtor_present(mut self, value: Option<bool>) -> Self {
168+
self.vtor_present = value;
169+
self
170+
}
85171
/// Set the nvic_priority_bits of the cpu.
86172
pub fn nvic_priority_bits(mut self, value: u32) -> Self {
87173
self.nvic_priority_bits = Some(value);
@@ -92,6 +178,16 @@ impl CpuBuilder {
92178
self.has_vendor_systick = Some(value);
93179
self
94180
}
181+
/// Set the device_num_interrupts of the cpu.
182+
pub fn device_num_interrupts(mut self, value: Option<u32>) -> Self {
183+
self.device_num_interrupts = value;
184+
self
185+
}
186+
/// Set the sau_num_regions of the cpu.
187+
pub fn sau_num_regions(mut self, value: Option<u32>) -> Self {
188+
self.sau_num_regions = value;
189+
self
190+
}
95191
/// Validate and build a [`Cpu`].
96192
pub fn build(self, lvl: ValidateLevel) -> Result<Cpu, SvdError> {
97193
let mut cpu = Cpu {
@@ -110,12 +206,21 @@ impl CpuBuilder {
110206
fpu_present: self
111207
.fpu_present
112208
.ok_or_else(|| BuildError::Uninitialized("fpu_present".to_string()))?,
209+
fpu_double_precision: self.fpu_double_precision,
210+
dsp_present: self.dsp_present,
211+
icache_present: self.icache_present,
212+
dcache_present: self.dcache_present,
213+
itcm_present: self.itcm_present,
214+
dtcm_present: self.dtcm_present,
215+
vtor_present: self.vtor_present,
113216
nvic_priority_bits: self
114217
.nvic_priority_bits
115218
.ok_or_else(|| BuildError::Uninitialized("nvic_priority_bits".to_string()))?,
116219
has_vendor_systick: self
117220
.has_vendor_systick
118221
.ok_or_else(|| BuildError::Uninitialized("has_vendor_systick".to_string()))?,
222+
device_num_interrupts: self.device_num_interrupts,
223+
sau_num_regions: self.sau_num_regions,
119224
};
120225
if !lvl.is_disabled() {
121226
cpu.validate(lvl)?;
@@ -146,12 +251,39 @@ impl Cpu {
146251
if let Some(fpu_present) = builder.fpu_present {
147252
self.fpu_present = fpu_present;
148253
}
254+
if builder.fpu_double_precision.is_some() {
255+
self.fpu_double_precision = builder.fpu_double_precision;
256+
}
257+
if builder.dsp_present.is_some() {
258+
self.dsp_present = builder.dsp_present;
259+
}
260+
if builder.icache_present.is_some() {
261+
self.icache_present = builder.icache_present;
262+
}
263+
if builder.dcache_present.is_some() {
264+
self.dcache_present = builder.dcache_present;
265+
}
266+
if builder.itcm_present.is_some() {
267+
self.itcm_present = builder.itcm_present;
268+
}
269+
if builder.dtcm_present.is_some() {
270+
self.dtcm_present = builder.dtcm_present;
271+
}
272+
if builder.vtor_present.is_some() {
273+
self.vtor_present = builder.vtor_present;
274+
}
149275
if let Some(nvic_priority_bits) = builder.nvic_priority_bits {
150276
self.nvic_priority_bits = nvic_priority_bits;
151277
}
152278
if let Some(has_vendor_systick) = builder.has_vendor_systick {
153279
self.has_vendor_systick = has_vendor_systick;
154280
}
281+
if builder.device_num_interrupts.is_some() {
282+
self.device_num_interrupts = builder.device_num_interrupts;
283+
}
284+
if builder.sau_num_regions.is_some() {
285+
self.sau_num_regions = builder.sau_num_regions;
286+
}
155287
if !lvl.is_disabled() {
156288
self.validate(lvl)
157289
} else {

0 commit comments

Comments
 (0)