class Origen::Location::Base
A Location
is an abstract object used to represent any NVM location of interest, such as a pass code, security field, etc.
Attributes
address[RW]
byte_address[RW]
byte_aligned_byte_address[RW]
endian[RW]
endianess[RW]
owner[RW]
size_in_bytes[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/origen/location/base.rb, line 12 def initialize(options = {}) options = { size_in_bytes: 1, word_size_in_bytes: 2, endian: :big, data: 0, nil_state: 0 }.merge(options) @address = options.delete(:address) || options.delete(:byte_address) @endian = options.delete(:endian) @size_in_bytes = options.delete(:size_in_bytes) @nil_state = options.delete(:nil_state) @owner = options.delete(:owner) write(options.delete(:data), size_in_bytes: @size_in_bytes) create_address_methods(options) end
Public Instance Methods
aligned_address(bytes)
click to toggle source
# File lib/origen/location/base.rb, line 29 def aligned_address(bytes) f = bytes - 1 (address >> f) << f end
big_endian?()
click to toggle source
# File lib/origen/location/base.rb, line 34 def big_endian? endian == :big end
data(options = {})
click to toggle source
# File lib/origen/location/base.rb, line 49 def data(options = {}) data = @current_data nil_val = options[:nil_state] || @nil_state shift = 8 * (size_in_bytes - @current_data_size_in_bytes) mask = (1 << shift) - 1 if big_endian? data <<= shift if nil_val == 1 && shift != 0 data |= mask end else if nil_val == 1 data |= (mask << shift) end end data end
erase!()
click to toggle source
# File lib/origen/location/base.rb, line 85 def erase! action!(:erase, *args) end
little_endian?()
click to toggle source
# File lib/origen/location/base.rb, line 38 def little_endian? endian == :little end
program!()
click to toggle source
# File lib/origen/location/base.rb, line 81 def program! action!(:program, *args) end
read!(*args)
click to toggle source
# File lib/origen/location/base.rb, line 69 def read!(*args) action!(:read, *args) end
store!()
click to toggle source
# File lib/origen/location/base.rb, line 77 def store! action!(:store, *args) end
write(data, options = {})
click to toggle source
# File lib/origen/location/base.rb, line 42 def write(data, options = {}) @current_data = data @current_data_size_in_bytes = options[:size_in_bytes] || size_in_bytes self.data(options) end
Also aliased as: set
write!()
click to toggle source
# File lib/origen/location/base.rb, line 73 def write! action!(:write, *args) end
Private Instance Methods
action!(type, *args)
click to toggle source
# File lib/origen/location/base.rb, line 91 def action!(type, *args) if owner owner.send(type, self, *args) else fail "To #{type} a location an owner must be assigned to it!" end end
create_address_methods(options)
click to toggle source
# File lib/origen/location/base.rb, line 99 def create_address_methods(options) options.each do |key, value| if key.to_s =~ /(\w+)_size_in_bytes$/ define_singleton_method("#{Regexp.last_match[1].downcase}_aligned_address") do aligned_address(value) end define_singleton_method("#{Regexp.last_match[1].downcase}_aligned_byte_address") do aligned_address(value) end define_singleton_method("#{Regexp.last_match[1].downcase}_address") do address / value end end end end