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



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

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



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

def all_ground_pins
  @all_ground_pins ||= {}
end

#all_other_pin_groupsObject

Returns a hash containing all other pin groups stored by context



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

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



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

def all_other_pins
  @all_other_pins ||= {}
end

#all_pin_groupsObject

Returns a hash containing all pin groups stored by context



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

def all_pin_groups
  @all_pin_groups ||= {}
end

#all_pinsObject

Returns a hash containing all pins stored by their primary ID



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

def all_pins
  @all_pins ||= {}
end

#all_power_pin_groupsObject

Returns a hash containing all power pin groups stored by context



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

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



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

def all_power_pins
  @all_power_pins ||= {}
end

#all_virtual_pin_groupsObject

Returns a hash containing all virtual pin groups stored by context



179
180
181
# File 'lib/origen/pins/pin_bank.rb', line 179

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



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

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



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
268
269
270
271
272
# File 'lib/origen/pins/pin_bank.rb', line 242

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



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/origen/pins/pin_bank.rb', line 275

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



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/origen/pins/pin_bank.rb', line 183

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



231
232
233
234
235
236
237
238
239
# File 'lib/origen/pins/pin_bank.rb', line 231

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



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/origen/pins/pin_bank.rb', line 203

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



113
114
115
116
117
# File 'lib/origen/pins/pin_bank.rb', line 113

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



77
78
79
80
81
82
# File 'lib/origen/pins/pin_bank.rb', line 77

def ground_pins(options = {})
  options = options_with_current_package(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



120
121
122
123
124
# File 'lib/origen/pins/pin_bank.rb', line 120

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



84
85
86
87
88
89
# File 'lib/origen/pins/pin_bank.rb', line 84

def other_pins(options = {})
  options = options_with_current_package(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



99
100
101
102
103
# File 'lib/origen/pins/pin_bank.rb', line 99

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
68
# File 'lib/origen/pins/pin_bank.rb', line 63

def pins(options = {})
  options = options_with_current_package(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



106
107
108
109
110
# File 'lib/origen/pins/pin_bank.rb', line 106

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



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

def power_pins(options = {})
  options = options_with_current_package(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



225
226
227
228
# File 'lib/origen/pins/pin_bank.rb', line 225

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



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

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



91
92
93
94
95
96
# File 'lib/origen/pins/pin_bank.rb', line 91

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