Memory-Mapped Driver Abstraction
Implement a memory-mapped I/O driver abstraction in C for an embedded peripheral. The driver must allow safe register read/write using volatile pointers, support bitfield operations, and expose initialization and reset routines.
Constraints
- Base address provided in init().
- read32(offset), write32(offset,val).
- set_bit(offset,bit), clear_bit(offset,bit).
- Must use volatile uint32_t*.
- No dynamic allocation.
1#include <stdint.h>2void mmio_init(uint32_t base);3uint32_t mmio_read32(uint32_t off);4void mmio_write32(uint32_t off, uint32_t v);5void mmio_setbit(uint32_t off, int b);6void mmio_clearbit(uint32_t off, int b);