testbench实现
import "DPI-C" function void modulate_my_frame (input byte unsigned data[], int len1, int len2, inout byte unsigned d[]);
module harness;
byte unsigned c[];
byte unsigned d[];
int len1 = 10;
int len2 = 20;
initial begin
c = new[len1];
d = new[len2];
c[0] = 100;
c[1] = 100;
c[2] = 100;
c[3] = 100;
c[4] = 100;
c[5] = 100;
$display("c=%p", c);
modulate_my_frame(c, len1, len2, d);
$display("d=%p", d);
$finish;
end
initial begin
$fsdbDumpfile("top.fsdb");
$fsdbDumpvars(0);
end
endmodule
C函数实现
#include <stdio.h>
#include <svdpi.h>
void modulate_my_frame (const svOpenArrayHandle p, int len1, int len2, svOpenArrayHandle q)
{
int i, j;
unsigned char p1, *q1;
printf("len1=%0d\r\n", len1);
printf("len2=%0d\r\n", len2);
for (i = 0; i < len1; i++) {
p1 = *(unsigned char *)svGetArrElemPtr1(p, i);
printf("p[%d]=%2x\r\n", i, p1);
}
for (j = 0; j < len2; j++) {
*(unsigned char *)svGetArrElemPtr1(q, j) = 0x55;
}
}
Makefile脚本
all:
@make clean && make comp && make run
comp:
@vcs -sverilog -full64 -kdb -lca -debug_access+all +libext.sv+.v *.c *.sv
run:
@./simv
verdi:
@verdi -ssf top.fsdb &
clean:
@rm -rf `ls -1 | grep -E -v "Makefile|makefile|harness.sv|*.c"`