Class: Origen::Pins::PinBank

Inherits:
Object
  • Object
show all
Includes:
Origen::PersistentCallbacks
Defined in:
lib/origen/pins/pin_bank.rb

Overview

Stores all pins, pin aliases and pin groups for the current target. A central store is used to allow either top-level or sub-block objects to add pins to the current context available to the testers.

The global Origen pin bank (an instance of this class) is returned from Origen.pin_bank.

Instance Method Summary collapse

Methods included from Origen::PersistentCallbacks

#register_callback_listener

Instance Method Details

#add_pin(pin, _owner, _options = {}) ⇒ Origen::Pins::Pin

Add the given pin to the bank

Returns:



21
22
23
24
25
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
# File 'lib/origen/pins/pin_bank.rb', line 21

def add_pin(pin, _owner, _options = {})
  if pin.is_a?(PowerPin)
    bank = all_power_pins
  elsif pin.is_a?(GroundPin)
    bank = all_ground_pins
  elsif pin.is_a?(VirtualPin)
    bank = all_virtual_pins
  elsif pin.is_a?(OtherPin)
    bank = all_other_pins
  else
    bank = all_pins
  end
  if bank[pin.id]
    fail "A pin with id #{pin.id} already exists!"
  end

  all_ids << pin.id
  bank[pin.id] = pin
  # If ends in a number
  # if !options[:dont_create_group] && pin.id.to_s =~ /(.*?)(\d+)$/
  #  # Create a new group if one with the given name doesn't already exist
  #  unless group = all_pin_groups[$1.to_sym]
  #    group = PinCollection.new(owner, options)
  #    group.id = $1.to_sym
  #    all_pin_groups[$1.to_sym] = group
  #  end
  #  group.add_pin(pin)
  # end
  pin
end

#add_pin_group(group, owner, options = {}) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/origen/pins/pin_bank.rb', line 52

def add_pin_group(group, owner, options = {})
  unless options[:pins_exist]
    group.each do |pin|
      add_pin(pin, owner, options.merge(dont_create_group: true))
    end
  end
  store_pin_group(group, options)
  group
end

#all_ground_pin_groupsObject

Returns a hash containing all ground pin groups stored by context



164
165
166
# File 'lib/origen/pins/pin_bank.rb', line 164

def all_ground_pin_groups
  @all_ground_pin_groups ||= {}
end

#all_ground_pinsObject

Returns a hash containing all ground pins stored by their primary ID



144
145
146
# File 'lib/origen/pins/pin_bank.rb', line 144

def all_ground_pins
  @all_ground_pins ||= {}
end

#all_other_pin_groupsObject

Returns a hash containing all other pin groups stored by context



169
170
171
# File 'lib/origen/pins/pin_bank.rb', line 169

def all_other_pin_groups
  @all_other_pin_groups ||= {}
end

#all_other_pinsObject

Returns a hash containing all other pins stored by their primary ID



149
150
151
# File 'lib/origen/pins/pin_bank.rb', line 149

def all_other_pins
  @all_other_pins ||= {}
end

#all_pin_groupsObject

Returns a hash containing all pin groups stored by context



134
135
136
# File 'lib/origen/pins/pin_bank.rb', line 134

def all_pin_groups
  @all_pin_groups ||= {}
end

#all_pinsObject

Returns a hash containing all pins stored by their primary ID



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

def all_pins
  @all_pins ||= {}
end

#all_power_pin_groupsObject

Returns a hash containing all power pin groups stored by context



159
160
161
# File 'lib/origen/pins/pin_bank.rb', line 159

def all_power_pin_groups
  @all_power_pin_groups ||= {}
end

#all_power_pinsObject

Returns a hash containing all power pins stored by their primary ID



139
140
141
# File 'lib/origen/pins/pin_bank.rb', line 139

def all_power_pins
  @all_power_pins ||= {}
end

#all_virtual_pin_groupsObject

