Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Why Verilog $fread Only Read til 1658 Byte?

Status
Not open for further replies.

jasonkee111

Junior Member level 3
Joined
Feb 8, 2009
Messages
28
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,501
I face an issue of $fread only read up to 1658 Byte. The snippet of code is below:

Code:
    byte   TempDataBY[2000];

    FileID      = $fopen(BinFile.rbf, "r");
    if (FileID == NULL)
        $error ("Error Open File: %s", FileName);

    while (!$feof(FileID)) begin
        ReadStatus  = $fread(TempDataBY,FileID);
    end

    $display("FileID:%d, End of File", FileID);

Pls advice. Thanks.
 

I had to add a bunch of stuff and correct the typos of missing "" around the filename, but it worked for me. All the data from the file BinFile.rbf ends up in TempDataBY.


Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module test;
  
  localparam NULL = 0;
  integer FileID, ReadStatus;
  reg [8*20-1:0] FileName; //forced to use this instead of string (Vivado simulator does not support SV string)
 
  initial begin : file_io
    byte   TempDataBY[3000];
 
    FileID = $fopen("BinFile.rbf", "r");
    if (FileID == NULL) $error ("Error Open File: %s", FileName);
 
    while (!$feof(FileID)) begin
        ReadStatus  = $fread(TempDataBY,FileID);
    end
 
    // added to check the data loaded into TempDataBY by the $fread.
    for (int i=0;i<3000;i++) begin
      $display ("TempDataBY[%d] = %h", i, TempDataBY[i]);
    end
 
    $display("FileID:%d, End of File", FileID);
    $fclose(FileID);
  end
 
endmodule



I did end up getting a single warning from the simulator:
WARNING: Insufficient data from the input file for $fread
which doesn't make sense as I increased the size of the file to 4000 bytes. I started with 2000 bytes exactly then changed it to 2002 (used a text file of 0-9 repeated (ends with CR-LF )).

Not sure why you're not reading the entire binary file in. Are you sure the file isn't 1658 bytes in length?
 

Hi

i am sure that my binary file is more than 2kB. It is fine when i am using fscanf using the same method but the data stored in normat .txt. Anyway, i am using mentor questa and i have file an service request to them.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top