uvm_event method examples
Below is the list of methods implemented in uvm_event_base,
- new; Creates a new event object
- wait_trigger; Waits for an event to be triggered
- wait_ptrigger; Waits for a persistent trigger of the event, avoids race conditions
- wait_on; Waits for the event to be activated for the first time, returns immediately if the event is already triggered
- wait_off; Returns if the event is off, else waits for the event turned off via reset event call
- is_on; Returns 1 if the event has triggered
- is_off; Returns 1 if the event has not been triggered
- reset; resets the event to its off state
- get_trigger_time; Returns the last time at which the event got triggered is_on is_off reset
- get_num_waiters; Returns the number of processes waiting on the event
This section will see how to use these methods.
event examples
uvm_event and uvm_ptrigger show the usage of wait_trigger and wait_ptrigger respectively.
wait_on example
We know that event trigger and wait_trigger are a one-to-one mapping, i.e one event trigger will only unblock the one wait_trigger. one more wait_trigger will wait for the one more trigger.
But in the case of wait_on, the wait_on returns once the event is triggered until the event is off or reset.
module uvm_events_ex; uvm_event ev_1; //declaring uvm_event ev_1 initial begin ev_1 = new(); //Creating an event fork //process-1, triggers the event begin #40; $display($time," Triggering The Event"); ev_1.trigger; end //process-2, wait for the event to trigger begin $display($time," Waiting for the Event to trigger"); ev_1.wait_on; $display($time," Event is on"); #100; $display($time," Event is on"); end join end endmodule
Simulator Output
0 Waiting for the Event to trigger 40 Triggering The Event 40 Event is on 140 Event is on
wait_off and reset
module uvm_events_ex; uvm_event ev_1; //declaring uvm_event ev_1 initial begin ev_1 = new(); //Creating an event fork //process-1, triggers the event begin #40; $display($time," Triggering The Event"); ev_1.trigger; #500; $display($time," Resetting The Event"); ev_1.reset(); end //process-2, wait for the event to trigger begin $display($time," Waiting for the Event to trigger"); ev_1.wait_on; $display($time," Event is on"); #100; $display($time," Event is on"); $display($time," Waiting for the Event to reset"); ev_1.wait_off; $display($time," Event is off"); end join end endmodule
Simulator Output
0 Waiting for the Event to trigger 40 Triggering The Event 40 Event is on 140 Event is on 140 Waiting for the Event to reset 540 Resetting The Event 540 Event is off
is_on is_off get_number_waiters
module uvm_events_ex; uvm_event ev_1; //declaring uvm_event ev_1 initial begin ev_1 = new(); //Creating an event fork //process-1, triggers the event begin #40; $display($time," Number of waiting trigger are %0d",ev_1.get_num_waiters()); $display($time," Triggering The Event"); ev_1.trigger; #500; $display($time," Resetting The Event"); ev_1.reset(); end //process-2, wait for the event to trigger begin $display($time," Waiting for the Event to trigger"); ev_1.wait_on; if(ev_1.is_on) $display($time," Event is on"); $display($time," Waiting for the Event to reset"); ev_1.wait_off; if(ev_1.is_off) $display($time," Event is off"); end join end endmodule
Simulator Output
0 Waiting for the Event to trigger 40 Number of waiting trigger are 1 40 Triggering The Event 40 Event is on 40 Waiting for the Event to reset 540 Resetting The Event 540 Event is off