2016-03-06 37 views
2

我想避免在以下代碼中使用inout。避免在VHDL中使用inout

有什麼辦法可以做到嗎?例如幫助信號?

entity LA_Unit is 
    Port (Cin : in STD_LOGIC; 
      P : in STD_LOGIC_VECTOR (3 downto 0); 
      G : in STD_LOGIC_VECTOR (3 downto 0); 
      C3 : out STD_LOGIC; 
      C : inout STD_LOGIC_VECTOR (2 downto 0)); 
end LA_Unit; 

architecture Behavioral of LA_Unit is 
begin 
    C(0) <= (P(0) and Cin) xor G(0); 
    C(1) <= (P(1) and C(0)) xor G(1); 
    C(2) <= (P(2) and C(1)) xor G(2); 
    C3 <= (P(3) and C(2)) xor G(3); 
end Behavioral; 
+0

請註明其中一個答案是「解決方案」,如果一個解決您的問題。 – Paebbels

回答

4

使用信號作爲C(0)和C(1)的中間值。

輸入只能用於硬件io端口,如gpio端口或內存總線上的數據端口。

7

如果目的僅僅是提供C的中間值作爲模塊的輸出,則有不同的選項可以避免inout

如果這些工具支持VHDL-2008,則可以簡單地將inout更改爲out,然後仍然可以在內部讀取C

如果工具只支持VHDL-2002,那麼你仍然可以改變inoutout,但你需要一個內部信號,如:

architecture Behavioral of LA_Unit is 
    signal C_int : std_logic_vector(2 downto 0); 
begin 
    C_int(0) <= (P(0) and Cin) xor G(0); 
    C_int(1) <= (P(1) and C_int(0)) xor G(1); 
    C_int(2) <= (P(2) and C_int(1)) xor G(2); 
    C3  <= (P(3) and C_int(2)) xor G(3); 
    C  <= C_int; 
end Behavioral; 

由於xvan也寫,只使用inout的頂層端口芯片上,或特殊的測試臺使用,因爲inout芯片內部不支持。

4

有2個解決方案:

  1. 使用緩衝模式,而不是INOUT。

    entity LA_Unit is 
        Port (Cin : in STD_LOGIC; 
          P : in STD_LOGIC_VECTOR (3 downto 0); 
          G : in STD_LOGIC_VECTOR (3 downto 0); 
          C3 : out STD_LOGIC; 
          C : buffer STD_LOGIC_VECTOR (2 downto 0)); 
    end LA_Unit; 
    
    architecture Behavioral of LA_Unit is 
    begin 
        C(0) <= (P(0) and Cin) xor G(0); 
        C(1) <= (P(1) and C(0)) xor G(1); 
        C(2) <= (P(2) and C(1)) xor G(2); 
        C3 <= (P(3) and C(2)) xor G(3); 
    end Behavioral; 
    

    有些工具在這種模式下有問題。

  2. 中間信號:

    entity LA_Unit is 
        Port (Cin : in STD_LOGIC; 
          P : in STD_LOGIC_VECTOR (3 downto 0); 
          G : in STD_LOGIC_VECTOR (3 downto 0); 
          C3 : out STD_LOGIC; 
          C : out STD_LOGIC_VECTOR (2 downto 0) 
    ); 
    end entity; 
    
    architecture rtl of LA_Unit is 
        signal C_i : STD_LOGIC_VECTOR(3 downto 0); 
    begin 
        C_i(0) <= (P(0) and Cin) xor G(0); 
        C_i(1) <= (P(1) and C_i(0)) xor G(1); 
        C_i(2) <= (P(2) and C_i(1)) xor G(2); 
        C_i(3) <= (P(3) and C_i(2)) xor G(3); 
        C <= C_i(2 downto 0); 
        C3 <= C_i(3); 
    end architecture 
    
+0

在第二個例子中,端口'C'應該有'out'模式。 –

+0

@MartinZabel修復它:)。 – Paebbels