ghdl / ghdl-cosim

Documentation with code examples about interfacing VHDL with foreign languages and tools through GHDL
https://ghdl.github.io/ghdl-cosim
Apache License 2.0
46 stars 9 forks source link

VHPIDIRECT: How to send/receive top level signals to DUT #31

Closed r2com closed 1 year ago

r2com commented 1 year ago

First let me tell you my targeted intention with GHDL/co-sim: I want to do advanced verification of my large VHDL design in software with c++. So the idea is, I have the most top level synthesizeable design file: top.vhd, and there won't be any VHD testbench above it. That top.vhd will be written and read the data from its top pins by a software coroutine.

Alright so I went through a long route of building the gcc backend version of GHDL in Linux (Debian), ghdl is working.

My next thing is to run some starter example. I went ahead and studied the shghdl example from this co-sim repo and decided that the proper elaboration route for me would be using gcc as entry point (Linking GHDL object files to C).

I do this:

ghdl -a tb.vhd
gcc main.c -o main -ldl
ghdl --bind tb
gcc test.c -shared -Wl,`ghdl --list-link tb` -Wl,--version-script=./test.ver -Wl,-u,ghdl_main -o tb.lib
./main 

And I get the output:

Hello Something!
tb.vhd:7:5:@0ms:(report note): Hello shared/shghdl!
ghdl_main return: 0
tb.vhd:7:5:@0ms:(report note): Hello shared/shghdl!
ghdl_main return: 0
tb.vhd:7:5:@0ms:(report note): Hello shared/shghdl!
ghdl_main return: 0

Which is great, which means its all working. However, printing from top VHD file is cool, but now I need to start doing the real scenario which for me is: actually start driving data to the input pins of top.vhd and reading data from output pins of top.vhd (in this current simple example that file is tb.vhd, in my case I plan it to be non-testbench type synthesizeable vhdl file)

Can I have some hint on how to do it? would be nice to have similar to shghdl but more practical example.

So am I supposed to send/receive data through the ghdl_main function, or what is the proper mechanism?

r2com commented 1 year ago

anyway, it seems that for what I'm interested in, the VPI would be a way to go for this usage scenario. feel free to close this issue if you agree.