Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
17 years ago

Interfacing to C

Has anybody managed to successfully interface to C in Modelsim?

I have a function or procedure in VHDL which I want to farm out to a bit of C code:

function my_function (input : integer) return real;
attribute foreign of my_function  : function is "my_function path_to_my_package.dll";
The C code looks like:

__declspec( dllexport ) double my_function (int input) {
    double temp = 1E15;
    return temp;
}
__declspec( dllexport ) is just to get Visual C to make the function visible to the outside world.

I've tried this as a procedure too:

procedure my_proc (input : in integer; real_output : out real);
attribute foreign of my_proc : function is "my_proc path_to_my_package.dll";
And two alternatives for the C (neither of which work):

__declspec( dllexport ) void my_proc (int input, double output) {
    output = 1E15;
    return;
}
__declspec( dllexport ) void my_proc (int input, double *output) {
    *output = 1E15;
    return;
}
Everything compiles and Modelsim loads everything without complaint but I can't get the C code to modify the variable in VHDL. I don't get any errors when I run a simulation but the VHDL variable remains unchanged.

I've scoured the Modelsim FLI document and I can't find any suggestion of what I'm doing wrong.

Does anybody have any ideas?

Cheers