通用记录(通过vhdl 2008通用包尝试)

时间:2013-04-17 09:23:35

标签: vhdl

我想为组件C编写一个库,该组件内部拆分为两个组件c1c2,这些组件可由泛型配置。子模块应该通过记录连接,这取决于泛型。记录也应该在组件中使用。通常我会在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 =&gt;使用通用参数
  • 实例化genericPackagePartgenericPackage
  • 该记录可在genericPackage
  • 的测试平台中找到
  • 内部genericPackagePart genericPackage使用传递给genericPackagePart
  • 的参数进行实例化
  • 该记录在genericPackagePart
  • 中可用

Modelsim给出了错误(test是我给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,但这并没有解决基于泛型的包实例化问题


对于completness,这里是包和一个测试平台:

封装

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;

1 个答案:

答案 0 :(得分: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