main.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # -*- coding: utf-8 -*-
  2. #
  3. # AWL simulator - Dummy hardware interface
  4. #
  5. # Copyright 2013-2017 Michael Buesch <m@bues.ch>
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License along
  18. # with this program; if not, write to the Free Software Foundation, Inc.,
  19. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. #
  21. from __future__ import division, absolute_import, print_function, unicode_literals
  22. from awlsim.common.compat import *
  23. from awlsim.common.util import *
  24. from awlsim.common.exceptions import *
  25. #from awlsimhw_dummy.main cimport * #@cy
  26. from awlsim.core.hardware_params import *
  27. from awlsim.core.hardware import * #+cimport
  28. from awlsim.core.operators import * #+cimport
  29. from awlsim.core.offset import * #+cimport
  30. from awlsim.core.cpu import * #+cimport
  31. class HardwareInterface_Dummy(AbstractHardwareInterface): #+cdef
  32. name = "dummy"
  33. description = "Dummy hardware module that does nothing."
  34. def __init__(self, sim, parameters={}):
  35. AbstractHardwareInterface.__init__(self,
  36. sim = sim,
  37. parameters = parameters)
  38. def doStartup(self):
  39. pass # Do nothing
  40. def doShutdown(self):
  41. pass # Do nothing
  42. def readInputs(self): #+cdef
  43. pass # Do nothing
  44. def writeOutputs(self): #+cdef
  45. pass # Do nothing
  46. def directReadInput(self, accessWidth, accessOffset): #@nocy
  47. #@cy cdef bytearray directReadInput(self, uint32_t accessWidth, uint32_t accessOffset):
  48. if accessOffset < self.inputAddressBase:
  49. return bytearray()
  50. # Just read the current value from the CPU and return it.
  51. try:
  52. return self.sim.cpu.fetchInputRange(accessOffset, accessWidth // 8)
  53. except AwlSimError as e:
  54. # We may be out of process image range. Just return 0.
  55. return bytearray( (0,) * (accessWidth // 8) )
  56. def directWriteOutput(self, accessWidth, accessOffset, data): #@nocy
  57. #@cy cdef ExBool_t directWriteOutput(self, uint32_t accessWidth, uint32_t accessOffset, bytearray data) except ExBool_val:
  58. if accessOffset < self.outputAddressBase:
  59. return False
  60. # Just pretend we wrote it somewhere.
  61. return True
  62. # Module entry point
  63. HardwareInterface = HardwareInterface_Dummy