gpt4 book ai didi

vhdl - VHDL中进程之间的通信

转载 作者:行者123 更新时间:2023-12-04 02:57:14 25 4
gpt4 key购买 nike

我在进程之间进行通信时遇到问题。我曾经使用 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;

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

最佳答案

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

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;

旁注 - 你的代码不适合综合......你真的只想要时钟部分之外的重置部分:
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;

关于vhdl - VHDL中进程之间的通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16311178/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com