PLI (which stands for Programming Language Interface) and FLI (which stands for Foreign Language Interface) allow you to write C/C++ code and then call this code from your Verilog testbench. In order to be able to do something that is relevant to the simulation (for example to set or reset signals), the C/C++ code you write must have access to the internal data structures of the simulator (for example to the data base that contains the names of all the signals in the design). The standards for PLI/FLI defines a set of functions that every Verilog simulator must support, and that can access and manipulate the simulator data structures. Among programmers, such a set of functions is generally referred to as API (Application Programmer Interface), that is, a set of functions that a program exposes so that programmers can customize it or write other programs that use it. A famous example is Microsoft Windows API. Microsoft Windows API allows you, for example, to call a function that will create a new window.
My intention in this tutorial is to provide fully commented, rather simple but working, PLI applications, along with detailed instructions on how to make these PLI applications actually work. From my experience, the most annoying part in PLI, is to actually make the first PLI application work, espacially if you are using Windows. The examples below have all been written for Modelsim running on a Windows platform, using Microsoft Visual C++ (Microsoft Visual Studio).
download "Hello World"
This program is a PLI application that writes the words "Hello World" to your simulator standard output (i.e. the main screen). Follow the steps below to run it (all of them are very simple so don't worry):
1. Unzip the files.
2. Start Microsoft Visual Studio
3. Choose "file -> open -> project" and choose "pli_hello1.vcproj" from the unzipped library.
4. In order for the project to compile and link properly you must specify the locations of two files - "veriuser.h" and "mtipli.lib"
5. In the "Solution Explorer" at the top left of the screen select the project "pli_hello1".
6. Right click and choose "properties"
7. On the left hand side of the "pli_hello1 property pages" box choose "C/C++ -> general"
8. On the right hand side go to "Additional Include Directories" and add the "include" directory in your modelsim installation directory
9. On the left hand side choose "Linker -> general"
10. On the right hand side go to "Additional Library Directories" and add the "win32" directory in your modelsim installation directory
11. On the left hand side choose "Linker -> input"
12. On the right hand side go to "Additional Dependancies" and add the filename "mtipli.lib"
13. Close the properties box and choose "build -> "rebuild pli_hello1"
14. Open the "pli_hello1" directory in the explorer, go to the "debug" directory and copy the file "pli_hello1.dll"
15. Paste the file "pli_hello1.dll" at your modelsim installation directory.
16. Open the file "modelsim.ini" at your modelsim installation directory, look for the word "veriuser", delete the semi-colon at the beginning and replace "veriuser.sl" with "pli_hello1.dll"
17. Save the file "pli_hello1.v" (from the .zip file you just downloaded) in the "examples" library at your modelsim installation directory
18. Run modelsim, compile "pli_hello1.v" (vlog pli_hello1.v) and then load it (vsim pli_hello1). Modelsim should write that it has loaded the pli_hello1.dll in the output.
19. Type "run -all". You should see the words "Wellcome to the wonderful world of PLI" on the screen.
20. Good luck.
This is the simplest way to do this. There are many possible shortcuts but I haven't taken them. You will find them easily yourself.
文章评论(0条评论)
登录后参与讨论