/**********************************************************************

* $hello example -- Verilog HDL test bench.

*

* For the book, "The Verilog PLI Handbook" by Stuart Sutherland

* Copyright 1999 & 2001, Kluwer Academic Publishers, Norwell, MA, USA

* Contact: www.wkap.il

* Example copyright 1998, Sutherland HDL Inc, Portland, Oregon, USA

* Contact: www.sutherland-hdl.com

*********************************************************************/

`timescale 1ns / 1ns

module test;

initial

begin

$hello;

// #10 $stop;

#10 $finish;

end

endmodule

/**********************************************************************/

文件名为hello_test.v

/**********************************************************************

* $hello example -- PLI application using VPI routines

*

* C source to print "Hello World" as a PLI application.

*

* Usage: $hello;

*

* For the book, "The Verilog PLI Handbook" by Stuart Sutherland

* Copyright 1999 & 2001, Kluwer Academic Publishers, Norwell, MA, USA

* Contact: www.wkap.il

* Example copyright 1998, Sutherland HDL Inc, Portland, Oregon, USA

* Contact: www.sutherland-hdl.com

*********************************************************************/

#include /* ANSI C standard library */

#include /* ANSI C standard input/output library */

#include /* ANSI C standard arguments library */

#include "vpi_user.h" /* IEEE 1364 PLI VPI routine library */

/**********************************************************************

* calltf routine

*********************************************************************/

PLI_INT32 PLIbook_hello_calltf(PLI_BYTE8 *user_data)

{

vpi_printf("\nHello World!\n\n");

return(0);

}

/**********************************************************************

* $hello Registration Data

* (add this function name to the vlog_startup_routines array)

*********************************************************************/

void PLIbook_hello_register()

{

s_vpi_systf_data tf_data;

tf_data.type = vpiSysTask;

tf_data.sysfunctype = 0;

tf_data.tfname = "$hello";

tf_data.calltf = PLIbook_hello_calltf;

tf_data.compiletf = NULL;

tf_data.sizetf = NULL;

tf_data.user_data = NULL;

vpi_register_systf(&tf_data);

}

文件名为hello_vpi.c

/**********************************************************************

* Example vpi_user.c file

*

* vpi_user.c file to register PLI applications using the VPI library.

*

* For the book, "The Verilog PLI Handbook" by Stuart Sutherland

* Copyright 1999 & 2001, Kluwer Academic Publishers, Norwell, MA, USA

* Contact: www.wkap.il

* Example copyright 1998, Sutherland HDL Inc, Portland, Oregon, USA

* Contact: www.sutherland-hdl.com

*********************************************************************/

#include "vpi_user.h"

/* prototypes of the PLI registration routines */

extern void PLIbook_hello_register();

void (*vlog_startup_routines[])() =

{

/*** add user entries here ***/

PLIbook_hello_register,

0 /*** final entry must be 0 ***/

};

文件名为 vpi_user.c

gcc -m32 vpi_user.c hello_vpi.c -fPIC -shared -o hello.so

vcs +cli+3 +vpi -R -load ./hello.so:PLIbook_hello_register ./hello_test.v

前提:存在vpi_user.h文件

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