Skip to content

Commit 0f73e45

Browse files
committed
riscv section
1 parent 8194739 commit 0f73e45

File tree

13 files changed

+849
-0
lines changed

13 files changed

+849
-0
lines changed

svd-encoder/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 `riscv` element for configuration parameters related to RISC-V targets.
1011
- Bump MSRV to 1.65.0
1112

1213
## [v0.14.3] - 2023-11-15

svd-encoder/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,6 @@ mod readaction;
103103
mod register;
104104
mod registercluster;
105105
mod registerproperties;
106+
mod riscv;
106107
mod usage;
107108
mod writeconstraint;

svd-encoder/src/riscv.rs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
use super::{new_node, Config, Element, Encode, EncodeError, XMLNode};
2+
use crate::svd::riscv::{Hart, Priority, Riscv};
3+
4+
impl Encode for Riscv {
5+
type Error = EncodeError;
6+
7+
fn encode_with_config(&self, config: &Config) -> Result<Element, EncodeError> {
8+
let mut elem = Element::new("riscv");
9+
10+
if let Some(clic) = &self.clic {
11+
elem.children.push(new_node("clic", clic.clone()));
12+
}
13+
if let Some(clint) = &self.clint {
14+
elem.children.push(new_node("clint", clint.clone()));
15+
}
16+
if let Some(plic) = &self.plic {
17+
elem.children.push(new_node("plic", plic.clone()));
18+
}
19+
if !self.core_interrupts.is_empty() {
20+
let mut interrupts = Element::new("coreInterrupts");
21+
for interrupt in &self.core_interrupts {
22+
interrupts
23+
.children
24+
.push(interrupt.encode_node_with_config(config)?);
25+
}
26+
elem.children.push(XMLNode::Element(interrupts));
27+
}
28+
if !self.priorities.is_empty() {
29+
let mut priorities = Element::new("priorities");
30+
for priority in &self.priorities {
31+
priorities
32+
.children
33+
.push(priority.encode_node_with_config(config)?);
34+
}
35+
elem.children.push(XMLNode::Element(priorities));
36+
}
37+
if !self.harts.is_empty() {
38+
let mut harts = Element::new("harts");
39+
for hart in &self.harts {
40+
harts.children.push(hart.encode_node_with_config(config)?);
41+
}
42+
elem.children.push(XMLNode::Element(harts));
43+
}
44+
45+
Ok(elem)
46+
}
47+
}
48+
49+
impl Encode for Priority {
50+
type Error = EncodeError;
51+
52+
fn encode_with_config(&self, _config: &Config) -> Result<Element, EncodeError> {
53+
let mut children = vec![new_node("name", self.name.clone())];
54+
if let Some(desc) = &self.description {
55+
children.push(new_node("description", desc.clone()));
56+
}
57+
children.push(new_node("value", format!("{}", self.value)));
58+
59+
let mut elem = Element::new("priority");
60+
elem.children = children;
61+
Ok(elem)
62+
}
63+
}
64+
65+
impl Encode for Hart {
66+
type Error = EncodeError;
67+
68+
fn encode_with_config(&self, _config: &Config) -> Result<Element, EncodeError> {
69+
let mut children = vec![new_node("name", self.name.clone())];
70+
if let Some(desc) = &self.description {
71+
children.push(new_node("description", desc.clone()));
72+
}
73+
children.push(new_node("value", format!("{}", self.value)));
74+
75+
let mut elem = Element::new("hart");
76+
elem.children = children;
77+
Ok(elem)
78+
}
79+
}

svd-parser/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 `riscv` element for configuration parameters related to RISC-V targets.
1011
- Bump MSRV to 1.65.0
1112

1213
## [v0.14.5] - 2024-01-03

svd-parser/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ mod readaction;
211211
mod register;
212212
mod registercluster;
213213
mod registerproperties;
214+
mod riscv;
214215
mod usage;
215216
mod writeconstraint;
216217

