Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vhpidirect: add 'quickstart/package' #7

Merged
merged 8 commits into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
quickstart/random,
quickstart/math,
quickstart/customc,
quickstart/package,
umarcor marked this conversation as resolved.
Show resolved Hide resolved
wrapping/basic,
wrapping/time,
linking/bind,
Expand Down
7 changes: 7 additions & 0 deletions doc/vhpidirect/examples/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,10 @@ When the required functionality is not available in pre-built libraries, custom
This example shows how to bind custom C functions in VHDL as either procedures or functions. Four cases are included: ``custom_procedure``, ``custom_procedure_withargs``, ``custom_function`` and ``custom_function_withargs``. In all cases, the parameters are defined as integers, in order to keep it simple. See :ref:`COSIM:VHPIDIRECT:Declarations` for further details.

Since either C sources or pre-compiled ``.o`` objects can be added, in C/C++ projects of moderate complexity, it might be desirable to merge all the C sources in a single object before elaborating the design.

:cosimtree:`package <vhpidirect/quickstart/package>`
****************************************************

If the auxillary VHPIDIRECT subprograms need to be accessed in more than one entity, it is possible to package the subprograms.
umarcor marked this conversation as resolved.
Show resolved Hide resolved

In this example 2 different entities use a C defined ``c_printInt(val: integer)`` subprogram to print two different numbers. The subprogram attribute is declared as foreign in the ``pkg`` package and a dummy body for it is defined in the ``pkg`` package body. The dummy body contains an explicit assert that will highlight any failures to call the VHPIDIRECT C function.
umarcor marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions vhpidirect/quickstart/package/caux.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include<stdio.h>
void printInt(int var){
printf("C-side print of int: %d\n", var);
}
24 changes: 24 additions & 0 deletions vhpidirect/quickstart/package/ent.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use work.pkg.all;

entity ent is
end ent;

architecture rtl_A of ent is
begin
process
begin
report "Entity1 calling c_print(1)." severity note;
c_printInt(1);
wait;
end process;
end rtl_A;

architecture rtl_B of ent is
begin
process
begin
report "Entity2 calling c_print(2)." severity note;
c_printInt(2);
wait;
end process;
end rtl_B;
11 changes: 11 additions & 0 deletions vhpidirect/quickstart/package/pkg.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package pkg is
procedure c_printInt(val: integer);
attribute foreign of c_printInt : procedure is "VHPIDIRECT printInt";
end package pkg;

package body pkg is
procedure c_printInt(val: integer) is
begin
assert false report "c_printInt VHPI" severity failure;
end;
end package body pkg;
14 changes: 14 additions & 0 deletions vhpidirect/quickstart/package/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env sh

set -e

cd $(dirname "$0")

echo "Analyze pkg.vhd ent.vhd tb.vhd"
ghdl -a pkg.vhd ent.vhd tb.vhd

echo "Build tb with caux.c"
ghdl -e -Wl,caux.c tb

echo "Execute tb"
./tb
15 changes: 15 additions & 0 deletions vhpidirect/quickstart/package/tb.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
entity tb is
end tb;

architecture arch of tb is
begin

entA : entity work.ent(rtl_A);
entB : entity work.ent(rtl_B);

process
begin
report "Testbench." severity note;
wait;
end process;
end;