spicebind 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. spicebind-0.0.1/.github/workflows/docs.yml +61 -0
  2. spicebind-0.0.1/.github/workflows/tests.yml +26 -0
  3. spicebind-0.0.1/.gitignore +212 -0
  4. spicebind-0.0.1/CMakeLists.txt +100 -0
  5. spicebind-0.0.1/LICENSE +28 -0
  6. spicebind-0.0.1/PKG-INFO +210 -0
  7. spicebind-0.0.1/README.md +177 -0
  8. spicebind-0.0.1/cpp/AnalogDigitalInterface.cpp +377 -0
  9. spicebind-0.0.1/cpp/AnalogDigitalInterface.h +115 -0
  10. spicebind-0.0.1/cpp/Config.cpp +120 -0
  11. spicebind-0.0.1/cpp/Config.h +59 -0
  12. spicebind-0.0.1/cpp/Debug.h +36 -0
  13. spicebind-0.0.1/cpp/NgSpiceCallbacks.cpp +111 -0
  14. spicebind-0.0.1/cpp/NgSpiceCallbacks.h +75 -0
  15. spicebind-0.0.1/cpp/TimeBarrier.h +161 -0
  16. spicebind-0.0.1/cpp/VpiCallbacks.cpp +281 -0
  17. spicebind-0.0.1/cpp/VpiCallbacks.h +71 -0
  18. spicebind-0.0.1/cpp/vpi_module.cpp +32 -0
  19. spicebind-0.0.1/cpp/vpi_user.h +1008 -0
  20. spicebind-0.0.1/docs/.gitignore +3 -0
  21. spicebind-0.0.1/docs/Doxyfile +2804 -0
  22. spicebind-0.0.1/docs/README.md +15 -0
  23. spicebind-0.0.1/docs/assets/__init__.py +0 -0
  24. spicebind-0.0.1/docs/assets/pygments_hdlspice.py +98 -0
  25. spicebind-0.0.1/docs/source/adc.md +22 -0
  26. spicebind-0.0.1/docs/source/api.rst +15 -0
  27. spicebind-0.0.1/docs/source/conf.py +377 -0
  28. spicebind-0.0.1/docs/source/index.md +86 -0
  29. spicebind-0.0.1/docs/source/spelling_wordlist.txt +11 -0
  30. spicebind-0.0.1/docs/source/spi_adc.md +14 -0
  31. spicebind-0.0.1/docs/source/timing_synchronization.rst +204 -0
  32. spicebind-0.0.1/examples/adc/Makefile +23 -0
  33. spicebind-0.0.1/examples/adc/README.md +19 -0
  34. spicebind-0.0.1/examples/adc/flash_adc8.cir +29 -0
  35. spicebind-0.0.1/examples/adc/flash_adc8.v +57 -0
  36. spicebind-0.0.1/examples/adc/flash_adc8_tb.v +55 -0
  37. spicebind-0.0.1/examples/adc/test_flash_adc8.py +236 -0
  38. spicebind-0.0.1/examples/spi_adc/README.md +15 -0
  39. spicebind-0.0.1/examples/spi_adc/spi_adc.cir +31 -0
  40. spicebind-0.0.1/examples/spi_adc/spi_adc.v +59 -0
  41. spicebind-0.0.1/examples/spi_adc/test_spi_adc.py +82 -0
  42. spicebind-0.0.1/noxfile.py +143 -0
  43. spicebind-0.0.1/pyproject.toml +61 -0
  44. spicebind-0.0.1/setup.py +10 -0
  45. spicebind-0.0.1/spicebind/__init__.py +51 -0
  46. spicebind-0.0.1/spicebind/cli.py +39 -0
  47. spicebind-0.0.1/tests/debug.cir +122 -0
  48. spicebind-0.0.1/tests/debug.v +22 -0
  49. spicebind-0.0.1/tests/error.cir +7 -0
  50. spicebind-0.0.1/tests/error.v +16 -0
  51. spicebind-0.0.1/tests/multi_instance.cir +18 -0
  52. spicebind-0.0.1/tests/multi_instance.v +20 -0
  53. spicebind-0.0.1/tests/rawread.py +81 -0
  54. spicebind-0.0.1/tests/tb.sv +41 -0
  55. spicebind-0.0.1/tests/test.cir +99 -0
  56. spicebind-0.0.1/tests/test_debug.py +94 -0
  57. spicebind-0.0.1/tests/test_error.py +42 -0
  58. spicebind-0.0.1/tests/test_multi_instance.py +72 -0
  59. spicebind-0.0.1/tests/test_tb.py +155 -0
