Sha256: cac0d93f14d2e1212a326a165b1d9f4fa2f0ce53b0d752c2817edfda281263ac

Contents?: true

Size: 1.9 KB

Versions: 6

Compression:

Stored size: 1.9 KB

Contents

module OrigenAhb
  class Driver
    attr_reader :owner

    def initialize(owner, options = {})
      @owner = owner
    end

    def read_register(reg_or_val, options = {})
      options = {
        haddr:     options[:address] || reg_or_val.address,
        hdata:     reg_or_val,
        hwrite:    0,
        hsize:     get_hsize(reg_or_val.size),
        hburst:    0,
        hmastlock: 0,
        hprot:     0xF
      }.merge(options)
      cc '==== AHB Read Transaction ===='
      if reg_or_val.respond_to?('data')
        data = reg_or_val.data
      else
        data = reg_or_val
        options[:hsize] = 2
      end
      cc 'Address: 0x' + options[:haddr].to_s(16) + ' Data: 0x' + data.to_s(16) + ' Size: ' + options[:hsize].to_s
      $dut.ahb_trans(options)
    end

    def write_register(reg_or_val, options = {})
      options = {
        haddr:     options[:address] || reg_or_val.address,
        hdata:     reg_or_val,
        hwrite:    1,
        hsize:     get_hsize(reg_or_val.size),
        hburst:    0,
        hmastlock: 0,
        hprot:     0xF
      }.merge(options)
      cc '==== AHB Write Transaction ===='
      if reg_or_val.respond_to?('data')
        data = reg_or_val.data
      else
        data = reg_or_val
        options[:hsize] = 2
      end
      cc 'Address: 0x' + options[:haddr].to_s(16) + ' Data: 0x' + data.to_s(16) + ' Size: ' + options[:hsize].to_s
      $dut.ahb_trans(options)
    end

    def get_hsize(size)
      if size <= 8
        hsize = 0
      elsif size > 8 and size <= 16
        hsize = 1
      elsif size > 16 and size <= 32
        hsize = 2
      elsif size > 32 and size <= 64
        hsize = 3
      elsif size > 64 and size <= 128
        hsize = 4
      elsif size > 128 and size <= 256
        hsize = 5
      elsif size > 256 and size <= 512
        hsize = 6
      elsif size > 512 and size <= 1024
        hsize = 7
      end
      get_hsize = hsize
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
origen_ahb-0.2.1 lib/origen_ahb/driver.rb
origen_ahb-0.2.0 lib/origen_ahb/driver.rb
origen_ahb-0.2.0.pre10 lib/origen_ahb/driver.rb
origen_ahb-0.2.0.pre9 lib/origen_ahb/driver.rb
origen_ahb-0.2.0.pre8 lib/origen_ahb/driver.rb
origen_ahb-0.2.0.pre6 lib/origen_ahb/driver.rb