API#

namespace spice_vpi#
class AnalogDigitalInterface#
#include <AnalogDigitalInterface.h>

Manages the interface between analog (SPICE) and digital (HDL) signals.

This class handles:

  • Port discovery and management

  • Signal conversion between analog voltages and digital logic levels

  • Thread-safe access to port data

  • Synchronization between SPICE and HDL simulators

Public Functions

explicit AnalogDigitalInterface(const Config::Settings &config)#

Constructor.

Parameters:

config – Configuration settings to use for signal conversion

void add_port(vpiHandle port)#

Add a port to be managed by this interface.

Parameters:

port – VPI handle to the port

void set_analog_input(const char *name, double *value)#

Set analog input value (from digital side)

Parameters:
  • name – Port name

  • value – Pointer to receive the analog value

void analog_outputs_update()#

Update analog output values from SPICE.

void set_digital_output()#

Set digital output values (to digital side)

void digital_input_update(vpiHandle handle)#

Update when digital input changes (called from VPI callback)

Parameters:

handle – VPI handle to the changed signal

std::vector<std::string> get_analog_input_names() const#

Get all analog input names (for SPICE iteration)

Returns:

Vector of port names

void print_status() const#

Print debug status information.

void update_all_digital_inputs()#

Update all digital inputs.

Private Functions

double digital_to_analog(int digital_value) const#
int analog_to_digital(double analog_value) const#

Private Members

std::unordered_map<std::string, PortInfo> analog_inputs_#
std::unordered_map<std::string, PortInfo> analog_outputs_#
mutable std::mutex inputs_mutex_#
mutable std::mutex outputs_mutex_#
const Config::Settings *config_#

Private Static Functions

static std::string create_indexed_name(const std::string &base_name, int index)#
struct PortInfo#

Public Functions

PortInfo()#
PortInfo(const PortInfo &other)#
PortInfo &operator=(const PortInfo &other)#
PortInfo(PortInfo &&other) noexcept#
PortInfo &operator=(PortInfo &&other) noexcept#

Public Members

std::string name#
std::string base_name#
vpiHandle handle#
int direction#
int net_type#
int size#
bool is_vector#
int bit_index#
double value#
bool changed#
namespace spice_vpi
namespace spice_vpi
class Config#
#include <Config.h>

Configuration manager for SPICE-VPI bridge.

Handles reading and validating environment variables and configuration

Public Static Functions

static Settings load_from_environment()#

Load configuration from environment variables.

Throws:

std::runtime_error – if required environment variables are missing

Returns:

Configuration settings

static void validate(const Settings &settings)#

Validate configuration settings.

Parameters:

settings – Configuration to validate

Throws:

std::invalid_argument – if configuration is invalid

Private Static Functions

static std::string get_required_env_var(const char *name)#
static std::string get_optional_env_var(const char *name, const std::string &default_value = "")#
static double get_optional_env_double(const char *name, double default_value)#
static void parse_instance_names(const std::string &env_value, std::vector<std::string> &instance_names, bool &full_path_discovery)#

Parse comma-separated instance names from environment variable.

Parameters:
  • env_value – The value from HDL_INSTANCE environment variable

  • instance_names – Output vector to store parsed instance names

  • full_path_discovery – Output flag indicating if there was any comma

struct Settings#

Public Members

std::string spice_netlist_path#
std::vector<std::string> hdl_instance_names#
bool full_path_discovery = false#
double vcc_voltage = 1.0#
double logic_threshold_low = 0.3#
double logic_threshold_high = 0.7#
double min_analog_change_threshold = 1e-9#
unsigned long long time_precision = 1e12#
namespace spice_vpi
template<typename TimeT>
class TimeBarrier#
#include <TimeBarrier.h>

Two-party virtual-time synchronization barrier with shutdown support.

Coordinates time progression between two simulation engines (HDL and SPICE). Each engine calls update() with its current time. If one engine gets ahead, it blocks until the other catches up or shutdown is called.

Template Parameters:

TimeT – Time type (typically unsigned long long for femtosecond precision)

Public Functions

inline TimeBarrier()#
bool update(int engine_id, TimeT current_time)#

Update time for one engine and wait for synchronization.

Parameters:
  • engine_id – Engine identifier (HDL_ENGINE_ID or SPICE_ENGINE_ID)

  • current_time – Current virtual time for this engine

Returns:

false if barrier was shut down before sync completed

void update_no_wait(int engine_id, TimeT current_time)#

Update time without waiting for synchronization.

Parameters:
  • engine_id – Engine identifier

  • current_time – Current virtual time for this engine

TimeT get_time(int engine_id) const#

Get current time for specified engine.

Parameters:

engine_id – Engine identifier

Returns:

Current time for the engine

void shutdown()#

Signal shutdown to wake all waiting threads.

bool is_shutdown() const#

Check if barrier has been shut down.

void set_needs_redo(bool needs_redo)#
bool needs_redo() const#
void set_next_spice_step_time(TimeT time)#
TimeT get_next_spice_step_time() const#

Public Static Attributes

static constexpr int HDL_ENGINE_ID = 0#
static constexpr int SPICE_ENGINE_ID = 1#

Private Functions

void validate_engine_id(int engine_id) const#

Private Members

mutable std::mutex mutex_#
std::condition_variable cv_#
std::array<TimeT, 2> times_#
std::atomic<bool> is_shutdown_#
std::atomic<bool> needs_redo_#
std::atomic<TimeT> next_spice_step_time_#
namespace spice_vpi