/**********************************************************************
* $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文件