Commit 8c5b1498 authored by Michael Büsch's avatar Michael Büsch

Saner OB100/101/102 startup behavior

Signed-off-by: Michael Büsch's avatarMichael Buesch <m@bues.ch>
parent 1974377e
......@@ -622,11 +622,18 @@ class S7CPU(object):
self.startupTime = self.now
# Run startup OB
for obNumber in (100, 101, 102):
ob = self.obs.get(obNumber)
if ob is not None:
self.__runOB(ob)
break
if 102 in self.obs and self.is4accu:
# Cold start.
# This is only done on 4xx-series CPUs.
self.__runOB(self.obs[102])
elif 100 in self.obs:
# Warm start.
# This really is a cold start, because remanent
# resources were reset. However we could not execute
# OB 102, so this is a fallback.
# This is not 100% compliant with real CPUs, but it probably
# is sane behavior.
self.__runOB(self.obs[100])
# Run one cycle of the user program
def runCycle(self):
......
......@@ -28,6 +28,8 @@ from awlsim.core.util import *
class S7CPUSpecs(object):
"STEP 7 CPU Specifications"
# Mnemonic identifiers
# Note: These numbers are .awlpro file ABI.
EnumGen.start
MNEMONICS_AUTO = EnumGen.item
MNEMONICS_EN = EnumGen.item
......
......@@ -22,6 +22,7 @@
from __future__ import division, absolute_import, print_function, unicode_literals
from awlsim.core.compat import *
from awlsim.core.cpuspecs import *
from awlsim.core.util import *
import datetime
......@@ -42,10 +43,13 @@ else:
class Project(object):
def __init__(self, projectFile, awlFiles=[], symTabFiles=[]):
def __init__(self, projectFile, awlFiles=[], symTabFiles=[], cpuSpecs=None):
self.projectFile = projectFile
self.awlFiles = awlFiles
self.symTabFiles = symTabFiles
if not cpuSpecs:
cpuSpecs = S7CPUSpecs()
self.cpuSpecs = cpuSpecs
@classmethod
def dataIsProject(cls, data):
......@@ -71,6 +75,7 @@ class Project(object):
projectDir = os.path.dirname(projectFile)
awlFiles = []
symTabFiles = []
cpuSpecs = S7CPUSpecs()
try:
p = _ConfigParser()
p.readfp(StringIO(text), projectFile)
......@@ -81,6 +86,7 @@ class Project(object):
"File version is %d, but expected %d." %\
(version, expectedVersion))
# CPU section
nrAwl = p.getint("CPU", "nr_awl_files")
if nrAwl < 0 or nrAwl > 0xFFFF:
raise AwlSimError("Project file: Invalid number of "\
......@@ -88,7 +94,14 @@ class Project(object):
for i in range(nrAwl):
path = p.get("CPU", "awl_file_%d" % i)
awlFiles.append(cls.__generic2path(path, projectDir))
if p.has_option("CPU", "mnemonics"):
mnemonics = p.getint("CPU", "mnemonics")
cpuSpecs.setConfiguredMnemonics(mnemonics)
if p.has_option("CPU", "nr_accus"):
nrAccus = p.getint("CPU", "nr_accus")
cpuSpecs.setNrAccus(nrAccus)
# SYMBOLS section
nrSymTab = p.getint("SYMBOLS", "nr_sym_tab_files")
if nrSymTab < 0 or nrSymTab > 0xFFFF:
raise AwlSimError("Project file: Invalid number of "
......@@ -102,7 +115,8 @@ class Project(object):
return cls(projectFile = projectFile,
awlFiles = awlFiles,
symTabFiles = symTabFiles)
symTabFiles = symTabFiles,
cpuSpecs = cpuSpecs)
@classmethod
def fromFile(cls, filename):
......@@ -145,6 +159,8 @@ class Project(object):
for i, awlFile in enumerate(self.awlFiles):
path = self.__path2generic(awlFile, projectDir)
lines.append("awl_file_%d=%s" % (i, path))
lines.append("mnemonics=%d" % self.cpuSpecs.getConfiguredMnemonics())
lines.append("nr_accus=%d" % self.cpuSpecs.nrAccus)
lines.append("")
lines.append("[SYMBOLS]")
lines.append("nr_sym_tab_files=%d" % len(self.symTabFiles))
......
......@@ -129,9 +129,12 @@ def cpuDumpCallback(cpu):
def makeLoglevel():
return Logging.LOG_ERROR if opt_quiet else Logging.LOG_INFO
def assignCpuSpecs(specs):
specs.setConfiguredMnemonics(opt_mnemonics)
specs.setNrAccus(4 if opt_fouraccu else 2)
def assignCpuSpecs(cpuSpecs, projectCpuSpecs):
cpuSpecs.assignFrom(projectCpuSpecs)
if opt_mnemonics is not None:
cpuSpecs.setConfiguredMnemonics(opt_mnemonics)
if opt_nrAccus is not None:
cpuSpecs.setNrAccus(opt_nrAccus)
def readInputFile(inputFile):
if Project.fileIsProject(inputFile):
......@@ -160,9 +163,12 @@ def run(inputFile):
parseTrees.append(p.getParseTree())
symTables = []
for symTabFile in project.symTabFiles:
mnemonics = project.cpuSpecs.getConfiguredMnemonics()
if opt_mnemonics is not None:
mnemonics = opt_mnemonics
tab = SymTabParser.parseFile(symTabFile,
autodetectFormat = True,
mnemonics = opt_mnemonics)
mnemonics = mnemonics)
symTables.append(tab)
writeStdout("Initializing simulator...\n")
......@@ -177,7 +183,7 @@ def run(inputFile):
parameters = parameters)
cpu = s.getCPU()
assignCpuSpecs(cpu.getSpecs())
assignCpuSpecs(cpu.getSpecs(), project.cpuSpecs)
cpu.enableObTempPresets(opt_obtemp)
cpu.enableExtendedInsns(opt_extInsns)
if not opt_noCpuDump and not opt_quiet:
......@@ -268,7 +274,7 @@ def runWithServerBackend(inputFile):
client.enableExtendedInsns(opt_extInsns)
client.setCycleTimeLimit(opt_cycletime)
specs = client.getCpuSpecs()
assignCpuSpecs(specs)
assignCpuSpecs(specs, project.cpuSpecs)
client.setCpuSpecs(specs)
# Fire up the core
......@@ -316,7 +322,7 @@ def main():
global opt_cycletime
global opt_quiet
global opt_noCpuDump
global opt_fouraccu
global opt_nrAccus
global opt_extInsns
global opt_obtemp
global opt_mnemonics
......@@ -331,10 +337,10 @@ def main():
opt_cycletime = 5.0
opt_quiet = False
opt_noCpuDump = False
opt_fouraccu = False
opt_nrAccus = None
opt_extInsns = False
opt_obtemp = False
opt_mnemonics = "auto"
opt_mnemonics = None
opt_hwmods = []
opt_hwinfos = []
opt_profile = 0
......@@ -369,7 +375,7 @@ def main():
printError("-C|--cycle-time: Invalid time format")
sys.exit(1)
if o in ("-4", "--fouraccu"):
opt_fouraccu = True
opt_nrAccus = 4
if o in ("-q", "--quiet"):
opt_quiet = True
if o in ("-D", "--no-cpu-dump"):
......@@ -444,6 +450,7 @@ def main():
Logging.setLoglevel(makeLoglevel())
opt_mnemonics = {
None : None,
"en" : S7CPUSpecs.MNEMONICS_EN,
"de" : S7CPUSpecs.MNEMONICS_DE,
"auto" : S7CPUSpecs.MNEMONICS_AUTO,
......
......@@ -10,6 +10,11 @@ END_ORGANIZATION_BLOCK
ORGANIZATION_BLOCK OB 1
BEGIN
// assert 4-accus
__FEATURE 0
__ASSERT== __ACCU 1, 4
// check that OB 100 was executed
L MD 0
__ASSERT== __ACCU 1, 100
END_ORGANIZATION_BLOCK
[AWLSIM_PROJECT]
file_version=0
date=1990-01-01 00:00:00.000000
[CPU]
nr_awl_files=1
awl_file_0=startup_OB100.awl
mnemonics=0
nr_accus=4
[SYMBOLS]
nr_sym_tab_files=0
ORGANIZATION_BLOCK OB 101
BEGIN
L MD 0
__ASSERT== __ACCU 1, 0
L 101
T MD 0
END_ORGANIZATION_BLOCK
ORGANIZATION_BLOCK OB 1
BEGIN
L MD 0
__ASSERT== __ACCU 1, 101
END_ORGANIZATION_BLOCK
......@@ -10,6 +10,12 @@ END_ORGANIZATION_BLOCK
ORGANIZATION_BLOCK OB 1
BEGIN
// assert 4-accus
__FEATURE 0
__ASSERT== __ACCU 1, 4
// check that OB 102 was executed
L MD 0
__ASSERT== __ACCU 1, 102
END_ORGANIZATION_BLOCK
[AWLSIM_PROJECT]
file_version=0
date=1990-01-01 00:00:00.000000
[CPU]
nr_awl_files=1
awl_file_0=startup_OB102.awl
mnemonics=0
nr_accus=4
[SYMBOLS]
nr_sym_tab_files=0
......@@ -30,6 +30,12 @@ END_ORGANIZATION_BLOCK
ORGANIZATION_BLOCK OB 1
BEGIN
// assert 2-accus
__FEATURE 0
__ASSERT== __ACCU 1, 2
// check that OB 100 was executed
L MD 0
__ASSERT== __ACCU 1, 100
END_ORGANIZATION_BLOCK
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