forked from Rahix/atdf2svd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch.rs
More file actions
62 lines (54 loc) · 1.99 KB
/
patch.rs
File metadata and controls
62 lines (54 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! Patches for atdf files that can generally be applied
use crate::chip;
use crate::util;
use crate::ElementExt;
use std::collections::HashMap;
pub fn signals_to_port_fields(chip: &mut chip::Chip, tree: &xmltree::Element) -> crate::Result<()> {
let port_module = tree
.first_child("devices")?
.first_child("device")?
.first_child("peripherals")?
.first_child_by_attr(Some("module"), "name", "PORT")?;
for port in chip
.peripherals
.values_mut()
.filter(|p| p.name.starts_with("PORT"))
{
let name = port.name.chars().rev().next().unwrap();
let pins: Vec<_> = port_module
.first_child_by_attr(Some("instance"), "name", &port.name)?
.first_child("signals")?
.children
.iter()
.map(|el| el.attr("index"))
.map(|r| r.and_then(|s| util::parse_int(s)))
.collect::<Result<_, _>>()?;
let fields: HashMap<String, chip::Field> = pins
.into_iter()
.map(|p| chip::Field {
name: format!("P{}{}", name, p),
description: Some(format!("Pin {}{}", name, p)),
range: (p, p),
access: chip::AccessMode::ReadWrite,
restriction: chip::ValueRestriction::Any,
})
.map(|f| (f.name.clone(), f))
.collect();
for reg in port.registers.values_mut() {
if !reg.name.ends_with(name) {
log::error!("Register {:?} has a weird name!", reg.name);
}
reg.fields = fields.clone();
// Ensure that direct access to the register is unsafe
reg.restriction = chip::ValueRestriction::Unsafe;
}
}
Ok(())
}
pub fn remove_unsafe_cpu_regs(chip: &mut chip::Chip, _el: &xmltree::Element) -> crate::Result<()> {
if let Some(cpu) = chip.peripherals.get_mut("CPU") {
cpu.registers.remove("SREG");
cpu.registers.remove("SP");
}
Ok(())
}