一個簡單的DPI Array Packed case
這個例子是在Cadence的IUS9.2的cdnshelp上所找到的
這是個dynamic array的case
另外所寫的static array的case在Cadence 上測不過
但VCS上似乎可用, static array還要多花一些時間測試
gcc –I/IUS9.2/linux/tools/include/ -shared –o test.so test.c
使用gcc時, 副檔名必須為c
g++ –I/IUS9.2/linux/tools/include/ -shared –o test.so test.cpp
使用g++時, 副檔名必須為cpp
irun_92 main.sv –sv_lib test.so
//test.c
#include <stdio.h>
#include “svdpi.h”
#include <stdlib.h>
void reverse_logic_vec(const svOpenArrayHandle a, const svOpenArrayHandle b) {
// test.cpp 如果用g++ 就改成下面這一行
// extern “C” void reverse_logic_vec
// (const svOpenArrayHandle a, const svOpenArrayHandle b) {
// 此處 a 為 input , b為output
int i;
int left, right, low, high;
svLogicVecVal *bv1, *bv2, *bv3, *bv4;
bv1 = (svLogicVecVal *) malloc (sizeof(svLogicVecVal) *1);
bv2 = (svLogicVecVal *) malloc (sizeof(svLogicVecVal) *1);
bv3 = (svLogicVecVal *) malloc (sizeof(svLogicVecVal) *1);
bv4 = (svLogicVecVal *) malloc (sizeof(svLogicVecVal) *1);
svGetLogicArrElem1VecVal(bv1, a, 0); 將array a[0]的值傳給bv1
svGetLogicArrElem1VecVal(bv2, a, 1); 將array a[1]的值傳給bv2
svGetLogicArrElem1VecVal(bv3, a, 2); 將array a[2]的值傳給bv3
svGetLogicArrElem1VecVal(bv4, a, 3); 將array a[3]的值傳給bv4
svPutLogicArrElem1VecVal(b, bv1, 3); 將bv1的值傳給array b[3]
svPutLogicArrElem1VecVal(b, bv2, 2); 將bv2的值傳給array b[2]
svPutLogicArrElem1VecVal(b, bv3, 1); 將bv3的值傳給array b[1]
svPutLogicArrElem1VecVal(b, bv4, 0); 將bv4的值傳給array b[0]
}
module main();
logic [4:1] input_1 [3:0];
logic [4:1] input_1 [3:0];
logic [0:3] output_1 [3:0];
import "DPI-C" function void reverse_logic_vec (input logic [3:0] i[ ], output logic [3:0] o[ ] );
initial begin
input_1[0] = 4’b1111;
input_1[1] = 4’b0000;
input_1[2] = 4’bxxxx;
input_1[3] = 4’bzzzz;
#5 reverse_logic_vec(input_1, output_1);
// input_1 對應到C code上的array a,
// output_1對應到C code上的array b,
for (int i = 0; i<4 ; i++) begin
$display("input[%d] = %b, output[%d] = %b\n ",i, input_1[i], i, output_1[i] );
end
#5 $finish;
endmodule
$display("input[%d] = %b, output[%d] = %b\n ",i, input_1[i], i, output_1[i] );
end
#5 $finish;
endmodule
上面有用到svLogicVecVal, 照文件上的說明
svBitVecVal canonical form for 2-state packed arrays
svLogicVecVal canonical form for 4-state packed arrays
沒有留言:
張貼留言