在其他泛型中使用 VHDL 泛型值

use*_*098 4 vhdl

我希望能够将多个通道指定为泛型,并使用它来指定包含更多参数的数组的范围。编译时,我的 Aldec 编译告诉我在接口列表完成之前不能引用 'num_chan'。

有谁知道实现这一目标的方法?

ENTITY deframer IS
    generic (
      num_chan : integer                      := 2;            
      ch_low   : int_arr(num_chan-1 downto 0) := (  1, 189);   
      ch_hi    : int_arr(num_chan-1 downto 0) := (127, 189));
Run Code Online (Sandbox Code Playgroud)

Mor*_*mer 5

在 VHDL-2002(及更早版本)中,在给定泛型列表中声明的正式泛型不能用于在该列表中声明其他泛型,这就是您看到的错误的原因。

在 VHDL-2008 中这是可能的,因此如果所需的工具支持 VHDL-2008 和该功能(“在通用列表中引用泛型”),那么您可以向工具指示使用了 VHDL-2008。

VHDL-2002 的解决方案是使ch_lowch_hi数组足够大以容纳 的任何值num_chan,然后用虚拟值填充未使用的值,例如(假设num_chan最多为 10,使用 -1 作为虚拟值):

generic(
  num_chan : integer            := 2;
  ch_low   : int_arr_t(1 to 10) := (  1, 189, others => -1);
  ch_hi    : int_arr_t(1 to 10) := (127, 189, others => -1));
Run Code Online (Sandbox Code Playgroud)