全局包合并几个包vhdl

Global Package to merge several packages vhdl

我有一个在 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 中给出的值,作为未注释的那个的函数。

我不知道有什么简单的方法可以通过使用另一个包来使一个包中的内容可见。 (这在使用 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 之后而不是之前执行。

您是否尝试过上下文子句声明和对它的引用?这是我有一个供参考:

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,但是对于仿真,它是很好支持的。