forked from ghdl/ghdl-cosim
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vhpidirect: add 'arrays/logicvector'
- Loading branch information
1 parent
9547159
commit 9c06dfd
Showing
5 changed files
with
175 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
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
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,52 @@ | ||
#include <stdio.h> | ||
#define SIZE_LOGIC_VEC_A (sizeof(logic_vec_A)/sizeof(char)) | ||
#define SIZE_LOGIC_VEC_B (sizeof(logic_vec_B)/sizeof(char)) | ||
|
||
static const char HDL_LOGIC_CHAR[] = { 'U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-'}; | ||
|
||
enum HDL_LOGIC_STATES { | ||
HDL_U = 0, | ||
HDL_X = 1, | ||
HDL_0 = 2, | ||
HDL_1 = 3, | ||
HDL_Z = 4, | ||
HDL_W = 5, | ||
HDL_L = 6, | ||
HDL_H = 7, | ||
HDL_D = 8, | ||
}; | ||
|
||
char logic_vec_A[3]; | ||
char logic_vec_B[6]; | ||
|
||
int getLogicVecSize(char returnA){ | ||
if(returnA) | ||
return SIZE_LOGIC_VEC_A; | ||
else | ||
return SIZE_LOGIC_VEC_B; | ||
} | ||
|
||
char* getLogicVecA(){ | ||
//The HDL_LOGIC_STATES enum is used | ||
logic_vec_A[0] = HDL_U; | ||
logic_vec_A[1] = HDL_X; | ||
logic_vec_A[2] = HDL_0; | ||
|
||
printf("A: 1D Array Logic Values [%ld]:\n", SIZE_LOGIC_VEC_A); | ||
for(int i = 0; i < SIZE_LOGIC_VEC_A; i++){ | ||
printf("[%d] = %c\t", i, HDL_LOGIC_CHAR[logic_vec_A[i]]); | ||
} | ||
printf("\n"); | ||
return logic_vec_A; | ||
} | ||
|
||
char* getLogicVecB(){ | ||
//The equivalent value of HDL_LOGIC_STATES is used | ||
printf("B: 1D Array Logic Values [%ld]:\n", SIZE_LOGIC_VEC_B); | ||
for(int i = 0; i < SIZE_LOGIC_VEC_B; i++){ | ||
logic_vec_B[i] = 8-i;//The last 'SIZE_LOGIC_VEC_B' HDL_LOGIC values, in reverse order. | ||
printf("[%d] = %c\t", i, HDL_LOGIC_CHAR[logic_vec_B[i]]); | ||
} | ||
printf("\n"); | ||
return logic_vec_B; | ||
} |
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,14 @@ | ||
#!/usr/bin/env sh | ||
|
||
cd "$(dirname $0)" | ||
|
||
set -e | ||
|
||
echo "Analyze tb.vhd" | ||
ghdl -a tb.vhd | ||
|
||
echo "Build tb (with caux.c)" | ||
ghdl -e -Wl,caux.c tb | ||
|
||
echo "Execute tb" | ||
./tb |
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,53 @@ | ||
library ieee; | ||
use ieee.std_logic_1164.all; | ||
|
||
entity tb is | ||
end; | ||
|
||
architecture arch of tb is | ||
begin | ||
|
||
process | ||
|
||
function getLogicVecSize(returnSizeOfA: boolean) return integer is | ||
begin assert false report "VHPIDIRECT getLogicVecSize" severity failure; end; | ||
attribute foreign of getLogicVecSize : function is "VHPIDIRECT getLogicVecSize"; | ||
|
||
subtype logic_vec_a_t is std_logic_vector(0 to getLogicVecSize(true)-1); | ||
type logic_vec_a_ptr_t is access logic_vec_a_t; | ||
|
||
subtype logic_vec_b_t is std_ulogic_vector(0 to getLogicVecSize(false)-1); | ||
type logic_vec_b_ptr_t is access logic_vec_b_t; | ||
|
||
function getLogicVecA return logic_vec_a_ptr_t is | ||
begin assert false report "VHPIDIRECT getLogicVecA" severity failure; end; | ||
attribute foreign of getLogicVecA : function is "VHPIDIRECT getLogicVecA"; | ||
|
||
function getLogicVecB return logic_vec_b_ptr_t is | ||
begin assert false report "VHPIDIRECT getLogicVecB" severity failure; end; | ||
attribute foreign of getLogicVecB : function is "VHPIDIRECT getLogicVecB"; | ||
|
||
variable g_logic_vec_a: logic_vec_a_ptr_t := getLogicVecA; | ||
variable g_logic_vec_b: logic_vec_b_ptr_t := getLogicVecB; | ||
|
||
constant logicArray: std_logic_vector(0 to 8) := ('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-'); | ||
|
||
begin | ||
|
||
report "g_logic_vec_a'length: " & integer'image(g_logic_vec_a'length) severity note; | ||
|
||
for x in g_logic_vec_a'range loop | ||
report "Asserting VecA [" & integer'image(x) & "]: " & std_logic'image(g_logic_vec_a(x)) severity note; | ||
assert g_logic_vec_a(x) = logicArray(x) severity failure; | ||
end loop; | ||
|
||
report "g_logic_vec_b'length: " & integer'image(g_logic_vec_b'length) severity note; | ||
|
||
for x in g_logic_vec_b'range loop | ||
report "Asserting VecB [" & integer'image(x) & "]: " & std_logic'image(g_logic_vec_b(x)) severity note; | ||
assert g_logic_vec_b(x) = logicArray(8-x) severity failure; | ||
end loop; | ||
|
||
wait; | ||
end process; | ||
end; |