I am looking for some suggestions/minor adjustments to my code.
I want to set a flag for one clk cycle whenever the request is asserted(0->1). if the req is high for n number of continuous cloks then just set the flag only for the first clk cycle.
Thanks in advance.
forever @(posedge m_vif.uclk iff m_vif.Req == 1) begin
flag = 1;
@(posedge m_vif.uclk); //after one cycle clear the flag
flag = 0;
@(posedge m_vif.uclk iff m_vif.Req == 0); //wait till posedgeclk and req is 0
// or
// wait(m_vif.Req == 0);
end
// problem with my code is
// 1st clk Req = 1
// 2nd clk Req = 0
// 3rd clk Req = 1
// in this case the last event @(posedge m_vif.uclk iff m_vif.Req == 0); will evaluate to false and my loop would be waiting for Req == 0.
// one solution i could think here is removing posedge clk like --> wait(m_vif.Req == 0);
// so that it completes loops and goto start of forever loop for next clock
// Question:
// is there a better solution! if i want to synchronize the logic with clk like above in code. if so, how do i do ?
In reply to NaveenReddy:
You should be using non-blocking assignments.
forever @(posedge m_vif.uclk iff m_vif.Req == 1) begin
flag <= 1;
//after one cycle clear the flag
flag <= @(posedge m_vif.uclk) 0;
@(posedge m_vif.uclk iff m_vif.Req == 0); //wait till posedgeclk and req is 0
end