Infinite Loop using While

In reply to Vinay Jain:

I have added $display statements in the code like the below:


class Receiver ;
...
    task dutOutMonitor ();
        @ (posedge ifc.wr_doing ) 
        @ (posedge ifc.spi_cs ) 
 
        while (ifc.spi_cs == 1'b1 ) 
        begin
            $display ("1. Value of spi_cs is %d", ifc.spi_cs);
            @ (posedge ifc.spi_sck ) 
              $display ("2. Value of spi_cs is %d", ifc.spi_cs);
        end
             $display ("3. Value of spi_cs is %d", ifc.spi_cs);  
         @ (negedge ifc.spi_cs )
             $display ("4. Value of spi_cs is %d", ifc.spi_cs);
    endtask
endclass
 
program execTest ();
initial 
begin: WRITE
     genObj.CONFIG();
     genObj.randomize();
     genObj.WRITE();
     receivObj.dutOutMonitor();    
end
endprogram

And this is the output that I am getting

===== INFO: Starting WRITE
Task: CONFIG
Task: WRITE
TASK: dutOutMonitor
1. Value of spi_cs is 1
2. Value of spi_cs is 1
1. Value of spi_cs is 1
2. Value of spi_cs is 1
1. Value of spi_cs is 1
2. Value of spi_cs is 1
1. Value of spi_cs is 1
... (all the same sequence)

I have a feeling, that when entering into while statement, it doesn’t check the external signals - ifc.spi_cs. So to get out from the while, I need to modify the ifc.spi_cs signal inside while cycle.