Returns a hash containing all virtual pin groups stored by context



174
175
176
# File 'lib/origen/pins/pin_bank.rb', line 174

def all_virtual_pin_groups
  @all_virtual_pin_groups ||= {}
end

#all_virtual_pinsObject

Returns a hash containing all virtual pins stored by their primary ID



154
155
156
# File 'lib/origen/pins/pin_bank.rb', line 154

def all_virtual_pins
  @all_virtual_pins ||= {}
end

#before_load_targetObject

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.

There is one pin bank per Origen thread, this clears the bank every time the target is changed



14
15
16
# File 'lib/origen/pins/pin_bank.rb', line 14

def before_load_target
  empty!
end

#delete_pin(pin) ⇒ Object

Delete a specific pin



237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/origen/pins/pin_bank.rb', line 237

def delete_pin(pin)
  if pin.is_a?(PowerPin)
    bank = all_power_pins
  elsif pin.is_a?(GroundPin)
    bank = all_ground_pins
  elsif pin.is_a?(OtherPin)
    bank = all_other_pins
  elsif pin.is_a?(VirtualPin)
    bank = all_virtual_pins
  else
    bank = all_pins
  end
  # First delete the pin from any of the pin groups it resides
  Origen.pin_bank.pin_groups.each do |_name, grp|
    next unless grp.store.include?(pin)

    grp.delete(pin)
  end
  # Now delete the pin from the pin bank
  if bank[pin.id]
    bank.delete(pin.id)
    # Delete all known aliases as well
    known_aliases.delete(pin.name)
  else
    if pin.id == pin.name
      fail "A pin with id #{pin.id} does not exist!"
    else
      fail "A pin with id #{pin.id} and name #{pin.name} does not exist!"
    end
  end
end

#delete_pingroup(group) ⇒ Object

Delete a specific pin group



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/origen/pins/pin_bank.rb', line 270

def delete_pingroup(group)
  found_group = false
  if group.power_pins?
    base = all_power_pin_groups
  elsif group.ground_pins?
    base = all_ground_pin_groups
  elsif group.other_pins?
    base = all_other_pin_groups
  elsif group.virtual_pins?
    base = all_virtual_pin_groups
  else
    base = all_pin_groups
  end
  pin_group_stores_in_context(base) do |store|
    if store.include?(group.id)
      store.delete(group.id)
      found_group = true
    end
  end
  fail "A pin group with id #{group.id} does not exist!" unless found_group == true
end

#find(id, options = {}) ⇒ Object



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

def find(id, options = {})
  id = id.to_sym
  if options[:power_pin]
    pin = all_power_pins[id] || find_pin_group(id, options)
  elsif options[:ground_pin]
    pin = all_ground_pins[id] || find_pin_group(id, options)
  elsif options[:virtual_pin]
    pin = all_virtual_pins[id] || find_pin_group(id, options)
  elsif options[:other_pin]
    pin = all_other_pins[id] || find_pin_group(id, options)
  else
    pin = all_pins[id] || find_by_alias(id, options) || find_pin_group(id, options)
  end
  if pin
    if options[:ignore_context] || pin.enabled?(options)
      pin
    end
  end
end

#find_or_create_pin_group(id, owner, options = {}) ⇒ Object

Find an existing pin group with the given ID if it exists and return it, otherwise create one



226
227
228
229
230
231
232
233
234
# File 'lib/origen/pins/pin_bank.rb', line 226

def find_or_create_pin_group(id, owner, options = {})
  group = find_pin_group(id, options)
  unless group
    group = PinCollection.new(owner, options)
    group.id = id
    store_pin_group(group, options)
  end
  group
end

#find_pin_group(id, options = {}) ⇒ Object



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/origen/pins/pin_bank.rb', line 198

