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

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

#include <MemoryConfig.hxx>

Inheritance diagram for openlcb::ReadOnlyMemoryBlock:
openlcb::MemorySpace Destructable

Public Member Functions

 ReadOnlyMemoryBlock (const void *data)
 Creates a memory block for a given pointer of data.
 
 ReadOnlyMemoryBlock (const void *data, address_t len)
 Initializes a memory block with a given block of memory.
 
address_t max_address () OVERRIDE
 
size_t read (address_t source, uint8_t *dst, 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 bool read_only ()
 
virtual address_t min_address ()
 
virtual size_t write (address_t destination, const uint8_t *data, size_t len, errorcode_t *error, Notifiable *again)
 
virtual errorcode_t freeze ()
 Handles space freeze command.
 
virtual errorcode_t unfreeze ()
 Handles space unfreeze command.
 

Private Attributes

const 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-only memory space.

The data must be given as a const void* pointer, which can point both to RAM or flash (either rodata or specific flash addresses).

Definition at line 134 of file MemoryConfig.hxx.

Constructor & Destructor Documentation

◆ ReadOnlyMemoryBlock() [1/2]

openlcb::ReadOnlyMemoryBlock::ReadOnlyMemoryBlock ( const void *  data)
inline

Creates a memory block for a given pointer of data.

The pointer must stay alive so long as this object is alive.

Parameters
datais a null-terminated string, which may point into read-only memory.

Definition at line 140 of file MemoryConfig.hxx.

◆ ReadOnlyMemoryBlock() [2/2]

openlcb::ReadOnlyMemoryBlock::ReadOnlyMemoryBlock ( const 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 so long as this object is alive. It may point into read-only memory.

Definition at line 149 of file MemoryConfig.hxx.

Member Function Documentation

◆ max_address()

address_t openlcb::ReadOnlyMemoryBlock::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 155 of file MemoryConfig.hxx.

◆ read()

size_t openlcb::ReadOnlyMemoryBlock::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 160 of file MemoryConfig.hxx.

Member Data Documentation

◆ data_

const uint8_t* openlcb::ReadOnlyMemoryBlock::data_
private

Definition at line 177 of file MemoryConfig.hxx.

◆ len_

const address_t openlcb::ReadOnlyMemoryBlock::len_
private

Definition at line 178 of file MemoryConfig.hxx.


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