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: BMP + GIF decode format-coverage gate (#143). More...

#include <stddef.h>
#include <stdint.h>
#include "imgfmt_fixtures.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 "reflow_image.h"
Include dependency graph for main.c:

Go to the source code of this file.

Enumerations

enum  ef_consts_t : uint32_t {
  k_ef_uart_baud = 115200U ,
  k_ef_fb_w = 160U ,
  k_ef_fb_h = 120U ,
  k_ef_arena_bytes = 128U * 1024U ,
  k_ef_col_bg = 0x202028U ,
  k_ef_fnv_offset = 0x811C9DC5U ,
  k_ef_fnv_prime = 0x01000193U ,
  k_ef_hex_nibbles = 8U ,
  k_ef_nibble_bits = 4U ,
  k_ef_nibble_mask = 0x0FU ,
  k_ef_dec_ten = 10U
}
 Console / render knobs (no magic numbers). More...

Functions

static void ef_print (const uint8_t *msg, uint32_t len)
 Emit a byte run on the SCI8 console.
static void ef_panic_halt (const uint8_t *msg, uint32_t len)
 Print the fail banner and trap (ra8_emulator halts on the BKPT).
static uint32_t ef_framebuffer_hash (void)
 FNV-1a hash over the rendered framebuffer.
static void ef_print_hex (uint32_t value)
 Print a 32-bit value as 8 upper-case hex digits.
static void ef_setup_or_halt (void)
 Bring up clocks/MSTP/time + the SCI8 console; halt on failure.
static uint32_t ef_decode_and_hash (const uint8_t *bytes, size_t len, const uint8_t *fail_msg, uint32_t fail_len)
 Clear the framebuffer, decode+scale+blit one image, hash the result.
void main (void)
 App entry: decode the baked BMP + GIF on silicon, print the banner.

Variables

static uint16_t s_framebuffer [(size_t) k_ef_fb_h *(size_t) k_ef_fb_w]
 RGB565 framebuffer each image is rendered into.
static uint8_t s_img_arena [k_ef_arena_bytes]
 Fixed bump arena backing the heap-free image decode.
static const uint8_t k_msg_boot [] = "ereader-imgfmt-hil: boot\r\n"
static const uint8_t k_msg_fail [] = "ereader-imgfmt-hil: FAIL init\r\n"
static const uint8_t k_msg_dbmp [] = "ereader-imgfmt-hil: FAIL bmp\r\n"
static const uint8_t k_msg_dgif [] = "ereader-imgfmt-hil: FAIL gif\r\n"
static const uint8_t k_msg_pre [] = "ereader-imgfmt-hil: bmp="
static const uint8_t k_msg_gif [] = " gif="
static const uint8_t k_msg_ok [] = " PASS\r\n"

Detailed Description

On-silicon HIL: BMP + GIF decode format-coverage gate (#143).

Closes the stb_image format-coverage gap: the firmware links four decoders (STBI_ONLY_JPEG/PNG/GIF/BMP in stb_image_impl.c), but only PNG (ereader_image, #106) and JPEG (ereader_jpeg) had a gate. This app exercises the remaining two – BMP and GIF – end to end through the same zero-heap ra8_img_decode_blit pipeline, so any drift in those decoders trips a gate.

  1. ra8_gfx_init – bind a 160x120 RGB565 framebuffer.
  2. For each format: clear the framebuffer, ra8_img_decode_blit the baked image (decode + aspect-preserving scale-to-fit + blit, allocating only from a fixed 128 KiB SRAM bump arena – no malloc, NASA Rule 3), then FNV-1a-32 hash the framebuffer.

The console banner on success is:

ereader-imgfmt-hil: bmp=<8hex> gif=<8hex> PASS

Deterministic (fixed blobs through deterministic decoders + scaler), so the banner is identical on host, ra8_emulator, and silicon. A decode failure prints a FAIL banner and halts on a BKPT before the PASS line, so the gate is exact.

[Ring 7 / App] {World: NS}

Since
0.1.0

Definition in file main.c.

Enumeration Type Documentation

◆ ef_consts_t

enum ef_consts_t : uint32_t

Console / render knobs (no magic numbers).

Enumerator
k_ef_uart_baud 

Console baud.

k_ef_fb_w 

Framebuffer width, pixels.

k_ef_fb_h 

Framebuffer height, pixels.

k_ef_arena_bytes 

Image decode scratch, bytes.

k_ef_col_bg 

Framebuffer clear colour.

k_ef_fnv_offset 

FNV-1a 32-bit offset basis.

k_ef_fnv_prime 

FNV-1a 32-bit prime.

k_ef_hex_nibbles 

Hex digits in a 32-bit value.

k_ef_nibble_bits 

Bits per hex nibble.

k_ef_nibble_mask 

Low-nibble mask.

k_ef_dec_ten 

Hex digit / decimal split.

Definition at line 50 of file main.c.

Function Documentation

◆ ef_decode_and_hash()

uint32_t ef_decode_and_hash ( const uint8_t * bytes,
size_t len,
const uint8_t * fail_msg,
uint32_t fail_len )
static

Clear the framebuffer, decode+scale+blit one image, hash the result.

Halts on decode failure before returning.

Parameters
[in]bytesEncoded image bytes (BMP or GIF).
[in]lenLength of bytes.
[in]fail_msgBanner emitted (then BKPT) if the decode fails.
[in]fail_lenLength of fail_msg.
Returns
The FNV-1a hash of the framebuffer after the blit.
Precondition
ra8_gfx_init bound s_framebuffer.
Postcondition
s_framebuffer holds the scaled image; the arena is reset to empty.
Since
0.1.0

Definition at line 151 of file main.c.

References ef_framebuffer_hash(), ef_panic_halt(), k_ef_arena_bytes, k_ef_col_bg, k_ef_fb_h, k_ef_fb_w, k_ra8_ok, ra8_gfx_clear(), ra8_img_decode_blit(), and s_img_arena.

Referenced by main().

◆ ef_framebuffer_hash()

uint32_t ef_framebuffer_hash ( void )
static

FNV-1a hash over the rendered framebuffer.

Definition at line 94 of file main.c.

References k_ef_fnv_offset, k_ef_fnv_prime, and s_framebuffer.

Referenced by ef_decode_and_hash().

◆ ef_panic_halt()

void ef_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 84 of file main.c.

References ef_print().

Referenced by ef_decode_and_hash(), ef_setup_or_halt(), and main().

◆ ef_print()

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

Emit a byte run on the SCI8 console.

Definition at line 78 of file main.c.

References ra8_board_uart_console_write().

Referenced by ef_panic_halt(), ef_print_hex(), and main().

◆ ef_print_hex()

void ef_print_hex ( uint32_t value)
static

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

Definition at line 106 of file main.c.

References ef_print(), k_ef_dec_ten, k_ef_hex_nibbles, k_ef_nibble_bits, and k_ef_nibble_mask.

Referenced by main().

◆ ef_setup_or_halt()

void ef_setup_or_halt ( void )
static

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

Definition at line 118 of file main.c.

References ef_panic_halt(), k_ef_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: decode the baked BMP + GIF on silicon, 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 bmp/gif framebuffer-CRC banner is emitted; CPU loops in WFI.
Since
0.1.0

Definition at line 182 of file main.c.

References ef_decode_and_hash(), ef_panic_halt(), ef_print(), ef_print_hex(), ef_setup_or_halt(), k_bmp, k_bmp_len, k_ef_fb_h, k_ef_fb_w, k_gif, k_gif_len, k_msg_boot, k_msg_dbmp, k_msg_dgif, k_msg_fail, k_msg_gif, k_msg_ok, k_msg_pre, k_ra8_gfx_format_rgb565, k_ra8_ok, ra8_gfx_init(), ra8_isr_globals_enable(), and s_framebuffer.

Variable Documentation

◆ k_msg_boot

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

Definition at line 69 of file main.c.

◆ k_msg_dbmp

const uint8_t k_msg_dbmp[] = "ereader-imgfmt-hil: FAIL bmp\r\n"
static

Definition at line 71 of file main.c.

Referenced by main().

◆ k_msg_dgif

const uint8_t k_msg_dgif[] = "ereader-imgfmt-hil: FAIL gif\r\n"
static

Definition at line 72 of file main.c.

Referenced by main().

◆ k_msg_fail

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

Definition at line 70 of file main.c.

◆ k_msg_gif

const uint8_t k_msg_gif[] = " gif="
static

Definition at line 74 of file main.c.

Referenced by main().

◆ k_msg_ok

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

Definition at line 75 of file main.c.

◆ k_msg_pre

const uint8_t k_msg_pre[] = "ereader-imgfmt-hil: bmp="
static

Definition at line 73 of file main.c.

◆ s_framebuffer

uint16_t s_framebuffer[(size_t) k_ef_fb_h *(size_t) k_ef_fb_w]
static

RGB565 framebuffer each image is rendered into.

Definition at line 65 of file main.c.

◆ s_img_arena

uint8_t s_img_arena[k_ef_arena_bytes]
static

Fixed bump arena backing the heap-free image decode.

Definition at line 67 of file main.c.