VHDL中进程间的通信

nig*_*ong 3 fpga vhdl 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;
Run Code Online (Sandbox Code Playgroud)

这种方法有效,但我认为这不是一个好方法。我必须编写一个 flag 和 clrFlag 来完成这项任务。我想做的就是当发生某些事情时(例如 A <= in;),它会触发另一个过程,例如 Proc_B 运行一次或多次。解决这个问题的最佳实践是什么?谢谢!

Mar*_*son 5

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

Proc_B : process
begin
    wait until flag'event;
    B <= data;
end process;
Run Code Online (Sandbox Code Playgroud)

每当你需要发生一些事情时,只需写下标志及其相反即可。

在可综合逻辑中,您要么必须像您所做的那样交换标志信号,要么使用其他一些更高级别的通信(例如 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;
Run Code Online (Sandbox Code Playgroud)

旁注 - 您的代码对于综合来说并不理想...您实际上只需要时钟部分之外的重置部分:

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;
Run Code Online (Sandbox Code Playgroud)