【问题标题】:What happens when there are multiple architectures on a single entity?当单个实体上有多个架构时会发生什么?
【发布时间】:2015-06-19 07:06:28
【问题描述】:

假设一个实体定义了两种架构。这两种架构使用相同的实体(显然),随后两者将输出引脚设置为不同的值。我的问题是,程序(模拟器)如何确定输出应该是什么(即选择哪种架构)?

这是一个例子:

library ieee;
use ieee.std_logic_1164.all;

entity Exercise_4 is 
generic (n : integer := 4);
port(
a, b : std_logic_vector (n-1 downto 0);
clk, rst : std_logic;
q, qn : buffer std_logic_vector (n-1 downto 0));
end;

architecture one of Exercise_4  is
begin
process (clk, rst)
    begin
    if rst = '0' then 
        q <= (others=>'0');
    elsif (clk' event and clk = '0') then
        q <= a ;
    end if;
end process;

process (clk, rst)
begin
    if rst = '0' then 
        qn <= (others=>'1');
    elsif (clk' event and clk = '0') then
        for i in a'range loop
            qn(i) <= not q(i) ;
        end loop;
    end if;
end process;
end;

architecture two of Exercise_4  is
begin
process (clk,rst)
    begin
    if rst = '0' then 
        q <= (others=>'0'); 
        qn <= (others=>'0');
    elsif (clk' event and clk = '0') then
        q <= a;
        qn <= b ;
    end if;
end process;
end;

我做了一个模拟,发现 q 得到了 a 的赋值,qn 获取分配的 b 的值。似乎编译器选择了第二种架构我不明白为什么程序决定这样做。

谢谢。

【问题讨论】:

  • 这取决于你的编译器。有些只是采用第一个拱门,有些正在使用专用的configuration 构造。
  • 很奇怪。如您所见,我什至没有使用配置结构。并且编译器“混合”了这两种架构——它从第一个架构中获取了q,从第二个架构中获取了qn。这可能吗?
  • Eugene 的评论对于兼容的 VHDL 实现来说是不准确的。在没有绑定指示的情况下,默认绑定指示将使用“与实体声明关联的最近分析的体系结构主体”——第二个出现在设计文件或最后分析的体系结构中。请参阅 IEEE Std 1076-2008 7.3.3 默认绑定指示,第 4 段。(您可能需要阅读 7.3 的大部分内容)。并且不可能从一种架构中获取q 并从另一种架构中获取qn,这也表明您没有充分证明您的问题。
  • 在这两种架构中,q 被分配给a。我不明白为什么q 在这两种架构中会有任何不同。 qn 会。
  • 是的,你都是对的 @JonathanDrolet @DavidKoontz ,q 也从第二个架构获得 a。我很困惑,因为两种架构中的同一行,我没有注意到(也是深夜)。无论如何,谢谢大家。

标签: compilation vhdl modelsim quartus


【解决方案1】:

如果您不指定自己选择哪种架构²,那么编译器将采用“与实体声明关联的最新分析的架构主体”(假设编译器符合 IEEE 标准)[1]。

² 您可以选择您喜欢的架构,例如在更高设计级别的组件声明部分(映射信号的地方):

entity topentity is 
end;

architecture toparch of topentity is

  -- component instantiation
  component Exercise_4 is
  generic (n : integer := 4);
  port(
    a, b : std_logic_vector (n-1 downto 0);
    clk, rst : std_logic;
    q, qn : buffer std_logic_vector (n-1 downto 0));
  end component Exercise_4;

begin

  -- component mapping
  E4: entity work.Exercise_4(one)
  generic map ( .. )
  port( .. );

end architecture toparch;

[1] IEEE Std 1076-2008 7.3.3 默认绑定指示,第 4 段。


免责声明:答案是在上述 cmets 的帮助下构建的。无侵犯版权之意。 ;P

【讨论】:

    【解决方案2】:

    在没有配置绑定的情况下,默认情况下编译器会考虑代码文件中的最后一个架构体。

    【讨论】:

      猜你喜欢
      • 2020-06-13
      • 2011-02-23
      • 1970-01-01
      • 1970-01-01
      • 2017-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多