對於在EDA Playground中使用VCS中的DPI-C的以下代碼,我沒有得到正確的輸出。我期望6作爲答案,但我每次獲得248,而不考慮a和b的值。我已經嘗試在helloFromC.c中使用svLogic,int和unsigned char作爲a_int的數據類型。在DPI-C中,哪些數據類型用於內部變量?
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
從'svdpi.h'頭看起來'svLogic'是'uint8_t'。如果是這樣,那與C中的「%d」格式字符串不匹配。 –
「邏輯」是一個4狀態變量。嘗試'位'。另外,因爲你使用3位變量,所以在'c'中掩碼m/ – Serge
@Serge我沒有得到你的意思「掩蓋m中的'c'」 –