Class: CrossOrigen::CMSISSVD

Inherits:
XMLDoc
  • Object
show all
Defined in:
lib/cross_origen/cmsis_svd.rb

Constant Summary

Constants inherited from XMLDoc

XMLDoc::HTML_SANITIZATION_CONFIG, XMLDoc::HTML_TRANSFORMER, XMLDoc::HTML_TRANSFORMS

Instance Attribute Summary

Attributes inherited from XMLDoc

#creation_info, #import_info, #owner

Instance Method Summary collapse

Methods inherited from XMLDoc

#doc, #extract, #fetch, #initialize, #pre_sanitize, #to_html, #to_markdown, #try

Constructor Details

This class inherits a constructor from CrossOrigen::XMLDoc

Instance Method Details

#import(file, options = {}) ⇒ Object

rubocop:disable CyclomaticComplexity



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
# File 'lib/cross_origen/cmsis_svd.rb', line 3

def import(file, options = {}) # rubocop:disable CyclomaticComplexity
  filename = Pathname.new(file).basename('.*').to_s

  unless options[:refresh] || CrossOrigen.refresh?
    return if owner.import(filename, allow_missing: true)
  end

  model = CrossOrigen::Model.new

  doc(file, options) do |doc|
    peripherals = peripherals(doc)
    groups = peripherals.values.map { |v| v[:group] }.uniq

    groups.each { |group| model.sub_block group }

    peripherals.each do |name, attrs|
      base = attrs[:group] ? model.send(attrs[:group]) : model
      block = base.sub_block name, base_address: attrs[:base_address]

      if attrs[:parent]
        add_registers(block, find_peripheral_by_name(doc, attrs[:parent]))
      end
      add_registers(block, find_peripheral_by_name(doc, name))
    end
  end
  model.export(filename, include_timestamp: CrossOrigen.include_timestamp?)
  owner.import(filename)
end