两个进程的同步
Synchronization of two processes
我的架构使用平方根组件,它有以下端口:
component SQRT is
port (sqrt_clock : in std_logic;
start : in std_logic;
value : in std_logic_vector (15 downto 0);
result : out std_logic_vector (7 downto 0);
busy : out std_logic
);
end component;
当 sqrt-module 完成它的工作时,忙信号将为'0'
在我的主要进程中,我遍历输入数组并计算两个整数 a 和 b,它们是我的平方根模块的输入。然后,我想用输出文件填充第二个数据数组,其数组大小与输入数组相同
Main_Process: process(clk)
variable a : integer := 0;
variable b : integer := 0;
begin
if reset = '0'then
...
elsif clk'event and clk = '1' then
for iter in 0 to arraySize-1 loop
-- x and y calculation with inputarray(iter)
value <= std_logic_vector(TO_UNSIGNED(a+b, 16));
start <= '1';
outputarray(iter) <= TO_INTEGER(unsigned(sqrt_output));
end loop;
end case;
end process;
我希望主进程在每次数组迭代后等到 sqrt 模块完成计算。在没有任何同步的情况下,来自 sqrt 模块的第一个结果将填充到所有输出数组元素中。如果行为正确,主进程应该等到 sqrt-module 完成计算,然后填充输出数组元素,并在最后一步继续 for 循环等。
我尝试将 "busy" 信号放入主进程的敏感列表中:
Main_Process: process(clk, busy)
variable a : integer := 0;
variable b : integer := 0;
begin
if reset = '0'then
...
elsif clk'event and clk = '1' then
--only iterate further then sqrt is finished (busy = 0)
for iter in 0 to arraySize-1 loop
-- x and y calculation with inputarray(iter)
value <= std_logic_vector(TO_UNSIGNED(a+b, 16));
start <= '1';
if busy = '0' then
outputarray(iter) <= TO_INTEGER(unsigned(sqrt_output));
start <= '0';
end if;
end loop;
end if;
end process;
不幸的是,它不起作用。有没有一种简单的方法来实现同步。没有第三个 FSM 过程?
注意:我希望代码也可以综合。
在您的简化示例中,您不需要主时钟信号,因此您可以删除灵敏度列表。
wait until busy = '0'
outputarray(iter) <= TO_INTEGER(unsigned(sqrt_output));
start <= '0';
另一种方法是用 while
替换 for
循环
variable iter : integer range 0 to arraySize;
variable first : boolean;
[...]
iter := 0;
first := true;
while iter < arraySize loop
if busy = '0' then
if first = false then
outputarray(iter) <= TO_INTEGER(unsigned(sqrt_output));
start <= '0';
end if
-- x and y calculation with inputarray(iter)
value <= std_logic_vector(TO_UNSIGNED(a+b, 16));
start <= '1';
first := false;
iter := iter + 1;
end if
end loop;
我的架构使用平方根组件,它有以下端口:
component SQRT is
port (sqrt_clock : in std_logic;
start : in std_logic;
value : in std_logic_vector (15 downto 0);
result : out std_logic_vector (7 downto 0);
busy : out std_logic
);
end component;
当 sqrt-module 完成它的工作时,忙信号将为'0'
在我的主要进程中,我遍历输入数组并计算两个整数 a 和 b,它们是我的平方根模块的输入。然后,我想用输出文件填充第二个数据数组,其数组大小与输入数组相同
Main_Process: process(clk)
variable a : integer := 0;
variable b : integer := 0;
begin
if reset = '0'then
...
elsif clk'event and clk = '1' then
for iter in 0 to arraySize-1 loop
-- x and y calculation with inputarray(iter)
value <= std_logic_vector(TO_UNSIGNED(a+b, 16));
start <= '1';
outputarray(iter) <= TO_INTEGER(unsigned(sqrt_output));
end loop;
end case;
end process;
我希望主进程在每次数组迭代后等到 sqrt 模块完成计算。在没有任何同步的情况下,来自 sqrt 模块的第一个结果将填充到所有输出数组元素中。如果行为正确,主进程应该等到 sqrt-module 完成计算,然后填充输出数组元素,并在最后一步继续 for 循环等。
我尝试将 "busy" 信号放入主进程的敏感列表中:
Main_Process: process(clk, busy)
variable a : integer := 0;
variable b : integer := 0;
begin
if reset = '0'then
...
elsif clk'event and clk = '1' then
--only iterate further then sqrt is finished (busy = 0)
for iter in 0 to arraySize-1 loop
-- x and y calculation with inputarray(iter)
value <= std_logic_vector(TO_UNSIGNED(a+b, 16));
start <= '1';
if busy = '0' then
outputarray(iter) <= TO_INTEGER(unsigned(sqrt_output));
start <= '0';
end if;
end loop;
end if;
end process;
不幸的是,它不起作用。有没有一种简单的方法来实现同步。没有第三个 FSM 过程?
注意:我希望代码也可以综合。
在您的简化示例中,您不需要主时钟信号,因此您可以删除灵敏度列表。
wait until busy = '0'
outputarray(iter) <= TO_INTEGER(unsigned(sqrt_output));
start <= '0';
另一种方法是用 while
for
循环
variable iter : integer range 0 to arraySize;
variable first : boolean;
[...]
iter := 0;
first := true;
while iter < arraySize loop
if busy = '0' then
if first = false then
outputarray(iter) <= TO_INTEGER(unsigned(sqrt_output));
start <= '0';
end if
-- x and y calculation with inputarray(iter)
value <= std_logic_vector(TO_UNSIGNED(a+b, 16));
start <= '1';
first := false;
iter := iter + 1;
end if
end loop;