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.
Each line can be in different lenght.
The stracture of the lines:
len, cmd, addr, data, data, data, data, ……., \n
For example: “3,write,A0001000,00000000,00012000,A0000000,C0000000,00B00000 \n”
here is the code that i have written. I’m not sure if the assigmnent to the transaction should be here, or should I write a function in the transaction which will do it.
I attached the transaction code and the sequence code:
transaction
typedef enum {READ = 0, WRITE = 1} direction_enum;
//----------------------------------------------------------------------
//Transaction
//----------------------------------------------------------------------
class axi_transaction extends uvm_sequence_item();
bit id = 0; //const
bit [31:0] addr;
bit [2:0] size = 0'b100;//const
direction_enum rw;
bit [31:0] transfers [$];
//factory registration
`uvm_object_utils_begin(axi_transaction)
`uvm_object_utils_end
//constructor
function new(string name = "axi_transaction");
super.new(name);
endfunction: new
endclass: axi_transaction
sequence:
//----------------------------------------------------------------------
//Sequence
//----------------------------------------------------------------------
class axi_sequence extends uvm_sequence#(axi_transaction);
`uvm_object_utils(axi_sequence)
//new
function new (string name = "axi_sequence");
super.new(name);
endfunction: new
task body();
int file_p, temp, len, success;
int count;
byte mode;
string str;
logic [31:0] data;
axi_transaction ax_trx;
file_p = $fopen("commands_file.txt", "r");
//in case file doesn't exist
if (!file_p)
begin
`uvm_error("ERROR:"," FILE OPENED FAILED");
end
//read file
while (!$feof)
begin
temp = $fgets(str, file_p);
ax_trx = axi_transaction::type_id::create(.name("ax_trx"), .contxt(get_full_name()));
start_item(ax_trx);
temp = $sscanf(str, "%d", len);
temp = $sscanf(str, "%c", mode);
case(mode)
"r": ax_trx.rw = READ;
"w": ax_trx.rw = WRITE;
default: success = 0;
endcase //case(mode)
temp = $sscanf(str,"%h", ax_trx.addr);
for (int i = 0; i < len; i++) begin
temp = $sscanf(str,"%h", ax_trx.transfers[i]);
end
end
finish_item(ax_trx);
endtask: body
endclass: axi_sequence