Module: IPXACT::Tools

Defined in:
lib/ipxact_tools.rb

Defined Under Namespace

Classes: Diagnosis, GraphPathFinder, InterruptLineDetector, ValidationError, ValidationMessage, ValidationWarning

Class Method Summary collapse

Class Method Details

.resolve_base_address(platform, data_path, initial_value = 0) ⇒ Object

Computes a the base address of the last component instance mentionned in the data_path. The latter should be calculated using the #resolve_data_path method. Additionally, this method takes into account all subcomponents from the data_path, and basically adds up mirrored slave ports’ remap addresses.

Returns the base address of the target component, as an Integer.

Parameters:

  • platform (IPXACT::Platform)

    The reference platform

  • data_path (Arrray)

    the data path from which the base address should be calculated. Please refer to the documentation of #resolve_data_path for more details on the structure of this argument.

  • initial_value (Integer) (defaults to: 0)

    the value that should be added to the base address computed by the method.



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/ipxact_tools.rb', line 205

def self.resolve_base_address(platform, data_path, initial_value = 0)
  base_address = initial_value
  data_path.each do |connection|
    connection.each do |connection_step|
      subcomponent = platform.rec_get_subcomponent(connection_step[:component_instance])
      port = subcomponent.ports \
                .select{|port| port[:name] == connection_step[:port_name]} \
                .first
      if port[:type] == :mirrored_slave && !port[:port_data].nil?
        base_address += port[:port_data][:remap][:address].to_i(16)
      end
    end
  end
  base_address
end

.resolve_data_path(platform, subcomponent_start, subcomponent_end) ⇒ Array<Array<Hash>>

Calculates an optimal path in the subcomponent graph between subcomponent_start and subcomponent_end. This computation takes into account hierarchical subcomponents, and identifies optimal sub-paths in these elements as well, using hierconnections. This method is in fact the facade for the GraphPathFinder class. It handles the creation of the connection Hash, and translates the result in a IPXACT-specific format.

Parameters:

  • platform (IPXACT::Platform)

    The reference platform

  • subcomponent_start (String)

    The name of the component instance that should be the source of the data path.

  • subcomponent_end (String)

    The name of the component instance that should be the target of the data path.

Returns:

  • (Array<Array<Hash>>)

    an Array of Arrays of Hashes that summarizes the component instances and the ports on the data path. Note that this data path may be used for calculating the target component’s base address. The Arrays of Hashes are composed of 2 elements, the first element being the source of a connection step and the second element being the target of the connection step. Each element is a Hash, built as follows: :component_instance the String name of the component instance that is traversed by the data path; :port_name the String name of the port of the component instance that is being traversed.

Raises:

  • several exceptions. Please refer to GraphPathFinder class for more details.



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/ipxact_tools.rb', line 157

def self.resolve_data_path(platform, subcomponent_start, subcomponent_end)
  nodes, connections = prepare_pathfinder_connections(platform)

  pathfinder_connections = connections.collect do |connection|
    {
      :link => [nodes.index(connection[0][:component_instance]),
                nodes.index(connection[1][:component_instance])],
      :ports => [connection[0][:port_name], connection[1][:port_name]]
    }
  end

  pathfinder_interconnect = {:nodes => nodes, :connections => pathfinder_connections}
  pathfinder = IPXACT::Tools::GraphPathFinder.new(pathfinder_interconnect)
  finder_result = pathfinder.resolve(subcomponent_start, subcomponent_end)

  formatted_result = finder_result.collect do |res|
    pathfinder_interconnect[:connections][res]
  end.collect do |connection|
    [
      {
        :component_instance => pathfinder_interconnect[:nodes][connection[:link][0]],
        :port_name => connection[:ports][0]
      },
      {
        :component_instance => pathfinder_interconnect[:nodes][connection[:link][1]],
        :port_name => connection[:ports][1]
      }
    ]
  end
end

.validate_data_path(platform, data_path) ⇒ Array<IPXACT::Tools::ValidationMessage>

Validates the given data path. In particular, the method verifies that no interrupt line is present in the data path.

Parameters:

  • platform (IPXACT::Platform)

    The reference platform

  • data_path (Array)

    The data path to validate

Returns:



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/ipxact_tools.rb', line 88

def self.validate_data_path(platform, data_path)
  diagnosis = Diagnosis.new
  path_ports = data_path.collect do |el|
    platform.rec_get_subcomponent(el[0][:component_instance]).ports.select{|p|
      p[:name] == el[0][:port_name]
    }.first
  end

  if path_ports.first[:type] == :master

    # Interrupt line detection
    detector = IPXACT::Tools::InterruptLineDetector.new
    stack = detector.viterbi(path_ports)
    rendered_stack = detector.render_seq(stack)

    interrupt_line_index = rendered_stack.find_index{|el| el == :int}
    unless interrupt_line_index.nil?
      diagnosis.errors << ValidationError.new(:probable_interrupt_line => data_path[interrupt_line_index])
    end

    # Concurrent access check
    target_component_name = data_path.last[1][:component_instance]
    target_component = platform.rec_get_subcomponent(target_component_name)
    components = platform.rec_get_subcomponents.reject{|el| el == target_component}

    cpu_instances = []
    components.each do |instance_name, component|
      if component.has_cpu?
        cpu_instances << instance_name
      end
    end

    if cpu_instances.size >= 2
      diagnosis.warnings << ValidationWarning.new(:cpu_nb_causes_concurrent_access_risk => cpu_instances)
    end
  else
    diagnosis.errors << ValidationError.new(:first_element_not_a_master => data_path.first)
  end

  return diagnosis
end