diff options
-rw-r--r-- | README.md (renamed from readme.md) | 38 | ||||
-rw-r--r-- | src/createKicadLibrary.py | 42 | ||||
-rw-r--r-- | src/ghdlserver/ghdlserver.c | 6 | ||||
-rw-r--r-- | src/model_generation.py | 22 | ||||
-rwxr-xr-x | src/ngspice_ghdl.py | 79 | ||||
-rw-r--r-- | src/outitf.c | 9 |
6 files changed, 98 insertions, 98 deletions
@@ -1,9 +1,7 @@ Ngspice Ghdl Interfacing Documentation ==== -It contains all the documenation for Ngspice and Ghdl related work. - -> Note: This project is in beta version and has been tested for rings, counters and PWM controllers. +It contains all the documentation for Ngspice and GHDL related work. ## How is Ngspice interfaced with GHDL? @@ -18,33 +16,33 @@ So the idea of interfacing is just to write VHDL code for a model and use it as GHDL's foreign language interface is used for this inter-process communication. -## Pre-requisites -1. Ubuntu 16.04-18.04 (You can try it on other version and let us know) -2. GHDL (LLVM)-0.36 -3. Ngspice-31 +## Releases +* Ubuntu 16.04 OS and above LTS versions. +* Microsoft Windows 7, 8 and 10. +> Note: Refer [`installers`](https://github.com/fossee/nghdl/tree/installers) branch for documentation on packaging for above mentioned platforms. -## How to install? -This module is made available with eSim (Electronic Circuit Simulation). -Refer https://esim.fossee.in/ for more information. + +## Features +* Support for 500 digital models. +* Support for digital models upto 64 output ports/pins. +* Multiple instances of same digital model. -## Installed Code Structure -1. Ngspice will be installed in home directory $HOME. -2. Source code for all other file will be present in ~/.esim-nghdl -3. symlink "nghdl" is stored in /usr/local/bin +## Pre-requisites +* GHDL (LLVM)-v0.37 +* Ngspice-v31 -## Features -1. Support for 512 digital models. -2. Support for digital models upto 64 output ports/pins. -3. Multiple instances of same digital model. +## How to install? +This module is made available with eSim (Electronic Circuit Simulation). +Refer https://esim.fossee.in/ for more information. ## How to use the Examples provided with NGHDL? -1. Launch eSim --> Click on "NGHDL" icon from the left toolbar --> Click on "Browse" button --> Go to ../nghdl/Example/ +1. Launch eSim --> Click on "NGHDL" icon from the left toolbar --> Click on "Browse" button --> Go to `nghdl/Example/` 2. Locate the example you wish to simulate, find the VHDL file within that example and click on "Open" button at the bottom of "Open File" window. 3. Click on "Upload" button in the NGHDL window. File will be processed in the backend for few seconds. Now exit the NGHDL window. -4. Open the desired example under eSim/Examples/NGHDL_Examples/ using the "Open Project" button, double click on the project when the project is loaded in the "Projects" window. +4. Open the desired example under `eSim/Examples/Mixed_Signal/` using the "Open Project" button, double click on the project when the project is loaded in the "Projects" window. 5. Click on the "Simulation" button on eSim Main window. diff --git a/src/createKicadLibrary.py b/src/createKicadLibrary.py index 2b3e7d7..e98d0d0 100644 --- a/src/createKicadLibrary.py +++ b/src/createKicadLibrary.py @@ -2,13 +2,14 @@ from Appconfig import Appconfig import re
import os
import xml.etree.cElementTree as ET
-from PyQt4 import QtGui
+from PyQt5 import QtWidgets
-class AutoSchematic(QtGui.QWidget):
+class AutoSchematic(QtWidgets.QWidget):
- def __init__(self, modelname):
- QtGui.QWidget.__init__(self)
+ def __init__(self, parent, modelname):
+ QtWidgets.QWidget.__init__(self)
+ self.parent = parent
self.modelname = modelname.split('.')[0]
self.template = Appconfig.kicad_lib_template.copy()
self.xml_loc = Appconfig.xml_loc
@@ -16,7 +17,8 @@ class AutoSchematic(QtGui.QWidget): if os.name == 'nt':
eSim_src = Appconfig.src_home
inst_dir = eSim_src.replace('\eSim', '')
- self.kicad_nghdl_lib = inst_dir + '/KiCad/share/kicad/library/eSim_Nghdl.lib'
+ self.kicad_nghdl_lib = \
+ inst_dir + '/KiCad/share/kicad/library/eSim_Nghdl.lib'
else:
self.kicad_nghdl_lib = '/usr/share/kicad/library/eSim_Nghdl.lib'
self.parser = Appconfig.parser_nghdl
@@ -33,14 +35,14 @@ class AutoSchematic(QtGui.QWidget): self.createLib()
elif (xmlFound == os.path.join(self.xml_loc, 'Nghdl')):
print('Library already exists...')
- ret = QtGui.QMessageBox.warning(
- self, "Warning", '''<b>Library files for this model ''' +
+ ret = QtWidgets.QMessageBox.warning(
+ self.parent, "Warning", '''<b>Library files for this model ''' +
'''already exist. Do you want to overwrite it?</b><br/>
If yes press ok, else cancel it and ''' +
'''change the name of your vhdl file.''',
- QtGui.QMessageBox.Ok, QtGui.QMessageBox.Cancel
+ QtWidgets.QMessageBox.Ok, QtWidgets.QMessageBox.Cancel
)
- if ret == QtGui.QMessageBox.Ok:
+ if ret == QtWidgets.QMessageBox.Ok:
print("Overwriting existing libraries")
self.getPortInformation()
self.createXML()
@@ -51,11 +53,11 @@ class AutoSchematic(QtGui.QWidget): quit()
else:
print('Pre existing library...')
- ret = QtGui.QMessageBox.critical(
- self, "Error", '''<b>A standard library already exists ''' +
+ ret = QtWidgets.QMessageBox.critical(
+ self.parent, "Error", '''<b>A standard library already exists ''' +
'''with this name.</b><br/><b>Please change the name ''' +
'''of your vhdl file and upload it again</b>''',
- QtGui.QMessageBox.Ok
+ QtWidgets.QMessageBox.Ok
)
# quit()
@@ -82,17 +84,17 @@ class AutoSchematic(QtGui.QWidget): ET.SubElement(root, "type").text = "Nghdl"
ET.SubElement(root, "node_number").text = str(len(self.portInfo))
ET.SubElement(root, "title").text = (
- "Add parameters for " + str(self.modelname))
+ "Add parameters for " + str(self.modelname))
ET.SubElement(root, "split").text = self.splitText
param = ET.SubElement(root, "param")
ET.SubElement(param, "rise_delay", default="1.0e-9").text = (
- "Enter Rise Delay (default=1.0e-9)")
+ "Enter Rise Delay (default=1.0e-9)")
ET.SubElement(param, "fall_delay", default="1.0e-9").text = (
- "Enter Fall Delay (default=1.0e-9)")
+ "Enter Fall Delay (default=1.0e-9)")
ET.SubElement(param, "input_load", default="1.0e-12").text = (
- "Enter Input Load (default=1.0e-12)")
+ "Enter Input Load (default=1.0e-12)")
ET.SubElement(param, "instance_id", default="1").text = (
- "Enter Instance ID (Between 0-99)")
+ "Enter Instance ID (Between 0-99)")
tree = ET.ElementTree(root)
tree.write(str(self.modelname) + '.xml')
print("Leaving the directory ", xmlDestination)
@@ -229,11 +231,11 @@ class AutoSchematic(QtGui.QWidget): os.chdir(cwd)
print('Leaving directory, ', self.lib_loc)
- QtGui.QMessageBox.information(
- self, "Library added",
+ QtWidgets.QMessageBox.information(
+ self.parent, "Library added",
'''Library details for this model is added to the ''' +
'''<b>eSim_Nghdl.lib</b> in the KiCad shared directory''',
- QtGui.QMessageBox.Ok
+ QtWidgets.QMessageBox.Ok
)
diff --git a/src/ghdlserver/ghdlserver.c b/src/ghdlserver/ghdlserver.c index 410a2ff..f2b632d 100644 --- a/src/ghdlserver/ghdlserver.c +++ b/src/ghdlserver/ghdlserver.c @@ -10,9 +10,9 @@ ************************************************************************************ ************************************************************************************ * 08.Nov.2019 - Rahul Paknikar - Switched to blocking sockets from non-blocking - * - Close previous used socket to prevent from - * generating too many socket descriptors - * - Enabled SO_REUSEPORT, SO_DONTROUTE socket options + * - Close previous used socket to prevent from + * generating too many socket descriptors + * - Enabled SO_REUSEPORT, SO_DONTROUTE socket options * 5.July.2019 - Rahul Paknikar - Added loop to send all port values for * a given event. ************************************************************************************ diff --git a/src/model_generation.py b/src/model_generation.py index 7baecc1..f19a5c9 100644 --- a/src/model_generation.py +++ b/src/model_generation.py @@ -1,5 +1,3 @@ -#!/usr/bin/python3 - import re import os from configparser import SafeConfigParser @@ -289,11 +287,13 @@ class ModelGeneration: if os.name == 'nt': client_setup_ip += ''' - sprintf(ip_filename, "C:/Windows/Temp/NGHDL_COMMON_IP_%d.txt", getpid()); + sprintf(ip_filename, ''' \ + '''"C:/Windows/Temp/NGHDL_COMMON_IP_%d.txt", getpid()); ''' else: client_setup_ip += ''' - sprintf(ip_filename, "/tmp/NGHDL_COMMON_IP_%d.txt", getpid()); + sprintf(ip_filename, "/tmp/NGHDL_COMMON_IP_%d.txt",''' \ + ''' getpid()); ''' client_setup_ip += ''' @@ -495,8 +495,8 @@ class ModelGeneration: \t\t\telse if(*key_iter=='1')\n\t\t\t{\n\ \t\t\t\t_op_" + item.split(':')[0] + "[Ii]=ONE;\n\ \t\t\t}\n\t\t\telse\n\t\t\t{\n\ - \t\t\t\tfprintf(log_client,\"Unknown value return from server \\n\");\n\ - \t\t\t\tprintf(\"Client-Unknown value return \\n\");\n\t\t\t}\n\n\ + \t\t\t\tfprintf(log_client,\"Unknown value return from server \\n\");\ + \n\t\t\t\tprintf(\"Client-Unknown value return \\n\");\n\t\t\t}\n\n\ \t\t\tif(ANALYSIS == DC)\n\t\t\t{\n\ \t\t\t\tOUTPUT_STATE(" + item.split(':')[0] + "[Ii]) = _op_" + item.split(':')[0] + "[Ii];\n\ \t\t\t}\n\t\t\telse if(_op_" + item.split(':')[0] + "[Ii] != _op_" + item.split(':')[0] + "_old[Ii])\n\ @@ -555,8 +555,11 @@ class ModelGeneration: self.digital_home = self.parser.get('NGSPICE', 'DIGITAL_MODEL') self.msys_home = self.parser.get('COMPILER', 'MSYS_HOME') cmd_str2 = "\\'start_server.sh %d %s\\'" + "\\" + "\"" - cmd_str1 = os.path.normpath("\"cd " + self.digital_home + "/" + self.fname.split( - '.')[0] + "/DUTghdl/ && " + self.msys_home + "/bash.exe -c ") + cmd_str1 = os.path.normpath( + "\"cd " + self.digital_home + "/" + + self.fname.split('.')[0] + "/DUTghdl/ && " + + self.msys_home + "/bash.exe -c " + ) cmd_str1 = cmd_str1.replace("\\", "/") cfunc.write('\t\tsnprintf(command,1024, "start /min cmd /c ' + '\\' + cmd_str1 + cmd_str2 + ' &", sock_port, my_ip);') @@ -1072,7 +1075,8 @@ class ModelGeneration: if os.name == 'nt': start_server.write("ghdl -e -Wl,ghdlserver.o " + - "-Wl,libws2_32.a " + self.fname.split('.')[0] + "_tb &&\n") + "-Wl,libws2_32.a " + + self.fname.split('.')[0] + "_tb &&\n") start_server.write("./"+self.fname.split('.')[0]+"_tb.exe") else: start_server.write("ghdl -e -Wl,ghdlserver.o " + diff --git a/src/ngspice_ghdl.py b/src/ngspice_ghdl.py index e873555..fd17d7f 100755 --- a/src/ngspice_ghdl.py +++ b/src/ngspice_ghdl.py @@ -1,30 +1,28 @@ #!/usr/bin/python3 - -# This file create the gui to install code model in the ngspice. +# This file create the GUI to install code model in the Ngspice. import os import sys import shutil import subprocess -from PyQt4 import QtGui -from PyQt4 import QtCore -from configparser import SafeConfigParser +from PyQt5 import QtGui, QtCore, QtWidgets +from configparser import ConfigParser from Appconfig import Appconfig from createKicadLibrary import AutoSchematic from model_generation import ModelGeneration -class Mainwindow(QtGui.QWidget): +class Mainwindow(QtWidgets.QWidget): def __init__(self): # super(Mainwindow, self).__init__() - QtGui.QMainWindow.__init__(self) + QtWidgets.QMainWindow.__init__(self) print("Initializing..........") self.home = os.path.expanduser("~") # Reading all variables from config.ini - self.parser = SafeConfigParser() + self.parser = ConfigParser() self.parser.read( os.path.join(self.home, os.path.join('.nghdl', 'config.ini')) ) @@ -41,20 +39,20 @@ class Mainwindow(QtGui.QWidget): self.initUI() def initUI(self): - self.uploadbtn = QtGui.QPushButton('Upload') + self.uploadbtn = QtWidgets.QPushButton('Upload') self.uploadbtn.clicked.connect(self.uploadModel) - self.exitbtn = QtGui.QPushButton('Exit') + self.exitbtn = QtWidgets.QPushButton('Exit') self.exitbtn.clicked.connect(self.closeWindow) - self.browsebtn = QtGui.QPushButton('Browse') + self.browsebtn = QtWidgets.QPushButton('Browse') self.browsebtn.clicked.connect(self.browseFile) - self.addbtn = QtGui.QPushButton('Add Files') + self.addbtn = QtWidgets.QPushButton('Add Files') self.addbtn.clicked.connect(self.addFiles) - self.removebtn = QtGui.QPushButton('Remove Files') + self.removebtn = QtWidgets.QPushButton('Remove Files') self.removebtn.clicked.connect(self.removeFiles) - self.ledit = QtGui.QLineEdit(self) - self.sedit = QtGui.QTextEdit(self) + self.ledit = QtWidgets.QLineEdit(self) + self.sedit = QtWidgets.QTextEdit(self) self.process = QtCore.QProcess(self) - self.termedit = QtGui.QTextEdit(self) + self.termedit = QtWidgets.QTextEdit(self) self.termedit.setReadOnly(1) pal = QtGui.QPalette() bgc = QtGui.QColor(0, 0, 0) @@ -63,7 +61,7 @@ class Mainwindow(QtGui.QWidget): self.termedit.setStyleSheet("QTextEdit {color:white}") # Creating gridlayout - grid = QtGui.QGridLayout() + grid = QtWidgets.QGridLayout() grid.setSpacing(5) grid.addWidget(self.ledit, 1, 0) grid.addWidget(self.browsebtn, 1, 1) @@ -90,15 +88,15 @@ class Mainwindow(QtGui.QWidget): def browseFile(self): print("Browse button clicked") - self.filename = QtGui.QFileDialog.getOpenFileName( - self, 'Open File', '.') + self.filename = QtWidgets.QFileDialog.getOpenFileName( + self, 'Open File', '.')[0] self.ledit.setText(self.filename) print("Vhdl file uploaded to process :", self.filename) def addFiles(self): print("Starts adding supporting files") title = self.addbtn.text() - for file in QtGui.QFileDialog.getOpenFileNames(self, title): + for file in QtWidgets.QFileDialog.getOpenFileNames(self, title)[0]: self.sedit.append(str(file)) self.file_list.append(file) print("Supporting Files are :", self.file_list) @@ -116,7 +114,7 @@ class Mainwindow(QtGui.QWidget): self.file_list.remove(file) if nonvhdl_count > 0: - QtGui.QMessageBox.critical( + QtWidgets.QMessageBox.critical( self, 'Critical', '''<b>Important Message.</b> <br/><br/>Supporting files should be <b>.vhdl</b> file ''' ) @@ -131,14 +129,14 @@ class Mainwindow(QtGui.QWidget): # Looking if model directory is present or not if os.path.isdir(self.modelname): print("Model Already present") - ret = QtGui.QMessageBox.warning( + ret = QtWidgets.QMessageBox.warning( self, "Warning", "<b>This model already exist. Do you want to " + "overwrite it?</b><br/> If yes press ok, else cancel it and " + "change the name of your vhdl file.", - QtGui.QMessageBox.Ok, QtGui.QMessageBox.Cancel + QtWidgets.QMessageBox.Ok, QtWidgets.QMessageBox.Cancel ) - if ret == QtGui.QMessageBox.Ok: + if ret == QtWidgets.QMessageBox.Ok: print("Overwriting existing model " + self.modelname) if os.name == 'nt': cmd = "rmdir " + self.modelname + "/s /q" @@ -250,7 +248,7 @@ class Mainwindow(QtGui.QWidget): str(self.process.readAllStandardOutput().data(), encoding='utf-8') ) stderror = self.process.readAllStandardError() - if stderror.toUpper().contains("ERROR"): + if stderror.toUpper().contains(b"ERROR"): self.errorFlag = True self.termedit.append(str(stderror.data(), encoding='utf-8')) @@ -295,10 +293,7 @@ class Mainwindow(QtGui.QWidget): self.process = QtCore.QProcess(self) self.process.start(cmd) self.process.finished.connect(self.createSchematicLib) - QtCore.QObject.connect( - self.process, QtCore.SIGNAL("readyReadStandardOutput()"), - self, QtCore.SLOT("readAllStandard()") - ) + self.process.readyReadStandardOutput.connect(self.readAllStandard) os.chdir(self.cur_dir) except BaseException: @@ -309,16 +304,16 @@ class Mainwindow(QtGui.QWidget): if Appconfig.esimFlag == 1: if not self.errorFlag: print('Creating library files................................') - schematicLib = AutoSchematic(self.modelname) + schematicLib = AutoSchematic(self, self.modelname) schematicLib.createKicadLibrary() else: - QtGui.QMessageBox.critical( + QtWidgets.QMessageBox.critical( self, 'Error', '''Cannot create Schematic Library of ''' + '''your model. Resolve the <b>errors</b> shown on ''' + '''console of NGHDL window. ''' ) else: - QtGui.QMessageBox.information( + QtWidgets.QMessageBox.information( self, 'Message', '''<b>Important Message</b><br/><br/>''' + '''To create Schematic Library of your model, ''' + '''use NGHDL through <b>eSim</b> ''' @@ -344,15 +339,15 @@ class Mainwindow(QtGui.QWidget): self.runMake() self.runMakeInstall() else: - QtGui.QMessageBox.information( + QtWidgets.QMessageBox.information( self, 'Message', '''<b>Important Message.</b><br/>''' + '''<br/>This accepts only <b>.vhdl</b> file ''' ) except Exception as e: - QtGui.QMessageBox.critical(self, 'Error', str(e)) + QtWidgets.QMessageBox.critical(self, 'Error', str(e)) -class FileRemover(QtGui.QWidget): +class FileRemover(QtWidgets.QWidget): def __init__(self, main_obj): super(FileRemover, self).__init__() @@ -365,8 +360,8 @@ class FileRemover(QtGui.QWidget): print(self.files) - self.grid = QtGui.QGridLayout() - removebtn = QtGui.QPushButton('Remove', self) + self.grid = QtWidgets.QGridLayout() + removebtn = QtWidgets.QPushButton('Remove', self) removebtn.clicked.connect(self.removeFiles) self.grid.addWidget(self.createCheckBox(), 0, 0) @@ -376,15 +371,15 @@ class FileRemover(QtGui.QWidget): self.show() def createCheckBox(self): - self.checkbox = QtGui.QGroupBox() + self.checkbox = QtWidgets.QGroupBox() self.checkbox.setTitle('Remove Files') - self.checkgrid = QtGui.QGridLayout() + self.checkgrid = QtWidgets.QGridLayout() - self.checkgroupbtn = QtGui.QButtonGroup() + self.checkgroupbtn = QtWidgets.QButtonGroup() for path in self.files: print(path) - self.cb_dict[path] = QtGui.QCheckBox(path) + self.cb_dict[path] = QtWidgets.QCheckBox(path) self.checkgroupbtn.addButton(self.cb_dict[path]) self.checkgrid.addWidget(self.cb_dict[path], self.row, self.col) self.row += 1 @@ -420,7 +415,7 @@ class FileRemover(QtGui.QWidget): def main(): - app = QtGui.QApplication(sys.argv) + app = QtWidgets.QApplication(sys.argv) if len(sys.argv) > 1: if sys.argv[1] == '-e': Appconfig.esimFlag = 1 diff --git a/src/outitf.c b/src/outitf.c index 7cd0ddb..1ac92ab 100644 --- a/src/outitf.c +++ b/src/outitf.c @@ -21,9 +21,9 @@ Modified: 2000 AlansFixes, 2013/2015 patch by Krzysztof Blaszkowski #include "ngspice/ngspice.h" -/*05.June.2020 - BM - Added follwing includes for Windows OS */ +/*05.June.2020 - BM - Added follwing includes for Win OS */ #ifdef _WIN32 - #undef BOOLEAN /* Undefine it due to conflicting definitions in Windows OS */ + #undef BOOLEAN /* Undefine it due to conflicting definitions in Win OS */ #include <ws2tcpip.h> #include <winsock2.h> @@ -58,7 +58,6 @@ Modified: 2000 AlansFixes, 2013/2015 patch by Krzysztof Blaszkowski /* 27.May.2020 - BM - Added the following #include */ #ifdef __linux__ - #include <stdio.h> #include <sys/socket.h> #include <arpa/inet.h> #include <unistd.h> @@ -206,12 +205,14 @@ static void close_server() closesocket(sock); #endif } + + fclose(fptr); } #ifdef _WIN32 WSACleanup(); #endif - fclose(fptr); + remove(ip_filename); } |