始终在零时间阻止执行 [英] Always block execution at time zero

查看:27
本文介绍了始终在零时间阻止执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在零时间执行总是阻塞.例如下面的代码不会在零时间执行.

I want to execute always block at time zero. For e.g. below code won't execute at time zero.

always @* begin
//functional code
end

我在最后移动了敏感列表,以便代码在零时间执行,

I moved sensitivity list at the end so that code will execute at time zero,

always begin
//funcitonal code
@*;
end

此代码在零时间执行,但在零时间后根本不执行,即使块内使用的输入发生变化.例如,请参阅下面的代码及其输出:

This code executes at time zero but does not execute at all after time zero, even if there is a change in inputs used inside the block. For example see the code below and its output:

module AlwaysTimeZeroTest_v();

reg reg_A;

initial begin
  $display ("I'm in Initial begin block       \tTime=%f, reg_A=%b\n",$stime,reg_A);
  #1
  reg_A=1'bZ;

  #1
  reg_A=1'b1;

  #1
  reg_A=1'b0;

  #1
  reg_A=1'bZ;

  #5 $finish;
end

always @* begin
    $display ("I'm in Non-time Zero always block\tTime=%f, reg_A=%b\n",$stime,reg_A);
end

always begin
   $display ("I'm in time Zero always block     \tTime=%f, reg_A=%b\n",$stime,reg_A);
    @*;
end

endmodule

输出:

**I'm in Initial begin block              Time=0.000000, reg_A=x

I'm in time Zero always block           Time=0.000000, reg_A=x

I'm in Non-time Zero always block       Time=1.000000, reg_A=z

I'm in Non-time Zero always block       Time=2.000000, reg_A=1

I'm in Non-time Zero always block       Time=3.000000, reg_A=0

I'm in Non-time Zero always block       Time=4.000000, reg_A=z**

模拟通过 $finish(1) 在 9 NS + 0 时间完成

Simulation complete via $finish(1) at time 9 NS + 0

谁能解释为什么代码中的第二个总是阻塞在时间为零后根本不执行?

Can anyone explain why second always block in the code do not execute at all after time zero?

有没有一种方法可以实现始终块,以便它在零时间执行而不使用初始块?(类似于 SV 中的 always_comb?)

Is there a way I can implement always block so that it executes at time zero without using initial block? (something similar to always_comb in SV?)

推荐答案

很多人没有意识到 @ 是一个语句修饰符,而不是自己构造.它说延迟后面的语句,直到有事件发生.@(A or B) 表示等到 AB 的值发生变化(不要与A|B 的结果).@* 表示查看后面的语句,并构建一个隐式敏感信号列表以等待更改.

Many people do not realize that @ is a statement modifier, not construct by itself. It says to delay the statement that follows until there is an event. @(A or B) means wait until there is a change in the value of A or B (not to be confused with a change in the result of A|B). @* means look at the statement that follows, and build an implicit sensitivity list of signals to wait for a change.

在您的第一个 always 中,后面的语句是一个 begin/end 块,因此 reg_A 被添加到敏感列表中.在您的第二个 always 中,后面的语句是一个 null 语句,因此对任何更改都不敏感.

In your first always, the statement that follows is a begin/end block, so reg_A gets added to the sensitivity list. In your second always, the statement that follows is a null statement, so there is no sensitivity to any change.

确保 always @* 在时间 0 执行的唯一方法是将一些对变量的引用放在在时间 0 发生变化的块中.然后使用非阻塞赋值来该变量可避免任何时间 0 竞争条件.

The only way to make sure that always @* executes at time zero is to put some reference to variable in the block that has a change at time 0. Then use a non-blocking assignment to that variable to avoid any time 0 race conditions.

更好的是,使用专为解决此问题而设计的 alway_comb.

Better yet, use alway_comb which was especially designed to solve this problem.

这篇关于始终在零时间阻止执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