24.03.2013 Views

ModelSim SE User's Manual - Electrical and Computer Engineering

ModelSim SE User's Manual - Electrical and Computer Engineering

ModelSim SE User's Manual - Electrical and Computer Engineering

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

VPI example<br />

The following example is a trivial, but complete VPI application. A general VPI example<br />

can be found in /modeltech/examples/vpi.<br />

hello.c:<br />

#include "vpi_user.h"<br />

static PLI_INT32 hello(PLI_BYTE8 * param)<br />

{<br />

vpi_printf( "Hello world!\n" );<br />

return 0;<br />

}<br />

void RegisterMyTfs( void )<br />

{<br />

s_vpi_systf_data systf_data;<br />

vpiH<strong>and</strong>le systf_h<strong>and</strong>le;<br />

systf_data.type = vpiSysTask;<br />

systf_data.sysfunctype = vpiSysTask;<br />

systf_data.tfname = "$hello";<br />

systf_data.calltf = hello;<br />

systf_data.compiletf = 0;<br />

systf_data.sizetf = 0;<br />

systf_data.user_data = 0;<br />

systf_h<strong>and</strong>le = vpi_register_systf( &systf_data );<br />

vpi_free_object( systf_h<strong>and</strong>le );<br />

}<br />

void (*vlog_startup_routines[])() = {<br />

RegisterMyTfs,<br />

0<br />

};<br />

hello.v:<br />

module hello;<br />

initial $hello;<br />

endmodule<br />

Compile the VPI code for the Solaris operating system:<br />

% gcc -c -I/include hello.c<br />

% ld -G -o hello.sl hello.o<br />

Compile the Verilog code:<br />

% vlib work<br />

% vlog hello.v<br />

Simulate the design:<br />

% vsim -c -pli hello.sl hello<br />

# Loading work.hello<br />

# Loading ./hello.sl<br />

VSIM 1> run -all<br />

# Hello world!<br />

VSIM 2> quit<br />

VPI example UM-583<br />

<strong>ModelSim</strong> <strong>SE</strong> User’s <strong>Manual</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!