Sha256: 91de2bbc06501abdfab453204515c318da6b4c267f14f96cf2804a83bc5e50ee

Contents?: true

Size: 1.61 KB

Versions: 1

Compression:

Stored size: 1.61 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:     reg_or_val.address,
        hdata:     reg_or_val.data,
        hwrite:    0,
        hsize:     get_hsize(reg_or_val.size),
        hburst:    0,
        hmastlock: 0,
        hprot:     0xF
      }.merge(options)
      cc '==== AHB Read Transaction ===='
      cc 'Address: 0x' + options[:haddr].to_s(16) + ' Data: 0x' + options[:hdata].to_s(16) + ' Size: ' + options[:hsize].to_s
      $dut.ahb_trans(options)
    end

    def write_register(reg_or_val, options = {})
      options = {
        haddr:     reg_or_val.address,
        hdata:     reg_or_val.data,
        hwrite:    1,
        hsize:     get_hsize(reg_or_val.size),
        hburst:    0,
        hmastlock: 0,
        hprot:     0xF
      }.merge(options)
      cc '==== AHB Write Transaction ===='
      cc 'Address: 0x' + options[:haddr].to_s(16) + ' Data: 0x' + options[:hdata].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

1 entries across 1 versions & 1 rubygems

Version Path
origen_ahb-0.2.0.pre5 lib/origen_ahb/driver.rb