简体   繁体   English

Verilog中initial和always块的执行顺序

[英]Execution order of initial and always blocks in Verilog

I'm new to Verilog programming and would like to know how the Verilog program is executed.我是 Verilog 编程的新手,想知道 Verilog 程序是如何执行的。 Does all initial and always block execution begin at time t = 0, or does initial block execution begin at time t = 0 and all always blocks begin after initial block execution?是所有初始和始终块执行都在时间 t = 0 开始,还是初始块执行开始于时间 t = 0 并且所有始终块在初始块执行之后开始? I examined the Verilog program's abstract syntax tree, and all initial and always blocks begin at the same hierarchical level.我检查了 Verilog 程序的抽象语法树,所有初始块和始终块都从同一层次结构开始。 Thank you very much.非常感谢。

All initial and all always blocks throughout your design create concurrent processes that start at time 0. The ordering is indeterminate as far as the LRM is concerned.整个设计中的所有initial和 all always块都会创建从时间 0 开始的并发进程。就 LRM 而言,排序是不确定的。 But may be repeatable for debug purposes when executing the same version of the same simulation tool.但在执行同一仿真工具的同一版本时,出于调试目的可能是可重复的。 In other words, never rely on the simulation ordering to make you code execute properly.换句话说,永远不要依赖模拟排序来让你的代码正确执行。

Verilog requires event-driven simulation. Verilog 需要事件驱动的仿真。 As such, order of execution of all 'always' blocks and 'assign' statements depends on the flow of those events.因此,所有“always”块和“assign”语句的执行顺序取决于这些事件的流程。 Signal updated one block will cause execution of all other blocks which depend on those signals.信号更新一个块将导致执行依赖于这些信号的所有其他块。

The difference between always blocks and initial blocks is that the latter is executed unconditionally at time 0 and usually produces some initial events, like generation of clocks and/or schedule reset signals.始终块和初始块之间的区别在于后者在时间 0 无条件执行,并且通常会产生一些初始事件,例如时钟和/或调度重置信号的生成。 So, in a sense, initial blocks are executed first, before other blocks react to the events which are produced by them.因此,从某种意义上说,首先执行初始块,然后其他块对它们产生的事件做出反应。

But, there is no execution order across multiple initial blocks or across initial blocks and always blocks which were forced into execution by other initial blocks.但是,跨多个初始块或跨初始块没有执行顺序,并且总是由其他初始块强制执行的块。

In addition, there are other ways to generate events besides initial blocks.此外,除了初始块之外,还有其他方法可以生成事件。

In practice, nobody cares, and you shouldn't either.在实践中,没有人关心,你也不应该关心。

On actual hardware, the chip immediately after powering-up is very unstable because of the transient states of the power supply circuit, hence its initial states untrustworthy.在实际硬件上,刚上电后的芯片由于供电电路的瞬态状态非常不稳定,因此其初始状态是不可信的。

The method to ensure initial state in practice is to set them in the initial block as在实践中确保初始 state 的方法是在初始块中将它们设置为

always @ (event) {
    if(~n_reset) {
        initial_state=0
    } else {
        do_something();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM