`include "ovm.svh" import ovm_pkg::*; //-------------------------- class MyModel extends ovm_component; rand bit[3:0] wait_states; bit[3:0] max_wait_states=-1; bit[3:0] min_wait_states; constraint min_max_wait_states_c { wait_states >= min_wait_states; wait_states <= max_wait_states; } int compute_algorithm=-1; constraint compute_wait_states_c { (compute_algorithm > -1) -> wait_states == function_to_compute_wait_states(compute_algorithm); } `ovm_component_utils_begin(MyModel) `ovm_field_int(min_wait_states , OVM_ALL_ON | OVM_UNSIGNED) `ovm_field_int(max_wait_states , OVM_ALL_ON | OVM_UNSIGNED) `ovm_field_int(compute_algorithm, OVM_ALL_ON) `ovm_component_utils_end function new(string name, ovm_component parent=null); super.new(name, parent); endfunction virtual function void build(); super.build(); if (get_config_int("set_wait_states", max_wait_states)) begin min_wait_states=max_wait_states; end assert (this.randomize()); endfunction function bit[3:0] function_to_compute_wait_states(int algorithm); case (algorithm) 0 : return 2; //perhaps a value dependent on some other value 1 : return 4; 2 : return 8; default: return 10; endcase endfunction function void post_randomize(); ovm_report_info("KnobValues", $psprintf("Min=%0d, Max=%0d, Compute=%0d, Value=%0d", min_wait_states, max_wait_states, compute_algorithm, wait_states)); endfunction endclass : MyModel //-------------------------- class MyMemory extends ovm_component; rand MyModel model_q[2]; `ovm_component_utils(MyMemory) function new(string name, ovm_component parent=null); super.new(name, parent); foreach(model_q[mm]) begin string myName = $psprintf("mem%0d", mm); model_q[mm] = MyModel::type_id::create(myName, this); end endfunction endclass //-------------------------- class MyEnv extends ovm_env; rand MyMemory mem_q[4]; string names = "ABCD"; `ovm_component_utils(MyEnv) function new(string name, ovm_component parent=null); super.new(name, parent); foreach(mem_q[mm]) begin string myName = $psprintf("side%s", names.substr(mm,mm)); mem_q[mm] = MyMemory::type_id::create(myName, this); end endfunction virtual function void build(); super.build(); endfunction virtual task run(); #100 global_stop_request(); endtask endclass //-------------------------- module ModuleTop; MyEnv env; initial begin env = MyEnv::type_id::create("top", null); run_test(); end endmodule