Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
17249 Discussions

exporting system verilog functions and task to C using DPI

Altera_Forum
Honored Contributor II
5,019 Views

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
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
3,822 Views

Most likely you are using an unsupported gcc version. Check the compatibility of gcc versions with your version of modelsim. 

 

If you have ModelSim 10.1 or later, you can put your C file on the vlog command line and it will compile the C file for you 

 

vlog -dpiheader dpiheader.h helloc.sv helloc.c 

 

(Do not use the -sv switch if your SV files already have a .sv extension, otherwise all files including .v will be treated as SystemVerilog)
0 Kudos
Altera_Forum
Honored Contributor II
3,822 Views

i have a ModelSim-Altera 6.5b starter edition and 4.6.2 version of mingw in windows 7 pc... 

 

any idea if the gcc version is the right one? :$
0 Kudos
Altera_Forum
Honored Contributor II
3,822 Views

MinGW gcc 3.2.3 was the recommended version at the time Modelsim 6.5b was released in 2009. You either need to downgrade your gcc or upgrade your Modelsim.

0 Kudos
Altera_Forum
Honored Contributor II
3,822 Views

which version of ModelSim is compatible with 4.6.2 gcc? :| will try to upgrade ModelSim that particular version.. 

 

btw thanks a lot for the replies... i am literally running out of time for this project of mine.. :(
0 Kudos
Altera_Forum
Honored Contributor II
3,822 Views

It worked for me with 4.2.1 and that is the minimum version supported in Modelsim 10.2.  

 

You should install the version of gcc that the version of Modelsim recommends. You can have multiple versions on your system if you need them.
0 Kudos
Reply