84typedef enum : uint32_t {
99typedef enum : uint32_t {
142[[gnu::section(
".sdram_data"),
161[[gnu::section(
".sdram_data"),
165[[gnu::section(
".sdram_data"),
174[[gnu::section(
".sdram_data"),
189static const uint8_t
k_msg_boot[] =
"import_reader: boot\r\n";
192static const uint8_t
k_msg_miss[] =
"import_reader: first open MISS -> compiled, cache=";
193static const uint8_t
k_msg_hit[] =
"import_reader: second open HIT (no recompile), cache=";
197static const uint8_t
k_msg_ch[] =
"import_reader: ch";
200static const uint8_t
k_msg_pass[] =
"import_reader: miss->compile->cache->hit->read PASS\r\n";
225#define IMP_PUTS(lit) imp_print((lit), (uint32_t)sizeof(lit) - 1U)
269 for (uint32_t i = 0U; i < n; i++) {
291 __asm__
volatile(
"bkpt #0");
293 __asm__
volatile(
"wfi");
315 uint32_t cpuclk0_hz = 0U;
316 uint32_t pclka_hz = 0U;
332 *out_pclka_hz = pclka_hz;
617 uint32_t cache_len = 0U;
661 uint32_t pclka_hz = 0U;
679 __asm__
volatile(
"wfi");
void main(void)
Secure fallback main entry point.
Flat, execute-in-place container for a build-time "compiled" e-book.
ra8_err_t book_chapter_text(const void *base, uint32_t chapter_idx, char *out, size_t cap, size_t *out_len)
Extract one chapter's readable plain text from the DOM.
static const book_header_t * book_header(const void *base)
View the blob base as its header.
static const char * book_string(const void *base, uint32_t off)
Resolve a string-pool offset to a NUL-terminated UTF-8 string.
ra8_err_t book_validate(const void *base, size_t size)
Validate that a byte buffer is a well-formed, intact .rabook blob.
EPUB (.epub) reader and chapter iterator for ra8-firmware.
static const uint8_t k_msg_boot[]
static const uint8_t k_msg_fail[]
static const uint8_t k_msg_eol[]
static const uint8_t k_msg_miss[]
Console banner fragment: cache miss counter label.
static const uint8_t k_msg_hit[]
Console banner fragment: cache hit counter label.
static uint8_t s_imp_scratch[k_imp_scratch_cap]
Streaming CRC chunk for the source-key pass.
static epub_book_t s_imp_epub
Open-book storage owned across the compile.
static ra8_vmem_frame_t s_imp_cache_meta[k_imp_cache_frames]
Per-frame metadata for the source page cache.
static book_stylesheet_t s_imp_styles[k_imp_style_cap]
static uint8_t s_imp_readback[k_imp_readback_cap]
Cached-.rabook read-back buffer (4-byte aligned for the accessors).
static ra8_rabook_buffers_t s_imp_bufs
Builder arenas, pipeline scratch, stb arena, and the compiler cookie.
static void imp_build_cookie(void)
Populate the builder/scratch views + the production compile cookie.
static const ra8_port_pin_t k_imp_pin_copi
static char s_imp_strpool[k_imp_string_cap]
static uint8_t s_imp_image_raw[k_imp_imgraw_cap]
#define IMP_PUTS(lit)
Emit a NUL-terminated literal (length via sizeof at the call site).
static uint8_t s_imp_gray[k_imp_gray_cap]
static const uint8_t k_msg_cbytes[]
static void imp_panic(const char *stage)
Print the FAIL banner with a stage tag, then trap and park.
static void imp_run(ra8_fs_mount_t *mount)
Run the import twice (miss then hit), confirm the cache, read + walk.
static char s_imp_css[k_imp_css_cap]
imp_buf_cap_t
SDRAM working-arena capacities (sized for a small text book).
@ k_imp_readback_cap
Cached-.rabook read buffer.
@ k_imp_node_cap
Max DOM nodes.
@ k_imp_image_cap
Max image descriptors.
@ k_imp_cache_buckets
Page-cache hash buckets (~2x frames).
@ k_imp_string_cap
String-pool capacity (bytes).
@ k_imp_imgraw_cap
Raw cover/image scratch (bytes).
@ k_imp_cache_frame_bytes
Source page-cache frame size (bytes).
@ k_imp_gray_cap
Gray downscale scratch (pixels).
@ k_imp_xhtml_cap
Chapter XHTML scratch (bytes).
@ k_imp_attr_cap
Max attribute records.
@ k_imp_arena_cap
stb_image bump arena (bytes).
@ k_imp_css_cap
Stylesheet load scratch (bytes).
@ k_imp_out_cap
Output-blob capacity (bytes).
@ k_imp_cache_frames
Fixed frame budget: 64 x 4 KiB = 256 KiB.
@ k_imp_chapter_cap
Max chapters.
@ k_imp_imgpool_cap
Image-pool capacity (bytes).
@ k_imp_style_cap
Max stylesheets.
static void imp_init_card_or_halt(uint32_t pclka_hz)
Build the SCI-SPI transport, run SD identification; panic on failure.
static rabook_import_compiler_ctx_t s_imp_cookie
static uint8_t s_imp_cache_frames[k_imp_cache_frames *k_imp_cache_frame_bytes]
Fixed frame pool the streamed source is paged through (#230).
static const uint8_t k_msg_textlen[]
imp_config_t
Compile-time settings for the on-import compile + cache + read demo.
@ k_imp_spi_channel
Pmod2 / J25 SCI0 Simple-SPI.
@ k_imp_format_version
RABOOK1 on-disk format stamp.
@ k_imp_path_cap
Cache-path buffer (holds "BOOK.rabook").
@ k_imp_uart_baud
J-Link OB CDC console baud.
@ k_imp_scratch_cap
Source-CRC streaming chunk (bytes).
@ k_imp_dec_base
Radix for integer-to-ASCII.
@ k_imp_importer_version
Importer/compiler version stamp.
@ k_imp_str_max
Bound on a logged C-string (Rule 2).
static ra8_rabook_xml_workspace_t s_imp_xml_workspace
static ra8_err_t imp_read_cache(ra8_fs_mount_t *mount, const char *path, uint32_t *out_len)
Read the whole cached .rabook at path into s_imp_readback.
static const uint8_t k_msg_ch[]
static ra8_img_arena_t s_imp_arena
static const uint8_t k_msg_pass[]
static const uint8_t k_msg_card_ok[]
static ra8_rabook_pipeline_scratch_t s_imp_scr
static void imp_print(const uint8_t *msg, uint32_t len)
Write a byte run on the J-Link OB console.
static const uint8_t k_msg_mounted[]
static const uint8_t k_msg_chaps[]
static uint8_t s_imp_imgpool[k_imp_imgpool_cap]
static void imp_setup_or_halt(uint32_t *out_pclka_hz)
Bring up CGC + SysTick + console SCI; panic on failure.
static const ra8_port_pin_t k_imp_pin_sck
Pmod2 SPI pins (J25) – SCI0 Simple-SPI; CS held by GPIO.
static uint8_t s_imp_xhtml[k_imp_xhtml_cap]
Pipeline scratch (XHTML load + stylesheet load + image decode + gray downscale).
static ra8_vmem_t s_imp_cache
Source page cache; re-initialised by the adapter per compile.
static ra8_err_t imp_walk_book(uint32_t len)
Validate the cached blob and log its title, chapter count, and the plain-text length of every chapter...
static const char k_imp_epub_path[]
Root-level 8.3 source name the appliance imports.
static book_chapter_t s_imp_chapters[k_imp_chapter_cap]
RABOOK1 builder arenas (one per table + the two pools + output).
static book_node_t s_imp_nodes[k_imp_node_cap]
static void imp_mount_or_halt(ra8_fs_mount_t **out_mount)
Bind the SD-over-SPI block device into ra8_fs and mount the volume.
static const ra8_port_pin_t k_imp_pin_cs
static rabook_import_cfg_t imp_make_cfg(ra8_fs_mount_t *mount)
Build the import config that injects the production compile adapter.
static void imp_print_cstr(const char *str)
Emit a NUL-terminated C-string, bounded to k_imp_str_max bytes.
static ra8_vmem_key_t s_imp_cache_keys[k_imp_cache_frames]
Per-frame key storage for the source page cache.
static uint8_t s_imp_out[k_imp_out_cap]
static const uint8_t k_msg_title[]
static book_attr_t s_imp_attrs[k_imp_attr_cap]
static int32_t s_imp_cache_buckets[k_imp_cache_buckets]
Hash-bucket heads for the source page cache.
static void imp_print_uint(uint32_t value)
Print a small unsigned integer in decimal.
static uint8_t s_imp_img_scratch[k_imp_arena_cap]
static book_image_t s_imp_images[k_imp_image_cap]
static const ra8_port_pin_t k_imp_pin_cipo
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
@ k_ra8_board_pmod2_spi_cipo
Pmod2.3 CIPO (CIPO0_B), P602.
@ k_ra8_board_pmod2_spi_cs
Pmod2.1 CS (SS0_B), P604.
@ k_ra8_board_pmod2_spi_copi
Pmod2.2 COPI (COPI0_B), P603.
@ k_ra8_board_pmod2_spi_sck
Pmod2.4 SCK (SCK0_B), P601.
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.
ra8_err_t ra8_board_uart_console_flush(void)
Block until every byte queued on the J-Link OB VCOM console has finished clocking out on the wire.
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.
@ k_ra8_clock_id_pclka
PCLKA.
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.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Minimal FAT12/FAT16/FAT32 filesystem adapter (read + write).
ra8_err_t ra8_fs_mount(const ra8_fs_backend_t *backend, ra8_fs_mount_t **out_handle)
Mount a FAT volume from a block-device backend, auto-selecting the first partition.
ra8_err_t ra8_fs_size(const ra8_fs_file_t *file, uint64_t *out_bytes)
Report the file's size in bytes (64-bit on exFAT, #676).
ra8_err_t ra8_fs_read(ra8_fs_file_t *file, uint8_t *buf, uint32_t max_len, uint32_t *got_len)
Read up to max_len bytes; advance the cluster chain on cluster crossings.
ra8_err_t ra8_fs_open(ra8_fs_mount_t *handle, const char *path, ra8_fs_mode_t mode, ra8_fs_file_t **out_file)
Open or create a file by path, 8.3 or long.
ra8_err_t ra8_fs_close(ra8_fs_file_t *file)
Close an open file, stamping its final modification time.
@ k_ra8_fs_mode_read
Read-only, must exist.
NVIC + ICU IELSR allocator.
void ra8_isr_globals_enable(void)
Globally enable maskable interrupts (PRIMASK = 0).
Lightweight Logging Interface for ra8-firmware.
void ra8_log_init(void)
Initialise the logging backend.
ra8_port_pin_t
Packed (port << 8) | pin pin identifier.
End-to-end EPUB -> RABOOK1 compile pipeline (#149).
SD card driver in SPI-mode (PMOD-attached cards).
ra8_err_t ra8_sdmmc_spi_transport_sci(uint8_t sci_channel, uint32_t pclk_hz, const ra8_sdmmc_spi_sci_pins_t *pins, ra8_sdmmc_spi_transport_t *out)
Build the standard EK-RA8D2 SCI Simple-SPI transport for an SD card.
ra8_err_t ra8_sdmmc_spi_init(const ra8_sdmmc_spi_transport_t *transport)
Run the SD SPI-mode identification sequence on a card.
ra8_err_t ra8_sdmmc_spi_bind_fs_backend(ra8_fs_backend_t *out_backend)
Populate an ra8_fs_backend_t that mounts onto this SD driver.
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.
Byte-range page cache with SLRU eviction (Layer 2, #147).
ra8_keycache_cell_t ra8_vmem_frame_t
Per-frame cache metadata (one caller-owned array entry per frame).
Zero-heap builder that emits a RABOOK1 blob (the #149 compiler back-end).
On-import EPUB -> .rabook compile-and-cache manager (#151).
rabook_import_outcome_t
How rabook_import_open satisfied the request.
@ k_rabook_import_hit
Fresh cache reused; the compiler was NOT invoked.
@ k_rabook_import_compiled
Miss/stale; the book was compiled and cached.
ra8_err_t rabook_import_open(const rabook_import_cfg_t *cfg, const char *epub_path, char *out_cache_path, uint32_t cache_path_cap, rabook_import_outcome_t *out_outcome)
Resolve a source .epub to a fresh cached .rabook, compiling once.
Production adapter binding the import seam to the real compiler (#151).
ra8_err_t rabook_import_compile_adapter(void *compile_ctx, ra8_fs_mount_t *mount, const char *epub_path, const char *out_path)
Import-seam adapter: stream a .epub off mount and compile it.
One name="value" attribute on an element.
One spine document (a renderable chapter) plus its TOC label.
Descriptor for one transcoded image in the image pool.
A preserved CSS stylesheet and the chapter it scopes to.
Block-device interface that ra8_fs runs on top of.
Cached parse of one mounted FAT volume.
Caller-owned bump arena backing a single image decode.
Caller-owned, fixed-capacity arenas the builder appends into (no heap).
Caller-owned temporary buffers the pipeline stage needs.
Caller-owned storage for one parser invocation.
The four bus pins of an SCI Simple-SPI SD slot.
Driver-to-bus binding (Dependency Inversion seam).
The (object_id, frame-aligned offset) key the page cache hashes on.
Page-cache state (caller-owned; treat as private).
Injected dependencies + versioning for rabook_import_open.
uint32_t scratch_cap
Capacity of scratch in bytes.
ra8_fs_mount_t * mount
Mounted FAT volume (cache + source).
void * compile_ctx
Cookie forwarded to compile.
rabook_import_compile_fn compile
Compile-on-miss seam (non-NULL).
uint32_t format_version
.rabook format version stamp.
uint8_t * scratch
Streaming buffer for the source CRC.
uint32_t importer_version
Importer/compiler version stamp.
Cookie carrying the storage rabook_import_compile_adapter needs.