53#include "epub_fixture.h"
69typedef enum : uint32_t {
100typedef enum : uint32_t {
114typedef enum : uint32_t {
140static const uint8_t
k_msg_boot[] =
"epub-open-hil: boot\r\n";
145static const uint8_t
k_msg_fprov[] =
"epub-hil: FAIL provision\r\n";
147static const uint8_t
k_msg_fchap[] =
"epub-hil: FAIL chapters\r\n";
151static const uint8_t
k_msg_pre[] =
"epub-hil: chapters=";
173static void eoh_fail(uint32_t err,
const uint8_t* msg, uint32_t len)
178 __asm__
volatile(
"wfi");
183static uint32_t
eoh_crc32(
const uint8_t* data,
size_t len)
186 for (
size_t i = 0U; i < len; i++) {
187 crc ^= (uint32_t)data[i];
189 const uint32_t mask = (uint32_t)(-(int32_t)(crc & 1U));
223 for (uint32_t i = 0U; i < n; i++) {
233 const uint32_t pclka_hz = *(
const uint32_t*)ctx;
272 uint32_t cpuclk0_hz = 0U;
273 uint32_t pclka_hz = 0U;
291 *out_pclka_hz = pclka_hz;
325 opts.
label =
"RAEPUB";
360 uint16_t chapters = 0U;
376 (meta.
title[0] ==
'\0')) {
395 uint32_t pclka_hz = 0U;
405 uint32_t ch0_crc = 0U;
void main(void)
Secure fallback main entry point.
EPUB (.epub) reader and chapter iterator for ra8-firmware.
ra8_err_t epub_get_metadata(const epub_book_t *book, epub_metadata_t *out_meta)
Return Dublin Core metadata strings.
ra8_err_t epub_load_chapter(epub_book_t *book, uint16_t idx, uint8_t *out_xhtml, size_t max_len, size_t *got_len)
Extract the raw XHTML bytes of one chapter into the caller's buffer.
ra8_err_t epub_get_chapter_count(const epub_book_t *book, uint16_t *out_count)
Report how many chapters the spine contains.
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).
static const uint8_t k_epub_fixture[k_epub_fixture_len]
Baked seed_two_chapters.epub byte stream.
@ k_epub_fixture_len
EPUB fixture length.
static const uint8_t k_msg_fcard[]
static void eoh_print_hex(uint32_t value)
Print a 32-bit value as 8 upper-case hex digits.
static epub_book_t s_book
Opened book (large – file-scope, not on the stack).
static const ra8_port_pin_t k_eoh_pin_cipo
static const uint8_t k_msg_pre[]
static void eoh_init_card_or_halt(uint32_t *pclka_hz)
Init the SD card over SPI; halt with a diagnostic on failure.
static ra8_err_t eoh_spi_pins_init(void)
Route Pmod2 SPI pins and claim CS as a GPIO output (idle high).
volatile uint32_t g_eoh_heartbeat
Idle heartbeat; advances ONLY after a clean parse (the HIL gate).
volatile uint32_t g_eoh_chapters
Parsed chapter (spine) count on success; 0 otherwise.
static ra8_err_t eoh_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 const uint8_t k_msg_cardok[]
static uint32_t eoh_crc32(const uint8_t *data, size_t len)
CRC-32 (reflected, poly 0xEDB88320) over data.
static void eoh_provision_or_halt(ra8_fs_mount_t *mount)
Write the baked .epub onto the volume if k_eoh_book_path absent.
static ra8_fs_mount_t * eoh_mount_or_halt(void)
Mount the card, formatting FAT32 first if it is blank/unmountable.
static const uint8_t k_msg_ok[]
eoh_consts_t
Console / SPI / parse knobs (no magic numbers).
@ k_eoh_chap_cap
Chapter XHTML scratch capacity.
@ k_eoh_expect_crc
Chapter-0 XHTML CRC-32 (seed).
@ k_eoh_crc_bits
Bits folded per byte.
@ k_eoh_crc_poly
CRC-32 reflected polynomial.
@ k_eoh_hex_nibbles
Hex digits in a 32-bit value.
@ k_eoh_spi_chan
Pmod2 / J25 SCI0 Simple-SPI.
@ k_eoh_crc_init
CRC-32 initial value.
@ k_eoh_uart_baud
Console baud.
@ k_eoh_expect_chap
Spine length of the baked seed.
@ k_eoh_nibble_bits
Bits per hex nibble.
@ k_eoh_nibble_mask
Low-nibble mask.
@ k_eoh_dec_ten
Hex digit / decimal split.
static ra8_fs_backend_t s_backend
SD backend; file-scope so the mount handle may reference it.
static const uint8_t k_msg_fopen[]
static const uint8_t k_msg_fprov[]
static const char k_eoh_book_path[]
Book path on the SD volume (8.3 short name; ra8_fs is root-only).
static void eoh_setup_or_halt(uint32_t *out_pclka_hz)
Bring up CGC + SysTick + console SCI + SPI + CS GPIO; halt on fail.
static const ra8_port_pin_t k_eoh_pin_copi
static const uint8_t k_msg_crc[]
static void eoh_print_uint(uint32_t value)
Print a small unsigned integer in decimal.
static void eoh_print(const uint8_t *msg, uint32_t len)
Emit a byte run on the SCI8 console.
static const ra8_port_pin_t k_eoh_pin_sck
Pmod2 SPI pins (J25) – SCI0 Simple-SPI; CS held by GPIO.
static ra8_err_t eoh_spi_set_clock(void *ctx, uint32_t hz)
static const uint8_t k_msg_fload[]
volatile uint32_t g_eoh_crc
Chapter-0 decompressed-XHTML CRC-32 on success; 0 otherwise.
static const uint8_t k_msg_fchap[]
static const uint8_t k_msg_fmeta[]
volatile uint32_t g_eoh_err
First failing stage (eoh_err_t), 0 on success.
static uint16_t eoh_parse_or_halt(ra8_fs_mount_t *mount, uint32_t *out_crc)
Open the provisioned .epub off SD, verify the spine, CRC chapter 0.
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[]
eoh_pace_t
Idle-loop pacing for the success heartbeat.
@ k_eoh_frame_ms
Heartbeat period in milliseconds.
static const uint8_t k_msg_finit[]
static ra8_err_t eoh_spi_cs(void *ctx, bool asserted)
ra8_sdmmc_spi_transport_t::cs over ra8_gpio (CS active-low).
static const uint8_t k_msg_fcrc[]
static const uint8_t k_msg_fmount[]
static uint8_t s_chapter[k_eoh_chap_cap]
Chapter-0 XHTML scratch (file-scope to keep the stack small).
eoh_err_t
Failure-stage codes stamped to g_eoh_err for SWD / --dump-sym.
@ k_eoh_err_mount
Mount (and format-if-blank).
@ k_eoh_err_none
No failure (success path).
@ k_eoh_err_meta
Metadata parse / empty title.
@ k_eoh_err_init
CGC / time / console / SPI bring-up.
@ k_eoh_err_prov
Provision the .epub onto the card.
@ k_eoh_err_chap
Chapter-count mismatch.
@ k_eoh_err_card
SD card SPI init.
@ k_eoh_err_open
epub_open_streamed_fs.
@ k_eoh_err_load
Chapter-0 DEFLATE load.
@ k_eoh_err_crc
Chapter-0 CRC mismatch.
static void eoh_fail(uint32_t err, const uint8_t *msg, uint32_t len)
Stamp the failure stage, print the FAIL banner, and park the CPU.
static const ra8_port_pin_t k_eoh_pin_cs
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).
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).