mem.h

C source for Emulating a round-screen ESP32 board, 35 lines. Raw file

// mem.h - ESP32-S3 physical memory map. The CPU and peripherals go through here.
#pragma once
#include <stdint.h>
#include <stdbool.h>

// Backing stores are placed at the real ESP32-S3 addresses so the UNCHANGED
// firmware image loads and runs exactly as on silicon.
void      mem_init(void);
bool      mem_is_ram(uint32_t a);          // RAM/flash-backed (vs MMIO/unmapped)
uint8_t  *mem_host(uint32_t a);            // host pointer to a backed address, or NULL

uint8_t   mem_r8 (uint32_t a);
uint16_t  mem_r16(uint32_t a);
uint32_t  mem_r32(uint32_t a);
void      mem_w8 (uint32_t a, uint8_t  v);
void      mem_w16(uint32_t a, uint16_t v);
void      mem_w32(uint32_t a, uint32_t v);

// The loader writes a firmware segment straight into the backing store.
void      mem_load(uint32_t a, const uint8_t *data, uint32_t len);

// Raw flash / PSRAM backing at a chip offset — the MSPI controller (mmio.c) and the
// MMU translation (mem.c) reach the chips through here, independent of the windows.
uint8_t  *mem_flash(uint32_t off);         // host ptr at flash offset, or NULL if OOB
uint32_t  mem_flash_size(void);
uint8_t  *mem_psram(uint32_t off);         // host ptr at PSRAM offset, or NULL if OOB
uint32_t  mem_psram_size(void);

// One entry of the flash/PSRAM MMU page table (0x600C5000+), read from mmio.c.
uint32_t  mmu_entry(uint32_t index);

// MMIO (peripherals at 0x6000_0000..) is handled here (implemented in mmio.c).
uint32_t  mmio_read (uint32_t a);
void      systimer_step(void);   // advance SYSTIMER alarms (interrupts)
void      mmio_write(uint32_t a, uint32_t v);