2013-05-01 101 views
1

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

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 < = in;),它会触发另一个proc,例如Proc_B运行一次或多次。这个问题的最佳做法是什么?谢谢!

回答

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; 

a只需用旗帜反面写下你需要发生的事情。在合成逻辑中,您必须像您一样交换标志信号,或者使用其他更高级别的通信(如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;