Memory-Mapped Input/Output (MMIO)
Detailed Description
These accessors are used to access memory-mapped I/O registers on the chip as well as external devices hooked up through the external bus interface. Accessing such registers usually have side-effects, so these accessors ensure that the registers are accessed exactly as many times as specified.
Traditionally, such registers are accessed through pointers declared as "volatile", but using dedicated accessors has a number of advantages:
- Conceptually, it makes much more sense to provide special access semantics as part of an operation instead of the data associated with it.
- The optimal way to access a register may vary from compiler to compiler (for example, gcc appears to generate slightly better code from inline assembly than from volatile access.) Such details are best hidden behind an accessor layer like this.
- When dedicated accessors are used, it becomes very obvious that the code using them are in fact dealing with I/O. A volatile struct access looks just like any other struct access.
Define Documentation
| #define AVR_MMIO_OFFSET 0x20 |
Memory mapped register address offset.
Offset that needs to be added to an I/O space address to get the corresponding memory mapped address.
Definition at line 52 of file io.h.
Function Documentation
| static uint8_t mmio_read8 |
( |
const void * |
p |
) |
[inline, static] |
Read a byte from a memory-mapped register.
The compiler will optimise this to an I/O space access when applicable.
- Parameters:
-
- Returns:
- The value at the virtual address specified by p.
Definition at line 67 of file io.h.