diff --git a/emulation/renode.svd b/emulation/renode.svd
index d238a7d5b..40cf6f1a9 100644
--- a/emulation/renode.svd
+++ b/emulation/renode.svd
@@ -12,6 +12,92 @@
0xFFFFFFFF
+
+ CPU
+ 0xF0000000
+ CPU
+
+
+ TIMER_LATCH
+ 0x0000
+ 0x00
+ 32
+
+
+ timer_latch
+ 0
+ [0:0]
+ 0
+
+
+
+
+ TIMER_TIME1
+
+ 0x0004
+ 0x00
+ 32
+
+
+ timer_time
+ 31
+ [31:0]
+ 0
+
+
+
+
+ TIMER_TIME0
+
+ 0x0008
+ 0x00
+ 32
+
+
+ timer_time
+ 31
+ [31:0]
+ 0
+
+
+
+
+ TIMER_TIME_CMP1
+
+ 0x000c
+ 0x7fffffff
+ 32
+
+
+ timer_time_cmp
+ 31
+ [31:0]
+ 0
+
+
+
+
+ TIMER_TIME_CMP0
+
+ 0x0010
+ 0x7fffffff
+ 32
+
+
+ timer_time_cmp
+ 31
+ [31:0]
+ 0
+
+
+
+
+
+ 0
+ 0x14
+ registers
+
+
IDENTIFIER_MEM
0xF0001000
@@ -682,32 +768,6 @@ register to disable individual events.]]>
1
-
- UART_PHY
- 0xF0006000
- UART_PHY
-
-
- TUNING_WORD
- 0x0000
- 0x4b7f5a
- 32
-
-
- tuning_word
- 31
- [31:0]
- 0
-
-
-
-
-
- 0
- 0x4
- registers
-
-
UART
0xF0007000
@@ -866,32 +926,6 @@ register to disable individual events.]]>
2
-
- CONSOLE_PHY
- 0xF0008000
- CONSOLE_PHY
-
-
- TUNING_WORD
- 0x0000
- 0x4b7f5a
- 32
-
-
- tuning_word
- 31
- [31:0]
- 0
-
-
-
-
-
- 0
- 0x4
- registers
-
-
CONSOLE
0xF0009000
@@ -1050,32 +1084,6 @@ register to disable individual events.]]>
3
-
- APP_UART_PHY
- 0xF000A000
- APP_UART_PHY
-
-
- TUNING_WORD
- 0x0000
- 0x4b7f5a
- 32
-
-
- tuning_word
- 31
- [31:0]
- 0
-
-
-
-
-
- 0
- 0x4
- registers
-
-
APP_UART
0xF000B000
@@ -1320,10 +1328,10 @@ register to disable individual events.]]>
GIT_GITREV
0x0014
- 0xe0fc761f
+ 0xd77dca2f
32
@@ -1340,7 +1348,7 @@ the exact git version used to build this firmware.]]>
is ``1``, then the repository this was built from has one additional commit
beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]>
0x0018
- 0x0a
+ 0x0d
32
@@ -3030,7 +3038,7 @@ again until the interrupt is serviced.]]>
SEED1
0x0000
- 0x156ab1cc
+ 0x48f7dee1
32
@@ -3045,7 +3053,7 @@ again until the interrupt is serviced.]]>
SEED0
0x0004
- 0x1918cfd8
+ 0xc2db130
32
@@ -5182,5 +5190,34 @@ entered. Defaults to a range of 1.67-5.00 seconds]]>
0x00040000
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/svd2utra/examples/soc.svd b/svd2utra/examples/soc.svd
index d238a7d5b..40cf6f1a9 100644
--- a/svd2utra/examples/soc.svd
+++ b/svd2utra/examples/soc.svd
@@ -12,6 +12,92 @@
0xFFFFFFFF
+
+ CPU
+ 0xF0000000
+ CPU
+
+
+ TIMER_LATCH
+ 0x0000
+ 0x00
+ 32
+
+
+ timer_latch
+ 0
+ [0:0]
+ 0
+
+
+
+
+ TIMER_TIME1
+
+ 0x0004
+ 0x00
+ 32
+
+
+ timer_time
+ 31
+ [31:0]
+ 0
+
+
+
+
+ TIMER_TIME0
+
+ 0x0008
+ 0x00
+ 32
+
+
+ timer_time
+ 31
+ [31:0]
+ 0
+
+
+
+
+ TIMER_TIME_CMP1
+
+ 0x000c
+ 0x7fffffff
+ 32
+
+
+ timer_time_cmp
+ 31
+ [31:0]
+ 0
+
+
+
+
+ TIMER_TIME_CMP0
+
+ 0x0010
+ 0x7fffffff
+ 32
+
+
+ timer_time_cmp
+ 31
+ [31:0]
+ 0
+
+
+
+
+
+ 0
+ 0x14
+ registers
+
+
IDENTIFIER_MEM
0xF0001000
@@ -682,32 +768,6 @@ register to disable individual events.]]>
1
-
- UART_PHY
- 0xF0006000
- UART_PHY
-
-
- TUNING_WORD
- 0x0000
- 0x4b7f5a
- 32
-
-
- tuning_word
- 31
- [31:0]
- 0
-
-
-
-
-
- 0
- 0x4
- registers
-
-
UART
0xF0007000
@@ -866,32 +926,6 @@ register to disable individual events.]]>
2
-
- CONSOLE_PHY
- 0xF0008000
- CONSOLE_PHY
-
-
- TUNING_WORD
- 0x0000
- 0x4b7f5a
- 32
-
-
- tuning_word
- 31
- [31:0]
- 0
-
-
-
-
-
- 0
- 0x4
- registers
-
-
CONSOLE
0xF0009000
@@ -1050,32 +1084,6 @@ register to disable individual events.]]>
3
-
- APP_UART_PHY
- 0xF000A000
- APP_UART_PHY
-
-
- TUNING_WORD
- 0x0000
- 0x4b7f5a
- 32
-
-
- tuning_word
- 31
- [31:0]
- 0
-
-
-
-
-
- 0
- 0x4
- registers
-
-
APP_UART
0xF000B000
@@ -1320,10 +1328,10 @@ register to disable individual events.]]>
GIT_GITREV
0x0014
- 0xe0fc761f
+ 0xd77dca2f
32
@@ -1340,7 +1348,7 @@ the exact git version used to build this firmware.]]>
is ``1``, then the repository this was built from has one additional commit
beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]>
0x0018
- 0x0a
+ 0x0d
32
@@ -3030,7 +3038,7 @@ again until the interrupt is serviced.]]>
SEED1
0x0000
- 0x156ab1cc
+ 0x48f7dee1
32
@@ -3045,7 +3053,7 @@ again until the interrupt is serviced.]]>
SEED0
0x0004
- 0x1918cfd8
+ 0xc2db130
32
@@ -5182,5 +5190,34 @@ entered. Defaults to a range of 1.67-5.00 seconds]]>
0x00040000
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/svd2utra/src/generate.rs b/svd2utra/src/generate.rs
index 02008a735..e8af0ed5c 100644
--- a/svd2utra/src/generate.rs
+++ b/svd2utra/src/generate.rs
@@ -48,10 +48,17 @@ pub struct MemoryRegion {
pub size: usize,
}
+#[derive(Default, Debug)]
+pub struct Constant {
+ pub name: String,
+ pub value: String,
+}
+
#[derive(Default, Debug)]
pub struct Description {
pub peripherals: Vec,
pub memory_regions: Vec,
+ pub constants: Vec,
}
impl core::fmt::Display for ParseError {
@@ -393,6 +400,56 @@ fn parse_memory_regions(
Ok(())
}
+fn generate_constants(
+ reader: &mut Reader,
+ description: &mut Description,
+) -> Result<(), ParseError> {
+ let mut buf = Vec::new();
+ loop {
+ match reader.read_event(&mut buf) {
+ Ok(Event::Empty(ref e)) => match e.name() {
+ b"constant" => {
+ let mut constant_descriptor = Constant::default();
+ for maybe_att in e.attributes() {
+ match maybe_att {
+ Ok(att) => {
+ let att_name = String::from_utf8(att.key.to_vec()).expect("constant: error parsing attribute name");
+ let att_value = String::from_utf8(att.value.to_vec()).expect("constant: error parsing attribute value");
+ match att_name {
+ _ if att_name == "name" => constant_descriptor.name = att_value,
+ _ if att_name == "value" => constant_descriptor.value = att_value,
+ _ => panic!("unexpected attribute name")
+ }
+ },
+ _ => panic!("unexpected value in constant: {:?}", maybe_att),
+ }
+ }
+ description
+ .constants
+ .push(constant_descriptor)
+ },
+ _ => panic!("unexpected tag in : {:?}", e),
+ },
+ // note to future self: if Litex goe away from attributes to nested elements, you would want
+ // Ok(Event::Start(ref e) => match e.name() ... to descend into the next tag level, and then
+ // use the tag_name match and extract_contents methods from other functions to generate
+ // the structure.
+ // note that the two formats could be mutually exclusively compatible within the same code base:
+ // if there are no attributes, the attribute iterator would do nothing; and if there are no
+ // child elements, the recursive descent would also do nothing.
+ Ok(Event::End(ref e)) => match e.name() {
+ b"constants" => {
+ break
+ }
+ e => panic!("unhandled value: {:?}", e),
+ },
+ Ok(Event::Text(_)) => (),
+ e => panic!("unhandled value: {:?}", e)
+ }
+ }
+ Ok(())
+}
+
fn parse_vendor_extensions(
reader: &mut Reader,
description: &mut Description,
@@ -402,6 +459,7 @@ fn parse_vendor_extensions(
match reader.read_event(&mut buf) {
Ok(Event::Start(ref e)) => match e.name() {
b"memoryRegions" => parse_memory_regions(reader, description)?,
+ b"constants" => generate_constants(reader, description)?,
_ => panic!("unexpected tag in : {:?}", e),
},
Ok(Event::End(ref e)) => match e.name() {
@@ -581,6 +639,31 @@ fn print_memory_regions(regions: &[MemoryRegion], out: &mut U) -> std:
Ok(())
}
+fn print_constants(constants: &[Constant], out: &mut U) -> std::io::Result<()> {
+ writeln!(out, "\n// Litex auto-generated constants")?;
+ for constant in constants {
+ let maybe_intval = constant.value.parse::();
+ match maybe_intval {
+ Ok(intval) => {
+ writeln!(
+ out,
+ "pub const LITEX_{}: usize = {};",
+ constant.name, intval
+ )?;
+ },
+ Err(_) => {
+ writeln!(
+ out,
+ "pub const LITEX_{}: &str = \"{}\";",
+ constant.name, constant.value
+ )?;
+ }
+ }
+ }
+ writeln!(out)?;
+ Ok(())
+}
+
fn print_peripherals(peripherals: &[Peripheral], out: &mut U) -> std::io::Result<()> {
writeln!(out, "// Physical base addresses of registers")?;
for peripheral in peripherals {
@@ -740,6 +823,7 @@ pub fn generate(src: T, dest: &mut U) -> Result<(), ParseErro
print_header(dest).or(Err(ParseError::WriteError))?;
print_memory_regions(&description.memory_regions, dest).or(Err(ParseError::WriteError))?;
print_peripherals(&description.peripherals, dest).or(Err(ParseError::WriteError))?;
+ print_constants(&description.constants, dest).or(Err(ParseError::WriteError))?;
print_tests(&description.peripherals, dest).or(Err(ParseError::WriteError))?;
Ok(())
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index 4f8e380fa..0dd4174d1 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -44,7 +44,7 @@ fn try_main() -> Result<(), DynError> {
"log-server",
"com",
"xous-names",
- "keyboard",
+ //"keyboard",
"trng",
//"llio",
];