Re: How to "import" an interface into a module w/o `include?
- From: Mark Odell <mao@xxxxxxxxxxxxxx>
- Date: Wed, 12 Sep 2007 13:15:36 GMT
On 2007-09-11, Jonathan Bromley <jonathan.bromley@xxxxxxxxxxxxx> wrote:
On Tue, 11 Sep 2007 20:01:28 -0000,
mrfirmware <mrfirmware@xxxxxxxxx> wrote:
[...]<mrfirmw...@xxxxxxxxx> wrote:
I'd like to have a file with an interface in it and then "import" it
into my top level testbench.sv file. Something like this:
// File: my_if.sv
interface my_if;
...
endinterface : my_if
---
// File testbench.sv
import my_if::*;
module testbench;
my_if if0;
...
endmodule : testbench
There's something very basic I'm missing here, I realize that.
[ModelSim/Questa] (v6.3b). I do compile different sources into different
libs but not one file per lib. Must I?
No, certainly not. In fact, many people work with just one
single library for the entire project; that's OK too.
I've got my RTL in lib nz_rtl,
my testbench and top level .sv files in lib nz_top, and my packages in
nz_pkg.
Do you mean the source files are in those directories, or
do you mean that you have used 'vlog' to compile your source files
into ModelSim libraries of those names? If these are simply
the names of directories that contain your source code, then
they are not "libraries" at all and your use of the -L option
is misplaced.
No. For now, I have all my files in one dir. No sub-dirs. Make will find
all the sources automatically when I do end up moving them into proper subdirs.
I put my sole a typedef package file and the interface file
into nz_pkg and then tell vlog about all the library dirs via -L
nz_rtl -L nz_pkg, etc. However, vlog just complains that 'my_if' is an
undefined variable (which isn't too surprising as I don't know how it
could possibly know it's an interface).
Ahah... Do you *really* mean that it's *vlog* complaining (not vsim) ?
If so, it's simple... You don't want the -L option at that stage,
unless you're using packages. You need the -L option to 'vsim'
to tell it the names of all the libraries into which you've compiled
your various SystemVerilog modules and interfaces.
Indeed. E.g.
vlog testbench.sv -work /user/modell/proj/xs1_tb/out/nz_tb
-L /user/modell/proj/xs1_tb/out/nz_pkg
-L /user/modell/proj/xs1_tb/out/nz_rtl
-quiet -nologo -novopt -incr -lint -source -hazards
-timescale 1ns/1ps -dpiheader testbench_dpi.h
###### testbench.sv(145): perbus_if pb_if();
** Error: testbench.sv(145): Undefined variable: perbus_if.
** Error: testbench.sv(145): near "pb_if": syntax error, unexpected "IDENTIFIER"
Line 145 contains the attempt to instantiate a perbus_if which is
an interface defined in the nz_pkg lib (created by vlib).
Just as a for-instance...
Suppose you have this file tree:
project_home/
project_home/sim/ ---- working dir for the simulator
project_home/sources/ ---- dir to hold all source code
project_home/sources/nz_pkg/
project_home/sources/nz_pkg/your_interface.sv
project_home/sources/nz_pkg/your_package.sv
project_home/sources/nz_rtl/
project_home/sources/nz_rtl/your_module1.sv
project_home/sources/nz_rtl/your_module2.sv
project_home/sources/nz_top/
project_home/sources/nz_top/your_design_top.sv
project_home/sources/nz_top/your_testbench.sv
File "your_package.sv" contains a package:
package your_package;
...
endpackage : your_package
Most of the other files import it; for example,
file "your_interface.sv" might look like this:
import your_package::*;
interface your_interface;
...
endinterface
And the instance hierarchy will be
your_testbench
|
|__ your_design_top
|
|__ your_module1
|
|__ your_interface
|
|__ your_module2
My compile/load script for ModelSim might look
something like this:
cd project_home/sim
# make a bunch of libraries - only needed on first run of
# the script, will give harmless warnings on later runs
vlib pkg_lib; # make a ModelSim lib for the packages
vlib rtl_lib; # and another for the RTL design
vlib tb_lib; # and a third for the testbench
# compile package first, into pkg_lib
vlog -work pkg_lib ../sources/nz_pkg/your_package.sv
# now compile all the other code, in any order;
# make pkg_lib visible to each compile so they can
# import the package as needed; put design modules
# into "rtl_lib" and testbench modules into "tb_lib"
vlog -work rtl_lib -L pkg_lib ../sources/nz_pkg/your_interface.sv
vlog -work rtl_lib -L pkg_lib ../sources/nz_rtl/*.sv
vlog -work rtl_lib -L pkg_lib ../sources/nz_top/your_design_top.sv
vlog -work tb_lib -L pkg_lib ../sources/nz_top/your_testbench.sv
# OK, now everything compiled, load it into ModelSim
# making sure that the simulator looks in the right libs
vsim -novopt -L pkg_lib -L rtl_lib tb_lib.your_testbench
This is pretty much what my makefile does too. I do use vmap to map the
long dir name to a shorter name but I think that step could be skipped
as I never actually refer to the short name in any switch usage.
Natch, you may want to add a bunch of other options on some
of these commands. The point I'm really trying to get across
is that a directory full of source code is absolutely NOT the
same as a ModelSim library. (Please, please don't get me
started about Verilog configurations and "libraries", the
Verilog library mapping file [as opposed to ModelSim's
library mapping] and the `uselib directive. That would
take too long, and it's not at all clear my blood pressure
would cope.)
Hope this makes some sense.
It does and thank you.
--
- Mark
.
- Follow-Ups:
- Re: How to "import" an interface into a module w/o `include?
- From: Jonathan Bromley
- Re: How to "import" an interface into a module w/o `include?
- References:
- SV: How to "import" an interface into a module w/o `include?
- From: mrfirmware
- Re: SV: How to "import" an interface into a module w/o `include?
- From: Jonathan Bromley
- Re: How to "import" an interface into a module w/o `include?
- From: mrfirmware
- Re: How to "import" an interface into a module w/o `include?
- From: Jonathan Bromley
- SV: How to "import" an interface into a module w/o `include?
- Prev by Date: Re: Verilog LRM
- Next by Date: Re: How to "import" an interface into a module w/o `include?
- Previous by thread: Re: How to "import" an interface into a module w/o `include?
- Next by thread: Re: How to "import" an interface into a module w/o `include?
- Index(es):
Relevant Pages
|