|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
End-to-end on-import EPUB -> .rabook compile + cache + read (#151). More...
#include <stddef.h>#include <stdint.h>#include "book.h"#include "epub.h"#include "ra8_board_ek_ra8d2.h"#include "ra8_boot_entry.h"#include "ra8_cgc.h"#include "ra8_err.h"#include "ra8_fs.h"#include "ra8_isr.h"#include "ra8_log.h"#include "ra8_rabook_pipeline.h"#include "ra8_sdmmc_spi.h"#include "ra8_time.h"#include "ra8_vmem.h"#include "rabook_compile.h"#include "rabook_import.h"#include "rabook_import_compiler.h"Go to the source code of this file.
Macros | |
| #define | IMP_PUTS(lit) |
| Emit a NUL-terminated literal (length via sizeof at the call site). | |
Enumerations | |
| enum | imp_config_t : uint32_t { k_imp_uart_baud = 115200U , k_imp_spi_channel = 0U , k_imp_format_version = 1U , k_imp_importer_version = 1U , k_imp_scratch_cap = 4096U , k_imp_path_cap = 16U , k_imp_dec_base = 10U , k_imp_str_max = 256U } |
| Compile-time settings for the on-import compile + cache + read demo. More... | |
| enum | imp_buf_cap_t : uint32_t { k_imp_cache_frame_bytes = 4096U , k_imp_cache_frames = 64U , k_imp_cache_buckets = 128U , k_imp_chapter_cap = 32U , k_imp_node_cap = 2048U , k_imp_attr_cap = 512U , k_imp_style_cap = 16U , k_imp_image_cap = 32U , k_imp_string_cap = 64U * 1024U , k_imp_imgpool_cap = 1024U * 1024U , k_imp_out_cap = 512U * 1024U , k_imp_xhtml_cap = 64U * 1024U , k_imp_css_cap = 16U * 1024U , k_imp_imgraw_cap = 2U * 1024U * 1024U , k_imp_arena_cap = 4U * 1024U * 1024U , k_imp_gray_cap = 2U * 1024U * 1024U , k_imp_readback_cap = 512U * 1024U } |
| SDRAM working-arena capacities (sized for a small text book). More... | |
Functions | |
| static void | imp_print (const uint8_t *msg, uint32_t len) |
| Write a byte run on the J-Link OB console. | |
| static void | imp_print_cstr (const char *str) |
| Emit a NUL-terminated C-string, bounded to k_imp_str_max bytes. | |
| static void | imp_print_uint (uint32_t value) |
| Print a small unsigned integer in decimal. | |
| static void | imp_panic (const char *stage) |
| Print the FAIL banner with a stage tag, then trap and park. | |
| static void | imp_setup_or_halt (uint32_t *out_pclka_hz) |
| Bring up CGC + SysTick + console SCI; panic on failure. | |
| static void | imp_init_card_or_halt (uint32_t pclka_hz) |
| Build the SCI-SPI transport, run SD identification; panic on failure. | |
| 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 void | imp_build_cookie (void) |
| Populate the builder/scratch views + the production compile cookie. | |
| static rabook_import_cfg_t | imp_make_cfg (ra8_fs_mount_t *mount) |
| Build the import config that injects the production compile adapter. | |
| 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 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 void | imp_run (ra8_fs_mount_t *mount) |
| Run the import twice (miss then hit), confirm the cache, read + walk. | |
| void | main (void) |
| App entry: bring up the SD card, mount, import + cache + read, PASS. | |
Variables | |
| static const ra8_port_pin_t | k_imp_pin_sck = (ra8_port_pin_t)k_ra8_board_pmod2_spi_sck |
| Pmod2 SPI pins (J25) – SCI0 Simple-SPI; CS held by GPIO. | |
| static const ra8_port_pin_t | k_imp_pin_cipo = (ra8_port_pin_t)k_ra8_board_pmod2_spi_cipo |
| static const ra8_port_pin_t | k_imp_pin_copi = (ra8_port_pin_t)k_ra8_board_pmod2_spi_copi |
| static const ra8_port_pin_t | k_imp_pin_cs = (ra8_port_pin_t)k_ra8_board_pmod2_spi_cs |
| static const char | k_imp_epub_path [] = "BOOK.EPB" |
| Root-level 8.3 source name the appliance imports. | |
| static uint8_t | s_imp_scratch [k_imp_scratch_cap] |
| Streaming CRC chunk for the source-key pass. | |
| 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 ra8_vmem_frame_t | s_imp_cache_meta [k_imp_cache_frames] |
| Per-frame metadata for the source page cache. | |
| static ra8_vmem_key_t | s_imp_cache_keys [k_imp_cache_frames] |
| Per-frame key storage for the source page cache. | |
| static int32_t | s_imp_cache_buckets [k_imp_cache_buckets] |
| Hash-bucket heads for the source page cache. | |
| static ra8_vmem_t | s_imp_cache |
| Source page cache; re-initialised by the adapter per compile. | |
| static epub_book_t | s_imp_epub |
| Open-book storage owned across the compile. | |
| 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 book_attr_t | s_imp_attrs [k_imp_attr_cap] |
| static book_stylesheet_t | s_imp_styles [k_imp_style_cap] |
| static book_image_t | s_imp_images [k_imp_image_cap] |
| static char | s_imp_strpool [k_imp_string_cap] |
| static uint8_t | s_imp_imgpool [k_imp_imgpool_cap] |
| static uint8_t | s_imp_out [k_imp_out_cap] |
| static uint8_t | s_imp_xhtml [k_imp_xhtml_cap] |
| Pipeline scratch (XHTML load + stylesheet load + image decode + gray downscale). | |
| static ra8_rabook_xml_workspace_t | s_imp_xml_workspace |
| static uint8_t | s_imp_image_raw [k_imp_imgraw_cap] |
| static uint8_t | s_imp_img_scratch [k_imp_arena_cap] |
| static uint8_t | s_imp_gray [k_imp_gray_cap] |
| static char | s_imp_css [k_imp_css_cap] |
| static uint8_t | s_imp_readback [k_imp_readback_cap] |
| Cached-.rabook read-back buffer (4-byte aligned for the accessors). | |
| static const uint8_t | k_msg_boot [] = "import_reader: boot\r\n" |
| static const uint8_t | k_msg_card_ok [] = "import_reader: card ready\r\n" |
| static const uint8_t | k_msg_mounted [] = "import_reader: volume mounted\r\n" |
| static const uint8_t | k_msg_miss [] = "import_reader: first open MISS -> compiled, cache=" |
| static const uint8_t | k_msg_hit [] = "import_reader: second open HIT (no recompile), cache=" |
| static const uint8_t | k_msg_cbytes [] = "import_reader: cache bytes=" |
| static const uint8_t | k_msg_title [] = "import_reader: title=" |
| static const uint8_t | k_msg_chaps [] = " chapters=" |
| static const uint8_t | k_msg_ch [] = "import_reader: ch" |
| static const uint8_t | k_msg_textlen [] = " textlen=" |
| static const uint8_t | k_msg_eol [] = "\r\n" |
| static const uint8_t | k_msg_pass [] = "import_reader: miss->compile->cache->hit->read PASS\r\n" |
| static const uint8_t | k_msg_fail [] = "import_reader: FAIL " |
| static ra8_rabook_buffers_t | s_imp_bufs |
| Builder arenas, pipeline scratch, stb arena, and the compiler cookie. | |
| static ra8_rabook_pipeline_scratch_t | s_imp_scr |
| static ra8_img_arena_t | s_imp_arena |
| static rabook_import_compiler_ctx_t | s_imp_cookie |
End-to-end on-import EPUB -> .rabook compile + cache + read (#151).
The on-silicon proof of the self-contained-appliance flow specified in issue #151: drop a raw .epub on the SD card and the device "just works." This app mounts a FAT volume on a micro-SD over ra8_sdmmc_spi, then drives the rabook_import cache manager wired to its PRODUCTION compile adapter (rabook_import_compile_adapter, which STREAMS the source through a bounded ra8_vmem page cache – no whole-file load buffer, #230 – into rabook_compile_from_epub):
On success it prints exactly import_reader: miss->compile->cache->hit->read PASS; any failed step prints import_reader: FAIL <stage> and parks the core. The ra8_emulator headless gate (and a future HIL runner) scrape for that PASS line.
Required external hardware (on-bench): Digilent PMOD MicroSD (part 410-380) in Pmod2 (J25) with a microSD card carrying a BOOK.EPB text EPUB. Under ra8_emulator attach an image with --sd <image> (build one with tools/mkfontimg <book.epub> card.img BOOK.EPB).
Definition in file main.c.
| #define IMP_PUTS | ( | lit | ) |
Emit a NUL-terminated literal (length via sizeof at the call site).
Definition at line 225 of file main.c.
Referenced by imp_init_card_or_halt(), imp_mount_or_halt(), imp_panic(), imp_run(), imp_walk_book(), and main().
| enum imp_buf_cap_t : uint32_t |
SDRAM working-arena capacities (sized for a small text book).
| enum imp_config_t : uint32_t |
Compile-time settings for the on-import compile + cache + read demo.
|
static |
Populate the builder/scratch views + the production compile cookie.
Binds every caller-owned SDRAM arena into the views the real compiler needs and the cookie the import adapter forwards – including the fixed source page-cache storage the adapter streams the .epub through (#230). No buffer is aliased: image_raw is distinct from the img_arena / gray source the transcode stage reads (a contract
Definition at line 417 of file main.c.
References k_imp_attr_cap, k_imp_cache_buckets, k_imp_cache_frame_bytes, k_imp_cache_frames, k_imp_chapter_cap, k_imp_gray_cap, k_imp_image_cap, k_imp_imgpool_cap, k_imp_node_cap, k_imp_out_cap, k_imp_string_cap, k_imp_style_cap, s_imp_arena, s_imp_attrs, s_imp_bufs, s_imp_cache, s_imp_cache_buckets, s_imp_cache_frames, s_imp_cache_keys, s_imp_cache_meta, s_imp_chapters, s_imp_cookie, s_imp_css, s_imp_epub, s_imp_gray, s_imp_image_raw, s_imp_images, s_imp_img_scratch, s_imp_imgpool, s_imp_nodes, s_imp_out, s_imp_scr, s_imp_strpool, s_imp_styles, s_imp_xhtml, and s_imp_xml_workspace.
Referenced by main().
|
static |
Build the SCI-SPI transport, run SD identification; panic on failure.
| [in] | pclka_hz | Live PCLKA rate (Hz) feeding the SCI baud divider. |
pclka_hz is the live PCLKA rate. Definition at line 346 of file main.c.
References imp_panic(), IMP_PUTS, k_imp_pin_cipo, k_imp_pin_copi, k_imp_pin_cs, k_imp_pin_sck, k_imp_spi_channel, k_msg_card_ok, k_ra8_ok, ra8_sdmmc_spi_init(), and ra8_sdmmc_spi_transport_sci().
Referenced by main().
|
static |
Build the import config that injects the production compile adapter.
| [in] | mount | Mounted volume holding the source and the cache. |
mount is a live mount. Definition at line 477 of file main.c.
References rabook_import_cfg_t::compile, rabook_import_cfg_t::compile_ctx, rabook_import_cfg_t::format_version, rabook_import_cfg_t::importer_version, k_imp_format_version, k_imp_importer_version, k_imp_scratch_cap, rabook_import_cfg_t::mount, rabook_import_compile_adapter(), s_imp_cookie, s_imp_scratch, rabook_import_cfg_t::scratch, and rabook_import_cfg_t::scratch_cap.
Referenced by imp_run().
|
static |
Bind the SD-over-SPI block device into ra8_fs and mount the volume.
| [out] | out_mount | Receives the mounted-volume handle on success. |
out_mount is writable. Definition at line 377 of file main.c.
References imp_panic(), IMP_PUTS, k_msg_mounted, k_ra8_ok, ra8_fs_mount(), and ra8_sdmmc_spi_bind_fs_backend().
Referenced by main().
|
static |
Print the FAIL banner with a stage tag, then trap and park.
| [in] | stage | NUL-terminated stage label (non-NULL). |
stage is NUL-terminated. Definition at line 285 of file main.c.
References imp_print(), imp_print_cstr(), IMP_PUTS, k_msg_eol, k_msg_fail, and ra8_board_uart_console_flush().
Referenced by imp_init_card_or_halt(), imp_mount_or_halt(), imp_run(), and imp_setup_or_halt().
|
static |
Write a byte run on the J-Link OB console.
| [in] | msg | Bytes to emit (non-NULL, length len). |
| [in] | len | Byte count to emit. |
msg points to at least len readable bytes. Definition at line 219 of file main.c.
References ra8_board_uart_console_write().
Referenced by imp_panic(), imp_print_cstr(), imp_print_uint(), imp_run(), and imp_walk_book().
|
static |
Emit a NUL-terminated C-string, bounded to k_imp_str_max bytes.
| [in] | str | NUL-terminated string to emit (non-NULL). |
str is NUL-terminated. Definition at line 237 of file main.c.
References imp_print(), and k_imp_str_max.
Referenced by imp_panic(), imp_run(), and imp_walk_book().
|
static |
Print a small unsigned integer in decimal.
| [in] | value | Value to print (0 .. UINT32_MAX). |
value fits a uint32_t (always true). Definition at line 256 of file main.c.
References imp_print(), and k_imp_dec_base.
Referenced by imp_run(), and imp_walk_book().
|
staticnodiscard |
Read the whole cached .rabook at path into s_imp_readback.
| [in] | mount | Mounted volume. |
| [in] | path | Root-level cache path (non-NULL). |
| [out] | out_len | Receives the byte length read. |
| k_ra8_ok | The cache was read fully into the buffer. |
| k_ra8_err_no_mem | The cache is larger than the read-back buffer. |
| k_ra8_err_* | An ra8_fs open/size/read failure. |
mount is mounted and path names a present cache file. out_len is writable. Definition at line 512 of file main.c.
References k_ra8_err_no_mem, k_ra8_fs_mode_read, k_ra8_ok, ra8_fs_close(), ra8_fs_open(), ra8_fs_read(), ra8_fs_size(), and s_imp_readback.
Referenced by imp_run().
|
static |
Run the import twice (miss then hit), confirm the cache, read + walk.
| [in] | mount | Mounted volume carrying the source .epub. |
mount is mounted and carries k_imp_epub_path. Definition at line 598 of file main.c.
References imp_make_cfg(), imp_panic(), imp_print(), imp_print_cstr(), imp_print_uint(), IMP_PUTS, imp_read_cache(), imp_walk_book(), k_imp_epub_path, k_imp_path_cap, k_msg_cbytes, k_msg_eol, k_msg_hit, k_msg_miss, k_ra8_ok, k_rabook_import_compiled, k_rabook_import_hit, and rabook_import_open().
Referenced by main().
|
static |
Bring up CGC + SysTick + console SCI; panic on failure.
| [out] | out_pclka_hz | Cached PCLKA rate (Hz) for the SD transport factory. |
out_pclka_hz is writable. Definition at line 313 of file main.c.
References imp_panic(), k_imp_uart_baud, k_ra8_clock_id_cpuclk0, k_ra8_clock_id_pclka, k_ra8_ok, ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), and ra8_time_init().
Referenced by main().
|
staticnodiscard |
Validate the cached blob and log its title, chapter count, and the plain-text length of every chapter.
| [in] | len | Byte length of the blob in s_imp_readback. |
| k_ra8_ok | Blob validated and walked. |
| k_ra8_err_* | book_validate / per-chapter walk error. |
len is the true readable length. Definition at line 553 of file main.c.
References book_chapter_text(), book_header(), book_string(), book_validate(), book_header_t::chapter_count, imp_print(), imp_print_cstr(), imp_print_uint(), IMP_PUTS, k_msg_ch, k_msg_chaps, k_msg_eol, k_msg_textlen, k_msg_title, k_ra8_ok, s_imp_readback, s_imp_xhtml, and book_header_t::title_off.
Referenced by imp_run().
| void main | ( | void | ) |
App entry: bring up the SD card, mount, import + cache + read, PASS.
The application entry point Reset_Handler hands control to.
Definition at line 659 of file main.c.
References imp_build_cookie(), imp_init_card_or_halt(), imp_mount_or_halt(), IMP_PUTS, imp_run(), imp_setup_or_halt(), k_msg_boot, k_msg_pass, ra8_board_uart_console_flush(), ra8_isr_globals_enable(), and ra8_log_init().
|
static |
|
static |
Definition at line 126 of file main.c.
Referenced by imp_init_card_or_halt().
|
static |
Definition at line 127 of file main.c.
Referenced by imp_init_card_or_halt().
|
static |
Definition at line 128 of file main.c.
Referenced by imp_init_card_or_halt().
|
static |
Pmod2 SPI pins (J25) – SCI0 Simple-SPI; CS held by GPIO.
Definition at line 125 of file main.c.
Referenced by imp_init_card_or_halt().
|
static |
|
static |
Definition at line 190 of file main.c.
Referenced by fs_fmt_init_card_or_halt(), imp_init_card_or_halt(), sdhi_card_init_or_halt(), and sdhi_demo_init_card_or_halt().
|
static |
|
static |
Definition at line 197 of file main.c.
Referenced by erb_render_chapter(), and imp_walk_book().
|
static |
Definition at line 196 of file main.c.
Referenced by imp_walk_book().
|
static |
|
static |
|
static |
Definition at line 191 of file main.c.
Referenced by imp_mount_or_halt().
|
static |
|
static |
Definition at line 198 of file main.c.
Referenced by imp_walk_book().
|
static |
Definition at line 195 of file main.c.
Referenced by imp_walk_book().
|
static |
Definition at line 397 of file main.c.
Referenced by imp_build_cookie().
|
static |
Definition at line 164 of file main.c.
Referenced by imp_build_cookie().
|
static |
Builder arenas, pipeline scratch, stb arena, and the compiler cookie.
Definition at line 395 of file main.c.
Referenced by imp_build_cookie().
|
static |
Source page cache; re-initialised by the adapter per compile.
Definition at line 155 of file main.c.
Referenced by imp_build_cookie().
|
static |
Hash-bucket heads for the source page cache.
Definition at line 152 of file main.c.
Referenced by imp_build_cookie().
|
static |
Fixed frame pool the streamed source is paged through (#230).
Definition at line 143 of file main.c.
Referenced by imp_build_cookie().
|
static |
Per-frame key storage for the source page cache.
Definition at line 149 of file main.c.
Referenced by imp_build_cookie().
|
static |
Per-frame metadata for the source page cache.
Definition at line 146 of file main.c.
Referenced by imp_build_cookie().
|
static |
RABOOK1 builder arenas (one per table + the two pools + output).
Definition at line 162 of file main.c.
Referenced by imp_build_cookie().
|
static |
Definition at line 398 of file main.c.
Referenced by imp_build_cookie(), and imp_make_cfg().
|
static |
Definition at line 179 of file main.c.
Referenced by imp_build_cookie().
|
static |
Open-book storage owned across the compile.
Definition at line 158 of file main.c.
Referenced by imp_build_cookie().
|
static |
Definition at line 178 of file main.c.
Referenced by imp_build_cookie().
|
static |
Definition at line 176 of file main.c.
Referenced by imp_build_cookie().
|
static |
Definition at line 167 of file main.c.
Referenced by imp_build_cookie().
|
static |
Definition at line 177 of file main.c.
Referenced by imp_build_cookie().
|
static |
Definition at line 169 of file main.c.
Referenced by imp_build_cookie().
|
static |
Definition at line 163 of file main.c.
Referenced by imp_build_cookie().
|
static |
Definition at line 170 of file main.c.
Referenced by imp_build_cookie().
|
static |
Cached-.rabook read-back buffer (4-byte aligned for the accessors).
Definition at line 182 of file main.c.
Referenced by imp_read_cache(), and imp_walk_book().
|
static |
Definition at line 396 of file main.c.
Referenced by imp_build_cookie().
|
static |
Streaming CRC chunk for the source-key pass.
Definition at line 139 of file main.c.
Referenced by imp_make_cfg().
|
static |
Definition at line 168 of file main.c.
Referenced by imp_build_cookie().
|
static |
Definition at line 166 of file main.c.
Referenced by imp_build_cookie().
|
static |
Pipeline scratch (XHTML load + stylesheet load + image decode + gray downscale).
Definition at line 173 of file main.c.
Referenced by imp_build_cookie(), and imp_walk_book().
|
static |
Definition at line 175 of file main.c.
Referenced by imp_build_cookie().