good day!
can anybody tell me, how to read data from binary file not from the beginnig, but partly? for example, i have a file, which consists data for 8 pixels(8 bits per pixel), but i want to load into my design data for pixels number 2, 3 and 4. how can i do such a thing in SV?
Hi,
You can use $readmemb system task which read/load data from txt file into array(Section 21.4 from IEEE 1008-2009)
eg :
logic [7:0] mem [0:15]
string file;
initial begin
file = “inputfile.txt”
$readmemb(file,mem);
end
Now you can use any bits of your pixel by accessing mem array.
eg :
mem[1] //2nd
mem[2] //3rd
mem[3] //4th
Regards,
Vinay Jain
See sections 21.3.4 Reading data from a file and 21.3.5 File positioning of the IEEE 1800-2012 LRM. Look up $fscanf and $fseek. If your data is not too large, it might be easier to read in all the data into an unpacked array with $fread, and then index into the array for the pixel value you want.