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

Headless on-silicon HIL gate for in-content hyperlink navigation (#110). More...

#include <stddef.h>
#include <stdint.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_isr.h"
#include "ra8_mstp.h"
#include "ra8_time.h"
#include "reflow.h"
Include dependency graph for main.c:

Go to the source code of this file.

Enumerations

enum  lk_consts_t : uint32_t {
  k_lk_view_w = 280U ,
  k_lk_view_h = 360U ,
  k_lk_font_px = 16U ,
  k_lk_ink = 0xFF101010U ,
  k_lk_link_col = 0xFF2A52BEU ,
  k_lk_uart_baud = 115200U ,
  k_lk_fnv_offset = 2166136261U ,
  k_lk_fnv_prime = 16777619U ,
  k_lk_hex_nibbles = 8U ,
  k_lk_nibble_bits = 4U ,
  k_lk_nibble_mask = 0x0FU ,
  k_lk_dec_ten = 10U
}
 Viewport / console / hash knobs (no magic numbers). More...

Functions

static void lk_print (const uint8_t *msg, uint32_t len)
 Emit a byte run on the SCI8 console.
static void lk_panic_halt (const uint8_t *msg, uint32_t len)
 Print the fail banner and trap (ra8_emulator halts on the BKPT).
static void lk_print_hex (uint32_t value)
 Print a 32-bit value as 8 upper-case hex digits.
static void lk_print_uint (uint32_t value)
 Print a small unsigned integer in decimal.
static void lk_print_bool (bool yes)
 Print "Y" or "N".
static uint32_t lk_geom_hash (void)
 FNV-1a-32 over the laid-out link-rectangle geometry.
static void lk_probe_rect (uint32_t idx, bool *out_cross, bool *out_frag)
 Classify the href at a link rect's centre via the public nav API.
static void lk_setup_or_halt (void)
 Bring up clocks/MSTP/time + the SCI8 console; halt on failure.
void main (void)
 App entry: lay out the link chapter, drive the nav API, print results.

Variables

static reflow_t s_engine
 Reflow engine (large – file-scope, not on the stack).
static const char k_lk_chapter []
 Baked chapter: two links (cross-chapter + fragment) and an anchor.
static const uint8_t k_msg_boot [] = "ereader-link-hil: boot\r\n"
static const uint8_t k_msg_fail [] = "ereader-link-hil: FAIL init\r\n"
static const uint8_t k_msg_lerr [] = "ereader-link-hil: FAIL layout\r\n"
static const uint8_t k_msg_pre [] = "ereader-link-hil: links="
static const uint8_t k_msg_cross [] = " cross="
static const uint8_t k_msg_frag [] = " frag="
static const uint8_t k_msg_apage [] = " apage="
static const uint8_t k_msg_geom [] = " geom="
static const uint8_t k_msg_eol [] = "\r\n"
static const uint8_t k_msg_yes [] = "Y"
static const uint8_t k_msg_no [] = "N"

Detailed Description

Headless on-silicon HIL gate for in-content hyperlink navigation (#110).

Closes the real-hardware gap for the <a href> link pipeline: tokenize the href + element id, lay out the chapter, build tappable link rectangles + anchor positions, then drive the navigation API the way a touch tap would – no panel / SD / touch needed. The app:

  1. Lays out a baked chapter (two <a href> links + a <p id="foot"> anchor) through reflow with the bundled Ahem face.
  2. Synthesises a "tap" at the centre of each laid-out link rectangle and resolves it with reflow_hit_test_link() + reflow_href_split(): one link classifies as a cross-chapter target, one as a same-chapter #fragment.
  3. Resolves the fragment to its page with reflow_find_anchor().
  4. Folds an FNV-1a-32 hash over the laid-out link-rectangle geometry and prints a banner on the SCI8 J-Link OB console:

    ereader-link-hil: links=2 cross=Y frag=Y apage=<P> geom=<8 hex>

Ahem is a fixed-metric face, so the layout + link geometry are deterministic; the banner is identical every boot and matches the host / ra8_emulator run.

[Ring 7 / App] {World: NS}

Since
0.1.0

Definition in file main.c.

Enumeration Type Documentation

◆ lk_consts_t

enum lk_consts_t : uint32_t

Viewport / console / hash knobs (no magic numbers).

Enumerator
k_lk_view_w 

Layout viewport width, pixels.

k_lk_view_h 

Layout viewport height, pixels.

k_lk_font_px 

Body font size, pixels.

k_lk_ink 

Body ink colour (ARGB).

k_lk_link_col 

Anchor colour (ARGB).

k_lk_uart_baud 

Console baud.

k_lk_fnv_offset 

FNV-1a-32 offset basis.

k_lk_fnv_prime 

FNV-1a-32 prime.

k_lk_hex_nibbles 

Hex digits in a 32-bit value.

k_lk_nibble_bits 

Bits per hex nibble.

k_lk_nibble_mask 

Low-nibble mask.

k_lk_dec_ten 

Hex digit / decimal split.

Definition at line 48 of file main.c.

Function Documentation

◆ lk_geom_hash()

uint32_t lk_geom_hash ( void )
static

FNV-1a-32 over the laid-out link-rectangle geometry.

Definition at line 145 of file main.c.

References k_lk_fnv_offset, k_lk_fnv_prime, and s_engine.

Referenced by main().

◆ lk_panic_halt()

void lk_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 94 of file main.c.

References lk_print().

Referenced by lk_setup_or_halt(), and main().

◆ lk_print()

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

Emit a byte run on the SCI8 console.

Definition at line 88 of file main.c.

References ra8_board_uart_console_write().

Referenced by lk_panic_halt(), lk_print_bool(), lk_print_hex(), lk_print_uint(), and main().

◆ lk_print_bool()

void lk_print_bool ( bool yes)
static

Print "Y" or "N".

Definition at line 135 of file main.c.

References k_msg_no, k_msg_yes, and lk_print().

Referenced by main().

◆ lk_print_hex()

void lk_print_hex ( uint32_t value)
static

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

Definition at line 104 of file main.c.

References k_lk_dec_ten, k_lk_hex_nibbles, k_lk_nibble_bits, k_lk_nibble_mask, and lk_print().

Referenced by main().

◆ lk_print_uint()

void lk_print_uint ( uint32_t value)
static

Print a small unsigned integer in decimal.

Definition at line 116 of file main.c.

References k_lk_dec_ten, and lk_print().

Referenced by main().

◆ lk_probe_rect()

void lk_probe_rect ( uint32_t idx,
bool * out_cross,
bool * out_frag )
static

Classify the href at a link rect's centre via the public nav API.

Parameters
[in]idxLink-rect index to probe.
[out]out_crossSet true when the href is a cross-chapter target.
[out]out_fragSet true when the href is a same-chapter fragment.
Returns
None.

Definition at line 164 of file main.c.

References reflow_link_rect_t::h, k_ra8_ok, k_reflow_href_chapter, k_reflow_href_chapter_fragment, k_reflow_href_empty, k_reflow_href_fragment, reflow_link_rect_t::page_index, reflow_hit_test_link(), reflow_href_split(), s_engine, reflow_link_rect_t::w, reflow_link_rect_t::x, and reflow_link_rect_t::y.

Referenced by main().

◆ lk_setup_or_halt()

void lk_setup_or_halt ( void )
static

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

Definition at line 191 of file main.c.

References k_lk_uart_baud, k_msg_fail, k_ra8_clock_id_cpuclk0, k_ra8_ok, lk_panic_halt(), 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: lay out the link chapter, drive the nav API, print results.

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 nav-result banner is emitted; the CPU then loops in WFI.
Since
0.1.0

Definition at line 216 of file main.c.

References k_ahem_ttf, k_ahem_ttf_len, k_lk_chapter, k_lk_font_px, k_lk_ink, k_lk_link_col, k_lk_view_h, k_lk_view_w, k_msg_apage, k_msg_boot, k_msg_cross, k_msg_eol, k_msg_fail, k_msg_frag, k_msg_geom, k_msg_lerr, k_msg_pre, k_ra8_ok, lk_geom_hash(), lk_panic_halt(), lk_print(), lk_print_bool(), lk_print_hex(), lk_print_uint(), lk_probe_rect(), lk_setup_or_halt(), ra8_isr_globals_enable(), reflow_find_anchor(), reflow_init(), reflow_layout_chapter(), and s_engine.

Variable Documentation

◆ k_lk_chapter

const char k_lk_chapter[]
static
Initial value:
=
"<html><body><h1>Chapter One</h1>"
"<p>Jump to the <a href=\"ch2.xhtml\">next chapter</a> or skip to the "
"<a href=\"#foot\">footnote</a> below for the citation.</p>"
"<p>Body paragraph with enough words to occupy a couple of lines so the "
"layout has real content to paginate around the links.</p>"
"<p id=\"foot\">Footnote: this is the cited reference text.</p></body></html>"

Baked chapter: two links (cross-chapter + fragment) and an anchor.

Definition at line 67 of file main.c.

Referenced by main().

◆ k_msg_apage

const uint8_t k_msg_apage[] = " apage="
static

Definition at line 81 of file main.c.

Referenced by main().

◆ k_msg_boot

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

Definition at line 75 of file main.c.

◆ k_msg_cross

const uint8_t k_msg_cross[] = " cross="
static

Definition at line 79 of file main.c.

Referenced by main().

◆ k_msg_eol

const uint8_t k_msg_eol[] = "\r\n"
static

Definition at line 83 of file main.c.

◆ k_msg_fail

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

Definition at line 76 of file main.c.

◆ k_msg_frag

const uint8_t k_msg_frag[] = " frag="
static

Definition at line 80 of file main.c.

Referenced by main().

◆ k_msg_geom

const uint8_t k_msg_geom[] = " geom="
static

Definition at line 82 of file main.c.

◆ k_msg_lerr

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

Definition at line 77 of file main.c.

◆ k_msg_no

const uint8_t k_msg_no[] = "N"
static

Definition at line 85 of file main.c.

Referenced by lk_print_bool().

◆ k_msg_pre

const uint8_t k_msg_pre[] = "ereader-link-hil: links="
static

Definition at line 78 of file main.c.

◆ k_msg_yes

const uint8_t k_msg_yes[] = "Y"
static

Definition at line 84 of file main.c.

Referenced by lk_print_bool().

◆ s_engine

reflow_t s_engine
static

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

Definition at line 64 of file main.c.