Export DPI function question about the real type and realtime type

Here is my code below. I always got syntax error during the compilation. Can anyone help me here ?


realtime time1;
realtime time2;
always @ (posedge clk) begin
    time1 <= $realtime;
    time2 <= time1;
end

export "DPI-C" function get_period();

function realtime get_period();
    return (time1 - time2);
endfunction

In reply to zz8318:

It would help to provide the error message as well as a complete example.

I suspect that you have encountered a tool bug. realtime is synonym for real and real types are compatible with the float datatype in C.

This Mentor/Siemens EDA sponsored public forum is not for discussing tool specific usage or issues. Please read your tool’s user manual or contact your tool vendor directly for support.

In reply to dave_59:

Hi Dave,

A quick question here. Do I need to add the return data type in below code to specific ?

export “DPI-C” function ??? get_period();

In reply to zz8318:

No, you are just exporting the function name. Its prototype is in the function declaration.

In reply to dave_59:

Looks like I don’t need ‘()’ following the function name. It passed if I coded like below.

export “DPI-C” function get_period;

In reply to dave_59:

Hi Dave,

I have further question on this topic.

If I coded as below in SV side.


realtime time1;
realtime time2;
always @ (posedge clk) begin
    time1 <= $realtime;
    time2 <= time1;
end

export "DPI-C" function get_period;

function void get_period(output realtime rt);
    rt = (time1 - time2);
endfunction

And in Cplusplus side, how can I get the value rt ?

I coded as below but failed at compilation.
[c]
extern “C” void get_period(double &t);

double &t;
get_period(t);
[/c]

In reply to zz8318:

Repeating my suggestion, it would help to provide the error message as well as a complete example.

The following works for me on EDAPlayground.

#include "dpi.h"
#include <iostream>
using namespace std;
extern "C" void get_period(double* rt);
extern "C" void C_main() {
    double p;
    get_period(&p);
    cout << "Period is " << p << "\n";
}

Most tools provide an automatic header (dpi.h) file so you can match your code’s prototypes with the required prototypes and get a compiler error if they do not match.