class Origen::Ports::Port

Attributes

id[R]
name[R]
owner[R]
parent[R]
size[R]
type[R]

Public Class Methods

new(parent, id, options = {}) click to toggle source
# File lib/origen/ports/port.rb, line 14
def initialize(parent, id, options = {})
  @size = options[:size] || 1
  @parent = parent
  @id = id
  @type = options[:type]
  @bit_names = {}.with_indifferent_access
end

Public Instance Methods

[](val) click to toggle source
# File lib/origen/ports/port.rb, line 117
def [](val)
  Section.new(self, val)
end
bit_order() click to toggle source

Prevent infinite loop if a child bit collection checks bit_order

# File lib/origen/ports/port.rb, line 72
def bit_order
  parent.bit_order
end
bits(index, name, options = {}) click to toggle source
# File lib/origen/ports/port.rb, line 63
def bits(index, name, options = {})
  if @defining
    @bit_names[name] = index
  else
    fail 'Cannot add additional port bits once the port definition is complete'
  end
end
describe(options = {}) click to toggle source
# File lib/origen/ports/port.rb, line 26
def describe(options = {})
  desc = ['********************']
  desc << "Port id:   #{id}"
  desc << "Port path: #{path}"
  desc << ''
  desc << 'Connections'
  desc << '-----------'
  desc << ''
  table = netlist.table
  ((size - 1)..0).to_a.each do |i|
    if table[path]
      c = [table[path]['*'], table[path][i]].flatten.compact.map { |n| n.is_a?(Proc) ? 'Proc' : n }
      desc << "#{i} - #{c.shift}"
      c.each do |n|
        desc << "     - #{n}"
      end
    else
      desc << "#{i} - none"
    end
  end
  desc << ''

  if options[:return]
    desc
  else
    puts desc.join("\n")
  end
end
drive(value = nil, options = {}) click to toggle source
# File lib/origen/ports/port.rb, line 76
def drive(value = nil, options = {})
  value, options = nil, value if value.is_a?(Hash)
  if options[:index]
    if options[:index].is_a?(Integer)
      drive_values[options[:index]] = value ? value[0] : nil
    else
      options[:index].to_a.each do |i|
        drive_values[i] = value ? value[i] : nil
      end
    end
  else
    size.times do |i|
      drive_values[i] = value ? value[i] : nil
    end
  end
  @drive_value = value
end
drive_values() click to toggle source
# File lib/origen/ports/port.rb, line 94
def drive_values
  @drive_values ||= Array.new(size)
end
inspect() click to toggle source
# File lib/origen/ports/port.rb, line 22
def inspect
  "<#{self.class}:#{object_id} id:#{id} path:#{path}>"
end
method_missing(method, *args, &block) click to toggle source
Calls superclass method
# File lib/origen/ports/port.rb, line 102
def method_missing(method, *args, &block)
  if @bit_names.key?(method)
    Section.new(self, @bit_names[method])
  elsif BitCollection.instance_methods.include?(method)
    to_bc.send(method, *args, &block)
  else
    super
  end
end
path() click to toggle source
# File lib/origen/ports/port.rb, line 55
def path
  if parent.path.empty?
    id.to_s
  else
    "#{parent.path}.#{id}"
  end
end
respond_to?(*args) click to toggle source
Calls superclass method
# File lib/origen/ports/port.rb, line 112
def respond_to?(*args)
  @bit_names.key?(args.first) || super(*args) ||
    BitCollection.instance_methods.include?(args.first)
end
to_bc() click to toggle source
# File lib/origen/ports/port.rb, line 121
def to_bc
  to_section.to_bc
end
to_section() click to toggle source
# File lib/origen/ports/port.rb, line 98
def to_section
  Section.new(self, (size - 1)..0)
end

Private Instance Methods

defining() { || ... } click to toggle source
# File lib/origen/ports/port.rb, line 127
def defining
  @defining = true
  yield
  @defining = false
end