I am trying to create a task that reads in a hex file (raw video data) and injects it axis stream. I am looking for some guidance on the System Verilog file operations work. My pixels are 16-bits but for now, all I am trying to do is read single bytes in from the file. Here is the code I have so far:
task task_file_to_axis(
input [1024*8-1:0] file_name,
input [31:0] frame_width,
input [31:0] frame_height,
input [31:0] num_frames,
output error
);
integer file_handler;
logic [31:0] pixel;
begin
file_handler = $fopen (file_name, "rb");
if(file_handler == 0) begin
$display("Failed to open file: %0s", file_name);
$stop;
end
$fread(pixel, file_handler);
$display("pixel read: %h", pixel);
end
endtask
All this does is read the first 4 bytes (because I made the pixel [31:0]). I am wondering how I can modify this to work in a loop. Is there someway to put an offset into the $fread command?
Here I tried to use $fscanf in a loop to store the values in a 2d array, but this doesn't work:
reg [15:0] frame[0:18432];
begin
file_handler = $fopen (file_name, "rb");
if(file_handler == 0) begin
$display("Failed to open file: %0s", file_name);
$stop;
end
for(int i = 0; i < 5; i++) begin
pixel = $fscanf(file_handler, "%h", frame[i] );
$display("pixel read: %h", frame[i]);
end
Any help is appreciated, thanks in advance!