sv coverage snippets

发布时间 2024-01-08 10:54:21作者: LeslieQ
点击查看代码
snippet coverage function coverage
	\`include "group_coverage.sv"
	class ${1:uvc}_coverage extends uvm_component;
	virtual ${1:uvc}_cov_intf cov_vif;
	bit     has_coverage = 1;
	\`uvm_component_utils(${1:uvc}_coverage)
	${2:function1}_grp    ${2:function1}_grp_inst ;
	${3:function2}_grp    ${3:function2}_grp_inst ;
	  function new (string name = "${1:uvc}_cov", uvm_component parent);
	    super.new(name, parent);
	    ${1:function1}_grp_inst = new() ;
	  endfunction : new

	  function void build_phase(uvm_phase phase);
	    super.build_phase(phase);
	    // Get configuration from tb
	    if(!uvm_config_db#(virtual ${1:uvc}_cov_intf)::get(this,"","cov_vif", cov_vif)) begin
	      \`uvm_fatal(get_full_name(),"cannot get cov_intf object from config DB")
	    end
	    //Get has_coverage from tb or test
	    if(!uvm_config_db#(bit)::get(this,"","coverage_control", has_coverage)) begin
	      has_coverage = 1;//default is open cov
	    end
	    //Macro used to get the cov_flag
	    //"default" takes effect when config_db::get failed
	    //"cov_name" is a string representing the name of covergroup
	    \`define GET_COV_FLAG(default,"${2:function1}_grp_name") \
	    bit cov_flag; \
	    if(!uvm_config_db#(bit)::get(this,"","${2:function1}_grp_name", cov_flag)) begin \
	      cov_flag = default; \
	    end
	  endfunction:build_phase

	  task run_phase(uvm_phase phase);
	    if(has_coverage) begin
		fork
		    ${2:function1}_grp_sample();
		    //......  other sample task
		join
	    end
	  endtask:run_phase




	  task ${2:function1}_grp_sample();
	    `GET_COV_FLAG(0,"${2:function1}_grp")
	    if (cov_flag) begin
	      forever begin
	        @(posedge cov_vif.clk iff cov_vif.srst_n);
	        if(cov_vif.sin1) begin//sample event
	            ${2:function1}_grp_inst.sample();
	        end
	      end
	    end
	  endtask:${2:function1}_grp_sample
	  //..other sample task
	endclass:$1_coverage