在vhdl中处理对同一个信号的多个写操作

Handle mutliple write operations to the same signal in vhdl

我有 n 个组件计算某个哈希值,但我不知道它们何时会完成。完成后,他们应该将找到的散列发送到主组件,其中哪个散列先到达主组件并不重要,只要他收到一个即可。

在 2 个或更多组件同时完成哈希计算而不需要 n 个信号(每个哈希一个)进入主机的情况下,是否有一种方法可以避免竞争条件?

我尝试实现位于主组件和 n 个组件之间的以下内容,但意识到这没有多大意义,因为仍然存在所有组件写入相同内容的竞争条件 hash_in信号。

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

-- System to connect multiple components to one master
-- When a component finds a hash, it writes to hash_in. Bus saves hash_in to an internal signal
-- and waits until master_ready is set to 1 to pass it the next signal
-- (Master sets master_ready to 0 while it's processing the last hash).

entity connector is
  port(
    -- The signal that all n components write to
    hash_in             : in    std_logic_vector(255 downto 0);
    -- Signal indicating if master is ready for the next hash
    master_ready        : in    std_logic;
    -- Hash we give to master
    hash_out            : out   std_logic_vector(255 downto 0)
  );
end connector;

architecture arch of connector is

  signal hash_internal : std_logic_vector(255 downto 0) := (others => '0');

begin

  hash_out <= hash_internal;

  process(master_ready, hash_in)
  begin

    if(master_ready) then
      hash_internal <= hash_in;
    end if;

  end process;

end architecture;

提前致谢!

根据你的问题,我假设你必须最小化最终设计的大小。

VHDL(仅)是描述硬件设计的一种方式。因此,在编写任何 VHDL 之前,您应该确定如何在目标技术中以最小尺寸实现该功能。

目标技术不太可能支持具有多个驱动程序的信号,因此这意味着您不能在尝试使用此类功能的地方用 VHDL 编写设计,因为综合工具将无法映射VHDL设计到目标技术。

可能最小的设计是使用多路复用器,该多路复用器可以 select 基于所有就绪信号的解码的适当组件,正如 Tricky 在评论中所写的那样。

它可能像一个相当大的解决方案一样接缝,但如果这是目标技术允许的最佳解决方案,那么它就是最小的解决方案。

So button line:了解目标技术允许的内容,编写 VHDL,以便综合工具将设计有效地映射到目标技术,最后检查结果实现是否符合预期。