|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460 |
- class driver extends uvm_driver #(seq);
- `uvm_component_utils(driver)
-
- virtual axi_driver_if vif;
- sequence seq;
-
- function new(string name="driver", uvm_component parent=null);
- super.new(name, parent);
- endfunction
-
- virtual function void build_phase(uvm_phase phase);
- super.build_phase(phase);
- seq=sequence::type_id::create("seq");
- if(!uvm_config_db#(virtual axi_driver_if)::get(this," ","vif",vif))
- `uvm_error("driver"," Interface not set");
- endfunction
-
- task reset();
- begin
-
- vif.awvalid <= 0;
- vif.awready <= 0;
- vif.awid <= 0;
- vif.awlen <= 0;
- vif.awsize <= 0;
- vif.awaddr <= 0;
- vif.awburst <= 0;
- vif.wvalid <= 0;
- vif.wready <= 0;
- vif.wid <= 0;
- vif.wdata <= 0;
- vif.wstrb <= 0;
- vif.wlast <= 0;
- vif.bready <= 0;
- vif.bvalid <= 0;
- vif.bid <= 0;
- vif.bresp <= 0;
- vif.arvalid <= 0;
- vif.arready <= 0;
- vif.arid <= 0;
- vif.arlen <= 0;
- vif.arsize <= 0;
- vif.araddr <= 0;
- vif.arburst <= 0;
- vif.rvalid <= 0;
- vif.rready <= 0;
- vif.rid <= 0;
- vif.rdata <= 0;
- vif.rstrb <= 0;
- vif.rlast <= 0;
- vif.rresp <= 0;
- @(posedge vif.clk);
- `uvm_info(get_type_name(),"reset applied",UVM_MEDIUM)
- end
- endtask
- virtual task run_phase(uvm_phase phase);
- reset();
- seq_tem_port.get_next_item(txn);
- if(wr_rd==1)
- begin
- wrtie_address();
- write_data();
- write_response();
- end
- else
- begin
- read_address();
- read_data();
- end
- endtask
- virtual task write_address();
- vif.awready<=0;
- vif.awaddr<= txn.awaddr;
- vif.awsize<= txn.awsize;
- vif.awlen<= txn.awlen;
- vif.awcache<= txn.awcache;
- vif.awburst<= txn.awburst;
- vif.awvalid<=1'b1;
- case (txn.awburst)
- 2'b00 : write_ad_fixed_burst;
- 2'b01 : write_ad_incr_burst;
- 2'b10 : write_ad_wrap_burst;
- endcase
- while(vif.awready==0)
- $display("within loop");
- begin
- @(posedge vif.clk);
- if(vif.awvalid==1)
- begin
- awready=1;
- $display("write address phase is completed");
- end
- end
- vif.awvalid=0;
- endtask
-
- ////////////////// wridte_fixed burst////////////////
- virtual task write_ad_fixed_burst();
- vif.awlen <= txn.awlen;
- vif.awid <= txn.awid;
- vif.awaddr <= txn.awaddr;
- vif.awsize<= txn.awsize;
- vif.awvalid<= 1;
- wait(vif.awready);
- vif.awvalid<=0;
- write_data();
- endtask
- virtual task write_data();
- vif.wready<=0;
- for(int i=0;i<=txn.awlen+1;i++) begin
- $display("write data started");
- vif.wdata<=txn.wdata[i];
- vif.wstrb<=txn.wstrb[i];
- vif.wid<=txn.wid;
- vif.wvalid<=1'b1;
- if(i=txn.awlen+1) vif.wlast=1;
- while (wready=0)
- begin @(posedge vif.clk)
- if (vif.wready==1)
- txn.wready=1;
- end
- vif.wlast=0;
- vif.wvalid=0;
- vif.wready=0;
- $display("write data completed");
- end
- write_ad_incr();
- endtask
-
- //////////////////////write_address_incremental/////////////////
- virtual task write_ad_incr();
- vif.awlen <= txn.awlen;
- for(int i=0; i<(txn.awlen +1);i++)
- vif.awid <= txn.awid;
- vif.awaddr <= txn.awaddr;
- vif.awsize<= txn.awsize;
- txn.awaddr<= txn.awaddr+(2**awsize);
- vif.awvalid<= 1;
- wait(vif.awready);
- vif.awvalid<=0;
- write_data();
- endtask
- virtual task write_data();
- vif.wready<=0;
- for(int i=0;i<=txn.awlen+1;i++) begin
- $display("write data started");
- vif.wdata<=txn.wdata[i];
- vif.wstrb<=txn.wstrb[i];
- vif.wid<=txn.wid;
- vif.wvalid<=1'b1;
- if(i=txn.awlen+1) vif.wlast=1;
- while (wready=0)
- begin @(posedge vif.clk)
- if (vif.wready==1)
- txn.wready=1;
- end
- vif.wlast=0;
- vif.wvalid=0;
- vif.wready=0;
- $display("write data completed");
- write_ad_wrap();
- end
- endtask
-
- ///////////wri_address_wrap///////////////////////
- virtual task write_ad_wrap();
- vif.awlen <= '{1,3,7,15};
- vif.awid <= txn.awid;
- vif.awaddr <= txn.awaddr;
- vif.awsize<= txn.awsize;
-
- begin
- int burst_length=(awlen+1);
- int burst_size=(awsize+1);
- int lower_boundary=INT[awaddr/(burst_length*burst_size)]*(burst_length*burst_size);
- int upper_boundary=lower_boundar+(burst_length*burst_size);
- for (int i=0; i< (pkt.awlen+1);i++)
- begin
- if(vif.awaddr==upper_boundary)
- vif.awaddr=lower_boundary;
- else
- vif.awaddr <= vif.awaddr+ (2**vif.awsize);
- vif.awvalid<= 1;
- wait(vif.awready);
- vif.awvalid<=0;
- end
- write_data();
- endtask
-
- virtual task write_data();
- vif.wready<=0;
- for(int i=0;i<=txn.awlen+1;i++) begin
- $display("write data started");
- vif.wdata<=txn.wdata[i];
- vif.wstrb<=txn.wstrb[i];
- vif.wid<=txn.wid;
- vif.wvalid<=1'b1;
- if(i=txn.awlen+1) vif.wlast=1;
- while (wready=0)
- begin @(posedge vif.clk)
- if (vif.wready==1)
- txn.wready=1;
- end
- vif.wlast=0;
- vif.wvalid=0;
- vif.wready=0;
- $display("write data completed");
- write_response();
- end
- endtask
- virtual task write_response();
- if(vif.wvalid&&vif.wready&&vif.wlast)
- wait(bvalid)
- begin
- vif.bid = pkt.bid;
- vif.bresp = pkt.bresp;
- end
- vif.bready <= 1 ;
- for(i=0;i<=awlen+1;i++)
- begin
- if(vif.awid==vif.bid)
- case(vif.bresp)
- 2'b00:"okay";
- 2'b01:"exclusive okay";
- 2'b10:"slave error";
- 2'b11:"decode error";
- endcase
- end
- vif.bready<=0;
- endtask
-
-
- ///////////////////////Read address////////////////////////////////////////////////
-
-
- task read_adress();
-
- `uvm_info("master_driver",$sformatf("message from driver\n %s",pkt.sprint()),UVM_HIGH)
-
- vif.arid <= pkt.arid;
- vif.araddr <= pkt.araddr;
- vif.arlen <= pkt.arlen;
- vif.arsize <= pkt.arsize;
- vif.arburst <= pkt.arburst;
- vif.arvalid <= 1;
- `uvm_info("master_driver",$sformatf("message from driver \n %s",pkt.sprint()),UVM_HIGH)
-
- case (txn.arburst)
-
- 2'b00 : read_address_fixed_burst;
- 2'b01 : read_address_incr_burst;
- 2'b10 : read_address_wrap_burst;
-
- endcase
-
- @(posedge vif.clk);
-
- wait (vif.arready);
-
- vif.arvalid <= 0;
-
- endtask
- //////////////////////////////////////// raed wrap burst////////////////////
- virtual task read_ad_wrap();
- vif.awlen <= '{1,3,7,15};
- vif.arid <= txn.arid;
- vif.araddr <= txn.araddr;
- vif.arsize<= txn.arsize;
-
- begin
- int burst_length=(arlen+1);
- int burst_size=(arsize+1);
- int lower_boundary=INT[araddr/(burst_length*burst_size)]*(burst_length*burst_size);
- int upper_boundary=lower_boundar+(burst_length*burst_size);
- for (int i=0; i< (pkt.arlen+1);i++)
- begin
- if(vif.araddr==upper_boundary)
- vif.araddr=lower_boundary;
- else
- vif.araddr <= vif.araddr+ (2**vif.arsize);
- vif.arvalid<= 1;
- wait(vif.arready);
- vif.arvalid<=0;
- end
- read_data1();
- endtask
-
- virtual task read_data1();
- vif.rready<=0;
- for(int i=0;i<=txn.arlen+1;i++) begin
- $display("read data started");
- vif.rdata<=txn.rdata[i];
- vif.rid<=txn.rid;
- vif.rvalid<=1'b1;
- if(i=txn.arlen+1) vif.rlast=1;
- while (rready=0)
- begin @(posedge vif.clk)
- if (vif.rready==1)
- txn.rready=1;
- end
- vif.rlast=0;
- vif.rvalid=0;
- $display("read data completed");
- end
- foreach (vif.rdata[i])
- begin
- if (vif.arid == vif.rid)
- begin
- case (vif.rresp)
-
- 2'b00 : s = "Transaction OKAY";
- 2'b01 : s = "Transaction FAILED";
- 2'b10 : s = "SLAVE ERROR";
- 2'b11 : s = "DEEOCDE ERROR";
-
- endcase
-
- `uvm_info("axi master_driver",$sformatf("\n t %s response for the received data \n",s),UVM_MEDIUM)
-
- end
- end
-
- vif.rready <= 0;
-
- endtask
-
-
-
-
- //////////////////////////////////////// INCR address ////////////////
- task read_address_incr_burst();
- vif.arlen <=txn.arlen;
- for(int i=0; i<(arlen +1);i++)
- begin
- vif.araddr<=txn.araddr;
- vif.arid <= txn.arid;
- vif.arvalid<= 1;
- pkt.araddr<= txn.araddr +(2**vif.arsize);
- wait(vif.arready);
- vif.arvalid<=0;
-
- end
- read_data();
- endtask
-
- virtual task read_data();
- vif.rready<=0;
- for(int i=0;i<=txn.arlen+1;i++) begin
- $display("read data started");
- vif.rdata<=txn.rdata[i];
- vif.rid<=txn.rid;
- vif.rvalid<=1'b1;
- if(i=txn.arlen+1) vif.rlast=1;
- while (rready=0)
- begin @(posedge vif.clk)
- if (vif.rready==1)
- txn.rready=1;
- end
- vif.rlast=0;
- vif.rvalid=0;
- $display("read data completed");
- end
- vif.rready <= 1;
-
- foreach (vif.rdata[i])
- begin
- if (vif.arid == vif.rid)
- begin
- case (vif.rresp)
-
- 2'b00 : s = "Transaction OKAY";
- 2'b01 : s = "Transaction FAILED";
- 2'b10 : s = "SLAVE ERROR";
- 2'b11 : s = "DEEOCDE ERROR";
-
- endcase
-
- `uvm_info("master_driver",$sformatf("\n\t %s response for the recieved data \n",s),UVM_MEDIUM)
-
- end
- end
-
- vif.rready <= 0;
-
- endtask
- ///////////////read address fixed burst////////////////////////
- task read_address_fixed_burst ();
- begin
- vif.arlen <= txn.arlen;
- vif.arid <= txn.arid;
- vif.araddr <= txn.araddr;
- vif.arvalid<= 1;
- wait(vif.arready);
- vif.arvalid<=0;
- end
- rd_dt_fixed_burst();
-
- endtask
-
-
-
- task rd_dt_fixed_burst ();
- vif.rready<=0;
- for(int i=0;i<=txn.arlen+1;i++) begin
- $display("read data started");
- vif.rdata<=txn.rdata[i];
- vif.rid<=txn.rid;
- vif.rvalid<=1'b1;
- if(i=txn.arlen+1) vif.rlast=1;
- while (rready=0)
- begin @(posedge vif.clk)
- if (vif.rready==1)
- txn.rready=1;
- end
- vif.rlast=0;
- vif.rvalid=0;
- $display("read data completed");
- end
- foreach (vif.rdata[i])
- begin
- if (vif.arid == vif.rid)
- begin
- case (vif.rresp)
-
- 2'b00 : s = "Transaction OKAY";
- 2'b01 : s = "Transaction FAILED";
- 2'b10 : s = "SLAVE ERROR";
- 2'b11 : s = "DEEOCDE ERROR";
-
- endcase
-
- `uvm_info("master_driver",$sformatf("\n\t %s response for recieved data \n",s),UVM_MEDIUM)
-
- end
- end
-
- vif.rready <= 0;
-
- endtask
-
- if(txn.resest==1) begin
- reset();
- end
- //Write operation support
- else if(txn.wr_rd==1) begin
- `uvm_info(get_type_name()," write packet is received in driver ",UVM_MEDIUM)
- begin
- write_address();
- end
-
- //read operation support
- else if( txn.wr_rd==0)
- begin
- read_address();
- end
- seq_item_port.item_done();
- end
- endtask
- endclass
-
|