OpenCores
URL https://opencores.org/ocsvn/qaz_libs/qaz_libs/trunk

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [axi4_lib/] [sim/] [src/] [legacy/] [axi4_bfm_pkg.sv] - Rev 45

Compare with Previous | Blame | View Log

//////////////////////////////////////////////////////////////////////
////                                                              ////
//// Copyright (C) 2015 Authors and OPENCORES.ORG                 ////
////                                                              ////
//// This source file may be used and distributed without         ////
//// restriction provided that this copyright statement is not    ////
//// removed from the file and that any derivative work contains  ////
//// the original copyright notice and the associated disclaimer. ////
////                                                              ////
//// This source file is free software; you can redistribute it   ////
//// and/or modify it under the terms of the GNU Lesser General   ////
//// Public License as published by the Free Software Foundation; ////
//// either version 2.1 of the License, or (at your option) any   ////
//// later version.                                               ////
////                                                              ////
//// This source is distributed in the hope that it will be       ////
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
//// PURPOSE.  See the GNU Lesser General Public License for more ////
//// details.                                                     ////
////                                                              ////
//// You should have received a copy of the GNU Lesser General    ////
//// Public License along with this source; if not, download it   ////
//// from http://www.opencores.org/lgpl.shtml                     ////
////                                                              ////
//////////////////////////////////////////////////////////////////////


