Module: Origen::Memory
- Defined in:
- lib/origen/memory.rb
Instance Method Summary collapse
- #memory(address, options = {}) ⇒ Object (also: #mem)
- #memory_address_aligned?(address) ⇒ Boolean
- #memory_width ⇒ Object
- #memory_width=(size) ⇒ Object
Instance Method Details
#memory(address, options = {}) ⇒ Object Also known as: mem
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/origen/memory.rb', line 3 def memory(address, = {}) 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, ) end end |
#memory_address_aligned?(address) ⇒ Boolean
18 19 20 21 22 23 24 25 26 |
# File 'lib/origen/memory.rb', line 18 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 |
#memory_width ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/origen/memory.rb', line 28 def memory_width if is_top_level? @memory_width ||= 32 else Origen.top_level.memory_width end end |
#memory_width=(size) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/origen/memory.rb', line 36 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 |