module Origen::Chips

Constants

NOTE_TYPES
SPEC_TYPES
SpecTableAttr

Attributes

_chips[RW]
_designs[RW]
_docs[RW]
_notes[RW]

Public Instance Methods

chip(name, description, selector = {}, options = {}, &block) click to toggle source

Define and instantiate a Spec object

# File lib/origen/chips.rb, line 51
def chip(name, description, selector = {}, options = {}, &block)
  # return chips(name, group) unless block_given?
  _chips
  name = name_audit(name)
  group = selector[:group]
  family = selector[:family]
  performance = selector[:performance]
  previous_parts = selector[:previous_parts]
  power = selector[:power]
  chip_holder = Chip.new(name, description, previous_parts, power, options)
  if has_chip?(name, group: group, family: family, performance: performance, creating_chip: true)
    fail "Chip already exists for chip: #{name}, group: #{group}, family: #{family} for object #{self}"
  end

  @_chips[group][family][performance][name] = chip_holder
end
chips(s = nil, options = {}) click to toggle source

Returns a hash of hash containing all specs/modes If no spec is specified then all specs are returned via inspect If a spec is specified, a spec object will be returned if found in the current mode. If a mode option is passed and no spec is passed it will filter the specs inspect display by the mode and visa-versa

# File lib/origen/chips.rb, line 30
def chips(s = nil, options = {})
  options = {
    group:       nil,
    family:      nil,
    performance: nil,
    part:        nil,
    chip:        nil
  }.update(options || {})
  _chips
  if s.nil?
    show_chips(options)
  elsif s.is_a? Hash
    options.update(s)
    show_chips(options)
  else
    options[:chip] = s
    show_chips(options)
  end
end
delete_all_chips() click to toggle source

Delete all specs

# File lib/origen/chips.rb, line 168
def delete_all_chips
  @_chips = nil
end
delete_all_designs() click to toggle source
# File lib/origen/chips.rb, line 182
def delete_all_designs
  @_designs = nil
end
delete_all_docs() click to toggle source

Delete all doc

# File lib/origen/chips.rb, line 178
def delete_all_docs
  @_docs = nil
end
delete_all_notes() click to toggle source

Delete all notes

# File lib/origen/chips.rb, line 173
def delete_all_notes
  @_notes = nil
end
design(date, type, revision, description, options = {}) click to toggle source
# File lib/origen/chips.rb, line 111
def design(date, type, revision, description, options = {})
  _designs
  @_designs[type][revision] = Design_Entry.new(date, type, revision, description, options)
end
designs(options = {}) click to toggle source
# File lib/origen/chips.rb, line 153
def designs(options = {})
  options = {
    type: nil,
    rev:  nil
  }.update(options)
  designs_to_be_shown = []
  filter_hash(_designs, options[:type]).each do |type, hash|
    filter_hash(hash, options[:rev]).each do |revision, hash_|
      designs_to_be_shown << hash_
    end
  end
  designs_to_be_shown
end
doc(date, type, revision, description, options = {}) click to toggle source
# File lib/origen/chips.rb, line 106
def doc(date, type, revision, description, options = {})
  _docs
  @_docs[type][revision] = Doc_Entry.new(date, type, revision, description, options)
end
docs(options = {}) click to toggle source
# File lib/origen/chips.rb, line 139
def docs(options = {})
  options = {
    type: nil,
    rev:  nil
  }.update(options)
  docs_to_be_shown = []
  filter_hash(_docs, options[:type]).each do |type, hash|
    filter_hash(hash, options[:rev]).each do |revision, hash_|
      docs_to_be_shown << hash_
    end
  end
  docs_to_be_shown
end
has_chip?(s, options = {}) click to toggle source

Check if the current IP has a spec

# File lib/origen/chips.rb, line 87
def has_chip?(s, options = {})
  _chips
  options = {
    group:         nil,
    family:        nil,
    performance:   nil,
    chip:          nil,
    creating_spec: false
  }.update(options)
  options[:chip] = s
  !!show_chips(options)
