diff --git a/src/model.rs b/src/model.rs index 2de938d..7af4e25 100644 --- a/src/model.rs +++ b/src/model.rs @@ -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, /// What signals are used in the peripheral. pub signals: Vec, } +/// 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, +} + /// A group of registers. #[derive(Clone, Debug, PartialOrd, PartialEq, Eq, Hash)] pub struct RegisterGroup { diff --git a/src/pack.rs b/src/pack.rs index a6dd2a5..aa24809 100644 --- a/src/pack.rs +++ b/src/pack.rs @@ -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 @@ -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 { @@ -174,6 +176,22 @@ fn read_signal(signal: &Element) -> Signal { } } +/// Reads a register group reference. +/// +/// This looks like so +/// ```xml +/// +/// ``` +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 @@ -183,6 +201,7 @@ fn read_signal(signal: &Element) -> Signal { /// /// /// +/// ``` fn read_register_group(register_group: &Element) -> RegisterGroup { let (name, caption) = ( register_group.attributes.get("name").unwrap(),