Writing binary data with Verilator

This is definitely one I know the masses are waiting to find out how to do. 🙂

So you are simulating a verilog design with Verilator and you want to output part of your design data to a file in binary format. (Example you're outputting an image.)

So lets say you want to do this:

  1.  
  2. fd=$fopen("somefile.dat", "wb");
  3. $fwrite ( fd, "%c", data );
  4.  

And you expect a file with binary data but instead you get a text file.

Well in Verilator you can embed c statements. So you can do this instead:

  1.  
  2. $c( "fwrite( (void*) &", data,", 1, 1, (FILE*)", fd, ");" );
  3.  

There. Fixed.

  1. No Comments



css.php