saritr
September 1, 2016, 1:56pm
1
I have a file with multiple lines with the following structere
r,ACFE13D5,00000000
w,FE1234AC,00000000
The mid value is hexa adreess, and the last value should be data with lengh of 32 bit(also hexa).
What is the simple way ro read such a file and get the values into the following transaction prototype:
direction_enum rw; // where- typedef enum { READ = 0, WRITE = 1 } direction_enum;
bit [31:0] addr;
bit [31:0] data;
In reply to saritr :
I think, SV does not have any system function to read a file with Mixed data type values.(e.g. int, hex, hex).
If you consider implementing file with only Hex or Binary values, then these are the functions.
$readmemb("file", variable_array[]); // To read binary values from file
$readmemh("file", variable_array[]); // To read hex values from file
dave_59
September 1, 2016, 3:27pm
3
*In reply to mayurkubavat : *Not correct. Use $fscanf
int fd; // file descriptor
byte mode;
int status;
fd = $fopen("filename","r");
status = $fscanf("%c,%h,%h",mode,addr,data);
if(status != 3) error;// you did not read in 3 values
case(mode)
"r": rw=READ;
"w": rw=WRITE;
default: error;
endcase
In reply to dave_59 :
Awesome! Thanks for pointing it out.
saritr
September 4, 2016, 8:37am
5
In reply to dave_59 :
Don’t you have to define error?
dave_59
September 4, 2016, 2:50pm
6
In reply to saritr :
I don’t have to, but you do :)
I’m only showing you how to do the file I/O. It’s up to you to write the code around it.