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

On-silicon HIL: ra8_widget compositor + ra8_app framework (#145/#146). More...

#include <stddef.h>
#include <stdint.h>
#include "ra8_app.h"
#include "ra8_board_ek_ra8d2.h"
#include "ra8_boot_entry.h"
#include "ra8_box.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 "ra8_ui.h"
#include "ra8_widget.h"
Include dependency graph for main.c:

Go to the source code of this file.

Data Structures

struct  wa_fill_t
 A solid-fill widget: renders one colour into its rect via ra8_gfx. More...
struct  wa_app_state_t
 Per-app state: its widget tree + a focus-lifecycle counter. More...

Enumerations

enum  wa_consts_t : uint32_t {
  k_wa_uart_baud = 115200U ,
  k_wa_fb_w = 160U ,
  k_wa_fb_h = 120U ,
  k_wa_statusbar_h = 16U ,
  k_wa_col_bg = 0x101018U ,
  k_wa_col_status = 0x808088U ,
  k_wa_col_library = 0x3050C0U ,
  k_wa_col_reader = 0xC05030U ,
  k_wa_fnv_offset = 0x811C9DC5U ,
  k_wa_fnv_prime = 0x01000193U ,
  k_wa_hex_nibbles = 8U ,
  k_wa_nibble_bits = 4U ,
  k_wa_nibble_mask = 0x0FU ,
  k_wa_dec_ten = 10U
}
 Console / layout knobs (no magic numbers). More...
enum  wa_app_id_t : uint16_t {
  k_wa_app_library = 1U ,
  k_wa_app_reader = 2U
}
 Registered app ids. More...

Functions

static void wa_print (const uint8_t *msg, uint32_t len)
 Emit a byte run on the SCI8 console.
static void wa_panic_halt (const uint8_t *msg, uint32_t len)
 Print the fail banner and trap (ra8_emulator halts on the BKPT).
static uint32_t wa_framebuffer_hash (void)
 FNV-1a hash over the composited framebuffer.
static void wa_print_hex (uint32_t value)
 Print a 32-bit value as 8 upper-case hex digits.
static void wa_fill_render (ra8_widget_t *w)
 Widget render callback: fill the widget's rect with its colour.
static void wa_state_init (wa_app_state_t *st, uint32_t content_color)
 Build one app's widget tree: status bar (fixed) over content (flex).
static void wa_app_render (const ra8_app_t *a)
 App.render: lay out + composite the app's widget tree.
static void wa_app_enter (ra8_app_t *a)
static void wa_app_leave (ra8_app_t *a)
static void wa_setup_or_halt (void)
 Bring up clocks/MSTP/time + the SCI8 console; halt on failure.
static void wa_run_two_apps (ra8_app_registry_t *reg, uint32_t *out_lib, uint32_t *out_rdr)
 Launch + composite both apps, returning each composite's hash.
static void wa_verify_or_halt (uint32_t lib_crc, uint32_t rdr_crc)
 Assert distinct composites, a fired lifecycle, and a partial flush.
void main (void)
 App entry: register two widget-tree apps, launch + composite each.

Variables

static uint16_t s_framebuffer [(size_t) k_wa_fb_h *(size_t) k_wa_fb_w]
 RGB565 framebuffer all widgets composite into.
static wa_app_state_t s_library
static wa_app_state_t s_reader
static const uint8_t k_msg_boot [] = "widget-app-hil: boot\r\n"
static const uint8_t k_msg_fail [] = "widget-app-hil: FAIL init\r\n"
static const uint8_t k_msg_freg [] = "widget-app-hil: FAIL register\r\n"
static const uint8_t k_msg_fcrc [] = "widget-app-hil: FAIL crc-equal\r\n"
static const uint8_t k_msg_flife [] = "widget-app-hil: FAIL lifecycle\r\n"
static const uint8_t k_msg_fdmg [] = "widget-app-hil: FAIL damage\r\n"
static const uint8_t k_msg_pre [] = "widget-app-hil: apps=2 lib="
static const uint8_t k_msg_rdr [] = " rdr="
static const uint8_t k_msg_flush [] = " flush=160x16 hint=fast"
static const uint8_t k_msg_ok [] = " PASS\r\n"
static const ra8_widget_vtable_t k_wa_fill_vt
 Shared vtable for the solid-fill widget.
static const ra8_app_vtable_t k_wa_app_vt
 Shared app lifecycle vtable.

Detailed Description

On-silicon HIL: ra8_widget compositor + ra8_app framework (#145/#146).

End-to-end on the M85, proving the widget/app foundation works on-target:

  1. Two apps (library, reader) register into an ra8_app registry, each running its init once.
  2. Each app is a widget tree: a status-bar widget (fixed height) over a content widget (flex), laid out by ra8_widget_layout_stack (delegating to ra8_box) and drawn by each widget's render callback through ra8_gfx into a 160x120 RGB565 framebuffer.
  3. ra8_app_launch(library) -> ra8_app_render composites the library tree; FNV-1a hash the framebuffer -> lib_crc.
  4. ra8_app_launch(reader) fires library.on_leave + reader.on_enter (the focus lifecycle), then ra8_app_render composites the reader tree -> rdr_crc. The two CRCs differ (different content widget).
  5. Damage/partial-flush (#145): invalidate only the status bar with the fast hint -> ra8_widget_damage returns just the status-bar rect + the fast refresh hint – the minimal e-ink flush.

The console banner on success is:

widget-app-hil: apps=2 lib=<8hex> rdr=<8hex> flush=160x16 hint=fast PASS

Deterministic (fixed composition through deterministic layout + fills), so the ra8_emulator banner is the regression net. Any failure prints a FAIL banner and halts on a BKPT before PASS.

[Ring 6 / App] {World: NS}

Since
0.1.0

Definition in file main.c.

Enumeration Type Documentation

◆ wa_app_id_t

enum wa_app_id_t : uint16_t

Registered app ids.

Enumerator
k_wa_app_library 

Library / home app.

k_wa_app_reader 

EPUB reader app.

Definition at line 74 of file main.c.

◆ wa_consts_t

enum wa_consts_t : uint32_t

Console / layout knobs (no magic numbers).

Enumerator
k_wa_uart_baud 

Console baud.

k_wa_fb_w 

Framebuffer width, pixels.

k_wa_fb_h 

Framebuffer height, pixels.

k_wa_statusbar_h 

Status-bar widget height.

k_wa_col_bg 

Framebuffer clear colour.

k_wa_col_status 

Status-bar fill (gray).

k_wa_col_library 

Library content fill (blue).

k_wa_col_reader 

Reader content fill (orange).

k_wa_fnv_offset 

FNV-1a 32-bit offset basis.

k_wa_fnv_prime 

FNV-1a 32-bit prime.

k_wa_hex_nibbles 

Hex digits in a 32-bit value.

k_wa_nibble_bits 

Bits per hex nibble.

k_wa_nibble_mask 

Low-nibble mask.

k_wa_dec_ten 

Hex digit / decimal split.

Definition at line 56 of file main.c.

Function Documentation

◆ main()

void main ( void )

App entry: register two widget-tree apps, launch + composite each.

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 apps/CRC/flush banner is emitted; CPU loops in WFI.
Since
0.1.0

Definition at line 284 of file main.c.

References k_msg_boot, k_msg_fail, k_msg_flush, k_msg_freg, k_msg_ok, k_msg_pre, k_msg_rdr, k_ra8_gfx_format_rgb565, k_ra8_ok, k_wa_app_library, k_wa_app_reader, k_wa_app_vt, k_wa_col_library, k_wa_col_reader, k_wa_fb_h, k_wa_fb_w, ra8_app_register(), ra8_app_registry_init(), ra8_gfx_init(), ra8_isr_globals_enable(), s_framebuffer, s_library, s_reader, wa_panic_halt(), wa_print(), wa_print_hex(), wa_run_two_apps(), wa_setup_or_halt(), wa_state_init(), and wa_verify_or_halt().

◆ wa_app_enter()

void wa_app_enter ( ra8_app_t * a)
static

Definition at line 198 of file main.c.

◆ wa_app_leave()

void wa_app_leave ( ra8_app_t * a)
static

Definition at line 203 of file main.c.

◆ wa_app_render()

void wa_app_render ( const ra8_app_t * a)
static

◆ wa_fill_render()

void wa_fill_render ( ra8_widget_t * w)
static

Widget render callback: fill the widget's rect with its colour.

Definition at line 151 of file main.c.

References ra8_gfx_rect().

◆ wa_framebuffer_hash()

uint32_t wa_framebuffer_hash ( void )
static

FNV-1a hash over the composited framebuffer.

Definition at line 127 of file main.c.

References k_wa_fnv_offset, k_wa_fnv_prime, and s_framebuffer.

Referenced by wa_run_two_apps().

◆ wa_panic_halt()

void wa_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 117 of file main.c.

References wa_print().

Referenced by main(), wa_run_two_apps(), wa_setup_or_halt(), and wa_verify_or_halt().

◆ wa_print()

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

Emit a byte run on the SCI8 console.

Definition at line 111 of file main.c.

References ra8_board_uart_console_write().

Referenced by main(), wa_panic_halt(), and wa_print_hex().

◆ wa_print_hex()

void wa_print_hex ( uint32_t value)
static

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

Definition at line 139 of file main.c.

References k_wa_dec_ten, k_wa_hex_nibbles, k_wa_nibble_bits, k_wa_nibble_mask, and wa_print().

Referenced by main().

◆ wa_run_two_apps()

void wa_run_two_apps ( ra8_app_registry_t * reg,
uint32_t * out_lib,
uint32_t * out_rdr )
static

Launch + composite both apps, returning each composite's hash.

Definition at line 238 of file main.c.

References k_msg_freg, k_ra8_ok, k_wa_app_library, k_wa_app_reader, ra8_app_launch(), ra8_app_render(), wa_framebuffer_hash(), and wa_panic_halt().

Referenced by main().

◆ wa_setup_or_halt()

void wa_setup_or_halt ( void )
static

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

Definition at line 220 of file main.c.

References k_msg_fail, k_ra8_clock_id_cpuclk0, k_ra8_ok, k_wa_uart_baud, ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), ra8_mstp_init(), ra8_time_init(), and wa_panic_halt().

Referenced by main().

◆ wa_state_init()

void wa_state_init ( wa_app_state_t * st,
uint32_t content_color )
static

Build one app's widget tree: status bar (fixed) over content (flex).

Definition at line 165 of file main.c.

References wa_fill_t::color, wa_app_state_t::content_fill, wa_app_state_t::enters, k_wa_col_status, k_wa_fill_vt, k_wa_statusbar_h, wa_app_state_t::leaves, wa_app_state_t::status_fill, and wa_app_state_t::widgets.

Referenced by main().

◆ wa_verify_or_halt()

void wa_verify_or_halt ( uint32_t lib_crc,
uint32_t rdr_crc )
static

Variable Documentation

◆ k_msg_boot

const uint8_t k_msg_boot[] = "widget-app-hil: boot\r\n"
static

Definition at line 99 of file main.c.

◆ k_msg_fail

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

Definition at line 100 of file main.c.

◆ k_msg_fcrc

const uint8_t k_msg_fcrc[] = "widget-app-hil: FAIL crc-equal\r\n"
static

Definition at line 102 of file main.c.

◆ k_msg_fdmg

const uint8_t k_msg_fdmg[] = "widget-app-hil: FAIL damage\r\n"
static

Definition at line 104 of file main.c.

Referenced by wa_verify_or_halt().

◆ k_msg_flife

const uint8_t k_msg_flife[] = "widget-app-hil: FAIL lifecycle\r\n"
static

Definition at line 103 of file main.c.

Referenced by wa_verify_or_halt().

◆ k_msg_flush

const uint8_t k_msg_flush[] = " flush=160x16 hint=fast"
static

Definition at line 107 of file main.c.

Referenced by main().

◆ k_msg_freg

const uint8_t k_msg_freg[] = "widget-app-hil: FAIL register\r\n"
static

Definition at line 101 of file main.c.

Referenced by main(), and wa_run_two_apps().

◆ k_msg_ok

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

Definition at line 108 of file main.c.

◆ k_msg_pre

const uint8_t k_msg_pre[] = "widget-app-hil: apps=2 lib="
static

Definition at line 105 of file main.c.

◆ k_msg_rdr

const uint8_t k_msg_rdr[] = " rdr="
static

Definition at line 106 of file main.c.

Referenced by main().

◆ k_wa_app_vt

const ra8_app_vtable_t k_wa_app_vt
static
Initial value:
= {
.init = nullptr,
.on_enter = wa_app_enter,
.tick = nullptr,
.render = wa_app_render,
.on_input = nullptr,
.on_leave = wa_app_leave,
.deinit = nullptr,
}
static void wa_app_leave(ra8_app_t *a)
Definition main.c:203
static void wa_app_enter(ra8_app_t *a)
Definition main.c:198
static void wa_app_render(const ra8_app_t *a)
App.render: lay out + composite the app's widget tree.
Definition main.c:186

Shared app lifecycle vtable.

Definition at line 209 of file main.c.

Referenced by main().

◆ k_wa_fill_vt

const ra8_widget_vtable_t k_wa_fill_vt
static
Initial value:
= {
.measure = nullptr,
.render = wa_fill_render,
.on_input = nullptr,
}
static void wa_fill_render(ra8_widget_t *w)
Widget render callback: fill the widget's rect with its colour.
Definition main.c:151

Shared vtable for the solid-fill widget.

Definition at line 158 of file main.c.

Referenced by wa_state_init().

◆ s_framebuffer

uint16_t s_framebuffer[(size_t) k_wa_fb_h *(size_t) k_wa_fb_w]
static

RGB565 framebuffer all widgets composite into.

Definition at line 80 of file main.c.

◆ s_library

wa_app_state_t s_library
static

Definition at line 96 of file main.c.

Referenced by main(), wa_verify_or_halt(), wd_register_apps(), and wd_selfcheck().

◆ s_reader

wa_app_state_t s_reader
static

Definition at line 97 of file main.c.