我在 EDA Playground 的 VCS 中使用 DPI-C 的以下代码没有得到正确的输出。我希望 6 作为答案,但无论 a 和 b 值如何,我每次都会得到 248。我尝试使用 svLogic、int 和 unsigned char 作为 helloFromC.c 中 a_int 的数据类型。
module automatic test;
import "DPI-C" function void helloFromC(logic [2:0] a, logic [2:0] b);
initial run();
task run();
logic [2:0] a;
logic [2:0] b;
logic [2:0] c;
a = 3'b100;
b = 3'b010;
c = a+b;
$display("Output from SV is %0d", c);
helloFromC(a,b);
endtask
endmodule
这是我的 C 程序
#include <stdio.h>
#include <svdpi.h>
extern "C" int helloFromC(svLogic a, svLogic b) {
svLogic a_int = a+b;
printf("Output from C is %d", a_int);
return 0;
}
我得到输出
Output from SV is 6
Output from C is 248