【问题标题】:Synchronization of two processes两个进程的同步
【发布时间】:2017-12-11 17:33:19
【问题描述】:

我的架构使用平方根组件,它有以下端口:

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 模块完成它的工作时,忙碌信号将是 '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 完成计算,然后填充 output-array 元素并在最后一步继续 for 循环等等。

我尝试将“忙碌”信号放入主进程的敏感度列表中:

 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 进程?

注意:我希望代码也是可合成的。

【问题讨论】:

    标签: vhdl


    【解决方案1】:

    在您的简化示例中,您不需要主时钟信号,因此您可以删除灵敏度列表。

    wait until busy = '0'
    outputarray(iter) <= TO_INTEGER(unsigned(sqrt_output)); 
    start <= '0';
    

    另一种选择是将for 循环替换为while

    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;
    

    【讨论】:

    • 很遗憾,您不能在具有敏感度列表的进程中放置等待语句
    • 这就是为什么答案说“删除敏感列表”
    • @BrianDrummond 他的评论是在我编辑答案之前。我不好。
    猜你喜欢
    • 1970-01-01
    • 2012-06-08
    • 1970-01-01
    • 1970-01-01
    • 2011-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多