// --------------------------------------------------------------------
//
package axi4_bfm_pkg;

  // --------------------------------------------------------------------
  //
  import tb_bfm_pkg::*;
  import axi4_transaction_pkg::*;


  // --------------------------------------------------------------------
  //
  class ar_master_transaction_class #(A = 32, N = 8, I = 1)
    extends tb_blocking_transaction_q_class #(axi4_transaction_class #(.A(A), .N(N), .I(I)));

    virtual axi4_if  #(.A(A), .N(N), .I(I)) axi4_m;


    //--------------------------------------------------------------------
    function new
      (
        virtual axi4_if  #(.A(A), .N(N), .I(I)) axi4_m
      );

      super.new();
      this.axi4_m = axi4_m;

    endfunction: new


    // --------------------------------------------------------------------
    //
    function void
      ar_default;

      axi4_m.cb_m.araddr   <= 'bx;
      axi4_m.cb_m.arburst  <= 'bx;
      axi4_m.cb_m.arcache  <= 'bx;
      axi4_m.cb_m.arid     <= 'bx;
      axi4_m.cb_m.arlen    <= 'bx;
      axi4_m.cb_m.arlock   <= 'bx;
      axi4_m.cb_m.arprot   <= 'bx;
      axi4_m.cb_m.arqos    <= 'bx;
      axi4_m.cb_m.arregion <= 'bx;
      axi4_m.cb_m.arsize   <= 'bx;
      axi4_m.cb_m.arvalid  <= 0;

    endfunction: ar_default


    // --------------------------------------------------------------------
    //
    task automatic
      transaction
      (
        ref T tr_h
      );

      ->this.start;

      repeat(tr_h.delay_h.next()) @(axi4_m.cb_m);

      axi4_m.cb_m.araddr   <= tr_h.addr;
      axi4_m.cb_m.arid     <= tr_h.id;
      axi4_m.cb_m.arlen    <= tr_h.len;
      axi4_m.cb_m.arsize   <= tr_h.size;

      axi4_m.cb_m.arburst  <= tr_h.burst;
      axi4_m.cb_m.arcache  <= tr_h.cache;
      axi4_m.cb_m.arlock   <= tr_h.lock;
      axi4_m.cb_m.arprot   <= tr_h.prot;
      axi4_m.cb_m.arqos    <= tr_h.qos;
      axi4_m.cb_m.arregion <= tr_h.region;
      axi4_m.cb_m.arvalid  <= 1;

      $display("^^^ %16.t | %m | master AR transaction @ 0x%08x |", $time, tr_h.addr);

      repeat(1) @(axi4_m.cb_m);
      wait(axi4_m.cb_m.arready);

      axi4_m.zero_cycle_delay();
      ar_default();

      ->this.done;

    endtask: transaction


  // --------------------------------------------------------------------
  //
  endclass: ar_master_transaction_class


  // --------------------------------------------------------------------
  //
  class r_master_transaction_class #(A = 32, N = 8, I = 1)
    extends tb_blocking_transaction_q_class #(axi4_transaction_class #(.A(A), .N(N), .I(I)));

    virtual axi4_if  #(.A(A), .N(N), .I(I)) axi4_m;


    //--------------------------------------------------------------------
    function new
      (
        virtual axi4_if  #(.A(A), .N(N), .I(I)) axi4_m
      );

      super.new();
      this.axi4_m = axi4_m;

    endfunction: new


    // --------------------------------------------------------------------
    //
    function void
      r_default;

      axi4_m.cb_m.rready <= 0;

    endfunction: r_default


    // --------------------------------------------------------------------
    //
    task automatic
      transaction
      (
        ref T tr_h
      );

      ->this.start;

      tr_h.data_h = new(tr_h.len);

      foreach(tr_h.payload_h.w[i])
      begin
        repeat(tr_h.delay_h.next()) @(axi4_m.cb_m);
        axi4_m.cb_m.rready <= 1;
        repeat(1) @(axi4_m.cb_m);

        wait(axi4_m.cb_m.rvalid);
        axi4_m.zero_cycle_delay();

        tr_h.data_h.w[i] = axi4_m.cb_m.rdata;

        $display("^^^ %16.t | %m | master R transaction | %d | 0x%016x |", $time, i, tr_h.data_h.w[i]);
        r_default();
      end

      ->this.done;

    endtask: transaction


  // --------------------------------------------------------------------
  //
  endclass: r_master_transaction_class


  // --------------------------------------------------------------------
  //
  class aw_master_transaction_class #(A = 32, N = 8, I = 1)
    extends tb_blocking_transaction_q_class #(axi4_transaction_class #(.A(A), .N(N), .I(I)));

    virtual axi4_if  #(.A(A), .N(N), .I(I)) axi4_m;


    //--------------------------------------------------------------------
    function new
      (
        virtual axi4_if  #(.A(A), .N(N), .I(I)) axi4_m
      );

      super.new();
      this.axi4_m = axi4_m;

    endfunction: new


    // --------------------------------------------------------------------
    //
    function void
      aw_default;

      axi4_m.cb_m.awaddr   <= 'bx;
      axi4_m.cb_m.awburst  <= 'bx;
      axi4_m.cb_m.awcache  <= 'bx;
      axi4_m.cb_m.awid     <= 'bx;
      axi4_m.cb_m.awlen    <= 'bx;
      axi4_m.cb_m.awlock   <= 'bx;
      axi4_m.cb_m.awprot   <= 'bx;
      axi4_m.cb_m.awqos    <= 'bx;
      axi4_m.cb_m.awregion <= 'bx;
      axi4_m.cb_m.awsize   <= 'bx;
      axi4_m.cb_m.awvalid  <= 0;

    endfunction: aw_default

    // --------------------------------------------------------------------
    //
    task automatic
      transaction
      (
        ref T tr_h
      );

      ->this.start;

      repeat(tr_h.delay_h.next()) @(axi4_m.cb_m);

      axi4_m.cb_m.awaddr   <= tr_h.addr;
      axi4_m.cb_m.awid     <= tr_h.id;
      axi4_m.cb_m.awlen    <= tr_h.len;
      axi4_m.cb_m.awsize   <= tr_h.size;

      axi4_m.cb_m.awburst  <= tr_h.burst;
      axi4_m.cb_m.awcache  <= tr_h.cache;
      axi4_m.cb_m.awlock   <= tr_h.lock;
      axi4_m.cb_m.awprot   <= tr_h.prot;
      axi4_m.cb_m.awqos    <= tr_h.qos;
      axi4_m.cb_m.awregion <= tr_h.region;
      axi4_m.cb_m.awvalid  <= 1;

      $display("^^^ %16.t | %m | master AW transaction @ 0x%08x |", $time, tr_h.addr);

      repeat(1) @(axi4_m.cb_m);
      wait(axi4_m.cb_m.awready);

      axi4_m.zero_cycle_delay();
      aw_default();

      ->this.done;

    endtask: transaction


  // --------------------------------------------------------------------
  //
  endclass: aw_master_transaction_class


  // --------------------------------------------------------------------
  //
  class w_master_transaction_class #(A = 32, N = 8, I = 1)
    extends tb_blocking_transaction_q_class #(axi4_transaction_class #(.A(A), .N(N), .I(I)));

    virtual axi4_if  #(.A(A), .N(N), .I(I)) axi4_m;


    //--------------------------------------------------------------------
    function new
      (
        virtual axi4_if  #(.A(A), .N(N), .I(I)) axi4_m
      );

      super.new();
      this.axi4_m = axi4_m;

    endfunction: new


    // --------------------------------------------------------------------
    //
    function void
      w_default;

      axi4_m.cb_m.wdata    <= 'bx;
      axi4_m.cb_m.wlast    <= 'bx;
      axi4_m.cb_m.wstrb    <= {N{1'b1}};
      axi4_m.cb_m.wvalid   <= 0;

    endfunction: w_default


    // --------------------------------------------------------------------
    //
    task automatic
      transaction
      (
        ref T tr_h
      );

      ->this.start;

      foreach(tr_h.payload_h.w[i])
      begin
        repeat(tr_h.delay_h.next()) @(axi4_m.cb_m);

        axi4_m.cb_m.wdata  <= tr_h.payload_h.w[i];
        // axi4_m.cb_m.wstrb  <= tr_h.strb;    // need to fix

        if(i < tr_h.payload_h.w.size - 1)
          axi4_m.cb_m.wlast   <= 0;
        else
          axi4_m.cb_m.wlast   <= 1;

        axi4_m.cb_m.wvalid <= 1;

        repeat(1) @(axi4_m.cb_m);
        wait(axi4_m.cb_m.wready);

        axi4_m.zero_cycle_delay();
        $display("^^^ %16.t | %m | master W transaction | %d | 0x%016x |", $time, i, tr_h.payload_h.w[i]);
        w_default();
      end

      ->this.done;

    endtask: transaction


  // --------------------------------------------------------------------
  //
  endclass: w_master_transaction_class


  // --------------------------------------------------------------------
  //
  class b_master_transaction_class #(A = 32, N = 8, I = 1)
    extends tb_blocking_transaction_q_class #(axi4_transaction_class #(.A(A), .N(N), .I(I)));

    virtual axi4_if  #(.A(A), .N(N), .I(I)) axi4_m;


    //--------------------------------------------------------------------
    function new
      (
        virtual axi4_if  #(.A(A), .N(N), .I(I)) axi4_m
      );

      super.new();
      this.axi4_m = axi4_m;

    endfunction: new


    // --------------------------------------------------------------------
    //
    function void
      b_default;

      axi4_m.cb_m.bready   <= 0;

    endfunction: b_default


    // --------------------------------------------------------------------
    //
    task automatic
      transaction
      (
        ref T tr_h
      );

      ->this.start;

      repeat(tr_h.delay_h.next()) @(axi4_m.cb_m);
      axi4_m.cb_m.bready <= 1;
      repeat(1) @(axi4_m.cb_m);

      wait(axi4_m.cb_m.bvalid);
      axi4_m.zero_cycle_delay();

      $display("^^^ %16.t | %m | master B transaction | 0x%x |", $time, axi4_m.cb_m.bresp);
      b_default();

      ->this.done;

    endtask: transaction


  // --------------------------------------------------------------------
  //
  endclass: b_master_transaction_class


  // --------------------------------------------------------------------
  //
  class axi4_master_bfm_class #(A = 32, N = 8, I = 1);

    ar_master_transaction_class #(.A(A), .N(N), .I(I))  ar_h;
    r_master_transaction_class  #(.A(A), .N(N), .I(I))  r_h;
    aw_master_transaction_class #(.A(A), .N(N), .I(I))  aw_h;
    w_master_transaction_class #(.A(A), .N(N), .I(I))   w_h;
    b_master_transaction_class  #(.A(A), .N(N), .I(I))  b_h;

    axi4_transaction_class tr_h;
    virtual axi4_if  #(.A(A), .N(N), .I(I)) axi4_m;


    //--------------------------------------------------------------------
    function new
      (
        virtual axi4_if  #(.A(A), .N(N), .I(I)) axi4_m
      );

      this.axi4_m = axi4_m;

      ar_h = new(axi4_m);
      r_h = new(axi4_m);
      aw_h = new(axi4_m);
      w_h = new(axi4_m);
      b_h = new(axi4_m);
      
      ar_h.init();
      ar_h.ar_default();

      r_h.init();
      r_h.r_default();

      aw_h.init();
      aw_h.aw_default();

      w_h.init();
      w_h.w_default();

      b_h.init();
      b_h.b_default();

    endfunction: new


    // --------------------------------------------------------------------
    //
    function void
      init;

    endfunction: init


    // --------------------------------------------------------------------
    //
    task
      basic_read
      (
        input   logic [(A-1):0]   araddr,
        input   logic [7:0]       arlen,
        output  logic [(8*N)-1:0] data[],
        output  logic [1:0]       rresp
      );

      this.tr_h = new;
      this.tr_h.basic_read(araddr, arlen);

      ar_h.put(tr_h);
      r_h.put(tr_h);

      @(r_h.done);
      data = tr_h.data_h.w;
      rresp = tr_h.resp;

    endtask: basic_read
    

    // --------------------------------------------------------------------
    //
    task
      basic_random_read_burst
      (
        output  logic [(8*N)-1:0] data[],
        output  logic [1:0]       rresp
      );

      this.tr_h = new;
      this.tr_h.basic_random_burst;

      ar_h.put(tr_h);
      r_h.put(tr_h);

      @(r_h.done);
      data = tr_h.data_h.w;
      rresp = tr_h.resp;

    endtask: basic_random_read_burst


    // --------------------------------------------------------------------
    //
    task
      basic_write
      (
        input   logic [(A-1):0]   awaddr,
        input   logic [7:0]       awlen,
        input   logic [(8*N)-1:0] data[],
        output  logic [1:0]       bresp
      );

      this.tr_h = new;
      this.tr_h.basic_write(awaddr, awlen);

      foreach(this.tr_h.payload_h.w[i])
        this.tr_h.payload_h.w[i] = data[i];

      aw_h.put(tr_h);
      w_h.put(tr_h);
      b_h.put(tr_h);

      @(b_h.done);
      bresp = tr_h.resp;

    endtask: basic_write
    

    // --------------------------------------------------------------------
    //
    task
      basic_random_write_burst
      (
        output  logic [1:0]       bresp
      );

      this.tr_h = new;
      this.tr_h.basic_random_burst;

      aw_h.put(tr_h);
      w_h.put(tr_h);
      b_h.put(tr_h);

      @(b_h.done);
      bresp = tr_h.resp;

    endtask: basic_random_write_burst


  // --------------------------------------------------------------------
  //
  endclass: axi4_master_bfm_class
  
  
// --------------------------------------------------------------------
//
endpackage: axi4_bfm_pkg


Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.