【问题标题】:Avoid using inout in VHDL避免在 VHDL 中使用 inout
【发布时间】:2016-03-06 19:46:03
【问题描述】:

我想避免在下面的代码中使用 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;

【问题讨论】:

  • 如果一个答案解决了您的问题,请将其中一个答案标记为“解决方案”。

标签: vhdl inout


【解决方案1】:

如果目的只是提供C 的中间值作为模块的输出,则有不同的选项可以避免inout

如果工具支持VHDL-2008,您只需将inout更改为out,然后仍然可以在内部读取C

如果工具只支持 VHDL-2002,那么您仍然可以将 inout 更改为 out,但您需要一个内部信号,例如:

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

【讨论】:

    【解决方案2】:

    使用信号作为 C(0) 和 C(1) 的中间体。

    Inouts 只能用于硬件 io 端口,例如 gpio 端口,或内存总线上的数据端口。

    【讨论】:

      【解决方案3】:

      有两种解决方案:

      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
        

      【讨论】:

      • 第二个例子中端口C的模式应该是out
      • @MartinZabel 修复了它:)。
      猜你喜欢
      • 2015-06-22
      • 1970-01-01
      • 1970-01-01
      • 2016-12-02
      • 2021-06-07
      • 2011-09-03
      • 2013-03-05
      • 2012-12-07
      • 1970-01-01
      相关资源
      最近更新 更多