SHARE
TWEET

TestTop.sv

bobomarinov Jun 10th, 2019 136 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `include "fifo.sv"
  2. `include "memory2port.sv"
  3. `include "iface.sv"
  4.  
  5. module TestTop();
  6.    
  7. class Transaction;
  8.    rand bit [3:0]   data;
  9.    bit [3:0] data_rd;
  10.    rand bit            write_enable;
  11.    rand bit            read_enable;
  12.    rand bit reset;
  13.    bit       full;
  14.    bit       empty;
  15.  
  16.    constraint write_90 { write_enable dist {1 := 70,
  17.                         0 := 20};}
  18.      
  19.      constraint reset_10 {
  20.     ~reset -> write_enable == 0 ;
  21.     ~reset -> read_enable == 0 ; }
  22.        
  23. endclass // Transaction
  24.    
  25. class Generator;
  26.    
  27.    rand Transaction tr;
  28.    mailbox   #(Transaction) mb;
  29.    
  30.    function new(mailbox #(Transaction) mb);
  31.       this.mb = mb;
  32.    endfunction // new
  33.  
  34.    task run();
  35.       $display("Generator starting...");
  36.        
  37.       repeat(150) begin
  38.      tr = new();
  39.      $display("Generator running...");
  40.      $display("Puting into mailbox generated data");
  41.      if(!tr.randomize() ) $fatal("Gen:: tr randomization failed");
  42.          mb.put(tr);
  43.       end
  44.      
  45.    endtask
  46. endclass // Generator
  47.  
  48.    
  49. class Monitor;
  50.    virtual   iface viface;
  51.    byte      readed_data;
  52.    Transaction tr_monitor;
  53.    mailbox   #(Transaction) monitor_mb;
  54.    
  55.    function new(virtual iface viface, mailbox #(Transaction) monitor_mb);
  56.       this.viface = viface;
  57.       this.monitor_mb = monitor_mb;
  58.    endfunction // new
  59.    
  60.    task run();
  61.       $display("Monitor starting..");
  62.      
  63.       tr_monitor = new();
  64.       forever begin
  65.      
  66.      
  67.      @(negedge viface.clk)begin  //read
  68.         $display("Monitor runing...");
  69.         tr_monitor.data_rd <= viface.rd_data;
  70.         tr_monitor.write_enable <= viface.write_enable;
  71.         tr_monitor.read_enable <= viface.read_enable;
  72.         tr_monitor.reset <= viface.reset;
  73.         tr_monitor.empty <= viface.empty;
  74.         tr_monitor.full <= viface.full;
  75.         tr_monitor.data <= viface.data;
  76.        
  77.         $display("INTERFACEDATA // data_rd=%d, write_enable=%d, read_enable=%d, reset=%d, empty=%d, full=%d, data=%d", viface.rd_data, viface.write_enable, viface.read_enable, viface.reset, viface.empty, viface.full, viface.data);
  78.        
  79.         $display("TRDATA // data_rd=%d, write_enable=%d, read_enable=%d, reset=%d, empty=%d, full=%d, data=%d", tr_monitor.data_rd, tr_monitor.write_enable, tr_monitor.read_enable, tr_monitor.reset, tr_monitor.empty, tr_monitor.full, tr_monitor.data);
  80.        
  81.         monitor_mb.put(tr_monitor);
  82.      end
  83.       end
  84.    endtask //
  85. endclass // Monitor
  86.  
  87.    
  88. class Scoreboard;
  89.    byte queue[$:16];
  90.    byte queue_data;
  91.    byte queue_data2;  
  92.    bit  read_enable_2;
  93.    bit  empty_2;
  94.    mailbox #(Transaction) monitor_mb;
  95.    Transaction tr_scoreboard;
  96.    
  97.    function new(mailbox #(Transaction) monitor_mb);
  98.       this.monitor_mb = monitor_mb;
  99.    endfunction // new
  100.  
  101.    task run();
  102.       $display("Scoreboard starting..");
  103.  
  104.       forever begin    
  105.      monitor_mb.get(tr_scoreboard);
  106.      read_enable_2 <= tr_scoreboard.read_enable;
  107.      empty_2 <= tr_scoreboard.empty;
  108.      
  109.      $display("Data tranfered to scoreboard!");
  110.      $display("SCOREDATA // data_rd=%d, write_enable=%d, read_enable=%d, reset=%d, empty=%d, full=%d, data=%d", tr_scoreboard.data_rd, tr_scoreboard.write_enable, tr_scoreboard.read_enable, tr_scoreboard.reset, tr_scoreboard.empty, tr_scoreboard.full, tr_scoreboard.data);
  111.      
  112.      
  113.      if (~tr_scoreboard.reset)begin
  114.         queue = {};
  115.         qsize = queue.size();
  116.         $display("Reseting...");
  117.      end
  118.  
  119.      else begin
  120.         $display("Runing scoreboard");
  121.        
  122.         if(read_enable_2  & qsize != 0 & ~empty_2)begin
  123.            $display("Reading from queue..");
  124.            queue_data = queue.pop_front();
  125.            qsize = queue.size();
  126.            assert (queue_data == tr_scoreboard.data_rd) //sravnqvame edin cykal po kasno zaradi zakasnenieto ot pametta
  127.          $display("TRUE");
  128.         end
  129.  
  130.         if(tr_scoreboard.write_enable & qsize < 16 & ~tr_scoreboard.full)begin  //write
  131.            $display("Writing to queue...");
  132.            queue.push_back(tr_scoreboard.data);
  133.            qsize <= queue.size();
  134.         end      
  135.      end  
  136.       end
  137.       //  end
  138.    endtask // run  
  139. endclass // Scoreboard
  140.  
  141. class Driver;
  142.    Transaction tr;
  143.    mailbox   #(Transaction) mb;
  144.    virtual   iface viface;
  145.    
  146.    function new(mailbox #(Transaction) mb, virtual iface viface);
  147.       this.mb = mb;
  148.       this.viface = viface;
  149.    endfunction // new
  150.    
  151.    task run();
  152.       $display("Driver starting..");
  153.       forever begin
  154.      @(posedge viface.clk)begin
  155.         $display("Driver runing..");
  156.         $display("Getting generated data from mailbox");
  157.         mb.get(tr);
  158.         viface.reset <= tr.reset;
  159.         viface.data <= tr.data;
  160.         viface.write_enable <= tr.write_enable;
  161.         viface.read_enable <= tr.read_enable;
  162.      end
  163.       end
  164.    endtask // run
  165. endclass // Driver
  166.  
  167.    
  168. class Agent;
  169.    Scoreboard sb;
  170.    Monitor mntr;
  171.    Generator gen;
  172.    Driver drv;
  173.    mailbox #(Transaction) mb;
  174.    mailbox #(Transaction) monitor_mb;
  175.    virtual iface viface;
  176.  
  177.    function new(virtual iface viface);
  178.       this.viface = viface;
  179.    endfunction // new
  180.    
  181.    task build();
  182.       $display("Build...");
  183.       monitor_mb = new();
  184.       sb = new(monitor_mb);
  185.       mb = new();
  186.       gen = new(mb);
  187.       mntr = new(viface,monitor_mb);
  188.       drv = new(mb,viface);
  189.    endtask // build
  190.  
  191.    task run();
  192.       $display("Test running..");
  193.       fork
  194.      gen.run();
  195.      drv.run();
  196.      sb.run();
  197.      mntr.run();
  198.       join_any
  199.    endtask // testrun
  200.    
  201.  
  202. endclass // Agent
  203.    
  204.    bit       clk;
  205.    byte      qsize;
  206.    iface viface(.clk(clk));  
  207.    Agent agnt;
  208.    
  209.    initial begin
  210.       clk = 0;
  211.    end
  212.  
  213.    initial begin
  214.       agnt = new(viface);
  215.       agnt.build();
  216.       agnt.run();
  217.    end
  218.  
  219.    initial begin
  220.       #10000 $finish;
  221.    end
  222.    
  223.    always begin
  224.       #10 clk = ~clk;
  225.    end
  226.    
  227.  
  228.    
  229.    fifo dut(.reset(iface.reset),   //vrazka s interface
  230.         .data_in(iface.data),
  231.         .WE(iface.write_enable),
  232.         .RE(iface.read_enable),
  233.         .write_clk(clk),
  234.         .read_clk(clk),
  235.         .data_out(iface.rd_data),
  236.         .full(iface.full),
  237.         .empty(iface.empty)
  238.         );
  239.  
  240. endmodule // TestTop
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top