Class: Origen::Location::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/origen/location/base.rb

Overview

A Location is an abstract object used to represent any NVM location of interest, such as a pass code, security field, etc.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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

Instance Attribute Details

#addressObject Also known as: byte_address, byte_aligned_byte_address

Returns the value of attribute address



6
7
8
# File 'lib/origen/location/base.rb', line 6

def address
  @address
end

#endianObject Also known as: endianess

Returns the value of attribute endian



6
7
8
# File 'lib/origen/location/base.rb', line 6

def endian
  @endian
end

#ownerObject

Returns the value of attribute owner



6
7
8
# File 'lib/origen/location/base.rb', line 6

def owner
  @owner
end

#size_in_bytesObject

Returns the value of attribute size_in_bytes



6
7
8
# File 'lib/origen/location/base.rb', line 6

def size_in_bytes
  @size_in_bytes
end

Instance Method Details

#aligned_address(bytes) ⇒ Object



29
30
31
32
# File 'lib/origen/location/base.rb', line 29

def aligned_address(bytes)
  f = bytes - 1
  (address >> f) << f
end

#big_endian?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/origen/location/base.rb', line 34

def big_endian?
  endian == :big
end

#data(options = {}) ⇒ Object Also known as: value, val



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# 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!Object



85
86
87
# File 'lib/origen/location/base.rb', line 85

def erase!
  action!(:erase, *args)
end

#little_endian?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/origen/location/base.rb', line 38

def little_endian?
  endian == :little
end

#program!Object



81
82
83
# File 'lib/origen/location/base.rb', line 81

def program!
  action!(:program, *args)
end

#read!(*args) ⇒ Object



69
70
71
# File 'lib/origen/location/base.rb', line 69

def read!(*args)
  action!(:read, *args)
end

#store!Object



77
78
79
# File 'lib/origen/location/base.rb', line 77

def store!
  action!(:store, *args)
end

#write(data, options = {}) ⇒ Object Also known as: set



42
43
44
45
46
# 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

#write!Object



73
74
75
# File 'lib/origen/location/base.rb', line 73

def write!
  action!(:write, *args)
end