aboutsummaryrefslogtreecommitdiffstats
path: root/awlsim/common/cpuconfig.py
blob: de378499f19504f2baf99f64c30e7877d5a0efc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# -*- coding: utf-8 -*-
#
# AWL simulator - CPU core configuration
#
# Copyright 2012-2017 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.enumeration import *
from awlsim.common.exceptions import *


__all__ = [ "S7CPUConfig", ]


class S7CPUConfig(object):
	"""STEP 7 CPU core configuration"""

	# Mnemonic identifiers
	# Note: These numbers are .awlpro file ABI.
	EnumGen.start
	MNEMONICS_AUTO		= EnumGen.item
	MNEMONICS_EN		= EnumGen.item
	MNEMONICS_DE		= EnumGen.item
	EnumGen.end

	DEFAULT_MNEMONICS	= MNEMONICS_AUTO
	DEFAULT_CLOCKMEM	= -1

	def __init__(self, cpu=None):
		self.cpu = None
		self.setConfiguredMnemonics(self.DEFAULT_MNEMONICS)
		self.setClockMemByte(self.DEFAULT_CLOCKMEM)
		self.cpu = cpu

	def assignFrom(self, otherCpuConfig):
		self.setConfiguredMnemonics(otherCpuConfig.getConfiguredMnemonics())
		self.setClockMemByte(otherCpuConfig.clockMemByte)

	def setConfiguredMnemonics(self, mnemonics):
		if mnemonics not in (self.MNEMONICS_AUTO,
				     self.MNEMONICS_EN,
				     self.MNEMONICS_DE):
			raise AwlSimError("Invalid mnemonics configuration: %d" % mnemonics)
		self.__configuredMnemonics = mnemonics
		self.setDetectedMnemonics(self.MNEMONICS_AUTO)

	def setDetectedMnemonics(self, mnemonics):
		self.__detectedMnemonics = mnemonics

	def getConfiguredMnemonics(self):
		return self.__configuredMnemonics

	def getMnemonics(self):
		if self.__configuredMnemonics == self.MNEMONICS_AUTO:
			return self.__detectedMnemonics
		return self.__configuredMnemonics

	def setClockMemByte(self, byteAddress):
		self.clockMemByte = byteAddress
		if self.cpu:
			self.cpu.initClockMemState()
bues.ch cgit interface