2016-07-25 6 views
2

私はVHDLで大きなプロジェクトを開始しています。できるだけ多くの順序で記述されるように、すべての基本コンポーネント(加算器、マルチプレクサ、レジスタなど) 。再帰的自己インスタンス化コンポーネント[VHDL]

各エンティティごとに異なるアーキテクチャを使用して(抽象化の異なるレイヤーまたは異なる種類の実装を実行する)、構成を使用して1つを選択することを考えています。

私の質問です:コンポーネントを再帰的にインスタンス化することは可能ですか?それは内部で使用される加算器を構成することが可能である

-- Behavioral Add 
architecture BHV of ADDER is 
    out <= A + B; 
end architecture BHV; 


-- Ripple Carry Adder 
architecture RCA of ADDER is 
    ... 
end architecture RCA; 


-- Carry Select Adder 
architecture CSA of ADDER is 
    component ADDER -- <== this should be configured as RCA 
    ... 
end architecture CSA; 

entity ADDER is 
    generic(...); 
    port(...); 
end entity ADDER; 

は、それから私は、たとえば、アーキテクチャの異なる種類を持っていると思います。たとえば

、の加算器を見てみましょうキャリー無限のインスタンス化ループで終わらずにリップルキャリーを選択しますか?

+0

しばしばちょうどそれを試している、このような質問への答え。私は行くまで私は答えを知らなかった。 –

答えて

1

はい、無限インスタンス化ループで終了することなく、リップルキャリーを使用してキャリーセレクト内で使用する加算器を構成することは可能です。再帰的なインスタンス化では、終了条件が必要です。再帰を終了するものです。設定はその役割を実行しています。

library IEEE; 
use IEEE.std_logic_1164.all; 
use IEEE.numeric_std.all; 

entity ADDER is 
    generic(WIDTH : positive := 8); 
    port(CIN : in std_logic; 
     A : in std_logic_vector(WIDTH-1 downto 0); 
     B : in std_logic_vector(WIDTH-1 downto 0); 
     F : out std_logic_vector(WIDTH-1 downto 0); 
     COUT : out std_logic); 
end entity ADDER; 

-- Ripple Carry Adder 
architecture RCA of ADDER is 
    signal CIN0 : unsigned(0 downto 0); 
    signal FIN : unsigned(WIDTH downto 0); 
begin 
    CIN0(0) <= CIN; 
    FIN <= resize(unsigned(A), WIDTH+1) + resize(unsigned(B), WIDTH+1) + CIN0; -- yes, I know it's not a ripple carry adder 
    F <= std_logic_vector(FIN(WIDTH-1 downto 0)); 
    COUT <= FIN(WIDTH); 
end architecture RCA; 

-- Carry Select Adder 
architecture CSA of ADDER is 
    component ADDER is 
    generic(WIDTH : positive); 
    port(CIN : in std_logic; 
      A : in std_logic_vector(WIDTH-1 downto 0); 
      B : in std_logic_vector(WIDTH-1 downto 0); 
      F : out std_logic_vector(WIDTH-1 downto 0); 
      COUT : out std_logic); 
    end component ADDER; 
    signal F0, F1  : std_logic_vector(WIDTH-1 downto 0); 
    signal COUT0, COUT1 : std_logic; 
begin 
    ADD0: ADDER generic map(WIDTH => WIDTH) 
    port map ( 
      CIN => '0' , 
      A => A , 
      B => B , 
      F => F0 , 
      COUT => COUT0); 
    ADD1: ADDER generic map(WIDTH => WIDTH) 
    port map ( 
      CIN => '1' , 
      A => A , 
      B => B , 
      F => F1 , 
      COUT => COUT1); 
    COUT <= COUT1 when CIN = '1' else COUT0; 
    F <= F1 when CIN = '1' else F0; 
end architecture CSA; 

-- here's the configuration 
configuration CSAC of ADDER is 
    for CSA 
    for all: ADDER 
     use entity work.ADDER(RCA); 
    end for; 
    end for; 
end configuration CSAC; 

http://www.edaplayground.com/x/2Yu3

関連する問題