60typedef enum : uint8_t {
115 if (st->
view ==
nullptr) {
116 (void)
priv_emu_io_errf(
"ra8_emulator: could not open window; continuing headless\n");
145 uint32_t click_tab_idx = 0U;
245 bool wdt_rst =
false;
246 bool iwdt_rst =
false;
292 const uint8_t kb = (uint8_t)key_byte;
311 uint16_t cnx = (uint16_t)cfg->
click_x;
312 uint16_t cny = (uint16_t)cfg->
click_y;
396 k_rec_path_cap = 1024U,
398 char fpath[k_rec_path_cap];
399 (void)snprintf(fpath,
430 struct timespec ts_now = {};
431 (void)clock_gettime(CLOCK_MONOTONIC, &ts_now);
432 const uint64_t now_us = ((uint64_t)ts_now.tv_sec * (uint64_t)
k_us_per_s) +
433 ((uint64_t)ts_now.tv_nsec / (uint64_t)
k_ns_per_us);
531 (((
double)(clock() - st->
t0) / (
double)CLOCKS_PER_SEC) >= st->
guards.
wall_s)) {
677 if (stop_on ==
nullptr) {
683 const bool hit = ((last_uart !=
nullptr) && (
strstr(last_uart, stop_on) !=
nullptr)) ||
684 ((last_itm !=
nullptr) && (
strstr(last_itm, stop_on) !=
nullptr)) ||
685 ((last_rtt !=
nullptr) && (
strstr(last_rtt, stop_on) !=
nullptr));
746 (((
double)(clock() - st->
t0) / (
double)CLOCKS_PER_SEC) >= st->
guards.
wall_s)) {
801 if (st->
view !=
nullptr) {
Multi-channel console log store backing the board view's tabbed console.
const char * board_console_line(board_console_ch_t ch, uint32_t back)
Fetch a retained line by age (0 = newest) from a channel.
@ k_board_console_ch_itm
CoreSight ITM/SWO trace ([itm]).
@ k_board_console_ch_count
Channel count (ring + tab array size).
@ k_board_console_ch_rtt
SEGGER RTT up-buffer 0 drain ([rtt]).
Virtual network peer for ra8_emulator – talks TCP/IP to the firmware.
void board_net_tick(void)
Advance the peer's state machine one tick (ARP -> ping -> TCP echo).
Composite board-view renderer: panel framebuffer + a status sidebar.
board_overlay_btn_t board_overlay_hit_button(uint16_t x, uint16_t y, uint16_t panel_w)
Classify a composite-space click against the sidebar's on-screen buttons.
board_overlay_btn_t
On-screen sidebar control a click landed on.
@ k_board_overlay_btn_sw2
On-screen SW2 (P008) push-button.
@ k_board_overlay_btn_battery
Battery slider track: set SOC.
@ k_board_overlay_btn_batt_chg
Battery CHG button: toggle charge.
@ k_board_overlay_btn_none
Click did not land on a control.
@ k_board_overlay_btn_lowpower
CORE low-power toggle button.
@ k_board_overlay_btn_sw1
On-screen SW1 (P009) push-button.
bool board_overlay_hit_console_tab(uint16_t x, uint16_t y, uint16_t panel_w, uint32_t tab_count, uint32_t *out_idx)
Map a composite-space click on the console tab bar to a tab index.
Register-accurate peripheral-model framework for the board emulator.
void board_periph_tick(uc_engine *uc)
Advance every modelled timer by one emulation chunk and raise events.
void board_periph_sci_feed_rx(uint8_t channel, const uint8_t *data, uint32_t len)
Queue host->firmware bytes for a channel's receive path.
void board_periph_reset_set_cause(bool power_on, bool software, bool watchdog, bool iwdt)
Record the cause of a warm reboot in the sticky RSTSRn flags.
const char * board_periph_uart_last_line(void)
The most recent complete line the firmware transmitted over any SCI.
uint8_t board_periph_sci_console_channel(void)
The SCI channel the EK-RA8D2 console (J-Link OB VCOM) uses.
uint32_t board_periph_irq_total(void)
Total NVIC interrupts the ICU has delivered in this run.
uint32_t board_periph_touch_reported(void)
Count of touch contacts the firmware has drained from the GT911 model.
bool board_periph_reset_take_request(bool *out_watchdog, bool *out_iwdt)
Consume a pending peripheral reboot request, if any (run-loop side).
void board_periph_touch_inject(uint16_t x, uint16_t y)
Arm a pending touch contact for the modelled GT911 device.
SD-card-over-SPI device model for ra8_emulator (attached to SPI_B).
USBFS controller model + a virtual USB host for the board emulator.
bool board_usb_configured(void)
Report whether enumeration reached the CONFIGURED state.
Minimal self-contained macOS window for the board emulator.
bool board_view_poll_click(board_view_t *view, uint16_t *x, uint16_t *y)
Report the most recent unprocessed left mouse-down, once.
bool board_view_poll_drag(board_view_t *view, uint16_t *x, uint16_t *y)
Report the current position of a held-button drag, once.
bool board_view_pump(board_view_t *view)
Drain pending UI events; report whether the window was closed.
void board_view_present(board_view_t *view, emu_presentation_workspace_t *presentation)
Snapshot an RGB565 fd surface and request a redraw.
board_view_t * board_view_open(board_view_storage_t *storage, uint16_t width_px, uint16_t height_px, const char *title)
Open a desktop window of the given pixel size.
bool board_view_poll_release(board_view_t *view)
Report whether the primary mouse button was released since the last poll.
int32_t board_view_poll_scroll(board_view_t *view)
Drain the accumulated console scroll-wheel notches since the last poll.
Emulator text-console surfaces: UART echo, ITM/SWO echo, escapes.
Second-core (cpu1, Cortex-M33) engine: release watch, boot, stepping.
void emu_cpu1_step(void)
Boot cpu1 on a pending release, then step it one interleave chunk.
ELF32 image services for the board emulator (load / symbols / vectors).
uint32_t warm_reboot(uc_engine *uc, const emu_elf_source_t *elf, bool trace)
Warm-reboot the firmware: re-run from the reset vector in place.
Shared Unicorn engine access utilities for the board emulator.
Cortex-M exception model constants and interfaces for ra8_emulator.
void emu_exc_arm_systick(void)
Pend the periodic SysTick for this outer chunk.
void dwt_cyccnt_advance(uc_engine *uc)
Advance the DWT cycle counter by one outer chunk's worth of cycles.
uint32_t emu_exc_pendsv_takes(void)
PendSV exceptions taken this run (report + idle signature).
void emu_exc_clear_reboot_request(void)
Clear the latched warm-reboot request (after performing it).
bool emu_exc_reboot_requested(void)
Whether AIRCR.SYSRESETREQ requested a warm reboot.
uint32_t emu_exc_svc_takes(void)
SVCall exceptions taken this run (report + idle signature).
Bounded raw-descriptor I/O seam for the RA8 emulator.
emu_io_result_t priv_emu_io_errf(const char *format,...)
Format bounded text and write it to the injected error descriptor.
Shared aliased-memory backing and Unicorn memory-map bindings.
uc_err emu_mem_read(uc_engine *uc, uint64_t address, void *bytes, size_t count)
Read guest memory through the central access seam.
Sparse MMIO model of the Renesas peripheral space.
uint32_t emu_mmio_writes(void)
Total peripheral MMIO writes this run (monotonic).
uint32_t emu_mmio_reads(void)
Total peripheral MMIO reads this run (monotonic).
Armv8-M MPU enforcement model for ra8_emulator.
Firmware profiler (RA8_EMU_PROFILE): sampling, hooks, reports.
prof_mode_t emu_prof_mode(void)
The latched profiler mode.
@ k_prof_insn
=full/=insn: exact per-instruction + calls.
@ k_prof_wall
=1: cheap chunk-start wall-time sampler.
void prof_add(uint32_t pc, double dt)
Attribute wall seconds to the function owning pc (wall mode).
bool emu_prof_stop_hit(void)
Whether the RA8_EMU_STOP_PC address was reached.
double board_now_s(void)
Monotonic wall-clock seconds.
uint64_t emu_prof_total_insns(void)
Total instructions retired under the per-instruction hook.
static void internal_run_setup_geometry(const emu_run_cfg_t *cfg, run_loop_t *st)
Derive the presentation geometry from the panel size and rotation.
loop_action_t
Loop-control verdict a per-phase run-loop helper hands back.
@ k_loop_break
Leave the outer loop (stop condition / fault).
@ k_loop_continue
Restart the outer loop (reboot / tail-chain).
@ k_loop_next
Fall through to the next phase in the body.
static void internal_run_loop_tick_inputs(run_loop_t *st)
Arm the tick, advance time/peripherals, drain input, replay the click.
static loop_action_t internal_run_loop_click_tail(run_loop_t *st)
Run the bounded post-click tail and the CPU-time wall guard (headless).
static loop_action_t internal_run_loop_present_and_stops(run_loop_t *st)
Dispatch the per-chunk output / stop phase by run mode.
static bool internal_run_stop_idle(run_loop_t *st)
Steady-state idle early-stop (RA8_EMU_IDLE_STOP).
static bool internal_run_stop_usb(run_loop_t *st)
USB device- and host-mode enumeration early-stops.
static bool internal_run_stop_wall(run_loop_t *st)
CPU-time wall-clock safety guard (headless plain run).
static void internal_run_loop_setup(const emu_run_cfg_t *cfg, run_loop_t *st)
Populate the run state from the config before the chunk loop.
static void internal_run_open_view(const emu_run_cfg_t *cfg, run_loop_t *st)
Open the live window over the owned raw-fd surface when requested.
static bool internal_run_stop_sym(run_loop_t *st)
–stop-sym watched-global early-stop.
static void internal_run_loop(run_loop_t *st)
Drive the chunked run loop to a stop condition.
int emu_run_and_report(const emu_run_cfg_t *cfg)
Run the firmware to a stop condition, print the report, map the exit code.
static bool internal_run_stop_banner(run_loop_t *st)
Generic console-banner early-stop (RA8_EMU_STOP_ON).
static loop_action_t internal_run_loop_headless(run_loop_t *st)
Evaluate every headless plain-run early-stop in order.
static loop_action_t internal_run_loop_prologue(run_loop_t *st)
Run-loop prologue: wall-profiler charge, telemetry, warm reboots.
static loop_action_t internal_run_loop_view(run_loop_t *st)
Handle live-window mouse input, presenting, and the close request.
static void internal_run_classify_click(const emu_run_cfg_t *cfg, run_loop_t *st)
Classify a headless –click into a tab / button / panel target once.
static bool internal_run_stop_prof_idle(run_loop_t *st)
Profiler compute-idle early-stop (insn mode, build-stable).
static loop_action_t internal_run_loop_run_chunk(run_loop_t *st)
Run one chunk via priv_run_inner and service its post-chunk resets.
static void internal_run_loop_record(run_loop_t *st)
Step cpu1 and dump a –record frame at the recording cadence.
static void internal_run_view_maybe_present(run_loop_t *st)
Composite and present the live window at the ~60 Hz present cadence.
run_guards_t run_read_guards(const emu_run_cfg_t *cfg, const board_view_t *view)
Read the run-guard environment knobs (see run_guards_t).
Shared run-loop state + cross-TU run helpers (ra8_emulator internal).
void priv_run_report(const run_loop_t *st)
Print the run-end report (stop summary, verdict, –dump-sym probes).
void priv_run_write_outputs(const run_loop_t *st)
Write the –ppm snapshot and the –record summary line.
int priv_run_cleanup(const run_loop_t *st)
Save the SD image, close owned descriptors + engine, map the exit code.
bool priv_run_inner(uc_engine *uc, uint32_t vtor_base, uint32_t *run_pc_io, uc_err *err_out)
Run one outer chunk's inner exception-resolve loop.
void priv_run_hold_view(const run_loop_t *st)
Hold the live window on the final frame until the user closes it.
Armv8.1-M instruction-emulation seams (M85 ops on Unicorn's M33).
Virtual USB host-mode devices behind the ra8_usb_host_* / hmsc seams.
bool emu_usbh_done(void)
Whether the virtual host-mode device served its final request.
Board-view presentation: frames, composition, input routing, panels.
void apply_battery_click(board_overlay_btn_t btn, uint16_t cx, uint16_t disp_w)
Apply a POWER-section click to the fuel-gauge / core model.
void set_switch(board_overlay_btn_t btn, bool pressed)
Toggle a user switch's pressed level (active-low) for an on-screen button.
void emu_view_select_console_tab(uint32_t tab_idx)
Switch the visible console channel to tab_idx (tab-bar click).
void emu_view_publish(uint32_t pc, uint32_t chunks)
Publish the run-loop telemetry the board view shows.
@ k_view_yield_us
Yield this long when a present is skipped.
@ k_record_every
Chunks between recorded frames (1000/20).
@ k_view_frame_us
Min wall-us between live presents (~60 Hz).
@ k_view_present_every
Present the frame every Nth chunk.
@ k_ns_per_us
Nanoseconds per microsecond.
@ k_us_per_s
Microseconds per second.
@ k_reboot_settle
Chunks to run before a scheduled –reboot.
void emu_view_wheel(int32_t notches)
Page the console scrollback by mouse-wheel notches.
int write_ppm(const char *path, const emu_presentation_workspace_t *presentation)
Write an RGB565 frame to a binary PPM (P6) for headless inspection.
bool build_composite(uc_engine *uc, emu_presentation_workspace_t *presentation, const char *app_name)
Stream the panel and status sidebar into a raw-fd surface.
void unrotate_click(uint16_t cx, uint16_t cy, uint16_t panel_w, uint16_t panel_h, uint32_t deg, uint16_t *nx, uint16_t *ny)
Map a click in the rotated displayed panel back to native panel coords.
board_overlay_btn_t route_click(uint16_t cx, uint16_t cy, uint16_t panel_w, uint16_t panel_h, uint16_t disp_w, uint32_t rotate_deg)
Route a composite-space click to the right input model.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
char * strstr(const char *haystack, const char *needle)
Locate substring in string.
uint16_t panel_height
Native panel height.
uint16_t composite_width
Display plus sidebar width.
int fd
Owned unlinked descriptor, or -1.
uint16_t display_height
Rotation-adjusted panel height.
uint16_t composite_height
Display/sidebar maximum height.
uint16_t display_width
Rotation-adjusted panel width.
uint16_t panel_width
Native panel width.
Everything setup hands the run loop: engine, image, CLI products.
int click_y
–click row (composite pixels).
int click_x
–click column (composite pixels).
const char * record_dir
–record directory (NULL when unused).
bool want_click
–click armed.
const char * win_title
Window / sidebar caption.
bool want_view
–view (live window requested).
emu_elf_source_t * elf
Open caller-owned firmware source.
uint32_t initial_pc
Reset-vector PC (Thumb bit set).
bool want_trace
–trace (forwarded to warm reboots).
uint32_t stop_sym_thresh
–stop-sym threshold value.
uc_engine * uc
The prepared cpu0 engine.
uint32_t rotate_deg
–rotate display rotation.
uint32_t stop_sym_addr
–stop-sym resolved address (0 = off).
int reboot_count
–reboot N scheduled warm reboots.
uint32_t vtor_base
VTOR fallback (the MRAM vector base).
emu_presentation_workspace_t * presentation
Owned streamed frame surface.
uint32_t max_chunks
Outer-chunk budget.
bool wall_guard_on
false: WALL_S=0 disabled the guard.
uint32_t prof_idle_arm
Chunks before the profiler stop arms.
const char * stop_on
Console-banner stop substring (or NULL).
uint32_t click_settle_chunks
Post-click drain window (chunks).
uint32_t idle_stop_chunks
Idle steady-state stop (0 = off).
uint32_t prof_idle_insns
Profiler idle chunk threshold.
uint32_t usbh_stop_settle
USB host-mode early-stop settle.
uint32_t prof_idle_need
Consecutive idle chunks that stop.
double wall_s
CPU-time guard bound, seconds.
uint32_t usb_stop_settle
USB device-mode early-stop settle.
The whole run's mutable state, threaded through the phase helpers.
bool timed_out
Wall-clock guard fired.
board_overlay_btn_t held_btn
SW held down (released on up).
clock_t t0
CPU-time origin for the guard.
board_view_storage_t view_storage
Caller-owned live-view handle storage.
emu_presentation_workspace_t * presentation
Owned raw-fd presentation surface.
double prof_prev_t
Start time of the prior chunk.
bool usb_stopped
USB / banner early stop fired.
uint16_t comp_h
Composite (panel + sidebar) height.
uint32_t usb_stop_run
USB device settle countup.
uint32_t last_boot_chunk
Chunk of the last (re)boot.
int reboot_count
–reboot warm reboots remaining.
board_overlay_btn_t click_btn
Classified –click target button.
uint16_t panel_w
Firmware render width in pixels.
bool closed
Live window was closed.
board_view_t * view
Live window (NULL when headless).
uint32_t prof_prev_pc
PC charged by the wall profiler.
run_guards_t guards
Env-tunable budgets + stop conditions.
uint32_t rec_frames
–record frames written.
bool slider_grab
Battery slider grabbed by a drag.
uint32_t settle_left
Post-click drain countdown.
uint32_t idle_run
Consecutive steady-idle chunks.
uint64_t prof_idle_prev_i
Prior total insns (profiler).
bool prof_stopped
Profiler stop fired.
const emu_run_cfg_t * cfg
Setup products (engine, image, CLI knobs).
uint16_t panel_h
Firmware render height in pixels.
uint64_t idle_sig_prev
Prior idle-signature sum.
uint32_t run_pc
Current resume PC.
uint16_t comp_w
Composite (panel + sidebar) width.
bool idle_stopped
Idle steady-state stop fired.
uint64_t last_present_us
wall-us of the last live present.
bool button_fired
Headless click button fired once.
bool stop_sym_hit
–stop-sym threshold reached.
uint32_t prof_idle_run
Consecutive profiler-idle chunks.
uc_err err
Latest uc_emu_start status.
uint32_t chunks
Outer chunks executed so far.
uint16_t disp_w
Displayed width (rotation-swapped).
bool click_was_tab
–click landed on a console tab.
uint16_t disp_h
Displayed height (rotation-swapped).
uint32_t usbh_stop_run
USB host settle countup.