-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
138 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,20 @@ | ||
library ieee; | ||
use ieee.std_logic_1164.all; | ||
use ieee.numeric_std.all; | ||
|
||
entity adder is | ||
port | ||
( | ||
nibble1, nibble2 : in unsigned(3 downto 0); | ||
sum : out unsigned(3 downto 0); | ||
carry_out : out std_logic | ||
); | ||
end entity adder; | ||
|
||
architecture behavioral of adder is | ||
signal temp : unsigned(4 downto 0); | ||
begin | ||
temp <= ("0" & nibble1) + nibble2; | ||
sum <= temp(3 downto 0); | ||
carry_out <= temp(4); | ||
end architecture behavioral; |
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,25 @@ | ||
#! /bin/sh | ||
|
||
. ../../testenv.sh | ||
|
||
analyze adder.vhdl | ||
elab adder | ||
|
||
if ghdl_has_feature adder vpi; then | ||
if [ "$OS" = "Windows_NT" ]; then | ||
# Need to put the directory containing libghdlvpi.dll in the path. | ||
vpi_lib=`$GHDL --vpi-library-dir | sed -e 's!\\\\!/!g' -e 's!^C:!/C!g'` | ||
echo vpi_lib: $vpi_lib | ||
PATH="$PATH:$vpi_lib" | ||
fi | ||
|
||
$GHDL --vpi-compile -v gcc -c vpi_plugin.c | ||
$GHDL --vpi-link -v gcc -o vpi_plugin.vpi vpi_plugin.o | ||
|
||
simulate adder --vpi=./vpi_plugin.vpi | ||
|
||
rm -f vpi_plugin.vpi vpi_plugin.o | ||
fi | ||
clean | ||
|
||
echo "Test successful" |
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,93 @@ | ||
#include<vpi_user.h> | ||
#include<inttypes.h> | ||
#include<stdio.h> | ||
|
||
//#define STOP_ITERATION 1000000000 // Initial value | ||
#define STOP_ITERATION 10000 | ||
|
||
uint32_t iteration = 0; | ||
|
||
|
||
PLI_INT32 start_cb(p_cb_data); | ||
PLI_INT32 end_cb(p_cb_data); | ||
PLI_INT32 rw_cb(p_cb_data); | ||
PLI_INT32 ro_cb(p_cb_data); | ||
PLI_INT32 delay_rw_cb(p_cb_data); | ||
PLI_INT32 delay_ro_cb(p_cb_data); | ||
|
||
void register_cb(PLI_INT32(*f)(p_cb_data), | ||
PLI_INT32 reason, | ||
int64_t cycles){ | ||
|
||
s_cb_data cbData; | ||
s_vpi_time simuTime; | ||
if (cycles < 0){ | ||
cbData.time = NULL; | ||
} else { | ||
cbData.time = &simuTime; | ||
simuTime.type = vpiSimTime; | ||
simuTime.high = (PLI_INT32) (cycles >> 32); | ||
simuTime.low = (PLI_INT32) (cycles & 0xFFFFFFFF); | ||
} | ||
|
||
cbData.reason = reason; | ||
cbData.cb_rtn = f; | ||
cbData.user_data = 0; | ||
cbData.value = 0; | ||
|
||
vpi_register_cb(&cbData); | ||
} | ||
|
||
void entry_point_cb() { | ||
register_cb(start_cb, cbStartOfSimulation, -1); | ||
register_cb(end_cb, cbEndOfSimulation, -1); | ||
register_cb(delay_ro_cb, cbAfterDelay, 0); | ||
} | ||
|
||
PLI_INT32 start_cb(p_cb_data data){ | ||
(void) data; | ||
printf("Start of simulation \n"); | ||
return 0; | ||
} | ||
|
||
PLI_INT32 end_cb(p_cb_data data){ | ||
(void) data; | ||
printf("End of simulation %u \n", iteration); | ||
return 0; | ||
} | ||
|
||
|
||
PLI_INT32 rw_cb(p_cb_data data){ | ||
(void) data; | ||
if(iteration < STOP_ITERATION) { | ||
register_cb(delay_ro_cb, cbAfterDelay, 1); | ||
} else { | ||
vpi_control(vpiFinish, 0); | ||
} | ||
|
||
iteration++; | ||
return 0; | ||
} | ||
|
||
PLI_INT32 ro_cb(p_cb_data data){ | ||
(void) data; | ||
register_cb(delay_rw_cb, cbAfterDelay, 0); | ||
return 0; | ||
} | ||
|
||
PLI_INT32 delay_rw_cb(p_cb_data data){ | ||
(void) data; | ||
register_cb(rw_cb, cbReadWriteSynch, 0); | ||
return 0; | ||
} | ||
|
||
PLI_INT32 delay_ro_cb(p_cb_data data){ | ||
(void) data; | ||
register_cb(ro_cb, cbReadOnlySynch, 0); | ||
return 0; | ||
} | ||
|
||
void (*vlog_startup_routines[]) () = { | ||
entry_point_cb, | ||
0 | ||
}; |