微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 微电子和IC设计 > IC验证交流 > SystemVerilog DPI 问题

SystemVerilog DPI 问题

时间:10-02 整理:3721RD 点击:
有如下代码:
#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
哪位高手请指点一下。
非常感谢!

C里不能调用时间推进的SV task, 大概

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top