Environment Sınıfı

Gün 7: Bitirme Projesi - Bölüm 2 | Tüm bileşenleri kapsayan ortam sınıfı

Kaynak Kod

// =============================================================================
// GUN 7 - Konu 3: Environment - Tum Bilesenleri Kapsayan Sinif
// =============================================================================

class ALU_Environment;
  // Bilesenler
  ALU_Generator   gen;
  ALU_Driver      drv;
  ALU_Monitor     mon;
  ALU_Scoreboard  scb;
  ALU_Coverage    cov;  // 7_5_coverage.sv'de tanimli

  // Mailbox'lar
  mailbox #(ALU_Transaction) gen2drv_mbx;
  mailbox #(ALU_Transaction) drv2scb_mbx;
  mailbox #(ALU_Transaction) mon2scb_mbx;

  // Virtual interface
  virtual alu_if.driver  drv_vif;
  virtual alu_if.monitor mon_vif;

  // Konfigurasyon
  int num_transactions;

  function new(virtual alu_if.driver drv_vif, virtual alu_if.monitor mon_vif, int num_txn = 100);
    this.drv_vif = drv_vif;
    this.mon_vif = mon_vif;
    this.num_transactions = num_txn;
  endfunction

  // Tum bilesenleri olustur ve bagla
  function void build();
    $display("[Environment] Build asamasi");

    // Mailbox'lari olustur
    gen2drv_mbx = new();
    drv2scb_mbx = new();
    mon2scb_mbx = new();

    // Bilesenleri olustur
    gen = new(gen2drv_mbx, num_transactions);
    drv = new(drv_vif, gen2drv_mbx, drv2scb_mbx);
    mon = new(mon_vif, mon2scb_mbx);
    scb = new(drv2scb_mbx, mon2scb_mbx);
    cov = new();

    $display("[Environment] Tum bilesenler olusturuldu");
  endfunction

  // Reset
  task reset();
    $display("[Environment] Reset");
    drv.reset();
  endtask

  // Tum bilesenleri calistir
  task run();
    $display("[Environment] Calistiriliyor...\n");

    fork
      gen.run();
      drv.run();
      mon.run();
      scb.run();
    join_any

    // Generator bitene kadar bekle
    wait(gen.done.triggered);
    
    // Pipeline'in bosalmasini bekle
    #500;
  endtask

  // Rapor
  function void report();
    $display("\n[Environment] Final Rapor");
    $display("  Generator : %0d uretildi", gen.num_transactions);
    $display("  Driver    : %0d suruldu", drv.driven_count);
    $display("  Monitor   : %0d izlendi", mon.monitored_count);
    scb.report();
    cov.report();
  endfunction
endclass