2016-03-06 63 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