main.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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.cython_support cimport * #@cy
  23. from awlsim.common.compat import *
  24. from awlsim.common.util import *
  25. from awlsim.common.exceptions import *
  26. #from awlsimhw_dummy.main cimport * #@cy
  27. from awlsim.core.hardware_params import *
  28. from awlsim.core.hardware import * #+cimport
  29. from awlsim.core.operators import * #+cimport
  30. from awlsim.core.offset import * #+cimport
  31. from awlsim.core.cpu import * #+cimport
  32. class HardwareInterface_Dummy(AbstractHardwareInterface): #+cdef
  33. name = "dummy"
  34. description = "Dummy hardware module that does nothing."
  35. def __init__(self, sim, parameters={}):
  36. AbstractHardwareInterface.__init__(self,
  37. sim = sim,
  38. parameters = parameters)
  39. def doStartup(self):
  40. pass # Do nothing
  41. def doShutdown(self):
  42. pass # Do nothing
  43. def readInputs(self): #+cdef
  44. pass # Do nothing
  45. def writeOutputs(self): #+cdef
  46. pass # Do nothing
  47. def directReadInput(self, accessWidth, accessOffset): #@nocy
  48. #@cy cdef bytearray directReadInput(self, uint32_t accessWidth, uint32_t accessOffset):
  49. if accessOffset < self.inputAddressBase:
  50. return bytearray()
  51. # Just read the current value from the CPU and return it.
  52. try:
  53. return self.sim.cpu.fetchInputRange(accessOffset, accessWidth // 8)
  54. except AwlSimError as e:
  55. # We may be out of process image range. Just return 0.
  56. return bytearray( (0,) * (accessWidth // 8) )
  57. def directWriteOutput(self, accessWidth, accessOffset, data): #@nocy
  58. #@cy cdef ExBool_t directWriteOutput(self, uint32_t accessWidth, uint32_t accessOffset, bytearray data) except ExBool_val:
  59. if accessOffset < self.outputAddressBase:
  60. return False
  61. # Just pretend we wrote it somewhere.
  62. return True
  63. # Module entry point
  64. HardwareInterface = HardwareInterface_Dummy