endif
-CC_SRCS ?= "--cc dut.v"
+CC_SRCS ?= "--cc sim.v"
SRC_DIR ?= .
INC_DIR ?= .
SRCS_SIM_ABSPATH = $(wildcard $(SRC_DIR)/*.c)
SRCS_SIM = $(notdir $(SRCS_SIM_ABSPATH))
-SRCS_SIM_CPP = dut_init.cpp $(SRC_DIR)/veril.cpp
+SRCS_SIM_CPP = sim_init.cpp $(SRC_DIR)/veril.cpp
OBJS_SIM = $(SRCS_SIM:.c=.o)
all: modules sim
.PHONY: sim
sim: $(OBJS_SIM) | mkdir
- verilator -Wno-fatal -O3 $(CC_SRCS) --top-module dut --exe \
+ verilator -Wno-fatal -O3 $(CC_SRCS) --top-module sim --exe \
-DPRINTF_COND=0 \
$(SRCS_SIM_CPP) $(OBJS_SIM) \
- --top-module dut \
+ --top-module sim \
$(if $(THREADS), --threads $(THREADS),) \
-CFLAGS "$(CFLAGS) -I$(SRC_DIR)" \
-LDFLAGS "$(LDFLAGS)" \
$(INC_DIR) \
-Wno-BLKANDNBLK \
-Wno-WIDTH
- make -j -C $(OBJ_DIR) -f Vdut.mk Vdut
+ make -j -C $(OBJ_DIR) -f Vsim.mk Vsim
.PHONY: modules
modules:
struct session_list_s *sesslist=NULL;
struct event_base *base=NULL;
-static int litex_sim_initialize_all(void **dut, void *base)
+static int litex_sim_initialize_all(void **sim, void *base)
{
struct module_s *ml=NULL;
struct module_s *mli=NULL;
struct pad_list_s *plist=NULL;
struct pad_list_s *pplist=NULL;
struct session_list_s *slist=NULL;
- void *vdut=NULL;
+ void *vsim=NULL;
int i;
int ret = RC_OK;
goto out;
}
/* Init generated */
- litex_sim_init(&vdut);
+ litex_sim_init(&vsim);
/* Get pads from generated */
ret = litex_sim_pads_get_list(&plist);
}
}
}
- *dut = vdut;
+ *sim = vsim;
out:
return ret;
}
static void cb(int sock, short which, void *arg)
{
struct session_list_s *s;
- void *vdut=arg;
+ void *vsim=arg;
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 0;
if(s->tickfirst)
s->module->tick(s->session);
}
- litex_sim_eval(vdut);
+ litex_sim_eval(vsim);
litex_sim_dump();
for(s = sesslist; s; s=s->next)
{
int main(int argc, char *argv[])
{
- void *vdut=NULL;
+ void *vsim=NULL;
struct timeval tv;
int ret;
}
litex_sim_init_cmdargs(argc, argv);
- if(RC_OK != (ret = litex_sim_initialize_all(&vdut, base)))
+ if(RC_OK != (ret = litex_sim_initialize_all(&vsim, base)))
{
goto out;
}
tv.tv_sec = 0;
tv.tv_usec = 0;
- ev = event_new(base, -1, EV_PERSIST, cb, vdut);
+ ev = event_new(base, -1, EV_PERSIST, cb, vsim);
event_add(ev, &tv);
event_base_dispatch(base);
#if VM_COVERAGE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "Vdut.h"
+#include "Vsim.h"
#include "verilated.h"
#ifdef TRACE_FST
#include "verilated_fst_c.h"
long tfp_start;
long tfp_end;
-extern "C" void litex_sim_eval(void *vdut)
+extern "C" void litex_sim_eval(void *vsim)
{
- Vdut *dut = (Vdut*)vdut;
- dut->eval();
+ Vsim *sim = (Vsim*)vsim;
+ sim->eval();
}
extern "C" void litex_sim_init_cmdargs(int argc, char *argv[])
Verilated::commandArgs(argc, argv);
}
-extern "C" void litex_sim_init_tracer(void *vdut, long start, long end)
+extern "C" void litex_sim_init_tracer(void *vsim, long start, long end)
{
- Vdut *dut = (Vdut*)vdut;
+ Vsim *sim = (Vsim*)vsim;
tfp_start = start;
tfp_end = end;
Verilated::traceEverOn(true);
#ifdef TRACE_FST
tfp = new VerilatedFstC;
- dut->trace(tfp, 99);
- tfp->open("dut.fst");
+ sim->trace(tfp, 99);
+ tfp->open("sim.fst");
#else
tfp = new VerilatedVcdC;
- dut->trace(tfp, 99);
- tfp->open("dut.vcd");
+ sim->trace(tfp, 99);
+ tfp->open("sim.vcd");
#endif
}
#if VM_COVERAGE
extern "C" void litex_sim_coverage_dump()
{
- VerilatedCov::write("dut.cov");
+ VerilatedCov::write("sim.cov");
}
#endif
#ifdef __cplusplus
extern "C" void litex_sim_init_cmdargs(int argc, char *argv[]);
-extern "C" void litex_sim_eval(void *vdut);
-extern "C" void litex_sim_init_tracer(void *vdut, long start, long end)
+extern "C" void litex_sim_eval(void *vsim);
+extern "C" void litex_sim_init_tracer(void *vsim, long start, long end)
extern "C" void litex_sim_tracer_dump();
extern "C" int litex_sim_got_finish();
#if VM_COVERAGE
extern "C" void litex_sim_coverage_dump();
#endif
#else
-void litex_sim_eval(void *vdut);
-void litex_sim_init_tracer(void *vdut);
+void litex_sim_eval(void *vsim);
+void litex_sim_init_tracer(void *vsim);
void litex_sim_tracer_dump();
int litex_sim_got_finish();
void litex_sim_init_cmdargs(int argc, char *argv[]);
class SimPlatform(GenericPlatform):
- def __init__(self, *args, toolchain="verilator", **kwargs):
- GenericPlatform.__init__(self, *args, **kwargs)
+ def __init__(self, *args, name="sim", toolchain="verilator", **kwargs):
+ GenericPlatform.__init__(self, *args, name=name, **kwargs)
self.sim_requested = []
if toolchain == "verilator":
self.toolchain = verilator.SimVerilatorToolchain()
#endif /* __SIM_CORE_H_ */
"""
- tools.write_to_file("dut_header.h", content)
+ tools.write_to_file("sim_header.h", content)
def _generate_sim_cpp_struct(name, index, siglist):
content = ''
for i, (signame, sigbits, sigfname) in enumerate(siglist):
- content += ' {}{}[{}].signal = &dut->{};\n'.format(name, index, i, sigfname)
+ content += ' {}{}[{}].signal = &sim->{};\n'.format(name, index, i, sigfname)
idx_int = 0 if not index else int(index)
content += ' litex_sim_register_pads({}{}, (char*)"{}", {});\n\n'.format(name, index, name, idx_int)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "Vdut.h"
+#include "Vsim.h"
#include <verilated.h>
-#include "dut_header.h"
+#include "sim_header.h"
-extern "C" void litex_sim_init_tracer(void *vdut, long start, long end);
+extern "C" void litex_sim_init_tracer(void *vsim, long start, long end);
extern "C" void litex_sim_tracer_dump();
extern "C" void litex_sim_dump()
extern "C" void litex_sim_init(void **out)
{{
- Vdut *dut;
+ Vsim *sim;
- dut = new Vdut;
+ sim = new Vsim;
- litex_sim_init_tracer(dut, {}, {});
+ litex_sim_init_tracer(sim, {}, {});
""".format(trace_start, trace_end)
for args in platform.sim_requested:
content += _generate_sim_cpp_struct(*args)
content += """\
- *out=dut;
+ *out=sim;
}
"""
- tools.write_to_file("dut_init.cpp", content)
+ tools.write_to_file("sim_init.cpp", content)
def _generate_sim_variables(include_paths):
def _run_sim(build_name, as_root=False):
run_script_contents = "sudo " if as_root else ""
- run_script_contents += "obj_dir/Vdut"
+ run_script_contents += "obj_dir/Vsim"
run_script_file = "run_" + build_name + ".sh"
tools.write_to_file(run_script_file, run_script_contents, force_unix=True)
if sys.platform != "win32":
class SimVerilatorToolchain:
- def build(self, platform, fragment, build_dir="build", build_name="dut",
+ def build(self, platform, fragment, build_dir="build", build_name="sim",
serial="console", build=True, run=True, threads=1,
verbose=True, sim_config=None, coverage=False, opt_level="O0",
trace=False, trace_fst=False, trace_start=0, trace_end=-1):