Forum Discussion
Altera_Forum
Honored Contributor
14 years agoCheers Dave. I am doing the interactive testbench for now but I am having problems with reading the input data file. I have an array of size 153600 bytes that I save as follows in matlab:
fid = fopen('image_binval.bin', 'w');
fwrite(fid, data_image_1d,'uint8');
The main parts of my current systemverilog testbench file are shown below. I am just making sure the correct values are being read in. When I run it in modelsim, src_transaction.data shows the correct data values in the wavewindow until variable i reaches 57672. After that, it just displays a x in between red lines. I can't find where I am going wrong. Any help please?
`define NUMBER_OF_PIXEL_VALUES 153600
`timescale 1ns / 1ps
module sopc_system_tb();
import verbosity_pkg::*;
// 50MHz clock period
localparam time CLK50_PERIOD = (1.0e9/50.0e6)*1ns;
// Clock and reset
logic clk;
logic rstN;
// Avalon ST
typedef logic AvalonSTData_t;
reg storage_values ; //153600 values for 640x240 image
integer fileInput, r;
//the ST transaction is defined using SystemVerilog structure data type
typedef struct
{ int idles; //idle is not part of Avalon ST signal, it is used in BFM only
bit startofpacket;
bit endofpacket;
AvalonSTData_t data;
} transaction_struct;
transaction_struct src_transaction, snk_transaction;
int i, j;
// 50MHz system clock
initial
clk = 1'b0;
always
# (CLK50_PERIOD/2) clk <= ~clk;
// SOPC system -Set up the Dut
sopc_system
dut
(
.clk_0 (clk),
.reset_n (rstN)
);
// Stimulus
// ------------------------------------------------------------
initial
begin
// Initialize input and output text files
fileInput = $fopen("image_binval.bin", "r");
r = $fread(storage_values, fileInput, 0, `NUMBER_OF_PIXEL_VALUES-1);
// Initialize the BFM
// ------------------------------------------------------------
set_verbosity(`VERBOSITY);
`SRC.init();
`SNK.init();
rstN = 0;
# 50ns rstN <= 1;
// --------------------------------------------------------
$display("Simulation Start");
// --------------------------------------------------------
for (i = 0; i < `NUMBER_OF_PIXEL_VALUES; i++)
begin
@(posedge clk);
src_transaction.idles = 0;
src_transaction.data = storage_values;
if (i == 0)
src_transaction.startofpacket = 1;
else
src_transaction.startofpacket = 0;
if (i == `NUMBER_OF_PIXEL_VALUES-1)
src_transaction.endofpacket = 1;
else
src_transaction.endofpacket = 0;
end
end
endmodule