end
has_chips?(options = {}) click to toggle source

Returns Boolean based on whether the calling object has any defined specs If the mode option is selected then the search is narrowed

# File lib/origen/chips.rb, line 70
def has_chips?(options = {})
  _chips
  options = {
    group:         nil,
    family:        nil,
    performance:   nil,
    chip:          nil,
    creating_chip: false
  }.update(options)
  if @_chips.nil? || @_chips == {}
    false
  else
    !!show_chips(options)
  end
end
note(id, type, feature) click to toggle source

Define and instantiate a Note object

# File lib/origen/chips.rb, line 101
def note(id, type, feature)
  _notes
  @_notes[id][type] = RSS_Note.new(id, type, feature)
end
notes(options = {}) click to toggle source

Returns a Note object from the notes hash

# File lib/origen/chips.rb, line 117
def notes(options = {})
  options = {
    id:   nil,
    type: nil
  }.update(options)
  notes_found = Hash.new do |h, k|
    h[k] = {}
  end
  _notes.filter(options[:id]).each do |id, hash|
    hash.filter(options[:type]).each do |type, note|
      notes_found[id][type] = note
    end
  end
  if notes_found.empty?
    nil
  elsif notes_found.size == 1
    notes_found.values.first.values.first
  else
    notes_found
  end
end

Private Instance Methods

filter_hash(hash, filter) click to toggle source

Return a hash based on the filter provided

# File lib/origen/chips.rb, line 224
def filter_hash(hash, filter)
  fail 'Hash argument is not a Hash!' unless hash.is_a? Hash

  filtered_hash = {}
  select_logic = case filter
    when String then 'k[Regexp.new(filter)]'
    when (Fixnum || Integer || Float || Numeric) then "k[Regexp.new('#{filter}')]"
    when Regexp then 'k[filter]'
    when Symbol then
      'k == filter'
    when NilClass then true # Return all specs if a filter is set to nil (i.e. user doesn't care about this filter)
    else true
                 end
  filtered_hash = hash.select do |k, v|
    [TrueClass, FalseClass].include?(select_logic.class) ? select_logic : eval(select_logic)
  end
  filtered_hash
end
show_chips(options = {}) click to toggle source

Filters the 4D hash to find specs for all user visible API

# File lib/origen/chips.rb, line 244
def show_chips(options = {})
  options = {
    group:             nil,
    family:            nil,
    performance:       nil,
    part:              nil,
    chips_to_be_shown: ChipArray.new,
    creating_chip:     false
  }.update(options)
  chips_to_be_shown = options[:chips_to_be_shown]
  filter_hash(_chips, options[:group]).each do |_group, hash|
    filter_hash(hash, options[:family]).each do |_family, hash_|
      filter_hash(hash_, options[:performance]).each do |_performance, hash__|
        filter_hash(hash__, options[:part]).each do |_part, chip|
          chips_to_be_shown << chip
        end
      end
    end
  end
  # If no specs were found must check the possibility another search
  # should be started with mode set to :local or :global
  if chips_to_be_shown.empty?
    # Don't want to re-call this method if the callee is trying to create a spec and just wants to know
    # if there is a spec with the exact same options
    if options[:creating_chip] == false
      # Doesn't make sense to recall the method however if the mode is already set to :global or :local
      options[:chips_to_be_shown] = chips_to_be_shown
      Origen.log.debug "re-calling show_chips with options #{options}"
      return show_chips(options)
    end
    Origen.log.debug "Returning no chips for options #{options}"
    nil
  elsif chips_to_be_shown.size == 1
    Origen.log.debug "returning one spec #{chips_to_be_shown.first.part_name}"
    chips_to_be_shown.first
  else
    Origen.log.debug "returning an array of specs during initial search: #{chips_to_be_shown}"
    chips_to_be_shown
  end
end