Class: Origen::Ports::Port
Instance Attribute Summary collapse
Instance Method Summary
collapse
#connect_to
Constructor Details
#initialize(parent, id, options = {}) ⇒ Port
Returns a new instance of Port.
14
15
16
17
18
19
20
|
# 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
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
102
103
104
105
106
107
108
109
110
|
# 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
|
Instance Attribute Details
#id ⇒ Object
Also known as:
name
Returns the value of attribute id.
8
9
10
|
# File 'lib/origen/ports/port.rb', line 8
def id
@id
end
|
#parent ⇒ Object
Also known as:
owner
Returns the value of attribute parent.
7
8
9
|
# File 'lib/origen/ports/port.rb', line 7
def parent
@parent
end
|
Returns the value of attribute size.
6
7
8
|
# File 'lib/origen/ports/port.rb', line 6
def size
@size
end
|
Returns the value of attribute type.
9
10
11
|
# File 'lib/origen/ports/port.rb', line 9
def type
@type
end
|
Instance Method Details
117
118
119
|
# File 'lib/origen/ports/port.rb', line 117
def [](val)
Section.new(self, val)
end
|
#bit_order ⇒ Object
Prevent infinite loop if a child bit collection checks bit_order
72
73
74
|
# File 'lib/origen/ports/port.rb', line 72
def bit_order
parent.bit_order
end
|
#bits(index, name, options = {}) ⇒ Object
63
64
65
66
67
68
69
|
# 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 = {}) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# 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 = {}) ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# 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 ⇒ Object
94
95
96
|
# File 'lib/origen/ports/port.rb', line 94
def drive_values
@drive_values ||= Array.new(size)
end
|
22
23
24
|
# File 'lib/origen/ports/port.rb', line 22
def inspect
"<#{self.class}:#{object_id} id:#{id} path:#{path}>"
end
|
55
56
57
58
59
60
61
|
# 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) ⇒ Boolean
112
113
114
115
|
# 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
|
121
122
123
|
# File 'lib/origen/ports/port.rb', line 121
def to_bc
to_section.to_bc
end
|
#to_section ⇒ Object
98
99
100
|
# File 'lib/origen/ports/port.rb', line 98
def to_section
Section.new(self, (size - 1)..0)
end
|