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 text alignment + justification (#108). 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  al_consts_t : uint32_t {
  k_al_view_w = 280U ,
  k_al_view_h = 360U ,
  k_al_font_px = 16U ,
  k_al_ink = 0xFF101010U ,
  k_al_link_col = 0xFF2A52BEU ,
  k_al_uart_baud = 115200U ,
  k_al_fnv_offset = 2166136261U ,
  k_al_fnv_prime = 16777619U ,
  k_al_hex_nibbles = 8U ,
  k_al_nibble_bits = 4U ,
  k_al_nibble_mask = 0x0FU ,
  k_al_dec_ten = 10U
}
 Viewport / console / hash knobs (no magic numbers). More...

Functions

static void al_print (const uint8_t *msg, uint32_t len)
 Emit a byte run on the SCI8 console.
static void al_panic_halt (const uint8_t *msg, uint32_t len)
 Print the fail banner and trap (ra8_emulator halts on the BKPT).
static void al_print_hex (uint32_t value)
 Print a 32-bit value as 8 upper-case hex digits.
static void al_print_uint (uint32_t value)
 Print a small unsigned integer in decimal.
static uint32_t al_geom_hash (void)
 FNV-1a-32 over every laid-out glyph's (x, y) position.
static void al_setup_or_halt (void)
 Bring up clocks/MSTP/time + the SCI8 console; halt on failure.
void main (void)
 App entry: lay out the aligned chapter, hash the geometry, print.

Variables

static reflow_t s_engine
 Reflow engine (large – file-scope, not on the stack).
static const char k_al_chapter []
 Baked chapter: right, centre, justified, and default-left paragraphs.
static const uint8_t k_msg_boot [] = "ereader-align-hil: boot\r\n"
static const uint8_t k_msg_fail [] = "ereader-align-hil: FAIL init\r\n"
static const uint8_t k_msg_lerr [] = "ereader-align-hil: FAIL layout\r\n"
static const uint8_t k_msg_pre [] = "ereader-align-hil: glyphs="
static const uint8_t k_msg_geom [] = " geom="
static const uint8_t k_msg_eol [] = "\r\n"

Detailed Description

Headless on-silicon HIL gate for text alignment + justification (#108).

Closes the real-hardware gap for the alignment pipeline: parse style="text-align:...", lay out centre / right / justified paragraphs, and shift / space the glyphs accordingly – no panel / SD / touch needed. The app lays out a baked chapter (one paragraph each of right, centre, justify, and the default left) through reflow with the fixed-metric Ahem face, folds an FNV-1a-32 hash over the laid-out glyph geometry (every glyph's x + y), and prints a banner on the SCI8 J-Link OB console:

ereader-align-hil: glyphs=<N> geom=<8 hex>

Ahem's fixed metrics make the layout deterministic; the banner is identical every boot and matches the host / ra8_emulator run, so any drift in the alignment offsets or the justification slack changes the hash.

[Ring 7 / App] {World: NS}

Since
0.1.0

Definition in file main.c.

Enumeration Type Documentation

◆ al_consts_t

enum al_consts_t : uint32_t

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

Enumerator
k_al_view_w 

Layout viewport width, pixels.

k_al_view_h 

Layout viewport height, pixels.

k_al_font_px 

Body font size, pixels.

k_al_ink 

Body ink colour (ARGB).

k_al_link_col 

Anchor colour (ARGB).

k_al_uart_baud 

Console baud.

k_al_fnv_offset 

FNV-1a-32 offset basis.

k_al_fnv_prime 

FNV-1a-32 prime.

k_al_hex_nibbles 

Hex digits in a 32-bit value.

k_al_nibble_bits 

Bits per hex nibble.

k_al_nibble_mask 

Low-nibble mask.

k_al_dec_ten 

Hex digit / decimal split.

Definition at line 42 of file main.c.

Function Documentation

◆ al_geom_hash()

uint32_t al_geom_hash ( void )
static

FNV-1a-32 over every laid-out glyph's (x, y) position.

Definition at line 124 of file main.c.

References k_al_fnv_offset, k_al_fnv_prime, and s_engine.

Referenced by main().

◆ al_panic_halt()

void al_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 83 of file main.c.

References al_print().

Referenced by al_setup_or_halt(), and main().

◆ al_print()

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

Emit a byte run on the SCI8 console.

Definition at line 77 of file main.c.

References ra8_board_uart_console_write().

Referenced by al_panic_halt(), al_print_hex(), al_print_uint(), and main().

◆ al_print_hex()

void al_print_hex ( uint32_t value)
static

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

Definition at line 93 of file main.c.

References al_print(), k_al_dec_ten, k_al_hex_nibbles, k_al_nibble_bits, and k_al_nibble_mask.

Referenced by main().

◆ al_print_uint()

void al_print_uint ( uint32_t value)
static

Print a small unsigned integer in decimal.

Definition at line 105 of file main.c.

References al_print(), and k_al_dec_ten.

Referenced by main().

◆ al_setup_or_halt()

void al_setup_or_halt ( void )
static

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

Definition at line 139 of file main.c.

References al_panic_halt(), k_al_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: lay out the aligned chapter, hash the geometry, 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 geometry-hash banner is emitted; the CPU then loops in WFI.
Since
0.1.0

Definition at line 164 of file main.c.

References al_geom_hash(), al_panic_halt(), al_print(), al_print_hex(), al_print_uint(), al_setup_or_halt(), k_ahem_ttf, k_ahem_ttf_len, k_al_chapter, k_al_font_px, k_al_ink, k_al_link_col, k_al_view_h, k_al_view_w, k_msg_boot, k_msg_eol, k_msg_fail, k_msg_geom, k_msg_lerr, k_msg_pre, k_ra8_ok, ra8_isr_globals_enable(), reflow_init(), reflow_layout_chapter(), and s_engine.

Variable Documentation

◆ k_al_chapter

const char k_al_chapter[]
static
Initial value:
=
"<html><body><h1 style=\"text-align:center\">Aligned</h1>"
"<p style=\"text-align:right\">Right aligned paragraph flush to the margin.</p>"
"<p style=\"text-align:center\">Centred paragraph line in the column.</p>"
"<p style=\"text-align:justify\">aa bb cc dd ee ff gg hh ii jj kk ll mm nn oo "
"pp qq rr ss tt uu vv ww xx yy zz</p>"
"<p>Plain left paragraph as the default baseline.</p></body></html>"

Baked chapter: right, centre, justified, and default-left paragraphs.

Definition at line 61 of file main.c.

Referenced by main().

◆ k_msg_boot

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

Definition at line 69 of file main.c.

◆ k_msg_eol

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

Definition at line 74 of file main.c.

◆ k_msg_fail

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

Definition at line 70 of file main.c.

◆ k_msg_geom

const uint8_t k_msg_geom[] = " geom="
static

Definition at line 73 of file main.c.

Referenced by main().

◆ k_msg_lerr

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

Definition at line 71 of file main.c.

Referenced by erb_render_chapter(), and main().

◆ k_msg_pre

const uint8_t k_msg_pre[] = "ereader-align-hil: glyphs="
static

Definition at line 72 of file main.c.

◆ s_engine

reflow_t s_engine
static

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

Definition at line 58 of file main.c.