Commit dd46b322 authored by Michael Büsch's avatar Michael Büsch

coreserver: Add basic fup/kop support

Signed-off-by: Michael Büsch's avatarMichael Buesch <m@bues.ch>
parent 0eaa0f3b
......@@ -371,6 +371,10 @@ def main():
server.loadLibraryBlock(libSel)
for awlSrc in project.getAwlSources():
server.loadAwlSource(awlSrc)
for fupSrc in project.getFupSources():
server.loadFupSource(fupSrc)
for kopSrc in project.getKopSources():
server.loadKopSource(kopSrc)
# Set the Linux-CNC watchdog as cycle exit hook.
server.setCycleExitHook(watchdogHook)
......
......@@ -167,11 +167,23 @@ def run(inputFile):
project = Project.fromProjectOrRawAwlFile(inputFile)
writeStdout("Parsing code...\n")
generatedAwlSrcs = []
# Parse FUP sources
#TODO
# Parse KOP sources
#TODO
# Parse AWL sources
parseTrees = []
for awlSrc in project.getAwlSources():
for awlSrc in itertools.chain(project.getAwlSources(),
generatedAwlSrcs):
p = AwlParser()
p.parseSource(awlSrc)
parseTrees.append(p.getParseTree())
# Parse symbol tables
symTables = []
for symTabSrc in project.getSymTabSources():
mnemonics = project.getCpuSpecs().getConfiguredMnemonics()
......@@ -198,6 +210,7 @@ def run(inputFile):
for name, parameters in opt_hwmods:
loadMod(name, parameters)
# Configure the CPU
cpu = s.getCPU()
assignCpuSpecs(cpu.getSpecs(), project.getCpuSpecs())
cpu.enableObTempPresets(project.getObTempPresetsEn() or opt_obtemp)
......@@ -206,6 +219,8 @@ def run(inputFile):
cpu.setBlockExitCallback(cpuDumpCallback, cpu)
cpu.setCycleTimeLimit(opt_cycletime)
cpu.setRunTimeLimit(opt_maxRuntime)
# Download the program
writeStdout("Initializing CPU...\n")
for symTable in symTables:
s.loadSymbolTable(symTable)
......@@ -213,6 +228,8 @@ def run(inputFile):
s.loadLibraryBlock(libSel)
for parseTree in parseTrees:
s.load(parseTree)
# Run the program
s.startup()
writeStdout("[Initialization finished - CPU is executing user code]\n")
try:
......
......@@ -111,7 +111,9 @@ class AwlValidator(object):
client.reset()
client.loadProject(project, loadSymTabs=False,
loadLibSelections=False,
loadSources=False)
loadSources=False,
loadFup=False,
loadKop=False)
client.loadSymTabSources(symTabSources)
client.loadLibraryBlocks(libSelections)
client.loadAwlSources(awlSources)
......
......@@ -450,13 +450,47 @@ class AwlSimClient(object):
finally:
self.__transceiver.txCork(False)
if status != AwlSimMessage_REPLY.STAT_OK:
raise AwlSimError("AwlSimClient: Failed to AWL source")
raise AwlSimError("AwlSimClient: Failed to load AWL source")
return True
def loadFupSource(self, fupSource):
if not self.__transceiver:
return False
msg = AwlSimMessage_FUPSRC(fupSource)
self.__transceiver.txCork(True)
try:
status = self.__sendAndWaitFor_REPLY(msg, 10.0)
finally:
self.__transceiver.txCork(False)
if status != AwlSimMessage_REPLY.STAT_OK:
raise AwlSimError("AwlSimClient: Failed to load FUP source")
return True
def loadKopSource(self, kopSource):
if not self.__transceiver:
return False
msg = AwlSimMessage_KOPSRC(fupSource)
self.__transceiver.txCork(True)
try:
status = self.__sendAndWaitFor_REPLY(msg, 10.0)
finally:
self.__transceiver.txCork(False)
if status != AwlSimMessage_REPLY.STAT_OK:
raise AwlSimError("AwlSimClient: Failed to load FUP source")
return True
def loadAwlSources(self, awlSources):
return all(self.loadAwlSource(awlSource)
for awlSource in awlSources)
def loadFupSources(self, fupSources):
return all(self.loadFupSource(fupSource)
for fupSource in fupSources)
def loadKopSources(self, kopSources):
return all(self.loadKopSource(kopSource)
for kopSource in kopSources)
def getSymTabSource(self, identHash, sync=True):
if not self.__transceiver:
return False
......@@ -654,7 +688,8 @@ class AwlSimClient(object):
loadCpuSpecs=True, loadTempPresets=True,
loadExtInsns=True, loadHwMods=True,
loadSymTabs=True, loadLibSelections=True,
loadSources=True):
loadSources=True,
loadFup=True, loadKop=True):
"""Load selected settings and sources from project.
"""
if loadCpuSpecs:
......@@ -671,6 +706,10 @@ class AwlSimClient(object):
self.loadLibraryBlocks(project.getLibSelections())
if loadSources:
self.loadAwlSources(project.getAwlSources())
if loadFup:
self.loadFupSources(project.getFupSources())
if loadKop:
self.loadKopSources(project.getKopSources())
# Set the memory areas we are interested in receiving
# dumps for, in the server.
......
......@@ -80,7 +80,7 @@ class AwlSimMessage(object):
# Payload (optional)
hdrStruct = struct.Struct(str(">HHHHI"))
HDR_MAGIC = 0x5715
HDR_MAGIC = 0x5716
HDR_LENGTH = hdrStruct.size
# Message IDs:
......@@ -100,6 +100,10 @@ class AwlSimMessage(object):
MSG_ID_SYMTABSRC = EnumGen.item
MSG_ID_HWMOD = EnumGen.item
MSG_ID_LIBSEL = EnumGen.item
MSG_ID_GET_FUPSRC = EnumGen.item #TODO not implemented, yet
MSG_ID_FUPSRC = EnumGen.item
MSG_ID_GET_KOPSRC = EnumGen.item #TODO not implemented, yet
MSG_ID_KOPSRC = EnumGen.item
MSG_ID_BUILD = EnumGen.itemAt(0x0170)
MSG_ID_REMOVESRC = EnumGen.itemAt(0x0180)
MSG_ID_REMOVEBLK = EnumGen.item
......@@ -115,7 +119,7 @@ class AwlSimMessage(object):
# State
MSG_ID_GET_RUNSTATE = EnumGen.itemAt(0x0300)
MSG_ID_RUNSTATE = EnumGen.item
MSG_ID_GET_CPUDUMP = EnumGen.item #TODO not implemented, yet
MSG_ID_GET_CPUDUMP = EnumGen.item #TODO not implemented, yet
MSG_ID_CPUDUMP = EnumGen.item
MSG_ID_REQ_MEMORY = EnumGen.item
MSG_ID_MEMORY = EnumGen.item
......@@ -377,6 +381,20 @@ class AwlSimMessage_AWLSRC(_AwlSimMessage_source):
msgId = AwlSimMessage.MSG_ID_AWLSRC
sourceClass = AwlSource
class AwlSimMessage_GET_FUPSRC(_AwlSimMessage_GET_source):
msgId = AwlSimMessage.MSG_ID_GET_FUPSRC
class AwlSimMessage_FUPSRC(_AwlSimMessage_source):
msgId = AwlSimMessage.MSG_ID_FUPSRC
sourceClass = FupSource
class AwlSimMessage_GET_KOPSRC(_AwlSimMessage_GET_source):
msgId = AwlSimMessage.MSG_ID_GET_KOPSRC
class AwlSimMessage_KOPSRC(_AwlSimMessage_source):
msgId = AwlSimMessage.MSG_ID_KOPSRC
sourceClass = KopSource
class AwlSimMessage_HWMOD(AwlSimMessage):
msgId = AwlSimMessage.MSG_ID_HWMOD
......@@ -748,7 +766,7 @@ class AwlSimMessage_INSNSTATE(AwlSimMessage):
# CPU AR 2 (32 bit)
# CPU DB register (16 bit)
# CPU DI register (16 bit)
# AWL source ident hash bytes (variable length)
# Source ident hash bytes (variable length)
plDataStruct = struct.Struct(str(">IIHHIIIIIIHH"))
def __init__(self, sourceId, lineNr, serial, flags, stw, accu1, accu2, accu3, accu4, ar1, ar2, db, di):
......@@ -881,6 +899,8 @@ class AwlSimMessage_GET_IDENTS(AwlSimMessage):
GET_SYMTABSRCS = EnumGen.bitmask # Get SymTabSource()s (w/o data)
GET_HWMODS = EnumGen.bitmask # Get HW modules
GET_LIBSELS = EnumGen.bitmask # Get AwlLibEntrySelection()s
GET_FUPSRCS = EnumGen.bitmask # Get FupSource()s (w/o data)
GET_KOPSRCS = EnumGen.bitmask # Get KopSource()s (w/o data)
EnumGen.end
# Payload header struct:
......@@ -911,48 +931,64 @@ class AwlSimMessage_IDENTS(AwlSimMessage):
# Number of symbol tables (32 bit)
# Number of hardware modules (32 bit)
# Number of library selections (32 bit)
# Number of FUP sources (32 bit)
# Number of KOP sources (32 bit)
# Reserved (32 bit)
# Reserved (32 bit)
# Reserved (32 bit)
# Reserved (32 bit)
plHdrStruct = struct.Struct(str(">IIIIII"))
# Reserved (32 bit)
# Reserved (32 bit)
# Reserved (32 bit)
# Reserved (32 bit)
# Reserved (32 bit)
# Reserved (32 bit)
plHdrStruct = struct.Struct(str(">6I40x"))
# Payload module header struct:
# Number of parameters (32 bit)
# Reserved (32 bit)
plModStruct = struct.Struct(str(">II"))
# Reserved (32 bit)
# Reserved (32 bit)
plModStruct = struct.Struct(str(">I12x"))
# awlSources: List of AwlSource()s
# symTabSources: List of SymTabSource()s
# hwMods: List of HwmodDescriptor()s
# libSelections: List of AwlLibEntrySelection()s
def __init__(self, awlSources, symTabSources, hwMods, libSelections):
def __init__(self, awlSources, symTabSources, hwMods, libSelections, fupSources, kopSources):
self.awlSources = awlSources
self.symTabSources = symTabSources
self.hwMods = hwMods
self.libSelections = libSelections
self.fupSources = fupSources
self.kopSources = kopSources
def toBytes(self):
payload = [ self.plHdrStruct.pack(len(self.awlSources),
len(self.symTabSources),
len(self.hwMods),
len(self.libSelections),
0, 0), ]
for src in self.awlSources:
payload.append(self.packString(src.name))
payload.append(self.packString(src.filepath))
payload.append(self.packBytes(src.identHash))
for src in self.symTabSources:
payload.append(self.packString(src.name))
payload.append(self.packString(src.filepath))
payload.append(self.packBytes(src.identHash))
len(self.fupSources),
len(self.kopSources)) ]
def addSrcs(srcs):
for src in srcs:
payload.append(self.packString(src.name))
payload.append(self.packString(src.filepath))
payload.append(self.packBytes(src.identHash))
addSrcs(self.awlSources)
addSrcs(self.symTabSources)
for hwmodDesc in self.hwMods:
params = hwmodDesc.getParameters()
payload.append(self.plModStruct.pack(len(params), 0))
payload.append(self.plModStruct.pack(len(params)))
payload.append(self.packString(hwmodDesc.getModuleName()))
for pName, pVal in dictItems(params):
payload.append(self.packString(pName))
payload.append(self.packString(pVal))
for libSel in self.libSelections:
payload.append(AwlSimMessage_LIBSEL.packLibSelection(libSel))
addSrcs(self.fupSources)
addSrcs(self.kopSources)
payload = b''.join(payload)
return AwlSimMessage.toBytes(self, len(payload)) + payload
......@@ -963,33 +999,29 @@ class AwlSimMessage_IDENTS(AwlSimMessage):
symTabSources = []
hwMods = []
libSelections = []
fupSources = []
kopSources = []
offset = 0
nrAwl, nrSym, nrHw, nrLib, _a, _b = cls.plHdrStruct.unpack_from(
nrAwl, nrSym, nrHw, nrLib, nrFup, nrKop = cls.plHdrStruct.unpack_from(
payload, offset)
offset += cls.plHdrStruct.size
for i in range(nrAwl):
name, count = cls.unpackString(payload, offset)
offset += count
path, count = cls.unpackString(payload, offset)
offset += count
identHash, count = cls.unpackBytes(payload, offset)
offset += count
src = AwlSource(name, path, None)
src.identHash = identHash # Force hash
awlSources.append(src)
for i in range(nrSym):
name, count = cls.unpackString(payload, offset)
offset += count
path, count = cls.unpackString(payload, offset)
offset += count
identHash, count = cls.unpackBytes(payload, offset)
offset += count
src = SymTabSource(name, path, None)
src.identHash = identHash # Force hash
symTabSources.append(src)
def unpackSrcs(srcClass, sourcesList, count, offset):
for i in range(count):
name, count = cls.unpackString(payload, offset)
offset += count
path, count = cls.unpackString(payload, offset)
offset += count
identHash, count = cls.unpackBytes(payload, offset)
offset += count
src = srcClass(name, path, None)
src.identHash = identHash # Force hash
sourcesList.append(src)
return offset
offset = unpackSrcs(AwlSource, awlSources, nrAwl, offset)
offset = unpackSrcs(SymTabSource, symTabSources, nrSym, offset)
for i in range(nrHw):
nrParam, _unused = cls.plModStruct.unpack_from(
payload, offset)
(nrParam, ) = cls.plModStruct.unpack_from(
payload, offset)
offset += cls.plModStruct.size
modName, count = cls.unpackString(payload, offset)
offset += count
......@@ -1005,12 +1037,16 @@ class AwlSimMessage_IDENTS(AwlSimMessage):
libSel, offset = AwlSimMessage_LIBSEL.unpackLibSelection(
payload, offset)
libSelections.append(libSel)
offset = unpackSrcs(FupSource, fupSources, nrFup, offset)
offset = unpackSrcs(KopSource, kopSources, nrKop, offset)
except (ValueError, struct.error, AwlSimError) as e:
raise TransferError("IDENTS: Invalid data format")
return cls(awlSources = awlSources,
symTabSources = symTabSources,
hwMods = hwMods,
libSelections = libSelections)
libSelections = libSelections,
fupSources = fupSources,
kopSources = kopSources)
class AwlSimMessage_GET_BLOCKINFO(AwlSimMessage):
msgId = AwlSimMessage.MSG_ID_GET_BLOCKINFO
......@@ -1109,6 +1145,10 @@ class AwlSimMessageTransceiver(object):
AwlSimMessage.MSG_ID_SYMTABSRC : AwlSimMessage_SYMTABSRC,
AwlSimMessage.MSG_ID_HWMOD : AwlSimMessage_HWMOD,
AwlSimMessage.MSG_ID_LIBSEL : AwlSimMessage_LIBSEL,
AwlSimMessage.MSG_ID_GET_FUPSRC : AwlSimMessage_GET_FUPSRC,
AwlSimMessage.MSG_ID_FUPSRC : AwlSimMessage_FUPSRC,
AwlSimMessage.MSG_ID_GET_KOPSRC : AwlSimMessage_GET_KOPSRC,
AwlSimMessage.MSG_ID_KOPSRC : AwlSimMessage_KOPSRC,
AwlSimMessage.MSG_ID_BUILD : AwlSimMessage_BUILD,
AwlSimMessage.MSG_ID_REMOVESRC : AwlSimMessage_REMOVESRC,
AwlSimMessage.MSG_ID_REMOVEBLK : AwlSimMessage_REMOVEBLK,
......
......@@ -559,6 +559,12 @@ class AwlSimServer(object):
self.awlSourceContainer.addManager(srcManager)
self.__updateProjectFile()
def loadFupSource(self, fupSource):
pass#TODO
def loadKopSource(self, kopSource):
pass#TODO
def loadSymTabSource(self, symTabSource):
symbolTable = SymTabParser.parseSource(symTabSource,
autodetectFormat = True,
......@@ -698,6 +704,18 @@ class AwlSimServer(object):
self.loadLibraryBlock(msg.libSelection)
client.transceiver.send(AwlSimMessage_REPLY.make(msg, status))
def __rx_FUPSRC(self, client, msg):
printDebug("Received message: FUPSRC")
status = AwlSimMessage_REPLY.STAT_OK
self.loadFupSource(msg.source)
client.transceiver.send(AwlSimMessage_REPLY.make(msg, status))
def __rx_KOPSRC(self, client, msg):
printDebug("Received message: KOPSRC")
status = AwlSimMessage_REPLY.STAT_OK
self.loadKopSource(msg.source)
client.transceiver.send(AwlSimMessage_REPLY.make(msg, status))
def __rx_BUILD(self, client, msg):
printDebug("Received message: BUILD")
status = AwlSimMessage_REPLY.STAT_OK
......@@ -809,7 +827,7 @@ class AwlSimServer(object):
def __rx_GET_IDENTS(self, client, msg):
printDebug("Received message: GET_IDENTS")
awlSrcs = symSrcs = hwMods = libSels = ()
awlSrcs = symSrcs = hwMods = libSels = fupSrcs = kopSrcs = ()
if msg.getFlags & msg.GET_AWLSRCS:
awlSrcs = self.awlSourceContainer.getSources()
if msg.getFlags & msg.GET_SYMTABSRCS:
......@@ -818,8 +836,13 @@ class AwlSimServer(object):
hwMods = self.loadedHwModules
if msg.getFlags & msg.GET_LIBSELS:
libSels = self.loadedLibSelections
if msg.getFlags & msg.GET_FUPSRCS:
pass#TODO
if msg.getFlags & msg.GET_KOPSRCS:
pass#TODO
reply = AwlSimMessage_IDENTS(awlSrcs, symSrcs,
hwMods, libSels)
hwMods, libSels,
fupSrcs, kopSrcs)
client.transceiver.send(reply)
__msgRxHandlers = {
......@@ -835,6 +858,8 @@ class AwlSimServer(object):
AwlSimMessage.MSG_ID_SYMTABSRC : __rx_SYMTABSRC,
AwlSimMessage.MSG_ID_HWMOD : __rx_HWMOD,
AwlSimMessage.MSG_ID_LIBSEL : __rx_LIBSEL,
AwlSimMessage.MSG_ID_FUPSRC : __rx_FUPSRC,
# AwlSimMessage.MSG_ID_KOPSRC : __rx_KOPSRC,
AwlSimMessage.MSG_ID_BUILD : __rx_BUILD,
AwlSimMessage.MSG_ID_REMOVESRC : __rx_REMOVESRC,
AwlSimMessage.MSG_ID_REMOVEBLK : __rx_REMOVEBLK,
......@@ -994,6 +1019,10 @@ class AwlSimServer(object):
self.loadLibraryBlock(libSel)
for awlSrc in project.getAwlSources():
self.loadAwlSource(awlSrc)
for fupSrc in project.getFupSources():
self.loadFupSource(fupSrc)
for kopSrc in project.getKopSources():
self.loadKopSource(kopSrc)
self.__projectFile = project.getProjectFile()
self.__projectWriteBack = writeBack
......
from __future__ import division, absolute_import, print_function, unicode_literals
......@@ -616,6 +616,8 @@ class CpuWidget(QWidget):
client = self.mainWidget.getSimClient()
project = self.mainWidget.getProject()
awlSources = self.mainWidget.projectWidget.getAwlSources()
fupSources = self.mainWidget.projectWidget.getFupSources()
kopSources = self.mainWidget.projectWidget.getKopSources()
symTabSources = self.mainWidget.projectWidget.getSymTabSources()
libSelections = self.mainWidget.projectWidget.getLibSelections()
if not all(awlSources) or not all(symTabSources):
......@@ -629,10 +631,14 @@ class CpuWidget(QWidget):
client.loadProject(project, loadSymTabs=False,
loadLibSelections=False,
loadSources=False)
loadSources=False,
loadFup=False,
loadKop=False)
client.loadSymTabSources(symTabSources)
client.loadLibraryBlocks(libSelections)
client.loadAwlSources(awlSources)
client.loadFupSources(fupSources)
client.loadKopSources(kopSources)
self.state.setState(RunState.STATE_ONLINE)
except AwlParserError as e:
......@@ -682,6 +688,20 @@ class CpuWidget(QWidget):
(awlSource.name,
awlSource.identHashStr))
client.loadAwlSource(awlSource)
elif selectedResource == projectWidget.RES_FUP:
fupSource = projectWidget.getCurrentFupSource()
if fupSource:
printVerbose("Single FUP download: %s/%s" %\
(fupSource.name,
fupSource.identHashStr))
client.loadFupSource(fupSource)
elif selectedResource == projectWidget.RES_KOP:
kopSource = projectWidget.getCurrentKopSource()
if kopSource:
printVerbose("Single KOP download: %s/%s" %\
(kopSource.name,
kopSource.identHashStr))
client.loadKopSource(kopSource)
elif selectedResource == projectWidget.RES_SYMTABS:
symTabSource = projectWidget.getCurrentSymTabSource()
if symTabSource:
......
from __future__ import division, absolute_import, print_function, unicode_literals
import awlsim_loader.cython_helper as __cython
__importmod = "awlsim.fupcompiler"
if __cython.shouldUseCython(__importmod): #@nocy
#if True: #@cy
__importcymod = __cython.cythonModuleName(__importmod)
try:
exec("from %s import *" % __importcymod)
except ImportError as e:
__cython.cythonImportError(__importcymod, str(e))
if not __cython.shouldUseCython(__importmod): #@nocy
exec("from %s import *" % __importmod) #@nocy
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