#cmsis-svd #inheritance #svd #expander #cmsis #parser

svd-expander

在 CMSIS-SVD 规范中扩展数组和解析继承链

10 个版本

0.4.0 2020年5月14日
0.3.3 2020年5月14日
0.2.5 2020年5月12日
0.1.2 2020年5月11日

#612硬件支持

Download history 7/week @ 2024-03-29 351/week @ 2024-06-07 29/week @ 2024-06-14 11/week @ 2024-07-05

每月54次 下载

MIT/Apache

210KB
5.5K SLoC

crates.io crates.io Documentation Rust CI

svd-expander

在 CMSIS-SVD 规范中扩展数组和解析继承链。

示例用法

use svd_expander::DeviceSpec;

fn main() {
  let xml = r##"
  <device>
    <name>CORTEX_DEVICE</name>
    <peripherals>

      <peripheral>
        <name>GPIOA</name>
        <baseAddress>0x40010000</baseAddress>
        <registers>
          <register>
            <name>IDR</name>
            <description>Input Data Register</description>
            <addressOffset>0x00</addressOffset>
            <fields>

              <!-- 
                This field is a template that will be expanded 
                out to 16 input fields named D1 through D16.
              -->

              <field>
                <name>D%s</name>
                <bitWidth>1</bitWidth>
                <bitOffset>0</bitOffset>
                <dim>16</dim>
                <dimIndex>1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16</dimIndex>
                <dimIncrement>1</dimIncrement>
              </field>

            </fields>
          </register>
        </registers>
      </peripheral>

      <!-- 
        GPIOA will be copied to make GPIOB below, which is identical 
        except for any overridden properties (just name and 
        baseAddress in this case).
      -->

      <peripheral derivedFrom="GPIOA">
        <name>GPIOB</name>
        <baseAddress>0x40010100</baseAddress>
      </peripheral>

    </peripherals>
  </device>
  "##;

  let device = DeviceSpec::from_xml(xml).unwrap();

  // The IDR register on GPIOA has been expanded to 16 fields.
  assert_eq!(16, device.get_register("GPIOA.IDR").unwrap().fields.len());

  // Those fields each had their bit offset (location in the register)
  // incremented appropriately.
  assert_eq!(0, device.get_field("GPIOA.IDR.D1").unwrap().offset);
  assert_eq!(1, device.get_field("GPIOA.IDR.D2").unwrap().offset);
  // ...etc...
  assert_eq!(9, device.get_field("GPIOA.IDR.D10").unwrap().offset);
  // ...etc...

  // GPIOB also has an IDR register with 16 fields, which was inherited 
  // from GPIOA.
  assert_eq!(16, device.get_register("GPIOB.IDR").unwrap().fields.len());

  // GPIOB kept its name and base address when it inherited properties
  // from GPIOA.
  assert_eq!("GPIOB", device.get_peripheral("GPIOB").unwrap().name);
  assert_eq!(0x40010100, device.get_peripheral("GPIOB").unwrap().base_address);

}

此crate旨在用于代码生成器。它正在积极开发中,欢迎提交错误报告和功能请求。

依赖项

~1–1.5MB
~32K SLoC