Altera® AXI4 Bus Functional Model User Guides

ID 838773
Date 5/19/2025
Public
Document Table of Contents

2.4.5. Altera® AXI4 Streaming BFM Platform Designer Example

The following example testbench is a modification of the axi4st_bfm_system_tb.v Platform Designer-generated testbench. For more information about creating simulation models and setup scripts, refer to Quartus Prime Pro Edition User Guide: Third-party Simulation.

Figure 15. Altera AXI4 Streaming BFM Platform Designer Example


// axi4st_bfm_system_tb.v

// Generated using ACDS version XX.X.X

import altera_lnsim_ver.axi4_stream_bfm_types_pkg::*;
import altera_lnsim_ver.axi4_stream_bytes_class_pkg::*;
import altera_lnsim_ver.axi4_stream_transfer_class_pkg::*;
import altera_lnsim_ver.axi4_stream_packet_class_pkg::*;

// For simplicity, defining hierarchical names of manager and subordinate BFMs
// <PD system inst>.<PD bfm inst>.<PD bfm inst>.axi4_stream_<tx/rx>_bfm
`define  bfm_tx axi4st_bfm_system_inst.axi4st_tx_bfm.axi4st_tx_bfm.axi4_stream_tx_bfm
`define  bfm_rx axi4st_bfm_system_inst.axi4st_rx_bfm.axi4st_rx_bfm.axi4_stream_rx_bfm

parameter DATA_BUS_WIDTH = 4;  // Data Bus Width in bytes. 
parameter TID_WIDTH = 8;       // TID width in bits. 
parameter TDEST_WIDTH = 4;     // TDEST width in bits. 
parameter TUSER_WIDTH = 12;    // TUSER width in bits. 

