hi,
I have a string in below format and i would like to read the final value of the string from the system verilog. can someone help me how to do it using sscanf or is there any other way to do it easily?
i just want the value 0x1 to be read and assign it to some variable. how can i do that?
i tried this way:
bit [31:0] value;
string str1= “sys.hir00.mbo01.fir_hid.nn0.hero0.nd.gb.crappy.REG0.FIELD”
int fd = $fopen (“rndcfg.cfg”, “r”);
if (fd == 0) begin
$display (“ERROR: opening file”);
$finish;
end
while (!$feof(fd)) begin
$fgets (line, fd); //Get entire line
if (match(line,str1)) begin
$fwrite(rv,“%s\n”,line);
$sscanf(line, “%s, %s, %s, %x”, first, hierarchy, nob, &value);
$display(“%s, %s, %s, %x”,first, hierarchy, nob, value);
end
end
in the above code match is my own function. (which is working totally fine)
is there a way i can get 0x1 to the variable value. – the above code doesnt seems to be working. when i am printing value… its not showing 0x1.
It would be very helpful if you post a complete, self-contained example which can be run. This ensures that others see exactly what the issue is.
Are you trying to read a string name of a register and then assign a value to that register? If so, you can not do that in SystemVerilog. You would have to compare the string to a known value and then assign the register appropriately.
If this is not what you want to accomplish, you will have to explain your issue more clearly.
i have a file which would contain the below format:
-sys.hir00.mbo01.fir_hid.nn0.hero0.nd.gb.crappy.REG0 0x00000149
// sys.hir00.mbo01.fir_hid.nn0.hero0.nd.gb.crappy.REG0.FIELD [2:0] 0x1
// sys.hir00.mbo01.fir_hid.nn0.hero0.nd.gb.crappy.REG0.FIELD1 [5:3] 0x1
// sys.hir00.mbo01.fir_hid.nn0.hero0.nd.gb.crappy.REG0.FIELD2 [7:6] 0x1
// sys.hir00.mbo01.fir_hid.nn0.hero0.nd.gb.crappy.REG0.FIELD3 [31:8] 0x1
now my requirement is to read this file and get the value of either the REG0 which is 0x00000149 or if i want i should be able to get FIELD1 value which 0x1.
i would simply call from my function as GetValue(“path”)
Ex: GetValue(“sys.hir00.mbo01.fir_hid.nn0.hero0.nd.gb.crappy.REG0”); → this should return the entire value of the register which is 0x00000149
or
GetValue(“sys.hir00.mbo01.fir_hid.nn0.hero0.nd.gb.crappy.REG0.FIELD1”); → this should return the value of the field which is 0x1.
Currently i am able to open the file and match the string in the file and get the entire line, but not able to get the value of the reg or field.
If this is part of the UVM register model, it already provides a string to register name lookup.
You can tool specific commands or the PLI to access identifiers using a string. This forum is not for discussing tool specific issues, and using the PLI is beyond the scope of what we can get into in this forum