From d1fae68d6c23903c73907874fdea7fd28a56a6b0 Mon Sep 17 00:00:00 2001 From: Clo91eaf Date: Fri, 10 May 2024 10:55:08 +0800 Subject: [PATCH] [dut] add --trace to specify trace wave or not --- src/dut.rs | 27 ++++++++++++++++++--------- src/emulator.rs | 4 ++-- src/main.rs | 6 +++++- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/dut.rs b/src/dut.rs index 3a98b52..a10d83f 100644 --- a/src/dut.rs +++ b/src/dut.rs @@ -22,14 +22,17 @@ pub struct Dut { pub ticks: u64, pub prepare_for_difftest: bool, pub inst: u32, - pub data: u64 + pub data: u64, + pub trace: bool, } impl Dut { - pub fn new() -> Self { + pub fn new(trace: bool) -> Self { let mut top = Top::default(); - top.open_trace("wave.vcd", 99).unwrap(); + if trace { + top.open_trace("wave.vcd", 99).unwrap(); + } Dut { top, @@ -38,7 +41,8 @@ impl Dut { ticks: 0, prepare_for_difftest: false, inst: 0, - data: 0 + data: 0, + trace, } } @@ -52,11 +56,17 @@ impl Dut { self.top.reset_toggle(); } + fn trace(&mut self, ticks: u64) { + if self.trace { + self.top.trace_at(Duration::from_nanos(ticks)); + } + } + /// drive the instruction SRAM interface pub fn step(&mut self, inst: u32, data: u64) -> anyhow::Result<(SramRequest, SramRequest, DebugInfo)> { match self.ticks { 0 | 2 => self.reset_toggle(), - _ => {}, + _ => {} } // a little trick: there must be 2 state transitions after clock posedge @@ -66,16 +76,15 @@ impl Dut { self.top.set_inst_sram_rdata(inst); self.top.set_data_sram_rdata(data); self.top.eval(); - } - self.top.trace_at(Duration::from_nanos(self.ticks * 2)); + } + self.trace(self.ticks * 2); self.clock_toggle(); self.top.eval(); - self.top.trace_at(Duration::from_nanos(self.ticks * 2 + 1)); + self.trace(self.ticks * 2 + 1); self.ticks += 1; - Ok({ ( SramRequest::new(self.top.inst_sram_en() != 0, self.top.inst_sram_addr()), diff --git a/src/emulator.rs b/src/emulator.rs index c9010c1..d1feb42 100644 --- a/src/emulator.rs +++ b/src/emulator.rs @@ -126,10 +126,10 @@ pub struct Emulator { impl Emulator { /// Constructor for an emulator. - pub fn new() -> Emulator { + pub fn new(trace: bool) -> Emulator { Self { cpu: Cpu::new(), - dut: Dut::new(), + dut: Dut::new(trace), ui_buffer: UIBuffer::new(), cont: false, exit: false, diff --git a/src/main.rs b/src/main.rs index 7756ec2..9ebd0f0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,6 +32,10 @@ struct Args { /// Enable tui #[arg(short, long)] tui: bool, + + /// Enable wave trace + #[arg(short, long)] + trace: bool, } /// Main function of RISC-V emulator for the CLI version. @@ -54,7 +58,7 @@ fn main() -> anyhow::Result<()> { } // Create an emulator object and start the execution. - let mut emu = Emulator::new(); + let mut emu = Emulator::new(args.trace); emu.reset();