Module: Origen::SubBlocks::RegBaseAddress

Included in:
Origen::SubBlocks
Defined in:
lib/origen/sub_blocks.rb

Instance Method Summary collapse

Instance Method Details

#base_addressObject



154
155
156
# File 'lib/origen/sub_blocks.rb', line 154

def base_address
  reg_base_address
end

#reg_base_address(options = {}) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
# File 'lib/origen/sub_blocks.rb', line 109

def reg_base_address(options = {})
  if options[:relative]
    reg_base_address_for_domain(options)
  else
    total_reg_base_address = reg_base_address_for_domain(options)
    if parent
      total_reg_base_address += parent.reg_base_address(options)
    end
    total_reg_base_address
  end
end

#reg_base_address_for_domain(options) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/origen/sub_blocks.rb', line 121

def reg_base_address_for_domain(options)
  if @reg_base_address
    if @reg_base_address.is_a?(Hash)
      if options[:domain]
        if options[:domain].is_a?(Hash)
          domains = options[:domain].keys
        else
          domains = [options[:domain]].flatten
        end
        bases = domains.map do |d|
          @reg_base_address.with_indifferent_access[d]
        end.compact
        if bases.empty?
          @reg_base_address[:default] || 0
        else
          if bases.size > 1
            fail 'Multiple base addresses found, specify the domain you want, e.g. reg.address(domain: :ahb)'
          else
            bases.first
          end
        end
      else
        @reg_base_address[:default] || 0
      end
    else
      @reg_base_address
    end
  else
    0
  end
end