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.
Function Documentation
| void mmio_ccp_write8 |
( |
void * |
addr, |
|
|
uint8_t |
value | |
|
) |
| | |
Write to a CCP-protected 8-bit register.
- Parameters:
-
| addr | Address of the I/O register |
| value | Value to be written |
| static uint16_t mmio_read16 |
( |
const void * |
p |
) |
[inline, static] |
16-bit read from I/O register
Reads LSB from address p and MSB from address p+1, in this order.
- Note:
- Interrupts are not disabled in this function. This must be done in the calling code if interrupts can corrupt reads, i.e., they access 16-bit registers in the same peripheral module and at the same time as this function.
- Parameters:
-
| p | Address of LSB I/O register to read from |
Definition at line 72 of file io.h.
| static void mmio_write16 |
( |
void * |
p, |
|
|
uint16_t |
val | |
|
) |
| | [inline, static] |
16-bit write to I/O register
Writes LSB to address p and MSB to address p+1, in this order.
- Note:
- Interrupts are not disabled in this function. This must be done in the calling code if interrupts can corrupt writes, i.e., they access 16-bit registers in the same peripheral module and at the same time as this function.
- Parameters:
-
| p | Address of LSB I/O register to write to |
| val | 16-bit value to write to registers |
Definition at line 95 of file io.h.