class RPicSim::Storage::Register

Attributes

name[R]
size[R]

The size of the register in bytes.

Public Class Methods

new(mplab_register, memory, width) click to toggle source

@param mplab_register [Mplab::MplabRegister] @param memory An optional parameter that enables memory_value.

# File lib/rpicsim/storage/register.rb, line 10
def initialize(mplab_register, memory, width)
  @mplab_register = mplab_register
  @name = mplab_register.name.to_sym

  @size = case width
          when 8 then 1
          when 16 then 2
          when 24 then 3
          when 32 then 4
          else raise "Unsupported register width: #{name} is #{width}-bit."
          end

  var_type = case size
             when 1 then MemoryUInt8
             when 2 then MemoryUInt16
             when 3 then MemoryUInt24
             when 4 then MemoryUInt32
             end

  @var = var_type.new(name, address).bind(memory)
end

Public Instance Methods

address() click to toggle source

Gets the address of the register. @return [Integer]

# File lib/rpicsim/storage/register.rb, line 60
def address
  @mplab_register.address
end
addresses() click to toggle source

Gets the range of addresses occupied. @return [Range] A range of integers.

# File lib/rpicsim/storage/register.rb, line 66
def addresses
  address...(address + size)
end
inspect() click to toggle source
# File lib/rpicsim/storage/register.rb, line 74
def inspect
  '<%s %s 0x%x>' % [self.class, name, address]
end
memory_value() click to toggle source

Reads the value directly from the memory object backing the register.

# File lib/rpicsim/storage/register.rb, line 54
def memory_value
  @var.value
end
memory_value=(value) click to toggle source

For some registers, like STATUS, you cannot read and write the full range of possible values using {#value=} because some bits are not writable by the CPU. This setter gets around that by writing directly to the memory object that backs the register.

# File lib/rpicsim/storage/register.rb, line 49
def memory_value=(value)
  @var.value = value
end
to_s() click to toggle source
# File lib/rpicsim/storage/register.rb, line 70
def to_s
  name.to_s
end
value() click to toggle source

Reads the value of the register. @return [Integer]

# File lib/rpicsim/storage/register.rb, line 40
def value
  @mplab_register.read
end
value=(val) click to toggle source

Sets the value of the register. @param val [Integer]

# File lib/rpicsim/storage/register.rb, line 34
def value=(val)
  @mplab_register.write val
end