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

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [axi4_stream_lib/] [sim/] [src/] [legacy/] [tb_axis_to_axi4_agent_class_pkg.sv] - Rev 49

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 tb_axis_to_axi4_agent_class_pkg;

  // --------------------------------------------------------------------
  //
  import axi4_memory_pkg::*;
  import axis_bfm_pkg::*;


  // --------------------------------------------------------------------
  //
  class tb_axis_to_axi4_agent_class  #(N, A, I, D, U);

    axi4_memory_class #(A, N, I) m_h;
    axis_tx_bfm_class  #(N, I, D, U) s_h;
    memory_tr_class #(A, N, I) m_tr_h;
    axis_tr_class  #(N, I, D, U) s_tr_h;

    virtual axi4_if #(.A(A), .N(N), .I(I)) axi4_m;
    virtual axis_if #(.N(N), .I(I), .D(D), .U(U)) axis_in;

    mailbox #(memory_tr_class #(A, N, I)) q;


    // --------------------------------------------------------------------
    //
    task wait_for_sof;
      @(posedge axis_in.cb_s.tuser);
      $display("^^^ %16.t | %m", $time);
    endtask: wait_for_sof


    // --------------------------------------------------------------------
    //
    task wait_for_dma_done(int bvalid_count);
      repeat(bvalid_count)
        @(axi4_m.cb_s iff axi4_m.cb_m.bvalid & axi4_m.cb_s.bready);
      $display("^^^ %16.t | %m", $time);
    endtask: wait_for_dma_done


    // --------------------------------------------------------------------
    //
    task random_transaction(int addr, int size, int stride);
      m_h.clear_all();
      m_tr_h = new();
      m_tr_h.random(addr, size);
      q.put(m_tr_h);

      $display("^^^ %16.t | %m | m_tr_h.data.size = %x", $time, m_tr_h.data.size);
      for(int i = 0; i < m_tr_h.data.size; i += N)
      begin
        s_tr_h = new();
        for(int k = 0; k < N; k++)
        begin
          s_tr_h.tdata[k*8 +: 8] = m_tr_h.data[i + k];
        end

        if(i == 0)
          s_tr_h.tuser = 'b1;
        else
          s_tr_h.tuser = 'b0;

        if(i + N < m_tr_h.data.size)
          s_tr_h.tlast = 1'b0;
        else
          s_tr_h.tlast = 1'b1;

        s_h.q.put(s_tr_h);
      end

      wait_for_dma_done(size / stride);
    endtask: random_transaction


    // --------------------------------------------------------------------
    //
    task automatic compare(int offset);
      byte data[];

      $display("^^^ %16.t | %m", $time);
      $display("^^^ %16.t | q.num             = %d", $time, q.num);
      $display("^^^ %16.t | s_h.q.num         = %d", $time, s_h.q.num);
      $display("^^^ %16.t | m_tr_h.data.size  = %d", $time, m_tr_h.data.size);

      if(q.try_get(m_tr_h) == 0)
      begin
        $display("!!! %16.t | ERROR!!! try_get(m_tr_h) == 0", $time);
        $stop;
      end

      data = new[m_tr_h.data.size];
      m_h.dump_words(offset, data);

      foreach(m_tr_h.data[i])
        if(data[i] != m_tr_h.data[i])
        begin
          $display("!!! %16.t | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^", $time);
          $display("!!! %16.t | %x ", $time, i);
          $display("!!! %16.t | %x | %x |", $time, data[i], m_tr_h.data[i]);
          $stop;
        end

      $display("^^^ %16.t | %m | done!", $time);

    endtask: compare


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

      this.axi4_m = axi4_m;
      this.axis_in = axis_in;
      m_h = new(axi4_m);
      s_h = new(axis_in);
      q = new();
    endfunction: new


  // --------------------------------------------------------------------
  //
  endclass: tb_axis_to_axi4_agent_class

// --------------------------------------------------------------------
//
endpackage: tb_axis_to_axi4_agent_class_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.