Class: OrigenAhb::Driver

Inherits:
Object
  • Object
show all
Defined in:
lib/origen_ahb/driver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, options = {}) ⇒ Driver

Returns a new instance of Driver.


5
6
7
# File 'lib/origen_ahb/driver.rb', line 5

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

Instance Attribute Details

#ownerObject (readonly)

Returns the value of attribute owner.


3
4
5
# File 'lib/origen_ahb/driver.rb', line 3

def owner
  @owner
end

Instance Method Details

#get_hsize(size) ⇒ Object


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/origen_ahb/driver.rb', line 51

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

#read_register(reg_or_val, options = {}) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/origen_ahb/driver.rb', line 9

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

#write_register(reg_or_val, options = {}) ⇒ Object


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/origen_ahb/driver.rb', line 30

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