verilator/test_regress/t/t_order_multidriven.cpp
Wilson Snyder 2cad22a22a
Add simulation context (VerilatedContext) (#2660). (#2813)
**   Add simulation context (VerilatedContext) to allow multiple fully independent
      models to be in the same process.  Please see the updated examples.
**   Add context->time() and context->timeInc() API calls, to set simulation time.
      These now are recommended in place of the legacy sc_time_stamp().
2021-03-07 11:01:54 -05:00

67 lines
1.3 KiB
C++

// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed into the Public Domain, for any use,
// without warranty, 2013 by Ted Campbell.
// SPDX-License-Identifier: CC0-1.0
#include "Vt_order_multidriven.h"
#include "verilated.h"
#include "verilated_vcd_c.h"
double sc_time_stamp() { return 0; }
Vt_order_multidriven* vcore;
VerilatedVcdC* vcd;
vluint64_t vtime;
#define PHASE_90
static void half_cycle(int clk) {
if (clk & 1) vcore->i_clk_wr = !vcore->i_clk_wr;
if (clk & 2) vcore->i_clk_rd = !vcore->i_clk_rd;
vtime += 10 / 2;
vcore->eval();
vcore->eval();
vcd->dump(vtime);
}
static void cycle() {
#ifdef PHASE_90
half_cycle(1);
half_cycle(2);
half_cycle(1);
half_cycle(2);
#else
half_cycle(3);
half_cycle(3);
#endif
}
int main() {
const std::unique_ptr<VerilatedContext> contextp{new VerilatedContext};
contextp->traceEverOn(true);
vcore = new VM_PREFIX{contextp.get()};
vcd = new VerilatedVcdC;
vcore->trace(vcd, 99);
vcd->open(VL_STRINGIFY(TEST_OBJ_DIR) "/simx.vcd");
vcore->i_clk_wr = 0;
vcore->i_clk_rd = 0;
for (int i = 0; i < 256; ++i) { //
cycle();
}
vcd->close();
vcore->final();
VL_DO_DANGLING(delete vcore, vcore);
printf("*-* All Finished *-*\n");
}