[SOLVED] Verilog read-file task, unexpected behaviour

Status
Not open for further replies.

wtr

Full Member level 5
Joined
May 1, 2014
Messages
299
Helped
29
Reputation
58
Reaction score
25
Trophy points
1,308
Activity points
4,108
Hello all,

The following code is

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
task TSK_READ_FILE;
    integer scan_file;
    reg [7:0] w_or_r;
    integer len;
    reg [31:0] addr; 
    reg [31:0] data;
    integer i;
    begin
        while (!$feof(`ORIGIN.TSK_OPENR_FILE.data_file)) begin
            scan_file = $fscanf(`ORIGIN.TSK_OPENR_FILE.data_file, "%s %d %h %h\n", w_or_r, len, addr, data);
            if (w_or_r == "w")
            begin
                
                // is designed to always be length 1, 
                // data needs to be muti-dimensinal otherwise
                for (i=0; i<len; i=i+1) 
                begin
                    `ORIGIN.DATA_STORE[3+4*i] = data[31:24];
                    `ORIGIN.DATA_STORE[2+4*i] = data[23:16];
                    `ORIGIN.DATA_STORE[1+4*i] = data[15:8];
                    `ORIGIN.DATA_STORE[0+4*i] = data[7:0];
                end
 
                // TSK_TX_MEMORY_WRITE_32 
                //--  Tag (7:0) tag_;
                //--  Traffic Class [2:0] tc_;
                //--  Length (in DW)[10:0] len_;
                //--  Address[31:0] addr_;
                //--  Last DW Byte Enable[3:0] last_dw_be_;
                //--  First DW Byte Enable[3:0] first_dw_be_;
                //--  Poisoned Data: Payload is invalid if set ep_;
                `ORIGIN.TSK_TX_MEMORY_WRITE_32(
                    `ORIGIN.DEFAULT_TAG,
                    `ORIGIN.DEFAULT_TC, 
                    len,
                    addr,
                    4'h0,
                    4'hF,
                    1'b0);
 
                $display("[%t] : Writing to addr %x is %x", $realtime, addr, {`ORIGIN.DATA_STORE[3],`ORIGIN.DATA_STORE[2],`ORIGIN.DATA_STORE[1],`ORIGIN.DATA_STORE[0]});
                `ORIGIN.TSK_TX_CLK_EAT(100);
                `ORIGIN.DEFAULT_TAG = `ORIGIN.DEFAULT_TAG + 1;
                `ORIGIN.TSK_WRITEW_FILE(addr,data[31:0]);
            end
            else if (w_or_r == "r")
            begin
                `ORIGIN.P_READ_DATA = 32'hffff_ffff;
                //fork
                //TSK_TX_MEMORY_READ_32;
                //-- Tag                 [7:0]    tag_;         
                //-- Traffic Class       [2:0]    tc_;          
                //-- Length (in DW)      [10:0]   len_;         
                //-- Address             [31:0]   addr_;        
                //-- Last DW Byte Enable [3:0]    last_dw_be_;  
                //-- First DW Byte Enable[3:0]    first_dw_be_; 
                `ORIGIN.TSK_TX_MEMORY_READ_32(
                    `ORIGIN.DEFAULT_TAG,
                    `ORIGIN.DEFAULT_TC,
                    len,
                    addr,
                    4'h0,
                    4'hF);
                `ORIGIN.TSK_WAIT_FOR_READ_DATA;
                `ORIGIN.TSK_TX_CLK_EAT(10);
                `ORIGIN.TSK_WRITER_FILE(addr,`ORIGIN.P_READ_DATA);
                //join
                // Only works based on previous
                $display("[%t] : Readback from addr %x is %x   expected: %x", $realtime, addr, `ORIGIN.P_READ_DATA, data);
 
            end
            else if (w_or_r == "#")
            begin
                $display("Comment detected");
            end
            else
            begin
                $display("ERROR, the stimulus file does not specify if the line is read/write/comment");
            end
        end
    end
endtask



Where file read in is
Code:
# FPGA Compile info
r 1 00000140 00000000
r 1 00000160 00000000
r 1 00000180 00000000
r 1 000001A0 00000000
# Next comment

The output in the write out file is as expected, however the transcript window is flawed. I'm getting the following in modelsim transcript window.


The problem is after the comment detected, the if statement seems to run through every instance of the comment & generate the "ERROR, the stimulus file ..." . Now I was hoping the fscanf read the entire line in, however now i'm of the opinion that it's only reading in sections that match the % <- character & therefore it has to do multiple scans for %s string to be traversed until the next line.

Does anyone know of a way I can clean up my transcript window for evidence logging?

- - - Updated - - -

I think I found the answer to my problem.

When in the
Code:
else if (w_or_r == "#")
            begin
                $display("Comment detected");
            end
section, all I need to do is place
Code:
else if (w_or_r == "#")
            begin

                //$display("Comment detected");
                scan_file = fgets(str, `ORIGIN.TSK_OPENR_FILE.data_file);
            end

This way I'll read to the end of the line, when at the condition comment detected.

Problem I have now is, what happens with str overflows (I've assigned it to reg of size [256*8:0]).

Is there a more elegant way that will read, regardless of size of scan until end of line?

Regards,
Wes
 

I would just fgetc the first character and determine if you are looking at a comment line (#) a read or write line (r/w) and only parse the lines with an fscanf if the line is a r/w line. Right now it tries to parse lines that are marked # or r/w in the same way.

Your current fix is a bandaid.

You could use an SV sting type instead to avoid the string overflow.
 
Reactions: wtr

    wtr

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…