当单个实体上有多个架构时会发生什么?

Era*_*ran 3 compilation vhdl modelsim quartus

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

下面是一个例子:

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;
Run Code Online (Sandbox Code Playgroud)

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

谢谢你。

Jim*_*ams 5

如果您没有指定自己选择哪种架构²,那么编译器将采用“与实体声明关联的最近分析的架构主体”(假设编译器符合 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;
Run Code Online (Sandbox Code Playgroud)

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


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