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 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

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)



540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
# File 'lib/origen/pins/pin_collection.rb', line 540

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, read



371
372
373
374
375
376
377
378
379
380
381
382
383
# File 'lib/origen/pins/pin_collection.rb', line 371

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!



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

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



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

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

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



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

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



414
415
416
417
# File 'lib/origen/pins/pin_collection.rb', line 414

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

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



422
423
424
425
# File 'lib/origen/pins/pin_collection.rb', line 422

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



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

def capture
  each(&:capture)
  myself
end

#capture!Object Also known as: store!



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

def capture!
  capture
  cycle
end

#comparing?Boolean

Returns:

  • (Boolean)


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

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

#comparing_mem?Boolean

Returns:

  • (Boolean)


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

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

#cycleObject



367
368
369
# File 'lib/origen/pins/pin_collection.rb', line 367

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


307
308
309
310
311
# File 'lib/origen/pins/pin_collection.rb', line 307

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



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

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



478
479
480
# File 'lib/origen/pins/pin_collection.rb', line 478

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

#delete!Object

Delete this pingroup (myself)



502
503
504
# File 'lib/origen/pins/pin_collection.rb', line 502

def delete!
  owner.delete_pin(myself)
end

#delete_at(index) ⇒ Object

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



483
484
485
# File 'lib/origen/pins/pin_collection.rb', line 483

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



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

def dont_care
  each(&:dont_care)
  myself
end

#dont_care!Object



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

def dont_care!
  dont_care
  cycle
end

#drive(val) ⇒ Object Also known as: write



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 Also known as: write!



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

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

#drive_hiObject Also known as: write_hi

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



246
247
248
249
# File 'lib/origen/pins/pin_collection.rb', line 246

def drive_hi
  each(&:drive_hi)
  myself
end

#drive_hi!Object Also known as: write_hi!



252
253
254
255
# File 'lib/origen/pins/pin_collection.rb', line 252

def drive_hi!
  drive_hi
  cycle
end

#drive_loObject Also known as: write_lo

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



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

def drive_lo
  each(&:drive_lo)
  myself
end

#drive_lo!Object Also known as: write_lo!



265
266
267
268
# File 'lib/origen/pins/pin_collection.rb', line 265

def drive_lo!
  drive_lo
  cycle
end

#drive_memObject



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

def drive_mem
  each(&:drive_mem)
  myself
end

#drive_mem!Object



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

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”



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

def drive_very_hi
  each(&:drive_very_hi)
  myself
end

#drive_very_hi!Object



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

def drive_very_hi!
  drive_very_hi
  cycle
end

#driving?Boolean

Returns:

  • (Boolean)


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

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

#driving_mem?Boolean

Returns:

  • (Boolean)


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

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



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

def expect_mem
  each(&:expect_mem)
  myself
end

#expect_mem!Object



298
299
300
301
# File 'lib/origen/pins/pin_collection.rb', line 298

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)


461
462
463
# File 'lib/origen/pins/pin_collection.rb', line 461

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



363
364
365
# File 'lib/origen/pins/pin_collection.rb', line 363

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)


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

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



487
488
489
490
491
492
493
494
495
496
497
498
499
# File 'lib/origen/pins/pin_collection.rb', line 487

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



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

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

#repeat_previous?Boolean

Returns:

  • (Boolean)


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

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

#restoreObject



359
360
361
# File 'lib/origen/pins/pin_collection.rb', line 359

def restore
  each(&:restore)
end

#restore_stateObject



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

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



355
356
357
# File 'lib/origen/pins/pin_collection.rb', line 355

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)


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

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



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

def toggle
  each(&:toggle)
  myself
end

#toggle!Object



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

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