Class: Origen::Pins::PinCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable, OrgFile::Interceptable, PinCommon
Defined in:
lib/origen/pins/pin_collection.rb

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

ORG_FILE_INTERCEPTED_METHODS =
[
  :drive, :drive_hi, :drive_lo, :drive_very_hi, :drive_mem, :expect_mem, :toggle,
  :repeat_previous=, :capture, :assert, :compare, :expect,
  :assert_hi, :expect_hi, :compare_hi, :assert_lo, :expect_lo, :compare_lo,
  :dont_care
]

Constants included from Enumerable

Enumerable::PRIMATIVES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OrgFile::Interceptable

#__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 (private)


528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
# File 'lib/origen/pins/pin_collection.rb', line 528

def method_missing(method, *args, &block)
  # Where the collection is only comprised of one pin delegate missing methods/attributes
  # to that pin
  if size == 1
    first.send(method, *args, &block)
  # Send all assignment methods to all contained pins
  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
      # Allow getters if all pins are the same
      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

#colorObject

Returns the value of attribute color


21
22
23
# File 'lib/origen/pins/pin_collection.rb', line 21

def color
  @color
end

#descriptionObject

Returns the value of attribute description


18
19
20
# File 'lib/origen/pins/pin_collection.rb', line 18

def description
  @description
end

#endianObject

Returns the value of attribute endian


17
18
19
# File 'lib/origen/pins/pin_collection.rb', line 17

def endian
  @endian
end

#groupObject

Returns the value of attribute group


19
20
21
# File 'lib/origen/pins/pin_collection.rb', line 19

def group
  @group
end

#group_strObject

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


150
151
152
153
154
155
156
157
158
159
160
# File 'lib/origen/pins/pin_collection.rb', line 150

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


172
173
174
# File 'lib/origen/pins/pin_collection.rb', line 172

def []=(index, pin)
  @store[index] = pin
end

#add_pin(pin, _options = {}) ⇒ Object Also known as: <<


201
202
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
# File 'lib/origen/pins/pin_collection.rb', line 201

def add_pin(pin, _options = {})
  if pin.is_a?(PinCollection)
    # Need this to bypass the endianness aware iteration, the storing order
    # is always the same. So can't use each and co here.
    pin.size.times do |i|
      pin[i].invalidate_group_cache
      @store.push(pin[i])
    end
  else
    # Convert any named reference to a pin object
    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


365
366
367
368
369
370
371
372
373
374
375
376
377
# File 'lib/origen/pins/pin_collection.rb', line 365

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!


381
382
383
384
# File 'lib/origen/pins/pin_collection.rb', line 381

def assert!(*args)
  assert(*args)
  cycle
end

#assert_hi(options = {}) ⇒ Object Also known as: expect_hi, compare_hi

Set all pins in the pin group to expect 1's on future cycles


389
390
391
392
# File 'lib/origen/pins/pin_collection.rb', line 389

def assert_hi(options = {})
  each { |pin| pin.assert_hi(options) }
  myself
end

#assert_hi!Object Also known as: expect_hi!, compare_hi!


396
397
398
399
# File 'lib/origen/pins/pin_collection.rb', line 396

def assert_hi!
  assert_hi
  cycle
end

#assert_lo(options = {}) ⇒ Object Also known as: expect_lo, compare_lo

Set all pins in the pin group to expect 0's on future cycles


404
405
406
407
# File 'lib/origen/pins/pin_collection.rb', line 404

def assert_lo(options = {})
  each { |pin| pin.assert_lo(options) }
  myself
end

#assert_lo!Object Also known as: expect_lo!, compare_lo!


411
412
413
414
# File 'lib/origen/pins/pin_collection.rb', line 411

def assert_lo!
  assert_lo
  cycle
end

#captureObject Also known as: store

Mark the (data) from all the pins in the pin group to be captured


331
332
333
334
# File 'lib/origen/pins/pin_collection.rb', line 331

def capture
  each(&:capture)
  myself
end

#capture!Object Also known as: store!


337
338
339
340
# File 'lib/origen/pins/pin_collection.rb', line 337

def capture!
  capture
  cycle
end

#comparing?Boolean

Returns:

  • (Boolean)

433
434
435
# File 'lib/origen/pins/pin_collection.rb', line 433

def comparing?
  all?(&:comparing?)
end

#comparing_mem?Boolean

Returns:

  • (Boolean)

437
438
439
# File 'lib/origen/pins/pin_collection.rb', line 437

def comparing_mem?
  all?(&:comparing_mem?)
end

#cycleObject


361
362
363
# File 'lib/origen/pins/pin_collection.rb', line 361

def cycle
  Origen.tester.cycle
end

#dataObject Also known as: val, value

