Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
openlcb::ReadWriteMemoryBlock Class Reference

Memory space implementation that exports a some memory-mapped data as a read-write memory space. More...

#include <MemoryConfig.hxx>

Inheritance diagram for openlcb::ReadWriteMemoryBlock:
openlcb::MemorySpace Destructable

Public Member Functions

 ReadWriteMemoryBlock (void *data, address_t len)
 Initializes a memory block with a given block of memory.
 
bool read_only () OVERRIDE
 
address_t max_address () OVERRIDE
 
size_t read (address_t source, uint8_t *dst, size_t len, errorcode_t *error, Notifiable *again) OVERRIDE
 
size_t write (address_t destination, const uint8_t *data, size_t len, errorcode_t *error, Notifiable *again) OVERRIDE
 
- Public Member Functions inherited from openlcb::MemorySpace
virtual bool set_node (Node *node)
 Specifies which node the next operation pertains.
 
virtual address_t min_address ()
 
virtual errorcode_t freeze ()
 Handles space freeze command.
 
virtual errorcode_t unfreeze ()
 Handles space unfreeze command.
 

Private Attributes

uint8_t * data_
 
const address_t len_
 

Additional Inherited Members

- Public Types inherited from openlcb::MemorySpace
typedef uint32_t address_t
 
typedef uint16_t errorcode_t
 
- Static Public Attributes inherited from openlcb::MemorySpace
static const errorcode_t ERROR_AGAIN = 0x3FFF
 This error code signals that the operation was only partially completed, the again notify was used and will be notified when the operation can be re-tried).
 

Detailed Description

Memory space implementation that exports a some memory-mapped data as a read-write memory space.

The data must be given as a void* pointer pointing to RAM (or other memory-mapped structures).

Definition at line 184 of file MemoryConfig.hxx.

Constructor & Destructor Documentation

◆ ReadWriteMemoryBlock()

openlcb::ReadWriteMemoryBlock::ReadWriteMemoryBlock ( void *  data,
address_t  len 
)
inline

Initializes a memory block with a given block of memory.

The address range [data, data+len) must be dereferenceable for read and write so long as this object is alive.

Definition at line 190 of file MemoryConfig.hxx.

Member Function Documentation

◆ max_address()

address_t openlcb::ReadWriteMemoryBlock::max_address ( )
inlinevirtual
Returns
the largest valid address for this block. A read of 1 from this address should succeed in returning the last byte.

Implements openlcb::MemorySpace.

Definition at line 202 of file MemoryConfig.hxx.

◆ read()

size_t openlcb::ReadWriteMemoryBlock::read ( address_t  source,
uint8_t *  dst,
size_t  len,
errorcode_t *  error,
Notifiable again 
)
inlinevirtual
Returns
the number of bytes successfully read (before hitting end of space). If *error is set to non-null, then the operation has failed. If the operation needs to be continued, then sets error to ERROR_AGAIN, and calls the Notifiable
Parameters
againwhen a re-try makes sense. The caller should call read once more, with the offset adjusted with the previously returned bytes.

Implements openlcb::MemorySpace.

Definition at line 207 of file MemoryConfig.hxx.

◆ read_only()

bool openlcb::ReadWriteMemoryBlock::read_only ( )
inlinevirtual
Returns
whether the memory space does not accept writes.

Reimplemented from openlcb::MemorySpace.

Definition at line 197 of file MemoryConfig.hxx.

◆ write()

size_t openlcb::ReadWriteMemoryBlock::write ( address_t  destination,
const uint8_t *  data,
size_t  len,
errorcode_t *  error,
Notifiable again 
)
inlinevirtual
Returns
the number of bytes successfully written (before hitting end of space). If *error is set to non-null, then the operation has failed. If the operation needs to be continued, then sets error to MemorySpace::ERROR_AGAIN, and calls the Notifiable
Parameters
againwhen a re-try makes sense. The caller should call write once more, with the offset adjusted with the previously returned bytes.

Reimplemented from openlcb::MemorySpace.

Definition at line 223 of file MemoryConfig.hxx.

Member Data Documentation

◆ data_

uint8_t* openlcb::ReadWriteMemoryBlock::data_
private

Definition at line 237 of file MemoryConfig.hxx.

◆ len_

const address_t openlcb::ReadWriteMemoryBlock::len_
private

Definition at line 238 of file MemoryConfig.hxx.


The documentation for this class was generated from the following file: