2017-09-24 01:18:07 +00:00
|
|
|
// DESCRIPTION: Verilator: Verilog example module
|
|
|
|
//
|
|
|
|
// This file ONLY is placed into the Public Domain, for any use,
|
|
|
|
// without warranty, 2017 by Wilson Snyder.
|
|
|
|
//======================================================================
|
|
|
|
|
|
|
|
// Include common routines
|
|
|
|
#include <verilated.h>
|
|
|
|
|
|
|
|
// Include model header, generated from Verilating "top.v"
|
|
|
|
#include "Vtop.h"
|
|
|
|
|
|
|
|
// Current simulation time (64-bit unsigned)
|
|
|
|
vluint64_t main_time = 0;
|
|
|
|
// Called by $time in Verilog
|
2018-08-25 13:52:45 +00:00
|
|
|
double sc_time_stamp() {
|
|
|
|
return main_time; // Note does conversion to real, to match SystemC
|
2017-09-24 01:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv, char** env) {
|
2019-10-06 14:32:49 +00:00
|
|
|
// This is a more complicated example, please also see the simpler examples/make_hello_c.
|
2017-09-24 01:18:07 +00:00
|
|
|
|
|
|
|
// Prevent unused variable warnings
|
|
|
|
if (0 && argc && argv && env) {}
|
|
|
|
|
|
|
|
// Set debug level, 0 is off, 9 is highest presently used
|
2019-03-02 01:14:48 +00:00
|
|
|
// May be overridden by commandArgs
|
2017-09-24 01:18:07 +00:00
|
|
|
Verilated::debug(0);
|
|
|
|
|
|
|
|
// Randomization reset policy
|
2019-03-02 01:14:48 +00:00
|
|
|
// May be overridden by commandArgs
|
2017-09-24 01:18:07 +00:00
|
|
|
Verilated::randReset(2);
|
|
|
|
|
2020-03-02 02:39:23 +00:00
|
|
|
// Verilator must compute traced signals
|
|
|
|
Verilated::traceEverOn(true);
|
|
|
|
|
2019-03-02 01:14:48 +00:00
|
|
|
// Pass arguments so Verilated code can see them, e.g. $value$plusargs
|
|
|
|
// This needs to be called before you create any model
|
|
|
|
Verilated::commandArgs(argc, argv);
|
|
|
|
|
2020-03-02 02:39:23 +00:00
|
|
|
// Create logs/ directory in case we have traces to put under it
|
|
|
|
Verilated::mkdir("logs");
|
|
|
|
|
2017-09-24 01:18:07 +00:00
|
|
|
// Construct the Verilated model, from Vtop.h generated from Verilating "top.v"
|
2019-05-08 02:34:09 +00:00
|
|
|
Vtop* top = new Vtop; // Or use a const unique_ptr, or the VL_UNIQUE_PTR wrapper
|
2017-09-24 01:18:07 +00:00
|
|
|
|
|
|
|
// Set some inputs
|
|
|
|
top->reset_l = !0;
|
|
|
|
top->fastclk = 0;
|
|
|
|
top->clk = 0;
|
|
|
|
top->in_small = 1;
|
|
|
|
top->in_quad = 0x1234;
|
2017-11-25 20:14:31 +00:00
|
|
|
top->in_wide[0] = 0x11111111;
|
2017-09-24 01:18:07 +00:00
|
|
|
top->in_wide[1] = 0x22222222;
|
2017-11-25 20:14:31 +00:00
|
|
|
top->in_wide[2] = 0x3;
|
2017-09-24 01:18:07 +00:00
|
|
|
|
|
|
|
// Simulate until $finish
|
|
|
|
while (!Verilated::gotFinish()) {
|
2017-10-10 11:18:01 +00:00
|
|
|
main_time++; // Time passes...
|
|
|
|
|
|
|
|
// Toggle clocks and such
|
|
|
|
top->fastclk = !top->fastclk;
|
|
|
|
if ((main_time % 10) == 3) {
|
|
|
|
top->clk = 1;
|
|
|
|
}
|
|
|
|
if ((main_time % 10) == 8) {
|
|
|
|
top->clk = 0;
|
|
|
|
}
|
|
|
|
if (main_time > 1 && main_time < 10) {
|
|
|
|
top->reset_l = !1; // Assert reset
|
|
|
|
} else {
|
|
|
|
top->reset_l = !0; // Deassert reset
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assign some other inputs
|
|
|
|
top->in_quad += 0x12;
|
|
|
|
|
|
|
|
// Evaluate model
|
2020-03-02 02:39:23 +00:00
|
|
|
// (If you have multiple models being simulated in the same
|
|
|
|
// timestep then instead of eval(), call eval_step() on each, then
|
|
|
|
// eval_end_step() on each.)
|
2017-10-10 11:18:01 +00:00
|
|
|
top->eval();
|
|
|
|
|
|
|
|
// Read outputs
|
2019-05-08 02:34:09 +00:00
|
|
|
VL_PRINTF("[%" VL_PRI64 "d] clk=%x rstl=%x iquad=%" VL_PRI64 "x"
|
|
|
|
" -> oquad=%" VL_PRI64"x owide=%x_%08x_%08x\n",
|
|
|
|
main_time, top->clk, top->reset_l, top->in_quad,
|
|
|
|
top->out_quad, top->out_wide[2], top->out_wide[1], top->out_wide[0]);
|
2017-09-24 01:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Final model cleanup
|
|
|
|
top->final();
|
|
|
|
|
|
|
|
// Coverage analysis (since test passed)
|
|
|
|
#if VM_COVERAGE
|
2018-08-27 22:07:52 +00:00
|
|
|
Verilated::mkdir("logs");
|
2017-09-24 01:18:07 +00:00
|
|
|
VerilatedCov::write("logs/coverage.dat");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Destroy model
|
|
|
|
delete top; top = NULL;
|
|
|
|
|
|
|
|
// Fin
|
|
|
|
exit(0);
|
|
|
|
}
|