2013-05-01 102 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;