68typedef enum : uint32_t {
147static const char s_pc_body[] =
"<html><body><h1>Cache</h1>"
148 "<p>Pagination cache round-trip on silicon.</p>"
149 "<p>Second paragraph for the break engine.</p></body></html>";
155typedef enum : uint32_t {
171typedef enum : uint32_t {
216static const uint8_t
s_msg_boot[] =
"pagecache-hil: boot\r\n";
234static const uint8_t
s_msg_ok[] =
" crc_match=1 invalidate=1 PASS\r\n";
270 __asm__
volatile(
"wfi");
292 for (
size_t i = 0U; i < len; i++) {
293 crc ^= (uint32_t)data[i];
294 for (uint32_t bit = 0U; bit < (uint32_t)
k_pc_crc_bits; bit++) {
295 const uint32_t mask = (uint32_t)(-(int32_t)(crc & 1U));
321 for (
size_t i = 0U; i < len; i++) {
350 const uint32_t pclka_hz = *(
const uint32_t*)ctx;
446 uint32_t cpuclk0_hz = 0U;
447 uint32_t pclka_hz = 0U;
467 *out_pclka_hz = pclka_hz;
515 opts.
label =
"RAPCACHE";
678 if (got != (uint32_t)n) {
766 uint32_t pclka_hz = 0U;
778 uint32_t font_len = 0U;
void main(void)
Secure fallback main entry point.
static ra8_fs_backend_t s_backend
SD backend; file-scope so the mount handle may reference it.
static ra8_err_t internal_pc_spi_pins_init(void)
Route Pmod2 SPI signals and initialize chip select high.
pc_err_t
Failure-stage codes stamped to g_pc_err for SWD / --dump-sym.
@ k_pc_err_none
No failure (success path).
@ k_pc_err_crc
Reloaded layout CRC != live CRC.
@ k_pc_err_persist
Write / read-back the blob on SD.
@ k_pc_err_init
CGC / time / console / SPI bring-up.
@ k_pc_err_ser
reflow_cache_serialize.
@ k_pc_err_font
Provision / read FONT.OTF.
@ k_pc_err_load
reflow_cache_load (expected hit).
@ k_pc_err_layout
reflow_init / layout_chapter.
@ k_pc_err_mount
Mount (and format-if-blank).
@ k_pc_err_readback
Read-back blob != written blob.
@ k_pc_err_card
SD card SPI init.
@ k_pc_err_invalid
Alt-size load did not invalidate.
static reflow_t s_engine
Reflow engine (glyph / page / token / text pools live inside).
static ra8_fs_mount_t * internal_pc_mount_or_halt(void)
Bind and mount the SD filesystem, formatting blank media if needed.
static const ra8_port_pin_t s_pc_pin_copi
Pmod2 controller-output/peripheral-input pin.
static const char s_pc_cache_path[]
Root-directory 8.3 name for the serialized pagination cache.
volatile uint32_t g_pc_crc_match
1 if the reloaded-cache blob CRC equals the live-layout blob CRC.
volatile uint32_t g_pc_invalidate
1 if loading the blob at the alt font size returned invalid_state.
static uint8_t s_font_buf[k_pc_font_cap]
Font blob read off the card.
static const uint8_t s_msg_boot[]
Console marker emitted after core and peripheral setup.
static uint8_t s_live_blob[k_pc_blob_cap]
Serialised cache blob from the live layout.
static ra8_err_t internal_pc_spi_cs(void *ctx, bool asserted)
Drive the SD-card active-low chip-select GPIO.
static const uint8_t s_msg_ok[]
Final cache-CRC and invalidation success suffix.
volatile uint32_t g_pc_live_crc
CRC-32 of the live-layout serialised blob.
static uint32_t internal_pc_read_cache(ra8_fs_mount_t *mount, uint8_t *buf, uint32_t cap)
Read the persisted cache file into a bounded caller buffer.
volatile uint32_t g_pc_heartbeat
Idle heartbeat; advances ONLY after every assertion passes.
static const ra8_port_pin_t s_pc_pin_sck
Pmod2 SCI clock pin used by the SD-card transport.
pc_consts_t
Console / SPI / reflow knobs (no magic numbers).
@ k_pc_blob_cap
Cache-blob buffer capacity, bytes.
@ k_pc_font_cap
Font read buffer (OTF is ~57 KiB; trimmed from 128 KiB when the fs sector arena grew ....
@ k_pc_uart_baud
Console baud.
@ k_pc_link_argb
Anchor text colour.
@ k_pc_spi_chan
Pmod2 / J25 SCI0 Simple-SPI.
@ k_pc_view_w
Reflow viewport width, px.
@ k_pc_ink_argb
Body text colour.
@ k_pc_crc_poly
CRC-32 reflected polynomial.
@ k_pc_font_px
Body font size, px (round-trip key).
@ k_pc_font_px_alt
Alt font size to force invalidation.
@ k_pc_crc_init
CRC-32 initial value.
@ k_pc_view_h
Reflow viewport height, px.
@ k_pc_crc_bits
Bits folded per byte.
pc_pace_t
Idle-loop pacing for the success heartbeat.
@ k_pc_frame_ms
Heartbeat period in milliseconds.
static void internal_pc_fail(uint32_t err)
Stamp the failure stage and park the CPU without a heartbeat.
static ra8_err_t internal_pc_spi_xfer(void *ctx, const uint8_t *tx, uint8_t *rx, uint32_t len)
Exchange an SD-card byte span through SCI SPI.
static bool internal_pc_blob_equal(const uint8_t *a, const uint8_t *b, size_t len)
Compare two equal-length cache-blob spans.
static void internal_pc_print(const uint8_t *msg, uint32_t len)
Emit a byte run on the board console.
static uint32_t internal_pc_crc32(const uint8_t *data, size_t len)
Calculate reflected CRC-32 over a byte span.
static bool internal_pc_engine_init(uint16_t font_px, uint32_t font_len)
Initialise the engine at font_px over the SD font.
static const uint8_t s_msg_pass[]
Prefix for the final reset-survival hit diagnostic.
static uint8_t s_read_blob[k_pc_blob_cap]
Blob read back off SD (compared to s_live_blob).
static ra8_err_t internal_pc_spi_set_clock(void *ctx, uint32_t hz)
Apply an SD-card SPI clock through the SCI transport.
static uint8_t s_reser_blob[k_pc_blob_cap]
Blob re-serialised from the reloaded engine (CRC vs live).
static void internal_pc_reload_check_or_halt(uint32_t font_len, size_t n)
Load the read-back blob into a fresh same-size engine and CRC it.
static const char s_pc_font_path[]
Root-directory 8.3 name for the persisted font.
static void internal_pc_font_or_halt(ra8_fs_mount_t *mount, uint32_t *out_len)
Provision FONT.OTF if absent, then read it into s_font_buf.
static void internal_pc_setup_or_halt(uint32_t *out_pclka_hz)
Bring up clocks, timekeeping, console, and the SD SPI controller.
static void internal_pc_init_card_or_halt(uint32_t *pclka_hz)
Initialize the SD card over the configured SPI transport.
static const ra8_port_pin_t s_pc_pin_cipo
Pmod2 controller-input/peripheral-output pin.
static const char s_pc_body[]
Fixed HTML chapter used by the live and cached layout passes.
static void internal_pc_invalidate_check_or_halt(uint32_t font_len, size_t n)
Verify that a font-size change invalidates the persisted cache.
volatile uint32_t g_pc_err
First failing stage (pc_err_t), 0 on success.
static const ra8_port_pin_t s_pc_pin_cs
GPIO-driven active-low SD-card chip-select pin.
static void internal_pc_live_layout_or_halt(uint32_t font_len, size_t *out_n)
Lay out the chapter live and serialise it into s_live_blob.
static void internal_pc_persist_and_verify_or_halt(ra8_fs_mount_t *mount, size_t n)
Persist the live cache blob and verify an exact read-back.
volatile uint32_t g_pc_cache_crc
CRC-32 of the reloaded-then-reserialised blob.
volatile uint32_t g_pc_hit
1 if the cache file existed at boot (reset-survival hit).
volatile uint32_t g_pc_pages
Page count produced by the live layout.
Declaration of the Latin-1 Literata font baked into internal flash.
const unsigned int g_ra8_font_literata_latin1_len
Length of g_ra8_font_literata_latin1 in bytes.
const unsigned char g_ra8_font_literata_latin1[]
Baked Latin-1 subset of Literata Regular (TrueType/glyf), in flash.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
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.
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_invalid_state
Module in wrong state for requested operation.
@ 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_format(const ra8_fs_backend_t *backend, const ra8_fs_format_opts_t *opts)
Format a block device as a fresh, empty FAT12/FAT16/FAT32/exFAT volume.
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_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.
ra8_err_t ra8_fs_write_file(ra8_fs_mount_t *handle, const char *path, const uint8_t *data, uint32_t len)
Create a whole file in one call (provisioning helper).
@ k_ra8_fs_type_fat32
count_of_clusters >= 65525.
@ k_ra8_fs_mode_read
Read-only, must exist.
@ k_ra8_psel_sci_async
00100b: SCI async serial (UART).
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.
@ k_ra8_level_high
Drive or read 1.
@ k_ra8_level_low
Drive or read 0.
High-level GPIO helpers on top of the PORT + PFS register layer.
ra8_err_t ra8_gpio_output_init(ra8_port_pin_t pin, ra8_level_t init_level)
Configure a pin as a digital output and drive it to an initial level.
ra8_err_t ra8_gpio_write(ra8_port_pin_t pin, ra8_level_t level)
Drive a previously-configured output to the given level.
ra8_err_t ra8_pfs_route_peripheral(ra8_port_pin_t pin, ra8_psel_t psel, const char *owner)
Route a pin to a non-IRQ peripheral function via PFS.PSEL.
SCI Simple-SPI controller-mode driver (polling, full-duplex).
ra8_err_t ra8_sci_spi_set_clock(uint8_t channel, uint32_t baud_hz, uint32_t pclk_hz)
Re-program the bit-rate without otherwise reconfiguring.
ra8_err_t ra8_sci_spi_xfer(uint8_t channel, const uint8_t *tx, uint8_t *rx, uint32_t len)
Full-duplex multi-byte transfer.
ra8_err_t ra8_sci_spi_init(uint8_t channel, const ra8_sci_spi_cfg_t *cfg)
Bring an SCI channel up as a Simple-SPI controller.
SD card driver in SPI-mode (PMOD-attached cards).
@ k_ra8_sdmmc_spi_clock_init_hz
Mandatory init clock floor.
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.
SPI_B controller driver (RA8D2 Type-B SPI peripheral).
@ k_ra8_spi_mode_0
CPOL=0, CPHA=0.
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.
void ra8_delay_ms(uint32_t ms)
Busy-wait for at least ms milliseconds.
HTML / CSS reflow + paginate engine for the ra8d2 ereader.
ra8_err_t reflow_layout_chapter(reflow_t *engine, const uint8_t *xhtml_buf, size_t xhtml_len, uint32_t *out_total_pages)
Parse + lay out one chapter of XHTML.
ra8_err_t reflow_init(uint16_t viewport_w, uint16_t viewport_h, const uint8_t *font_data, size_t font_len, uint16_t font_px, uint32_t body_color, uint32_t link_color, reflow_t *out_engine)
Initialise a reflow engine for a given viewport / font.
Import-time pagination cache for reflow (#79).
ra8_err_t reflow_cache_serialize(const reflow_t *engine, const uint8_t *content, size_t content_len, uint8_t *out_buf, size_t out_cap, size_t *out_len)
Serialise the laid-out pages of engine into a keyed byte blob.
ra8_err_t reflow_cache_load(reflow_t *engine, const uint8_t *content, size_t content_len, const uint8_t *buf, size_t len)
Validate a cache blob and, if it matches, restore the layout.
Block-device interface that ra8_fs runs on top of.
Cached parse of one mounted FAT volume.
Configuration descriptor for ra8_sci_spi_init.
Driver-to-bus binding (Dependency Inversion seam).
Reflow / pagination engine state.