Verilog之event的用法

编写verilog的testbench时,可使用event变量触发事件。

event变量声明为:

event e_var;

event触发为:

->e_var;

捕获触发为:

@(e_var);

在modelsim中可运行的实例码如下:

10个时间单位后reset_trigger事件被触发,捕获后将reset设置一个时钟周期再触发reset_done_trigger。之后再分别设置10个周期的随机信号给enable和reset。


 

`timescale 1ns/100ps

 module event_test;

 event reset_trigger;

 event reset_done_trigger;

 reg clk;

 reg reset;

 reg enable;

 

 initial

     begin

           clk = 0;

           forever

                 #5 clk = ~clk;

      end

 

 initial

     begin

           forever

                 begin

                      @(reset_trigger);

                      @(negedge clk);

                      reset = 1;

                      @(negedge clk);

                      reset = 0;

                      -> reset_done_trigger;

                 end

      end

     

 initial

     begin

           #10 -> reset_trigger;

           @(reset_done_trigger);

           fork

                 repeat (10)

                      begin

                            @(negedge clk);

                            enable = $random;

                      end

                 repeat (10)

                      begin

                            @(negedge clk);

                            reset = $random;

                      end

           join

      end

 endmodule


你可能感兴趣的:(Verilog之event的用法)