【发布时间】:2020-06-13 11:41:28
【问题描述】:
我有 n 个组件来计算某个哈希值,但我不知道它们何时会完成。完成后,他们应该将找到的哈希发送到主组件,在那里,哪个哈希首先到达主组件并不重要,只要他收到一个。
在两个或更多组件同时完成计算其哈希而不需要 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;
提前致谢!
【问题讨论】:
-
让多个设备写入同一个信号会在同一个信号上创建多个驱动程序。您需要一个可以根据所有就绪信号的解码选择适当组件的多路复用器。解码中可以应用优先级。