- When
nghdl
button clicked ineSim
it calls thengspice_ghdl.py
fromnghdl
installed directory
ngspice_ghdl.py
defines the UI for nghdl, and the functionality of each button- When
Upload
clicked, it callsuploadModel
function fromngspice_ghdl.py
- Similarly functions called on each button click defined
uploadModel
inturn calls these 5 functions sequentially =>-
- createModelDirectory()
-
- addingModelInModpath()
-
- createModelFiles()
-
- runMake()
-
- runMakeInstall()
createModelDirectory()
- Create directory for the specified file name at
~/nghdl-simulator/src/xspice/icm/ghdl/
- The location where the directory is created in mentioned at
~/.nghdl/config.ini
, this config file is inside a hidden folder.ngdhl
, created when nghdl is installed - If a folder of the same name exists, it asks to overwrite, then removes earlier folder, and writes new one
addingModelInModpath()
- This adds the name of the new model created to
modpath.lst
file modpath.lst
is located at~/nghdl-simulator/src/xspice/icm/ghdl
, this should contain name of all the models that the folder has- Similarly you can look at
~/nghdl-simulator/src/xspice/icm/digital
which also contains amodpath.list
for all the models in that folder - This
modpath.lst
is used in theGNUMakefile
at~/nghdl-simulator/release/src/xspice/icm
- This file used to keep a track of all components created
- If model already there it isn't added to the list
createModelFiles()
- Calls
model_generation.py
at the installed nghdl location undersrc/model_generation.py
- Moves the generated
cfunc.mod
andifspec.ifs
files to~/nghdl-simulator/src/xspice/icm/ghdl/modelName
- Creates
DUTghdl
folder at~/nghdl-simulator/src/xspice/icm/ghdl/modelName
- Move
compile.sh
,uthash.sh
,ghdlserver.c
,ghdlserver.h
,Utility_Package.vhdl
,Vhpi_Package.vhdl
to theDUTghdl
folder - Copy
modelName.vhdl
file from source location toDUTghdl
folder - Rum
compile.sh
which generates the object file forghdlserver.c
- Give permission to
start_server.sh
andsock_pkg_create.sh
to execute chod a+x - Finally remove
compile.sh
andghdlserver.c
model_generation.py
- Creates the following files =>
-
connection_info.txt
-
cfunc.mod
-
ifspec.ifs
-
modelName_tb.vhdl
=> testbench file for the model
-
start_server.sh
-
sock_pkg_create.sh
- The above files can be found either at
~/nghdl-simulator/src/xspice/icm/ghdl/modelName
orDUTghdl
folder inside it
runMake()
- Runs the
Makefile
at~/nghdl-simulator/release
- Executing by running
make
command
runMakeInstall()
- Executes
make install
- Finally calls
createSchematicLib()
createSchematicLib()
- Connects with
createKicadLibrary.py
file at~/nghdl/src
- Generates the
lib
file for the model, to be used byKiCad
- This is generated from a template stored at
Appconfig.py
- The generated
lib
is stored at~/eSim_kicad.lib
- Also creates
xml
file for the model, which is stored at eSim undereSimLoc/src/modelParamXML/Nghdl
Finally all the relevant files are generated, now while executing ngspice, we need to make sure to run the ngspice, which is located at -
~/nghdl-simulator/install_dir/bin/ngspice
this has the binary for the ngspice,- And also the script at
~/nghdl-simulator/install_dir/share/ngspice/scripts/spinit
=spinit
has the linecodemodel ...
mentioning acm
file to execute at runtime - This has mention of
ghdl.cm
which makes sure that ourcfunc.c
file is executed at runtime - You can see the
ghdl.cm
file is located at~/nghdl-simulator/release/src/xspice/icm/ghdl
- Also the
cfunc.c
files, located at~/nghdl-simulator/release/src/xspice/icm/ghdl/modelName
- These have mention of the
start_server.sh
file atDUTghdl
, hence server is started and values passed as well - Also you can look at
~/nghdl-simulator/release/src/xspice/icm/digital
it hasdigital.cm
and the folders inside havecfunc.c
- Also has
ifspec.c
which defines the interface
- If you have ngspice currently installed remove it and genearate a softlink or command for the ngspice installed at -
~/nghdl-simulator/install_dir/bin/ngspice
whereis ngspice
, run this to get the location from wherengspice
is being executed currently
-
To generate softlink refer - Creating softlinki
-
Exeecute
ln -s ~/nghdl-simulator/install_dir/bin/ngspice /usr/bin/ngspice
-
Note that all the paths mentioned here are specific to a Linux machine.
- Also the installation script doesn't install ghdl, you will have to do it manually, either through a
.deb
package or build it from source - Note that since we are using socket programming here, we require either the
llvm
architecture orgcc
. Usingmcode
backend won't work here
- To install ghdl from source, this Github issue might be helpful, the steps are -
-
sudo ./configure --with-llvm-config
-
- sudo make
-
- sudo make install
- Check this Github issue for those building from
.deb
package - To check current version and architecure of ghdl use -
-
ghdl --version
command, it should havellvm
code generator orgcc
- Also once ghdl is installed, to check syntax of your vhdl files use -
ghdl -s <vhdl file location>