Module: Origen::Utility
- Included in:
- Application::Release
- Defined in:
- lib/origen/utility.rb,
lib/origen/utility/diff.rb,
lib/origen/utility/mailer.rb,
lib/origen/utility/csv_data.rb,
lib/origen/utility/collector.rb,
lib/origen/utility/file_diff.rb,
lib/origen/utility/block_args.rb,
lib/origen/utility/input_capture.rb,
lib/origen/utility/time_and_date.rb
Defined Under Namespace
Modules: FileDiff, InputCapture, TimeAndDate Classes: BlockArgs, CSV, Collector, Diff, Mailer
Class Method Summary collapse
- .collector(options = {}, &block) ⇒ Object
-
.read_hex(reg_or_val) ⇒ Object
Creates a hex-like representation of a register read value, where bits within a nibble have different flags set the nibble will be expanded to bits.
Instance Method Summary collapse
Class Method Details
.collector(options = {}, &block) ⇒ Object
100 101 102 |
# File 'lib/origen/utility.rb', line 100 def self.collector( = {}, &block) Origen::Utility::Collector.new(, &block) end |
.read_hex(reg_or_val) ⇒ Object
Creates a hex-like representation of a register read value, where bits within a nibble have different flags set the nibble will be expanded to bits
read_hex(0x55) # => "0x55"
read_hex(nil) # => "0xX"
myreg.size # => 32
read_hex(myreg) # => "0xXXXXXXXX"
myreg[7..4].store
read_hex(myreg) # => "0xXXXXXXSX"
myreg[23..16].read
read_hex(myreg) # => "0xXX00XXSX"
myreg[23..16].read(0x12)
read_hex(myreg) # => "0xXX12XXSX"
reg[31..28].("sub")
reg[31..28].read
read_hex(myreg) # => "0xVX12XXSX"
reg[5].clear_flags
read_hex(myreg) # => "0xVX12XX_ssxs_X"
reg[21].("sub")
reg[18].store
read_hex(myreg) # => "0xVX_00v1_0s10_XX_ssxs_X"
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/origen/utility.rb', line 35 def self.read_hex(reg_or_val) if reg_or_val.respond_to?(:data) # Make a binary string of the data, like 010S0011SSSS0110 # (where S, X or V represent store, dont care or overlay) regval = '' reg_or_val.shift_out_left do |bit| if bit.is_to_be_stored? regval += 'S' elsif bit.is_to_be_read? if bit. regval += 'V' else regval += bit.data.to_s end else regval += 'X' end end # Now group by nibbles to give a hex-like representation, and where nibbles # that are not all of the same type are expanded, e.g. -010s-3S6 outstr = '' regex = '^' r = reg_or_val.size % 4 unless r == 0 regex += '(' + ('.' * r) + ')' end (reg_or_val.size / 4).times { regex += '(....)' } regex += '$' Regexp.new(regex) =~ regval nibbles = [] (reg_or_val.size / 4).times do |n| # now grouped by nibble nibbles << Regexp.last_match[n + 1] end unless r == 0 nibbles << Regexp.last_match[(reg_or_val.size / 4) + 1] end nibbles.each_with_index do |nibble, i| # If contains any special chars... if nibble =~ /[XSV]/ # If all the same... if nibble.split('').all? { |c| c == nibble[0] } outstr += nibble[0, 1] # .to_s # Otherwise present this nibble in 'binary' format else outstr += (i == 0 ? '' : '_') + nibble.downcase + (i == nibbles.size - 1 ? '' : '_') end # Otherwise if all 1s and 0s... else outstr += '%1X' % nibble.to_i(2) end end "0x#{outstr.gsub('__', '_')}" else if reg_or_val reg_or_val.to_hex else '0xX' end end end |
Instance Method Details
#which(cmd) ⇒ Object
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/origen/utility.rb', line 105 def which(cmd) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each do |ext| exe = File.join(path, "#{cmd}#{ext}") return exe if File.executable?(exe) && !File.directory?(exe) end end nil end |