Class: Origen::Pins::PinCollection
Overview
A class that is used to wrap collections of one or more pins. Anytime a group of pins is fetched or returned by the Pin API it will be wrapped in a PinCollection.
Constant Summary
collapse
- ORG_FILE_INTERCEPTED_METHODS =
[
:drive, :write, :drive_hi, :write_hi, :drive_lo, :write_lo, :drive_very_hi, :drive_mem, :expect_mem, :toggle,
:repeat_previous=, :capture, :assert, :read, :compare, :expect,
:assert_hi, :expect_hi, :compare_hi, :read_hi, :assert_lo, :expect_lo, :compare_lo, :read_lo,
:dont_care
]
Constants included
from Enumerable
Enumerable::PRIMATIVES
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#[](*indexes) ⇒ Object
-
#[]=(index, pin) ⇒ Object
-
#add_pin(pin, _options = {}) ⇒ Object
(also: #<<)
-
#assert(value, options = {}) ⇒ Object
(also: #compare, #expect, #read)
-
#assert!(*args) ⇒ Object
(also: #compare!, #expect!, #read!)
-
#assert_hi(options = {}) ⇒ Object
(also: #expect_hi, #compare_hi, #read_hi)
Set all pins in the pin group to expect 1's on future cycles.
-
#assert_hi! ⇒ Object
(also: #expect_hi!, #compare_hi!, #read_hi!)
-
#assert_lo(options = {}) ⇒ Object
(also: #expect_lo, #compare_lo, #read_lo)
Set all pins in the pin group to expect 0's on future cycles.
-
#assert_lo! ⇒ Object
(also: #expect_lo!, #compare_lo!, #read_lo!)
-
#capture ⇒ Object
(also: #store)
Mark the (data) from all the pins in the pin group to be captured.
-
#capture! ⇒ Object
(also: #store!)
-
#comparing? ⇒ Boolean
-
#comparing_mem? ⇒ Boolean
-
#cycle ⇒ Object
-
#data ⇒ Object
(also: #val, #value)
Returns the data value held by the collection ==== Example pins(:porta).write(0x55) pins(:porta).data # => 0x55.
-
#data_b ⇒ Object
Returns the inverse of the data value held by the collection.
-
#delete(p) ⇒ Object
Deletes all occurrences of a pin in a pin group.
-
#delete! ⇒ Object
Delete this pingroup (myself).
-
#delete_at(index) ⇒ Object
Deletes the pin at a particular numeric index within the pin group.
-
#describe(display = :id) ⇒ Object
Describe the pin group contents.
-
#dont_care ⇒ Object
Set all pins in the pin group to X on future cycles.
-
#dont_care! ⇒ Object
-
#drive(val) ⇒ Object
(also: #write)
-
#drive!(val) ⇒ Object
(also: #write!)
-
#drive_hi ⇒ Object
(also: #write_hi)
Set all pins in pin group to drive 1's on future cycles.
-
#drive_hi! ⇒ Object
(also: #write_hi!)
-
#drive_lo ⇒ Object
(also: #write_lo)
Set all pins in pin group to drive 0's on future cycles.
-
#drive_lo! ⇒ Object
(also: #write_lo!)
-
#drive_mem ⇒ Object
-
#drive_mem! ⇒ Object
-
#drive_very_hi ⇒ Object
Set all pins in the pin group to drive a high voltage on future cycles (if the tester supports it).
-
#drive_very_hi! ⇒ Object
-
#driving? ⇒ Boolean
-
#driving_mem? ⇒ Boolean
-
#each ⇒ Object
Overrides the regular Ruby array each to be endian aware.
-
#expect_mem ⇒ Object
-
#expect_mem! ⇒ Object
-
#global_path_to ⇒ Object
-
#ground_pins? ⇒ Boolean
Returns true if the pin collection contains ground pins rather than regular pins.
-
#high_voltage? ⇒ Boolean
-
#id ⇒ Object
-
#id=(val) ⇒ Object
-
#initialize(owner, *pins) ⇒ PinCollection
constructor
A new instance of PinCollection.
-
#invalidate_vector_cache ⇒ Object
private
-
#inverted? ⇒ Boolean
-
#name ⇒ Object
-
#name=(val) ⇒ Object
Explicitly set the name of a pin group/collection.
-
#org_file_intercepted_methods ⇒ Object
-
#other_pins? ⇒ Boolean
Returns true if the pin collection contains other pins rather than regular pins.
-
#pins(nick = :id) ⇒ Object
-
#power_pins? ⇒ Boolean
Returns true if the pin collection contains power pins rather than regular pins.
-
#repeat_previous=(bool) ⇒ Object
-
#repeat_previous? ⇒ Boolean
-
#restore ⇒ Object
-
#restore_state ⇒ Object
-
#rtl_name ⇒ Object
-
#save ⇒ Object
-
#size ⇒ Object
-
#sort!(&block) ⇒ Object
-
#sort_by! ⇒ Object
-
#to_be_captured? ⇒ Boolean
(also: #to_be_stored?, #is_to_be_stored?, #is_to_be_captured?)
Returns true if the (data) from the pin collection is marked to be captured.
-
#to_vector ⇒ Object
Returns the value held by the pin group as a string formatted to the current tester's pattern syntax.
-
#toggle ⇒ Object
-
#toggle! ⇒ Object
-
#vector_formatted_value=(val) ⇒ Object
Set the values and states of the pin group's pins from a string formatted to the current tester's pattern syntax, this is the opposite of the to_vector method.
-
#virtual_pins? ⇒ Boolean
Returns true if the pin collection contains virtual pins rather than regular pins.
#__interceptor__=, included, #myself
Methods included from Enumerable
#debug, #list
Methods included from PinCommon
#add_configuration, #add_mode, #add_package, #enabled?, #enabled_in_configuration?, #enabled_in_mode?, #enabled_in_package?, #finalize, #to_sym
Constructor Details
#initialize(owner, *pins) ⇒ PinCollection
Returns a new instance of PinCollection.
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/origen/pins/pin_collection.rb', line 23
def initialize(owner, *pins)
options = pins.last.is_a?(Hash) ? pins.pop : {}
options = {
endian: :big
}.merge(options)
@power_pins = options.delete(:power_pin) || options.delete(:power_pins)
@ground_pins = options.delete(:ground_pin) || options.delete(:ground_pins)
@virtual_pins = options.delete(:virtual_pin) || options.delete(:virtual_pins)
@other_pins = options.delete(:other_pin) || options.delete(:other_pins)
@endian = options[:endian]
@rtl_name = options[:rtl_name]
@description = options[:description] || options[:desc]
@options = options
@store = []
pins.each_with_index do |pin, i|
@store[i] = pin
end
on_init(owner, options)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
|
# File 'lib/origen/pins/pin_collection.rb', line 543
def method_missing(method, *args, &block)
if size == 1
first.send(method, *args, &block)
elsif method.to_s =~ /.*=$/
each do |pin|
pin.send(method, *args, &block)
end
else
if block_given?
fail 'Blocks are not currently supported by pin collections containing multiple pins!'
else
ref = first.send(method, *args)
if myself.all? { |pin| pin.send(method, *args) == ref }
ref
else
fail "The pins held by pin collection #{id} have different values for #{method}"
end
end
end
end
|
Instance Attribute Details
Returns the value of attribute color.
21
22
23
|
# File 'lib/origen/pins/pin_collection.rb', line 21
def color
@color
end
|
#description ⇒ Object
Returns the value of attribute description.
18
19
20
|
# File 'lib/origen/pins/pin_collection.rb', line 18
def description
@description
end
|
Returns the value of attribute endian.
17
18
19
|
# File 'lib/origen/pins/pin_collection.rb', line 17
def endian
@endian
end
|
Returns the value of attribute group.
19
20
21
|
# File 'lib/origen/pins/pin_collection.rb', line 19
def group
@group
end
|
#group_str ⇒ Object
Returns the value of attribute group_str.
20
21
22
|
# File 'lib/origen/pins/pin_collection.rb', line 20
def group_str
@group_str
end
|
Instance Method Details
#[](*indexes) ⇒ Object
152
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/origen/pins/pin_collection.rb', line 152
def [](*indexes)
if indexes.size > 1 || indexes.first.is_a?(Range)
p = PinCollection.new(owner, @options)
expand_and_order(indexes).each do |index|
p << @store[index]
end
p
else
@store[indexes.first]
end
end
|
#[]=(index, pin) ⇒ Object
174
175
176
|
# File 'lib/origen/pins/pin_collection.rb', line 174
def []=(index, pin)
@store[index] = pin
end
|
#add_pin(pin, _options = {}) ⇒ Object
Also known as:
<<
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
# File 'lib/origen/pins/pin_collection.rb', line 203
def add_pin(pin, _options = {})
if pin.is_a?(PinCollection)
pin.size.times do |i|
pin[i].invalidate_group_cache
@store.push(pin[i])
end
else
if power_pins?
pin = owner.power_pins(pin)
elsif ground_pins?
pin = owner.ground_pins(pin)
elsif other_pins?
pin = owner.other_pins(pin)
elsif virtual_pins?
pin = owner.virtual_pins(pin)
else
pin = owner.pins(pin)
end
unless @store.include?(pin)
pin.invalidate_group_cache
@store.push(pin)
end
end
end
|
#assert(value, options = {}) ⇒ Object
Also known as:
compare, expect, read
373
374
375
376
377
378
379
380
381
382
383
384
385
|
# File 'lib/origen/pins/pin_collection.rb', line 373
def assert(value, options = {})
value = clean_value(value)
each_with_index do |pin, i|
if !value.respond_to?('data')
pin.assert(value[size - i - 1], options)
elsif value[size - i - 1].is_to_be_read?
pin.assert(value[size - i - 1].data, options)
else
pin.dont_care
end
end
myself
end
|
#assert!(*args) ⇒ Object
Also known as:
compare!, expect!, read!
390
391
392
393
|
# File 'lib/origen/pins/pin_collection.rb', line 390
def assert!(*args)
assert(*args)
cycle
end
|
#assert_hi(options = {}) ⇒ Object
Also known as:
expect_hi, compare_hi, read_hi
Set all pins in the pin group to expect 1's on future cycles
399
400
401
402
|
# File 'lib/origen/pins/pin_collection.rb', line 399
def assert_hi(options = {})
each { |pin| pin.assert_hi(options) }
myself
end
|
#assert_hi! ⇒ Object
Also known as:
expect_hi!, compare_hi!, read_hi!
407
408
409
410
|
# File 'lib/origen/pins/pin_collection.rb', line 407
def assert_hi!
assert_hi
cycle
end
|
#assert_lo(options = {}) ⇒ Object
Also known as:
expect_lo, compare_lo, read_lo
Set all pins in the pin group to expect 0's on future cycles
416
417
418
419
|
# File 'lib/origen/pins/pin_collection.rb', line 416
def assert_lo(options = {})
each { |pin| pin.assert_lo(options) }
myself
end
|
#assert_lo! ⇒ Object
Also known as:
expect_lo!, compare_lo!, read_lo!
424
425
426
427
|
# File 'lib/origen/pins/pin_collection.rb', line 424
def assert_lo!
assert_lo
cycle
end
|
#capture ⇒ Object
Also known as:
store
Mark the (data) from all the pins in the pin group to be captured
339
340
341
342
|
# File 'lib/origen/pins/pin_collection.rb', line 339
def capture
each(&:capture)
myself
end
|
#capture! ⇒ Object
Also known as:
store!
345
346
347
348
|
# File 'lib/origen/pins/pin_collection.rb', line 345
def capture!
capture
cycle
end
|
#comparing? ⇒ Boolean
447
448
449
|
# File 'lib/origen/pins/pin_collection.rb', line 447
def comparing?
all?(&:comparing?)
end
|
#comparing_mem? ⇒ Boolean
451
452
453
|
# File 'lib/origen/pins/pin_collection.rb', line 451
def comparing_mem?
all?(&:comparing_mem?)
end
|
369
370
371
|
# File 'lib/origen/pins/pin_collection.rb', line 369
def cycle
Origen.tester.cycle
end
|
#data ⇒ Object
Also known as:
val, value
Returns the data value held by the collection
Example
pins(:porta).write(0x55)
pins(:porta).data
309
310
311
312
313
|
# File 'lib/origen/pins/pin_collection.rb', line 309
def data
data = 0
each_with_index { |pin, i| data |= pin.data << (size - i - 1) }
data
end
|
Returns the inverse of the data value held by the collection
318
319
320
321
|
# File 'lib/origen/pins/pin_collection.rb', line 318
def data_b
~data & ((1 << size) - 1)
end
|
#delete(p) ⇒ Object
Deletes all occurrences of a pin in a pin group
480
481
482
|
# File 'lib/origen/pins/pin_collection.rb', line 480
def delete(p)
@store.delete(p)
end
|
Delete this pingroup (myself)
504
505
506
|
# File 'lib/origen/pins/pin_collection.rb', line 504
def delete!
owner.delete_pin(myself)
end
|
#delete_at(index) ⇒ Object
Deletes the pin at a particular numeric index within the pin group
485
486
487
|
# File 'lib/origen/pins/pin_collection.rb', line 485
def delete_at(index)
@store.delete_at(index)
end
|
#describe(display = :id) ⇒ Object
Describe the pin group contents. Default is to display pin.id but passing in :name will display pin.name
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
# File 'lib/origen/pins/pin_collection.rb', line 180
def describe(display = :id)
desc = ['********************']
desc << "Group id: #{id}"
desc << "\nDescription: #{description}" if description
desc << "\nEndianness: #{endian}"
unless size == 0
desc << ''
desc << 'Pins'
desc << '-------'
if display == :id
desc << map(&:id).join(', ')
elsif display == :name
desc << map(&:name).join(', ')
else
fail 'Error: Argument options for describe method are :id and :name. Default is :id'
end
end
desc << '********************'
puts desc.join("\n")
end
|
#dont_care ⇒ Object
Set all pins in the pin group to X on future cycles
433
434
435
436
|
# File 'lib/origen/pins/pin_collection.rb', line 433
def dont_care
each(&:dont_care)
myself
end
|
#dont_care! ⇒ Object
438
439
440
441
|
# File 'lib/origen/pins/pin_collection.rb', line 438
def dont_care!
dont_care
cycle
end
|
#drive(val) ⇒ Object
Also known as:
write
232
233
234
235
236
237
238
|
# File 'lib/origen/pins/pin_collection.rb', line 232
def drive(val)
value = clean_value(value)
each_with_index do |pin, i|
pin.drive(val[size - i - 1])
end
myself
end
|
#drive!(val) ⇒ Object
Also known as:
write!
241
242
243
244
|
# File 'lib/origen/pins/pin_collection.rb', line 241
def drive!(val)
drive(val)
cycle
end
|
#drive_hi ⇒ Object
Also known as:
write_hi
Set all pins in pin group to drive 1's on future cycles
248
249
250
251
|
# File 'lib/origen/pins/pin_collection.rb', line 248
def drive_hi
each(&:drive_hi)
myself
end
|
#drive_hi! ⇒ Object
Also known as:
write_hi!
254
255
256
257
|
# File 'lib/origen/pins/pin_collection.rb', line 254
def drive_hi!
drive_hi
cycle
end
|
#drive_lo ⇒ Object
Also known as:
write_lo
Set all pins in pin group to drive 0's on future cycles
261
262
263
264
|
# File 'lib/origen/pins/pin_collection.rb', line 261
def drive_lo
each(&:drive_lo)
myself
end
|
#drive_lo! ⇒ Object
Also known as:
write_lo!
267
268
269
270
|
# File 'lib/origen/pins/pin_collection.rb', line 267
def drive_lo!
drive_lo
cycle
end
|
#drive_mem ⇒ Object
285
286
287
288
|
# File 'lib/origen/pins/pin_collection.rb', line 285
def drive_mem
each(&:drive_mem)
myself
end
|
#drive_mem! ⇒ Object
290
291
292
293
|
# File 'lib/origen/pins/pin_collection.rb', line 290
def drive_mem!
drive_mem
cycle
end
|
#drive_very_hi ⇒ Object
Set all pins in the pin group to drive a high voltage on future cycles (if the tester supports it). For example on a J750 high-voltage channel the pin state would be set to “2”
275
276
277
278
|
# File 'lib/origen/pins/pin_collection.rb', line 275
def drive_very_hi
each(&:drive_very_hi)
myself
end
|
#drive_very_hi! ⇒ Object
280
281
282
283
|
# File 'lib/origen/pins/pin_collection.rb', line 280
def drive_very_hi!
drive_very_hi
cycle
end
|
#driving? ⇒ Boolean
455
456
457
|
# File 'lib/origen/pins/pin_collection.rb', line 455
def driving?
all?(&:driving?)
end
|
#driving_mem? ⇒ Boolean
459
460
461
|
# File 'lib/origen/pins/pin_collection.rb', line 459
def driving_mem?
all?(&:driving_mem?)
end
|
Overrides the regular Ruby array each to be endian aware. If the pin collection/group is defined as big endian then this will yield the least significant pin first, otherwise for little endian the most significant pin will come out first.
138
139
140
141
142
143
144
145
146
|
# File 'lib/origen/pins/pin_collection.rb', line 138
def each
size.times do |i|
if endian == :big
yield @store[size - i - 1]
else
yield @store[i]
end
end
end
|
#expect_mem ⇒ Object
295
296
297
298
|
# File 'lib/origen/pins/pin_collection.rb', line 295
def expect_mem
each(&:expect_mem)
myself
end
|
#expect_mem! ⇒ Object
300
301
302
303
|
# File 'lib/origen/pins/pin_collection.rb', line 300
def expect_mem!
expect_mem
cycle
end
|
#global_path_to ⇒ Object
47
48
49
|
# File 'lib/origen/pins/pin_collection.rb', line 47
def global_path_to
"dut.pins(:#{id})"
end
|
#ground_pins? ⇒ Boolean
Returns true if the pin collection contains ground pins rather than regular pins
108
109
110
|
# File 'lib/origen/pins/pin_collection.rb', line 108
def ground_pins?
@ground_pins
end
|
#high_voltage? ⇒ Boolean
463
464
465
|
# File 'lib/origen/pins/pin_collection.rb', line 463
def high_voltage?
all?(&:high_voltage?)
end
|
122
123
124
|
# File 'lib/origen/pins/pin_collection.rb', line 122
def id
@id
end
|
365
366
367
|
# File 'lib/origen/pins/pin_collection.rb', line 365
def id=(val)
@id = val.to_sym
end
|
#invalidate_vector_cache ⇒ Object
This method is part of a private API.
You should avoid using this method if possible, as it may be removed or be changed in the future.
72
73
74
|
# File 'lib/origen/pins/pin_collection.rb', line 72
def invalidate_vector_cache
@vector_formatted_value = nil
end
|
#inverted? ⇒ Boolean
443
444
445
|
# File 'lib/origen/pins/pin_collection.rb', line 443
def inverted?
all?(&:inverted?)
end
|
131
132
133
|
# File 'lib/origen/pins/pin_collection.rb', line 131
def name
@name || id
end
|
#name=(val) ⇒ Object
Explicitly set the name of a pin group/collection
127
128
129
|
# File 'lib/origen/pins/pin_collection.rb', line 127
def name=(val)
@name = val
end
|
#org_file_intercepted_methods ⇒ Object
#other_pins? ⇒ Boolean
Returns true if the pin collection contains other pins rather than regular pins
118
119
120
|
# File 'lib/origen/pins/pin_collection.rb', line 118
def other_pins?
@other_pins
end
|
#pins(nick = :id) ⇒ Object
489
490
491
492
493
494
495
496
497
498
499
500
501
|
# File 'lib/origen/pins/pin_collection.rb', line 489
def pins(nick = :id)
Origen.deprecate <<-END
The PinCollection#pins method is deprecated, if you want to get a list of pin IDs
in the given collection just do pins(:some_group).map(&:id)
Note that the pins method (confusingly) also does a sort, to replicate that:
pins(:some_group).map(&:id).sort
END
if nick == :id
@store.map(&:id).sort
elsif nick == :name
@store.map(&:name).sort
end
end
|
#power_pins? ⇒ Boolean
Returns true if the pin collection contains power pins rather than regular pins
103
104
105
|
# File 'lib/origen/pins/pin_collection.rb', line 103
def power_pins?
@power_pins
end
|
#repeat_previous=(bool) ⇒ Object
333
334
335
336
|
# File 'lib/origen/pins/pin_collection.rb', line 333
def repeat_previous=(bool)
each { |pin| pin.repeat_previous = bool }
myself
end
|
#repeat_previous? ⇒ Boolean
467
468
469
|
# File 'lib/origen/pins/pin_collection.rb', line 467
def repeat_previous?
all?(&:repeat_previous?)
end
|
361
362
363
|
# File 'lib/origen/pins/pin_collection.rb', line 361
def restore
each(&:restore)
end
|
#restore_state ⇒ Object
351
352
353
354
355
|
# File 'lib/origen/pins/pin_collection.rb', line 351
def restore_state
save
yield
restore
end
|
43
44
45
|
# File 'lib/origen/pins/pin_collection.rb', line 43
def rtl_name
(@rtl_name || id).to_s
end
|
357
358
359
|
# File 'lib/origen/pins/pin_collection.rb', line 357
def save
each(&:save)
end
|
148
149
150
|
# File 'lib/origen/pins/pin_collection.rb', line 148
def size
@store.size
end
|
#sort!(&block) ⇒ Object
164
165
166
167
|
# File 'lib/origen/pins/pin_collection.rb', line 164
def sort!(&block)
@store = sort(&block)
myself
end
|
169
170
171
172
|
# File 'lib/origen/pins/pin_collection.rb', line 169
def sort_by!
@store = sort_by
myself
end
|
#to_be_captured? ⇒ Boolean
Also known as:
to_be_stored?, is_to_be_stored?, is_to_be_captured?
Returns true if the (data) from the pin collection is marked to be captured
472
473
474
|
# File 'lib/origen/pins/pin_collection.rb', line 472
def to_be_captured?
all?(&:to_be_captured?)
end
|
#to_vector ⇒ Object
Returns the value held by the pin group as a string formatted to the current tester's pattern syntax
63
64
65
66
67
68
69
|
# File 'lib/origen/pins/pin_collection.rb', line 63
def to_vector
return @vector_formatted_value if @vector_formatted_value
vals = map(&:to_vector)
vals.reverse! if endian == :little
@vector_formatted_value = vals.join('')
end
|
323
324
325
326
|
# File 'lib/origen/pins/pin_collection.rb', line 323
def toggle
each(&:toggle)
myself
end
|
328
329
330
331
|
# File 'lib/origen/pins/pin_collection.rb', line 328
def toggle!
toggle
cycle
end
|
Set the values and states of the pin group's pins from a string formatted to the current tester's pattern syntax, this is the opposite of the to_vector method
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/origen/pins/pin_collection.rb', line 89
def vector_formatted_value=(val)
unless @vector_formatted_value == val
unless val.size == size
fail 'When setting vector_formatted_value on a pin group you must supply values for all pins!'
end
val.split(//).reverse.each_with_index do |val, i|
myself[i].vector_formatted_value = val
end
@vector_formatted_value = val
end
end
|
#virtual_pins? ⇒ Boolean
Returns true if the pin collection contains virtual pins rather than regular pins
113
114
115
|
# File 'lib/origen/pins/pin_collection.rb', line 113
def virtual_pins?
@virtual_pins
end
|