forked from umarcor/ghdl-cosim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add packageless intvector generic example (umarcor#5 c)
- Loading branch information
1 parent
0d9977c
commit 07efdff
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <stdio.h> | ||
#define SIZE_ARRAY (sizeof(intArray)/sizeof(int)) | ||
|
||
int intArray[5]; | ||
int* getIntArr_ptr(){//function acts like a constructor so initialise the variable | ||
for (int i = 0; i < SIZE_ARRAY; i++) | ||
{ | ||
intArray[i] = 11*(i+1); | ||
} | ||
return intArray; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env sh | ||
|
||
set -e | ||
|
||
cd $(dirname "$0") | ||
|
||
echo "Analyze tb.vhd" | ||
ghdl -a tb.vhd | ||
|
||
echo "Build tb (with caux.c) [GHDL]" | ||
ghdl -e -Wl,caux.c tb | ||
|
||
echo "Execute tb (-gArraySize=5)" | ||
./tb -gArraySize=5 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
entity tb is | ||
generic( | ||
arraySize : integer := 1 | ||
); | ||
end entity tb; | ||
|
||
architecture RTL of tb is | ||
begin | ||
process | ||
type int_arr is array(0 to arraySize-1) of integer; | ||
type int_arr_ptr is access int_arr; -- represented C-side with int* | ||
|
||
impure function c_intArr_ptr return int_arr_ptr is | ||
begin | ||
assert false report "c_intArr_ptr VHPI" severity failure; | ||
end; | ||
attribute foreign of c_intArr_ptr : function is "VHPIDIRECT getIntArr_ptr"; | ||
|
||
variable c_intArr : int_arr_ptr := c_intArr_ptr; | ||
begin | ||
report "ArraySize Interface Generic: " & integer'image(arraySize); | ||
|
||
for i in 0 to arraySize-1 loop | ||
report "c_intArr[" & integer'image(i) & "] = " & integer'image(c_intArr(i)) & ". Set to: " & integer'image(-2*c_intArr(i)); | ||
c_intArr(i) := -2*c_intArr(i); | ||
end loop; | ||
|
||
wait; | ||
end process; | ||
|
||
end architecture RTL; |