@@ -0,0 +1,61 @@
1
+ name: Docs
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ matrix:
10
+ python-version: ["3.12"]
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+ - name: Set up Python ${{ matrix.python-version }}
14
+ uses: actions/setup-python@v3
15
+ with:
16
+ python-version: ${{ matrix.python-version }}
17
+ - name: Install dependencies
18
+ env:
19
+ DEBIAN_FRONTEND: noninteractive
20
+ run: |
21
+ sudo apt-get install \
22
+ --yes --no-install-recommends \
23
+ doxygen ngspice iverilog ngspice-dev libngspice0-dev
24
+ - name: Install Python packages
25
+ run: |
26
+ pip install -e ".[docs]"
27
+ pip install nox
28
+ - name: Build docs
29
+ run: |
30
+ nox -s docs
31
+
32
+
33
+ - name: Upload static files as artifact
34
+ id: deployment
35
+ uses: actions/upload-pages-artifact@v3
36
+ with:
37
+ path: .nox/.cache/docs_out
38
+
39
+ # Deploy job
40
+ deploy:
41
+ # Add a dependency to the build job
42
+ needs: build
43
+ # Only deploy on main branch
44
+ if: github.ref == 'refs/heads/main'
45
+
46
+ # Grant GITHUB_TOKEN the permissions required to make a Pages deployment
47
+ permissions:
48
+ pages: write # to deploy to Pages
49
+ id-token: write # to verify the deployment originates from an appropriate source
50
+
51
+ # Deploy to the github-pages environment
52
+ environment:
53
+ name: github-pages
54
+ url: ${{ steps.deployment.outputs.page_url }}
55
+
56
+ # Specify runner + deployment step
57
+ runs-on: ubuntu-latest
58
+ steps:
59
+ - name: Deploy to GitHub Pages
60
+ id: deployment
61
+ uses: actions/deploy-pages@v4
@@ -0,0 +1,26 @@
1
+ name: Tests
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ python-version: ["3.8", "3.12"]
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ - name: Set up Python ${{ matrix.python-version }}
15
+ uses: actions/setup-python@v3
16
+ with:
17
+ python-version: ${{ matrix.python-version }}
18
+ - name: Install system dependencies
19
+ run: |
20
+ sudo apt-get install ngspice iverilog ngspice-dev libngspice0-dev
21
+ - name: Install nox
22
+ run: |
23
+ pip install nox
24
+ - name: Run tests
25
+ run: |
26
+ nox -s test
@@ -0,0 +1,212 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+
110
+ # pdm
111
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112
+ #pdm.lock
113
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114
+ # in version control.
115
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116
+ .pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121
+ __pypackages__/
122
+
123
+ # Celery stuff
124
+ celerybeat-schedule
125
+ celerybeat.pid
126
+
127
+ # SageMath parsed files
128
+ *.sage.py
129
+
130
+ # Environments
131
+ .env
132
+ .venv
133
+ env/
134
+ venv/
135
+ ENV/
136
+ env.bak/
137
+ venv.bak/
138
+
139
+ # Spyder project settings
140
+ .spyderproject
141
+ .spyproject
142
+
143
+ # Rope project settings
144
+ .ropeproject
145
+
146
+ # mkdocs documentation
147
+ /site
148
+
149
+ # mypy
150
+ .mypy_cache/
151
+ .dmypy.json
152
+ dmypy.json
153
+
154
+ # Pyre type checker
155
+ .pyre/
156
+
157
+ # pytype static type analyzer
158
+ .pytype/
159
+
160
+ # Cython debug symbols
161
+ cython_debug/
162
+
163
+ # PyCharm
164
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
167
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
168
+ #.idea/
169
+
170
+ # Abstra
171
+ # Abstra is an AI-powered process automation framework.
172
+ # Ignore directories containing user credentials, local state, and settings.
173
+ # Learn more at https://abstra.io/docs
174
+ .abstra/
175
+
176
+ # Visual Studio Code
177
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
178
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
179
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
180
+ # you could uncomment the following to ignore the enitre vscode folder
181
+ # .vscode/
182
+
183
+ # Ruff stuff:
184
+ .ruff_cache/
185
+
186
+ # PyPI configuration file
187
+ .pypirc
188
+
189
+ # Cursor
190
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
191
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
192
+ # refer to https://docs.cursor.com/context/ignore-files
193
+ .cursorignore
194
+ .cursorindexingignore
195
+
196
+ # cocotb
197
+ sim_build
198
+
199
+ spicebind/*.vpi
200
+
201
+
202
+ # Vim tmp files
203
+ *.swp
204
+ *~
205
+
206
+ # VSCode project files
207
+ .vscode/
208
+ *.code-workspace
209
+
210
+ # Emacs tmp files
211
+ \#*\#
212
+ \.\#*
@@ -0,0 +1,100 @@
1
+ cmake_minimum_required(VERSION 3.15)
2
+ project(spicebind_vpi LANGUAGES CXX)
3
+
4
+
5
+ # Call CMake with: cmake -DNGSPICE_ROOT=/path/to/ngspice <src_dir>
6
+ set(NGSPICE_ROOT "" CACHE PATH
7
+ "Root of an NGSpice installation containing include/ and lib/."
8
+ )
9
+
10
+ if(NOT NGSPICE_ROOT)
11
+ # Try to locate the ngspice executable first
12
+ find_program(NGSPICE_EXE
13
+ NAMES ngspice # ngspice.exe on Windows is also matched
14
+ DOC "Full path to the ngspice executable"
15
+ )
16
+
17
+ if(NGSPICE_EXE)
18
+ # bin -> parent -> install root
19
+ get_filename_component(NGSPICE_BIN_DIR "${NGSPICE_EXE}" DIRECTORY)
20
+ get_filename_component(NGSPICE_ROOT "${NGSPICE_BIN_DIR}" DIRECTORY)
21
+
22
+ message(STATUS "Found ngspice executable: ${NGSPICE_EXE}")
23
+ message(STATUS "Inferred NGSPICE_ROOT: ${NGSPICE_ROOT}")
24
+ # else()
25
+ # message(FATAL_ERROR
26
+ # "Could not find 'ngspice' in your PATH and NGSPICE_ROOT was not "
27
+ # "given. Either install NGSpice or run CMake with "
28
+ # "-DNGSPICE_ROOT=/path/to/ngspice."
29
+ # )
30
+ endif()
31
+ endif()
32
+
33
+
34
+ # ---------------------------------------------------------------------------
35
+ # Source files and common configuration
36
+ # ---------------------------------------------------------------------------
37
+ set(SPICEBIND_SRC
38
+ cpp/Config.cpp
39
+ cpp/AnalogDigitalInterface.cpp
40
+ cpp/NgSpiceCallbacks.cpp
41
+ cpp/VpiCallbacks.cpp
42
+ cpp/vpi_module.cpp
43
+ )
44
+
45
+ set(_ngspice_possible_libdirs
46
+ "${NGSPICE_ROOT}/lib"
47
+ )
48
+
49
+ # Function to configure a VPI target with common settings
50
+ function(configure_vpi_target target_name)
51
+ set_target_properties(${target_name} PROPERTIES
52
+ CXX_STANDARD 17
53
+ POSITION_INDEPENDENT_CODE ON
54
+ PREFIX "" # stop CMake from adding "lib"
55
+ SUFFIX ".vpi" # final name: ${target_name}.vpi
56
+ LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/spicebind"
57
+ )
58
+
59
+ target_include_directories(${target_name}
60
+ PRIVATE
61
+ ${CMAKE_CURRENT_SOURCE_DIR}/cpp
62
+ ${NGSPICE_ROOT}/include
63
+ )
64
+
65
+ target_link_directories(${target_name} PRIVATE ${_ngspice_possible_libdirs})
66
+ target_link_libraries(${target_name} PRIVATE ngspice)
67
+ endfunction()
68
+
69
+ # ---------------------------------------------------------------------------
70
+ # RELEASE variant
71
+ # ---------------------------------------------------------------------------
72
+ add_library(spicebind_vpi SHARED ${SPICEBIND_SRC})
73
+ configure_vpi_target(spicebind_vpi)
74
+
75
+ # ---------------------------------------------------------------------------
76
+ # DEBUG variant
77
+ # ---------------------------------------------------------------------------
78
+ add_library(spicebind_vpi_debug SHARED ${SPICEBIND_SRC})
79
+ configure_vpi_target(spicebind_vpi_debug)
80
+
81
+ # ► debug-specific compile flags ◄
82
+ target_compile_definitions(spicebind_vpi_debug PRIVATE DEBUG)
83
+ target_compile_options(spicebind_vpi_debug PRIVATE
84
+ $<$<CXX_COMPILER_ID:MSVC>:/Zi /Od>
85
+ $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-g -O0>
86
+ )
87
+
88
+ # convenience meta-target: cmake --build . --target debug
89
+ add_custom_target(debug ALL DEPENDS spicebind_vpi_debug)
90
+
91
+ # ---------------------------------------------------------------------------
92
+ # Installation for Python packaging
93
+ # ---------------------------------------------------------------------------
94
+ # Install VPI files to the Python package directory
95
+ install(FILES
96
+ $<TARGET_FILE:spicebind_vpi>
97
+ $<TARGET_FILE:spicebind_vpi_debug>
98
+ DESTINATION spicebind
99
+ COMPONENT python_package
100
+ )
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2025, Tomasz Hemperek
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,210 @@
1
+ Metadata-Version: 2.2
2
+ Name: spicebind
3
+ Version: 0.0.1
4
+ Summary: SpiceBind is a bridge that embeds the ngspice analog engine inside VPI-capable Verilog simulator for mixed-signal co-simulation.
5
+ Author: Tomasz Hemperek
6
+ Classifier: Development Status :: 3 - Alpha
7
+ Classifier: Intended Audience :: Developers
8
+ Classifier: Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Project-URL: Homepage, https://github.com/themperek/spicebind
12
+ Project-URL: Repository, https://github.com/themperek/spicebind
13
+ Requires-Python: >=3.8
14
+ Provides-Extra: dev
15
+ Requires-Dist: pytest; extra == "dev"
16
+ Requires-Dist: cocotb; extra == "dev"
17
+ Requires-Dist: numpy; extra == "dev"
18
+ Requires-Dist: matplotlib; extra == "dev"
19
+ Requires-Dist: cocotbext-spi; extra == "dev"
20
+ Requires-Dist: tomli; extra == "dev"
21
+ Provides-Extra: docs
22
+ Requires-Dist: sphinx>=8.2; extra == "docs"
23
+ Requires-Dist: breathe; extra == "docs"
24
+ Requires-Dist: sphinx-book-theme==1.1.3; extra == "docs"
25
+ Requires-Dist: sphinx-design>=0.6.1; extra == "docs"
26
+ Requires-Dist: sphinxcontrib-spelling>=5.3.0; extra == "docs"
27
+ Requires-Dist: pyenchant; extra == "docs"
28
+ Requires-Dist: sphinx-argparse-cli; extra == "docs"
29
+ Requires-Dist: sphinx-autobuild; extra == "docs"
30
+ Requires-Dist: sphinx-codeautolink; extra == "docs"
31
+ Requires-Dist: myst-parser; extra == "docs"
32
+ Description-Content-Type: text/markdown
33
+
34
+ # SpiceBind
35
+
36
+ [![Tests](https://github.com/themperek/spicebind/actions/workflows/tests.yml/badge.svg)](https://github.com/themperek/spicebind/actions/workflows/tests.yml)
37
+ [![Docs](https://github.com/themperek/spicebind/actions/workflows/docs.yml/badge.svg)](https://themperek.github.io/spicebind/)
38
+
39
+ SpiceBind is a lightweight bridge that enables co-simulation of **analog [ngspice](https://ngspice.sourceforge.io/)** circuits alongside **HDL simulators**. This tool allows design engineers to seamlessly integrate SPICE-accurate analog models into their existing digital verification flows.
40
+
41
+ ⚠️ **Note**: This is an early release. We welcome feedback and contributions from the community.
42
+
43
+ ### Key Benefits
44
+
45
+ - **Preserve Your Existing Flow**: Keep your RTL, testbenches, and waveform viewers unchanged
46
+ - **SPICE Accuracy**: Replace any module with a SPICE-based analog model for accurate analog simulation
47
+ - **Unified Timeline**: Analog and digital domains run in synchronization
48
+ - **Zero Vendor Lock-in**: Works with open-source tools like Icarus Verilog up to commercial simulators (to be tested)
49
+ - **Verification Ready**: Compatible with [cocotb](https://www.cocotb.org/) for Python-based verification
50
+
51
+ ### Use Cases
52
+
53
+ Perfect for ASIC designers working on:
54
+ - Mixed-signal SoCs with analog IP blocks
55
+ - ADCs, DACs, and data converters
56
+ - PLLs, oscillators, and clock generation circuits
57
+ - Power management units
58
+ - Sensor interfaces and analog front-ends
59
+
60
+ ## How It Works
61
+
62
+ SpiceBind enables you to write Verilog source code that includes an empty Verilog module and have it implemented by ngspice. Here's how the magic happens:
63
+
64
+ ### The Process
65
+
66
+ 1. **Create a Verilog Module Shell**: Write a Verilog module with the desired interface (inputs and outputs). The module body can be empty - it will be implemented in SPICE.
67
+
68
+ 2. **Design the SPICE Implementation**: Create a corresponding SPICE netlist that implements the analog behavior of your module.
69
+
70
+ 3. **Name-Based Connection**:
71
+ - **Verilog input ports** appear in the SPICE circuit as external voltage sources
72
+ - **Selected SPICE circuit nodes** drive the Verilog output ports
73
+ - Connections are established by **matching names** between Verilog ports and SPICE nodes
74
+
75
+ 4. **VPI Integration**: A VPI (Verilog Procedural Interface) module links to ngspice's shared library, enabling communication between the digital simulator and the analog engine.
76
+
77
+ ### Example Flow
78
+
79
+ ```
80
+ Verilog: input real vin → SPICE: Vvin external_node 0 0 external
81
+ Verilog: output [3:0] code ← SPICE: circuit nodes code[3], code[2], code[1], code[0]
82
+ ```
83
+
84
+ During simulation, the VPI module:
85
+ - Reads values from Verilog input ports and sets corresponding SPICE voltage sources
86
+ - Runs SPICE analysis for the current time step
87
+ - Reads SPICE node voltages and drives corresponding Verilog output ports
88
+
89
+ This creates a co-simulation where analog and digital domains remain synchronized on a unified timeline.
90
+
91
+ ## Installation
92
+
93
+ ### Prerequisites
94
+
95
+ - C++ compiler with C++17 support
96
+ - ngspice library and development headers
97
+ - Verilog VPI compatible simulator (tested with [Icarus Verilog](https://github.com/steveicarus/iverilog))
98
+ - Python 3.6+ (optional)
99
+
100
+ ### Build Instructions
101
+
102
+ Clone the repository:
103
+ ```bash
104
+ git clone https://github.com/themperek/spicebind.git
105
+ cd spicebind
106
+ ```
107
+
108
+ **Option 1: Standalone VPI Module**
109
+ ```bash
110
+ mkdir build && cd build
111
+ cmake ..
112
+ cmake --build .
113
+ cmake --build . --target debug # Optional: builds debug version
114
+ ```
115
+
116
+ **Option 2: Python Integration**
117
+ ```bash
118
+ pip install -e .
119
+ ```
120
+
121
+ ## Quick Start
122
+
123
+ ### 1. Define Your Analog Block
124
+
125
+ Create a Verilog module with matching SPICE netlist with external voltage sources and ouptut ports.
126
+
127
+ **Verilog module** (e.g., `adc.v`):
128
+ ```verilog
129
+ module adc(
130
+ input real vin,
131
+ output reg [3:0] code
132
+ );
133
+ endmodule
134
+ ```
135
+
136
+ **SPICE netlist** (e.g., `adc.cir`):
137
+ ```spice
138
+ * External voltage source for input
139
+ Vvin adc_in 0 0 external
140
+
141
+ * ADC subcircuit instantiation
142
+ Xadc adc_in code[3] code[2] code[1] code[0] sar_adc
143
+
144
+ * Simulation settings
145
+ .tran 1ns 1
146
+ ```
147
+
148
+ ### 2. Configure Environment
149
+
150
+ Set the required environment variables:
151
+ ```bash
152
+ export SPICE_NETLIST=adc.cir
153
+ export HDL_INSTANCE=tb.adc
154
+ export VCC=3.3
155
+ ```
156
+
157
+ ### 3. Run Simulation
158
+
159
+ For Icarus Verilog:
160
+ ```bash
161
+ vvp -M $(spicebind-vpi-path) -m spicebind_vpi tb.vvp
162
+ ```
163
+
164
+ See the `examples/` directory for complete working examples.
165
+
166
+ ### Multiple Instance Support
167
+
168
+ For designs with multiple analog blocks, configure each instance in your SPICE netlist with full hierarchical paths:
169
+
170
+ **SPICE netlist**:
171
+ ```spice
172
+ * First ADC instance
173
+ Vtb.adc.vin vin 0 0 external
174
+ Xadc vin tb.adc.code[3] tb.adc.code[2] tb.adc.code[1] tb.adc.code[0] sar_adc
175
+
176
+ * Inverter instance
177
+ Vtb.inv.A inv_a 0 0 external
178
+ Xinv inv_a tb.inv.Y inv
179
+
180
+ .tran 1ns 1
181
+ ```
182
+
183
+ **Environment configuration**:
184
+ ```bash
185
+ export HDL_INSTANCE=tb.adc,tb.inv
186
+ ```
187
+
188
+ ### Configuration Options
189
+
190
+ - `SPICE_NETLIST`: Path to your SPICE netlist file
191
+ - `HDL_INSTANCE`: Comma-separated list of HDL instance paths
192
+ - `VCC`: Supply voltage for analog simulation
193
+ - Additional options available in the documentation
194
+
195
+ ## Documentation
196
+
197
+ For detailed documentation, examples, and API reference, visit: [https://themperek.github.io/spicebind/](https://themperek.github.io/spicebind/)
198
+
199
+ ## Contributing
200
+
201
+ We welcome contributions! Please see our contributing guidelines and feel free to:
202
+ - Report bugs and request features via GitHub Issues
203
+ - Submit pull requests for improvements
204
+ - Share your use cases and examples
205
+
206
+ ## Roadmap
207
+
208
+ - [ ] Enhanced testing and validation
209
+ - [ ] Bidirectional bus support
210
+ - [ ] Automatic SPICE wrapper generation