ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
main.c File Reference

Headless HIL gate: load a compiled .rabook and render it (small to large). More...

#include <stddef.h>
#include <stdint.h>
#include "book.h"
#include "font_fixture.h"
#include "ra8_board_ek_ra8d2.h"
#include "ra8_boot_entry.h"
#include "ra8_cgc.h"
#include "ra8_err.h"
#include "ra8_gfx.h"
#include "ra8_isr.h"
#include "ra8_mstp.h"
#include "ra8_time.h"
#include "rabook_fixture.h"
#include "rabook_gray8_fixture.h"
#include "reflow.h"
Include dependency graph for main.c:

Go to the source code of this file.

Enumerations

enum  erb_consts_t : uint32_t {
  k_erb_fb_w = 128U ,
  k_erb_fb_h = 160U ,
  k_erb_font_px = 16U ,
  k_erb_ink = 0xFF101010U ,
  k_erb_link_col = 0xFF2A52BEU ,
  k_erb_bg = 0xF4F0E8U ,
  k_erb_xhtml_cap = 2048U ,
  k_erb_uart_baud = 115200U ,
  k_erb_fnv_offset = 2166136261U ,
  k_erb_fnv_prime = 16777619U ,
  k_erb_hex_nibbles = 8U ,
  k_erb_nibble_bits = 4U ,
  k_erb_nibble_mask = 0x0FU ,
  k_erb_dec_ten = 10U
}
 Framebuffer / console / hash / buffer knobs. More...
