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 the GLCDC layer-1 render path. More...

#include <stdint.h>
#include "ra8_board_ek_ra8d2.h"
#include "ra8_boot_entry.h"
#include "ra8_cgc.h"
#include "ra8_display_pal.h"
#include "ra8_display_pal_lcd.h"
#include "ra8_err.h"
#include "ra8_glcdc.h"
#include "ra8_isr.h"
#include "ra8_mstp.h"
#include "ra8_panel.h"
#include "ra8_panel_timing.h"
#include "ra8_time.h"
Include dependency graph for main.c:

Go to the source code of this file.

Enumerations

enum  glcdc_hil_geom_t : uint16_t {
  k_gh_fb_w = 512U ,
  k_gh_fb_h = 512U ,
  k_gh_x_thickness = 4U
}
 Framebuffer geometry constants. More...
enum  glcdc_hil_color_t : uint16_t {
  k_gh_color_bg = 0x001FU ,
  k_gh_color_x = 0xFFE0U ,
  k_gh_color_border = 0xFFFFU
}
 RGB565 palette for the deterministic render pattern. More...
enum  glcdc_hil_console_t : uint32_t {
  k_gh_uart_baud = 115200U ,
  k_gh_fnv_offset = 2166136261U ,
  k_gh_fnv_prime = 16777619U ,
  k_gh_hex_nibbles = 8U ,
  k_gh_nibble_bits = 4U ,
  k_gh_nibble_mask = 0x0FU ,
  k_gh_dec_ten = 10U
}
 SCI8 J-Link OB console + text-format constants. More...

Functions

static void gh_print (const uint8_t *msg, uint32_t len)
 Emit a byte run on the SCI8 console.
static void gh_panic_halt (void)
 Park forever in WFI after a fatal init error.
static void gh_print_hex (uint32_t value)
 Print value as 8 uppercase hex digits.
static void gh_print_uint (uint32_t value)
 Print a small unsigned integer in decimal.
static void gh_fb_fill (uint16_t color)
 Fill the whole framebuffer with color.
static void gh_draw_x (uint16_t color)
 Draw a thick corner-to-corner X in color.
static void gh_draw_border (uint16_t color)
 Draw a 1-px border around the whole framebuffer in color.
static void gh_render_pattern (void)
 Paint the full deterministic render pattern.
static uint32_t gh_framebuffer_hash (void)
 FNV-1a-32 over the rendered framebuffer bytes.
static bool gh_glcdc_programmed (void)
 Bring the GLCDC layer-1 path up and prove it is programmed.
static void gh_setup_or_halt (void)
 Bring up clocks/MSTP/time + the SCI8 console; halt on failure.
void main (void)
 App entry: paint, bring the GLCDC up, hash, print the banner.

Variables

static uint16_t s_framebuffer [(uint32_t) k_gh_fb_w *(uint32_t) k_gh_fb_h]
 Render target in internal SRAM, 64-byte AXI-burst aligned so the GLCDC's AXI fetches are clean.
static const display_cfg_t k_gh_display_cfg
 Display PAL config selecting the GLCDC LCD backend.
volatile uint32_t g_glcdc_hil_ok = 0U
 1 once the GLCDC layer-1 render path is confirmed programmed.
volatile uint32_t g_glcdc_hil_crc = 0U
 FNV-1a-32 of the rendered framebuffer (the on-bench baseline).
volatile uint32_t g_glcdc_hil_status = 0U
 Last GLCDC SYS_STAT snapshot (diagnostic; not part of the CRC).
volatile uint32_t g_glcdc_hil_heartbeat = 0U
 Bumps on every idle-loop pass after a passing render.
static const uint8_t k_gh_msg_boot [] = "glcdc-hil: boot\r\n"
static const uint8_t k_gh_msg_fail_init [] = "glcdc-hil: FAIL init\r\n"
static const uint8_t k_gh_msg_fail_glcdc [] = "glcdc-hil: FAIL glcdc\r\n"
static const uint8_t k_gh_msg_pre [] = "glcdc-hil: layer1=ok dim="
static const uint8_t k_gh_msg_x [] = "x"
static const uint8_t k_gh_msg_crc [] = " crc="
static const uint8_t k_gh_msg_pass [] = " PASS\r\n"

Detailed Description

Headless on-silicon HIL gate for the GLCDC layer-1 render path.

