问题
I want to write a library for component C
, the component is split internally into two supcomponents c1
and c2
, which are configurable by generics. The submodules should be connected by a record, that depends on the generics. The record should also be used within the components. Usually I would instantiate the record in a package
, and use the package in the files for the subcomponents and in the file for the component. Since it is generic I figured using a generic Package (VHDL-2008) might offer a solution.
The Problem is I need to access the record also from within the subcomponents. To do so I need to use thePackage
, however to use a generic package I need to pass initial values (as far as I know).
So I tried (note: Iam not working with records here, I am just trying to get access to a generic package from a generic component, where I parameterize(?) the package with the parameters of the component):
entity genericPackagePart is
generic(
outputValue : integer
);
port(
result: out integer
);
end entity;
architecture behav of genericPackagePart is
package test is new work.genericPackage
generic map(
genSize => outputValue
);
use work.test.all;
begin
result <= dummy; -- dummy is a constant from genericPackage set to the value genSize (generic parameter)
end architecture;
However I get the following errors from modelsim:
** Error: (vcom-11) Could not find work.test.
** Error: genericPackagePart.vhd(17): (vcom-1195) Cannot find expanded name "work.test".
** Error: genericPackagePart.vhd(17): Unknown expanded name.
** Error: genericPackagePart.vhd(19): (vcom-1136) Unknown identifier "dummy".
** Error: genericPackagePart.vhd(20): VHDL Compiler exiting
Update:
I tried wrapping the genericPackagePart
in a generic package and to instantiate the genericPackage
from within that package with the generics, this did not work either.
The flow would have been:
- Testbench => Instantiate
genericPackagePart
andgenericPackage
with generic parameters - The record is available in the testbench from
genericPackage
- Inside
genericPackagePart
genericPackage
is instantiated with the parameters passed togenericPackagePart
- the record is available inside
genericPackagePart
Modelsim gave Errors (test
is the name I gave to the parameterizes instance of genericPackage
in genericPackagePart
, this is from the compile of genericPackagePart
):
** Error: (vcom-11) Could not find work.test.
** Error: genericPackagePart.vhd(11): (vcom-1195) Cannot find expanded name "work.test".
** Error: genericPackagePart.vhd(11): Unknown expanded name.
** Error: genericPackagePart.vhd(13): near "entity": expecting END
I looked at Passing Generics to Record Port Types but that does not solve the issue of the package instantiation based on generics
For completness here is the package and a testbench:
Package:
package genericPackage is
generic(genSize : integer := 1);
constant dummy : integer := genSize;
end package;
Testbench:
package myGenericPackage is new work.genericPackage
generic map(
genSize => 5
);
use work.myGenericPackage.all;
entity genericPackageTestbench is
end entity;
architecture testbench of genericPackageTestbench is
signal testsignal : integer;
signal testsignal2 : integer;
signal dummy : integer := 12;
component genericPackagePart is
generic(
outputValue : integer
);
port(
result: out integer
);
end component;
begin
test : process is
begin
wait for 20 ns;
testsignal <= dummy;
wait for 20 ns;
testsignal <= work.myGenericPackage.dummy;
wait;
end process;
testPart: genericPackagePart
port map(result => testsignal2)
generic map(outputValue => 128);
end architecture;
回答1:
I think the problem was that your package test
needs to be defined in the entity area, not the architecture area:
package genericPackage is
generic(genSize : integer := 1);
constant dummy : integer := genSize;
end package;
entity genericPackagePart is
generic(outputValue : integer);
port(result : out integer);
-- *** Generic package instantiated here ***
package test is new work.genericPackage
generic map(genSize => outputValue);
end entity;
architecture behav of genericPackagePart is
use test.all;
begin
result <= dummy; -- dummy is from genericPackage (=genSize)
end architecture;
Here's how I tested it (based on your testbench):
package myGenericPackage is new work.genericPackage
generic map(genSize => 5);
use work.myGenericPackage.all;
entity genericPackageTestbench is
end entity;
architecture testbench of genericPackageTestbench is
signal testsignal : integer;
signal testsignal2 : integer;
begin
test : process is
begin
testsignal <= work.myGenericPackage.dummy;
wait for 20 ns;
assert testsignal = work.myGenericPackage.dummy
report "test signal should be work.myGenericPackage.dummy"
severity error;
assert testsignal2 = 128 report "testsignal2 /= 128" severity error;
report "testsignal = " & integer'image(testsignal);
report "testsignal2 = " & integer'image(testsignal2);
report "Finished";
wait;
end process;
testPart : entity work.genericPackagePart
generic map(outputValue => 128)
port map(result => testsignal2);
end architecture;
Compiled and simulated with Modelsim 10.2:
vcom -2008 genpacktest.vhd; vsim -c genericPackageTestbench -do "run -all; quit"
Which reports:
# Loading std.standard
# Loading work.genericpackage
# Loading work.mygenericpackage
# Loading work.genericpackagetestbench(testbench)
# Loading work.genericpackagepart(behav)
# run -all
# ** Note: Finished
# Time: 20 ns Iteration: 0 Instance: /genericpackagetestbench
# ** Note: testsignal = 5
# Time: 20 ns Iteration: 0 Instance: /genericpackagetestbench
# ** Note: testsignal2 = 128
# Time: 20 ns Iteration: 0 Instance: /genericpackagetestbench
# quit
来源:https://stackoverflow.com/questions/16056291/generic-records-attempted-via-vhdl-2008-generic-package