Jump to content

Constraining a dynamic array in UVM sequence


Recommended Posts

Hi

i will start by explaining my requirement first . Using a UVM sequence my objective is to read data patterns from a file in hexadecimal format line by line and then feed/constrain the data field of my "trans" with data i read.

I am also unaware of the data length as that too can be variable and has to be determined dynamically

here is the code that i have written and that is not working . Need help/hint on same

===================================

virtual task body();

integer file_p, temp;

integer count =0;

reg [7:0] data;

string str;

file_p = $fopen("file.txt","r");

if (!file_p)

begin

`uvm_error("ERROR :","FILE OPENED FAILED :: NO SUCH FILE OR BAD FILE NAME");

end

else

begin

while(!$feof)

begin

temp = $fscanf(file_p,"%s",str);

count = count++;

end

end

$display("Value of Count = %d",count);

`uvm_do_with(trans, {

Addr == addr;

Direction == write;

Length == count;

for (int i = 0; i < count; i++) begin

$fscanf(file_p,"%s",data);

Data == data; // Data is dynamic array

end

})

endtask : body

===========================

Can anybody tell what is wrong i am doing here

i am alos open with same scenario being generated by uvm_create/uvm_send

Thanks

niks007

Edited by niks007
Link to comment
Share on other sites

Try this one, It should work

for (int i = 0; i < count; i++) begin

$fscanf(file_p,"%s",data);

Data_tmp == data; // Data_tmp is dynamic array

end

`uvm_do_with(trans, {

Addr == addr;

Direction == write;

Length == count;

foreach(Data)

Data inside {Data_tmp};

})

Link to comment
Share on other sites

Here is another way to try.

Why not initialize one global data_tmp[] in testbench layer? Then your sequence will see the data_tmp[].

Then you need not consume the "$fscanf(file_p,"%s",data);" in body of seq.

If your data is very large , and need more time.

You also need add sync signal in vbus_if, and do cfg.wait_for_init_competed() before `uvm_do_with in the seq

Edited by Roman
Link to comment
Share on other sites

It would help if you could show the exact format of the file. You say you want to read a hexadecimal formatted file line by line, yet you are reading entire file as a string. Why not use $fgets to read the file a line at a time, and then use $sscanf to convert each line. You can do this just before the `uvm_do

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...