VHDL初始化std_logic_vector类型的通用数组

5
我希望能在 VHDL 中实现一个环形缓存器用于卷积操作,并且使其具有通用性。我的问题是,如何在不引入其他信号或变量的情况下初始化内部数据。
通常,我可以通过以下方式初始化 std_logic_vector:
signal initialized_vector : std_logic_vector(15 downto 0) := (others => '0');

但是我不知道如何默认地将其应用到数组上。

这是我的代码:

entity convolution_ringbuffer is
    generic (
        BitDepth_signal : integer := 24;
        BufferSize : integer := 10
        );
    port (
        data_in : in std_logic_vector(BitDepth_signal-1 downto 0);
        sclk : in std_logic;
        enable : in std_logic;
        data_out : out std_logic_vector(BitDepth_signal-1 downto 0)
        );
end convolution_ringbuffer;

architecture behavioral of convolution_ringbuffer is

    type internal_data is array(0 to BufferSize-1) of std_logic_vector(BitDepth_signal-1 downto 0);
    signal data_internal : internal_data;

begin

    process ( sclk ) 

        variable current_position : integer range 0 to (BufferSize-1) := 0;

    begin

        if ( rising_edge(sclk) and enable = '1' ) then

            data_internal(current_position) <= std_logic_vector(data_in);

            if ( current_position < BufferSize-1 ) then
                current_position := current_position + 1;    
            else
                current_position := 0;
            end if;

        end if;

        if ( falling_edge(sclk) ) then
            data_out <= std_logic_vector(data_internal(current_position));
        end if;

    end process;

end behavioral;
1个回答

6

你可以像处理std_logic_vector一样处理它们。你只需要考虑有一个额外的维度:

signal data_internal : internal_data := (others=>(others=>'0'));

如果您有更复杂的初始化数据需要存储,您可以使用初始化函数:
function init return internal_data is
begin
    --do something (e.g. read data from a file, perform some initialization calculation, ...)
end function init;

signal data_internal : internal_data := init;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接