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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

UM-582 D - Verilog PLI / VPI / DPI<br />

PLI example<br />

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

The following example is a trivial, but complete PLI application.<br />

hello.c:<br />

#include "veriuser.h"<br />

static PLI_INT32 hello()<br />

{<br />

io_printf("Hi there\n");<br />

return 0;<br />

}<br />

s_tfcell veriusertfs[] = {<br />

{usertask, 0, 0, 0, hello, 0, "$hello"},<br />

{0} /* last entry must be 0 */<br />

};<br />

hello.v:<br />

module hello;<br />

initial $hello;<br />

endmodule<br />

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

% cc -c -I/modeltech/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 />

# Hi there<br />

VSIM 2> quit

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

Saved successfully!

Ooh no, something went wrong!