class Origen::Ports::Section

Attributes

index[R]
port[R]

Public Class Methods

new(port, index) click to toggle source
# File lib/origen/ports/section.rb, line 9
def initialize(port, index)
  @port = port
  @index = index
end

Public Instance Methods

[](index) click to toggle source
# File lib/origen/ports/section.rb, line 47
def [](index)
  Section.new(port, align_to_port(index))
end
drive(value = nil) click to toggle source
# File lib/origen/ports/section.rb, line 35
def drive(value = nil)
  port.drive(value, index: index)
end
drive_value() click to toggle source
# File lib/origen/ports/section.rb, line 39
def drive_value
  if size == 1
    port.drive_values[index]
  else
    fail 'drive_value is only supported for a single bit port section'
  end
end
id() click to toggle source
# File lib/origen/ports/section.rb, line 31
def id
  port.id
end
method_missing(method, *args, &block) click to toggle source
Calls superclass method
# File lib/origen/ports/section.rb, line 55
def method_missing(method, *args, &block)
  if BitCollection.instance_methods.include?(method)
    to_bc.send(method, *args, &block)
  else
    super
  end
end
owner()
Alias for: parent
parent() click to toggle source
# File lib/origen/ports/section.rb, line 26
def parent
  port.parent
end
Also aliased as: owner
path() click to toggle source
# File lib/origen/ports/section.rb, line 18
def path
  if index.is_a?(Range)
    port.path + "[#{index.first}:#{index.last}]"
  else
    port.path + "[#{index}]"
  end
end
respond_to?(*args) click to toggle source
Calls superclass method
# File lib/origen/ports/section.rb, line 51
def respond_to?(*args)
  super(*args) || BitCollection.instance_methods.include?(args.first)
end
size() click to toggle source
# File lib/origen/ports/section.rb, line 14
def size
  size_of(index)
end
to_bc() click to toggle source
# File lib/origen/ports/section.rb, line 63
def to_bc
  b = BitCollection.new(port, port.id)
  indexes = index.respond_to?(:to_a) ? index.to_a : [index]
  indexes.reverse_each do |i|
    b << netlist.data_bit(port.path, i)
  end
  b
end

Private Instance Methods

align_to_port(val) click to toggle source
# File lib/origen/ports/section.rb, line 82
def align_to_port(val)
  if val.is_a?(Range)
    nlsb = lsb + val.last
    nmsb = nlsb + size_of(val) - 1
    out_of_range(val) if nmsb > msb
    i = nmsb..nlsb
  else
    i = lsb + val
    out_of_range(val) if i > msb
  end
  i
end
lsb() click to toggle source
# File lib/origen/ports/section.rb, line 107
def lsb
  if index.is_a?(Range)
    index.last
  else
    index
  end
end
msb() click to toggle source
# File lib/origen/ports/section.rb, line 99
def msb
  if index.is_a?(Range)
    index.first
  else
    index
  end
end
out_of_range(val) click to toggle source
# File lib/origen/ports/section.rb, line 95
def out_of_range(val)
  fail "Requested section index (#{val}) is out of range for a port section of size #{size}"
end
size_of(index) click to toggle source
# File lib/origen/ports/section.rb, line 74
def size_of(index)
  if index.is_a?(Range)
    (index.first - index.last).abs + 1
  else
    1
  end
end