2

我想为 component 编写一个库C,该组件在内部分为两个 supcomponentsc1c2,它们可以由泛型配置。子模块应通过记录连接,这取决于泛型。该记录也应在组件内使用。通常我会在 a 中实例化记录package,并在子组件的文件和组件的文件中使用包。由于它是通用的,我认为使用通用包(VHDL-2008)可能会提供解决方案。

问题是我还需要从子组件中访问记录。为此,我需要use thePackage,但是要使用通用包,我需要传递初始值(据我所知)。

所以我尝试了(注意:我在这里没有处理记录,我只是想从通用组件访问通用包,我在其中参数化(?)带有组件参数的包):

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;

但是我从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

更新: 我尝试将其包装genericPackagePart在一个泛型包中,并使用泛型从该包中实例化 genericPackage,这也不起作用。

流程应该是:

  • Testbench => 实例化genericPackagePartgenericPackage使用通用参数
  • 该记录可在测试台中从genericPackage
  • 内部genericPackagePart genericPackage使用传递给的参数实例化genericPackagePart
  • 记录在里面genericPackagePart

Modelsim 给出了 Errors (test是我给 in 的参数化实例起的名字genericPackagegenericPackagePart这是来自 的编译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

我查看了Passing Generics to Record Port Types但这并没有解决基于泛型的包实例化问题


为了完整起见,这里是包和测试台:

包裹:

package genericPackage is
    generic(genSize : integer := 1);

    constant dummy : integer := genSize;
end package;

试验台:

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;
4

1 回答 1

2

我认为问题在于您的包test需要在实体区域而不是架构区域中定义:

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;

这是我测试它的方式(基于您的测试平台):

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;

使用 Modelsim 10.2 编译和仿真:

vcom -2008 genpacktest.vhd; vsim -c genericPackageTestbench -do "run -all; quit"

其中报告:

# 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 
于 2013-04-18T08:50:19.943 回答