Sha256: 15c4262fcb0e5030c967cfc10416b92ad2243814d730c83a70380e86c663a0f4

Contents?: true

Size: 1.23 KB

Versions: 11

Compression:

Stored size: 1.23 KB

Contents

module Origen
  module Memory
    def memory(address, options = {})
      if is_top_level?
        r = "mem_#{address.to_s(16)}".to_sym
        unless has_reg?(r)
          if memory_address_aligned?(address)
            add_reg r, address, size: memory_width
          end
        end
        send(r)
      else
        Origen.top_level.memory(address + base_address, options)
      end
    end
    alias_method :mem, :memory

    def memory_address_aligned?(address)
      b = (memory_width / 8) - 1
      unless address & b == 0
        s = b - 1
        aligned = (address >> s) << s
        fail "Address #{address.to_hex} is not aligned to the memory width, it should be #{aligned.to_hex}"
      end
      true
    end

    def memory_width
      if is_top_level?
        @memory_width ||= 32
      else
        Origen.top_level.memory_width
      end
    end

    def memory_width=(size)
      if is_top_level?
        unless size % 8 == 0
          fail 'Memory width must be a multiple of 8'
        end
        if @memory_width
          fail 'The memory width cannot be changed after a memory location has been referenced'
        end

        @memory_width = size
      else
        Origen.top_level.memory_width = size
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
origen-0.60.19 lib/origen/memory.rb
origen-0.60.18 lib/origen/memory.rb
origen-0.60.17 lib/origen/memory.rb
origen-0.60.16 lib/origen/memory.rb
origen-0.60.14 lib/origen/memory.rb
origen-0.60.13 lib/origen/memory.rb
origen-0.60.12 lib/origen/memory.rb
origen-0.60.11 lib/origen/memory.rb
origen-0.60.10 lib/origen/memory.rb
origen-0.60.9 lib/origen/memory.rb
origen-0.60.8 lib/origen/memory.rb