How do you ensure no race condition occurs?
Let’s take the example below. In that example, I’m trying to count the number of clock cycles between the negedge of sent_sdin.
So the possible problem here is to have a race condition of the assignment of variable in_between_negedge.
fork
// Detect send_sdin negedge
forever begin
@(negedge sigs.sentMon.sent_sdin);
`uvm_info("sent_monitor", $sformatf("sent_sdin first negedge!"), UVM_MEDIUM);
in_between_negedge = 1;
@(negedge sigs.sentMon.sent_sdin);
`uvm_info("sent_monitor", $sformatf("sent_sdin second negedge!"),UVM_MEDIUM);
in_between_negedge = 0;
end
forever begin
wait(in_between_negedge);
// Race condition may happen here. When negedge of sent_sdin comes, the while-loop may
// not be able to get a 0 value for in_between_negedge. So cnt_pulse will become 1 greater
// than the correct value.
while(in_between_negedge) begin
@(posedge sigs.ecu_clk);
++cnt_pulse;
end
end
join_any
Here’s the interface where sent_sdin is located. I don’t clocking block.
interface sent_if (input ecu_clk);
logic rstb;
logic sent_en;
logic sent_sdin;
logic sent_sdout_hi;
logic sent_sdout_lo;
logic sent_rx_enb;
logic sent_tx_enb;
endinterface