- `timescale 1ns/1ps
-
- //定义变量名称
- logic [3:0] DIV_CLKA;
- ...
- logci [3:0] DIV_CLKD;
-
- //定义类
- class pll_params;
- rand bit[3:0] refclk_div;
- ...
- rand bit[5:0] div_clk_6bit;
- //定义变量
- int ref_clk;
-
- function set_refclk(int ref_clk); //ref_clk叫参数
- this.ref_clk = ref_clk;
- endfunction
- function new(int seed);
- this.srandom(seed);
- endfunction
-
- constraint c{
-
- if(this.ref_clk>200){
- div_clk_6bit ==6`b0;
- }
- else{
- ...
- }
- }
-
- endclass
在类里面的function、task、constraint中使用class里面的变量,需要在变量前面加this.进行标记。注意:用this,与参数和变量是不是同名,没有关系