lib/origen/pins.rb in origen-0.6.5 vs lib/origen/pins.rb in origen-0.6.6

- old
+ new

@@ -174,10 +174,11 @@ autoload :PinBank, 'origen/pins/pin_bank' autoload :PinCommon, 'origen/pins/pin_common' autoload :PinClock, 'origen/pins/pin_clock' autoload :PowerPin, 'origen/pins/power_pin' autoload :GroundPin, 'origen/pins/ground_pin' + autoload :VirtualPin, 'origen/pins/virtual_pin' autoload :FunctionProxy, 'origen/pins/function_proxy' # @api private # API v2, deprecated def self.clear_pin_aliases @@ -211,10 +212,11 @@ # add_pin :fail, :name => "bist_fail" def add_pin(id = nil, options = {}, &_block) id, options = nil, id if id.is_a?(Hash) power_pin = options.delete(:power_pin) ground_pin = options.delete(:ground_pin) + virtual_pin = options.delete(:virtual_pin) if options[:size] && options[:size] > 1 group = PinCollection.new(self, options.merge(placeholder: true)) group.id = id if id options = { name: '' @@ -225,10 +227,12 @@ if power_pin group[i] = PowerPin.new(i, self, options) elsif ground_pin group[i] = GroundPin.new(i, self, options) + elsif virtual_pin + group[i] = VirtualPin.new(i, self, options) else group[i] = Pin.new(i, self, options) end group[i].invalidate_group_cache end @@ -245,10 +249,12 @@ else if power_pin pin = PowerPin.new(id || :temp, self, options) elsif ground_pin pin = GroundPin.new(id || :temp, self, options) + elsif virtual_pin + pin = VirtualPin.new(id || :temp, self, options) else pin = Pin.new(id || :temp, self, options) end yield pin if block_given? pin.finalize @@ -273,10 +279,19 @@ }.merge(options) add_pin(id, options, &block) end alias_method :add_ground_pins, :add_ground_pin + def add_virtual_pin(id = nil, options = {}, &block) + id, options = nil, id if id.is_a?(Hash) + options = { + virtual_pin: true + }.merge(options) + add_pin(id, options, &block) + end + alias_method :add_virtual_pins, :add_virtual_pin + # Specify the order that pins will appear in the output pattern, unspecified # pins will appear in an arbitrary order at the end # # API v2, deprecated def pin_pattern_order(*pin_ids) @@ -382,10 +397,16 @@ def has_ground_pin?(id) !!Origen.pin_bank.find(id, ground_pin: true) end alias_method :has_ground_pins?, :has_ground_pin? + # Equivalent to the has_pin? method but considers virtual pins rather than regular pins + def has_virtual_pin?(id) + !!Origen.pin_bank.find(id, virtual_pin: true) + end + alias_method :has_virtual_pins?, :has_virtual_pin? + def add_pin_group(id, *pins, &_block) if pins.last.is_a?(Hash) options = pins.pop else options = {} @@ -455,10 +476,22 @@ ground_pin: true }.merge(options) add_pin_group(id, *pins, options, &block) end + def add_virtual_pin_group(id, *pins, &block) + if pins.last.is_a?(Hash) + options = pins.pop + else + options = {} + end + options = { + virtual_pin: true + }.merge(options) + add_pin_group(id, *pins, options, &block) + end + # Similar to the pins method except that this method will bypass the package/mode/configuration # scope. # # Therefore with no id supplied it will return all known pins and with an id it will return the # given pin object regardless of where or not it is enabled by the current context @@ -486,10 +519,19 @@ else Origen.pin_bank.all_ground_pins end end + # Equivalent to the all_pins method but considers ground pins rather than regular pins + def all_virtual_pins(id = nil, _options = {}, &_block) + if id + pin = Origen.pin_bank.find(id, ignore_context: true, virtual_pin: true) + else + Origen.pin_bank.all_virtual_pins + end + end + def pin_groups(id = nil, options = {}, &_block) id, options = nil, id if id.is_a?(Hash) if id pin = Origen.pin_bank.find(id, options) unless pin @@ -551,10 +593,32 @@ Origen.pin_bank.ground_pin_groups(options) end end alias_method :ground_pin_group, :ground_pin_groups + # Equivalent to the pin_groups method but considers virtual pins rather than regular pins + def virtual_pin_groups(id = nil, options = {}, &_block) + id, options = nil, id if id.is_a?(Hash) + if id + pin = Origen.pin_bank.find(id, options.merge(virtual_pin: true)) + unless pin + puts <<-END +You have tried to reference virtual_pin_group :#{id} within #{self.class} but it does not exist, this could be +because the pin group has not been defined yet or it is an alias that is not available in the current context. + +If you meant to define the virtual_pin_group then use the add_virtual_pin_group method instead. + + END + fail 'Utility pin group not found' + end + pin + else + Origen.pin_bank.virtual_pin_groups(options) + end + end + alias_method :virtual_pin_group, :virtual_pin_groups + # Permits access via object.pin(x), returns a hash of all pins if no id # is specified. # ==== Examples # $top.pin(:done) # $soc.pin(:port_a1) @@ -577,10 +641,12 @@ else if options[:power_pin] Origen.pin_bank.power_pins elsif options[:ground_pin] Origen.pin_bank.ground_pins + elsif options[:virtual_pin] + Origen.pin_bank.virtual_pins else Origen.pin_bank.pins end end end @@ -598,9 +664,18 @@ # Equivalent to the pins method but considers ground pins rather than regular pins def ground_pins(id = nil, options = {}, &block) id, options = nil, id if id.is_a?(Hash) options = { ground_pin: true + }.merge(options) + pins(id, options, &block) + end + + # Equivalent to the pins method but considers virtual pins rather than regular pins + def virtual_pins(id = nil, options = {}, &block) + id, options = nil, id if id.is_a?(Hash) + options = { + virtual_pin: true }.merge(options) pins(id, options, &block) end def delete_all_pins