// Testbench provided by Platform Designer
`timescale 1 ps / 1 ps
module axi4st_bfm_system_tb (
	);

wire    axi4st_bfm_system_inst_clk_bfm_clk_clk; // ...
wire    axi4st_bfm_system_inst_reset_bfm_reset_reset; // ...

axi4st_bfm_system_inst_clk_bfm_ip axi4st_bfm_system_inst_clk_bfm (
.clk (axi4st_bfm_system_inst_clk_bfm_clk_clk)  //  output,  width = 1
);

axi4st_bfm_system_inst_reset_bfm_ip axi4st_bfm_system_inst_reset_bfm (
.reset (axi4st_bfm_system_inst_reset_bfm_reset_reset), //  output,  width = 1
.clk   (axi4st_bfm_system_inst_clk_bfm_clk_clk)        //   input,  width = 1
	);

axi4st_bfm_system axi4st_bfm_system_inst (
	.clk_clk     (axi4st_bfm_system_inst_clk_bfm_clk_clk), //   input,  width = 1
	.reset_reset (axi4st_bfm_system_inst_reset_bfm_reset_reset) //   input,...
	);
// End of Testbench provided by Platform Designer	
	
// Transfers
Axi4StreamTransfer#(.AXI4_STREAMING_DATA_BUS_WIDTH(DATA_BUS_WIDTH),
.AXI4_STREAMING_TID_WIDTH(TID_WIDTH),
.AXI4_STREAMING_TDEST_WIDTH(TDEST_WIDTH),
.AXI4_STREAMING_TUSER_WIDTH(TUSER_WIDTH)) tx_tr, rx_tr;
// Transfer Queues - Used to store tx and rx transfers for comparison at end of simulation
Axi4StreamTransfer#(.AXI4_STREAMING_DATA_BUS_WIDTH(DATA_BUS_WIDTH),
.AXI4_STREAMING_TID_WIDTH(TID_WIDTH),
.AXI4_STREAMING_TDEST_WIDTH(TDEST_WIDTH),
.AXI4_STREAMING_TUSER_WIDTH(TUSER_WIDTH)) trq_tx[$], trq_rx[$];  //RX History Queue
// Packet handles.
Axi4StreamPacket#(.AXI4_STREAMING_DATA_BUS_WIDTH(DATA_BUS_WIDTH),
.AXI4_STREAMING_TID_WIDTH(TID_WIDTH),
.AXI4_STREAMING_TDEST_WIDTH(TDEST_WIDTH),
.AXI4_STREAMING_TUSER_WIDTH(TUSER_WIDTH)) p;	

byte_t byte_buf [];

Axi4StreamBytes#(TUSER_WIDTH)		    asb; //Super Class
Axi4StreamBytesData#(TUSER_WIDTH)		asbd;
Axi4StreamBytesPosition#(TUSER_WIDTH)	asbp;
Axi4StreamBytesNull#(TUSER_WIDTH)		asbn;
Axi4StreamBytes#(TUSER_WIDTH)		    ba[];
Axi4StreamBytes#(TUSER_WIDTH)		    q[$];

int i;

string message;
string formatted_number;

initial begin

// Clear queues 
trq_tx.delete();
trq_rx.delete();

// Transfer 1 - load from buffer
byte_buf = '{8'h00, 8'h11, 8'h22, 8'h33, 8'h44, 8'h55, 8'h66, 8'h77,
	8'h88, 8'h99, 8'hAA, 8'hBB, 8'hCC, 8'hDD, 8'hEE, 8'hFF,
	8'h10, 8'h11, 8'h12, 8'h13, 8'h14, 8'h45, 8'h16, 8'h17,
	8'h18, 8'h19, 8'h1A, 8'h1B, 8'h1C, 8'h1D, 8'h1E, 8'h1F};
		
	tx_tr = new();
	tx_tr.set_payload_from_data(byte_buf);
	tx_tr.set_gap(5);
	tx_tr.print_payload();
	
	// Load transfer into queue to compare at end of simulation
	trq_tx.push_back(tx_tr);
	
	// Create Packet
	p = new();
	// Add transfer to packet
	p.add_transfer_to_packet(tx_tr);

// Transfer 2 - load using queue
	q.delete();
	asbd = new(8'h00);
	asbd.set_tuser_value('hbcd);
	asb  = asbd;
	q.push_back(asb);
	asbd = new(8'h11);
	asb  = asbd;
	q.push_back(asb);
	asbd = new(8'h22);
	asb  = asbd;
	q.push_back(asb);
	asbd = new(8'h33);
	asb  = asbd;
	q.push_back(asb);
	asbd = new(8'h00);
	asb  = asbd;
	q.push_back(asb);
	asbd = new(8'h11);
	asb  = asbd;
	q.push_back(asb);
	asbd = new(8'h22);
	asb  = asbd;
	q.push_back(asb);
	asbd = new(8'h33);
	asb  = asbd;
	q.push_back(asb);
	asbd.set_tuser_value('h123);
	asb  = asbd;
	q.push_back(asb);
	asbd = new(8'h11);
	asb  = asbd;
	q.push_back(asb);
	asbd = new(8'h12);
	asb  = asbd;
	q.push_back(asb);
	asbd = new(8'h13);
	asb  = asbd;
	q.push_back(asb);
	asbd = new(8'h14);
	asb  = asbd;
	q.push_back(asb);
	//Position Byte
	asbp = new();
	asb  = asbp;
	q.push_back(asb);
	//Position Byte
	asbp = new();
	asb  = asbp;
	q.push_back(asb);
	asbd = new(8'h17);
	asbd.set_tuser_value(0);
	asb  = asbd;
	q.push_back(asb);

	ba = new[q.size()];
	for(i=0; i<q.size(); i++)
	begin
		ba[i] = q[i];	
	end

	tx_tr = new();
	tx_tr.set_tdest('h7);
	tx_tr.set_tid('h14);
	tx_tr.set_payload_from_bytes(ba);
    tx_tr.print_transfer_short();
	
// Load transfer into queue to compare at end of simulation
	trq_tx.push_back(tx_tr);

// Add transfer to packet
	p.add_transfer_to_packet(tx_tr);
	
// Transmit packet
	`bfm_tx.transmit_bfm.put_packet_for_transmit(p);


	while (`bfm_rx.receive_bfm.get_number_of_transfers_in_queue() != trq_tx.size())
	begin
		@(posedge axi4st_bfm_system_inst_clk_bfm_clk_clk);
	end
		
	formatted_number = num_formatter(`bfm_rx.receive_bfm.get_number_of_transfers_in_queue(), "d");
	message = {"  Number of transfers in receive queue: ", formatted_number};
	$display("*****");
	$display("%s", message);
	$display("*****");

	while (`bfm_rx.receive_bfm.transfer_available())
	begin
		rx_tr = `bfm_rx.receive_bfm.get_transfer_from_receive();
		rx_tr.print_transfer_long();
		trq_rx.push_back(rx_tr);
	end
	  

  foreach(trq_rx[i])
  begin
	 if (trq_rx[i].is_not_equal(trq_tx[i]))
	 begin
		formatted_number = num_formatter(i, "d");
		message = {" Transacation Failed: ", formatted_number};
		$display("*****");
		$display("%s", message);
		$display("*****");
	 end
	 else
	 begin
		formatted_number = num_formatter(i, "d");
		message = {" Transacation Passed: ", formatted_number};
		$display("*****");
		$display("%s", message);
		$display("*****");
	 end
  end
end

endmodule

The following shows the simulation output from this example:

Figure 16. Streaming BFM Platform Designer Example Simulation Output