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

quickstart/sharedvar Example (Set Package shared variable) #4

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 10 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/sharedvar,
wrapping/basic,
wrapping/time,
linking/bind,
Expand Down
16 changes: 16 additions & 0 deletions vhpidirect/quickstart/sharedvar/ent1.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use work.pkg.all;
umarcor marked this conversation as resolved.
Show resolved Hide resolved

entity ent1 is
end ent1;

architecture rtl of ent1 is
begin
process
begin
report "Entity1 setting c_Var to 1." severity note;
c_Var.all := 1;
umarcor marked this conversation as resolved.
Show resolved Hide resolved
c_printVar;
wait;
end process ;
end rtl ; -- rtl

16 changes: 16 additions & 0 deletions vhpidirect/quickstart/sharedvar/ent2.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use work.pkg.all;

entity ent2 is
end ent2;

architecture rtl of ent2 is
begin
process
begin
report "Entity2 setting c_Var to 2." severity note;
c_Var.all := 2;
c_printVar;
wait;
end process ;
end rtl ; -- rtl

11 changes: 11 additions & 0 deletions vhpidirect/quickstart/sharedvar/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include<stdio.h>

int var;

int* getInt_ptr(){
return &var;
}

void printInt(){
printf("C-side print of int: %d\n", var);
}
21 changes: 21 additions & 0 deletions vhpidirect/quickstart/sharedvar/pkg.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package pkg is
radonnachie marked this conversation as resolved.
Show resolved Hide resolved
type int_ptr is access integer;

function c_Int_ptr return int_ptr;
attribute foreign of c_Int_ptr : function is "VHPIDIRECT getInt_ptr";
procedure c_printVar;
attribute foreign of c_printVar : procedure is "VHPIDIRECT printInt";

shared variable c_Var : int_ptr := c_Int_ptr;
end package pkg;

package body pkg is
function c_Int_ptr return int_ptr is
begin
assert false report "c_Int_ptr VHPI" severity failure;
end;
procedure c_printVar is
begin
assert false report "c_printVar VHPI" severity failure;
end;
end package body pkg;
14 changes: 14 additions & 0 deletions vhpidirect/quickstart/sharedvar/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")

umarcor marked this conversation as resolved.
Show resolved Hide resolved
echo "Analyze pkg.vhd ent1.vhd ent2.vhd tb.vhd"
umarcor marked this conversation as resolved.
Show resolved Hide resolved
ghdl -a pkg.vhd ent1.vhd ent2.vhd tb.vhd

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

echo "Execute tb"
./tb
22 changes: 22 additions & 0 deletions vhpidirect/quickstart/sharedvar/tb.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use work.pkg.all;
umarcor marked this conversation as resolved.
Show resolved Hide resolved

entity tb is
end tb;

architecture arch of tb is
component ent1
end component ent1;
component ent2
end component ent2;
begin

entA : component ent1;
entB : component ent2;

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

end;