Hi,Originally posted in cdnusers.org by prasad_vc
I need some help with file read. Here's the problem statement.
I want to read an file at runtime which will give me the size of the image and the actual data into an dynamic array, imgData.
I tried to use the code below, but i get the wrong result.
Can i use $readmemh system tasks to perform the same operation? This
should give me the exact file size and i don't want an arbitrary size
array, since i'll be packing the data and passing it over an interface.
int imgSize, status;
rand image_type imgType;
reg [7:0] imgData ;
integer file, start, count;
reg [7:0] mem[0:200_000] ;
YUV422 : begin
file = $fopen("YUV422.txt","rb");
if (file != 0) begin
$display("Error Opening YUV422 File.");
end // if (file
imgSize = $fread(mem,file);
imgData = new[imgSize] (mem);
$display("Number of Elements in Image = ",imgSize);
for(int i=0; i<= imgSize;i++) begin
$display("Data at Locatin [%h] is %h", i, imgData[i]);
default: $display("No Where!");