Problem using ovm_do macro

I am trying to use ovm_do in the body task of my sequence to create a packet object but everytime i get the following error :-

Error-[DCF] Dynamic cast failed
dri_seq.sv, 205
Casting of source class type ‘ovm_sequence_item’ to destination class type
‘my_packet’ failed due to type mismatch.
Please ensure matching types for dynamic cast

my packet type of object is derived from ovm_sequence_item so i dont know what i am missing here.

here’s the snippet from my sequence :-

class err_crc extends ovm_sequence;
`ovm_object_utils(err_crc)
rand int xy;
constraint ra {xy inside {0,1};}
function new (string name = “err_crc”);
super.new(name);
endfunction
my_packet pkt;

virtual task body();

$display("Hello , Sending packets with CRC error ",$time);
`ovm_do(pkt)

here’s my env :-

class my_env extends ovm_component;
my_driver _driver;

err_crc _crc_seq;

// bad_seq_no bad_seq;
//ovm_sequencer #(simple_item) main_seq;

my_sequencer my_seq;
`ovm_component_utils(my_env);
function new (string name,ovm_component parent = null);
super.new(name,parent);
endfunction
virtual function void build();
super.build();

    _crc_seq = err_crc::type_id::create("_crc_seq",this);
  
  _driver = my_driver::type_id::create("_driver",this);

 my_seq = my_sequencer::type_id::create("my_seq",this);

endfunction:build
virtual function void connect();
_driver.seq_item_port.connect(my_seq.seq_item_export);
endfunction:connect

task run();
$display(“Hello , I am in Environment’s super.run”,$time);
_crc_seq.start(my_seq);
global_stop_request();
//super.run();
endtask:run

endclass:my_env

Can somebody suggest what i am missing here ?

Thanks
vikram

Hey here is how i write my seq.

class read_mem extends ovm_sequence # (read_addr_ch_seq_item);
// plz note the read_addr_ch_seq_item is name of the class whose attributes will be randomized and those will be received by this seq.
// I donot see the parametrized class in your example.

read_addr_ch_seq_item w; //declaring a object of read_addr_ch_seq_item class

`ovm_sequence_utils(read_mem, read_addr_ch_sequencer) // I have registered the seq and then mentioning with which sequencer this seq is associated with … You have written ovm_object in your example.

function new(string name=“read_mem”);
super.new(name);
endfunction:new

task body ();
`ovm_do_with(w,{ // here in this ovm do with macro the attributes of the
w.i_arvalid_m==1;// read_addr_ch_seq_item class will be randomized and
w.i_araddr_m==32’h380000; // these constraints will be applied while
w.i_arlen_m==125;});//randomization
endtask: body

endclass: read_mem

THanks the sequence i wrote works if i use :-

for(int k=0;k<2;k++) begin
wait_for_grant();
pkt.randomize with {pkt.pkt_err == BAD_SEQ_NO;};
send_request(pkt);

i dont think it is neccessary to parametrize the sequence with the item , also the sequence registeration :- `ovm_object_utils(err_crc)
is ok as i just declare an ovm sequencer and call the start tasks on it in the env , i dont register it with the sequencer.

Nonetheless i tried your suggestion but i guess the same error, here’s the item :-

class my_packet extends ovm_sequence_item;
rand transfer_type pkt_tt;
rand pak_type pkt_t;
rand error_type pkt_err;
rand int unsigned routing_add;
rand int unsigned device_add;
rand int ep;
rand int seq_no;
rand int num_p;

constraint EP {ep inside {[1:31]};}
constraint TAG {seq_no inside {[1:31]};}
constraint NUM_P {num_p inside {[1:31]};}
function new(string name = “my_packet”);
super.new(name);
endfunction
endclass : my_packet

class bad_seq_no extends ovm_sequence #(my_packet);
`ovm_sequence_utils(bad_seq_no,my_sequencer)
function new (string name = “bad_seq_no”);
super.new(name);
endfunction
my_packet pkt;

virtual task body();

$display("Hello , Sending Bad Sequence Number packets ",$time);
//pkt = new();
`ovm_do(pkt)

//code which works :-

/*for(int k=0;k<2;k++) begin
wait_for_grant();
pkt.randomize with {pkt.pkt_err == BAD_SEQ_NO;};
send_request(pkt);
end */

endtask :body
endclass

here’s my env :-
class my_env extends ovm_component;
my_driver _driver;

bad_seq_no bad_seq;

my_sequencer my_seq;
`ovm_component_utils(my_env);
function new (string name,ovm_component parent = null);
super.new(name,parent);
endfunction
virtual function void build();
super.build();

 bad_seq = bad_seq_no::type_id::create("bad_seq",this);
    
 my_seq = my_sequencer::type_id::create("my_seq",this);

endfunction:build
virtual function void connect();
_driver.seq_item_port.connect(my_seq.seq_item_export);
endfunction:connect

task run();
$display(“Hello , I am in Environment’s super.run”,$time);

bad_seq.start(my_seq);
global_stop_request();
  endtask:run

endclass:my_env

I donot see the ovm macro to register the sequence item with the factory.

which is
`ovm_object_utils(class_name)

your code works with sv call for randomization but your code will not work with ovm do or ovm do with macro.

Try registering your my_packet class with above ovm macro and your code should work.