简体   繁体   English

如何使用verilog PLI通过ncverilog编译器与c进行通信

[英]how to use verilog PLI communicate with c by ncverilog compiler

I would like to communicate c with verilog. 我想用verilog与c沟通。 I find the Verilog PLI can solve my problem. 我发现Verilog PLI可以解决我的问题。 I read this website to learn http://www.asic-world.com/verilog/pli1.html#How_it_Works . 我阅读本网站了解http://www.asic-world.com/verilog/pli1.html#How_it_Works But I still can't work even a printf function. 但我仍然无法工作甚至printf功能。 I use ncverilog for verilog compiler. 我使用ncverilog进行verilog编译。 What I done is blow. 我所做的就是打击。 I can't have a successful compile for this. 我无法成功编译。 It says that it can't find the function. 它说它无法找到功能。 Can anyone tell me how to solve my problem. 谁能告诉我如何解决我的问题。 thanks =) 谢谢=)

C code: hello.c C代码:hello.c

#include<stdio.h>
void hello(){
   printf("HELLO");
}

make library: 制作图书馆:

gcc hello.c -fPIC -shared -o hello.so

verilog code: test.v verilog代码:test.v

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

verilog command: verilog命令:

ncverilog test.v +access+r -v hello.so

VPI (PLI 2.0) VPI (PLI 2.0)

hello_vpi.c : hello_vpi.c:

#include<stdio.h>
#include <vpi_user.h>
void hello(){
   printf("HELLO");
}

void register_hello()
{
    s_vpi_systf_data data;
    data.type      = vpiSysTask; //vpiSysFunc;
//  data.sysfunctype = vpiSysFuncInt; // return type if type is Func
    data.tfname    = "$hello";
    data.calltf    = hello;
    data.compiletf = 0;
    data.sizetf    = 0;
    data.user_data = 0;
    vpi_register_systf(&data);
}

Commands: 命令:

gcc hello_vpi.c -fPIC -shared -o hello_vpi.so
ncverilog test.v +access+r -loadvpi ./hello_vpi.so:register_hello

PLI 1.0 requires all the C methods use in verilog to be defined in s_tfcell veriusertfs[] . PLI 1.0要求在s_tfcell veriusertfs[]定义verilog中使用的所有C方法。 Ncverilog requires an additional bootstrap method that returns a type p_tf_cell , this method defines a static s_tfcell veriusertfs[] . Ncverilog需要一个额外的bootstrap方法,它返回一个p_tf_cell类型,这个方法定义了一个静态的s_tfcell veriusertfs[] Here is an example: 这是一个例子:

veriuser_nc.c : veriuser_nc.c:

#include "veriuser.h"
#include "acc_user.h"

extern void hello();

#define user_task          1
#define user_function      2

p_tfcell my_boot() {
  s_tfcell veriusertfs[] = {
    /* {user_function/usertask, (int)data, pli_checkp, pli_sizep, pli, ?, verilog_name, ? } */
    {usertask, 0, 0, 0, hello, 0, "$hello", 1},
    {0}  // last entry must be 0 
  };
  return(veriusertfs);
}

Commands: 命令:

gcc hello.c veriuser_nc.c -fPIC -shared -o hello_pli.so
ncverilog test.v +access+r -loadpli1 ./hello_pli.so:my_boot

VCS requires a tab file instead of an bootstrap method. VCS需要选项卡文件而不是引导程序方法。 This is lightly covered here: http://www.asic-world.com/verilog/pli2.html#Linking_With_Simulator 这里有一点: http//www.asic-world.com/verilog/pli2.html#Linking_With_Simulator


Another approach is to use SystemVerilog DPI which does not have a wrapper/translation layer in the same sense as PLI/VPI. 另一种方法是使用SystemVerilog DPI ,它没有与PLI / VPI相同的包装/转换层。

Add #include "svdpi.h" to the head of hello.c. #include "svdpi.h"添加到hello.c的头部。 I'm just changing the shared objects name to identify the library type (not required). 我只是更改共享对象名称以标识库类型(不是必需的)。 gcc hello.c -fPIC -shared -o hello_dpi.so

verilog code: test.sv verilog代码:test.sv

module test();
   import "DPI-C" pure function void hello();
   // DPI methods are treated as verilog task/function after import, including scope access
   initial begin
      hello(); // dpi doesn't have a $
      #10 $finish;
   end
endmodule

verilog command: verilog命令:

ncverilog -sv test.sv +access+r -sv_lib hello_dpi.so

Documentation on DPI is in the IEEE std 1800-2012 § 35. Direct programming interface. 有关DPI的文档在IEEE标准1800-2012§35 。直接编程接口。 PLI/VPI is covered in § 36 but does not cover simulator specif requirements. PLI / VPI在第36节中介绍,但不包括模拟器的特定要求。 For more description and tutorials about DPI, checkout http://en.wikipedia.org/wiki/SystemVerilog_DPI and http://www.doulos.com/knowhow/sysverilog/tutorial/dpi/ 有关DPI的更多说明和教程, 请访问 http://en.wikipedia.org/wiki/SystemVerilog_DPIhttp://www.doulos.com/knowhow/sysverilog/tutorial/dpi/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM