Skip to content

Commit 7d97df8

Browse files
committed
Set precision from VPI top.
1 parent 8afd658 commit 7d97df8

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

cpp/VpiCallbacks.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <exception>
1111
#include <thread>
1212
#include <chrono>
13+
#include <cmath>
1314

1415
// External global variables (defined in vpi_module.cpp)
1516
extern spice_vpi::TimeBarrier<unsigned long long> g_time_barrier;
@@ -148,7 +149,7 @@ auto vpi_start_of_sim_cb(p_cb_data cb_data_p) -> PLI_INT32 {
148149
try {
149150
// Load configuration from environment variables
150151
g_config = spice_vpi::Config::load_from_environment();
151-
152+
152153
// Initialize the interface with the configuration
153154
g_interface = std::make_unique<spice_vpi::AnalogDigitalInterface>(g_config);
154155

@@ -171,6 +172,11 @@ auto vpi_start_of_sim_cb(p_cb_data cb_data_p) -> PLI_INT32 {
171172
vpi_printf("** Info: Using logic thresholds: LOGIC_THRESHOLD_LOW=%g, LOGIC_THRESHOLD_HIGH=%g\n",
172173
g_config.logic_threshold_low, g_config.logic_threshold_high);
173174

175+
int time_unit = vpi_get(vpiTimeUnit, nullptr);
176+
int time_precision = vpi_get(vpiTimePrecision, nullptr);
177+
g_config.time_precision = static_cast<unsigned long long>(std::pow(10, -time_precision));
178+
vpi_printf("** Info: Simulation precision: %lld (10e%d)\n", g_config.time_precision, time_precision);
179+
174180
} catch (const std::exception& e) {
175181
ERROR("Configuration error: %s", e.what());
176182
return 1;

0 commit comments

Comments
 (0)