62typedef enum : uint32_t {
74typedef enum : uint32_t {
101typedef enum : uint32_t {
113typedef enum : uint32_t {
148static const uint8_t
k_msg_fprov[] =
"toc-hil: FAIL provision\r\n";
152static const uint8_t
k_msg_ok[] =
"toc-hil: ncx+nav+fallback PASS\r\n";
167static void etoc_fail(uint32_t err,
const uint8_t* msg, uint32_t len)
172 __asm__
volatile(
"wfi");
180 for (
size_t i = 0U; i < len; i++) {
181 crc ^= (uint32_t)data[i];
183 const uint32_t mask = (uint32_t)(-(int32_t)(crc & 1U));
197 return etoc_crc32((
const uint8_t*)title, len);
205 const uint32_t pclka_hz = *(
const uint32_t*)ctx;
244 uint32_t cpuclk0_hz = 0U;
245 uint32_t pclka_hz = 0U;
265 *out_pclka_hz = pclka_hz;
291 opts.
label =
"RAEPUB";
340 volatile uint32_t* kind,
341 volatile uint32_t* count,
342 volatile uint32_t* e0crc,
343 volatile uint32_t* ch0)
355 *count = (uint32_t)n;
366 *ch0 = (uint32_t)chap;
449 uint32_t pclka_hz = 0U;
void main(void)
Secure fallback main entry point.
EPUB (.epub) reader and chapter iterator for ra8-firmware.
ra8_err_t epub_toc_entry_to_chapter(const epub_book_t *book, uint16_t toc_idx, uint16_t *out_chapter_idx)
Resolve a TOC entry to the spine chapter index it points into.
ra8_err_t epub_get_toc_kind(const epub_book_t *book, uint8_t *out_kind)
Report which navigation document the TOC was parsed from.
ra8_err_t epub_get_toc_entry(const epub_book_t *book, uint16_t idx, epub_toc_entry_t *out_entry)
Copy one table-of-contents entry into the caller's struct.
ra8_err_t epub_get_chapter_count(const epub_book_t *book, uint16_t *out_count)
Report how many chapters the spine contains.
ra8_err_t epub_get_toc_count(const epub_book_t *book, uint16_t *out_count)
Report how many table-of-contents entries the book exposes.
ra8_fs -> epub bridge: open a .epub straight off a filesystem.
ra8_err_t epub_open_streamed_fs(ra8_fs_mount_t *mount, const char *path, epub_stream_fs_ctx_t *io, epub_book_t *out_book)
Stream-open an EPUB directly off a mounted ra8_fs volume, no residency (#151).
ra8_err_t epub_close_streamed_fs(epub_stream_fs_ctx_t *io, epub_book_t *book)
Close a book opened by epub_open_streamed_fs() and its source file.
Baked EPUB TOC fixtures for epub_toc (#116).
@ k_etoc_bad_len
Etoc bad length.
@ k_etoc_nav_len
Etoc nav length.
@ k_etoc_ncx_len
Etoc ncx length.
static const uint8_t k_etoc_bad[k_etoc_bad_len]
static const uint8_t k_etoc_nav[k_etoc_nav_len]
static const uint8_t k_etoc_ncx[k_etoc_ncx_len]
static const uint8_t k_msg_fcard[]
static epub_book_t s_book
Opened book (large – file-scope, not on the stack).
static const uint8_t k_msg_cardok[]
static const uint8_t k_msg_ok[]
static ra8_fs_backend_t s_backend
SD backend; file-scope so the mount handle may reference it.
static const uint8_t k_msg_fprov[]
static epub_stream_fs_ctx_t s_epub_io
Streamed-open source-file context; must outlive s_book (#230).
static const uint8_t k_msg_boot[]
static const uint8_t k_msg_finit[]
static const uint8_t k_msg_fmount[]
static const char k_etoc_path_ncx[]
SD paths for the three baked books (8.3 short names; ra8_fs root-only).
static const ra8_port_pin_t k_etoc_pin_cipo
volatile uint32_t g_etoc_bad_chap
malformed-TOC spine fallback.
static const ra8_port_pin_t k_etoc_pin_copi
static const char k_etoc_path_nav[]
etoc_expect_t
Byte-exact expected TOC results (host-verified).
@ k_etoc_entry0
Entry-0 -> spine index 0.
@ k_etoc_ncx_crc
crc32("Intro").
@ k_etoc_exp_chap
Spine length in every fixture.
@ k_etoc_ncx_kind
k_epub_toc_ncx.
@ k_etoc_bad_kind
k_epub_toc_none (no TOC doc).
@ k_etoc_nav_count
nav <ol> entries.
@ k_etoc_nav_crc
crc32("Cover").
@ k_etoc_nav_kind
k_epub_toc_nav.
@ k_etoc_ncx_count
navMap navPoints.
volatile uint32_t g_etoc_ncx_n
NCX toc_count on success.
static const ra8_port_pin_t k_etoc_pin_sck
Pmod2 SPI pins (J25) – SCI0 Simple-SPI; CS held by GPIO.
static void etoc_fail(uint32_t err, const uint8_t *msg, uint32_t len)
Stamp the failure stage, print the FAIL banner, and park the CPU.
volatile uint32_t g_etoc_bad_kind
malformed-TOC kind (expect 0).
volatile uint32_t g_etoc_nav_ch0
nav entry-0 -> spine index.
volatile uint32_t g_etoc_ncx_e0crc
NCX entry-0 label CRC.
static const ra8_port_pin_t k_etoc_pin_cs
etoc_pace_t
Idle-loop pacing for the success heartbeat.
@ k_etoc_frame_ms
Heartbeat period in milliseconds.
static const uint8_t k_msg_fnav[]
static void etoc_check_ncx(ra8_fs_mount_t *mount)
Parse + assert the NCX (EPUB2) TOC; latch the result globals.
static void etoc_read_toc(ra8_fs_mount_t *mount, const char *path, uint32_t stage, const uint8_t *fmsg, uint32_t fmsglen, volatile uint32_t *kind, volatile uint32_t *count, volatile uint32_t *e0crc, volatile uint32_t *ch0)
Open one book off SD and read its TOC kind/count + entry-0 label CRC.
volatile uint32_t g_etoc_err
First failing stage (etoc_err_t), 0 on success.
static ra8_err_t etoc_spi_cs(void *ctx, bool asserted)
ra8_sdmmc_spi_transport_t::cs over ra8_gpio (CS active-low).
static const uint8_t k_msg_fbad[]
static const uint8_t k_msg_fncx[]
static void etoc_print(const uint8_t *msg, uint32_t len)
Emit a byte run on the SCI8 console.
static void etoc_check_bad(ra8_fs_mount_t *mount)
Assert the malformed-TOC fallback: no TOC, spine still readable.
volatile uint32_t g_etoc_ncx_kind
NCX toc_kind on success.
volatile uint32_t g_etoc_nav_e0crc
nav entry-0 label CRC.
static ra8_err_t etoc_spi_set_clock(void *ctx, uint32_t hz)
static ra8_err_t etoc_spi_pins_init(void)
Route Pmod2 SPI pins and claim CS as a GPIO output (idle high).
volatile uint32_t g_etoc_nav_kind
nav toc_kind on success.
etoc_consts_t
Console / SPI / parse knobs (no magic numbers).
@ k_etoc_spi_chan
Pmod2 / J25 SCI0 Simple-SPI.
@ k_etoc_crc_poly
CRC-32 reflected polynomial.
@ k_etoc_uart_baud
Console baud.
@ k_etoc_kind_unset
Sentinel: toc_kind not yet read.
@ k_etoc_crc_init
CRC-32 initial value.
@ k_etoc_no_chap
Sentinel: entry has no spine target.
@ k_etoc_crc_bits
Bits folded per byte.
@ k_etoc_title_max
Bounded title scan (NASA Rule 2).
static ra8_fs_mount_t * etoc_mount_or_halt(void)
Mount the card, formatting FAT32 first if it is blank/unmountable.
static void etoc_init_card_or_halt(uint32_t *pclka_hz)
Init the SD card over SPI; halt with a diagnostic on failure.
static ra8_err_t etoc_spi_xfer(void *ctx, const uint8_t *tx, uint8_t *rx, uint32_t len)
ra8_sdmmc_spi_transport_t::xfer over ra8_sci_spi_xfer.
static void etoc_check_nav(ra8_fs_mount_t *mount)
Parse + assert the nav (EPUB3) TOC; latch the result globals.
volatile uint32_t g_etoc_heartbeat
Idle heartbeat; advances ONLY after all asserts pass (the HIL gate).
static void etoc_provision_one(ra8_fs_mount_t *mount, const char *path, const uint8_t *data, uint32_t len)
Write one baked book onto the volume if path is absent.
static void etoc_provision_or_halt(ra8_fs_mount_t *mount)
Provision all three baked TOC fixtures onto the card.
static uint32_t etoc_title_crc(const char *title)
CRC-32 over a null-terminated title (bounded by k_etoc_title_max).
etoc_err_t
Failure-stage codes stamped to g_etoc_err for SWD / --dump-sym.
@ k_etoc_err_mount
Mount (and format-if-blank).
@ k_etoc_err_nav
nav (EPUB3) TOC assertion.
@ k_etoc_err_ncx
NCX (EPUB2) TOC assertion.
@ k_etoc_err_bad
Malformed-TOC fallback assertion.
@ k_etoc_err_none
No failure (success path).
@ k_etoc_err_init
CGC / time / console / SPI bring-up.
@ k_etoc_err_prov
Provision a .epub onto the card.
@ k_etoc_err_card
SD card SPI init.
static const char k_etoc_path_bad[]
static uint32_t etoc_crc32(const uint8_t *data, size_t len)
CRC-32 (reflected, poly 0xEDB88320) over data.
static void etoc_setup_or_halt(uint32_t *out_pclka_hz)
Bring up CGC + SysTick + console SCI + SPI + CS GPIO; halt on fail.
volatile uint32_t g_etoc_ncx_ch0
NCX entry-0 -> spine index.
volatile uint32_t g_etoc_nav_n
nav toc_count on success.
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_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.
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_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.
Typed Port / Pin Constants for the RA8D2 IOPORT Module.
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.
Backing state for a streamed ra8_fs EPUB open (#151).
One titled entry in the table of contents.
char title[k_epub_meta_len]
Navigation label text ("" if none).
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).