def find_pin_group(id, options = {})
  options = {
    include_all: true
  }.merge(options)
  if options[:power_pin]
    base = all_power_pin_groups
  elsif options[:ground_pin]
    base = all_ground_pin_groups
  elsif options[:other_pin]
    base = all_other_pin_groups
  elsif options[:virtual_pin]
    base = all_virtual_pin_groups
  else
    base = all_pin_groups
  end
  pin_group_stores_in_context(base, options) do |store|
    return store[id] if store[id]
  end
  nil
end

#ground_pin_groups(options = {}) ⇒ Object

Returns a hash containing all ground_pin_groups available in the current context stored by their primary ID



108
109
110
111
112
# File 'lib/origen/pins/pin_bank.rb', line 108

def ground_pin_groups(options = {})
  current_pin_group_store(all_ground_pin_groups, options).select do |_id, group|
    group.enabled?(options)
  end
end

#ground_pins(options = {}) ⇒ Object



75
76
77
78
79
# File 'lib/origen/pins/pin_bank.rb', line 75

def ground_pins(options = {})
  all_ground_pins.select do |_id, pin|
    pin.enabled?(options)
  end
end

#other_pin_groups(options = {}) ⇒ Object

Returns a hash containing all ground_pin_groups available in the current context stored by their primary ID



115
116
117
118
119
# File 'lib/origen/pins/pin_bank.rb', line 115

def other_pin_groups(options = {})
  current_pin_group_store(all_other_pin_groups, options).select do |_id, group|
    group.enabled?(options)
  end
end

#other_pins(options = {}) ⇒ Object



81
82
83
84
85
# File 'lib/origen/pins/pin_bank.rb', line 81

def other_pins(options = {})
  all_other_pins.select do |_id, pin|
    pin.enabled?(options)
  end
end

#pin_groups(options = {}) ⇒ Object

Returns a hash containing all pin_groups available in the current context stored by their primary ID



94
95
96
97
98
# File 'lib/origen/pins/pin_bank.rb', line 94

def pin_groups(options = {})
  current_pin_group_store(all_pin_groups, options).select do |_id, group|
    group.enabled?(options)
  end
end

#pins(options = {}) ⇒ Object

Returns a hash containing all pins available in the current context stored by their primary ID



63
64
65
66
67
# File 'lib/origen/pins/pin_bank.rb', line 63

def pins(options = {})
  all_pins.select do |_id, pin|
    pin.enabled?(options)
  end
end

#power_pin_groups(options = {}) ⇒ Object

Returns a hash containing all power_pin_groups available in the current context stored by their primary ID



101
102
103
104
105
# File 'lib/origen/pins/pin_bank.rb', line 101

def power_pin_groups(options = {})
  current_pin_group_store(all_power_pin_groups, options).select do |_id, group|
    group.enabled?(options)
  end
end

#power_pins(options = {}) ⇒ Object



69
70
71
72
73
# File 'lib/origen/pins/pin_bank.rb', line 69

def power_pins(options = {})
  all_power_pins.select do |_id, pin|
    pin.enabled?(options)
  end
end

#register_alias(id, pin, _options = {}) ⇒ Object

This will be called by the pins whenever a new alias is added to them



220
221
222
223
# File 'lib/origen/pins/pin_bank.rb', line 220

def register_alias(id, pin, _options = {})
  known_aliases[id] ||= []
  known_aliases[id] << pin
end

#virtual_pin_groups(options = {}) ⇒ Object

Returns a hash containing all virtual_pin_groups available in the current context stored by their primary ID



122
123
124
125
126
# File 'lib/origen/pins/pin_bank.rb', line 122

def virtual_pin_groups(options = {})
  current_pin_group_store(all_virtual_pin_groups, options).select do |_id, group|
    group.enabled?(options)
  end
end

#virtual_pins(options = {}) ⇒ Object



87
88
89
90
91
# File 'lib/origen/pins/pin_bank.rb', line 87

def virtual_pins(options = {})
  all_virtual_pins.select do |_id, pin|
    pin.enabled?(options)
  end
end