VHDL:实例化的组件通用数组索引超出范围

VHDL:实例化的组件通用数组索引超出范围,vhdl,fpga,vivado,Vhdl,Fpga,Vivado,我正在尝试用VHDL实现一个加密算法,我创建了一个带有通用参数的反馈移位寄存器组件,以提高可重用性。这是我第一次使用泛型和数组,请耐心听我说 此组件将反馈位作为输入,并将其一些位(抽头)连接到输出端口,但可以使用通用参数更改此连接。FSR组件的代码: library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; use work.fsr_taps_type.all; entity FSR is

我正在尝试用VHDL实现一个加密算法,我创建了一个带有通用参数的反馈移位寄存器组件,以提高可重用性。这是我第一次使用泛型和数组,请耐心听我说

此组件将反馈位作为输入,并将其一些位(抽头)连接到输出端口,但可以使用通用参数更改此连接。FSR组件的代码:

library ieee;
  use ieee.std_logic_1164.all;
  use ieee.numeric_std.all;
  use work.fsr_taps_type.all;
  entity FSR is

    generic (
    r_WIDTH  : integer; -- Register width
    r_STEP   : integer;  -- Update step
    r_FWIDTH  : integer; -- Feedback output width
    r_HWIDTH  : integer; -- h-function output width
    r_TAPS    : TAPS;           -- Change the size according to the number of taps
    r_STATE   : TAPS
    );

    port (
    clk      : in std_logic;
    rst      : in std_logic;
    fb_in    : in std_logic_vector ((r_STEP-1) downto 0);
    init     : in std_logic;
    ini_data : in std_logic_vector ((r_WIDTH-1) downto 0);
    out_data : out std_logic_vector ((r_STEP-1) downto 0);
    fb_out   : out std_logic_vector ((r_FWIDTH-1) downto 0);
    h_out    : out std_logic_vector ((r_HWIDTH-1) downto 0)
    );
  end entity;

architecture behavioural of FSR is
signal shifted,shifted_next  : std_logic_vector((r_WIDTH-1) downto 0);
begin
process(clk,rst)
begin
if rst = '1' then
  shifted <= (others => '0');
elsif clk'event and clk = '1' then
  shifted <= shifted_next;
end if;
end process;

process (fb_in,init,ini_data,shifted)
begin
  if init = '1' then
    shifted_next <= ini_data;
  else
    shifted_next <= shifted((r_WIDTH-r_STEP-1) downto 0) & fb_in;
  end if;
end process;
out_data <= shifted ((r_WIDTH-1) downto (r_WIDTH-r_STEP));

-- The bits defined in the r_TAPS and r_STATE arrays are connected to the outputs in the same order as they are written (left to right)
-- Example: r_TAPS := (10,6) will create fb_out (1 downto 0) = bit10 & bit 6, in that order
-- Connect taps in the order of r_TAPS
    gen_feedback: for I in (r_FWIDTH-1) downto 0 generate
      fb_out(I) <= shifted(r_STATE(r_FWIDTH-I-1));
    end generate gen_feedback;

-- Connect output bits for h function
    gen_h: for I in (r_HWIDTH-1) downto 0 generate
      h_out(I) <= shifted(r_STATE(r_HWIDTH-I-1));
    end generate gen_h;

end architecture;
当我只创建第一个实例时,精化工作正如预期的那样,Vivado没有给出任何错误。但是,当我添加第二个实例时,会出现超出范围的错误:

ERROR: [Synth 8-97] array index 0 out of range (FSR.vhdl:54)
第54行是第一个for generate循环内的行:

fb_out(I) <= shifted(r_STATE(r_FWIDTH-I-1));
这似乎有效,我只需添加一个others语句来填充未使用的数组号,因此:

r_TAPS  (0 to 5) => (128,121,90,58,47,32)
变成这样:

r_TAPS  (0 to 5) => (128,121,90,58,47,32,others =>0)

正如我之前所说,我对VHDL中的数组不熟悉,所以我想知道是否有一种方法可以使用无约束数组类型对任意长的数组执行此操作。

这不是MCVE。我们应该如何识别第54行?另外,您认为每个数组聚合的索引范围是什么?提示:最小整数不是零。。。另外,我建议使用合适的ranged子类型Natural,而不是Integer。但我猜这是这一行:
fb_out(I)我猜是没有显式范围约束的数组聚合-它将从-2**31开始,因此0肯定超出范围。感谢您的回答,我还在学习,这是我第一次在VHDL中使用数组。在实例化组件时,我是否没有约束数组?如
r\u轻敲(0到28)
?在类型声明中约束数组大小是否更好,因为值永远不会高于某个数字?如果需要更大的阵列,我可以更改最大大小,但我觉得应该有更好的解决方案。。。我会尽快上传完整的代码Brian和Staszek很接近。对于
fb_out(I)(33116)
,29超出了r_状态的索引范围。提供一个,在模拟器中,这将是一个边界运行时错误。有个提示,先模拟一下。您的泛型常量在此处不兼容。按照Brian的建议,为未绑定数组定义使用自然范围。你应该在合成前进行模拟。
r_TAPS  (0 to 5) => (128,121,90,58,47,32)
r_TAPS  (0 to 5) => (128,121,90,58,47,32,others =>0)