enum  erb_img_const_t : uint32_t {
  k_erb_gray4_levels = 16U ,
  k_erb_level_count = 256U ,
  k_erb_img_max_px = 96U * 48U
}
 Full-resolution gray8 figure check bounds (#476). More...

Functions

static void erb_print (const uint8_t *msg, uint32_t len)
 Emit a byte run on the SCI8 console.
static void erb_panic_halt (const uint8_t *msg, uint32_t len)
 Print the fail banner and trap (ra8_emulator halts on the BKPT).
static void erb_print_hex (uint32_t value)
 Print a 32-bit value as 8 upper-case hex digits.
static void erb_print_uint (uint32_t value)
 Print a small unsigned integer in decimal.
static uint32_t erb_hash_fb (uint32_t seed)
 Fold the whole RGB565 framebuffer into a running FNV-1a-32.
static uint32_t erb_render_all (uint32_t *out_hash)
 Render every laid-out page of the current chapter; fold an FNV over it.
static void erb_setup_or_halt (void)
 Bring up clocks/MSTP/time + the SCI8 console; halt on failure.
static void erb_render_chapter (const void *book, uint32_t chapter_idx)
 Lay out + render one chapter; emit chN p=<pages> crc=<hash>.
static uint32_t erb_distinct_levels (const uint8_t *px, uint32_t n)
 Count the distinct gray8 tone levels in px[0..n) (bounded scan).
static void erb_render_image (void)
 Render the retained full-resolution gray8 figure and check it (#476).
void main (void)
 App entry: validate the baked book, render each chapter, print.

Variables

static uint16_t s_framebuffer [(size_t) k_erb_fb_h *(size_t) k_erb_fb_w]
 RGB565 framebuffer in internal SRAM (no panel attached).
static reflow_t s_engine
 Reflow engine (large – file-scope, not on the stack).
static char s_xhtml [k_erb_xhtml_cap]
 Scratch for one chapter's serialized XHTML (DOM -> renderer bridge).
static const uint8_t k_msg_boot [] = "ereader-rabook-hil: boot\r\n"
static const uint8_t k_msg_fail [] = "ereader-rabook-hil: FAIL init\r\n"
static const uint8_t k_msg_berr [] = "ereader-rabook-hil: FAIL book\r\n"
static const uint8_t k_msg_lerr [] = "ereader-rabook-hil: FAIL layout\r\n"
static const uint8_t k_msg_pre [] = "ereader-rabook-hil: chapters="
static const uint8_t k_msg_ch [] = " ch"
static const uint8_t k_msg_p [] = " p="
static const uint8_t k_msg_crc [] = " crc="
static const uint8_t k_msg_img [] = " img "
static const uint8_t k_msg_x [] = "x"
static const uint8_t k_msg_g8 [] = " gray8"
static const uint8_t k_msg_ok [] = " ok\r\n"

Detailed Description

Headless HIL gate: load a compiled .rabook and render it (small to large).

The on-silicon proof of the compiled-book path. A small two-chapter book, compiled by tools/epub_compile into the book format and baked (inflated) into rabook_fixture.h, is loaded the way the device loads any book:

  1. book_validate() – accept the flat blob (magic, bounds, CRC). A real SD-loaded book is book_open()-ed instead (mz_uncompress + validate); see README.md. The baked fixture is already inflated so the gate needs no decompressor.
  2. For each chapter, book_chapter_to_xhtml() walks the pre-parsed DOM and bridges it to the existing renderer.
  3. reflow_layout_chapter() paginates, then every page is rendered into a 128x160 RGB565 framebuffer and folded into an FNV-1a-32.
  4. A second, one-image .rabook (rabook_gray8_fixture.h) carries a raster at full source resolution in continuous-tone gray8 – the representation the compiler retains for zoomable content (#476), never a panel-quantised 4bpp copy. The gate confirms it is 8bpp and holds more than the 16 tones a gray4 store could reproduce, then blits it 1:1 (no downscale, no re-quantise).

The book's first chapter is short (a title + two paragraphs) and the second is longer (paginates further) – a small-to-large render in one book. The fixed-metric Ahem face makes pagination + render deterministic, so the banner on the SCI8 J-Link OB console is identical every boot and matches ra8_emulator:

ereader-rabook-hil: chapters=<N> ch0 p=<P> crc=<8hex> ch1 p=<P> crc=<8hex> img <W>x<H> gray8 ok

[Ring 7 / App] {World: NS}

Since
0.1.0

Definition in file main.c.

Enumeration Type Documentation

◆ erb_consts_t

enum erb_consts_t : uint32_t

Framebuffer / console / hash / buffer knobs.

Enumerator
k_erb_fb_w 

Framebuffer width, pixels.

k_erb_fb_h 

Framebuffer height, pixels.

k_erb_font_px 

Body font size, pixels.

k_erb_ink 

Body ink colour (ARGB).

k_erb_link_col 

Anchor colour (ARGB).

k_erb_bg 

Page background (0x00RRGGBB).

k_erb_xhtml_cap 

Per-chapter serialized XHTML cap.

k_erb_uart_baud 

Console baud.

k_erb_fnv_offset 

FNV-1a-32 offset basis.

k_erb_fnv_prime 

FNV-1a-32 prime.

k_erb_hex_nibbles 

Hex digits in a 32-bit value.

k_erb_nibble_bits 

Bits per hex nibble.

k_erb_nibble_mask 

Low-nibble mask.

k_erb_dec_ten 

Hex digit / decimal split.

Definition at line 57 of file main.c.

◆ erb_img_const_t

enum erb_img_const_t : uint32_t

Full-resolution gray8 figure check bounds (#476).

Enumerator
k_erb_gray4_levels 

Distinct tones a 4bpp store can ever show.

k_erb_level_count 

gray8 value space (presence bitmap size).

k_erb_img_max_px 

Fixture image pixel cap (bounds the scan).

Definition at line 97 of file main.c.

Function Documentation

◆ erb_distinct_levels()

uint32_t erb_distinct_levels ( const uint8_t * px,
uint32_t n )
static

Count the distinct gray8 tone levels in px[0..n) (bounded scan).

Parameters
[in]pxGray8 pixel bytes (non-NULL).
[in]nPixel count (<= k_erb_img_max_px, the scan bound).
Returns
The number of distinct byte values seen (0..256).

Definition at line 234 of file main.c.

References k_erb_img_max_px, and k_erb_level_count.

Referenced by erb_render_image().

◆ erb_hash_fb()

uint32_t erb_hash_fb ( uint32_t seed)
static

Fold the whole RGB565 framebuffer into a running FNV-1a-32.

Parameters
[in]seedRunning hash to extend (start from k_erb_fnv_offset).
Returns
The framebuffer-folded hash.

Definition at line 156 of file main.c.

References k_erb_fb_h, k_erb_fb_w, k_erb_fnv_prime, and s_framebuffer.

Referenced by erb_render_all().

◆ erb_panic_halt()

void erb_panic_halt ( const uint8_t * msg,
uint32_t len )
static

Print the fail banner and trap (ra8_emulator halts on the BKPT).

Definition at line 110 of file main.c.

References erb_print().

Referenced by erb_render_chapter(), erb_render_image(), erb_setup_or_halt(), and main().

◆ erb_print()

void erb_print ( const uint8_t * msg,
uint32_t len )
static

Emit a byte run on the SCI8 console.

Definition at line 104 of file main.c.

References ra8_board_uart_console_write().

Referenced by erb_panic_halt(), erb_print_hex(), erb_print_uint(), erb_render_chapter(), erb_render_image(), and main().

◆ erb_print_hex()

void erb_print_hex ( uint32_t value)
static

Print a 32-bit value as 8 upper-case hex digits.

Definition at line 120 of file main.c.

References erb_print(), k_erb_dec_ten, k_erb_hex_nibbles, k_erb_nibble_bits, and k_erb_nibble_mask.

Referenced by erb_render_chapter().

◆ erb_print_uint()

void erb_print_uint ( uint32_t value)
static

Print a small unsigned integer in decimal.

Definition at line 133 of file main.c.

References erb_print(), and k_erb_dec_ten.

Referenced by erb_render_chapter(), erb_render_image(), and main().

◆ erb_render_all()

uint32_t erb_render_all ( uint32_t * out_hash)
static

Render every laid-out page of the current chapter; fold an FNV over it.

Parameters
[out]out_hashReceives the FNV-1a-32 over every page's framebuffer.
Returns
The page count.

Definition at line 172 of file main.c.

References erb_hash_fb(), k_erb_bg, k_erb_fnv_offset, ra8_gfx_clear(), reflow_get_page_count(), reflow_render_page(), s_engine, and s_framebuffer.

Referenced by erb_render_chapter().

◆ erb_render_chapter()

void erb_render_chapter ( const void * book,
uint32_t chapter_idx )
static

Lay out + render one chapter; emit chN p=<pages> crc=<hash>.

Definition at line 205 of file main.c.

References book_chapter_to_xhtml(), erb_panic_halt(), erb_print(), erb_print_hex(), erb_print_uint(), erb_render_all(), k_erb_xhtml_cap, k_msg_berr, k_msg_ch, k_msg_crc, k_msg_lerr, k_msg_p, k_ra8_ok, reflow_layout_chapter(), s_engine, and s_xhtml.

Referenced by main().

◆ erb_render_image()

void erb_render_image ( void )
static

Render the retained full-resolution gray8 figure and check it (#476).

The compiled-book path retains zoomable rasters at full source resolution in continuous-tone gray8, never a panel-quantised 4bpp copy. This is the on-silicon proof: a one-image .rabook (rabook_gray8_fixture.h) is validated, and its image is confirmed to be an 8bpp raster (raw_size == width * height) carrying MORE than the 16 distinct tones a gray4 store could ever hold – so a gray4 import would have destroyed it. The pixels are then blitted 1:1 (no downscale, no re-quantise) to prove they render at full resolution. Any failure halts on the FAIL banner; success emits the deterministic img <W>x<H> gray8.

Precondition
ra8_gfx_init() has been called (the framebuffer is bound).
Postcondition
The img banner field is emitted, or the gate halts on a bad fixture.

Definition at line 264 of file main.c.

References book_header(), book_image_data(), book_image_pixfmt(), book_images(), book_validate(), erb_distinct_levels(), erb_panic_halt(), erb_print(), erb_print_uint(), book_image_t::format, book_image_t::height, book_header_t::image_count, k_book_image_gray4, k_book_pixfmt_gray8, k_erb_bg, k_erb_gray4_levels, k_erb_img_max_px, k_msg_berr, k_msg_g8, k_msg_img, k_msg_x, k_ra8_ok, k_rabook_gray8_fixture, k_rabook_gray8_fixture_len, ra8_gfx_blit_gray8(), ra8_gfx_clear(), book_image_t::raw_size, and book_image_t::width.

Referenced by main().

◆ erb_setup_or_halt()

void erb_setup_or_halt ( void )
static

Bring up clocks/MSTP/time + the SCI8 console; halt on failure.

Definition at line 187 of file main.c.

References erb_panic_halt(), k_erb_uart_baud, k_msg_fail, k_ra8_clock_id_cpuclk0, k_ra8_ok, ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), ra8_mstp_init(), and ra8_time_init().

Referenced by main().

◆ main()

void main ( void )

App entry: validate the baked book, render each chapter, print.

The application entry point Reset_Handler hands control to.

Precondition
Reset_Handler copied .data and zeroed .bss.
SystemInit set VTOR / FPU / priority grouping.
Postcondition
The per-chapter page-count + render-hash banner is emitted; loops in WFI.
Since
0.1.0

Definition at line 308 of file main.c.

References book_header(), book_validate(), book_header_t::chapter_count, erb_panic_halt(), erb_print(), erb_print_uint(), erb_render_chapter(), erb_render_image(), erb_setup_or_halt(), k_ahem_ttf, k_ahem_ttf_len, k_erb_fb_h, k_erb_fb_w, k_erb_font_px, k_erb_ink, k_erb_link_col, k_msg_berr, k_msg_boot, k_msg_fail, k_msg_ok, k_msg_pre, k_ra8_gfx_format_rgb565, k_ra8_ok, k_rabook_fixture, k_rabook_fixture_len, ra8_gfx_init(), ra8_isr_globals_enable(), reflow_init(), s_engine, and s_framebuffer.

Variable Documentation

◆ k_msg_berr

const uint8_t k_msg_berr[] = "ereader-rabook-hil: FAIL book\r\n"
static

Definition at line 85 of file main.c.

Referenced by erb_render_chapter(), erb_render_image(), and main().

◆ k_msg_boot

const uint8_t k_msg_boot[] = "ereader-rabook-hil: boot\r\n"
static

Definition at line 83 of file main.c.

◆ k_msg_ch

const uint8_t k_msg_ch[] = " ch"
static

Definition at line 88 of file main.c.

◆ k_msg_crc

const uint8_t k_msg_crc[] = " crc="
static

Definition at line 90 of file main.c.

◆ k_msg_fail

const uint8_t k_msg_fail[] = "ereader-rabook-hil: FAIL init\r\n"
static

Definition at line 84 of file main.c.

◆ k_msg_g8

const uint8_t k_msg_g8[] = " gray8"
static

Definition at line 93 of file main.c.

Referenced by erb_render_image().

◆ k_msg_img

const uint8_t k_msg_img[] = " img "
static

Definition at line 91 of file main.c.

Referenced by erb_render_image().

◆ k_msg_lerr

const uint8_t k_msg_lerr[] = "ereader-rabook-hil: FAIL layout\r\n"
static

Definition at line 86 of file main.c.

◆ k_msg_ok

const uint8_t k_msg_ok[] = " ok\r\n"
static

Definition at line 94 of file main.c.

◆ k_msg_p

const uint8_t k_msg_p[] = " p="
static

Definition at line 89 of file main.c.

Referenced by erb_render_chapter().

◆ k_msg_pre

const uint8_t k_msg_pre[] = "ereader-rabook-hil: chapters="
static

Definition at line 87 of file main.c.

◆ k_msg_x

const uint8_t k_msg_x[] = "x"
static

Definition at line 92 of file main.c.

◆ s_engine

reflow_t s_engine
static

Reflow engine (large – file-scope, not on the stack).

Definition at line 78 of file main.c.

◆ s_framebuffer

uint16_t s_framebuffer[(size_t) k_erb_fb_h *(size_t) k_erb_fb_w]
static

RGB565 framebuffer in internal SRAM (no panel attached).

Definition at line 75 of file main.c.

◆ s_xhtml

char s_xhtml[k_erb_xhtml_cap]
static

Scratch for one chapter's serialized XHTML (DOM -> renderer bridge).

Definition at line 81 of file main.c.