VHDL中进程之间的通信

时间:2013-05-01 00:44:35

标签: vhdl fpga inter-process-communicat

我在进程之间进行通信时遇到问题。我曾经使用flag和clearFlag来解决这个问题,但它有点烦人且不好看。处理这个问题的最佳做法是什么?以下是我之前如何做到的示例代码:

Proc_A : process (clk, reset, clrFlag)
begin
    if clrFlag = '1' then
        flag <='0';
    elsif reset = '0' then 
        A <= (others => '0');
    elsif rising_edge (clk) then
        A <= in;
        flag <= '1';
    end if;
end process;

Proc_B : process (clk, reset)
begin
    if reset = '0' then 
        B <= (others => '0');
    elsif rising_edge (clk) then
        if flag = '1' then
            B <= data;
            clrFlag <= '1';
        else 
            clrFlag <= '0';
        end if;
    end if;
end process;

这种方式有效,但我认为这不是很好的方法。我必须写一个标志和clrFlag夫妇来完成这项任务。我想要做的就是当事情发生时(例如A&lt; = in;),它触发另一个proc,例如Proc_B,运行一次或多次。这个问题的最佳做法是什么?谢谢!

1 个答案:

答案 0 :(得分:3)

你的代码不适合合成...你真的只想要在时钟部分之外重置部分:

Proc_A : process (clk, reset)
begin
    if reset = '0' then 
        A <= (others => '0');
    elsif rising_edge (clk) then
      if clrFlag = '1' then
        flag <='0';
      else
        A <= in;
        flag <= '1';
    end if;
end process;

关于你的实际问题:

对于模拟,您可以让进程等待信号:

Proc_B : process
begin
    wait until flag'event;
    B <= data;
end process;

然后只需用反向编写标记即可。

在可合成逻辑中,您必须像处理一样交换标记信号,或者使用其他更高级别的通信(如FIFO,消息框或类似信息)。

但是,如果所有proc_b逻辑都在一个周期内发生 - 那么你可以保证不会错过一个标志,并且即使标志一直被断言也能保持正常(因为它看起来像像你一样) - 你可以这样做(并结合这两个过程):

Proc : process (clk, reset, clrFlag)
begin
    flag <='0';
    if reset = '0' then 
        A <= (others => '0');
        B <= (others => '0');
    elsif rising_edge (clk) then
        if some_trigger_event = '1' then
           A <= in;
           flag <= '1';
        end if;
        -- recall that due to VHDL's scheduling rules, this "if" will take place 
        -- one clock cycle after the flag is written to, just as if it were in a
        -- separate process
        if flag = '1' then
            B <= data;
        end if;
    end if;
end process;