svd-parser/src/riscv.rs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
use super::*;
2+
use crate::svd::riscv::{Hart, Interrupt, Priority, Riscv};
3+
4+
impl Parse for Riscv {
5+
type Object = Self;
6+
type Error = SVDErrorAt;
7+
type Config = Config;
8+
9+
fn parse(tree: &Node, config: &Config) -> Result<Self, Self::Error> {
10+
if !tree.has_tag_name("riscv") {
11+
return Err(SVDError::NotExpectedTag("riscv".to_string()).at(tree.id()));
12+
}
13+
14+
let mut builder = Riscv::builder()
15+
.clic(tree.get_child_text("clic").ok())
16+
.clint(tree.get_child_text("clint").ok())
17+
.plic(tree.get_child_text("plic").ok());
18+
19+
if let Some(interrupts) = tree.get_child("coreInterrupts") {
20+
let interrupts: Result<Vec<_>, _> = interrupts
21+
.children()
22+
.filter(|t| t.is_element() && t.has_tag_name("interrupt"))
23+
.map(|i| Interrupt::parse(&i, config))
24+
.collect();
25+
builder = builder.core_interrupts(interrupts?);
26+
}
27+
28+
if let Some(priorities) = tree.get_child("priorities") {
29+
let priorities: Result<Vec<_>, _> = priorities
30+
.children()
31+
.filter(|t| t.is_element() && t.has_tag_name("priority"))
32+
.map(|i| Priority::parse(&i, config))
33+
.collect();
34+
builder = builder.priorities(priorities?);
35+
};
36+
37+
if let Some(harts) = tree.get_child("harts") {
38+
let harts: Result<Vec<_>, _> = harts
39+
.children()
40+
.filter(|t| t.is_element() && t.has_tag_name("hart"))
41+
.map(|i| Hart::parse(&i, config))
42+
.collect();
43+
builder = builder.harts(harts?);
44+
};
45+
46+
builder
47+
.build(config.validate_level)
48+
.map_err(|e| SVDError::from(e).at(tree.id()))
49+
}
50+
}
51+
52+
impl Parse for Priority {
53+
type Object = Self;
54+
type Error = SVDErrorAt;
55+
type Config = Config;
56+
57+
fn parse(tree: &Node, config: &Config) -> Result<Self, Self::Error> {
58+
if !tree.has_tag_name("priority") {
59+
return Err(SVDError::NotExpectedTag("priority".to_string()).at(tree.id()));
60+
}
61+
62+
Priority::builder()
63+
.name(tree.get_child_text("name")?)
64+
.description(tree.get_child_text_opt("description")?)
65+
.value(tree.get_child_u32("value")?)
66+
.build(config.validate_level)
67+
.map_err(|e| SVDError::from(e).at(tree.id()))
68+
}
69+
}
70+
71+
impl Parse for Hart {
72+
type Object = Self;
73+
type Error = SVDErrorAt;
74+
type Config = Config;
75+
76+
fn parse(tree: &Node, config: &Config) -> Result<Self, Self::Error> {
77+
if !tree.has_tag_name("hart") {
78+
return Err(SVDError::NotExpectedTag("hart".to_string()).at(tree.id()));
79+
}
80+
81+
Hart::builder()
82+
.name(tree.get_child_text("name")?)
83+
.description(tree.get_child_text_opt("description")?)
84+
.value(tree.get_child_u32("value")?)
85+
.build(config.validate_level)
86+
.map_err(|e| SVDError::from(e).at(tree.id()))
87+
}
88+
}

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 `riscv` element for configuration parameters related to RISC-V targets.
1011
- Add `DataType`
1112

1213
## [v0.14.8] - 2024-02-13

svd-rs/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ pub use self::protection::Protection;
9494
pub mod datatype;
9595
pub use self::datatype::DataType;
9696

97+
/// Custom objects for the RISC-V ecosystem
98+
pub mod riscv;
99+
97100
/// Level of validation
98101
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
99102
pub enum ValidateLevel {

0 commit comments

Comments
 (0)