Tag
[Ring 6 / APP] {World: S}

ereader_chrome gates the software rasteriser (ra8_box + ra8_gfx into an SRAM buffer) but never touches the display controller. This app closes the remaining gap: it proves the GLCDC hardware layer-1 render path is programmed and scanning a real framebuffer, deterministically and headlessly, with no human looking at the panel.

Sequence:

  1. Paint a deterministic RGB565 pattern (dark-blue field, yellow corner-to- corner X, white 1-px border) into a 512x512 SRAM framebuffer.
  2. Bring the panel up through the display PAL (display_init with the k_display_backend_lcd_ra8_glcdc backend), which runs the full GLCDC bring-up: panel power-on, GLCDC pin/clock setup, ra8_glcdc_init, background clear, ra8_glcdc_start(true), ra8_glcdc_layer1_show.
  3. Assert the hardware layer is actually programmed:
  4. Fold an FNV-1a-32 hash over the whole framebuffer and emit the result on the SCI8 J-Link OB console:

    glcdc-hil: layer1=ok dim=512x512 crc=<8 hex> PASS

The HIL gate (hil.conf, uart_scrape) asserts that line. The render is deterministic (integer paint into a zeroed static buffer), so the CRC is the same every boot; the layer1=ok ... PASS tail is only emitted once the GLCDC programming asserts above all hold – any GLCDC bring-up failure prints glcdc-hil: FAIL glcdc and trips the gate's negative match.

On ra8_emulator the panel compositor reads the GLCDC GR1 framebuffer registers to build the panel image, so a --ppm snapshot also shows the painted pattern – independent confirmation that the GR1 registers point at the buffer. The same FNV-1a-32 globals are exported for --dump-sym memprobe.

Since
0.1.0

Definition in file main.c.

Enumeration Type Documentation

◆ glcdc_hil_color_t

enum glcdc_hil_color_t : uint16_t

RGB565 palette for the deterministic render pattern.

Since
0.1.0
Enumerator
k_gh_color_bg 

Dark blue field.

k_gh_color_x 

Yellow diagonal X.

k_gh_color_border 

White 1-px frame.

Definition at line 88 of file main.c.

◆ glcdc_hil_console_t

enum glcdc_hil_console_t : uint32_t

SCI8 J-Link OB console + text-format constants.

Since
0.1.0
Enumerator
k_gh_uart_baud 

Console baud.

k_gh_fnv_offset 

FNV-1a-32 offset basis.

k_gh_fnv_prime 

FNV-1a-32 prime.

k_gh_hex_nibbles 

Hex digits in a 32-bit value.

k_gh_nibble_bits 

Bits per hex nibble.

k_gh_nibble_mask 

Low-nibble mask.

k_gh_dec_ten 

Hex digit / decimal split + buf.

Definition at line 100 of file main.c.

◆ glcdc_hil_geom_t

enum glcdc_hil_geom_t : uint16_t

Framebuffer geometry constants.

512x512 RGB565 (0.5 MiB) sits in internal SRAM and is composited top-left over the BG plane – the same size lcd_draw_x uses, since the 1024x600 panel framebuffer (1.2 MiB) does not fit on-chip and SDRAM bring-up is a separate task.

Since
0.1.0
Enumerator
k_gh_fb_w 

Framebuffer width, pixels.

k_gh_fb_h 

Framebuffer height, pixels.

k_gh_x_thickness 

Diagonal-X half thickness, pixels.

Definition at line 76 of file main.c.

Function Documentation

◆ gh_draw_border()

void gh_draw_border ( uint16_t color)
static

Draw a 1-px border around the whole framebuffer in color.

Definition at line 263 of file main.c.

References k_gh_fb_h, k_gh_fb_w, and s_framebuffer.

Referenced by gh_render_pattern().

◆ gh_draw_x()

void gh_draw_x ( uint16_t color)
static

Draw a thick corner-to-corner X in color.

Definition at line 244 of file main.c.

References k_gh_fb_h, k_gh_fb_w, k_gh_x_thickness, and s_framebuffer.

Referenced by gh_render_pattern().

◆ gh_fb_fill()

void gh_fb_fill ( uint16_t color)
static

Fill the whole framebuffer with color.

Definition at line 236 of file main.c.

References k_gh_fb_h, k_gh_fb_w, and s_framebuffer.