Returns the data value held by the collection

Example

pins(:porta).write(0x55)
pins(:porta).data         #  => 0x55

301
302
303
304
305
# File 'lib/origen/pins/pin_collection.rb', line 301

def data
  data = 0
  each_with_index { |pin, i| data |= pin.data << (size - i - 1) }
  data
end

#data_bObject

Returns the inverse of the data value held by the collection


310
311
312
313
# File 'lib/origen/pins/pin_collection.rb', line 310

def data_b
  # (& operation takes care of Bignum formatting issues)
  ~data & ((1 << size) - 1)
end

#delete(p) ⇒ Object

Deletes all occurrences of a pin in a pin group


466
467
468
# File 'lib/origen/pins/pin_collection.rb', line 466

def delete(p)
  @store.delete(p)
end

#delete!Object

Delete this pingroup (myself)


490
491
492
# File 'lib/origen/pins/pin_collection.rb', line 490

def delete!
  owner.delete_pin(myself)
end

#delete_at(index) ⇒ Object

Deletes the pin at a particular numeric index within the pin group


471
472
473
# File 'lib/origen/pins/pin_collection.rb', line 471

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


178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/origen/pins/pin_collection.rb', line 178

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_careObject

Set all pins in the pin group to X on future cycles


419
420
421
422
# File 'lib/origen/pins/pin_collection.rb', line 419

def dont_care
  each(&:dont_care)
  myself
end

#dont_care!Object


424
425
426
427
# File 'lib/origen/pins/pin_collection.rb', line 424

def dont_care!
  dont_care
  cycle
end

#drive(val) ⇒ Object


230
231
232
233
234
235
236
# File 'lib/origen/pins/pin_collection.rb', line 230

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


238
239
240
241
# File 'lib/origen/pins/pin_collection.rb', line 238

def drive!(val)
  drive(val)
  cycle
end

#drive_hiObject

Set all pins in pin group to drive 1's on future cycles


244
245
246
247
# File 'lib/origen/pins/pin_collection.rb', line 244

def drive_hi
  each(&:drive_hi)
  myself
end

#drive_hi!Object


249
250
251
252
# File 'lib/origen/pins/pin_collection.rb', line 249

def drive_hi!
  drive_hi
  cycle
end

#drive_loObject

Set all pins in pin group to drive 0's on future cycles


255
256
257
258
# File 'lib/origen/pins/pin_collection.rb', line 255

def drive_lo
  each(&:drive_lo)
  myself
end

#drive_lo!Object


260
261
262
263
# File 'lib/origen/pins/pin_collection.rb', line 260

def drive_lo!
  drive_lo
  cycle
end

#drive_memObject


277
278
279
280
# File 'lib/origen/pins/pin_collection.rb', line 277

def drive_mem
  each(&:drive_mem)
  myself
end

#drive_mem!Object


282
283
284
285
# File 'lib/origen/pins/pin_collection.rb', line 282

def drive_mem!
  drive_mem
  cycle
end

#drive_very_hiObject

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”


267
268
269
270
# File 'lib/origen/pins/pin_collection.rb', line 267

def drive_very_hi
  each(&:drive_very_hi)
  myself
end

#drive_very_hi!Object


272
273
274
275
# File 'lib/origen/pins/pin_collection.rb', line 272

def drive_very_hi!
  drive_very_hi
  cycle
end

#driving?Boolean

Returns:

  • (Boolean)

441
442
443
# File 'lib/origen/pins/pin_collection.rb', line 441

def driving?
  all?(&:driving?)
end

#driving_mem?Boolean

Returns:

  • (Boolean)

445
446
447
# File 'lib/origen/pins/pin_collection.rb', line 445

def driving_mem?
  all?(&:driving_mem?)
end

#eachObject

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.


136
137
138
139
140
141
142
143
144
# File 'lib/origen/pins/pin_collection.rb', line 136

def each
  size.times do |i|
    if endian == :big
      yield @store[size - i - 1]
    else
      yield @store[i]
    end
  end
end

#expect_memObject


287
288
289
290
# File 'lib/origen/pins/pin_collection.rb', line 287

def expect_mem
  each(&:expect_mem)
  myself
end

#expect_mem!Object


292
293
294
295
# File 'lib/origen/pins/pin_collection.rb', line 292

def expect_mem!
  expect_mem
  cycle
end

#global_path_toObject


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

Returns:

  • (Boolean)

106
107
108
# File 'lib/origen/pins/pin_collection.rb', line 106

def ground_pins?
  @ground_pins
end

#high_voltage?Boolean

Returns:

  • (Boolean)

449
450
451
# File 'lib/origen/pins/pin_collection.rb', line 449

def high_voltage?
  all?(&:high_voltage?)
