Skip to content

Commit

Permalink
[dut] add --trace to specify trace wave or not
Browse files Browse the repository at this point in the history
  • Loading branch information
Clo91eaf committed May 10, 2024
1 parent b760779 commit d1fae68
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
27 changes: 18 additions & 9 deletions src/dut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -38,7 +41,8 @@ impl Dut {
ticks: 0,
prepare_for_difftest: false,
inst: 0,
data: 0
data: 0,
trace,
}
}

Expand All @@ -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
Expand All @@ -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()),
Expand Down
4 changes: 2 additions & 2 deletions src/emulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();

Expand Down

0 comments on commit d1fae68

Please sign in to comment.