全局包合并多个包vhdl

时间:2016-11-28 11:42:29

标签: vhdl packages

我有一个vhdl中描述的系统,它应该以不同的配置运行。为此,我把最后一个放在不同的包文件中。我有一个全局包,我取消注释我想要合成的配置。我每次都使用这个全局包来声明我的实体。

但问题是,事实上在合成时,配置包中声明的类型和常量是不可见的。

我试图在全局包的声明之上的全局包文件中声明“use my_package.all”,我也尝试在全局包中。

我的意思是我试过了:

use work.config1.all;
package global_package is
   ...
end global_package;

我试过了:

package global_package is
   use work.config1.all;
   ...
end global_package;

实际上是由合成器接受的。

有人有解决方案吗?我真的不想在我的所有文件中评论和取消注释我想要的配置。

谢谢!

编辑:

例如,如果我有:

文件1:

package config1 is
    constant my_variable : integer := 1;
end config1;

文件2:

package config2 is
    constant my_variable : integer := 2;
end config2;

文件3:

use work.config1.all
-- use work.config2.all

package global is
    constant another_variable : integer := 5;
end global;

文件4:

use work.global.all

entity my_entity is
    port(clk : in std_logic);
end my_entity ;

architecture Behavioral of my_entity is
     signal sig1, sig2 : integer;
begin
     sig1 <= another_variable;  -- I can see and use here the constant "another_variable".
     sig2 <= my_variable; -- Error ! I would like to have access here to the constant "my_variable" that the synthesizer can't see. 
end Behavioral;

拥有这4个文件后,我无法通过“global”包访问“my_variable”。此外,我希望这个常量具有包config1或config2中给出的值,而不是未注释的值。

2 个答案:

答案 0 :(得分:1)

您是否尝试过上下文子句声明及其引用?这是我参考的一个:

context OsvvmContext is
    library OSVVM ;  
    use OSVVM.AlertLogPkg.all ; 
    use OSVVM.RandomPkg.all ;
    use OSVVM.CoveragePkg.all ;
    use OSVVM.MemoryPkg.all ;
    . . . 
end context OsvvmContext ; 

然后在你的设计中,你引用它:

library osvvm ;
  context osvvm.OsvvmContext ; 

这样,您可以编辑上下文子句并更改为整个项目包含的包​​集。它是VHDL-2008,所以对于合成YMMV,但是对于模拟,它得到很好的支持。

答案 1 :(得分:0)

我不知道通过使用另一个包可以在一个包中看到某种东西的简单方法。 (这在使用export的system-verilog中是可行的,但这对你没有帮助。)

相反,您可以通过各种其他方式解决问题。我不确切地知道你的问题是什么,但这里有一个建议:

package global is
  constant another_variable : integer := 5;
  function set_my_variable (i : integer) return integer;
  constant my_variable : integer := set_my_variable(another_variable);
end global;

package body global is
  function set_my_variable (i : integer) return integer is
  begin
    if i = 5 then
      return 1;
    else
      return 2;
    end if;
  end function;
end package body global;

library IEEE;
use IEEE.std_logic_1164.all;
use work.global.all;

entity my_entity is
    port(clk : in std_logic);
end my_entity ;

architecture Behavioral of my_entity is
     signal sig1, sig2 : integer;
begin
     sig1 <= another_variable;  -- I can see and use here the constant "another_variable".
     sig2 <= my_variable; -- Error ! I would like to have access here to the constant "my_variable" that the synthesizer can't see. 
end Behavioral;

https://www.edaplayground.com/x/5xNd

这里我使用一个函数初始化一个常量,该函数的输入是另一个常量。然后通过简单地编辑该常量,我可以改变许多其他常量的值。您可以编写各种函数来初始化您希望初始化的各种常量。

有趣的是,这样的功能在精心制作过程中执行。这可能会使调试变得棘手。如果你需要调试它,你可以调用函数来初始化一个信号或变量,这样函数就可以在0之后而不是之前执行。

相关问题