扫描二维码
随时随地手机看文章
class usb_simple_sequence extends uvm_sequence #(usb_transfer);rand int unsigned sequence_length;constraint reasonable_seq_len { sequence_length < 10 };//Constructorfunction new(string name=”usb_simple_bulk_sequence”);super.new(name);endfunction//Register with factory`uvm_object_utils(usb_simple_bulk_sequence)//the body() task is the actual logic of the sequencevirtual task body();repeat(sequence_length)`uvm_do_with(req, {//Setting the device_id to 2req.device_id == 8’d2;//Setting transfer type to BULKreq.type == usb_transfer::BULK_TRANSFER;})endtask : bodyendclass |
class usb_simple_bulk_test extends uvm_test;…virtual function void build_phase(uvm_phase phase );…uvm_config_db#(uvm_object_wrapper)::set(this, "sequencer_obj.main_phase","default_sequence", usb_simple_sequence::type_id::get());…endfunction : build_phaseendclass |
task pre_start()if(starting_phase != null)starting_phase.raise_objection(this);endtask : pre_starttask post_start()if(starting_phase != null)starting_phase.drop_objection(this);endtask : post_start |
class usb_simple_bulk_test extends uvm_test;usb_simple_sequence seq;…virtual function void main_phase(uvm_phase phase );…//User need to set the starting_phase as sequence start methodis explicitly called to invoke the sequenceseq.starting_phase = phase;seq.start();…endfunction : main_phaseendclass |
class usb_simple_sequence extends uvm_sequence #(usb_transfer);rand int unsigned sequence_length;constraint reasonable_seq_len { sequence_length < 10 };…virtual task body();usb_transfer::type_enum local_type;bit[7:0] local_device_id;//Get the values for the variables in case toplevel//test/sequence sets it.uvm_config_db#(int unsigned)::get(null, get_full_name(),“sequence_length”, sequence_length);uvm_config_db#(usb_transfer::type_enum)::get(null,get_full_name(), “local_type”, local_type);uvm_config_db#(bit[7:0])::get(null, get_full_name(),?“local_device_id”, local_device_id);repeat(sequence_length)`uvm_do_with(req, {req.device_id == local_device_id;req.type == local_type;})endtask : bodyendclass |
uvm_config_db#()::set中使用的参数类型和字符串(第三个参数)应该与uvm_config_db#()::get中使用的类型相匹配,否则将无法正确配置。这个地方如果出错会非常痛苦,但好在不需要经常修改,痛苦一次就好。另外,这几个配置项是随机类型,相应的配置值也需要满足约束范围。class usb_complex_sequence extends uvm_sequence #(usb_transfer);//Object of simple sequence used for sending bulk transferusb_simple_sequence simp_seq_bulk;//Object of simple sequence used for sending interrupt transferusb_simple_sequence simp_seq_int;…virtual task body();//Variable for getting device_id for bulk transferbit[7:0] local_device_id_bulk;//Variable for getting device_id for interrupt transferbit[7:0] local_device_id_int;//Variable for getting sequence length for bulkint unsigned local_seq_len_bulk;//Variable for getting sequence length for interruptint unsigned local_seq_len_int;//Get the values for the variables in case top level//test/sequence sets it.uvm_config_db#(int unsigned)::get(null, get_full_name(),“local_seq_len_bulk”,local_seq_len_bulk);uvm_config_db#(int unsigned)::get(null, get_full_name(),“local_seq_len_int”,local_seq_len_int);uvm_config_db#(bit[7:0])::get(null, get_full_name(),“local_device_id_bulk”,local_device_id_bulk);uvm_config_db#(bit[7:0])::get(null, get_full_name(),“local_device_id_int”,local_device_id_int);//Set the values for the variables to the lowerlevel//sequence/sequence item, which we got from//above uvm_config_db::get.//Setting the values for bulk sequenceuvm_config_db#(int unsigned)::set(null, {get_full_name(),”.”,”simp_seq_bulk”}, “sequence_length”,local_seq_len_bulk);uvm_config_db#(usb_transfer::type_enum)::set(null, {get_full_name(),“.”,“simp_seq_bulk”} , “local_type”,usb_transfer::BULK_TRANSFER);uvm_config_db#(bit[7:0])::set(null, {get_full_name(), “.”,”simp_seq_bulk”}, “local_device_id”,local_device_id_bulk);//Setting the values for interrupt sequenceuvm_config_db#(int unsigned)::set(null, {get_full_name(),”.”,”simp_seq_int”}, “sequence_length”,local_ seq_len_int);uvm_config_db#(usb_transfer::type_enum)::set(null, {get_full_name(),“.”,“simp_seq_int”} , “local_type”,usb_transfer::INT_TRANSFER);uvm_config_db#(bit[7:0])::set(null,{get_full_name(),“.”,”simp_seq_bulk”},“local_device_id”,local_device_id_int);`uvm_do(simp_seq_bulk)simp_seq_bulk.get_response();`uvm_send(simp_seq_int)simp_seq_int.get_response();endtask : bodyendclass |