Amba Apb Assignment
Amba Apb Assignment
Amba Apb Assignment
1. DUT OF SLAVE :
`define ADDR_WIDTH 32
`define DATA_WIDTH 32
`define SEL 4
`define STR 4
module apb_slave
( input clk,
input rst_n,
input [`ADDR_WIDTH-1:0] paddr,
input pwrite,
input penable,
input [`DATA_WIDTH-1:0] pwdata,
input [`SEL-1:0] psel,
input [`STR-1:0] pstrobe,
else
begin
case (apb_st)
SETUP : begin
prdata <= 0;// clear the prdata
if (psel[0] && !penable)
begin
if (pwrite)
begin
pwdata_temp<=pwdata;
if(pstrobe[0]==0)
pwdata_temp[7:0]<=8'b0;
if(pstrobe[1]==0)
pwdata_temp[15:8]<=8'b0;
if(pstrobe[2]==0)
pwdata_temp[23:16]<=8'b0;
if(pstrobe[3]==0)
pwdata_temp[31:24]<=8'b0;
W_ENABLE : begin
if (psel[0] && penable && pwrite) // write pwdata to memory
begin
mem[paddr] <=
{pwdata_temp[31:24],pwdata_temp[23:16],pwdata_temp[15:8],pwdata_temp[7:0]};
end
apb_st <= SETUP;
end
R_ENABLE : begin
if (psel[0] && penable && !pwrite)
begin
prdata <= mem[paddr];
end
apb_st <= SETUP; // return to SETUP
end
endcase
end
end
endmodule
2. TRANSACTION CLASS :
//TRANSACTION CLASS
//master_side.......
randc bit [`ADDR_WIDTH-1:0] PADDR;
randc bit [`DATA_WIDTH-1:0] PWDATA;
rand bit [`SEL-1:0] PSEL;
rand bit PWRITE;
rand bit PENABLE;
rand bit [`STR-1:0] PSTROBE;
//slave_side.....
bit PREADY;
bit [`DATA_WIDTH:0] PRDATA;
endclass
//................end of packet......................................
3. INTERFACE :
//INTERFACE
`define ADDR_WIDTH 32
`define DATA_WIDTH 32
`define SEL 4
`define STR 4
//master_side.......
logic [`ADDR_WIDTH-1:0] PADDR;
logic [`DATA_WIDTH-1:0] PWDATA;
logic [`SEL-1:0] PSEL;
logic PWRITE;
logic PENABLE;
logic [`STR-1:0] PSTROBE;
//slave_side.....
logic [`DATA_WIDTH-1:0] PRDATA;
logic PREADY;
endinterface
4. PASSIVE AGENT:
endclass
5. ACTIVE AGENT:
`uvm_component_utils(apb_bridge_agentact)
apb_bridge_sequencer apb_seq;
apb_bridge_dri apb_dri;
apb_bridge_moni_mst apb_moni_mst;
endclass
6. DRIVER:
`uvm_component_utils(apb_bridge_dri)
apb_config con;
virtual apb_interface vf;
int count=`PACKET;
forever
begin
seq_item_port.get_next_item(req);
apb_drive_logic();
seq_item_port.item_done();
req.print();
endclass
task apb_bridge_dri::apb_drive_logic();
begin
@(posedge vf.clk);
// IF THE SELECT AND ENABLE ARE LOW THEN, THERE WILL BE NO
TRANSFER
if(req.PSEL==4'b0 && req.PENABLE==1'b0)
begin
no_transfer();
end
//WRITE MODE
else if(req.PSEL!=4'b0 && req.PENABLE==1'b0 &&
req.PWRITE==1'b1)
begin
//req.print();
stimulus();
vf.PRDATA <=32'b0;
vf.PWDATA <=req.PWDATA;
vf.PSTROBE<=req.PSTROBE;
#1 @(posedge vf.clk);
vf.PENABLE <=1'b1;
wait(vf.PREADY==1'b1);
end
//READ MODE
else if(req.PSEL==1'b1 && req.PENABLE==1'b0 &&
req.PWRITE==1'b0)
begin
// req.print();
stimulus();
vf.PWDATA <=32'b0;
#1 @(posedge vf.clk);
vf.PENABLE <=1'b1;
wait(vf.PREADY==1'b1);
wait(vf.PRDATA);
end
end
endtask
task apb_bridge_dri::no_transfer();
begin
vf.PADDR <=0;
vf.PWDATA <=0;
vf.PSEL <=0;
vf.PWRITE <=0;
vf.PENABLE<=0;
vf.PSTROBE<=0;
end
endtask
task apb_bridge_dri::stimulus();
begin
vf.PENABLE<=req.PENABLE;
vf.PADDR <=req.PADDR;
vf.PSEL <=req.PSEL;
vf.PWRITE <=req.PWRITE;
end
endtask
//............end of driver................................
7. MONITOR READ:
`uvm_component_utils(apb_bridge_moni_read)
uvm_analysis_port #(apb_bridge_dataitem) item_collect_readport;
8. MONITOR MASTER:
`uvm_component_utils(apb_bridge_moni_mst)
uvm_analysis_port #(apb_bridge_dataitem) item_collect_port;
endclass
task apb_bridge_moni_mst::apb_moni_logic();
begin
@(posedge vf.clk);
if(vf.PSEL==4'b0 && vf.PENABLE==1'b0)
begin
get_stimulus();
end
wait(vf.PREADY==1'b1);
get_stimulus();
end
end
endtask
task apb_bridge_moni_mst::get_stimulus();
begin
monitor_tr.PENABLE=vf.PENABLE;
monitor_tr.PADDR =vf.PADDR;
monitor_tr.PSEL =vf.PSEL;
monitor_tr.PWRITE =vf.PWRITE;
monitor_tr.PWDATA =vf.PWDATA;
monitor_tr.PSTROBE=vf.PSTROBE;
end
endtask
//....................end of monitor......................
9. SEQUENCE:
// sanitory test case one write and one read ..next 256 write and read
`uvm_object_utils(apb_bridge_seq)
`uvm_object_utils(apb_bridge_seq1)
repeat(`PACKET)
begin
start_item(req);
assert(req.randomize());
finish_item(req);
end
endtask
endclass
`uvm_component_utils(apb_bridge_sequencer)
endclass
//...............end of sequencer.....................
`uvm_component_utils(apb_subscriber)
apb_bridge_dataitem trc;
covergroup apb_coverage;
endgroup
12. SCOREBORD:
`uvm_analysis_imp_decl(_WRT)
`uvm_analysis_imp_decl(_RED)
`uvm_component_utils(apb_bridge_scoreboard)
uvm_analysis_imp_WRT #(apb_bridge_dataitem,apb_bridge_scoreboard)
apb_write_export;
uvm_analysis_imp_RED #(apb_bridge_dataitem,apb_bridge_scoreboard)
apb_read_export;
end
endfunction
endclass
13. ENVIRONMENT:
`uvm_component_utils(apb_top_environ)
apb_bridge_agentact active_agent;
apb_bridge_scoreboard score_board;
apb_bridge_agentpass pasiv_agent;
apb_subscriber subscribe;
active_agent.apb_moni_mst.item_collect_port.connect(score_board.apb_write_export);
pasiv_agent.apb_read.item_collect_readport.connect(score_board.apb_read_export);
active_agent.apb_moni_mst.item_collect_port.connect(subscribe.analysis_export);
endfunction
endclass
14. TEST:
`uvm_component_utils(base_test)
apb_top_environ env;
apb_config con_t;
endclass
15. CONFIG :
`uvm_object_utils(apb_config)
endclass
16. TOP :
//top module
`include "uvm_macros.svh"
import uvm_pkg::*;
`include "define.sv"
`include "apb_interface.sv"
`include "apb_slave.sv"
`include "apb_config.sv"
`include "apb_bridge_dataitem.sv"
`include "apb_bridge_sequencer.sv"
`include "apb_bridge_dri.sv"
`include "apb_bridge_moni_mst.sv"
`include "apb_bridge_moni_read.sv"
`include "apb_bridge_agentact.sv"
`include "apb_bridge_agentpass.sv"
`include "apb_bridge_scoreboard.sv"
`include "apb_subscriber.sv"
`include "apb_top_environ.sv"
`include "apb_bridge_seq.sv"
`include "base_test.sv"
module apb_top;
bit clock,reset;
apb_interface intf(.clk(clock),.reset(reset));
apb_slave
dt(.clk(clock),.rst_n(reset),.paddr(intf.PADDR),.pwrite(intf.PWRITE),.psel(intf.PSEL),.p
enable(intf.PENABLE),.pwdata(intf.PWDATA),.prdata(intf.PRDATA),.pready(intf.PRE
ADY));
initial
begin
#5 reset=1'b1;
end
initial
begin
uvm_config_db #(virtual apb_interface)::set(null,"*","vif",intf);
run_test("base_test");
end
endmodule
17. COVERAGE REPORT :