2017-11-22 64 views
0

VHDLに畳み込み用のリングバッファを実装して汎用化したいと思います。私の問題は、信号や変数を追加することなく内部データを初期化する方法です。VHDLはstd_logic_vectorの汎用配列を初期化します

通常私は

signal initialized_vector : std_logic_vector(15 downto 0) := (others => '0'); 

でSTD_LOGIC_VECTORをintializeすることができますしかし、私はどのようにデフォルトでアレイ上にそれを行うには見当もつかない。

は、ここに私のコードです:

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; 

答えて

0

あなたはSTD_LOGIC_VECTORとほぼ同じことを行うことができます。あなたはちょうどあなたが1以上の次元を持っていることを考慮しなければならない:

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; 
+0

おかげで多くのことを、魔法のように動作します – ThomasM