Generate clk only when desired

In reply to PIYUSH PANWAR:

Hi All,
I am posting the solution for someone who is looking achieve the same thing what I was trying.

Hope it helps. (you will need to do this or something similar if trying to implement SPI interface verification component.)

fork
  begin
    while (device_enable && numClks !=0)
    begin
      gen_clk
      if (!device_on_hold)
        begin  
          numClks--;
          drive_valid_data_on_data_bus();
        end
      if (device_on_hold)
        begin
          drive_random_on_data_bus();
        end 
    end 
  end
join

task gen_clk();
  #5 clk <= 1;
  #5 clk <= 0;
endtask

Thanks for your help and valuable pointers.

Thanks & Regards,
Piyush