uvm 使用api模式来写sequence

方法1


class a_item extends uvm_sequence_item;
	rand bit [7:0] a_data;
	rand bit [7:0] b_data;
	`uvm_object_utils_begin(a_item)
		`uvm_field_int(a_data,UVM_ALL_ON)
		`uvm_field_int(b_data,UVM_ALL_ON)
	`uvm_object_utils_end	
	function new(string name="a_item");
		super.new(name);
	endfunction
endclass

class a_seq_base extends uvm_sequence;
	`uvm_object_utils(a_seq_base)
	a_item a_item_h;
	int a;
	int b;

	function new(string name="a_seq_base");
		super.new(name);
	endfunction
	virtual task body();
		`uvm_fatal(get_type_name(),"MUST override this class")
	endtask
endclass

class a_seq extends a_seq_base;
	`uvm_object_utils(a_seq)
	function new(string name="a_seq");
		super.new(name);
	endfunction

	//task set_item(a_item t,int a,int b);
	//	t.a_data = a;
	//	t.b_data = b;
	//endtask

	virtual task body();
		uvm_sequence_item tmp;
		tmp =create_item(a_item::get_type(),m_sequencer,"req");

		void'($cast(a_item_h,tmp));
		start_item(a_item_h);
		a_item_h.randomize();
		a_item_h.a_data = a;
		a_item_h.b_data = b;
			$display("--a_seq body0----$$$$$");
		//set_item(a_item_h,10,100);
		`uvm_info(get_name(),$sformatf("%s",a_item_h.sprint()),UVM_LOW)
			$display("--a_seq body1----$$$$$");
		finish_item(a_item_h);
		
	endtask
endclass

class a_seq_set_api extends a_seq_base;
	`uvm_object_utils(a_seq_set_api)

	a_seq a_seq_h;
	function new(string name="a_seq_set");
		super.new(name);
		a_seq_h = new("a_seq_h");
	endfunction
	function void set_sqr(uvm_sequencer handle=null);
		m_sequencer = handle;
	endfunction
	virtual task body();
		`uvm_fatal(get_type_name(),"must override api")
	endtask
	
	task set(int a , int b);
			$display("--a_seq_set body0----$$$$$");
		a_seq_h.a = a;
		a_seq_h.b = b;
		a_seq_h.start(m_sequencer);
			$display("--a_seq_set body1----$$$$$");
	endtask
endclass

class a_seq_actual extends a_seq_set_api;
	`uvm_object_utils(a_seq_actual)
	function new(string name="a_seq_actual");
		super.new(name);
	endfunction

	virtual task body();
			$display("--a_seq_actual body0----$$$$$");
		set(16,64);
		#100;
		set(40,10);
			$display("--a_seq_actual body1----$$$$$");
	endtask
endclass

方法2

class a_item extends uvm_sequence_item;
	int a;
	int b;
	`uvm_object_utils_begin(a_item)
	  `uvm_field_int(a,UVM_ALL_ON)
	  `uvm_field_int(b,UVM_ALL_ON)
	`uvm_object_utils_end
	function new(string name="a_item");
		super.new(name);
	endfunction
endclass

class a_seq extends uvm_sequence;
	`uvm_object_utils(a_seq)
	a_item a_item_h;
	function new(string name="a_seq");
		super.new(name);
		a_item_h = a_item::type_id::create("a_item_h");
	endfunction
  task set(int a);
		a_item_h.a = a;
	endtask	
	task body();
		start_item(a_item_h);
		a_item_h.randomize();
		`uvm_info(get_type_name(),"in a_seq2 run phase", UVM_LOW);
		//set_api(10);
		`uvm_info(get_name(),$sformatf("%s",a_item_h.sprint()),UVM_LOW)
		finish_item(a_item_h);
	endtask
	task set_api(int a);
		`uvm_info(get_type_name(),"in/ a_seq set_api phase", UVM_LOW);
		set(a);
		body();
	endtask

endclass

class ap_seq extends uvm_sequence;
	`uvm_object_utils(ap_seq)
	a_seq a_seq_h;
	function new(string name="a_seq");
		super.new(name);
		a_seq_h = a_seq::type_id::create("a_seq_h");
	endfunction
	task body();
	//	`uvm_info(get_type_name(),"in run phase", UVM_LOW);
	//	start_item(a_item_h);
	//	a_item_h.randomize();
	//	set_api(10);
	//	`uvm_info(get_name(),$sformatf("%s",a_item_h.sprint()),UVM_LOW)
	//	finish_item(a_item_h);
		`uvm_info(get_type_name(),"in ap_seq set_api phase", UVM_LOW);
		 a_seq_h.start(m_sequencer);
		 a_seq_h.set_api(10);
		 a_seq_h.set_api(20);
		 a_seq_h.set_api(30);
		 a_seq_h.set_api(40);
	endtask
endclass

你可能感兴趣的:(uvm)