Assertion for checking clock alignment

In reply to Mechanic:
How can we make sure whether the clock is available after the reset?s
I suggest the use of a task with a fork join_any; one thread is a timeout, the other an edge of the clk (clk2 in my model below) That task is triggered periodically


      task automatic t(); 
            bit vclk=0; 
            if(rst_n) begin 
                fork
                    #35;  // if ends first, then no clock 
                    @(clk2) vclk=1'b1;  // clk2 occurred                
                join_any
                a_noclk: assert(vclk) else $display("@ %t no clocks", $realtime);   
                if(!vclk) -> e; 
            end           
        endtask 
        
        initial  forever begin 
            #20 t(); 
        end

Below is my testbench. You can use that approach to test for a keep-alive of the clock.
You need to adjust the delay values.
You can use the SVA assertions for the exact periods of the clocks.
See SVA Alternative for Complex Assertions
Verification Horizons - March 2018 Issue | Verification Academy


 import uvm_pkg::*; `include "uvm_macros.svh" 
 module top; 
    bit  clk,  clk2, rst_n;  
    event e; 
    default clocking @(posedge clk); endclocking
        initial 
        begin 
            #20 rst_n=1'b1; 
            #200; 
            forever #10 clk=!clk;  
        end 
        //  how can we make sure whether the clock is available after the reset?s
        task automatic t(); 
            bit vclk=0; 
            if(rst_n) begin 
                fork
                    #35;  // if ends first, then no clock 
                    @(clk2) vclk=1'b1;  // clk2 occurred                
                join_any
                a_noclk: assert(vclk) else $display("@ %t no clocks", $realtime);   
                if(!vclk) -> e; 
            end           
        endtask 
        
        initial  forever begin 
            #20 t(); 
        end
        
        
        // assertions here 
        
        initial begin 
            bit va, vb;
            repeat(200) begin 
                repeat(1) @(posedge clk);   
                if (!randomize(clk2)  with 
                { clk2 dist {1'b1:=3, 1'b0:=1}; 
            }) `uvm_error("MYERR", "This is a randomize error");
        end 
        $stop; 
    end  
endmodule  

Ben Cohen
http://www.systemverilog.us/ ben@systemverilog.us
For training, consulting, services: contact Home - My cvcblr


  1. SVA Alternative for Complex Assertions
    Verification Horizons - March 2018 Issue | Verification Academy
  2. SVA: Package for dynamic and range delays and repeats | Verification Academy
  3. SVA in a UVM Class-based Environment
    SVA in a UVM Class-based Environment | Verification Horizons | Verification Academy