diff options
author | Tristan Gingold <tgingold@free.fr> | 2018-02-25 08:28:45 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2018-02-25 08:28:45 +0100 |
commit | 8c8b6285bd3532c2f158e33885ea5984dc62270b (patch) | |
tree | d18c47ff977796f398e29de22bdc80899f28ae2a /testsuite/gna/issue531/vpi1.c | |
parent | 39d357cdff5f78e3727db50b40b259d033670d7f (diff) | |
download | ghdl-8c8b6285bd3532c2f158e33885ea5984dc62270b.tar.gz ghdl-8c8b6285bd3532c2f158e33885ea5984dc62270b.tar.bz2 ghdl-8c8b6285bd3532c2f158e33885ea5984dc62270b.zip |
Add testcase for #531
Diffstat (limited to 'testsuite/gna/issue531/vpi1.c')
-rw-r--r-- | testsuite/gna/issue531/vpi1.c | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/testsuite/gna/issue531/vpi1.c b/testsuite/gna/issue531/vpi1.c new file mode 100644 index 000000000..a555ee4d6 --- /dev/null +++ b/testsuite/gna/issue531/vpi1.c @@ -0,0 +1,114 @@ +#include <stdio.h> +#include <string.h> +#include <vpi_user.h> + +struct net_descs +{ + const char *name; + vpiHandle *handle; +}; + +static vpiHandle clk, arg_a, arg_b, res; +static int cnt; + +static struct net_descs nets[] = { + { "sliced_ex.clk", &clk}, + { "sliced_ex.arg_a", &arg_a}, + { "sliced_ex.arg_b", &arg_b}, + { "sliced_ex.sub_module.res", &res}, + { NULL, NULL} +}; + +static PLI_INT32 +vpi_clk_proc(p_cb_data data) +{ + s_vpi_value val; + + val.format = vpiBinStrVal; + vpi_get_value (clk, &val); + /* Detect edge. */ + if (strcmp (val.value.str, "1") != 0) + return 0; + + val.format = vpiBinStrVal; + vpi_get_value (res, &val); + printf ("cycle %d: res = %s\n", cnt, val.value.str); + + switch (cnt) + { + case 0: + val.format = vpiBinStrVal; + val.value.str = "0001"; + vpi_put_value (arg_a, &val, NULL, vpiNoDelay); + val.format = vpiBinStrVal; + val.value.str = "0010"; + vpi_put_value (arg_b, &val, NULL, vpiNoDelay); + break; + case 2: + val.format = vpiBinStrVal; + val.value.str = "0010"; + vpi_put_value (arg_a, &val, NULL, vpiNoDelay); + val.format = vpiBinStrVal; + val.value.str = "0011"; + vpi_put_value (arg_b, &val, NULL, vpiNoDelay); + break; + case 3: + if (strcmp(val.value.str, "00000000") != 0) + printf ("Error!\n"); + break; + case 4: + if (strcmp(val.value.str, "00010011") != 0) + printf ("Error!\n"); + break; + default: + break; + } + + cnt++; + return 0; +} + +static PLI_INT32 +vpi_start_proc(p_cb_data data) +{ + s_vpi_value val; + s_cb_data cb; + int i; + + for (i = 0; nets[i].name; i++) + { + *nets[i].handle = vpi_handle_by_name ((char *)nets[i].name, NULL); + if (*nets[i].handle == NULL) + { + printf ("cannot get net %s\n", nets[i].name); + return 0; + } + } + + cb.reason = cbValueChange; + cb.cb_rtn = &vpi_clk_proc; + cb.user_data = NULL; + cb.obj = clk; + if (vpi_register_cb (&cb) == NULL) + vpi_printf ("cannot register ValueChange call back\n"); + + return 0; +} + +static void +my_handle_register(void) +{ + s_cb_data cb; + + cb.reason = cbStartOfSimulation; + cb.cb_rtn = &vpi_start_proc; + cb.user_data = NULL; + if (vpi_register_cb (&cb) == NULL) + vpi_printf ("cannot register EndStartOfSimulation call back\n"); +} + +void (*vlog_startup_routines[]) () = +{ + my_handle_register, + 0 +}; |