Commit 7398bc23 authored by Michael Büsch's avatar Michael Büsch

Change core server API to expect HwmodDescriptors

Signed-off-by: Michael Büsch's avatarMichael Buesch <m@bues.ch>
parent e4fa10bc
......@@ -281,10 +281,9 @@ def runWithServerBackend(inputFile):
# Load hardware modules
for modDesc in project.getHwmodSettings().getLoadedModules():
client.loadHardwareModule(modDesc.getModuleName(),
modDesc.getParameters())
client.loadHardwareModule(modDesc)
for name, parameters in opt_hwmods:
client.loadHardwareModule(name, parameters)
client.loadHardwareModule(HwmodDescriptor(name, parameters))
# Configure the core
if opt_noCpuDump:
......
......@@ -356,8 +356,7 @@ def main():
# Configure the core and the core server.
server = AwlSimServer()
for modDesc in hwmodSettings.getLoadedModules():
server.loadHardwareModule(modDesc.getModuleName(),
modDesc.getParameters())
server.loadHardwareModule(modDesc)
server.cpuEnableObTempPresets(project.getObTempPresetsEn())
server.cpuEnableExtendedInsns(project.getExtInsnsEn() or\
opt_extInsns)
......
# -*- coding: utf-8 -*-
#
# AWL simulator - Hardware module descriptors
#
# Copyright 2014-2015 Michael Buesch <m@bues.ch>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
from __future__ import division, absolute_import, print_function, unicode_literals
from awlsim.common.compat import *
from awlsim.common.util import *
class HwmodDescriptor(object):
"""Hardware module descriptor."""
def __init__(self, moduleName, parameters = None):
"""Hardware module descriptor initialization.
moduleName -> module name string
parameters -> parameter dict with
keys -> parameter name
values -> parameter value
"""
self.setModuleName(moduleName)
self.setParameters(parameters)
def dup(self):
"""Duplicate this descriptor.
"""
return HwmodDescriptor(self.getModuleName(),
dict(self.getParameters()))
def setModuleName(self, moduleName):
"""Set the module name string.
"""
self.moduleName = moduleName
def getModuleName(self):
"""Get the module name string.
"""
return self.moduleName
def setParameters(self, parameters):
"""Set the parameters dict.
"""
if not parameters:
parameters = {}
self.parameters = parameters
def addParameter(self, name, value):
"""Add a parameter to the parameter dict.
"""
self.setParameterValue(name, value)
def setParameterValue(self, name, value):
"""Set the value of a parameter.
"""
self.parameters[name] = value
def removeParameter(self, name):
"""Remove a parameter from the parameter dict.
"""
self.parameters.pop(name, None)
def getParameters(self):
"""Get the parameters dict (reference).
"""
return self.parameters
def getParameter(self, name):
"""Get one parameter by name.
"""
return self.parameters.get(name)
#TODO hash
......@@ -24,6 +24,7 @@ from awlsim.common.compat import *
from awlsim.common.cpuspecs import *
from awlsim.common.sources import *
from awlsim.common.hwmod import *
from awlsim.common.util import *
from awlsim.library.libselection import *
......@@ -40,43 +41,6 @@ else:
from configparser import Error as _ConfigParserError
class HwmodDescriptor(object):
"""Hardware module descriptor."""
def __init__(self, moduleName, parameters = None):
self.setModuleName(moduleName)
self.setParameters(parameters)
def dup(self):
return HwmodDescriptor(self.getModuleName(),
dict(self.getParameters()))
def setModuleName(self, moduleName):
self.moduleName = moduleName
def getModuleName(self):
return self.moduleName
def setParameters(self, parameters):
if not parameters:
parameters = {}
self.parameters = parameters
def addParameter(self, name, value):
self.setParameterValue(name, value)
def setParameterValue(self, name, value):
self.parameters[name] = value
def removeParameter(self, name):
self.parameters.pop(name, None)
def getParameters(self):
return self.parameters
def getParameter(self, name):
return self.parameters.get(name)
class GuiSettings(object):
def __init__(self,
editorAutoIndentEn=True,
......
......@@ -425,11 +425,10 @@ class AwlSimClient(object):
raise AwlSimError("AwlSimClient: Failed to load library block selection")
return True
def loadHardwareModule(self, name, parameters={}):
def loadHardwareModule(self, hwmodDesc):
if not self.__transceiver:
return False
msg = AwlSimMessage_HWMOD(name = name,
paramDict = parameters)
msg = AwlSimMessage_HWMOD(hwmodDesc)
status = self.__sendAndWaitFor_REPLY(msg)
if status != AwlSimMessage_REPLY.STAT_OK:
raise AwlSimError("AwlSimClient: Failed to load hardware module")
......
......@@ -24,6 +24,7 @@ from awlsim.common.compat import *
from awlsim.common.cpuspecs import *
from awlsim.common.project import *
from awlsim.common.hwmod import *
from awlsim.common.datatypehelpers import *
from awlsim.coreserver.memarea import *
......@@ -101,7 +102,8 @@ class AwlSimMessage(object):
MSG_ID_LIBSEL = EnumGen.item
MSG_ID_GET_IDENTS = EnumGen.itemAt(0x0190)
MSG_ID_IDENTS = EnumGen.item
#TODO: add messages to get compiled block info
MSG_ID_GET_BLOCKINFO = EnumGen.item
MSG_ID_BLOCKINFO = EnumGen.item
#TODO: add messages to delete compiled blocks and sources
# Configuration
MSG_ID_GET_OPT = EnumGen.itemAt(0x0200) #TODO not implemented, yet
......@@ -338,15 +340,15 @@ class AwlSimMessage_AWLSRC(_AwlSimMessage_source):
class AwlSimMessage_HWMOD(AwlSimMessage):
msgId = AwlSimMessage.MSG_ID_HWMOD
def __init__(self, name, paramDict):
self.name = name
self.paramDict = paramDict
# hwmodDesc -> HwmodDescriptor instance
def __init__(self, hwmodDesc):
self.hwmodDesc = hwmodDesc
def toBytes(self):
payload = b""
try:
payload += self.packString(self.name)
for pname, pval in self.paramDict.items():
payload += self.packString(self.hwmodDesc.getModuleName())
for pname, pval in self.hwmodDesc.getParameters().items():
payload += self.packString(pname)
payload += self.packString(pval)
return AwlSimMessage.toBytes(self, len(payload)) + payload
......@@ -368,7 +370,7 @@ class AwlSimMessage_HWMOD(AwlSimMessage):
paramDict[pname] = pval
except (ValueError) as e:
raise TransferError("LOAD_HW: Invalid data format")
return cls(name = name, paramDict = paramDict)
return cls(HwmodDescriptor(name, paramDict))
class AwlSimMessage_LIBSEL(AwlSimMessage):
msgId = AwlSimMessage.MSG_ID_LIBSEL
......@@ -809,7 +811,7 @@ class AwlSimMessage_IDENTS(AwlSimMessage):
# awlSources: List of AwlSource()s
# symTabSources: List of SymTabSource()s
# hwMods: List of tuples: (modName, parametersDict)
# hwMods: List of HwmodDescriptor()s
# libSelections: List of AwlLibEntrySelection()s
def __init__(self, awlSources, symTabSources, hwMods, libSelections):
self.awlSources = awlSources
......@@ -831,10 +833,11 @@ class AwlSimMessage_IDENTS(AwlSimMessage):
payload.append(self.packString(src.name))
payload.append(self.packString(src.filepath))
payload.append(self.packBytes(src.identHash))
for modName, parametersDict in self.hwMods:
payload.append(self.plModStruct.pack(len(parametersDict), 0))
payload.append(self.packString(modName))
for pName, pVal in parametersDict.items():
for hwmodDesc in self.hwMods:
params = hwmodDesc.getParameters()
payload.append(self.plModStruct.pack(len(params), 0))
payload.append(self.packString(hwmodDesc.getModuleName()))
for pName, pVal in params.items():
payload.append(self.packString(pName))
payload.append(self.packString(pVal))
for libSel in self.libSelections:
......@@ -898,6 +901,37 @@ class AwlSimMessage_IDENTS(AwlSimMessage):
hwMods = hwMods,
libSelections = libSelections)
class AwlSimMessage_GET_BLOCKINFO(AwlSimMessage):
msgId = AwlSimMessage.MSG_ID_GET_BLOCKINFO
# Get-flags. Specify what information to get.
EnumGen.start
GET_OB_INFO = EnumGen.bitmask # Get OB info
GET_FC_INFO = EnumGen.bitmask # Get FC info
GET_FB_INFO = EnumGen.bitmask # Get FB info
GET_DB_INFO = EnumGen.bitmask # Get DB info
EnumGen.end
# Payload header struct:
# Get-flags (32 bit)
# Reserved (32 bit)
plHdrStruct = struct.Struct(str(">II"))
def __init__(self, getFlags):
self.getFlags = getFlags
def toBytes(self):
payload = self.plHdrStruct.pack(self.getFlags, 0)
return AwlSimMessage.toBytes(self, len(payload)) + payload
@classmethod
def fromBytes(cls, payload):
try:
getFlags, _unused = cls.plHdrStruct.unpack_from(payload, 0)
except (ValueError, struct.error) as e:
raise TransferError("GET_BLOCKINFO: Invalid data format")
return cls(getFlags)
class AwlSimMessageTransceiver(object):
id2class = {
AwlSimMessage.MSG_ID_REPLY : AwlSimMessage_REPLY,
......
......@@ -216,8 +216,7 @@ class AwlSimServer(object):
self.awlSourceContainer = SourceContainer()
# Container of loaded and managed SymTabSource()s
self.symTabSourceContainer = SourceContainer()
# List of tuples of loaded hardware modules:
# (hwModName, parameterDict)
# List of tuples of loaded hardware modules (HwmodDescriptor instances)
self.loadedHwModules = []
# List of loaded AwlLibEntrySelection()s
self.loadedLibSelections = []
......@@ -446,12 +445,13 @@ class AwlSimServer(object):
self.symTabSourceContainer.addManager(srcManager)
def loadHardwareModule(self, moduleName, paramDict):
printInfo("Loading hardware module '%s'..." % moduleName)
hwClass = self.__sim.loadHardwareModule(moduleName)
def loadHardwareModule(self, hwmodDesc):
printInfo("Loading hardware module '%s'..." %\
hwmodDesc.getModuleName())
hwClass = self.__sim.loadHardwareModule(hwmodDesc.getModuleName())
self.__sim.registerHardwareClass(hwClass = hwClass,
parameters = paramDict)
self.loadedHwModules.append( (moduleName, paramDict) )
parameters = hwmodDesc.getParameters())
self.loadedHwModules.append(hwmodDesc)
def loadLibraryBlock(self, libSelection):
self.setRunState(self.STATE_STOP)
......@@ -557,7 +557,7 @@ class AwlSimServer(object):
def __rx_HWMOD(self, client, msg):
printDebug("Received message: HWMOD")
status = AwlSimMessage_REPLY.STAT_OK
self.loadHardwareModule(msg.name, msg.paramDict)
self.loadHardwareModule(msg.hwmodDesc)
client.transceiver.send(AwlSimMessage_REPLY.make(msg, status))
def __rx_LIBSEL(self, client, msg):
......
......@@ -597,8 +597,7 @@ class CpuWidget(QWidget):
client.enableExtendedInsns(project.getExtInsnsEn())
for modDesc in project.getHwmodSettings().getLoadedModules():
client.loadHardwareModule(modDesc.getModuleName(),
modDesc.getParameters())
client.loadHardwareModule(modDesc)
for symTabSource in symTabSources:
client.loadSymTabSource(symTabSource)
for libSel in libSelections:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment