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 all 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
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
vhpidirect/quickstart/random,
vhpidirect/quickstart/math,
vhpidirect/quickstart/customc,
vhpidirect/quickstart/package,
vhpidirect/quickstart/sharedvar,
vhpidirect/wrapping/basic,
vhpidirect/wrapping/time,
vhpidirect/linking/bind,
Expand All @@ -46,7 +46,7 @@ jobs:
vhpidirect/quickstart/random,
vhpidirect/quickstart/math,
vhpidirect/quickstart/customc,
vhpidirect/quickstart/package,
vhpidirect/quickstart/sharedvar,
vhpidirect/wrapping/basic,
vhpidirect/wrapping/time,
#vhpidirect/linking/bind, ! needs investigation, output of list-link seems to have wrong path format
Expand Down
28 changes: 28 additions & 0 deletions vhpidirect/quickstart/sharedvar/ent_08.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use work.pkg.all;

entity ent is
end ent;

architecture rtl_A of ent is
begin
process
begin
report "Entity1: c_Var is " & integer'image(c_Var.get);
report "Entity1: setting c_Var to 1." severity note;
c_Var.set(1);
c_printVar;
wait;
end process;
end rtl_A ;

architecture rtl_B of ent is
begin
process
begin
report "Entity2: c_Var is " & integer'image(c_Var.get);
report "Entity2: setting c_Var to 2." severity note;
c_Var.set(2);
c_printVar;
wait;
end process;
end rtl_B;
28 changes: 28 additions & 0 deletions vhpidirect/quickstart/sharedvar/ent_93.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use work.pkg.all;

entity ent is
end ent;

architecture rtl_A of ent is
begin
process
begin
report "Entity1: c_Var is " & integer'image(c_Var.all);
report "Entity1: setting c_Var to 1." severity note;
c_Var.all := 1;
c_printVar;
wait;
end process;
end rtl_A;

architecture rtl_B of ent is
begin
process
begin
report "Entity2: c_Var is " & integer'image(c_Var.all);
report "Entity2: setting c_Var to 2." severity note;
c_Var.all := 2;
c_printVar;
wait;
end process;
end rtl_B;
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);
}
39 changes: 39 additions & 0 deletions vhpidirect/quickstart/sharedvar/pkg_08.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package pkg is
type int_ptr is access integer;

impure function c_Int_ptr return int_ptr;
attribute foreign of c_Int_ptr : function is "VHPIDIRECT getInt_ptr";

procedure c_printVar;
umarcor marked this conversation as resolved.
Show resolved Hide resolved
attribute foreign of c_printVar : procedure is "VHPIDIRECT printInt";

type int_ptr_prot is protected
procedure set ( i: integer);
impure function get return integer;
end protected int_ptr_prot;

shared variable c_Var: int_ptr_prot;

end pkg;

package body pkg is
impure function c_Int_ptr return int_ptr is begin
assert false report "VHPI" severity failure;
end;

procedure c_printVar is
begin
assert false report "c_printVar VHPI" severity failure;
end;

type int_ptr_prot is protected body
variable var: int_ptr := c_Int_ptr;
procedure set ( i: integer) is begin
var.all := i;
end procedure;
impure function get return integer is begin
return var.all;
end get;
end protected body int_ptr_prot;
end pkg;

23 changes: 23 additions & 0 deletions vhpidirect/quickstart/sharedvar/pkg_93.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package pkg is
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;
umarcor marked this conversation as resolved.
Show resolved Hide resolved
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;
46 changes: 46 additions & 0 deletions vhpidirect/quickstart/sharedvar/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env sh

set -e

cd $(dirname "$0")

umarcor marked this conversation as resolved.
Show resolved Hide resolved

echo "VHDL 93: Analyze pkg_93.vhd ent_93.vhd tb.vhd"
ghdl -a --std=93 pkg_93.vhd ent_93.vhd tb.vhd

echo "Build tb_93 with main.c"
ghdl -e --std=93 -Wl,main.c -o tb_93 tb

echo "Execute tb_93"
./tb_93

echo "Clean tb_93"
rm work-obj*.cf tb_93 *.o
echo ""


echo "VHDL 08: Analyze pkg_08.vhd ent_08.vhd tb.vhd"
ghdl -a --std=08 pkg_08.vhd ent_08.vhd tb.vhd

echo "Build tb_08 with main.c"
ghdl -e --std=08 -Wl,main.c -o tb_08 tb

echo "Execute tb_08"
./tb_08

echo "Clean tb_08"
rm work-obj*.cf tb_08 *.o
echo ""


echo "VHDL 08 -frelaxed: Analyze pkg_93.vhd ent_93.vhd tb.vhd"
ghdl -a --std=08 -frelaxed pkg_93.vhd ent_93.vhd tb.vhd

echo "Build tb_08relaxed with main.c"
ghdl -e --std=08 -frelaxed -Wl,main.c -o tb_08relaxed tb

echo "Execute tb_08relaxed"
./tb_08relaxed

echo "Clean tb_08relaxed"
rm work-obj*.cf tb_08relaxed *.o
16 changes: 16 additions & 0 deletions vhpidirect/quickstart/sharedvar/tb.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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;