Code Browser Pages:
Files in
vmm1.2_example.tar



dummy_rtl.v
ReadMe.txt
vmm_cfg.sv
vmm_cov.sv
vmm_drv.sv
Current file: vmm_env.sv
vmm_gen.sv
vmm_interface.sv
vmm_packet.sv
vmm_rcv.sv
vmm_sbd.sv
vmm_scn.sv
vmm_top.sv



///////////////////////////////////////
///////////////////////////////////////
////                               ////
////        VMM 1.2 example        ////
////                               ////
////     For more vmm examples     ////
////     visit www.testbench.in    ////
////                               ////
///////////////////////////////////////
///////////////////////////////////////


//-----------------------------------------------------------------------------
// dummy rtl env-vmm_env class
//-----------------------------------------------------------------------------

class my_env extends vmm_env;
  // cfg class handle
  cfg_trans cfg;

  // driver class handle
  my_driver driver1;

  // monitor class handle
  my_monitor monitor1;

  // packet scenario generator handle
  packet_scenario_gen gen;

  // Scoreboard handle
  my_sb my_scbd;

  // generator output and driver input channel
  packet_channel gen2drv;

  // monitor output and scoreboard input channel
  packet_channel mon2scbd;

  // Driver/Monitor Virtual Interface
  virtual dut_if.driver drv_ifc;
  virtual dut_if.monitor mon_ifc;

  // consensus class handle
  vmm_consensus cnsus;

  // VMM logger for messages
  static vmm_log log = new("my_env", "Class");

  //-----------------------------------------------------------------------------
  // new() - constructor, pass in any virtual ports needed to connect to DUT
  //-----------------------------------------------------------------------------

  function new(virtual dut_if.driver drv_ifc, virtual dut_if.monitor mon_ifc);
    super.new();
    $timeformat(-9, 0, "ns", 0);
    this.drv_ifc = drv_ifc;
    this.mon_ifc = mon_ifc;
    cnsus = new(" cnsus", "Consensus");
    log.stop_after_n_errors(12);
  endfunction : new

  //-----------------------------------------------------------------------------
  // gen_cfg() - Generate a randomized testbench configuration
  //-----------------------------------------------------------------------------

  virtual function void gen_cfg();
    super.gen_cfg();
    `vmm_note(this.log,"Start of gen_cfg() method ");
    cfg = new();
    cfg.randomize() with {num_of_trans == 12;};
    `vmm_note(log, $psprintf("num of trans in configuration = 0",cfg.num_of_trans));
    `vmm_note(this.log,"End of gen_cfg() method ");
  endfunction

  //-----------------------------------------------------------------------------
  // build() - Build the testbench, xactors, scoreboard, callbacks
  //-----------------------------------------------------------------------------

  virtual function void build();
    super.build();
    `vmm_note(log,"build() - Inside ");
    this.gen2drv = new("GEN 2 DRV", " Class Channel ");
    this.mon2scbd = new("MON 2 SCBD", " Class Channel ");
    this.gen = new("SCENARIO PACKET GENERATOR", 0, this.gen2drv);
    `vmm_note(log, $psprintf(" ",this.gen.psdisplay()));
    this.driver1 = new("DRIVER ", 1, this.drv_ifc, this.gen2drv);
    this.monitor1 = new("MONITOR", 2, this.mon_ifc, this.mon2scbd);
    this.my_scbd = new("MY_SCBD");

    this.gen.stop_after_n_insts = cfg.num_of_trans ;
    this.gen.stop_after_n_scenarios = cfg.num_of_trans;

    begin
      my_driver_callbacks drv_cb = new(my_scbd);
      my_monitor_callbacks mon_cb = new(my_scbd);
      my_scenario scenario = new();
      this.driver1.append_callback(drv_cb);
      this.monitor1.append_callback(mon_cb);
      this.gen.scenario_set[0] = scenario;
    end

    this.driver1.register_vmm_sb_ds(my_scbd, vmm_sb_ds::INPUT);
    this.monitor1.register_vmm_sb_ds(my_scbd, vmm_sb_ds::EXPECT);
    this.cnsus.register_channel(this.gen.out_chan);
    this.cnsus.register_channel(this.driver1.get_data_chan);
    this.cnsus.register_xactor(this.gen);
    this.cnsus.register_xactor(this.driver1);
    `vmm_note(log,"build() - Exiting ");
  endfunction : build

  //-----------------------------------------------------------------------------
  // reset_dut() - Reset the DUT
  //-----------------------------------------------------------------------------

  virtual task reset_dut();
    super.reset_dut();
    drv_ifc.reset <= 1;
    repeat (2) @(drv_ifc.clk);
    drv_ifc.reset <= 0;
    this.gen2drv.flush();
    this.mon2scbd.flush();
  endtask

  //-----------------------------------------------------------------------------
  // cfg_dut() - Configure the DUT
  //-----------------------------------------------------------------------------

  virtual task cfg_dut();
     super.cfg_dut();
  endtask

  //-----------------------------------------------------------------------------
  // start() - Start each of the xactors
  //-----------------------------------------------------------------------------

  virtual task start();
    super.start();
    `vmm_note(log,"start() - Inside ");
    this.gen.start_xactor();
    this.driver1.start_xactor();
    this.monitor1.start_xactor();
    `vmm_note(log,"start() - Exiting ");
  endtask : start

  //-----------------------------------------------------------------------------
  // stop() - Stop each of the xactors
  //-----------------------------------------------------------------------------

  virtual task stop();
    string who[], why[];
    super.stop();
    `vmm_note(log,"stop() - Inside ");
    this.gen.stop_xactor();
    this.driver1.stop_xactor();
    this.monitor1.stop_xactor();
    cnsus.nays(who, why);
    foreach(who[i])
      `vmm_note(log, $psprintf(" who =  and why =  ",who[i],why[i]));
    cnsus.wait_for_consensus();
    `vmm_note(log,"stop() - Exiting ");
  endtask : stop

  //-----------------------------------------------------------------------------
  // wait_for_end() - Wait until the test completes
  //-----------------------------------------------------------------------------

  virtual task wait_for_end();
    super.wait_for_end();
    `vmm_note(log,"wait_for_end() - Inside ");
    // Wait for the generators to be done
    this.gen.notify.wait_for(packet_scenario_gen::DONE);
    while(this.my_scbd.get_n_pending() != 0) begin
      @(posedge drv_ifc.clk);
    end
    `vmm_note(log,"wait_for_end() - Exiting ");
  endtask: wait_for_end

  //-----------------------------------------------------------------------------
  // cleanup() - Cleanup the testbench, report any scoreboard errors etc.
  //-----------------------------------------------------------------------------

  virtual task cleanup();
    super.cleanup();
    if (this.my_scbd != null) this.my_scbd.report();
    `vmm_note(log, $psprintf(" Number of packets left = 0 ",this.my_scbd.get_n_orphaned()));
    this.my_scbd.flush();
  endtask

endclass : my_env

//-----------------------------------------------------------------------------
// end of file
//-----------------------------------------------------------------------------