UART simulation
This commit is contained in:
@@ -14,6 +14,8 @@ from .errors import UnsupportedInstruction
|
||||
from .runner import H8536Emulator
|
||||
from .rx_probe import (
|
||||
RunContext,
|
||||
UartTiming,
|
||||
_inject_frame_uart_timed,
|
||||
_interrupt_mask,
|
||||
_rx_byte_consumed,
|
||||
_rx_ready,
|
||||
@@ -88,6 +90,7 @@ class ReplayFrameResult:
|
||||
host_frame: bytes
|
||||
host_timestamp: str
|
||||
host_delta_ms: int
|
||||
rx_injection: str
|
||||
steps_before: int
|
||||
steps_during_rx: int
|
||||
emulator_gap_frames_before: tuple[bytes, ...]
|
||||
@@ -120,6 +123,7 @@ class BenchReplayResult:
|
||||
"host_timestamp": item.host_timestamp,
|
||||
"host_delta_ms": item.host_delta_ms,
|
||||
"host_frame": format_frame(item.host_frame),
|
||||
"rx_injection": item.rx_injection,
|
||||
"steps_before": item.steps_before,
|
||||
"steps_during_rx": item.steps_during_rx,
|
||||
"emulator_gap_frames_before": [format_frame(frame) for frame in item.emulator_gap_frames_before],
|
||||
@@ -150,6 +154,7 @@ class BenchReplayResult:
|
||||
lines.append(
|
||||
(
|
||||
f" [{index}] {item.host_timestamp} delta={item.host_delta_ms}ms "
|
||||
f"rx_injection={item.rx_injection} "
|
||||
f"steps_before={item.steps_before} steps_rx={item.steps_during_rx} "
|
||||
f"host={format_frame(item.host_frame)} "
|
||||
f"gap_emu={_format_frame_list(item.emulator_gap_frames_before)} "
|
||||
@@ -171,6 +176,8 @@ class ReplayConfig:
|
||||
frt1_ocia_steps: int | None = None
|
||||
frt2_ocia_steps: int | None = None
|
||||
clock_hz: int = 10_000_000
|
||||
uart_timing: bool = True
|
||||
uart_baud: int = 38_400
|
||||
p9_fast_path: bool = True
|
||||
p9_fast_input: int = 0xFF
|
||||
|
||||
@@ -256,12 +263,25 @@ def run_bench_replay(log_path: Path, *, rom_path: Path | None = None, config: Re
|
||||
steps_before = _run_cycles_for_ms(emulator, delta_ms, config.clock_hz, context)
|
||||
gap_frames = tuple(emulator.sci1.tx_frames[tx_frame_start_before_delay:])
|
||||
tx_frame_start = len(emulator.sci1.tx_frames)
|
||||
steps_during_rx = _inject_host_frame(emulator, host.frame, config.per_byte_steps, context)
|
||||
if config.uart_timing:
|
||||
timing = UartTiming(baud=config.uart_baud)
|
||||
steps_during_rx, inject_reason = _inject_frame_uart_timed(
|
||||
emulator,
|
||||
host.frame,
|
||||
timing=timing,
|
||||
max_steps_per_gap=config.per_byte_steps,
|
||||
context=context,
|
||||
)
|
||||
rx_injection = f"{timing.summary(emulator.clock_hz)} reason={inject_reason}"
|
||||
else:
|
||||
steps_during_rx = _inject_host_frame(emulator, host.frame, config.per_byte_steps, context)
|
||||
rx_injection = "polite_wait_for_rdrf_clear"
|
||||
replay_results.append(
|
||||
ReplayFrameResult(
|
||||
host_frame=host.frame,
|
||||
host_timestamp=host.timestamp,
|
||||
host_delta_ms=delta_ms,
|
||||
rx_injection=rx_injection,
|
||||
steps_before=steps_before,
|
||||
steps_during_rx=steps_during_rx,
|
||||
emulator_gap_frames_before=gap_frames,
|
||||
@@ -336,10 +356,12 @@ def build_arg_parser() -> argparse.ArgumentParser:
|
||||
parser.add_argument("log", type=Path, help="bench log produced by scripts/bench_connect_lcd_sequence.py")
|
||||
parser.add_argument("--rom", type=Path, help="ROM image path; defaults to ROM/M27C512@DIP28_1.BIN")
|
||||
parser.add_argument("--boot-steps", type=int, default=ReplayConfig.boot_steps)
|
||||
parser.add_argument("--per-byte-steps", type=int, default=ReplayConfig.per_byte_steps)
|
||||
parser.add_argument("--per-byte-steps", type=int, default=ReplayConfig.per_byte_steps, help="UART mode step limit between byte arrivals, or polite mode byte-consume limit")
|
||||
parser.add_argument("--post-log-steps", type=int, default=ReplayConfig.post_log_steps)
|
||||
parser.add_argument("--interval-steps", type=int, default=ReplayConfig.interval_steps)
|
||||
parser.add_argument("--clock-hz", type=lambda text: int(text, 0), default=ReplayConfig.clock_hz)
|
||||
parser.add_argument("--uart-baud", type=lambda text: int(text, 0), default=ReplayConfig.uart_baud, help="baud rate for bench-style UART injection")
|
||||
parser.add_argument("--polite-rx", action="store_true", help="wait for each RX byte to be consumed before injecting the next byte")
|
||||
parser.add_argument("--frt1-ocia-steps", type=int, default=ReplayConfig.frt1_ocia_steps)
|
||||
parser.add_argument("--frt2-ocia-steps", type=int, default=ReplayConfig.frt2_ocia_steps)
|
||||
parser.add_argument("--no-p9-fast-path", action="store_true", help="disable shortcut handling for known P9 routines")
|
||||
@@ -362,6 +384,8 @@ def main(argv: list[str] | None = None) -> int:
|
||||
frt1_ocia_steps=args.frt1_ocia_steps,
|
||||
frt2_ocia_steps=args.frt2_ocia_steps,
|
||||
clock_hz=args.clock_hz,
|
||||
uart_timing=not args.polite_rx,
|
||||
uart_baud=args.uart_baud,
|
||||
p9_fast_path=not args.no_p9_fast_path,
|
||||
p9_fast_input=args.p9_fast_input,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user