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_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.
-
#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
-
#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.
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 |
# 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 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
47 48 49 50 51 52 53 54 55 |
# File 'lib/origen/pins/pin_bank.rb', line 47 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
123 124 125 |
# File 'lib/origen/pins/pin_bank.rb', line 123 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
113 114 115 |
# File 'lib/origen/pins/pin_bank.rb', line 113 def all_ground_pins @all_ground_pins ||= {} end |
#all_pin_groups ⇒ Object
Returns a hash containing all pin groups stored by context
103 104 105 |
# File 'lib/origen/pins/pin_bank.rb', line 103 def all_pin_groups @all_pin_groups ||= {} end |
#all_pins ⇒ Object
Returns a hash containing all pins stored by their primary ID
98 99 100 |
# File 'lib/origen/pins/pin_bank.rb', line 98 def all_pins @all_pins ||= {} end |
#all_power_pin_groups ⇒ Object
Returns a hash containing all power pin groups stored by context
118 119 120 |
# File 'lib/origen/pins/pin_bank.rb', line 118 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
108 109 110 |
# File 'lib/origen/pins/pin_bank.rb', line 108 def all_power_pins @all_power_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
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/origen/pins/pin_bank.rb', line 178 def delete_pin(pin) if pin.is_a?(PowerPin) bank = all_power_pins elsif pin.is_a?(GroundPin) bank = all_ground_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
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 206 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 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
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/origen/pins/pin_bank.rb', line 127 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, ) 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
167 168 169 170 171 172 173 174 175 |
# File 'lib/origen/pins/pin_bank.rb', line 167 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
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/origen/pins/pin_bank.rb', line 143 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 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
91 92 93 94 95 |
# File 'lib/origen/pins/pin_bank.rb', line 91 def ground_pin_groups( = {}) current_pin_group_store(all_ground_pin_groups, ).select do |_id, group| group.enabled?() end end |
#ground_pins(options = {}) ⇒ Object
70 71 72 73 74 |
# File 'lib/origen/pins/pin_bank.rb', line 70 def ground_pins( = {}) all_ground_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
77 78 79 80 81 |
# File 'lib/origen/pins/pin_bank.rb', line 77 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
58 59 60 61 62 |
# File 'lib/origen/pins/pin_bank.rb', line 58 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
84 85 86 87 88 |
# File 'lib/origen/pins/pin_bank.rb', line 84 def power_pin_groups( = {}) current_pin_group_store(all_power_pin_groups, ).select do |_id, group| group.enabled?() end end |
#power_pins(options = {}) ⇒ Object
64 65 66 67 68 |
# File 'lib/origen/pins/pin_bank.rb', line 64 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
161 162 163 164 |
# File 'lib/origen/pins/pin_bank.rb', line 161 def register_alias(id, pin, = {}) known_aliases[id] ||= [] known_aliases[id] << pin end |