end

#idObject


120
121
122
# File 'lib/origen/pins/pin_collection.rb', line 120

def id
  @id
end

#id=(val) ⇒ Object


357
358
359
# File 'lib/origen/pins/pin_collection.rb', line 357

def id=(val)
  @id = val.to_sym
end

#invalidate_vector_cacheObject

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.


71
72
73
# File 'lib/origen/pins/pin_collection.rb', line 71

def invalidate_vector_cache
  @vector_formatted_value = nil
end

#inverted?Boolean

Returns:

  • (Boolean)

429
430
431
# File 'lib/origen/pins/pin_collection.rb', line 429

def inverted?
  all?(&:inverted?)
end

#nameObject


129
130
131
# File 'lib/origen/pins/pin_collection.rb', line 129

def name
  @name || id
end

#name=(val) ⇒ Object

Explicitly set the name of a pin group/collection


125
126
127
# File 'lib/origen/pins/pin_collection.rb', line 125

def name=(val)
  @name = val
end

#org_file_intercepted_methodsObject


51
52
53
# File 'lib/origen/pins/pin_collection.rb', line 51

def org_file_intercepted_methods
  ORG_FILE_INTERCEPTED_METHODS
end

#other_pins?Boolean

Returns true if the pin collection contains other pins rather than regular pins

Returns:

  • (Boolean)

116
117
118
# File 'lib/origen/pins/pin_collection.rb', line 116

def other_pins?
  @other_pins
end

#pins(nick = :id) ⇒ Object


475
476
477
478
479
480
481
482
483
484
485
486
487
# File 'lib/origen/pins/pin_collection.rb', line 475

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

Returns:

  • (Boolean)

101
102
103
# File 'lib/origen/pins/pin_collection.rb', line 101

def power_pins?
  @power_pins
end

#repeat_previous=(bool) ⇒ Object


325
326
327
328
# File 'lib/origen/pins/pin_collection.rb', line 325

def repeat_previous=(bool)
  each { |pin| pin.repeat_previous = bool }
  myself
end

#repeat_previous?Boolean

Returns:

  • (Boolean)

453
454
455
# File 'lib/origen/pins/pin_collection.rb', line 453

def repeat_previous?
  all?(&:repeat_previous?)
end

#restoreObject


353
354
355
# File 'lib/origen/pins/pin_collection.rb', line 353

def restore
  each(&:restore)
end

#restore_stateObject


343
344
345
346
347
# File 'lib/origen/pins/pin_collection.rb', line 343

def restore_state
  save
  yield
  restore
end

#rtl_nameObject


43
44
45
# File 'lib/origen/pins/pin_collection.rb', line 43

def rtl_name
  (@rtl_name || id).to_s
end

#saveObject


349
350
351
# File 'lib/origen/pins/pin_collection.rb', line 349

def save
  each(&:save)
end

#sizeObject


146
147
148
# File 'lib/origen/pins/pin_collection.rb', line 146

def size
  @store.size
end

#sort!(&block) ⇒ Object


162
163
164
165
# File 'lib/origen/pins/pin_collection.rb', line 162

def sort!(&block)
  @store = sort(&block)
  myself
end

#sort_by!Object


167
168
169
170
# File 'lib/origen/pins/pin_collection.rb', line 167

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

Returns:

  • (Boolean)

458
459
460
# File 'lib/origen/pins/pin_collection.rb', line 458

def to_be_captured?
  all?(&:to_be_captured?)
end

#to_vectorObject

Returns the value held by the pin group as a string formatted to the current tester's pattern syntax

Examples:


pin_group.drive_hi
pin_group.to_vector   # => "11111111"
pin_group.expect_lo
pin_group.to_vector   # => "LLLLLLLL"

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

#toggleObject


315
316
317
318
# File 'lib/origen/pins/pin_collection.rb', line 315

def toggle
  each(&:toggle)
  myself
end

#toggle!Object


320
321
322
323
# File 'lib/origen/pins/pin_collection.rb', line 320

def toggle!
  toggle
  cycle
end

#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

Examples:


pin_group.vector_formatted_value = "LLLLLLLL"
pin_group[0].driving?                          # => false
pin_group[0].value                             # => 0
pin_group.vector_formatted_value = "HHHH1111"
pin_group[0].driving?                          # => true
pin_group[0].value                             # => 1
pin_group[7].driving?                          # => false
pin_group[7].value                             # => 1

88
89
90
91
92
93
94
95
96
97
98
# File 'lib/origen/pins/pin_collection.rb', line 88

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

Returns:

  • (Boolean)

111
112
113
# File 'lib/origen/pins/pin_collection.rb', line 111

def virtual_pins?
  @virtual_pins
end