Referenced by gh_render_pattern().

◆ gh_framebuffer_hash()

uint32_t gh_framebuffer_hash ( void )
static

FNV-1a-32 over the rendered framebuffer bytes.

Definition at line 289 of file main.c.

References k_gh_fnv_offset, k_gh_fnv_prime, and s_framebuffer.

Referenced by main().

◆ gh_glcdc_programmed()

bool gh_glcdc_programmed ( void )
static

Bring the GLCDC layer-1 path up and prove it is programmed.

Runs display_init (full GLCDC bring-up) then asserts three independent facts: the init succeeded with a live handle, the bound framebuffer the backend reports is our exact buffer (GR1 fetch points here), and the GLCDC SYS_STAT register is reachable. The status mask itself is snapshotted for diagnostics but deliberately excluded from the deterministic banner because it is a live, free-running register.

Returns
true when all three GLCDC-programmed assertions hold.
Return values
trueGLCDC layer-1 is programmed and scanning s_framebuffer.
falseAny bring-up or binding assertion failed.
Precondition
gh_setup_or_halt has run (clocks, MSTP, console up).
s_framebuffer has been painted.
Postcondition
On true, g_glcdc_hil_status holds the SYS_STAT snapshot.
No framebuffer bytes are modified.
Note
Not thread-safe; single-shot bring-up helper.
Since
0.1.0

Definition at line 328 of file main.c.

References display_get_framebuffer(), display_init(), g_glcdc_hil_status, k_gh_display_cfg, k_ra8_ok, display_fb_t::pixels, ra8_glcdc_get_status(), and s_framebuffer.

Referenced by main().

◆ gh_panic_halt()

void gh_panic_halt ( void )
static

Park forever in WFI after a fatal init error.

Definition at line 191 of file main.c.

References gh_print(), and k_gh_msg_fail_init.

Referenced by gh_setup_or_halt().

◆ gh_print()

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

Emit a byte run on the SCI8 console.

Definition at line 185 of file main.c.

References ra8_board_uart_console_write().

Referenced by gh_panic_halt(), gh_print_hex(), gh_print_uint(), and main().

◆ gh_print_hex()

void gh_print_hex ( uint32_t value)
static

Print value as 8 uppercase hex digits.

Definition at line 200 of file main.c.

References gh_print(), k_gh_dec_ten, k_gh_hex_nibbles, k_gh_nibble_bits, and k_gh_nibble_mask.

Referenced by main().

◆ gh_print_uint()

void gh_print_uint ( uint32_t value)
static

Print a small unsigned integer in decimal.

Definition at line 212 of file main.c.

References gh_print(), and k_gh_dec_ten.

Referenced by main().

◆ gh_render_pattern()

void gh_render_pattern ( void )
static

Paint the full deterministic render pattern.

Definition at line 278 of file main.c.

References gh_draw_border(), gh_draw_x(), gh_fb_fill(), k_gh_color_bg, k_gh_color_border, and k_gh_color_x.

Referenced by main().

◆ gh_setup_or_halt()

void gh_setup_or_halt ( void )
static

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

Definition at line 353 of file main.c.

References gh_panic_halt(), k_gh_uart_baud, 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: paint, bring the GLCDC up, hash, print the banner.

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 layer1=ok ... PASS banner is emitted on a programmed GLCDC, or FAIL glcdc on a bring-up failure; the CPU then loops in WFI.
Since
0.1.0

Definition at line 384 of file main.c.

References g_glcdc_hil_crc, g_glcdc_hil_heartbeat, g_glcdc_hil_ok, gh_framebuffer_hash(), gh_glcdc_programmed(), gh_print(), gh_print_hex(), gh_print_uint(), gh_render_pattern(), gh_setup_or_halt(), k_gh_fb_h, k_gh_fb_w, k_gh_msg_boot, k_gh_msg_crc, k_gh_msg_fail_glcdc, k_gh_msg_pass, k_gh_msg_pre, k_gh_msg_x, and ra8_isr_globals_enable().

Variable Documentation

◆ g_glcdc_hil_crc

volatile uint32_t g_glcdc_hil_crc = 0U

FNV-1a-32 of the rendered framebuffer (the on-bench baseline).

Note
Exported for ra8_emulator --dump-sym memprobe.
Warning
Written only by main.
Since
0.1.0

Definition at line 153 of file main.c.

