Class: Origen::Ports::Section

Inherits:
Object
  • Object
show all
Includes:
Netlist::Connectable
Defined in:
lib/origen/ports/section.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Netlist::Connectable

#connect_to

Constructor Details

#initialize(port, index) ⇒ Section

Returns a new instance of Section


9
10
11
12
# File 'lib/origen/ports/section.rb', line 9

def initialize(port, index)
  @port = port
  @index = index
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object


55
56
57
58
59
60
61
# 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

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index


7
8
9
# File 'lib/origen/ports/section.rb', line 7

def index
  @index
end

#portObject (readonly)

Returns the value of attribute port


6
7
8
# File 'lib/origen/ports/section.rb', line 6

def port
  @port
end

Instance Method Details

#[](index) ⇒ Object


47
48
49
# File 'lib/origen/ports/section.rb', line 47

def [](index)
  Section.new(port, align_to_port(index))
end

#drive(value = nil) ⇒ Object


35
36
37
# File 'lib/origen/ports/section.rb', line 35

def drive(value = nil)
  port.drive(value, index: index)
end

#drive_valueObject


39
40
41
42
43
44
45
# 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

#idObject


31
32
33
# File 'lib/origen/ports/section.rb', line 31

def id
  port.id
end

#parentObject Also known as: owner


26
27
28
# File 'lib/origen/ports/section.rb', line 26

def parent
  port.parent
end

#pathObject


18
19
20
21
22
23
24
# 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) ⇒ Boolean

Returns:

  • (Boolean)

51
52
53
# File 'lib/origen/ports/section.rb', line 51

def respond_to?(*args)
  super(*args) || BitCollection.instance_methods.include?(args.first)
end

#sizeObject


14
15
16
# File 'lib/origen/ports/section.rb', line 14

def size
  size_of(index)
end

#to_bcObject


63
64
65
66
67
68
69
70
# 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