Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model peripheral register group references #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,28 @@ pub struct Module {
pub struct Instance {
/// The name of the peripheral instance, for example, `PORTB`.
pub name: String,
/// Reference to the register group that represents this instance.
pub register_group_ref: Option<RegisterGroupRef>,
/// What signals are used in the peripheral.
pub signals: Vec<Signal>,
}

/// A refereance to a register group.
#[derive(Clone, Debug, PartialOrd, PartialEq, Eq, Hash)]
pub struct RegisterGroupRef {
/// The name of the register group being referenced.
pub name: String,
/// The name of the register group being referenced in the module that
/// defines it.
pub name_in_module: String,
/// The offset of the register group.
pub offset: u32,
/// The address space.
pub address_space: String,
/// The caption describing the register group reference.
pub caption: Option<String>,
}

/// A group of registers.
#[derive(Clone, Debug, PartialOrd, PartialEq, Eq, Hash)]
pub struct RegisterGroup {
Expand Down
21 changes: 20 additions & 1 deletion src/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ fn read_variant(variant: &Element) -> Variant {
fn read_instance(instance: &Element) -> Instance {
let instance_name = instance.attributes.get("name").unwrap().clone();

let register_group_ref = instance.get_child("register-group").map(|e| read_register_group_ref(e));

let signals = match instance.get_child("signals") {
Some(signals) => signals
.children
Expand All @@ -163,7 +165,7 @@ fn read_instance(instance: &Element) -> Instance {
None => Vec::new(),
};

Instance { name: instance_name, signals: signals }
Instance { name: instance_name, register_group_ref: register_group_ref, signals: signals }
}

fn read_signal(signal: &Element) -> Signal {
Expand All @@ -174,6 +176,22 @@ fn read_signal(signal: &Element) -> Signal {
}
}

/// Reads a register group reference.
///
/// This looks like so
/// ```xml
/// <register-group address-space="data" name="PORTA" name-in-module="PORT" offset="0x0400"/>
/// ```
fn read_register_group_ref(register_group_ref: &Element) -> RegisterGroupRef {
RegisterGroupRef {
name: register_group_ref.attributes.get("name").unwrap().clone(),
name_in_module: register_group_ref.attributes.get("name-in-module").unwrap().clone(),
offset: read_int(register_group_ref.attributes.get("offset")).clone(),
address_space: register_group_ref.attributes.get("address-space").unwrap().clone(),
caption: register_group_ref.attributes.get("caption").map(|p| p.clone()),
}
}

/// Reads a register group.
///
/// This looks like so
Expand All @@ -183,6 +201,7 @@ fn read_signal(signal: &Element) -> Signal {
/// <register caption="EEPROM Address Register Bytes" name="EEAR" offset="0x41" size="2" mask="0x01FF"/>
/// <register caption="EEPROM Data Register" name="EEDR" offset="0x40" size="1" mask="0xFF"/>
/// </register-group>
/// ```
fn read_register_group(register_group: &Element) -> RegisterGroup {
let (name, caption) = (
register_group.attributes.get("name").unwrap(),
Expand Down