Altera_Forum
Honored Contributor
13 years agoexporting system verilog functions and task to C using DPI
hello,
I have been trying to import and export functions and task through DPI between system verilog and C. I have managed to import functions and task from C to SV:) but can't really figure out how to export SV functions and tasks to C:confused:. I tried an example code given in the modelsim manual but i just doesn't work :( this is how the code looks like; sv file: module helloc(); int ret; export "DPI-C" task verilog_task; task verilog_task (input i, output int o); # 10; $display ("hello from sv"); endtask import "DPI-C" context task c_task (input int i, output int o); initial begin c_task(1,ret); end endmodule C file :# include <stdio.h># include <svdpi.h># include <conio.h># include <dpiheader.h> int c_task(int i, int*o) { printf("hello from c"); verilog_task(i, o); *o = i; return 0; } the dpiheader.h file was generated by Modelsim when given the command vlog -sv -dpiheader dpiheader.h helloc.sv this is the error i get when trying to compile the C file: # In file included from helloc.c:4:0:# c:\mingw\bin\../lib/gcc/mingw32/4.7.2/../../../../include/dpiheader.h:26:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'int' the error is in the dpiheader file!!! and if i remove this header file then the compiler doesn't consider the verilog_task as a task. it gives an error again. I will obliged if someone can help me out with this prob:oops: really gotta figure this prob out asap... pls reply asap