UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
2,100 Views
Registered: ‎08-24-2015

Writing binary File writing in vivado simulation through Verilog RTL code

Hi,

 

I'm reading a text (.txt) file hex data from directory using below command,

                a1=$fopen("test1.txt","r");

                a2=$fscanf(a1,"%h",reg1);

I'm writing a text (.txt) file to directory using below command,

                a1=$fopen("test1.txt","w");

                      $fdisplay(a1,"%h",reg2);

 

Here my question is how to read and write  RAW (.raw) files ...?

 

It's not working for 

                a1=$fopen("test1.raw","r");

                a2=$fscanf(a1,"%h",reg1);

 

                b1=$fopen("test2.raw","w");

                b2=$fdisplay(b1,"%h",reg1);

So,  how to read and write  RAW (.raw) files ...? give me any suggestions.

0 Kudos
8 Replies
Highlighted
Observer ramp69
Observer
2,074 Views
Registered: ‎03-14-2017

Re: Writing binary File writing in vivado simulation through Verilog RTL code

I am assuming RAW files are binary in which case you can try 

 

a1=$fopen("test1.txt","rb"); -- for reading 

a1=$fopen("test1.txt","wb"); -- for writing

 

-r

0 Kudos
2,063 Views
Registered: ‎08-24-2015

Re: Writing binary File writing in vivado simulation through Verilog RTL code

Hi,

File Open is successful but when writing data into file it's not working.

For reading it's working perfectly but in writing,
If I write ex:2 it's taking 32 in ascii type.

So how to write into bin/raw file's
If see in C it will be like below,
fwrite(buffer,size(ptr), number of bytes,fd)


So how to write in VERILOG... ?
0 Kudos
Moderator
Moderator
2,054 Views
Registered: ‎05-31-2017

Re: Writing binary File writing in vivado simulation through Verilog RTL code

Hi balashyamu@gmail.com,

 

Are you sure that you are getting output in ASCII form ?

As, you are using the below statement, the value of reg1 will get written in to the test2.raw file in the hexa decimal format because you are using %h.

  b1=$fopen("test2.raw","w");

   $fdisplay(b1,"%h",reg1);

 

Thanks & Regards,
A.Shameer

0 Kudos
2,047 Views
Registered: ‎08-24-2015

Re: Writing binary File writing in vivado simulation through Verilog RTL code

Hi,

Thank you.....,

Please see once again my question,

I would like to write data in a .bin/ .raw files
0 Kudos
1,976 Views
Registered: ‎08-24-2015

Re: Writing binary File writing in vivado simulation through Verilog RTL code

Hi,

When writing into file it's not wiriting binary...

So how to write as a binary fill .bin/.raw....?
0 Kudos
Moderator
Moderator
1,967 Views
Registered: ‎05-31-2017

Re: Writing binary File writing in vivado simulation through Verilog RTL code

Hi balashyamu@gmail.com,

 

I have tried to write the values in the .bin file and I am able to write the values. I have checked the file in notepad++, all the values are in binary. Below is the format that I have used to write the values

file = $fopen ("simu.bin", "w");---> Opens the file

 $fwrite (file, "%b %b\n", addra, valid); ---> Writes the values of addra and valid variables in binary form to file.

 

Thanks & Regards,

A.Shameer

0 Kudos
1,886 Views
Registered: ‎08-24-2015

Re: Writing binary File writing in vivado simulation through Verilog RTL code

Hi,

 

I want create a binary file which contains raw data.

 

But,

file = $fopen ("simu.bin", "w");---> Opens the file

 $fwrite (file, "%b %b\n", addra, valid); ---> Writes the values of addra and valid variables in binary form to file.

 

Above syntax will create normal text file but not .bin/.raw.

 

This .raw/.bin we can see in Hxeditor not in notepad++.

 

Ex:

Offset (h)   00   01  02  03

00000000  3E   45  2A  78   (here some crypt comes>>>>>)

 

So any suggestions.

 

 

0 Kudos
Scholar richardhead
Scholar
1,877 Views
Registered: ‎08-01-2012

Re: Writing binary File writing in vivado simulation through Verilog RTL code

try
file = $fopen ("simu.bin", "wb");---> Opens the file IN BINARY mode
0 Kudos