init
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
/****************************************************************************
|
||||
+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+ +-+-+-+-+-+-+-+-+
|
||||
|F|u|n|c|t|i|o|n|a|l| |V|e|r|i|f|i|c|a|t|i|o|n| |o|f| |H|a|r|d|w|a|r|e|
|
||||
+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+ +-+-+-+-+-+-+-+-+
|
||||
|
||||
FILE apb_slave_agent.sv
|
||||
|
||||
DESCRIPTION slave agent
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
`ifndef APB_SLAVE_AGENT_SV
|
||||
`define APB_SLAVE_AGENT_SV
|
||||
|
||||
/**
|
||||
* Class: apb_slave_agent
|
||||
*/
|
||||
class apb_slave_agent extends uvm_agent;
|
||||
|
||||
// configuration object
|
||||
apb_slave_config cfg;
|
||||
|
||||
// components
|
||||
apb_slave_driver drv;
|
||||
apb_slave_sequencer seqr;
|
||||
apb_slave_monitor mon;
|
||||
|
||||
// UVM factory registration
|
||||
`uvm_component_utils_begin(apb_slave_agent)
|
||||
`uvm_field_object(cfg, UVM_DEFAULT | UVM_REFERENCE)
|
||||
`uvm_component_utils_end
|
||||
|
||||
// new - constructor
|
||||
function new(string name = "apb_slave_agent", uvm_component parent = null);
|
||||
super.new(name, parent);
|
||||
endfunction : new
|
||||
|
||||
// UVM build_phase
|
||||
function void build_phase(uvm_phase phase);
|
||||
super.build_phase(phase);
|
||||
|
||||
// get configuration object from db
|
||||
if(!uvm_config_db#(apb_slave_config)::get(this, "", "apb_slave_config", cfg))
|
||||
`uvm_fatal("NOCONFIG",{"Config object must be set for: ",get_full_name(),".cfg"})
|
||||
|
||||
// create driver and sequencer if agent is active
|
||||
if(cfg.is_active == UVM_ACTIVE) begin
|
||||
seqr = apb_slave_sequencer::type_id::create("seqr", this);
|
||||
drv = apb_slave_driver::type_id::create("drv", this);
|
||||
end
|
||||
// always create monitor
|
||||
mon = apb_slave_monitor::type_id::create("mon", this);
|
||||
endfunction : build_phase
|
||||
|
||||
// UVM connect_phase
|
||||
function void connect_phase(uvm_phase phase);
|
||||
super.connect_phase(phase);
|
||||
// connect driver and sequencer if agent is active
|
||||
if(cfg.is_active == UVM_ACTIVE) begin
|
||||
drv.seq_item_port.connect(seqr.seq_item_export);
|
||||
end
|
||||
endfunction : connect_phase
|
||||
|
||||
endclass : apb_slave_agent
|
||||
|
||||
`endif
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/****************************************************************************
|
||||
+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+ +-+-+-+-+-+-+-+-+
|
||||
|F|u|n|c|t|i|o|n|a|l| |V|e|r|i|f|i|c|a|t|i|o|n| |o|f| |H|a|r|d|w|a|r|e|
|
||||
+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+ +-+-+-+-+-+-+-+-+
|
||||
|
||||
FILE apb_slave_config.sv
|
||||
|
||||
DESCRIPTION slave configuration object
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
`ifndef APB_SLAVE_CONFIG_SV
|
||||
`define APB_SLAVE_CONFIG_SV
|
||||
|
||||
/**
|
||||
* Class: apb_slave_config
|
||||
*/
|
||||
class apb_slave_config extends uvm_object;
|
||||
|
||||
// is agent active or passive
|
||||
uvm_active_passive_enum is_active = UVM_ACTIVE;
|
||||
// checks and coverage control
|
||||
bit has_checks = 1;
|
||||
bit has_coverage = 1;
|
||||
// address range
|
||||
rand bit [ADDR_WIDTH - 1 : 0] start_address;
|
||||
rand bit [ADDR_WIDTH - 1 : 0] end_address;
|
||||
// slave index
|
||||
rand int unsigned psel_index;
|
||||
// create agent or just use cfg for address and psel purposes
|
||||
bit create_agent = 1;
|
||||
|
||||
// constraints
|
||||
constraint addr_cst { start_address <= end_address; }
|
||||
constraint psel_cst { psel_index inside {[0 : SLV_NUM]};} // max 15 slaves
|
||||
|
||||
// UVM factory registration
|
||||
`uvm_object_utils_begin(apb_slave_config)
|
||||
`uvm_field_enum(uvm_active_passive_enum, is_active, UVM_DEFAULT)
|
||||
`uvm_field_int(has_checks, UVM_DEFAULT)
|
||||
`uvm_field_int(has_coverage, UVM_DEFAULT)
|
||||
`uvm_field_int(start_address, UVM_DEFAULT)
|
||||
`uvm_field_int(end_address, UVM_DEFAULT)
|
||||
`uvm_field_int(psel_index, UVM_DEFAULT)
|
||||
`uvm_field_int(create_agent, UVM_DEFAULT)
|
||||
`uvm_object_utils_end
|
||||
|
||||
// new - constructor
|
||||
function new(string name = "apb_slave_config");
|
||||
super.new(name);
|
||||
endfunction : new
|
||||
|
||||
// checks to see if an address is in the configured range
|
||||
function bit check_address_range(bit [ADDR_WIDTH - 1 : 0] addr);
|
||||
return (!((start_address > addr) || (end_address < addr)));
|
||||
endfunction : check_address_range
|
||||
|
||||
// checks to see if current psel index is for this slave
|
||||
function bit check_psel_index(logic [SLV_NUM - 1 : 0] psel);
|
||||
for (int i = 0; i < SLV_NUM; i++) begin
|
||||
if((psel[i] == 1) && (psel_index == (i + 1)))
|
||||
return 1;
|
||||
end
|
||||
return 0;
|
||||
endfunction : check_psel_index
|
||||
|
||||
endclass : apb_slave_config
|
||||
|
||||
`endif
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
/****************************************************************************
|
||||
+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+ +-+-+-+-+-+-+-+-+
|
||||
|F|u|n|c|t|i|o|n|a|l| |V|e|r|i|f|i|c|a|t|i|o|n| |o|f| |H|a|r|d|w|a|r|e|
|
||||
+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+ +-+-+-+-+-+-+-+-+
|
||||
|
||||
FILE apb_slave_driver.sv
|
||||
|
||||
DESCRIPTION drives slave response
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
`ifndef APB_SLAVE_DRIVER_SV
|
||||
`define APB_SLAVE_DRIVER_SV
|
||||
|
||||
/**
|
||||
* Class: apb_slave_driver
|
||||
*/
|
||||
class apb_slave_driver extends uvm_driver #(apb_transaction, apb_transaction);
|
||||
|
||||
// apb virtual interface
|
||||
virtual apb_if vif;
|
||||
|
||||
// configuration
|
||||
apb_slave_config cfg;
|
||||
|
||||
// UVM factory registration
|
||||
`uvm_component_utils_begin(apb_slave_driver)
|
||||
`uvm_field_object(cfg, UVM_DEFAULT | UVM_REFERENCE)
|
||||
`uvm_component_utils_end
|
||||
|
||||
// new - constructor
|
||||
function new(string name = "apb_slave_driver", uvm_component parent = null);
|
||||
super.new(name, parent);
|
||||
endfunction : new
|
||||
|
||||
// UVM build_phase
|
||||
function void build_phase(uvm_phase phase);
|
||||
super.build_phase(phase);
|
||||
// get configuration object from db
|
||||
if(!uvm_config_db#(apb_slave_config)::get(this, "", "apb_slave_config", cfg))
|
||||
`uvm_fatal("NOCONFIG",{"Config object must be set for: ",get_full_name(),".cfg"})
|
||||
endfunction: build_phase
|
||||
|
||||
// UVM connect_phase
|
||||
function void connect_phase(uvm_phase phase);
|
||||
super.connect_phase(phase);
|
||||
// get interface from db
|
||||
if(!uvm_config_db#(virtual apb_if)::get(this, "", "apb_if", vif))
|
||||
`uvm_fatal("NOVIF",{"virtual interface must be set for: ",get_full_name(),".vif"})
|
||||
endfunction : connect_phase
|
||||
|
||||
// additional class methods
|
||||
extern virtual task run_phase(uvm_phase phase);
|
||||
extern virtual task get_and_drive();
|
||||
extern virtual task reset();
|
||||
extern virtual task drive_tr (apb_transaction tr);
|
||||
|
||||
endclass : apb_slave_driver
|
||||
|
||||
// UVM run_phase
|
||||
task apb_slave_driver::run_phase(uvm_phase phase);
|
||||
reset(); // init.
|
||||
forever begin
|
||||
fork
|
||||
get_and_drive(); // thread killed at reset
|
||||
@(negedge vif.presetn); // reset is active low
|
||||
join_any
|
||||
disable fork;
|
||||
|
||||
reset();
|
||||
end
|
||||
endtask : run_phase
|
||||
|
||||
// reset signals
|
||||
task apb_slave_driver::reset();
|
||||
`uvm_info(get_type_name(), "Reset observed", UVM_MEDIUM)
|
||||
vif.prdata <= {WDATA_WIDTH {1'bZ}};
|
||||
vif.pready <= 1'b0;
|
||||
vif.pslverr <= 1'b0;
|
||||
@(posedge vif.presetn); // reset dropped
|
||||
endtask : reset
|
||||
|
||||
// sequencer/driver handshake
|
||||
task apb_slave_driver::get_and_drive();
|
||||
forever begin
|
||||
seq_item_port.get_next_item(req);
|
||||
drive_tr(req);
|
||||
seq_item_port.item_done();
|
||||
end
|
||||
endtask : get_and_drive
|
||||
|
||||
// drive transaction
|
||||
task apb_slave_driver::drive_tr (apb_transaction tr);
|
||||
|
||||
// wait for the master to initiate the transaction
|
||||
@(posedge vif.pclk iff (vif.penable && cfg.check_psel_index(vif.psel)));
|
||||
|
||||
tr.dir = apb_direction_enum'(vif.pwrite);
|
||||
|
||||
// delay
|
||||
if (tr.delay > 0) begin
|
||||
repeat(tr.delay) @(posedge vif.pclk);
|
||||
end
|
||||
// respond
|
||||
vif.pslverr <= tr.error;
|
||||
vif.pready <= 1'b1;
|
||||
if (tr.dir == APB_READ)
|
||||
vif.prdata <= tr.rdata;
|
||||
@(posedge vif.pclk);
|
||||
vif.prdata <= {WDATA_WIDTH {1'bZ}};
|
||||
vif.pready <= 1'b0;
|
||||
|
||||
`uvm_info(get_type_name(), $sformatf("APB Finished Driving tr \n%s", tr.sprint()), UVM_HIGH)
|
||||
endtask : drive_tr
|
||||
|
||||
`endif
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
/****************************************************************************
|
||||
+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+ +-+-+-+-+-+-+-+-+
|
||||
|F|u|n|c|t|i|o|n|a|l| |V|e|r|i|f|i|c|a|t|i|o|n| |o|f| |H|a|r|d|w|a|r|e|
|
||||
+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+ +-+-+-+-+-+-+-+-+
|
||||
|
||||
FILE apb_slave_monitor.sv
|
||||
|
||||
DESCRIPTION monitors transactions for slave
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
`ifndef APB_SLAVE_MONITOR_SV
|
||||
`define APB_SLAVE_MONITOR_SV
|
||||
|
||||
/**
|
||||
* Class: apb_slave_monitor
|
||||
*/
|
||||
class apb_slave_monitor extends uvm_monitor;
|
||||
|
||||
// apb virtual interface
|
||||
virtual apb_if vif;
|
||||
|
||||
// configuration
|
||||
apb_slave_config cfg;
|
||||
|
||||
// TLM - from monitor to other components
|
||||
uvm_analysis_port #(apb_transaction) item_collected_port;
|
||||
|
||||
// keep track of number of transactions
|
||||
int unsigned num_transactions = 0;
|
||||
|
||||
// current transaction
|
||||
apb_transaction tr_collected;
|
||||
|
||||
// UVM factory registration
|
||||
`uvm_component_utils_begin(apb_slave_monitor)
|
||||
`uvm_field_object(cfg, UVM_DEFAULT | UVM_REFERENCE)
|
||||
`uvm_component_utils_end
|
||||
|
||||
// coverage
|
||||
covergroup cg_apb_slave;
|
||||
// cover direction - read or write
|
||||
cp_direction : coverpoint tr_collected.dir {
|
||||
bins write = {APB_WRITE};
|
||||
bins read = {APB_READ};
|
||||
}
|
||||
// cover delay - zero or more
|
||||
cp_delay : coverpoint tr_collected.delay {
|
||||
bins zero = {0};
|
||||
bins other = default;
|
||||
}
|
||||
// TODO : add others
|
||||
endgroup : cg_apb_slave;
|
||||
|
||||
// new - constructor
|
||||
function new(string name = "apb_slave_monitor", uvm_component parent = null);
|
||||
super.new(name, parent);
|
||||
item_collected_port = new("item_collected_port", this);
|
||||
cg_apb_slave = new();
|
||||
endfunction : new
|
||||
|
||||
// UVM build_phase
|
||||
function void build_phase(uvm_phase phase);
|
||||
super.build_phase(phase);
|
||||
// get configuration object from db
|
||||
if(!uvm_config_db#(apb_slave_config)::get(this, "", "apb_slave_config", cfg))
|
||||
`uvm_fatal("NOCONFIG",{"Config object must be set for: ",get_full_name(),".cfg"})
|
||||
endfunction: build_phase
|
||||
|
||||
// UVM connect_phase
|
||||
function void connect_phase(uvm_phase phase);
|
||||
super.connect_phase(phase);
|
||||
// get interface from db
|
||||
if(!uvm_config_db#(virtual apb_if)::get(this, "", "apb_if", vif))
|
||||
`uvm_fatal("NOVIF",{"virtual interface must be set for: ",get_full_name(),".vif"})
|
||||
endfunction : connect_phase
|
||||
|
||||
// additional class methods
|
||||
extern virtual task run_phase(uvm_phase phase);
|
||||
extern virtual task collect_transactions();
|
||||
extern virtual function void report_phase(uvm_phase phase);
|
||||
|
||||
endclass : apb_slave_monitor
|
||||
|
||||
// UVM run_phase
|
||||
task apb_slave_monitor::run_phase(uvm_phase phase);
|
||||
forever begin
|
||||
@(posedge vif.presetn); // reset dropped
|
||||
`uvm_info(get_type_name(), "Reset dropped", UVM_MEDIUM)
|
||||
|
||||
fork
|
||||
collect_transactions(); // thread killed at reset
|
||||
@(negedge vif.presetn); // reset is active low
|
||||
join_any
|
||||
disable fork;
|
||||
end
|
||||
endtask : run_phase
|
||||
|
||||
// monitor apb interface and collect transactions
|
||||
task apb_slave_monitor::collect_transactions();
|
||||
forever begin
|
||||
tr_collected = apb_transaction::type_id::create("tr_collected");
|
||||
|
||||
// collect transactions only for this slave
|
||||
@(posedge vif.pclk iff (cfg.check_psel_index(vif.psel)));
|
||||
tr_collected.addr = vif.paddr;
|
||||
tr_collected.dir = apb_direction_enum'(vif.pwrite);
|
||||
if(tr_collected.dir == APB_WRITE)
|
||||
tr_collected.wdata = vif.pwdata;
|
||||
|
||||
@(posedge vif.pclk); // enable
|
||||
@(posedge vif.pclk); // ready
|
||||
// wait for ready
|
||||
while (vif.pready !== 1'b1) begin
|
||||
@(posedge vif.pclk);
|
||||
tr_collected.delay++;
|
||||
end
|
||||
if(tr_collected.dir == APB_READ) begin
|
||||
tr_collected.rdata = vif.prdata;
|
||||
tr_collected.error = vif.pslverr;
|
||||
end
|
||||
|
||||
item_collected_port.write(tr_collected); // TLM
|
||||
// collect coverage if enabled
|
||||
if(cfg.has_coverage == 1) begin
|
||||
cg_apb_slave.sample();
|
||||
end
|
||||
`uvm_info(get_type_name(), $sformatf("Tr collected :\n%s", tr_collected.sprint()), UVM_MEDIUM)
|
||||
num_transactions++;
|
||||
end // forever
|
||||
endtask : collect_transactions
|
||||
|
||||
// UVM report_phase
|
||||
function void apb_slave_monitor::report_phase(uvm_phase phase);
|
||||
// final report
|
||||
`uvm_info(get_type_name(), $sformatf("Report: APB monitor collected %0d transfers", num_transactions), UVM_LOW);
|
||||
endfunction : report_phase
|
||||
|
||||
`endif
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/****************************************************************************
|
||||
+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+ +-+-+-+-+-+-+-+-+
|
||||
|F|u|n|c|t|i|o|n|a|l| |V|e|r|i|f|i|c|a|t|i|o|n| |o|f| |H|a|r|d|w|a|r|e|
|
||||
+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+ +-+-+-+-+-+-+-+-+
|
||||
|
||||
FILE apb_slave_sequencer.sv
|
||||
|
||||
DESCRIPTION
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
`ifndef APB_SLAVE_SEQUENCER_SV
|
||||
`define APB_SLAVE_SEQUENCER_SV
|
||||
|
||||
/**
|
||||
* Class: apb_slave_sequencer
|
||||
*/
|
||||
class apb_slave_sequencer extends uvm_sequencer #(apb_transaction, apb_transaction);
|
||||
|
||||
// UVM factory registration
|
||||
`uvm_component_utils (apb_slave_sequencer)
|
||||
|
||||
// new - constructor
|
||||
function new(string name = "apb_slave_sequencer", uvm_component parent = null);
|
||||
super.new(name, parent);
|
||||
endfunction : new
|
||||
|
||||
// Note: equivalent to
|
||||
// typedef uvm_sequencer#(apb_transaction, apb_transaction) apb_slave_sequencer;
|
||||
|
||||
endclass : apb_slave_sequencer
|
||||
|
||||
`endif
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/****************************************************************************
|
||||
+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+ +-+-+-+-+-+-+-+-+
|
||||
|F|u|n|c|t|i|o|n|a|l| |V|e|r|i|f|i|c|a|t|i|o|n| |o|f| |H|a|r|d|w|a|r|e|
|
||||
+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+ +-+-+-+-+-+-+-+-+
|
||||
|
||||
FILE apb_slave_base_seq.sv
|
||||
|
||||
DESCRIPTION base sequence to be extended by other sequences
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
`ifndef APB_SLAVE_BASE_SEQ_SV
|
||||
`define APB_SLAVE_BASE_SEQ_SV
|
||||
|
||||
/**
|
||||
* Class: apb_slave_base_seq
|
||||
*/
|
||||
class apb_slave_base_seq extends uvm_sequence #(apb_transaction, apb_transaction);
|
||||
|
||||
// UVM factory registration
|
||||
`uvm_object_utils(apb_slave_base_seq)
|
||||
|
||||
// new - constructor
|
||||
function new(string name = "apb_slave_base_seq");
|
||||
super.new(name);
|
||||
endfunction : new
|
||||
|
||||
endclass : apb_slave_base_seq
|
||||
|
||||
`endif
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/****************************************************************************
|
||||
+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+ +-+-+-+-+-+-+-+-+
|
||||
|F|u|n|c|t|i|o|n|a|l| |V|e|r|i|f|i|c|a|t|i|o|n| |o|f| |H|a|r|d|w|a|r|e|
|
||||
+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+ +-+-+-+-+-+-+-+-+
|
||||
|
||||
FILE apb_slave_seq_lib.sv
|
||||
|
||||
DESCRIPTION sequence includes
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
`ifndef APB_SLAVE_SEQ_LIB_SV
|
||||
`define APB_SLAVE_SEQ_LIB_SV
|
||||
|
||||
`include "slave/sequences/apb_slave_base_seq.sv"
|
||||
`include "slave/sequences/apb_slave_simple_seq.sv"
|
||||
|
||||
`endif
|
||||
@@ -0,0 +1,38 @@
|
||||
/****************************************************************************
|
||||
+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+ +-+-+-+-+-+-+-+-+
|
||||
|F|u|n|c|t|i|o|n|a|l| |V|e|r|i|f|i|c|a|t|i|o|n| |o|f| |H|a|r|d|w|a|r|e|
|
||||
+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+ +-+-+-+-+-+-+-+-+
|
||||
|
||||
FILE apb_slave_simple_seq.sv
|
||||
|
||||
DESCRIPTION simple sequence; always respond with random data
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
`ifndef APB_SLAVE_SIMPLE_SEQ_SV
|
||||
`define APB_SLAVE_SIMPLE_SEQ_SV
|
||||
|
||||
/**
|
||||
* Class: apb_slave_simple_seq
|
||||
*/
|
||||
class apb_slave_simple_seq extends apb_slave_base_seq;
|
||||
|
||||
// UVM factory registration
|
||||
`uvm_object_utils(apb_slave_simple_seq)
|
||||
|
||||
// new - constructor
|
||||
function new(string name = "apb_slave_simple_seq");
|
||||
super.new(name);
|
||||
endfunction : new
|
||||
|
||||
// sequence generation logic in body
|
||||
virtual task body();
|
||||
forever begin
|
||||
`uvm_do(req)
|
||||
end
|
||||
endtask : body
|
||||
|
||||
endclass : apb_slave_simple_seq
|
||||
|
||||
`endif
|
||||
|
||||
Reference in New Issue
Block a user