Buffer¶
This example shows how to use cosim.vhpidirect.VHPIDIRECT
(see VHPIDIRECT to interact with VUnit’s internal string_ptr
/byte_vector_ptr
and/or integer_vector_ptr
, from C and/or Python.
run.py
: supports a custom CLI option,--build
, that will setVU.set_sim_option("ghdl.elab_e", True)
.cosim.vhpidirect.VHPIDIRECT.bridge()
is used to enable external mode support forstring_ptr
and integer_vector_ptr (see Data Types).cosim.vhpidirect.VHPIDIRECT.include()
is used to build C sources with the provided C API/headers.cosim.vhpidirect.VHPIDIRECT.verscript()
is used to provide a version script that matches the functions in the C API.The
post_func
provided by VHPIDIRECT (seecosim.vhpidirect.VHPIDIRECT.post_func()
) is used to save in subdir vunit_out/cosim the CLI args that correspond to each testbench.
corun.py
: allows to dynamically load and run any of the simulation binaries built withrun.py
. Given a testbench name, it finds the corresponding binary and arguments JSON file. Then, it is loaded dynamically and data buffers allocated in Python are shared with the simulation.
Example session:
# python3 run.py --build -v
...
# ls vunit_out/cosim/
tb_external_byte_vector.json tb_external_integer_vector.json tb_external_string.json
# python3 corun.py tb_external_byte_vector
...
Note
GHDL with mcode backend does NOT generate executable binaries. In order to use the two-step workflow, eithe LLVM or GCC backends need to be used.
Note
corun.py
depends on cosim.utils
, which requires some additional dependencies. File requirements.txt
can be used to install all of them at once.