|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
On-silicon HIL: EPUB TOC navigation (NCX + nav.xhtml) from SD (#116). More...
#include <stddef.h>#include <stdint.h>#include "epub.h"#include "epub_fs.h"#include "epub_toc_fixture.h"#include "ra8_board_ek_ra8d2.h"#include "ra8_boot_entry.h"#include "ra8_cgc.h"#include "ra8_err.h"#include "ra8_isr.h"#include "ra8_log.h"#include "ra8_port_constants.h"#include "ra8_port_utils.h"#include "ra8_sci_spi.h"#include "ra8_sdmmc_spi.h"#include "ra8_spi.h"#include "ra8_time.h"Go to the source code of this file.
Enumerations | |
| enum | etoc_consts_t : uint32_t { k_etoc_uart_baud = 115200U , k_etoc_spi_chan = 0U , k_etoc_crc_init = 0xFFFFFFFFU , k_etoc_crc_poly = 0xEDB88320U , k_etoc_crc_bits = 8U , k_etoc_title_max = 256U , k_etoc_no_chap = 0xFFFFU , k_etoc_kind_unset = 0xFFU } |
| Console / SPI / parse knobs (no magic numbers). More... | |
| enum | etoc_expect_t : uint32_t { k_etoc_ncx_kind = 1U , k_etoc_ncx_count = 2U , k_etoc_ncx_crc = 0xDBC4EA24U , k_etoc_nav_kind = 2U , k_etoc_nav_count = 3U , k_etoc_nav_crc = 0x4CC9A9C1U , k_etoc_bad_kind = 0U , k_etoc_exp_chap = 2U , k_etoc_entry0 = 0U } |
| Byte-exact expected TOC results (host-verified). More... | |
| enum | etoc_err_t : uint32_t { k_etoc_err_none = 0U , k_etoc_err_init = 1U , k_etoc_err_card = 2U , k_etoc_err_mount = 3U , k_etoc_err_prov = 4U , k_etoc_err_ncx = 5U , k_etoc_err_nav = 6U , k_etoc_err_bad = 7U } |
| Failure-stage codes stamped to g_etoc_err for SWD / --dump-sym. More... | |
| enum | etoc_pace_t : uint32_t { k_etoc_frame_ms = 100U } |
| Idle-loop pacing for the success heartbeat. More... | |
Functions | |
| static void | etoc_print (const uint8_t *msg, uint32_t len) |
| Emit a byte run on the SCI8 console. | |
| 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. | |
| static uint32_t | etoc_crc32 (const uint8_t *data, size_t len) |
CRC-32 (reflected, poly 0xEDB88320) over data. | |
| static uint32_t | etoc_title_crc (const char *title) |
| CRC-32 over a null-terminated title (bounded by k_etoc_title_max). | |
| static ra8_err_t | etoc_spi_set_clock (void *ctx, uint32_t hz) |
| static ra8_err_t | etoc_spi_cs (void *ctx, bool asserted) |
| ra8_sdmmc_spi_transport_t::cs over ra8_gpio (CS active-low). | |
| 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 ra8_err_t | etoc_spi_pins_init (void) |
| Route Pmod2 SPI pins and claim CS as a GPIO output (idle high). | |
| static void | etoc_setup_or_halt (uint32_t *out_pclka_hz) |
| Bring up CGC + SysTick + console SCI + SPI + CS GPIO; halt on fail. | |
| 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_fs_mount_t * | etoc_mount_or_halt (void) |
| Mount the card, formatting FAT32 first if it is blank/unmountable. | |
| 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 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. | |
| static void | etoc_check_ncx (ra8_fs_mount_t *mount) |
| Parse + assert the NCX (EPUB2) TOC; latch the result globals. | |
| static void | etoc_check_nav (ra8_fs_mount_t *mount) |
| Parse + assert the nav (EPUB3) TOC; latch the result globals. | |
| static void | etoc_check_bad (ra8_fs_mount_t *mount) |
| Assert the malformed-TOC fallback: no TOC, spine still readable. | |
| void | main (void) |
| App entry: SD bring-up -> provision -> TOC asserts -> heartbeat idle. | |
Variables | |
| static const ra8_port_pin_t | k_etoc_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_etoc_pin_cipo = (ra8_port_pin_t)k_ra8_board_pmod2_spi_cipo |
| static const ra8_port_pin_t | k_etoc_pin_copi = (ra8_port_pin_t)k_ra8_board_pmod2_spi_copi |
| static const ra8_port_pin_t | k_etoc_pin_cs = (ra8_port_pin_t)k_ra8_board_pmod2_spi_cs |
| static const char | k_etoc_path_ncx [] = "TOCNCX.EPB" |
| SD paths for the three baked books (8.3 short names; ra8_fs root-only). | |
| static const char | k_etoc_path_nav [] = "TOCNAV.EPB" |
| static const char | k_etoc_path_bad [] = "TOCBAD.EPB" |
| volatile uint32_t | g_etoc_err = (uint32_t)k_etoc_err_none |
| First failing stage (etoc_err_t), 0 on success. | |
| volatile uint32_t | g_etoc_ncx_kind = 0U |
| NCX toc_kind on success. | |
| volatile uint32_t | g_etoc_ncx_n = 0U |
| NCX toc_count on success. | |
| volatile uint32_t | g_etoc_ncx_e0crc = 0U |
| NCX entry-0 label CRC. | |
| volatile uint32_t | g_etoc_ncx_ch0 = 0U |
| NCX entry-0 -> spine index. | |
| volatile uint32_t | g_etoc_nav_kind = 0U |
| nav toc_kind on success. | |
| volatile uint32_t | g_etoc_nav_n = 0U |
| nav toc_count on success. | |
| volatile uint32_t | g_etoc_nav_e0crc = 0U |
| nav entry-0 label CRC. | |
| volatile uint32_t | g_etoc_nav_ch0 = 0U |
| nav entry-0 -> spine index. | |
| volatile uint32_t | g_etoc_bad_kind = 0U |
| malformed-TOC kind (expect 0). | |
| volatile uint32_t | g_etoc_bad_chap = 0U |
| malformed-TOC spine fallback. | |
| volatile uint32_t | g_etoc_heartbeat = 0U |
| Idle heartbeat; advances ONLY after all asserts pass (the HIL gate). | |
| static epub_book_t | s_book |
| Opened book (large – file-scope, not on the stack). | |
| static epub_stream_fs_ctx_t | s_epub_io |
| Streamed-open source-file context; must outlive s_book (#230). | |
| static ra8_fs_backend_t | s_backend |
| SD backend; file-scope so the mount handle may reference it. | |
| static const uint8_t | k_msg_boot [] = "epub-toc-hil: boot\r\n" |
| static const uint8_t | k_msg_cardok [] = "epub-toc-hil: card ready\r\n" |
| static const uint8_t | k_msg_finit [] = "toc-hil: FAIL init\r\n" |
| static const uint8_t | k_msg_fcard [] = "toc-hil: FAIL card\r\n" |
| static const uint8_t | k_msg_fmount [] = "toc-hil: FAIL mount\r\n" |
| static const uint8_t | k_msg_fprov [] = "toc-hil: FAIL provision\r\n" |
| static const uint8_t | k_msg_fncx [] = "toc-hil: FAIL ncx\r\n" |
| static const uint8_t | k_msg_fnav [] = "toc-hil: FAIL nav\r\n" |
| static const uint8_t | k_msg_fbad [] = "toc-hil: FAIL bad\r\n" |
| static const uint8_t | k_msg_ok [] = "toc-hil: ncx+nav+fallback PASS\r\n" |
On-silicon HIL: EPUB TOC navigation (NCX + nav.xhtml) from SD (#116).
#74 added titled-TOC parsing to epub – both the EPUB2 NCX (<navMap>) and the EPUB3 nav.xhtml (<nav epub:type="toc">) forms – but it has only ever run on the x86 host. This app, building on epub_open (#114), runs the TOC path on the M85 against real .epub files staged on a microSD card.
It self-provisions three baked books onto the card (if absent) and parses each:
The HIL gate is memprobe (J-Link / ra8_emulator --dump-sym), not the console: an SD app drives the SCI0 Simple-SPI bus, and ra8_emulator folds every SCI channel into one console line, so the SCI8 banner is interleaved with SPI traffic there (the same reason the sibling SD HIL apps – epub_open, sd_font_render, fs_format_mount – gate on SWD globals). The success path advances g_etoc_heartbeat once per frame and only after every assertion passes; any failure stamps g_etoc_err and parks without bumping it. So a steadily advancing heartbeat with a zero g_etoc_err proves both TOC code paths plus the malformed-TOC fallback ran on real SD bytes. The console banner remains for a real-bench scope.
Required external hardware (on-bench): Digilent PMOD MicroSD (410-380) in Pmod2 (J25) with a microSD inserted. THIS APP MAY FORMAT THE CARD. Under ra8_emulator attach a blank card with --sd-new 64:fat32.
Definition in file main.c.
| enum etoc_consts_t : uint32_t |
Console / SPI / parse knobs (no magic numbers).
| enum etoc_err_t : uint32_t |
Failure-stage codes stamped to g_etoc_err for SWD / --dump-sym.
| enum etoc_expect_t : uint32_t |
Byte-exact expected TOC results (host-verified).
| enum etoc_pace_t : uint32_t |
|
static |
Assert the malformed-TOC fallback: no TOC, spine still readable.
Opens the no-TOC book, requires toc_kind none, then confirms the spine is still usable (epub_get_chapter_count == 2) so a renderer degrades to the spine list rather than faulting.
Definition at line 418 of file main.c.
References epub_close_streamed_fs(), epub_get_chapter_count(), epub_get_toc_kind(), epub_open_streamed_fs(), etoc_fail(), g_etoc_bad_chap, g_etoc_bad_kind, k_etoc_bad_kind, k_etoc_err_bad, k_etoc_exp_chap, k_etoc_kind_unset, k_etoc_path_bad, k_msg_fbad, k_ra8_ok, s_book, and s_epub_io.
Referenced by main().
|
static |
Parse + assert the nav (EPUB3) TOC; latch the result globals.
Definition at line 392 of file main.c.
References etoc_fail(), etoc_read_toc(), g_etoc_nav_ch0, g_etoc_nav_e0crc, g_etoc_nav_kind, g_etoc_nav_n, k_etoc_entry0, k_etoc_err_nav, k_etoc_nav_count, k_etoc_nav_crc, k_etoc_nav_kind, k_etoc_path_nav, and k_msg_fnav.
Referenced by main().
|
static |
Parse + assert the NCX (EPUB2) TOC; latch the result globals.
Definition at line 372 of file main.c.
References etoc_fail(), etoc_read_toc(), g_etoc_ncx_ch0, g_etoc_ncx_e0crc, g_etoc_ncx_kind, g_etoc_ncx_n, k_etoc_entry0, k_etoc_err_ncx, k_etoc_ncx_count, k_etoc_ncx_crc, k_etoc_ncx_kind, k_etoc_path_ncx, and k_msg_fncx.
Referenced by main().
|
static |
CRC-32 (reflected, poly 0xEDB88320) over data.
Definition at line 177 of file main.c.
References k_etoc_crc_bits, k_etoc_crc_init, and k_etoc_crc_poly.
Referenced by etoc_title_crc().
|
static |
Stamp the failure stage, print the FAIL banner, and park the CPU.
| [in] | err | Failure-stage code (etoc_err_t). |
| [in] | msg | Console diagnostic bytes. |
| [in] | len | Length of msg. |
Definition at line 167 of file main.c.
References etoc_print(), and g_etoc_err.
Referenced by etoc_check_bad(), etoc_check_nav(), etoc_check_ncx(), etoc_init_card_or_halt(), etoc_mount_or_halt(), etoc_provision_one(), etoc_read_toc(), and etoc_setup_or_halt().
|
static |
Init the SD card over SPI; halt with a diagnostic on failure.
Definition at line 269 of file main.c.
References etoc_fail(), etoc_print(), etoc_spi_cs(), etoc_spi_set_clock(), etoc_spi_xfer(), k_etoc_err_card, k_msg_cardok, k_msg_fcard, k_ra8_ok, and ra8_sdmmc_spi_init().
Referenced by main().
|
static |
Mount the card, formatting FAT32 first if it is blank/unmountable.
Definition at line 282 of file main.c.
References etoc_fail(), k_etoc_err_mount, k_msg_fmount, k_ra8_fs_type_fat32, k_ra8_ok, ra8_fs_format_opts_t::label, ra8_fs_format(), ra8_fs_mount(), ra8_sdmmc_spi_bind_fs_backend(), s_backend, and ra8_fs_format_opts_t::type.
Referenced by main().
|
static |
Emit a byte run on the SCI8 console.
Definition at line 155 of file main.c.
References ra8_board_uart_console_write().
Referenced by etoc_fail(), etoc_init_card_or_halt(), and main().
|
static |
Write one baked book onto the volume if path is absent.
Definition at line 302 of file main.c.
References etoc_fail(), k_etoc_err_prov, k_msg_fprov, k_ra8_fs_mode_read, k_ra8_ok, ra8_fs_close(), ra8_fs_open(), and ra8_fs_write_file().
Referenced by etoc_provision_or_halt().
|
static |
Provision all three baked TOC fixtures onto the card.
Definition at line 315 of file main.c.
References etoc_provision_one(), k_etoc_bad, k_etoc_bad_len, k_etoc_nav, k_etoc_nav_len, k_etoc_ncx, k_etoc_ncx_len, k_etoc_path_bad, k_etoc_path_nav, and k_etoc_path_ncx.
Referenced by main().
|
static |
Open one book off SD and read its TOC kind/count + entry-0 label CRC.
| [in] | mount | Mounted SD volume. |
| [in] | path | Book path on the volume. |
| [in] | stage | Failure-stage code for this book. |
| [in] | fmsg | FAIL banner for this book. |
| [in] | fmsglen | Length of fmsg. |
| [out] | kind | Receives epub_get_toc_kind. |
| [out] | count | Receives epub_get_toc_count. |
| [out] | e0crc | Receives the CRC-32 of entry 0's label (0 if no entries). |
| [out] | ch0 | Receives entry-0 -> spine index (0xFFFF if no entries). |
Definition at line 335 of file main.c.
References epub_close_streamed_fs(), epub_get_toc_count(), epub_get_toc_entry(), epub_get_toc_kind(), epub_open_streamed_fs(), epub_toc_entry_to_chapter(), etoc_fail(), etoc_title_crc(), k_etoc_no_chap, k_ra8_ok, s_book, s_epub_io, and epub_toc_entry_t::title.
Referenced by etoc_check_nav(), and etoc_check_ncx().
|
static |
Bring up CGC + SysTick + console SCI + SPI + CS GPIO; halt on fail.
Definition at line 242 of file main.c.
References etoc_fail(), etoc_spi_pins_init(), k_etoc_err_init, k_etoc_spi_chan, k_etoc_uart_baud, k_msg_finit, k_ra8_clock_id_cpuclk0, k_ra8_clock_id_pclka, k_ra8_ok, k_ra8_sdmmc_spi_clock_init_hz, k_ra8_spi_mode_0, ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), ra8_sci_spi_init(), and ra8_time_init().
Referenced by main().
|
static |
ra8_sdmmc_spi_transport_t::cs over ra8_gpio (CS active-low).
Definition at line 210 of file main.c.
References k_etoc_pin_cs, k_ra8_level_high, k_ra8_level_low, and ra8_gpio_write().
Referenced by etoc_init_card_or_halt().
|
staticnodiscard |
Route Pmod2 SPI pins and claim CS as a GPIO output (idle high).
Definition at line 224 of file main.c.
References k_etoc_pin_cipo, k_etoc_pin_copi, k_etoc_pin_cs, k_etoc_pin_sck, k_ra8_level_high, k_ra8_ok, k_ra8_psel_sci_async, ra8_gpio_output_init(), and ra8_pfs_route_peripheral().
Referenced by etoc_setup_or_halt().
|
static |
Definition at line 203 of file main.c.
References k_etoc_spi_chan, and ra8_sci_spi_set_clock().
Referenced by etoc_init_card_or_halt().
|
static |
ra8_sdmmc_spi_transport_t::xfer over ra8_sci_spi_xfer.
Definition at line 217 of file main.c.
References k_etoc_spi_chan, and ra8_sci_spi_xfer().
Referenced by etoc_init_card_or_halt().
|
static |
CRC-32 over a null-terminated title (bounded by k_etoc_title_max).
Definition at line 191 of file main.c.
References etoc_crc32(), and k_etoc_title_max.
Referenced by etoc_read_toc().
| void main | ( | void | ) |
App entry: SD bring-up -> provision -> TOC asserts -> heartbeat idle.
The application entry point Reset_Handler hands control to.
Definition at line 447 of file main.c.
References etoc_check_bad(), etoc_check_nav(), etoc_check_ncx(), etoc_init_card_or_halt(), etoc_mount_or_halt(), etoc_print(), etoc_provision_or_halt(), etoc_setup_or_halt(), g_etoc_heartbeat, k_etoc_frame_ms, k_msg_boot, k_msg_ok, ra8_delay_ms(), ra8_isr_globals_enable(), and ra8_log_init().
| volatile uint32_t g_etoc_bad_chap = 0U |
malformed-TOC spine fallback.
Definition at line 132 of file main.c.
Referenced by etoc_check_bad().
| volatile uint32_t g_etoc_bad_kind = 0U |
malformed-TOC kind (expect 0).
Definition at line 131 of file main.c.
Referenced by etoc_check_bad().
| volatile uint32_t g_etoc_err = (uint32_t)k_etoc_err_none |
First failing stage (etoc_err_t), 0 on success.
SWD / --dump-sym.
Definition at line 122 of file main.c.
Referenced by etoc_fail().
| volatile uint32_t g_etoc_heartbeat = 0U |
| volatile uint32_t g_etoc_nav_ch0 = 0U |
| volatile uint32_t g_etoc_nav_e0crc = 0U |
| volatile uint32_t g_etoc_nav_kind = 0U |
| volatile uint32_t g_etoc_nav_n = 0U |
| volatile uint32_t g_etoc_ncx_ch0 = 0U |
| volatile uint32_t g_etoc_ncx_e0crc = 0U |
| volatile uint32_t g_etoc_ncx_kind = 0U |
| volatile uint32_t g_etoc_ncx_n = 0U |
|
static |
Definition at line 95 of file main.c.
Referenced by etoc_check_bad(), and etoc_provision_or_halt().
|
static |
Definition at line 94 of file main.c.
Referenced by etoc_check_nav(), and etoc_provision_or_halt().
|
static |
SD paths for the three baked books (8.3 short names; ra8_fs root-only).
Definition at line 93 of file main.c.
Referenced by etoc_check_ncx(), and etoc_provision_or_halt().
|
static |
Definition at line 88 of file main.c.
Referenced by etoc_spi_pins_init().
|
static |
Definition at line 89 of file main.c.
Referenced by etoc_spi_pins_init().
|
static |
Definition at line 90 of file main.c.
Referenced by etoc_spi_cs(), and etoc_spi_pins_init().
|
static |
Pmod2 SPI pins (J25) – SCI0 Simple-SPI; CS held by GPIO.
Definition at line 87 of file main.c.
Referenced by etoc_spi_pins_init().
|
static |
|
static |
Definition at line 151 of file main.c.
Referenced by etoc_check_bad().
|
static |
|
static |
|
static |
|
static |
Definition at line 150 of file main.c.
Referenced by etoc_check_nav().
|
static |
Definition at line 149 of file main.c.
Referenced by etoc_check_ncx().
|
static |
|
static |
|
static |
|
static |
|
static |