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 map_base, uint32_t map_size)
Constructs a MemoryMap object.
- Parameters:
mem – The memory identifier.
map_base – The base address of the memory map.
map_size – The size of the memory map.
-
MemoryMap(const char *filename, uint32_t map_size, int flag = O_RDWR)
Constructs a MemoryMap object.
- Parameters:
filename – The name of the file to be mapped.
map_size – The size of the memory map.
flag – The flag to be used for the file.
-
~MemoryMap()
Destroys the MemoryMap object.
-
MemoryMap() = 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 has_error() const
Checks if an error occurred during memory map initialization.
- Returns:
True if an error occurred, false otherwise.
-
uint32_t memory_read(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 memory_write(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 memory_read_bit(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 memory_write_bit(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 MEM_
The memory identifier.
-
const bool HANDLE_FILE_
Flag indicating if the file should be closed.
-
const uint32_t MAP_SIZE_
The size of the memory map.
-
uint32_t *map_
Pointer to the memory map.
-
bool has_error_ = false
Flag indicating if an error occurred during initialization.
-
MemoryMap(int mem, uint32_t map_base, uint32_t map_size)
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
-
explicit 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
-
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 enable_interrupt() const
Enables interrupts.
The interrupt must be enabled after each interrupt.
-
bool wait_interrupt(std::atomic<bool> *exit_signal, std::chrono::time_point<std::chrono::steady_clock> stop_time) const
Waits for an interrupt.
- Parameters:
exit_signal – A pointer to an atomic boolean indicating if the thread should exit.
stop_time – 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 has_error() const
Checks if an error occurred during memory map initialization.
- Returns:
True if an error occurred, false otherwise.
-
explicit Uio(const char *filename)