Class: RPicSim::Storage::Register
- Inherits:
-
Object
- Object
- RPicSim::Storage::Register
- Defined in:
- lib/rpicsim/storage/register.rb
Instance Attribute Summary collapse
- #name ⇒ Object readonly
-
#size ⇒ Object
readonly
The size of the register in bytes.
Instance Method Summary collapse
-
#address ⇒ Integer
Gets the address of the register.
-
#addresses ⇒ Range
Gets the range of addresses occupied.
-
#initialize(mplab_register, memory, width) ⇒ Register
constructor
A new instance of Register.
- #inspect ⇒ Object
-
#memory_value ⇒ Object
Reads the value directly from the memory object backing the register.
-
#memory_value=(value) ⇒ Object
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.
- #to_s ⇒ Object
-
#value ⇒ Integer
Reads the value of the register.
-
#value=(val) ⇒ Object
Sets the value of the register.
Constructor Details
#initialize(mplab_register, memory, width) ⇒ Register
Returns a new instance of Register
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# 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 |
Instance Attribute Details
#name ⇒ Object (readonly)
3 4 5 |
# File 'lib/rpicsim/storage/register.rb', line 3 def name @name end |
#size ⇒ Object (readonly)
The size of the register in bytes.
6 7 8 |
# File 'lib/rpicsim/storage/register.rb', line 6 def size @size end |
Instance Method Details
#address ⇒ Integer
Gets the address of the register.
60 61 62 |
# File 'lib/rpicsim/storage/register.rb', line 60 def address @mplab_register.address end |
#addresses ⇒ Range
Gets the range of addresses occupied.
66 67 68 |
# File 'lib/rpicsim/storage/register.rb', line 66 def addresses address...(address + size) end |
#inspect ⇒ Object
74 75 76 |
# File 'lib/rpicsim/storage/register.rb', line 74 def inspect '<%s %s 0x%x>' % [self.class, name, address] end |
#memory_value ⇒ Object
Reads the value directly from the memory object backing the register.
54 55 56 |
# File 'lib/rpicsim/storage/register.rb', line 54 def memory_value @var.value end |
#memory_value=(value) ⇒ Object
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.
49 50 51 |
# File 'lib/rpicsim/storage/register.rb', line 49 def memory_value=(value) @var.value = value end |
#to_s ⇒ Object
70 71 72 |
# File 'lib/rpicsim/storage/register.rb', line 70 def to_s name.to_s end |
#value ⇒ Integer
Reads the value of the register.
40 41 42 |
# File 'lib/rpicsim/storage/register.rb', line 40 def value @mplab_register.read end |
#value=(val) ⇒ Object
Sets the value of the register.
34 35 36 |
# File 'lib/rpicsim/storage/register.rb', line 34 def value=(val) @mplab_register.write val end |