|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
有如下代码:
#include <stdio.h>
#include <svdpi.h>
extern void abp_write(int, int);
void c_test(int base) {
int addr, data;
for (addr=base; addr<base+5; addr++) {
data = addr * 100;
apb_write(addr, data);
printf("C_TEST: APB_Write : addr = 0x%8x, data = 0x%8xn", addr, data);
}
}
import "DPI-C" context task c_test(input int base_addr);
program top;
semaphore bus_sem = new(1);
export "DPI-C" task apb_write;
task apb_write(input int addr, data);
bus_sem.get(1);
#10 $display("VLOG : APB Write : Addr = %x, Data = %x ", addr, data);
bus_sem.put(1);
endtask
initial begin
fork
c_test(32'h1000);
c_test(32'h2000);
join
end
endprogram
看不出有什么问题
但用 QuestaSim 10.1b 和 gcc_4.2.1_mingw32vc9 写 的 Makefile
C_PATH = D:\a
DPI_LIB_PATH = C:\questasim_10.1b\include
all: work comp_tb comp_dpi run
work:
vlib work
comp_tb:
vlog -mfcu top.sv -l comp_tb.log
comp_dpi:
C:\ProgramFiles\gcc_4.2.1_mingw32vc9\bin\gcc -O4 -c -fPIC -Wall -I$(DPI_LIB_PATH) $(C_PATH)\c_test.c
C:\ProgramFiles\gcc_4.2.1_mingw32vc9\bin\gcc -shared -Wl,-Bsymbolic -Wl,-export-dynamic -o c_dpi.dll *.o
mv *.o work
mv c_dpi.dll work
run:
vsim -novopt -t 10ps -c -sv_lib work/c_dpi -do "run -all" top -l sim.log
仿真结果如下
D:\a>make all
vlog -mfcu top.sv -l comp_tb.log
QuestaSim vlog 10.1b Compiler 2012.04 Apr 26 2012
-- Compiling package top_sv_unit
-- Compiling program top
Top level modules:
top
C:\ProgramFiles\gcc_4.2.1_mingw32vc9\bin\gcc -O4 -c -fPIC -Wall -IC:\ProgramFile
s\questasim_10.1b\include D:\a\c_test.c
D:\a\c_test.c:1: warning: -fPIC ignored for target (all code is position indepen
dent)
D:\a\c_test.c: In function 'c_test':
D:\a\c_test.c:11: warning: implicit declaration of function 'apb_write'
C:\ProgramFiles\gcc_4.2.1_mingw32vc9\bin\gcc -shared -Wl,-Bsymbolic -Wl,-export-
dynamic -o c_dpi.dll *.o
c_test.o:c_test.c.text+0x2a): undefined reference to `apb_write'
collect2: ld returned 1 exit status
make: *** [comp_dpi] Error 1
哪位高手请指点一下。
非常感谢! |
|