build/sim/verilator: add trace parameter to enable tracer
This commit is contained in:
parent
7359a99bf9
commit
80bdae0e55
|
@ -22,6 +22,7 @@
|
||||||
#include <event2/event.h>
|
#include <event2/event.h>
|
||||||
|
|
||||||
void litex_sim_init(void **out);
|
void litex_sim_init(void **out);
|
||||||
|
void litex_sim_dump();
|
||||||
|
|
||||||
struct session_list_s {
|
struct session_list_s {
|
||||||
void *session;
|
void *session;
|
||||||
|
@ -45,7 +46,7 @@ static int litex_sim_initialize_all(void **dut, void *base)
|
||||||
void *vdut=NULL;
|
void *vdut=NULL;
|
||||||
int i;
|
int i;
|
||||||
int ret = RC_OK;
|
int ret = RC_OK;
|
||||||
|
|
||||||
/* Load external modules */
|
/* Load external modules */
|
||||||
ret = litex_sim_load_ext_modules(&mlist);
|
ret = litex_sim_load_ext_modules(&mlist);
|
||||||
if(RC_OK != ret)
|
if(RC_OK != ret)
|
||||||
|
@ -59,7 +60,7 @@ static int litex_sim_initialize_all(void **dut, void *base)
|
||||||
pmlist->module->start(base);
|
pmlist->module->start(base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load configuration */
|
/* Load configuration */
|
||||||
ret = litex_sim_file_to_module_list("sim_config.js", &ml);
|
ret = litex_sim_file_to_module_list("sim_config.js", &ml);
|
||||||
if(RC_OK != ret)
|
if(RC_OK != ret)
|
||||||
|
@ -68,14 +69,14 @@ static int litex_sim_initialize_all(void **dut, void *base)
|
||||||
}
|
}
|
||||||
/* Init generated */
|
/* Init generated */
|
||||||
litex_sim_init(&vdut);
|
litex_sim_init(&vdut);
|
||||||
|
|
||||||
/* Get pads from generated */
|
/* Get pads from generated */
|
||||||
ret = litex_sim_pads_get_list(&plist);
|
ret = litex_sim_pads_get_list(&plist);
|
||||||
if(RC_OK != ret)
|
if(RC_OK != ret)
|
||||||
{
|
{
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(mli = ml; mli; mli=mli->next)
|
for(mli = ml; mli; mli=mli->next)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -91,7 +92,7 @@ static int litex_sim_initialize_all(void **dut, void *base)
|
||||||
eprintf("Could not find module %s\n", mli->name);
|
eprintf("Could not find module %s\n", mli->name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
slist=(struct session_list_s *)malloc(sizeof(struct session_list_s));
|
slist=(struct session_list_s *)malloc(sizeof(struct session_list_s));
|
||||||
if(NULL == slist)
|
if(NULL == slist)
|
||||||
{
|
{
|
||||||
|
@ -109,7 +110,7 @@ static int litex_sim_initialize_all(void **dut, void *base)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
sesslist = slist;
|
sesslist = slist;
|
||||||
|
|
||||||
/* For each interface */
|
/* For each interface */
|
||||||
for(i = 0; i < mli->niface; i++)
|
for(i = 0; i < mli->niface; i++)
|
||||||
{
|
{
|
||||||
|
@ -129,7 +130,7 @@ static int litex_sim_initialize_all(void **dut, void *base)
|
||||||
if(RC_OK != ret)
|
if(RC_OK != ret)
|
||||||
{
|
{
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*dut = vdut;
|
*dut = vdut;
|
||||||
|
@ -141,12 +142,12 @@ int litex_sim_sort_session()
|
||||||
{
|
{
|
||||||
struct session_list_s *s;
|
struct session_list_s *s;
|
||||||
struct session_list_s *sprev=sesslist;
|
struct session_list_s *sprev=sesslist;
|
||||||
|
|
||||||
if(!sesslist->next)
|
if(!sesslist->next)
|
||||||
{
|
{
|
||||||
return RC_OK;
|
return RC_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(s = sesslist->next; s; s=s->next)
|
for(s = sesslist->next; s; s=s->next)
|
||||||
{
|
{
|
||||||
if(s->tickfirst)
|
if(s->tickfirst)
|
||||||
|
@ -160,7 +161,7 @@ int litex_sim_sort_session()
|
||||||
sprev = s;
|
sprev = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
return RC_OK;
|
return RC_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct event *ev;
|
struct event *ev;
|
||||||
|
@ -173,9 +174,8 @@ static void cb(int sock, short which, void *arg)
|
||||||
tv.tv_sec = 0;
|
tv.tv_sec = 0;
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
|
||||||
//litex_sim_eval(vdut);
|
|
||||||
for(i = 0; i < 1000; i++)
|
for(i = 0; i < 1000; i++)
|
||||||
{
|
{
|
||||||
for(s = sesslist; s; s=s->next)
|
for(s = sesslist; s; s=s->next)
|
||||||
|
@ -184,20 +184,19 @@ static void cb(int sock, short which, void *arg)
|
||||||
s->module->tick(s->session);
|
s->module->tick(s->session);
|
||||||
}
|
}
|
||||||
litex_sim_eval(vdut);
|
litex_sim_eval(vdut);
|
||||||
|
litex_sim_dump();
|
||||||
for(s = sesslist; s; s=s->next)
|
for(s = sesslist; s; s=s->next)
|
||||||
{
|
{
|
||||||
if(!s->tickfirst)
|
if(!s->tickfirst)
|
||||||
s->module->tick(s->session);
|
s->module->tick(s->session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//litex_sim_eval(vdut);
|
|
||||||
|
|
||||||
|
|
||||||
if (!evtimer_pending(ev, NULL)) {
|
if (!evtimer_pending(ev, NULL)) {
|
||||||
event_del(ev);
|
event_del(ev);
|
||||||
evtimer_add(ev, &tv);
|
evtimer_add(ev, &tv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
@ -206,7 +205,7 @@ int main()
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WSADATA wsa_data;
|
WSADATA wsa_data;
|
||||||
WSAStartup(0x0201, &wsa_data);
|
WSAStartup(0x0201, &wsa_data);
|
||||||
|
@ -220,23 +219,23 @@ int main()
|
||||||
ret=RC_ERROR;
|
ret=RC_ERROR;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(RC_OK != (ret = litex_sim_initialize_all(&vdut, base)))
|
if(RC_OK != (ret = litex_sim_initialize_all(&vdut, base)))
|
||||||
{
|
{
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(RC_OK != (ret = litex_sim_sort_session()))
|
if(RC_OK != (ret = litex_sim_sort_session()))
|
||||||
{
|
{
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
tv.tv_sec = 0;
|
tv.tv_sec = 0;
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
ev = event_new(base, -1, EV_PERSIST, cb, vdut);
|
ev = event_new(base, -1, EV_PERSIST, cb, vdut);
|
||||||
event_add(ev, &tv);
|
event_add(ev, &tv);
|
||||||
|
|
||||||
event_base_dispatch(base);
|
event_base_dispatch(base);
|
||||||
out:
|
out:
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -60,7 +60,7 @@ def _generate_sim_cpp_struct(name, index, siglist):
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
|
||||||
def _generate_sim_cpp(platform):
|
def _generate_sim_cpp(platform, trace=False):
|
||||||
content = """\
|
content = """\
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -69,12 +69,27 @@ def _generate_sim_cpp(platform):
|
||||||
#include <verilated.h>
|
#include <verilated.h>
|
||||||
#include "dut_header.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)
|
extern "C" void litex_sim_init(void **out)
|
||||||
{
|
{
|
||||||
Vdut *dut;
|
Vdut *dut;
|
||||||
|
|
||||||
dut = new Vdut;
|
dut = new Vdut;
|
||||||
|
|
||||||
|
litex_sim_init_tracer(dut);
|
||||||
|
|
||||||
"""
|
"""
|
||||||
for args in platform.sim_requested:
|
for args in platform.sim_requested:
|
||||||
content += _generate_sim_cpp_struct(*args)
|
content += _generate_sim_cpp_struct(*args)
|
||||||
|
@ -146,7 +161,7 @@ def _run_sim(build_name, as_root=False):
|
||||||
class SimVerilatorToolchain:
|
class SimVerilatorToolchain:
|
||||||
def build(self, platform, fragment, build_dir="build", build_name="dut",
|
def build(self, platform, fragment, build_dir="build", build_name="dut",
|
||||||
toolchain_path=None, serial="console", build=True, run=True, threads=1,
|
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.makedirs(build_dir, exist_ok=True)
|
||||||
os.chdir(build_dir)
|
os.chdir(build_dir)
|
||||||
|
@ -168,7 +183,7 @@ class SimVerilatorToolchain:
|
||||||
include_paths.append(path)
|
include_paths.append(path)
|
||||||
include_paths += platform.verilog_include_paths
|
include_paths += platform.verilog_include_paths
|
||||||
_generate_sim_h(platform)
|
_generate_sim_h(platform)
|
||||||
_generate_sim_cpp(platform)
|
_generate_sim_cpp(platform, trace)
|
||||||
_generate_sim_variables(include_paths)
|
_generate_sim_variables(include_paths)
|
||||||
if sim_config:
|
if sim_config:
|
||||||
_generate_sim_config(sim_config)
|
_generate_sim_config(sim_config)
|
||||||
|
|
Loading…
Reference in New Issue