Skip to content

Commit a686546

Browse files
committed
Add riscv to device
1 parent 0f73e45 commit a686546

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

svd-encoder/src/device.rs

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ impl Encode for Device {
3434
elem.children.push(new_node("licenseText", v.clone()));
3535
}
3636

37+
// TODO not sure if this is the correct position
38+
if let Some(v) = &self.riscv {
39+
elem.children
40+
.push(XMLNode::Element(v.encode_with_config(config)?));
41+
}
42+
3743
if let Some(v) = &self.cpu {
3844
elem.children
3945
.push(XMLNode::Element(v.encode_with_config(config)?));

svd-parser/src/device.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use super::*;
2-
use crate::svd::{cpu::Cpu, peripheral::Peripheral, registerproperties::RegisterProperties};
2+
use crate::svd::{
3+
cpu::Cpu, peripheral::Peripheral, registerproperties::RegisterProperties, riscv::Riscv,
4+
};
35

46
/// Parses a SVD file
57
impl Parse for Device {
@@ -18,6 +20,7 @@ impl Parse for Device {
1820
.name(tree.get_child_text("name")?)
1921
.series(tree.get_child_text_opt("series")?)
2022
.license_text(tree.get_child_text_opt("licenseText")?)
23+
.riscv(optional::<Riscv>("riscv", tree, config)?)
2124
.cpu(optional::<Cpu>("cpu", tree, config)?)
2225
.header_system_filename(tree.get_child_text_opt("headerSystemFilename")?)
2326
.header_definitions_prefix(tree.get_child_text_opt("headerDefinitionsPrefix")?)

svd-rs/src/device.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{
2-
BuildError, Cpu, Description, EmptyToNone, Name, Peripheral, RegisterProperties, SvdError,
3-
ValidateLevel,
2+
BuildError, Cpu, Description, EmptyToNone, Name, Peripheral, RegisterProperties, Riscv,
3+
SvdError, ValidateLevel,
44
};
55

66
/// Errors for [`Device::validate`]
@@ -105,6 +105,13 @@ pub struct Device {
105105
/// Specify the compliant CMSIS-SVD schema version
106106
#[cfg_attr(feature = "serde", serde(skip, default = "default_schema_version"))]
107107
pub schema_version: String,
108+
109+
/// Describe the processor included in the device
110+
#[cfg_attr(
111+
feature = "serde",
112+
serde(default, skip_serializing_if = "Option::is_none")
113+
)]
114+
pub riscv: Option<Riscv>,
108115
}
109116

110117
fn default_xmlns_xs() -> String {
@@ -130,6 +137,7 @@ pub struct DeviceBuilder {
130137
version: Option<String>,
131138
description: Option<String>,
132139
license_text: Option<String>,
140+
riscv: Option<Riscv>,
133141
cpu: Option<Cpu>,
134142
header_system_filename: Option<String>,
135143
header_definitions_prefix: Option<String>,
@@ -152,6 +160,7 @@ impl From<Device> for DeviceBuilder {
152160
version: Some(d.version),
153161
description: Some(d.description),
154162
license_text: d.license_text,
163+
riscv: d.riscv,
155164
cpu: d.cpu,
156165
header_system_filename: d.header_system_filename,
157166
header_definitions_prefix: d.header_definitions_prefix,
@@ -202,6 +211,11 @@ impl DeviceBuilder {
202211
self.license_text = value;
203212
self
204213
}
214+
/// Set the riscv of the device.
215+
pub fn riscv(mut self, value: Option<Riscv>) -> Self {
216+
self.riscv = value;
217+
self
218+
}
205219
/// Set the cpu of the device.
206220
pub fn cpu(mut self, value: Option<Cpu>) -> Self {
207221
self.cpu = value;
@@ -283,6 +297,7 @@ impl DeviceBuilder {
283297
})
284298
.ok_or_else(|| BuildError::Uninitialized("description".to_string()))?,
285299
license_text: self.license_text,
300+
riscv: self.riscv,
286301
cpu: self.cpu,
287302
header_system_filename: self.header_system_filename,
288303
header_definitions_prefix: self.header_definitions_prefix,
@@ -341,6 +356,9 @@ impl Device {
341356
if builder.license_text.is_some() {
342357
self.license_text = builder.license_text.empty_to_none();
343358
}
359+
if builder.riscv.is_some() {
360+
self.riscv = builder.riscv;
361+
}
344362
if builder.cpu.is_some() {
345363
self.cpu = builder.cpu;
346364
}

svd-rs/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ pub use self::datatype::DataType;
9696

9797
/// Custom objects for the RISC-V ecosystem
9898
pub mod riscv;
99+
pub use self::riscv::Riscv;
99100

100101
/// Level of validation
101102
#[derive(Clone, Copy, Debug, PartialEq, Eq)]

0 commit comments

Comments
 (0)