Step 1: create a PLI application program in C, such as, a "Hello world" as hereafter.
/********************************************************************** * $hello example -- PLI application using VPI routines * * C source to print "Hello World" as a PLI application. * * Usage: $hello; * * *********************************************************************/
#include /* ANSI C standard library */ #include /* ANSI C standard input/output library */ #include /* IEEE 1364 PLI VPI routine library */
/********************************************************************** * $hello Registration Data * (add this function name to the vlog_startup_routines array) *********************************************************************/ void hello_register() { s_vpi_systf_data tf_data;
Step 3: compiling and linking the $hello system task g++ -c -I/[install_dir]/modeltech/include [app-source-files] ld -G -B symbolic -o mti_pli_apps.so [pli_app_object_files]
In above $hello example, we do as follows: g++ -c -I/[install_dir]/modeltech/include hello_vpi.c g++ -c -I/[install_dir]/modeltech/include hello_register.c ld -G -B symbolic -o mti_pli_apps.so hello_vpi.o hello_register.o
Step 4: Modify the ModelSim .ini file at /[install_dir]/modeltech/modelsim.ini specify the names of the shared object libraries in the Veriuser variable. This variable is typically found towards the middle of the modelsim.ini file, and by default it is commented out. Any number of shared object files may be listed, separated by a white space. As an example, the $hello system task has shared object mti_pli_apps.so, then the Verisuer variable would be set to:
;List of dynamically loaded objects for Verilog PLI applications Veriuser=mti_pli_apps.so
Step 5: Create a verilog file to use $hello system task
hello.v
module hello(clk, reset); input clk, reset; initial begin $hello(); end
endmodule
Step 6: Create do files to run hello.v in ModelSim command-line mode
File test.do: #this is to run hello in cmd mode do test_stim.do quit -f
File test_stim.do
# setup an oscillator on the CLK input force clk 1 50 -r 100 force clk 0 100 -r 100
# reset the clock and then count to 100 force reset 1 run 100
force reset 0 run 10000
Step 7: Simulate Hello.v in modelSim
Type following command in Dos/Unix prompt $vsim -c -do test.do test -wlf test.wlf
The -c argument instructs ModelSim not to invoke the GUI. The -wlf argument saves the simulation results in a WLF file. This allows you to view the simulation results in the GUI for debugging purposes.