mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
svd2utra: implement bitWidth and bitOffset tags for fields
This commit is contained in:
parent
998061448c
commit
cb8ba8dbe3
1 changed files with 19 additions and 0 deletions
|
|
@ -121,6 +121,9 @@ fn generate_field<T: BufRead>(reader: &mut Reader<T>) -> Result<Field, ParseErro
|
||||||
let mut name = None;
|
let mut name = None;
|
||||||
let mut lsb = None;
|
let mut lsb = None;
|
||||||
let mut msb = None;
|
let mut msb = None;
|
||||||
|
let mut bit_offset = None;
|
||||||
|
let mut bit_width = None;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match reader.read_event(&mut buf) {
|
match reader.read_event(&mut buf) {
|
||||||
Ok(Event::Start(ref e)) => {
|
Ok(Event::Start(ref e)) => {
|
||||||
|
|
@ -153,6 +156,12 @@ fn generate_field<T: BufRead>(reader: &mut Reader<T>) -> Result<Field, ParseErro
|
||||||
.map_err(|_| ParseError::ParseIntError)?,
|
.map_err(|_| ParseError::ParseIntError)?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
"bitWidth" => {
|
||||||
|
bit_width = Some(parse_usize(extract_contents(reader)?.as_bytes())?)
|
||||||
|
}
|
||||||
|
"bitOffset" => {
|
||||||
|
bit_offset = Some(parse_usize(extract_contents(reader)?.as_bytes())?)
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -166,6 +175,16 @@ fn generate_field<T: BufRead>(reader: &mut Reader<T>) -> Result<Field, ParseErro
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If no msb/lsb and bitRange tags were encountered then
|
||||||
|
// it's possible that the field is defined via
|
||||||
|
// `bitWidth` and `bitOffset` tags instead. Let's handle this.
|
||||||
|
if lsb.is_none() && msb.is_none() {
|
||||||
|
if let (Some(bit_width), Some(bit_offset)) = (bit_width, bit_offset) {
|
||||||
|
lsb = Some(bit_offset);
|
||||||
|
msb = Some(bit_offset + bit_width - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(Field {
|
Ok(Field {
|
||||||
name: name.ok_or(ParseError::MissingValue)?,
|
name: name.ok_or(ParseError::MissingValue)?,
|
||||||
lsb: lsb.ok_or(ParseError::MissingValue)?,
|
lsb: lsb.ok_or(ParseError::MissingValue)?,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue