My first piece of advice with the PLI is to not use it. Why? Because if you can do something in Verilog, it is more clear and easier to maintain and reuse. For a simple device, write a model in Verilog before trying it with the PLI.
There are four levels of the PLI. The first are the TF (task/function) routines that allow C to access arguments to the system task, as in:
The next level are the ACC routines, which can access any signal in the
design. These can be used when for delay calculators and waveform dumping
Reading and Writing files from VerilogRead and writing files from Verilog - Now you can read any format file into your model, and open hundreds of output files. Used by dozens of companies around the world. If you are using the latest version of VCS, NC-Verilog, and ModelSim, this is already built into your simulator.
Download the latest file I/O routines for Verilog, currently v3.6 (released 8/31/04). (If you see a page of text when you download, try the uncompressed version, or do a File > Save As > "fileio.tar" as your browser may be automatically decompressing the file.) Read about this PLI application.
Other PLI applications
Read VCD files - My most frequent request from you readers is a way to look at signal changes in the simulation. Don't write it with the PLI - use VCD files instead. But how can you read them? My VCD reader package can read the files either from Unix, or back into a Verilog simulation. Think about analyzing signal behavior, replaying vectors from one simulation to another, or many other ideas.NEW 3/05 but it has been around for years...
Simple C++ example with VCS New 6/03
Read fixed patterns Updated 10/17/03Here is an application to read pattern files without having to be a programmer.
Strobe Compare - Compare the results from two Verilog simulations.
Find X - Locate the unknowns in your simulations. Great for debugging reset problems. Updated 10/17/03.
Write Stdio - How to use the VCS file pointer for stdout - useful for C programmers.
Your own idea - Ask me for help writing a new PLI application. Please note: if a task can be done in Verilog, it will be easier to debug, probably run faster, and be more portable than writing C code with a myriad of PLI calls. So don't ask for the C equivalent of a Verilog module.
Learn more about the PLIVerilog PLI Handbook - Stuart Sutherland has written great book on the PLI with detailed explanations and examples. His encyclopedic knowledge of the PLI makes this the most comprehensive guide available. Check out his site and place your order with him. Even if you only use one example, it will be worth every penny.
Stu has also published Verilog 2001, A Guide to the New Features of the Verilog Hardware Description Language. A great reference for anyone wanting to know more about what has changed, but does not want to wade through the IEEE manual.
Home SystemVerilog PLI Verilog Verification PMC Emacs Bike Personal Viewlogic