Referenced by main().

◆ g_glcdc_hil_heartbeat

volatile uint32_t g_glcdc_hil_heartbeat = 0U

Bumps on every idle-loop pass after a passing render.

Note
Exported for ra8_emulator --dump-sym liveness checks.
Warning
Written only by main.
Since
0.1.0

Definition at line 169 of file main.c.

Referenced by main().

◆ g_glcdc_hil_ok

volatile uint32_t g_glcdc_hil_ok = 0U

1 once the GLCDC layer-1 render path is confirmed programmed.

Note
Exported for ra8_emulator --dump-sym memprobe; the gate is uart_scrape.
Warning
Written only by main; readers must treat it as read-only.
Since
0.1.0

Definition at line 145 of file main.c.

Referenced by main().

◆ g_glcdc_hil_status

volatile uint32_t g_glcdc_hil_status = 0U

Last GLCDC SYS_STAT snapshot (diagnostic; not part of the CRC).

Note
Non-deterministic register on ra8_emulator; kept out of the banner.
Warning
Written only by main.
Since
0.1.0

Definition at line 161 of file main.c.

Referenced by gh_glcdc_programmed().

◆ k_gh_display_cfg

const display_cfg_t k_gh_display_cfg
static
Initial value:
= {
.framebuffer = s_framebuffer,
.framebuffer_bytes = sizeof(s_framebuffer),
.width_px = (uint16_t)k_gh_fb_w,
.height_px = (uint16_t)k_gh_fb_h,
.panel_timing = &s_ra8_panel_ek_ra8d2_timing,
}
static uint16_t s_framebuffer[(size_t) k_panel_height_px *(size_t) k_panel_width_px]
1024x600 RGB565 framebuffer in external SDRAM (GLCDC scans this).
Definition main.c:67
@ k_gh_fb_w
Framebuffer width, pixels.
Definition main.c:77
@ k_gh_fb_h
Framebuffer height, pixels.
Definition main.c:78
@ k_display_pixfmt_rgb565
16 bpp, 5/6/5 packed.
const display_backend_iface_t k_display_backend_lcd_ra8_glcdc
LCD backend vtable – pass its address through display_cfg_t.iface to drive the EK-RA8D2 panel.
static const ra8_glcdc_timing_t s_ra8_panel_ek_ra8d2_timing
EK-RA8D2 ER-TFT070-6 RGB timing for ra8_glcdc_init / the LCD backend.

Display PAL config selecting the GLCDC LCD backend.

Backend-agnostic: re-pointing iface at a different backend (e.g. an e-ink controller) is the only change needed to gate that path instead. The panel timing is the board BSP's EK-RA8D2 descriptor.

Since
0.1.0

Definition at line 128 of file main.c.

Referenced by gh_glcdc_programmed().

◆ k_gh_msg_boot

const uint8_t k_gh_msg_boot[] = "glcdc-hil: boot\r\n"
static

Definition at line 171 of file main.c.

Referenced by main().

◆ k_gh_msg_crc

const uint8_t k_gh_msg_crc[] = " crc="
static

Definition at line 176 of file main.c.

Referenced by main().

◆ k_gh_msg_fail_glcdc

const uint8_t k_gh_msg_fail_glcdc[] = "glcdc-hil: FAIL glcdc\r\n"
static

Definition at line 173 of file main.c.

Referenced by main().

◆ k_gh_msg_fail_init

const uint8_t k_gh_msg_fail_init[] = "glcdc-hil: FAIL init\r\n"
static

Definition at line 172 of file main.c.

Referenced by gh_panic_halt().

◆ k_gh_msg_pass

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

Definition at line 177 of file main.c.

Referenced by main().

◆ k_gh_msg_pre

const uint8_t k_gh_msg_pre[] = "glcdc-hil: layer1=ok dim="
static

Definition at line 174 of file main.c.

Referenced by main().

◆ k_gh_msg_x

const uint8_t k_gh_msg_x[] = "x"
static

Definition at line 175 of file main.c.

Referenced by main().

◆ s_framebuffer

uint16_t s_framebuffer[(uint32_t) k_gh_fb_w *(uint32_t) k_gh_fb_h]
static

Render target in internal SRAM, 64-byte AXI-burst aligned so the GLCDC's AXI fetches are clean.

Since
0.1.0

Definition at line 116 of file main.c.