From 7d9d0dd30fbd10907f529f72b26957d00a2fad44 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Thu, 28 Mar 2024 18:18:09 +0000 Subject: [PATCH] Implement vhpi_get_next_time --- src/rt/model.c | 8 ++++++++ src/rt/model.h | 1 + src/vhpi/vhpi-model.c | 11 ++++++++++- src/vhpi/vhpi-util.c | 7 ++++++- test/vhpi/vhpi1.c | 5 +++++ 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/rt/model.c b/src/rt/model.c index dda24dab..956dc6b6 100644 --- a/src/rt/model.c +++ b/src/rt/model.c @@ -3427,6 +3427,14 @@ int64_t model_now(rt_model_t *m, unsigned *deltas) return m->now; } +int64_t model_next_time(rt_model_t *m) +{ + if (heap_size(m->eventq_heap) == 0) + return TIME_HIGH; + else + return heap_min_key(m->eventq_heap); +} + void model_stop(rt_model_t *m) { relaxed_store(&m->force_stop, true); diff --git a/src/rt/model.h b/src/rt/model.h index fcf3c5b3..8b64aa1c 100644 --- a/src/rt/model.h +++ b/src/rt/model.h @@ -28,6 +28,7 @@ void model_run(rt_model_t *m, uint64_t stop_time); bool model_step(rt_model_t *m); bool model_can_create_delta(rt_model_t *m); int64_t model_now(rt_model_t *m, unsigned *deltas); +int64_t model_next_time(rt_model_t *m); void model_stop(rt_model_t *m); void model_interrupt(rt_model_t *m); int model_exit_status(rt_model_t *m); diff --git a/src/vhpi/vhpi-model.c b/src/vhpi/vhpi-model.c index 7195b0aa..c49d579e 100644 --- a/src/vhpi/vhpi-model.c +++ b/src/vhpi/vhpi-model.c @@ -3017,7 +3017,16 @@ void vhpi_get_time(vhpiTimeT *time_p, long *cycles) DLLEXPORT int vhpi_get_next_time(vhpiTimeT *time_p) { - VHPI_MISSING; + vhpi_clear_error(); + + VHPI_TRACE("time_p=%p", time_p); + + const uint64_t next = model_next_time(vhpi_context()->model); + + time_p->high = next >> 32; + time_p->low = next & 0xffffffff; + + return next == TIME_HIGH ? vhpiNoActivity : 0; } DLLEXPORT diff --git a/src/vhpi/vhpi-util.c b/src/vhpi/vhpi-util.c index f2dbf684..14b10f29 100644 --- a/src/vhpi/vhpi-util.c +++ b/src/vhpi/vhpi-util.c @@ -64,8 +64,13 @@ int vhpi_vprintf(const char *format, va_list args) vhpi_clear_error(); char *buf LOCAL = xvasprintf(format, args); + const size_t len = strlen(buf); + + for (char *eptr = buf + len - 1; eptr >= buf && *eptr == '\n'; eptr--) + *eptr = '\0'; + notef("VHPI printf $green$%s$$", buf); - return strlen(buf); + return len; } DLLEXPORT diff --git a/test/vhpi/vhpi1.c b/test/vhpi/vhpi1.c index 56c0541f..a037175c 100644 --- a/test/vhpi/vhpi1.c +++ b/test/vhpi/vhpi1.c @@ -345,6 +345,11 @@ static void start_of_sim(const vhpiCbDataT *cb_data) }; vhpi_register_cb(&cb_data2, 0); check_error(); + + vhpiTimeT next; + fail_unless(vhpi_get_next_time(&next) == 0); + fail_unless(next.high == 0); + fail_unless(next.low == 5000000); } static void end_of_sim(const vhpiCbDataT *cb_data) -- 2.39.2