litex
litex copied to clipboard
[enh] generate SVD CSR enumeratedValue based on fields values
The SVD schema supports listing possible values for CSR fields, as can be seen in Keil's example.
Ideally, all existing field documented should be formatted as SVD schema expects it. However, invalid values are filtered out using the schema's regex, guaranteeing a valid SVD output will be generated regardless.
Here is a snippet of a generated SVD (from linux-on-litex-vexriscv)
<peripheral>
<name>SDRAM</name>
...
<registers>
<register>
<name>DFII_CONTROL</name>
...
<fields>
<field>
<name>sel</name>
...
<enumeratedValues>
<enumeratedValue>
<name>Software</name>
<description>Software (CPU) control.</description>
<value>0b0</value>
</enumeratedValue>
<enumeratedValue>
<name>Hardware</name>
<description>Hardware control (default).</description>
<value>0b1</value>
</enumeratedValue>
</enumeratedValues>
@xobs / @bunnie - As likely users of this, could you review it?
There was a program that was presented at Latchup 2023 that I am having trouble finding now. It was a browser-based register explorer. When I checked before, it didn't support SVD files, but that was a pending request. I'd love to see what that does with this, and what the progress is on SVD import.
A practical and more common usecase would be svd2rust (https://docs.rs/svd-rs/0.14.2/svd_rs/enumeratedvalues/struct.EnumeratedValues.html), which appears to support enumerated values.
@xobs Thanks for the review
There was a program that was presented at Latchup 2023 that I am having trouble finding now. It was a browser-based register explorer.
https://github.com/SystemRDL/PeakRDL-html ? Looks very nice with the register coding / decoding of values and fields. Maybe it would be possible to output rdl from litex and / or integrating this interactive bit of HTML in LiteX's doc. I might take a look at it next time I'm neck deep debugging CSR values!
A practical and more common usecase would be svd2rust (https://docs.rs/svd-rs/0.14.2/svd_rs/enumeratedvalues/struct.EnumeratedValues.html), which appears to support enumerated values.
it does!
...
pub type DFII_CONTROL = crate::Reg<dfii_control::DFII_CONTROL_SPEC>;
#[doc = "Control DFI signals common to all phases"]
pub mod dfii_control {
#[doc = "Register `DFII_CONTROL` reader"]
pub type R = crate::R<DFII_CONTROL_SPEC>;
#[doc = "Register `DFII_CONTROL` writer"]
pub type W = crate::W<DFII_CONTROL_SPEC>;
#[doc = "Field `sel` reader - None"]
pub type SEL_R = crate::BitReader<SEL_A>;
#[doc = "None\n\nValue on reset: 1"]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum SEL_A {
#[doc = "0: Software (CPU) control."]
SOFTWARE = 0,
#[doc = "1: Hardware control (default)."]
HARDWARE = 1,
}
...
That's the one! I discovered https://github.com/SystemRDL/PeakRDL-svd/blob/main/docs/dev_notes.txt but there hasn't been any movement there in a few months...