Memory Control

The memory control component is responsible for managing the memory of the system. This includes access to device files such as /dev/mem as well as user space interrupts.

Classes

MemoryMap Class

class MemoryMap

Represents a memory map for accessing memory regions.

The MemoryMap class provides methods for reading and writing to memory regions specified by a base address and size. It also supports register operations such as reading and writing specific bits within a register.

Public Functions

MemoryMap(int mem, uint32_t mapBase, uint32_t mapSize)

Constructs a MemoryMap object.

Parameters:
  • mem – The memory identifier.

  • mapBase – The base address of the memory map.

  • mapSize – The size of the memory map.

MemoryMap(const char *filename, uint32_t mapSize, int flag = O_RDWR)

Constructs a MemoryMap object.

Parameters:
  • filename – The name of the file to be mapped.

  • mapSize – The size of the memory map.

  • flag – The flag to be used for the file.

~MemoryMap()

Destroys the MemoryMap object.

MemoryMap() = delete
MemoryMap(const MemoryMap&) = delete
MemoryMap &operator=(const MemoryMap&) = delete
MemoryMap(MemoryMap &&other) = delete
MemoryMap &operator=(MemoryMap &&other) = delete
uint64_t *get() const

Gets the pointer to the memory map.

This method reinterprets the pointer to the memory map as a pointer to a 64 bit integer.

Returns:

A pointer to the memory map.

bool hasError() const

Checks if an error occurred during memory map initialization.

Returns:

True if an error occurred, false otherwise.

uint32_t memoryRead(Offset offset)

Reads a value from memory at the specified offset.

Parameters:

offset – The offset within the memory map.

Returns:

The value read from memory.

void memoryWrite(Offset offset, uint32_t value)

Writes a value to memory at the specified offset.

Parameters:
  • offset – The offset within the memory map.

  • value – The value to write to memory.

bool memoryReadBit(Offset offset, Bit bit)

Reads a bit from a register memory at the specified position.

Parameters:
  • offset – The offset within the memory map.

  • bit – The bit to read.

Returns:

The value of the bit.

void memoryWriteBit(Offset offset, Bit bit, bool value)

Writes a bit into a register memory at the specified position.

Parameters:
  • offset – The offset within the memory map.

  • bit – The bit to write.

  • value – The value of the bit.

Returns:

The value of the bit.

Private Members

const int mMem

The memory identifier.

const bool mHandleFile

Flag indicating if the file should be closed.

const uint32_t mMapSize

The size of the memory map.

uint32_t *mMap

Pointer to the memory map.

bool mHasError = false

Flag indicating if an error occurred during initialization.

Uio Class

class Uio

Opens a uio device to react to interrupts.

The Uio class open a uio file and blocks. The block is released when an interrupt occurs.

Public Functions

Uio(const char *filename)

Constructs a Uio object.

Parameters:

filename – The name of the file to be mapped.

~Uio()

Destroys the Uio object.

Uio() = delete
Uio(const Uio&) = delete
Uio &operator=(const Uio&) = delete
Uio(Uio &&other) = delete
Uio &operator=(Uio &&other) = delete
void init(const char *filename)

Initializes the interrupt by getting a possible pending interrupt.

Parameters:

filename – The name of the file to be mapped.

void enableInterrupt() const

Enables interrupts.

The interrupt must be enabled after each interrupt.

bool waitInterrupt(std::atomic<bool> *exitSignal, std::chrono::time_point<std::chrono::steady_clock> stopTime) const

Waits for an interrupt.

Parameters:
  • exitSignal – A pointer to an atomic boolean indicating if the thread should exit.

  • stopTime – The time point at which the thread waits for the finished interrupt. It is used to stop waiting after a 1s timeout beginning from this time point.

Returns:

  • true on normal interrupt.

  • false if an error occurred, the thread should exit, or the timeout was reached.

bool hasError() const

Checks if an error occurred during memory map initialization.

Returns:

True if an error occurred, false otherwise.

Private Members

const int mMem

The memory identifier.

bool mHasError = false

Flag indicating if an error occurred during initialization.