Memory mapping.
More...
#include <iomap.h>
|
| IoMap () |
| Constructor.
|
|
virtual | ~IoMap () |
| Destructor.
|
|
bool | open (const char *device, size_t size, off_t base=0) |
|
bool | open (off_t base, size_t size) |
| Open a memory mapping on /dev/mem.
|
|
bool | openGpioMem (int gpio_bank, size_t size) |
| Open a GPIO memory mapping for RP1.
|
|
void | close () |
| Close a memory mapping.
|
|
volatile uint32_t * | io (size_t offset=0) const |
| Pointer to access registers.
|
|
volatile uint32_t * | operator[] (size_t offset) const |
| Pointer to access registers.
|
|
uint32_t | read (size_t offset) const |
| Read a register.
|
|
void | write (size_t offset, uint32_t value) |
| Write a value to a register.
|
|
uint32_t | atomicRead (size_t offset) const |
| Atomic read of a register.
|
|
void | atomicWrite (size_t offset, uint32_t value) |
| Atomic write to a register.
|
|
bool | isOpen () const |
| Indicates if a memory mapping is open.
|
|
off_t | base () const |
| Base address of the mapped area.
|
|
size_t | size () const |
| Size of the mapped area.
|
|
|
static size_t | pageSize () |
| Size of a mapping page.
|
|
Memory mapping.
Definition at line 34 of file iomap.h.
◆ IoMap()
Piduino::IoMap::IoMap |
( |
| ) |
|
◆ ~IoMap()
virtual Piduino::IoMap::~IoMap |
( |
| ) |
|
|
virtual |
◆ atomicRead()
uint32_t Piduino::IoMap::atomicRead |
( |
size_t |
offset | ) |
const |
|
inline |
Atomic read of a register.
- Parameters
-
offset | offset inside the area in sizeof(int) |
- Returns
- the value read
This function reads a register atomically, ensuring that the read operation is not interrupted by other threads or processes.
Definition at line 122 of file iomap.h.
References io().
◆ atomicWrite()
void Piduino::IoMap::atomicWrite |
( |
size_t |
offset, |
|
|
uint32_t |
value |
|
) |
| |
|
inline |
Atomic write to a register.
- Parameters
-
offset | offset inside the area in sizeof(int) |
value | value to write |
This function writes a value to a register atomically, ensuring that the write operation is not interrupted by other threads or processes. It uses C11 atomic operations to ensure memory consistency.
- Note
- This function is useful for ensuring that hardware registers are updated safely in a multi-threaded environment.
Definition at line 137 of file iomap.h.
References io().
◆ base()
off_t Piduino::IoMap::base |
( |
| ) |
const |
|
inline |
Base address of the mapped area.
Definition at line 153 of file iomap.h.
References _base.
◆ close()
void Piduino::IoMap::close |
( |
| ) |
|
◆ io()
volatile uint32_t * Piduino::IoMap::io |
( |
size_t |
offset = 0 | ) |
const |
|
inline |
◆ isOpen()
bool Piduino::IoMap::isOpen |
( |
| ) |
const |
|
inline |
Indicates if a memory mapping is open.
Definition at line 145 of file iomap.h.
References _fd.
◆ open() [1/2]
bool Piduino::IoMap::open |
( |
const char * |
device, |
|
|
size_t |
size, |
|
|
off_t |
base = 0 |
|
) |
| |
◆ open() [2/2]
bool Piduino::IoMap::open |
( |
off_t |
base, |
|
|
size_t |
size |
|
) |
| |
Open a memory mapping on /dev/mem.
- Parameters
-
base | base address of the area to be mapped, must be a multiple of pageSize(). |
size | size of the area to be mapped in bytes |
- Returns
- true if opened, false if error
◆ openGpioMem()
bool Piduino::IoMap::openGpioMem |
( |
int |
gpio_bank, |
|
|
size_t |
size |
|
) |
| |
Open a GPIO memory mapping for RP1.
- Parameters
-
gpio_bank | GPIO bank (0-4 for /dev/gpiomem0 to /dev/gpiomem4) |
size | size of the area to be mapped in bytes |
- Returns
- true if opened, false if error
- Exceptions
-
std::system_error | if the open the device or memory mapping fails. |
◆ operator[]()
volatile uint32_t * Piduino::IoMap::operator[] |
( |
size_t |
offset | ) |
const |
|
inline |
Pointer to access registers.
- Parameters
-
offset | offset inside the area in sizeof(int) |
- Returns
- pointer to the register, NULL if error
Definition at line 88 of file iomap.h.
References io().
◆ pageSize()
static size_t Piduino::IoMap::pageSize |
( |
| ) |
|
|
static |
◆ read()
uint32_t Piduino::IoMap::read |
( |
size_t |
offset | ) |
const |
|
inline |
Read a register.
- Parameters
-
offset | offset inside the area in sizeof(int) |
- Returns
- the value read
This function reads a register at the specified offset and returns its value. It is a convenience method that allows direct access to the memory-mapped registers.
Definition at line 101 of file iomap.h.
References io().
◆ size()
size_t Piduino::IoMap::size |
( |
| ) |
const |
|
inline |
Size of the mapped area.
Definition at line 160 of file iomap.h.
References _size.
◆ write()
void Piduino::IoMap::write |
( |
size_t |
offset, |
|
|
uint32_t |
value |
|
) |
| |
|
inline |
Write a value to a register.
- Parameters
-
offset | offset inside the area in sizeof(int) |
value | value to write |
Definition at line 110 of file iomap.h.
References io().
◆ _base
off_t Piduino::IoMap::_base |
|
private |
◆ _fd
◆ _map
void* Piduino::IoMap::_map |
|
private |
◆ _size
size_t Piduino::IoMap::_size |
|
private |