Skip to content

Commit

Permalink
[ESI Runtime][Verilator] Option to slow down the sim
Browse files Browse the repository at this point in the history
Add a 'DEBUG_PERIOD' option to slow down the simulation. Useful in
waveform debugging a fast simulation.
  • Loading branch information
teqdruid committed Dec 19, 2024
1 parent 348e82a commit c31f207
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/Dialect/ESI/runtime/cosim_dpi_server/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include "signal.h"
#include <iostream>
#include <thread>

vluint64_t timeStamp;

Expand All @@ -54,6 +55,14 @@ int main(int argc, char **argv) {
auto &dut = *new CLASSNAME(V, TOP_MODULE)();
char *waveformFile = getenv("SAVE_WAVE");

char *periodStr = getenv("DEBUG_PERIOD");
unsigned debugPeriod = 0;
if (periodStr) {
debugPeriod = std::stoi(periodStr);
std::cout << "[driver] Setting debug period to " << debugPeriod
<< std::endl;
}

VerilatedVcdC *tfp = nullptr;
if (waveformFile) {
#ifdef TRACE
Expand Down Expand Up @@ -97,6 +106,8 @@ int main(int argc, char **argv) {
dut.clk = !dut.clk;
if (tfp)
tfp->dump(timeStamp);
if (debugPeriod)
std::this_thread::sleep_for(std::chrono::milliseconds(debugPeriod));
}

// Tell the simulator that we're going to exit. This flushes the output(s) and
Expand Down
2 changes: 2 additions & 0 deletions lib/Dialect/ESI/runtime/cosim_dpi_server/esi-cosim.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ def run(self, inner_command: str, gui: bool = False) -> int:
simEnv = Simulator.get_env()
if self.debug:
simEnv["COSIM_DEBUG_FILE"] = "cosim_debug.log"
# Slow the simulation down to one tick per millisecond.
simEnv["DEBUG_PERIOD"] = "1"
simProc = subprocess.Popen(self.run_command(gui),
stdout=simStdout,
stderr=simStderr,
Expand Down

0 comments on commit c31f207

Please sign in to comment.