UVM TestBench Example code - verificationguide.com - EDA Playground
Warning! This exercise has been opened in another tab; autosave has been disabled. Close this tab or refresh to reactivate.

 Languages & Libraries

 Tools & Simulators

 Examples

205


68
 
1
//-------------------------------------------------------------------------
2
//              www.verificationguide.com   testbench.sv
3
//-------------------------------------------------------------------------
4
//---------------------------------------------------------------
5
//including interfcae and testcase files
6
`include "mem_interface.sv"
7
`include "mem_test.sv"
8
`include "mem_wr_rd_test.sv"
9
//---------------------------------------------------------------
10
11
module tbench_top;
12
13
  //---------------------------------------
14
  //clock and reset signal declaration
15
  //---------------------------------------
16
  bit clk;
17
  bit reset;
18
  
19
  //---------------------------------------
20
  //clock generation
21
  //---------------------------------------
22
  always #5 clk = ~clk;
23
  
24
  //---------------------------------------
25
  //reset Generation
26
  //---------------------------------------
27
  initial begin
28
    reset = 1;
29
    #5 reset =0;
30
  end
31
  
32
  //---------------------------------------
33
  //interface instance
34
  //---------------------------------------
35
  mem_if intf(clk,reset);
36
  
37
  //---------------------------------------
38
  //DUT instance
39
  //---------------------------------------
40
  memory DUT (
41
    .clk(intf.clk),
42
    .reset(intf.reset),
43
    .addr(intf.addr),
44
    .wr_en(intf.wr_en),
45
    .rd_en(intf.rd_en),
46
    .wdata(intf.wdata),
47
    .rdata(intf.rdata)
48
   );
49
  
50
  //---------------------------------------
51
  //passing the interface handle to lower heirarchy using set method 
52
  //and enabling the wave dump
53
  //---------------------------------------
54
  initial begin 
55
    uvm_config_db#(virtual mem_if)::set(uvm_root::get(),"*","vif",intf);
56
    //enable wave dump
57
    $dumpfile("dump.vcd"); 
58
    $dumpvars;
59
  end
60
  
61
  //---------------------------------------
62
  //calling test
63
  //---------------------------------------
64
  initial begin 
65
    run_test();
66
  end
67
  
68
endmodule
51
 
1
//-------------------------------------------------------------------------
2
//              Memory Model RTL - www.verificationguide.com
3
//-------------------------------------------------------------------------
4
/*
5
              -----------------
6
              |               |
7
    addr ---->|               |
8
              |               |------> rdata
9
              | Memory Model  |
10
   wdata ---->|               |
11
              |               | 
12
              -----------------
13
                   ^     ^
14
                   |     |
15
                wr_en  rd_en
16
17
-------------------------------------------------------------------------- */
18
module memory
19
  #( parameter ADDR_WIDTH = 2,
20
     parameter DATA_WIDTH = 8 ) (
21
    input clk,
22
    input reset,
23
    
24
    //control signals
25
    input [ADDR_WIDTH-1:0]  addr,
26
    input                   wr_en,
27
    input                   rd_en,
28
    
29
    //data signals
30
    input  [DATA_WIDTH-1:0] wdata,
31
    output [DATA_WIDTH-1:0] rdata
32
  ); 
33
  
34
  reg [DATA_WIDTH-1:0] rdata;
35
  
36
  //Memory
37
  reg [DATA_WIDTH-1:0] mem [2**ADDR_WIDTH];
38
39
  //Reset 
40
  always @(posedge reset) 
41
    for(int i=0;i<2**ADDR_WIDTH;i++) mem[i]=8'hFF;
42
   
43
  // Write data to Memory
44
  always @(posedge clk) 
45
    if (wr_en)    mem[addr] <= wdata;
46
47
  // Read data from memory
48
  always @(posedge clk)
49
    if (rd_en) rdata <= mem[addr];
50
51
endmodule
30127 views and 24 likes     
 
UVM TestBench Example code. www.verificationguide.com

UVM TestBench Example code. www.verificationguide.com

170:0