1

I have written system verilog code for reading data from an image file (800*600 -
*.raw). The file actually contains 800 * 600 * 3 bytes. But my code can only read upto almost half the data. After that the read data seems to be "00". Valuable suggestions for resolving this is appreciated..

My code is as follows.


//`define EOF 32'hFFFF_FFFF
//`define EOF \n

reg [7:0]data_byte;

class input_video_IF;
int count;
integer input_file, fread_return,output_file;


function new ();

input_file = $fopen("test_800.raw","r");
if(input_file)
begin
$display("File OPENED");
end
else
begin
$display("File error");
end

output_file = $fopen("output_800.raw", "w");
endfunction:new

task image_file_read();
count = 0;
//while (!$feof(input_file))
while(count != 1440000)
begin
fread_return = $fread(data_byte,input_file);
count++;
$display("%d %h",count,data_byte);
//$fwrite(output_file,data_byte);
end
$finish;
$fclose(input_file);
endtask : image_file_read

endclass

program Image_read_test;
int input_file;
input_video_IF In_IF = new();
initial

In_IF.image_file_read();


endprogram
  • Some minor comments about your code: `data_byte` should not be defined outside of the class. `count` doesn't need to be a class field. Both of these two variables could be defined locally inside the `image_file_read()` task. Also, `image_file_read()` doesn't consume time, so maybe it should rather be a function. – Tudor Timi Aug 20 '14 at 12:59
  • Are you sure you have a file that's big enough? – Tudor Timi Aug 20 '14 at 13:36

0 Answers0