Class: Origen::Pins::PinBank
- 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
-
#add_pin(pin, _owner, _options = {}) ⇒ Origen::Pins::Pin
Add the given pin to the bank.
- #add_pin_group(group, owner, options = {}) ⇒ Object
-
#all_ground_pin_groups ⇒ Object
Returns a hash containing all ground pin groups stored by context.
-
#all_ground_pins ⇒ Object
Returns a hash containing all ground pins stored by their primary ID.
-
#all_other_pin_groups ⇒ Object
Returns a hash containing all other pin groups stored by context.
-
#all_other_pins ⇒ Object
Returns a hash containing all other pins stored by their primary ID.
-
#all_pin_groups ⇒ Object
Returns a hash containing all pin groups stored by context.
-
#all_pins ⇒ Object
Returns a hash containing all pins stored by their primary ID.
-
#all_power_pin_groups ⇒ Object
Returns a hash containing all power pin groups stored by context.
-
#all_power_pins ⇒ Object
Returns a hash containing all power pins stored by their primary ID.
-
#all_virtual_pin_groups ⇒ Object
Returns a hash containing all virtual pin groups stored by context.
-
#all_virtual_pins ⇒ Object
Returns a hash containing all virtual pins stored by their primary ID.
-
#before_load_target ⇒ Object
private
There is one pin bank per Origen thread, this clears the bank every time the target is changed.
-
#delete_pin(pin) ⇒ Object
Delete a specific pin.
-
#delete_pingroup(group) ⇒ Object
Delete a specific pin group.
- #find(id, options = {}) ⇒ Object
-
#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.
- #find_pin_group(id, options = {}) ⇒ Object
-
#ground_pin_groups(options = {}) ⇒ Object
Returns a hash containing all ground_pin_groups available in the current context stored by their primary ID.
- #ground_pins(options = {}) ⇒ Object
-
#other_pin_groups(options = {}) ⇒ Object
Returns a hash containing all ground_pin_groups available in the current context stored by their primary ID.
- #other_pins(options = {}) ⇒ Object
-
#pin_groups(options = {}) ⇒ Object
Returns a hash containing all pin_groups available in the current context stored by their primary ID.
-
#pins(options = {}) ⇒ Object
Returns a hash containing all pins available in the current context stored by their primary ID.
-
#power_pin_groups(options = {}) ⇒ Object
Returns a hash containing all power_pin_groups available in the current context stored by their primary ID.
- #power_pins(options = {}) ⇒ Object
-
#register_alias(id, pin, _options = {}) ⇒ Object
This will be called by the pins whenever a new alias is added to them.
-
#virtual_pin_groups(options = {}) ⇒ Object
Returns a hash containing all virtual_pin_groups available in the current context stored by their primary ID.
- #virtual_pins(options = {}) ⇒ Object
Methods included from Origen::PersistentCallbacks
Instance Method Details
#add_pin(pin, _owner, _options = {}) ⇒ Origen::Pins::Pin
Add the given pin to the bank
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 |
# File 'lib/origen/pins/pin_bank.rb', line 21 def add_pin(pin, _owner, = {}) 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
51 52 53 54 55 56 57 58 59 |
# File 'lib/origen/pins/pin_bank.rb', line 51 def add_pin_group(group, owner, = {}) unless [:pins_exist] group.each do |pin| add_pin(pin, owner, .merge(dont_create_group: true)) end end store_pin_group(group, ) group end |
#all_ground_pin_groups ⇒ Object
Returns a hash containing all ground pin groups stored by context
163 164 165 |
# File 'lib/origen/pins/pin_bank.rb', line 163 def all_ground_pin_groups @all_ground_pin_groups ||= {} end |
#all_ground_pins ⇒ Object
Returns a hash containing all ground pins stored by their primary ID
143 144 145 |
# File 'lib/origen/pins/pin_bank.rb', line 143 def all_ground_pins @all_ground_pins ||= {} end |
#all_other_pin_groups ⇒ Object
Returns a hash containing all other pin groups stored by context
168 169 170 |
# File 'lib/origen/pins/pin_bank.rb', line 168 def all_other_pin_groups @all_other_pin_groups ||= {} end |
#all_other_pins ⇒ Object
Returns a hash containing all other pins stored by their primary ID
148 149 150 |
# File 'lib/origen/pins/pin_bank.rb', line 148 def all_other_pins @all_other_pins ||= {} end |
#all_pin_groups ⇒ Object
Returns a hash containing all pin groups stored by context
133 134 135 |
# File 'lib/origen/pins/pin_bank.rb', line 133 def all_pin_groups @all_pin_groups ||= {} end |
#all_pins ⇒ Object
Returns a hash containing all pins stored by their primary ID
128 129 130 |
# File 'lib/origen/pins/pin_bank.rb', line 128 def all_pins @all_pins ||= {} end |
#all_power_pin_groups ⇒ Object
Returns a hash containing all power pin groups stored by context
158 159 160 |
# File 'lib/origen/pins/pin_bank.rb', line 158 def all_power_pin_groups @all_power_pin_groups ||= {} end |
#all_power_pins ⇒ Object
Returns a hash containing all power pins stored by their primary ID
138 139 140 |
# File 'lib/origen/pins/pin_bank.rb', line 138 def all_power_pins @all_power_pins ||= {} end |
#all_virtual_pin_groups ⇒ Object
Returns a hash containing all virtual pin groups stored by context
173 174 175 |
# File 'lib/origen/pins/pin_bank.rb', line 173 def all_virtual_pin_groups @all_virtual_pin_groups ||= {} end |
#all_virtual_pins ⇒ Object
Returns a hash containing all virtual pins stored by their primary ID
153 154 155 |
# File 'lib/origen/pins/pin_bank.rb', line 153 def all_virtual_pins @all_virtual_pins ||= {} end |
#before_load_target ⇒ 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.
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
236 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 |
# File 'lib/origen/pins/pin_bank.rb', line 236 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
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/origen/pins/pin_bank.rb', line 268 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
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/origen/pins/pin_bank.rb', line 177 def find(id, = {}) id = id.to_sym if [:power_pin] pin = all_power_pins[id] || find_pin_group(id, ) elsif [:ground_pin] pin = all_ground_pins[id] || find_pin_group(id, ) elsif [:virtual_pin] pin = all_virtual_pins[id] || find_pin_group(id, ) elsif [:other_pin] pin = all_other_pins[id] || find_pin_group(id, ) else pin = all_pins[id] || find_by_alias(id, ) || find_pin_group(id, ) end if pin if [:ignore_context] || pin.enabled?() 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
225 226 227 228 229 230 231 232 233 |
# File 'lib/origen/pins/pin_bank.rb', line 225 def find_or_create_pin_group(id, owner, = {}) group = find_pin_group(id, ) unless group group = PinCollection.new(owner, ) group.id = id store_pin_group(group, ) end group end |
#find_pin_group(id, options = {}) ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/origen/pins/pin_bank.rb', line 197 def find_pin_group(id, = {}) = { include_all: true }.merge() if [:power_pin] base = all_power_pin_groups elsif [:ground_pin] base = all_ground_pin_groups elsif [:other_pin] base = all_other_pin_groups elsif [:virtual_pin] base = all_virtual_pin_groups else base = all_pin_groups end pin_group_stores_in_context(base, ) 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
107 108 109 110 111 |
# File 'lib/origen/pins/pin_bank.rb', line 107 def ground_pin_groups( = {}) current_pin_group_store(all_ground_pin_groups, ).select do |_id, group| group.enabled?() end end |
#ground_pins(options = {}) ⇒ Object
74 75 76 77 78 |
# File 'lib/origen/pins/pin_bank.rb', line 74 def ground_pins( = {}) all_ground_pins.select do |_id, pin| pin.enabled?() 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
114 115 116 117 118 |
# File 'lib/origen/pins/pin_bank.rb', line 114 def other_pin_groups( = {}) current_pin_group_store(all_other_pin_groups, ).select do |_id, group| group.enabled?() end end |
#other_pins(options = {}) ⇒ Object
80 81 82 83 84 |
# File 'lib/origen/pins/pin_bank.rb', line 80 def other_pins( = {}) all_other_pins.select do |_id, pin| pin.enabled?() end end |
#pin_groups(options = {}) ⇒ Object
Returns a hash containing all pin_groups available in the current context stored by their primary ID
93 94 95 96 97 |
# File 'lib/origen/pins/pin_bank.rb', line 93 def pin_groups( = {}) current_pin_group_store(all_pin_groups, ).select do |_id, group| group.enabled?() end end |
#pins(options = {}) ⇒ Object
Returns a hash containing all pins available in the current context stored by their primary ID
62 63 64 65 66 |
# File 'lib/origen/pins/pin_bank.rb', line 62 def pins( = {}) all_pins.select do |_id, pin| pin.enabled?() 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
100 101 102 103 104 |
# File 'lib/origen/pins/pin_bank.rb', line 100 def power_pin_groups( = {}) current_pin_group_store(all_power_pin_groups, ).select do |_id, group| group.enabled?() end end |
#power_pins(options = {}) ⇒ Object
68 69 70 71 72 |
# File 'lib/origen/pins/pin_bank.rb', line 68 def power_pins( = {}) all_power_pins.select do |_id, pin| pin.enabled?() end end |
#register_alias(id, pin, _options = {}) ⇒ Object
This will be called by the pins whenever a new alias is added to them
219 220 221 222 |
# File 'lib/origen/pins/pin_bank.rb', line 219 def register_alias(id, pin, = {}) 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
121 122 123 124 125 |
# File 'lib/origen/pins/pin_bank.rb', line 121 def virtual_pin_groups( = {}) current_pin_group_store(all_virtual_pin_groups, ).select do |_id, group| group.enabled?() end end |
#virtual_pins(options = {}) ⇒ Object
86 87 88 89 90 |
# File 'lib/origen/pins/pin_bank.rb', line 86 def virtual_pins( = {}) all_virtual_pins.select do |_id, pin| pin.enabled?() end end |