62typedef enum : uint32_t {
75typedef enum : uint32_t {
83typedef enum : uint32_t {
93typedef enum : uint32_t {
104typedef enum : uint16_t {
109typedef enum : uint32_t {
128typedef enum : uint32_t {
181static const uint8_t
k_msg_boot[] =
"mem-subsystem: boot 2KiB-resident-1MiB-paged\r\n";
203 __asm__
volatile(
"bkpt #0");
205 __asm__
volatile(
"wfi");
214 const uint32_t mask = (uint32_t)(-(int32_t)(crc & 1U));
223 const uint32_t x = (uint32_t)off;
256 for (uint32_t i = 0U; i < n; i++) {
282 void* extra =
nullptr;
291 uint32_t free_before = 0U;
356 (void)
memset(cell, 0, (
size_t)cell_bytes);
357 cell[0] = (uint8_t)key->
tile_x;
395 .decode_ctx =
nullptr,
430 if (buf ==
nullptr) {
433 for (uint32_t i = 0U; i < len; i++) {
456 for (
size_t i = 0U; i < got; i++) {
516 uint32_t obj_id = 0U;
559 uint32_t cpuclk0_hz = 0U;
613 __asm__
volatile(
"wfi");
void main(void)
Secure fallback main entry point.
static const uint8_t k_msg_ok[]
static const uint8_t k_msg_boot[]
static const uint8_t k_msg_arena[]
static ra8_tile_dims_t s_tile_dims[k_mem_tile_cells]
Tile-cache per-cell dimension descriptors.
static bool mem_stream_window(ra8_vmem_stream_t *st, uint64_t off, uint32_t len, uint32_t *crc, size_t *out_got)
Read one byte window through the stream, verify it, and fold it in.
static uint8_t s_arena_pool[k_mem_arena_pool_bytes]
Arena-exercise region.
static ra8_vmem_key_t s_vmem_fkeys[k_mem_vmem_frames]
Page-cache per-frame key storage.
mem_slab_cfg_t
Slab-exercise sizing.
@ k_mem_slab_pool_bytes
Backing pool size.
@ k_mem_slab_freed
Cells freed before the reset.
@ k_mem_slab_cell_bytes
Bytes per cell (512/64 = 8).
@ k_mem_slab_cells
Cells the pool divides into.
static ra8_err_t mem_tile_touch(ra8_tile_cache_t *tc, uint16_t tx)
Fetch (get + immediately put) tile column tx, so it is unpinned.
static const uint8_t k_msg_slab[]
static ra8_tile_key_t s_tile_keys[k_mem_tile_cells]
Tile-cache per-cell key storage.
static void mem_panic_halt(const uint8_t *msg, uint32_t len)
Print the fail banner and trap (ra8_emulator halts on the BKPT).
mem_gen_t
Deterministic backing-byte generator constants.
@ k_mem_gen_add
Additive constant.
@ k_mem_gen_shift_a
First xor-fold shift.
@ k_mem_gen_shift_out
Output byte select shift.
@ k_mem_gen_shift_b
Second xor-fold shift.
@ k_mem_gen_mul
Odd multiplicative mixer.
static uint8_t s_tile_cells[(size_t) k_mem_tile_cells *(size_t) k_mem_tile_cell_bytes]
Tile-cache decoded-pixel cells.
static const uint8_t k_msg_tile[]
static ra8_keycache_cell_t s_tile_meta[k_mem_tile_cells]
Tile-cache per-cell link metadata.
static ra8_vmem_frame_t s_vmem_fmeta[k_mem_vmem_frames]
Page-cache per-frame metadata.
static uint8_t mem_gen_byte(uint64_t off)
Deterministic backing byte at absolute off (host/emulator/silicon-equal).
static bool mem_vmem_read_windows(ra8_vmem_stream_t *st, uint32_t *crc)
Read every window and confirm the stream returned the expected lengths.
static int32_t s_vmem_fbuckets[k_mem_vmem_buckets]
Page-cache hash buckets.
static const uint8_t k_msg_vmem[]
static const uint8_t k_msg_fail_init[]
static void mem_setup_or_halt(void)
Bring up clocks / MSTP / time + the board console; halt on failure.
mem_vmem_cfg_t
vmem_stream-exercise sizing + read windows.
@ k_mem_vmem_buckets
Page-cache hash buckets.
@ k_mem_win1_len
Window 1 length.
@ k_mem_win2_off
Window 2 offset (spans several frames).
@ k_mem_win1_off
Window 1 offset (crosses frame boundary).
@ k_mem_vmem_objs
Registry slots.
@ k_mem_win_past_len
Past-EOF window length (reads 0).
@ k_mem_vmem_frame_bytes
Page-cache frame size.
@ k_mem_win2_len
Window 2 length.
@ k_mem_vmem_obj_bytes
Synthetic backing object size (1 MiB).
@ k_mem_win0_off
Window 0 offset (within frame 0).
@ k_mem_win_eof_len
Near-EOF window length (clamps to 50).
@ k_mem_win_eof_back
Bytes before EOF the near-EOF window starts.
@ k_mem_vmem_frames
Frames in the fixed pool (2 KiB resident).
@ k_mem_win_buf_bytes
Read scratch (>= the widest window).
@ k_mem_win0_len
Window 0 length.
mem_arena_cfg_t
Arena-exercise sizing.
@ k_mem_arena_big
Over-subscribed carve (must fail).
@ k_mem_arena_pool_bytes
Backing region size.
@ k_mem_arena_align0
First / big carve alignment.
@ k_mem_arena_align1
Second carve alignment.
@ k_mem_arena_carve1
Second carve size.
@ k_mem_arena_carve0
First carve size.
static ra8_vsource_obj_t s_vmem_objs[k_mem_vmem_objs]
Object-source registry slots.
static bool mem_run_vmem(mem_report_t *r)
Exercise 4: stream byte windows out of a 1 MiB object via a 2 KiB cache.
static bool mem_run_slab(mem_report_t *r)
Exercise 1: slab alloc-to-exhaustion, free, and reset-by-reinit.
static void mem_print_hex(uint32_t value)
Print a 32-bit value as 8 upper-case hex digits.
static uint32_t mem_crc32_byte(uint32_t crc, uint8_t b)
Fold one byte into a running CRC-32 (reflected, poly 0xEDB88320).
mem_console_t
Console + banner-format knobs (no magic numbers).
@ k_mem_crc_bits
Bits folded per byte.
@ k_mem_nibble_mask
Low-nibble mask.
@ k_mem_dec_base
Decimal base / hex-digit split.
@ k_mem_uart_baud
Console baud.
@ k_mem_hex_nibbles
Hex digits in a 32-bit value.
@ k_mem_crc_init
CRC-32 initial value.
@ k_mem_crc_xorout
CRC-32 final xor (== bitwise not).
@ k_mem_crc_poly
CRC-32 reflected polynomial.
@ k_mem_nibble_bits
Bits per hex nibble.
static ra8_err_t mem_tile_decode(void *ctx, const ra8_tile_key_t *key, uint8_t *cell, uint32_t cell_bytes, uint16_t *out_w, uint16_t *out_h)
Synthetic tile decoder: stamps the key column into the cell.
static const uint8_t k_msg_fail_arena[]
mem_tile_cfg_t
Tile-cache-exercise sizing + expected counters.
@ k_mem_tile_buckets
Hash buckets.
@ k_mem_tile_exp_hits
Expected hits after the drive.
@ k_mem_tile_cells
Cells in the cache.
@ k_mem_tile_distinct
Distinct tiles faulted (> cells).
@ k_mem_tile_cell_bytes
Bytes per tile cell.
@ k_mem_tile_exp_miss
Expected misses after the drive.
@ k_mem_tile_exp_evict
Expected evictions after the drive.
static const uint8_t k_msg_fail_tile[]
mem_tile_dim_t
Synthetic decoded-tile dimensions.
@ k_mem_tile_dim
Synthetic decoded tile edge length.
static void mem_print_uint(uint32_t value)
Print a small unsigned integer in decimal.
static const uint8_t k_msg_fail_slab[]
static bool mem_run_tiles(mem_report_t *r)
Exercise 3: overfill the tile cache to observe LRU eviction.
static uint8_t s_vmem_frames[(size_t) k_mem_vmem_frames *(size_t) k_mem_vmem_frame_bytes]
Page-cache frame storage (2 KiB resident).
static const uint8_t k_msg_fail_vmem[]
static bool mem_run_arena(mem_report_t *r)
Exercise 2: arena bump carves, over-subscription, and reset-by-reinit.
static uint8_t s_slab_pool[k_mem_slab_pool_bytes]
Slab-exercise pool.
static uint8_t s_win_buf[k_mem_win_buf_bytes]
Stream read scratch (>= the widest window).
static int32_t s_tile_buckets[k_mem_tile_buckets]
Tile-cache hash buckets.
static void mem_print(const uint8_t *msg, uint32_t len)
Emit a byte run on the board console.
static ra8_err_t mem_backing_read(void *ctx, uint64_t offset, uint8_t *buf, uint32_t len)
Backing read callback: fill buf with the deterministic generator.
Init-time bump arena – carves per-tier slab backing, zero-heap.
ra8_err_t ra8_arena_carve(ra8_arena_t *arena, uint32_t bytes, uint32_t align, void **out_ptr)
Carve an aligned sub-block from the arena (bump; no free).
ra8_err_t ra8_arena_remaining(const ra8_arena_t *arena, uint32_t *out_remaining)
Report the bytes still available in the arena.
ra8_err_t ra8_arena_init(ra8_arena_t *arena, void *base, uint32_t size)
Bind a bump arena over a caller-owned tier region.
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
ra8_err_t ra8_board_uart_console_write(const uint8_t *data, size_t len)
Polled blocking write to the J-Link OB VCOM console.
ra8_err_t ra8_board_uart_console_init(uint32_t baud)
Configure SCI8 + PD02/PD03 as the debug-console UART.
Boot entry points shared between a vector table and its startup code.
High-level Clock Generation Circuit driver.
ra8_err_t ra8_cgc_get_clock_hz(ra8_clock_id_t id, uint32_t *out_hz)
Query the current frequency of a clock-tree domain.
@ k_ra8_clock_id_cpuclk0
Cortex-M85 CPUCLK0.
ra8_err_t ra8_cgc_init(void)
Configure the clock tree to a safe default.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_no_mem
Static buffer exhausted (no dynamic memory on this project).
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
void * memset(void *dst, int value, size_t n)
Fill memory with a constant byte value.
NVIC + ICU IELSR allocator.
void ra8_isr_globals_enable(void)
Globally enable maskable interrupts (PRIMASK = 0).
Ref-counted Module Stop Control wrapper for the RA8D2.
ra8_err_t ra8_mstp_init(void)
Re-establish the ra8_mstp ref-count table from current hardware state.
Fixed-cell slab allocator – O(1), zero-fragmentation, zero-heap.
ra8_err_t ra8_slab_alloc(ra8_slab_t *slab, void **out_cell)
Allocate one cell from the slab (O(1)).
ra8_err_t ra8_slab_free(ra8_slab_t *slab, void *cell)
Return a previously-allocated cell to the slab (O(1)).
ra8_err_t ra8_slab_init(ra8_slab_t *slab, void *buffer, uint32_t buffer_bytes, uint32_t cell_bytes)
Initialise a slab over a caller-owned buffer.
ra8_err_t ra8_slab_stats(const ra8_slab_t *slab, uint32_t *out_free, uint32_t *out_total)
Report the slab's free / total cell counts.
Fixed-RAM-budget image-tile cache with LRU eviction (Layer 3b, #147).
ra8_err_t ra8_tile_cache_get(ra8_tile_cache_t *tc, const ra8_tile_key_t *key, ra8_tile_t *out_tile)
Get (and pin) the decoded tile for key.
ra8_err_t ra8_tile_cache_stats(const ra8_tile_cache_t *tc, uint32_t *out_hits, uint32_t *out_misses, uint32_t *out_evictions)
Report the cache hit / miss / eviction counters.
ra8_err_t ra8_tile_cache_put(ra8_tile_cache_t *tc, const uint8_t *pixels)
Release one pin on a tile previously returned by ra8_tile_cache_get.
ra8_err_t ra8_tile_cache_init(ra8_tile_cache_t *tc, const ra8_tile_cache_cfg_t *cfg)
Initialise a tile cache over caller-supplied storage.
SysTick-based tick counter, delay and timestamp helpers.
ra8_err_t ra8_time_init(uint32_t cpu_hz)
Initialise SysTick for a 1 kHz tick interrupt.
ra8_err_t ra8_vmem_init(ra8_vmem_t *vm, const ra8_vmem_cfg_t *cfg)
Initialise a page cache over caller-supplied storage.
ra8_err_t ra8_vmem_stats(const ra8_vmem_t *vm, uint32_t *out_hits, uint32_t *out_misses, uint32_t *out_evictions)
Report the cache hit / miss / eviction counters.
ra8_keycache_cell_t ra8_vmem_frame_t
Per-frame cache metadata (one caller-owned array entry per frame).
Read a page-cached object as a seekable byte stream (Layer 2 helper, #147/#151).
ra8_err_t ra8_vmem_stream_init(ra8_vmem_stream_t *st, ra8_vmem_t *vm, uint32_t object_id, uint64_t size)
Bind a page-cached paged object to the byte-stream reader.
size_t ra8_vmem_stream_read(void *ctx, uint64_t offset, void *buf, size_t len)
Read len bytes at absolute offset through the page cache.
Virtual-memory object sources – the page-cache storage seam (Layer 1, #147).
ra8_err_t ra8_vsource_loader(void *ctx, uint32_t object_id, uint64_t offset, uint8_t *frame, uint32_t frame_bytes)
Fill a page frame from an object – the ra8_vmem_loader_fn adapter.
ra8_err_t ra8_vsource_add_paged(ra8_vsource_t *vs, ra8_vsource_read_fn read, void *ctx, uint64_t base, uint64_t size, uint32_t *out_id)
Register a storage-paged object; returns its object_id.
ra8_err_t ra8_vsource_init(ra8_vsource_t *vs, ra8_vsource_obj_t *objs, uint32_t cap)
Initialise an empty source registry over a caller-owned object array.
Observables gathered from the four exercises.
uint32_t tile_evictions
Tile-cache eviction count.
uint32_t tile_hits
Tile-cache hit count.
uint32_t vmem_evictions
Page-cache evictions (paging proof).
uint32_t tile_misses
Tile-cache miss count.
uint32_t vmem_crc
CRC-32 over the streamed byte windows.
uint32_t arena_free
Bytes remaining after the arena reset.
uint32_t slab_free
Free cells after the slab reset.
Caller-owned bump-arena state over one tier region.
Per-cell link metadata (one caller-owned array entry per cell).
Caller-owned state for one fixed-cell pool.
Caller-supplied storage + decoder for ra8_tile_cache_init.
Tile-cache state (caller-owned; treat as private).
Per-cell user descriptor: the decoded tile dimensions.
Identifies one decoded image tile.
uint16_t tile_x
Tile column index (in tile units).
A pinned view of a cached tile returned by ra8_tile_cache_get.
const uint8_t * pixels
Decoded tile pixels (cell payload).
Caller-supplied storage + loader for ra8_vmem_init.
The (object_id, frame-aligned offset) key the page cache hashes on.
Binds one page-cached object to the byte-stream read adapter.
Page-cache state (caller-owned; treat as private).
One registered object's backing (paged or XIP).
Object-source registry (caller-owned; treat as private).