Skip to content

Commit

Permalink
vhpidirect: add 'quickstart/package'
Browse files Browse the repository at this point in the history
  • Loading branch information
radonnachie authored Apr 17, 2020
1 parent d394448 commit 95a760d
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
vhpidirect/quickstart/random,
vhpidirect/quickstart/math,
vhpidirect/quickstart/customc,
vhpidirect/quickstart/package,
vhpidirect/wrapping/basic,
vhpidirect/wrapping/time,
vhpidirect/linking/bind,
Expand All @@ -45,6 +46,7 @@ jobs:
vhpidirect/quickstart/random,
vhpidirect/quickstart/math,
vhpidirect/quickstart/customc,
vhpidirect/quickstart/package,
vhpidirect/wrapping/basic,
vhpidirect/wrapping/time,
#vhpidirect/linking/bind, ! needs investigation, output of list-link seems to have wrong path format
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 @@ -44,3 +44,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. This also makes it very easy to reuse the VHPIDIRECT declarations in different projects.

In this example 2 different entities use a C defined ``c_printInt(val: integer)`` subprogram to print two different numbers. Subprogram declaration requirements are detailed under the :ref:`COSIM:VHPIDIRECT:Declarations` section.
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;

0 comments on commit 95a760d

Please sign in to comment.