From 07791c71f368ceae43aa2fe2181fad61a2dbfc69 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Wed, 6 Mar 2024 21:17:04 +0000 Subject: [PATCH] Fix typo introduced by b52c576. Issue #857 --- src/rt/model.c | 2 +- src/vhpi/vhpi-model.c | 12 ++-- src/vhpi/vhpi-util.c | 1 + test/regress/testlist.txt | 1 + test/regress/vhpi12.vhd | 19 +++++ test/vhpi/Makemodule.am | 3 +- test/vhpi/vhpi12.c | 148 ++++++++++++++++++++++++++++++++++++++ test/vhpi/vhpi_test.c | 1 + test/vhpi/vhpi_test.h | 3 +- 9 files changed, 181 insertions(+), 9 deletions(-) create mode 100644 test/regress/vhpi12.vhd create mode 100644 test/vhpi/vhpi12.c diff --git a/src/rt/model.c b/src/rt/model.c index e4ba757a..4f27a35c 100644 --- a/src/rt/model.c +++ b/src/rt/model.c @@ -2004,7 +2004,7 @@ static void *calculate_driving_value(rt_model_t *m, rt_nexus_t *n) // for the signal of which S is a subelement, as appropriate. if (unlikely(n->flags & NET_F_DEPOSIT)) { rt_source_t *src = get_pseudo_source(m, n, SOURCE_DEPOSIT); - n->flags &= NET_F_DEPOSIT; + n->flags &= ~NET_F_DEPOSIT; return value_ptr(n, &(src->u.deposit.value)); } diff --git a/src/vhpi/vhpi-model.c b/src/vhpi/vhpi-model.c index 763cc9f5..f74f55be 100644 --- a/src/vhpi/vhpi-model.c +++ b/src/vhpi/vhpi-model.c @@ -1614,13 +1614,13 @@ vhpiHandleT vhpi_register_cb(vhpiCbDataT *cb_data_p, int32_t flags) cb->data = *cb_data_p; if (cb->Reason == vhpiCbAfterDelay) { - if (cb->data.time == NULL) { - vhpi_error(vhpiError, NULL, "missing time for vhpiCbAfterDelay"); - goto err; - } + if (cb->data.time == NULL) { + vhpi_error(vhpiError, NULL, "missing time for vhpiCbAfterDelay"); + goto err; + } - cb->when = vhpi_time_to_native(cb->data.time) - + model_now(vhpi_context()->model, NULL); + const uint64_t now = model_now(vhpi_context()->model, NULL); + cb->when = vhpi_time_to_native(cb->data.time) + now; } else if (cb->Reason == vhpiCbValueChange && cb->data.value) { vhpi_error(vhpiInternal, NULL, diff --git a/src/vhpi/vhpi-util.c b/src/vhpi/vhpi-util.c index c162152b..3df9d3ba 100644 --- a/src/vhpi/vhpi-util.c +++ b/src/vhpi/vhpi-util.c @@ -331,6 +331,7 @@ bool vhpi_is_repetitive(vhpiEnumT reason) case vhpiCbRepLastKnownDeltaCycle: case vhpiCbRepNextTimeStep: case vhpiCbRepEndOfTimeStep: + case vhpiCbRepAfterDelay: return true; default: return false; diff --git a/test/regress/testlist.txt b/test/regress/testlist.txt index e1a664d1..95ee6f06 100644 --- a/test/regress/testlist.txt +++ b/test/regress/testlist.txt @@ -955,3 +955,4 @@ issue854 normal,2019 ename8 normal,2008 issue856 normal,2019 driver22 fail,gold,2019 +vhpi12 normal,vhpi diff --git a/test/regress/vhpi12.vhd b/test/regress/vhpi12.vhd new file mode 100644 index 00000000..0bef1ef3 --- /dev/null +++ b/test/regress/vhpi12.vhd @@ -0,0 +1,19 @@ +library ieee; +use ieee.std_logic_1164.all; + +entity vhpi12 is + port ( d, clk : in std_logic; + q : out std_logic ); +end entity; + +architecture test of vhpi12 is +begin + + process (clk) is + begin + if rising_edge(clk) then + q <= d; + end if; + end process; + +end architecture; diff --git a/test/vhpi/Makemodule.am b/test/vhpi/Makemodule.am index 303250e8..217da4ba 100644 --- a/test/vhpi/Makemodule.am +++ b/test/vhpi/Makemodule.am @@ -16,7 +16,8 @@ lib_vhpi_test_so_SOURCES = \ test/vhpi/issue744.c \ test/vhpi/vhpi10.c \ test/vhpi/vhpi11.c \ - test/vhpi/issue762.c + test/vhpi/issue762.c \ + test/vhpi/vhpi12.c lib_vhpi_test_so_CFLAGS = $(PIC_FLAG) -I$(top_srcdir)/src/vhpi $(AM_CFLAGS) lib_vhpi_test_so_LDFLAGS = -shared $(VHPI_LDFLAGS) $(AM_LDFLAGS) diff --git a/test/vhpi/vhpi12.c b/test/vhpi/vhpi12.c new file mode 100644 index 00000000..2a7af610 --- /dev/null +++ b/test/vhpi/vhpi12.c @@ -0,0 +1,148 @@ +// +// Copyright (C) 2024 Nick Gasson +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +#include "vhpi_test.h" + +static vhpiHandleT h_sos; +static vhpiHandleT h_clk; +static vhpiHandleT h_d; +static vhpiHandleT h_q; +static vhpiHandleT h_timeout; + +static void register_timeout(void); + +static void set_clk(vhpiSmallEnumT bit) +{ + vhpiValueT val = { + .format = vhpiLogicVal, + }; + + val.value.enumv = bit; + vhpi_put_value(h_clk, &val, vhpiDepositPropagate); + check_error(); +} + +static vhpiSmallEnumT get_clk(void) +{ + vhpiValueT val = { + .format = vhpiLogicVal, + }; + + vhpi_get_value(h_clk, &val); + check_error(); + + return val.value.enumv; +} + +static void set_d(vhpiSmallEnumT bit) +{ + vhpiValueT val = { + .format = vhpiLogicVal, + }; + + val.value.enumv = bit; + vhpi_put_value(h_d, &val, vhpiDepositPropagate); + check_error(); +} + +static vhpiSmallEnumT get_q(void) +{ + vhpiValueT val = { + .format = vhpiLogicVal, + }; + + vhpi_get_value(h_q, &val); + check_error(); + + return val.value.enumv; +} + +static void toggle_clock(const vhpiCbDataT *cb_data) +{ + vhpi_printf("toggle clock"); + + if (get_clk() == vhpi1) { + set_clk(vhpi0); + + vhpiSmallEnumT q = get_q(); + vhpi_printf("q value %x", q); + fail_unless(q == vhpi1); + } + else + set_clk(vhpi1); + + vhpi_release_handle(h_timeout); + + static int rep = 10; + if (rep-- > 0) + register_timeout(); +} + +static void register_timeout(void) +{ + vhpiTimeT time = { + .low = 1000000 + }; + + vhpiCbDataT delay_cb = { + .reason = vhpiCbAfterDelay, + .cb_rtn = toggle_clock, + .time = &time + }; + h_timeout = vhpi_register_cb(&delay_cb, vhpiReturnCb); + check_error(); +} + +static void start_of_sim(const vhpiCbDataT *cb_data) +{ + vhpiHandleT root = vhpi_handle(vhpiRootInst, NULL); + check_error(); + fail_if(root == NULL); + vhpi_printf("root handle %p", root); + + h_clk = vhpi_handle_by_name("clk", root); + check_error(); + fail_if(h_clk == NULL); + vhpi_printf("clk handle %p", h_clk); + + h_d = vhpi_handle_by_name("d", root); + check_error(); + fail_if(h_d == NULL); + vhpi_printf("d handle %p", h_d); + + h_q = vhpi_handle_by_name("q", root); + check_error(); + fail_if(h_q == NULL); + vhpi_printf("q handle %p", h_q); + + set_clk(vhpi0); + set_d(vhpi1); + + register_timeout(); + + vhpi_release_handle(h_sos); +} + +void vhpi12_startup(void) +{ + vhpiCbDataT cb_data1 = { + .reason = vhpiCbStartOfSimulation, + .cb_rtn = start_of_sim, + }; + h_sos = vhpi_register_cb(&cb_data1, vhpiReturnCb); + check_error(); +} diff --git a/test/vhpi/vhpi_test.c b/test/vhpi/vhpi_test.c index 7f6302d2..76aa6114 100644 --- a/test/vhpi/vhpi_test.c +++ b/test/vhpi/vhpi_test.c @@ -40,6 +40,7 @@ static const vhpi_test_t tests[] = { { "vhpi10", vhpi10_startup }, { "vhpi11", vhpi11_startup }, { "issue762", issue762_startup }, + { "vhpi12", vhpi12_startup }, { NULL, NULL }, }; diff --git a/test/vhpi/vhpi_test.h b/test/vhpi/vhpi_test.h index ee7b96cc..e16e37dd 100644 --- a/test/vhpi/vhpi_test.h +++ b/test/vhpi/vhpi_test.h @@ -1,5 +1,5 @@ // -// Copyright (C) 2023 Nick Gasson +// Copyright (C) 2023-2024 Nick Gasson // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -39,6 +39,7 @@ void vhpi8_startup(void); void vhpi9_startup(void); void vhpi10_startup(void); void vhpi11_startup(void); +void vhpi12_startup(void); void issue744_startup(void); void issue762_startup(void); -- 2.39.2