|
楼主 |
发表于 2011-10-10 18:14:02
|
显示全部楼层
driver是这样定义的:
`ifndef _MPC_DRIVER_SV_
`define _MPC_DRIVER_SV_
class mpc_driver extends uvm_driver #(mpc_transaction) ;
`uvm_component_utils(mpc_driver)
protected virtual mpc_if m_mpc_if ;
//new -- constructor
function new(string name = "mpc_driver_inst", uvm_component parent) ;
super.new(name, parent) ;
`uvm_info("dirver", "Called mpc_driver::new", UVM_NONE) ;
endfunction : new
virtual function void build_phase(uvm_phase phase) ;
super.build_phase(phase) ;
if(!uvm_config_db#(virtual mpc_if)::get(this, "", "m_mpc_if", m_mpc_if))
`uvm_fatal("NOVIF",{"virtual interface must be set for: ",get_full_name(),".m_mpc_if"});
endfunction : build_phase
//run phase
virtual task run_phase(uvm_phase phase) ;
get_and_drive() ;
`uvm_info("dirver", "Called mpc_driver::run_phase", UVM_NONE) ;
endtask : run_phase
//get and drive
virtual protected task get_and_drive() ;
forever begin
@(posedge m_mpc_if.clk);
`uvm_info("dirver", "clock is ok!", UVM_NONE) ;
seq_item_port.get_next_item(req);
$cast(rsp, req.clone());
rsp.set_id_info(req);
drive_transaction(rsp);
seq_item_port.item_done();
seq_item_port.put_response(rsp);
end
endtask : get_and_drive
//drive transaction
virtual protected task drive_transaction(mpc_transaction trans) ;
`uvm_info("dirver", "Called mpc_driver::drive_transaction", UVM_NONE) ;
case(trans.read_write)
NOP : nop() ;
READ : read_word(trans.addr, trans.data) ;
WRITE : write_word(trans.addr, trans.data) ;
endcase
@(posedge m_mpc_if.clk) ;
nop() ;
endtask : drive_transaction
// bus idle
virtual protected task nop() ;
m_mpc_if.csn <= 'b1 ;
m_mpc_if.wr <= 'b0 ;
m_mpc_if.rd <= 'b0 ;
m_mpc_if.addr <= 'bz ;
m_mpc_if.din <= 'bz ;
m_mpc_if.dout <= 'bz ;
endtask : nop
// read one word
virtual protected task read_word(bit [31:0] addr, output bit [31:0] data) ;
m_mpc_if.csn <= 'b0 ;
m_mpc_if.wr <= 'b0 ;
m_mpc_if.rd <= 'b1 ;
m_mpc_if.addr <= addr ;
@(posedge m_mpc_if.clk iff m_mpc_if.tan === 'b1);
//data <= m_mpc_if.dout ;
endtask : read_word
// write one word
virtual protected task write_word(bit [31:0] addr, bit [31:0] data) ;
m_mpc_if.csn <= 'b0 ;
m_mpc_if.wr <= 'b1 ;
m_mpc_if.rd <= 'b0 ;
m_mpc_if.addr <= addr ;
m_mpc_if.din <= data ;
@(posedge m_mpc_if.clk iff m_mpc_if.tan === 'b1);
endtask : write_word
endclass : mpc_driver
`endif |
|