VHDL 块和受保护的输入 - 此代码的作用是什么?
VHDL block and guarded input - what does this code do?
我从初学者的 VHDL 教程中得到以下内容:
rising_edge: block(clk’event and clk = ‘1’)
begin
result <= guarded input or force after 10ns;
end block rising_edge
说明文字是
"Essentially I have a block called rising_edge, and it's a block with a guard condition which does the following, it checks that we have an event on the clock, and that the clock is equal to one, so we're effectively looking for the so called rising_edge. We're looking for the event where the clock goes from 0 to 1, and if it does, then we can conditionally assign the results, so you'll see that the result variable here says that it is a guarded input or force after 10 ns might seem a bit confusing, but consider it without the guarded keyword. All we're doing is we're assigning the result of the evaluation of input or force, and we're doing it in a guarded setup. So, in this case, the assignment of the signal result is only executed if the guard signal is actually true, and in our example it means that the assignment of the expression, which is input or force, will only happen on the rising_edge of the clock because that's on guard condition."
现在我已经一遍又一遍地阅读这篇文章并在网上进行搜索,但对于它的实际作用一无所知。有人可以温和地解释一下它的用途吗?
块本质上是一组并发语句。在实际使用方面,它与 process
非常相似,只是它的范围有限,允许 component
式信号映射(使用 port
和 port map
)。它可用于提高可读性(参见 this question) and really not much else. Blocks are resonably rarely used and frequently not synthesis supported(see here)。据我(有限)的了解,块的使用除了可读性外没有其他优势。
因为你的block语句包含了一个guard condition(clk'event and clk='1'
这里是guard condition),所以是一个guarded block。在受保护的块内,声明为受保护的信号(如在您的示例中) 仅当保护条件评估为 true
时才会分配
被保护的整个语句(即在你的情况下 input or force after 10ns
)只会在保护条件计算为 true
时执行,即在 clk
的上升沿.因此,就所有意图和目的而言,此块具有与
相同的行为
process(clk)
begin
if clk'event and clk = '1' then
result <= input or force after 10ns;
end if;
end process;
不过我要说,这是一个糟糕的例子。一方面,正如其他人所说, block
的使用非常罕见,它们通常只用于非常高级的设计中。自 1993 年以来,不鼓励使用 clk'event and clk = '1'
(参见 here)。还应该再次提到,使用 rising_edge
作为标签是一个糟糕的主意,使用 force
作为信号名称也是如此(在 VHDL 2008 中,force
是保留的可用于将信号强制为值的关键字)。
基于这应该是一个 初学者 教程的想法,并且没有任何解释为什么使用这种不寻常的风格,更多常规实现将是:
process : (clk)
begin
if (rising_edge(clk)) then
result <= input or force after 10 ns;
end if;
end process;
注意几点:
- 这假设
input
和 force
是实体的信号或输入。
- 如果您的代码要在真实的硬件设备中实现,那么对信号分配延迟建模是不常见的。
- 你问题中的代码使用了
after 10ns;
,这是无效的;您需要在值和单位之间添加 space(如我的代码所示)。
- 你问题中的代码使用
rising_edge
作为标识符,而这实际上已经被定义为一个函数,假设你包含的标准 IEEE 库比我认为的 VHDL93 更新。
- 您问题中的代码使用
force
作为信号名称,而这也是自 VHDL2008 以来保留的语言关键字。
我的建议是找一个不同的教程。您发布的报价没有写清楚,您发布的代码似乎让您走上了一条奇怪的道路。我只能认为该教程实际上非常非常古老。
我从初学者的 VHDL 教程中得到以下内容:
rising_edge: block(clk’event and clk = ‘1’)
begin
result <= guarded input or force after 10ns;
end block rising_edge
说明文字是
"Essentially I have a block called rising_edge, and it's a block with a guard condition which does the following, it checks that we have an event on the clock, and that the clock is equal to one, so we're effectively looking for the so called rising_edge. We're looking for the event where the clock goes from 0 to 1, and if it does, then we can conditionally assign the results, so you'll see that the result variable here says that it is a guarded input or force after 10 ns might seem a bit confusing, but consider it without the guarded keyword. All we're doing is we're assigning the result of the evaluation of input or force, and we're doing it in a guarded setup. So, in this case, the assignment of the signal result is only executed if the guard signal is actually true, and in our example it means that the assignment of the expression, which is input or force, will only happen on the rising_edge of the clock because that's on guard condition."
现在我已经一遍又一遍地阅读这篇文章并在网上进行搜索,但对于它的实际作用一无所知。有人可以温和地解释一下它的用途吗?
块本质上是一组并发语句。在实际使用方面,它与 process
非常相似,只是它的范围有限,允许 component
式信号映射(使用 port
和 port map
)。它可用于提高可读性(参见 this question) and really not much else. Blocks are resonably rarely used and frequently not synthesis supported(see here)。据我(有限)的了解,块的使用除了可读性外没有其他优势。
因为你的block语句包含了一个guard condition(clk'event and clk='1'
这里是guard condition),所以是一个guarded block。在受保护的块内,声明为受保护的信号(如在您的示例中) 仅当保护条件评估为 true
被保护的整个语句(即在你的情况下 input or force after 10ns
)只会在保护条件计算为 true
时执行,即在 clk
的上升沿.因此,就所有意图和目的而言,此块具有与
process(clk)
begin
if clk'event and clk = '1' then
result <= input or force after 10ns;
end if;
end process;
不过我要说,这是一个糟糕的例子。一方面,正如其他人所说, block
的使用非常罕见,它们通常只用于非常高级的设计中。自 1993 年以来,不鼓励使用 clk'event and clk = '1'
(参见 here)。还应该再次提到,使用 rising_edge
作为标签是一个糟糕的主意,使用 force
作为信号名称也是如此(在 VHDL 2008 中,force
是保留的可用于将信号强制为值的关键字)。
基于这应该是一个 初学者 教程的想法,并且没有任何解释为什么使用这种不寻常的风格,更多常规实现将是:
process : (clk)
begin
if (rising_edge(clk)) then
result <= input or force after 10 ns;
end if;
end process;
注意几点:
- 这假设
input
和force
是实体的信号或输入。 - 如果您的代码要在真实的硬件设备中实现,那么对信号分配延迟建模是不常见的。
- 你问题中的代码使用了
after 10ns;
,这是无效的;您需要在值和单位之间添加 space(如我的代码所示)。 - 你问题中的代码使用
rising_edge
作为标识符,而这实际上已经被定义为一个函数,假设你包含的标准 IEEE 库比我认为的 VHDL93 更新。 - 您问题中的代码使用
force
作为信号名称,而这也是自 VHDL2008 以来保留的语言关键字。
我的建议是找一个不同的教程。您发布的报价没有写清楚,您发布的代码似乎让您走上了一条奇怪的道路。我只能认为该教程实际上非常非常古老。