Hard Processor System Component Reference Manual: Agilex™ 5 SoCs

ID 813752
Date 4/10/2025
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

4.3.2. test_lwh2f.sv

  1. Change directory to <project directory>/simple_tb/simple_tb/sim/ .
  2. Create a file named test_lwh2f.sv and edit with contents as shown below.
    // test_lwh2f.sv
    
    `timescale 1 ps / 1 ps
    import altera_axi_bfm_pkg::*; 
    
    `define lwh2f_test_m        simple_tb.simple_inst.intel_agilex_5_soc_0.intel_agilex_5_soc_0.sm_hps.sundancemesa_hps_inst.lwh2f_bfm_gen.lwh2f_axi4_master_inst.AXI4MAN.bfm
    
    module test_lwh2f#(int A_WIDTH=29, int D_WIDTH=32)();
     
    int i,j;
    bit status, f_rw[8], f_incr[8][8];
    reg [A_WIDTH-1:0] Addr;		// 29 bit addr
    int Data[8];			// 32 bit data
    
    //-----------------------------------------------------------------------------------------------
    //----------------------------  BFM Manager (lwh2f)
    //-----------------------------------------------------------------------------------------------
    initial begin 
    
      AlteraAxiTransaction wr_resp_tr, rd_resp_tr;
    
      Data[0] = 'haaaaaaaa;
      Data[1] = 'hbbbbbbbb;
      Data[2] = 'hcccccccc;
      Data[3] = 'hdddddddd;
      
      $display("\n\n\n *************** START OF  LWH2F testing *************** \n\n\n");
      
      `lwh2f_test_m.m_reset();
    
    /////////////////////////////////////////// SINGLE WRITES //////////////////////////////////////
    for (i = 0; i < 4; i++) begin
      $display("\n@%0t*********** START OF WRITE #%d TEST *******  LWH2F  ********\n",$time, i);
      Addr = (i * 1<<AXI4_BYTES_4);
      wr_resp_tr = `lwh2f_test_m.manager_bfm_wr_tx( i, Addr );        // id, addr, data, burst_len, burst_size, burst_type
      wr_resp_tr.set_data_words(Data[i], 0);		// data, index
      wr_resp_tr.set_write_strobes(4'hf, 0);		// strobe, index
      `lwh2f_test_m.put_transaction(wr_resp_tr); 
      `lwh2f_test_m.drive_transaction(); 
      $display("\n@%0t*********** END OF   WRITE #%d TEST *******  LWH2F  ********\n",$time, i);
    end
    /////////////////////////////////////////// SINGLE READS  //////////////////////////////////////
    for (i = 0; i < 4; i++) begin
      $display("\n@%0t*********** START OF READ  #%d TEST ******   LWH2F   *********\n",$time, i); 
      Addr = (i * 1<<AXI4_BYTES_4);
      rd_resp_tr = `lwh2f_test_m.manager_bfm_rd_tx( i, Addr );	// id, addr
      rd_resp_tr.set_size(AXI4_BYTES_4);
      `lwh2f_test_m.put_transaction(rd_resp_tr); 
      `lwh2f_test_m.drive_transaction();
      if (rd_resp_tr.get_data_words(0) == Data[i]) begin
            f_rw[i]=1'b1;
            $display ("value of f_rw[%d] is %b", i, f_rw[i]);
            $display ( "@ %t Read correct data (%h) at address (0x%h)", $time, Data[i], Addr );
        end 
      else
            $display ( "@ %t Error: Expected data (%h) at address (0x%h), but got %d", $time, Data[i], Addr, rd_resp_tr.get_data_words(0));
      $display("\n@%0t*********** END OF   READ  #%d TEST ******   LWH2F   *********\n",$time, i);
    end
    /////////////////////////////////////////// INCR WRITES/READS  /////////////////////////////////
    for (i = 0; i < 4; i++) begin
      $display("\n@%0t*************** START OF INCR BURST #%d TEST ******   LWH2F   *********\n",$time, i); 
      Addr = 16+ (i*1<<AXI4_BYTES_4);
      wr_resp_tr = `lwh2f_test_m.manager_bfm_wr_tx( (4+i), Addr );	// id, addr
      wr_resp_tr.set_burst_length(3); 
      wr_resp_tr.set_size(AXI4_BYTES_4); 
      wr_resp_tr.set_burst_type(BURST_TYPE_INCR); 
      wr_resp_tr.set_data_words(Data[0], 0);	// data, id
      wr_resp_tr.set_data_words(Data[1], 1); 
      wr_resp_tr.set_data_words(Data[2], 2); 
      wr_resp_tr.set_data_words(Data[3], 3); 
      wr_resp_tr.set_write_strobes(4'hf, 0);	// strobe, id
      wr_resp_tr.set_write_strobes(4'hf, 1); 
      wr_resp_tr.set_write_strobes(4'hf, 2); 
      wr_resp_tr.set_write_strobes(4'hf, 3); 
      `lwh2f_test_m.put_transaction(wr_resp_tr);
      `lwh2f_test_m.drive_transaction();
    
      rd_resp_tr = `lwh2f_test_m.manager_bfm_rd_tx( (4+i), Addr );	// id, addr
      rd_resp_tr.set_burst_length(3); 
      rd_resp_tr.set_size(AXI4_BYTES_4); 
      rd_resp_tr.set_burst_type(BURST_TYPE_INCR); 
    
    fork 
       begin 
    	`lwh2f_test_m.put_transaction(rd_resp_tr); 
    	`lwh2f_test_m.drive_transaction(); 
       end 
       begin 
    	`lwh2f_test_m.put_transaction(wr_resp_tr); 
    	`lwh2f_test_m.drive_transaction(); 
       end 
    join 
    
       for (j=0; j<4; j++) begin
         if (rd_resp_tr.get_data_words(j) == Data[j]) begin
           f_incr[i][j]=1'b1;
           $display ( "@ %t  Read correct data (%h) at address (%h)", $time, Data[j], (Addr + j) );             
           end 
        else
           $display ( "@ %t  Error: Expected data (%h) at address (%h), but got %h", $time, Data[j], (Addr + j), rd_resp_tr.get_data_words(j));
        end	   //for j loop
    end	//for i loop
    /////////////////////////////////////////// CHECK TESTS        /////////////////////////////////
    #2000000	// optional delay - if timescale is 1ps/1ps, then  2000000 = 2ns
    status=1'b1;	//assume pass
    for (i = 0; i < 4; i++)
       if (f_rw[i]!=1'b1)
    	status=1'b0;
    
    for (i=0; i<4; i++)
       for (j=0; j<2; j++)
          	if (f_incr[i][j]!=1'b1)
          		status=1'b0;	
    	
    if (status==1'b1)
       $display ("\n\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> pass    LWH2F ");
    else begin
       $display ("\n\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> fail    LWH2F ");
       for (i=0; i<4; i++)
          for (j=0; j<2; j++)
     	 $display (">>> f_rw[%d] is %b  >>>  f_incr[%d][%d] is %b ", i, f_rw[i], i, j, f_incr[i][j] );
    end
    
    $display("\n@%0t************ END OF TEST ********      LWH2F    ********\n",$time); 
    
    end     // initial begin
    endmodule