Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I suggest approaching it like this:</p> <ol> <li>figure out your C/Verilog interface</li> <li>implement the audio file access with that interface in mind, but not worrying about VPI</li> <li>implement the C/Verilog glue using VPI</li> </ol> <p>The interface can probably be pretty simple. One function to open the audio file and specify any necessary parameters (sample size, big/little endian, etc...), and another function returns the next sample. If you need to support reading from multiple files in the same simulation, you'll need to pass sort of handle to the PLI functions to identify which file you're reading from.</p> <p>The Verilog usage could be as simple as:</p> <pre><code>initial $OpenAudioFile ("filename"); always @(posedge clk) audio_data &lt;= $ReadSample; </code></pre> <p>The image-vpi sample looks like a reasonable example to start from. The basic idioms to use in the C code are:</p> <p><strong>Argument access</strong></p> <pre><code>// Get a handle to the system task/function call that invoked your PLI routine vpiHandle tf_obj = vpi_handle (vpiSysTfCall, NULL) // Get an iterator for the arguments to your PLI routine vpiHandle arg_iter = vpi_iterate (vpiArgument, tf_obj) // Iterate through the arguments vpiHandle arg_obj; arg_obj = vpi_scan (arg_iter); // do something with the first argument arg_obj = vpi_scan (arg_iter); // do something with the second argument </code></pre> <p><strong>Retrieving values from Verilog</strong></p> <pre><code>s_vpi_value v; v.format = vpiIntVal; vpi_get_value (handle, &amp;v); // value is in v.value.integer </code></pre> <p><strong>Writing values to Verilog</strong></p> <pre><code>s_vpi_value v; v.format = vpiIntVal; v.value.integer = 0x1234; vpi_put_value (handle, &amp;v, NULL, vpiNoDelay); </code></pre> <p>To read or write values larger than 32 bits, you will need to use <code>vpiVectorVal</code> instead of <code>vpiIntVal</code>, and de/encode a s_vpi_vector structure.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload