#include <event2/event.h>
void litex_sim_init(void **out);
+void litex_sim_dump();
struct session_list_s {
void *session;
void *vdut=NULL;
int i;
int ret = RC_OK;
-
+
/* Load external modules */
ret = litex_sim_load_ext_modules(&mlist);
if(RC_OK != ret)
pmlist->module->start(base);
}
}
-
+
/* Load configuration */
ret = litex_sim_file_to_module_list("sim_config.js", &ml);
if(RC_OK != ret)
}
/* Init generated */
litex_sim_init(&vdut);
-
+
/* Get pads from generated */
ret = litex_sim_pads_get_list(&plist);
if(RC_OK != ret)
{
goto out;
}
-
+
for(mli = ml; mli; mli=mli->next)
{
eprintf("Could not find module %s\n", mli->name);
continue;
}
-
+
slist=(struct session_list_s *)malloc(sizeof(struct session_list_s));
if(NULL == slist)
{
goto out;
}
sesslist = slist;
-
+
/* For each interface */
for(i = 0; i < mli->niface; i++)
{
if(RC_OK != ret)
{
goto out;
- }
+ }
}
}
*dut = vdut;
{
struct session_list_s *s;
struct session_list_s *sprev=sesslist;
-
+
if(!sesslist->next)
{
return RC_OK;
}
-
+
for(s = sesslist->next; s; s=s->next)
{
if(s->tickfirst)
sprev = s;
}
- return RC_OK;
+ return RC_OK;
}
struct event *ev;
tv.tv_sec = 0;
tv.tv_usec = 0;
int i;
-
-
- //litex_sim_eval(vdut);
+
+
for(i = 0; i < 1000; i++)
{
for(s = sesslist; s; s=s->next)
s->module->tick(s->session);
}
litex_sim_eval(vdut);
+ litex_sim_dump();
for(s = sesslist; s; s=s->next)
{
if(!s->tickfirst)
s->module->tick(s->session);
}
}
- //litex_sim_eval(vdut);
-
-
+
if (!evtimer_pending(ev, NULL)) {
event_del(ev);
evtimer_add(ev, &tv);
}
-}
+}
int main()
{
struct timeval tv;
int ret;
-
+
#ifdef _WIN32
WSADATA wsa_data;
WSAStartup(0x0201, &wsa_data);
ret=RC_ERROR;
goto out;
}
-
+
if(RC_OK != (ret = litex_sim_initialize_all(&vdut, base)))
{
goto out;
}
-
+
if(RC_OK != (ret = litex_sim_sort_session()))
{
goto out;
}
-
-
+
+
tv.tv_sec = 0;
tv.tv_usec = 0;
ev = event_new(base, -1, EV_PERSIST, cb, vdut);
event_add(ev, &tv);
-
+
event_base_dispatch(base);
out:
return ret;
return content
-def _generate_sim_cpp(platform):
+def _generate_sim_cpp(platform, trace=False):
content = """\
#include <stdio.h>
#include <stdlib.h>
#include <verilated.h>
#include "dut_header.h"
+extern "C" void litex_sim_init_tracer(void *vdut);
+extern "C" void litex_sim_tracer_dump();
+
+extern "C" void litex_sim_dump()
+{
+"""
+ if trace:
+ content += """\
+ litex_sim_tracer_dump();
+"""
+ content += """\
+}
+
extern "C" void litex_sim_init(void **out)
{
Vdut *dut;
dut = new Vdut;
+ litex_sim_init_tracer(dut);
+
"""
for args in platform.sim_requested:
content += _generate_sim_cpp_struct(*args)
class SimVerilatorToolchain:
def build(self, platform, fragment, build_dir="build", build_name="dut",
toolchain_path=None, serial="console", build=True, run=True, threads=1,
- verbose=True, sim_config=None):
+ verbose=True, sim_config=None, trace=False):
os.makedirs(build_dir, exist_ok=True)
os.chdir(build_dir)
include_paths.append(path)
include_paths += platform.verilog_include_paths
_generate_sim_h(platform)
- _generate_sim_cpp(platform)
+ _generate_sim_cpp(platform, trace)
_generate_sim_variables(include_paths)
if sim_config:
_generate_sim_config(sim_config)