lib/origen/registers/reg.rb
# Returns the bit object(s) responding to the given name, wrapped in a BitCollection.
# This method also accepts multiple name possibilities, if neither bit exists in
# the register it will raise an error, otherwise it will return the first match.
# If no args passed in, it will return a BitCollection containing all bits.
# If a number is passed in then the bits from those positions are returned.
# ==== Example
#   add_reg :control, 0x55, :status => {:pos => 1, :bits => 2},
#                           :fail   => {:pos => 0}
#
#   reg(:control).bit(:fail)              # => Returns a BitCollection containing the fail bit
#   reg(:control).bits(:status)           # => Returns a BifCollection containing the status bits
#   reg(:control).bit(:bist_fail, :fail)  # => Returns a BitCollection containing the fail bit
#   reg(:control).bit(0)                  # => Returns a BitCollection containing the fail bit
#   reg(:control).bit(1)                  # => Returns a BitCollection containing status bit
#   reg(:control).bit(1,2)                # => Returns a BitCollection containing both status bits
Returns the bit object(s) responding to the given name, wrapped in a BitCollection.
This method also accepts multiple name possibilities, if neither bit exists in
the register it will raise an error, otherwise it will return the first match.
If no args passed in, it will return a BitCollection containing all bits.
If a number is passed in then the bits from those positions are returned.


Returns the bit object ( s ) responding to the given name wrapped in a BitCollection . This method also accepts multiple name possibilities if neither bit exists in the register it will raise an error otherwise it will return the first match . If no args passed in it will return a BitCollection containing all bits . If a number is passed in then the bits from those positions are returned .
def bit(*args)
        wbo = :lsb0
        if args.last.is_a?(Hash)
          wbo = args.last.delete(:with_bit_order) || :lsb0
          args.pop if args.last.size == 0
        end
        multi_bit_names = false
        constraint = extract_feature_params(args)
        if constraint.nil?
          constraint = :default
        end
        collection = BitCollection.new(self, :unknown, [], with_bit_order: wbo)
        if args.size == 0
          collection.add_name(name)
          @bits.each do |bit|
            collection << get_bits_with_constraint(bit.position, constraint)
          end
        else
          args.flatten!
          args.sort!
          args.reverse! if wbo == :msb0
          args.each do |arg_item|
            if arg_item.is_a?(Integer)
              b = get_bits_with_constraint(arg_item, constraint, with_bit_order: wbo)
              collection << b if b
            elsif arg_item.is_a?(Range)
              expand_range(arg_item, wbo) do |bit_number|
                collection << get_bits_with_constraint(bit_number, constraint, with_bit_order: wbo)
              end
            else
              multi_bit_names = args.size > 1
              if @lookup.include?(arg_item)
                split_bits = false
                @lookup.each { |_k, v| split_bits = true if v.is_a? Array }
                coll = get_lookup_feature_bits(arg_item, constraint, split_bits)
                if coll
                  coll.each do |b|
                    collection.add_name(arg_item)
                    collection << b
                  end
                end
              end
            end
          end
        end
        if collection.size == 0
          if Origen.config.strict_errors && !args.all? { |arg| arg.is_a?(Numeric) }
            puts "Register #{@name} does not have a bits(s) named :#{args.join(', :')} or it might not be enabled."
            puts 'This could also be a typo, these are the valid bit names:'
            puts @lookup.keys
            fail 'Missing bits error!'
          end
          nil
        else
          if multi_bit_names
            collection.sort_by!(&:position)
            wbo == :msb0 ? collection.with_msb0 : collection.with_lsb0
          end
          wbo == :msb0 ? collection.with_msb0 : collection.with_lsb0
        end
      end
def bit ( * args ) wbo = :lsb0 if args . last . is_a? ( Hash ) wbo = args . last . delete ( :with_bit_order ) || :lsb0 args . pop if args . last . size == 0 end multi_bit_names = false constraint = extract_feature_params ( args ) if constraint . nil? constraint = :default end collection = BitCollection . new ( self , :unknown , [ ] , with_bit_order : wbo ) if args . size == 0 collection . add_name ( name ) @bits . each do | bit | collection << get_bits_with_constraint ( bit . position , constraint ) end else args . flatten! args . sort! args . reverse! if wbo == :msb0 args . each do | arg_item | if arg_item . is_a? ( Integer ) b = get_bits_with_constraint ( arg_item , constraint , with_bit_order : wbo ) collection << b if b elsif arg_item . is_a? ( Range ) expand_range ( arg_item , wbo ) do | bit_number | collection << get_bits_with_constraint ( bit_number , constraint , with_bit_order : wbo ) end else multi_bit_names = args . size > 1 if @lookup . include? ( arg_item ) split_bits = false @lookup . each { | _k , v | split_bits = true if v . is_a? Array } coll = get_lookup_feature_bits ( arg_item , constraint , split_bits ) if coll coll . each do | b | collection . add_name ( arg_item ) collection << b end end end end end end if collection . size == 0 if Origen . config . strict_errors && ! args . all? { | arg | arg . is_a? ( Numeric ) } puts "Register #{@name} does not have a bits(s) named :#{args.join(', :')} or it might not be enabled." puts 'This could also be a typo, these are the valid bit names:' puts @lookup . keys fail 'Missing bits error!' end nil else if multi_bit_names collection . sort_by! ( & :position ) wbo == :msb0 ? collection . with_msb0 : collection . with_lsb0 end wbo == :msb0 ? collection . with_msb0 : collection . with_lsb0 end end
Returns the bit object(s) responding to the given name, wrapped in a BitCollection.
Returns the bit object ( s ) responding to the given name wrapped in a BitCollection .
# allow msb0 bit numbering if requested # return get_bits_with_constraint(nil,:default) if args.size == 0 # Reaches here if bit name is specified # Originally Origen returned nil when asking for a bit via an index which does not # exist, e.g. reg[1000] => nil # The args numeric clause here is to maintain that behavior
args
<not_specific>