File operation

Hi, I need to read the data from a file and make sure that i make transaction data of 128 from the collected data.

 file_read_data = $fopen("stimulus/data.txt", "r");
         
         while(!$feof(file_read_data)) begin 
            file_size_key = file_size_key + 1;
            qu.push_back($fgets(file_read_data));
         end
         
         for(int i=0;i<qu.size();i++) begin
            $display("The data in the queue = %h", qu[i]);
         end

I tried this logic but its not working.

In reply to shankar_logic:

What is your question?
It depends on the size of your file.
It seems some code is missing here. Please double check.

In reply to shankar_logic:
I’ve asked you several times to format your code with code tags. I have done that for you here - again.

I’ve also asked you several times explain what you mean by “not working”. Please explain by stated what you expect to happen versus what is actually happening.

My aim is to read the data from a file (which can be either a text file, binary file, character file or file containing hex values) and create transaction of 128 bits from that data and send them to the driver. I am facing issues since data can be of the variable length in the file.

In reply to shankar_logic:

It’s still not clear what you mean:
(1) what is a transaction of 128 bits?
(2) what means data of variable length?

Please explain.

I mean that i have a file which can be of any size (say 10 KB) and can be of any type (say text, hex, char, binary).

Now in the UVM environment,
In the sequence component, I have to read the contents of this file and collect 128 bits into either an array or queue and drive these 128 bits into the design. This is because the IP only accepts 128 bits of data during 1 clock cycle.

So, I am facing issues while implementing the logic.

In reply to shankar_logic:

I mean that i have a file which can be of any size (say 10 KB) and can be of any type (say text, hex, char, binary).

All files are binary, or a stream of 8-bit binary bytes. It is up to the user to interpret the bytes as ASCII codes for human readable characters. And then it up to the user to interpret the stream of characters as hexadecimal numbers. You use $fread, $fgets, or $fscanf depending on how you want to interpret the data.