Libraries and Packages
Libraries and Packages
Dr DC Hendry
1 Libraries
VHDL does not completely define this mechanism, rather, the final mapping of
a library name to a disc file is left to the vendor to define, Cadence use the file
cds.lib to do this, Synopsys use a file called .synopsys vss.setup for this.
Each vendor has their own conventions within such files. These files indicate for
each VHDL library name where to find that library on disc. Again depending
on the vendor, a library may reside in a single disc file (unusual), or more likely,
be mapped to a directory.
Here is the contents of the cds.lib file for the laboratory exercise:
The first line says that the VHDL library called worklib is to be found in the
directory ./workLib, i.e. a directory called workLib in the current directory.
Note that Cadence associates each VHDL library name with a directory.
The second line states that the library called tsmc018 is to be found in the given
directory. This library is that containing the simulation models for the TSMC
1.1 WORK Libraries and Packages
0.18m process used in the laboratory. You will see the name tsmc018 used in
the configuration files for those examples where a netlist is simulated.
The final line is replaced by the contents of the given filename (supplied by
Cadence) and contains define lines for libraries such as ieee.
1.1 WORK
All VHDL systems assume that one library called WORK is available. WORK is not
another library but an alias for an existing library to which all compiled designs
are written. The mechanism by which WORK is pointed at an existing library
is again tool vendor dependent, Cadence uses the file hdl.var to contain this
among other things. Here is the hdl.var file for the laboratory exercise:
INCLUDE /eng/goss/apps6/cds/ldv5.0/tools/inca/files/hdl.var
DEFINE WORK worklib
DEFINE NCVHDLOPTS -v93 -linedebug
1. The first line include a Cadence supplied hdl.var file that contains stan-
dard information needed by all simulations.
2. The second line indicates that WORK should be aliased to the library worklib.
3. The last line says to assume -v93 -linedebug by default when compiling
VHDL code.
The first line includes a Cadence supplied hdl.var that contains standard in-
formation needed by all simulations. The second line is the important one as
regards WORK, this indicates that the current WORK library is the VHDL library
called worklib. Finally, the last line says to assume -v93 -linedebug by de-
fault when compiling VHDL code.
In this section well briefly look at how to create your own library and then
to use that library in another design. Let us assume that we wish to create a
library called usb 2, and then later use components from that library within
designs stored in a library called soc.
1. Create a directory to contain the usb 2 code, create a cds.lib file defining
usb 2 as residing in the directory just created.
2. In the hdl.var file set WORK to point to usb 2.
3. Compile the code for the usb 2 design(s).
4. Create a second directory for the library called soc, and add a line to the
cds.lib file defining that library.
5. Edit the hdl.var file and now point WORK to the soc library.
6. Compile code for the soc design, using where required statements such as
library usb 2;.
2 Packages
package <package_name> is
<list of declarations>
where:
Here is an example package declaration that includes two constants and one
function:
package pckg_demo is
This package defines two constants for use throughout the design. The intention
here is that if the need arises to change either of these values then the change
need only be made once in the package source code. All code dependent on
the package is then recompiled and if the coding has made correct use of these
constants, all units will then consistently use the new value. Note that automatic
methods are available to recompile code dependent on these changes (Cadences
ncupdate for example).
The function declaration declares the function called ceillog2 that takes a
single natural number as its argument and then returns a single natural number
as its result. The constant in front of the argument indicates that the function
does not modify the argument n. This particular function returns the value of
dlog2 (n)e.
A package body for the above package need only contain the implementation of
the function ceillog2. Note that where this function is used in other design,
the implementation of the function is not needed by either the compiler or the
designer to use the function. The implementation is only needed when the
design is elaborated. Here is the formal syntax of a package body:
<list of declarations>
The package body for the above example with ceillog2 is:
library ieee;
use ieee.std_logic_1164.all;
The first line here states that the name ieee is a VHDL library. The second line,
the use clause, states that all objects within the package called std logic 1164
are to be made visible to the design unit that follows.
Note that it is to only the following design unit that the clause applies, not to
all design units in the file. A design unit consists of for example an entity header
and an architecture body. Thus if more than one design unit is in the same file,
then each must be preceded by the above.
If the package pckg demo above has been compiled into the library pointed to
by WORK then to use the package above we need only say:
where mylib is the name of the library whose contents are all to be made visible.
Note that use clauses can also be included within the declarations section of an
architecture body.
3 Configurations
<configuration_declarations>
<block_configuration>
This text is often preceded by library clauses and use clauses. In the above
<configuration name> is the name given by the designer to this configuration.
<entity name> is the name of the design entity to which the configuration
applies - this will usually be a testbench.
end example1_tb_cfg_rtl;
Note the use of the name example1 tb cfg rtl, it is intended to make the
relationship to the testbench example1 tb very clear. Use of such naming con-
ventions is all but essential for large designs. The <entity name> in this case
is example1 tb. The single block configuration is the text:
for tb
..
end for;
and indicates that this block (and since it is the outermost block, the entire con-
figuration) applies to the architecture called tb of the design unit example1 tb.
If you examine the source code of the example1 tb testbench you will find that
the testbench architecture is called tb, the relevant line of code is:
architecture tb of example1 tb is
Within the block configuration we then have optionally a use clause, followed
by one or more <configuration items>. A configuration item is very similar
to a block configuration item, it can in fact be a block configuration, but can
also be a component configuration.
and in this case states that for the example1 component with instantiation label
dut, the architecture rtl of the design example1 in the library work should be
used.
Here is a second example, this time for the netlist simulation of example1:
library tsmc018;
for tb
for dut : example1
use entity work.example1(netlist);
for netlist
use tsmc018.all;
end for;
end for;
end for;
end example1_tb_cfg_net;