verilog PLI 实例

在testbench中可以通过PLI调用c/c++函数

hello world示例:

hello.c

#include <stdio.h> 
 
void hello_call () {
  printf ("\nHello World\n");
}

hello.v

module hello_pli ();
        
initial begin
  $hello;
  #10  $finish;
end
        
endmodule

如果使用vcs,则要添加tab文件以确定函数的关联
hello.tab如下

$hello call=hello_call acc+=rw:*

编译运行命令为:

vcs -R -P hello.tab hello.v hello.c

可以再c程序中使用PLI标准函数
需包含头文件:

#include "acc_user.h"
#include "vcsuser.h"

常用函数如:
tf_getp(pnum); //返回verilog调用传递的第pnum个参数

tf_putp(pnum,pval) //设置第pnum个参数为pval

 

posted on 2013-06-14 15:33  逆转骑士  阅读(664)  评论(0编辑  收藏  举报

导航