diff --git a/verilog_iverilog/VPI_example/Makefile b/verilog_iverilog/VPI_example/Makefile new file mode 100644 index 0000000..7b09e7e --- /dev/null +++ b/verilog_iverilog/VPI_example/Makefile @@ -0,0 +1,15 @@ +OBJECTS= hello.vvp hello.o +CFLAGS = -Wall -O $(CFLAGS_$@) + + +simulate: ${OBJECTS} + vvp -M. -mhello hello.vvp + +%.o:%.c + iverilog-vpi $< --name $(subst .o,,$@) + +%.vvp:%.v + iverilog $^ -o $@ + +clean: + rm ${OBJECTS} -f diff --git a/verilog_iverilog/VPI_example/hello.c b/verilog_iverilog/VPI_example/hello.c new file mode 100644 index 0000000..64aa6e2 --- /dev/null +++ b/verilog_iverilog/VPI_example/hello.c @@ -0,0 +1,41 @@ +#include + +static int hello_compiletf(char* user_data){ + return 0; +} + +static int hello_calltf(char* user_data){ + vpiHandle systfref, args_iter, argh; + struct t_vpi_value argval; + int value; + + // Obtain a handle to the argument list + systfref = vpi_handle(vpiSysTfCall, NULL); + args_iter = vpi_iterate(vpiArgument, systfref); + + // Grab the value of the first argument + argh = vpi_scan(args_iter); + argval.format = vpiIntVal; + vpi_get_value(argh, &argval); + value = argval.value.integer; + vpi_printf("Hello World!\nVPI routine received %d\n", value); + + return 0; +} + +void hello_register(){ + s_vpi_systf_data tf_data; + + tf_data.type = vpiSysTask; + tf_data.tfname = "$hello"; + tf_data.calltf = hello_calltf; + tf_data.compiletf = hello_compiletf; + tf_data.sizetf = 0; + tf_data.user_data = 0; + vpi_register_systf(&tf_data); +} + +void (*vlog_startup_routines[])() = { + hello_register, + 0 +}; diff --git a/verilog_iverilog/VPI_example/hello.o b/verilog_iverilog/VPI_example/hello.o new file mode 100644 index 0000000..1e57f70 Binary files /dev/null and b/verilog_iverilog/VPI_example/hello.o differ diff --git a/verilog_iverilog/VPI_example/hello.v b/verilog_iverilog/VPI_example/hello.v new file mode 100644 index 0000000..ed77418 --- /dev/null +++ b/verilog_iverilog/VPI_example/hello.v @@ -0,0 +1,9 @@ +module main; +integer val; + +initial begin + val = 41; + $hello(val); +end + +endmodule diff --git a/verilog_iverilog/VPI_example/hello.vpi b/verilog_iverilog/VPI_example/hello.vpi new file mode 100755 index 0000000..c90ff49 Binary files /dev/null and b/verilog_iverilog/VPI_example/hello.vpi differ diff --git a/verilog_iverilog/VPI_example/hello.vvp b/verilog_iverilog/VPI_example/hello.vvp new file mode 100755 index 0000000..22a18b6 --- /dev/null +++ b/verilog_iverilog/VPI_example/hello.vvp @@ -0,0 +1,24 @@ +#! /usr/bin/vvp +:ivl_version "11.0 (stable)"; +:ivl_delay_selection "TYPICAL"; +:vpi_time_precision + 0; +:vpi_module "/usr/lib/x86_64-linux-gnu/ivl/system.vpi"; +:vpi_module "/usr/lib/x86_64-linux-gnu/ivl/vhdl_sys.vpi"; +:vpi_module "/usr/lib/x86_64-linux-gnu/ivl/vhdl_textio.vpi"; +:vpi_module "/usr/lib/x86_64-linux-gnu/ivl/v2005_math.vpi"; +:vpi_module "/usr/lib/x86_64-linux-gnu/ivl/va_math.vpi"; +S_0x561f1548f320 .scope module, "main" "main" 2 1; + .timescale 0 0; +v0x561f15457770_0 .var/i "val", 31 0; + .scope S_0x561f1548f320; +T_0 ; + %pushi/vec4 41, 0, 32; + %store/vec4 v0x561f15457770_0, 0, 32; + %vpi_call 2 6 "$hello", v0x561f15457770_0 {0 0 0}; + %end; + .thread T_0; +# The file index is used to find the file name in the following table. +:file_names 3; + "N/A"; + ""; + "hello.v";