microchip8_splittedPMarea_hasResetPC.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. """
  2. # TOP2049 Open Source programming suite
  3. #
  4. # pic8_splittedPMarea - file for newer 8bit PIC MCUs
  5. #
  6. # Copyright (c) 2013 Pavel Stemberk <stemberk@gmail.com>
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License along
  19. # with this program; if not, write to the Free Software Foundation, Inc.,
  20. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. """
  22. from libtoprammer.chips.microchip8.microchip8_splittedPMarea import *
  23. class microchip8_splittedPMarea_hasResetPC(microchip8_splittedPMarea):
  24. CMD_RESET_ADDRESS = 0x16
  25. userIDLocationSize = 4
  26. voltageVDD = 3
  27. voltageVPP = 8.5
  28. logicalFlashProgramMemorySize = 0x8000
  29. logicalFlashConfigurationMemorySize = 0x8000
  30. def __init__(self,
  31. chipPackage, chipPinVCC, chipPinsVPP, chipPinGND,
  32. signature,
  33. flashPageSize, flashPages,
  34. eepromPageSize, eepromPages,
  35. fuseBytes):
  36. microchip8_splittedPMarea.__init__(self, chipPackage, chipPinVCC,
  37. chipPinsVPP, chipPinGND, signature,
  38. flashPageSize, flashPages,
  39. eepromPageSize, eepromPages, fuseBytes)
  40. def setPC(self, address):
  41. if(self.isInsideProgramMemoryArea):
  42. if(address >= self.logicalFlashProgramMemorySize):
  43. raise TOPException('Cannot set PC to address inside PM {:x}'.format(address))
  44. if(address < self.PC):
  45. self.resetPC()
  46. self.setPC(address)
  47. else:
  48. if(address < self.logicalFlashProgramMemorySize):
  49. raise TOPException('Cannot set PC to address outside PM {:x}'.format(address))
  50. if(address < self.PC):
  51. self.resetPC()
  52. self.enterConfigArea()
  53. self.setPC(address)
  54. while(self.PC != address):
  55. self.incrementPC(1)
  56. def resetPC(self):
  57. if hasattr(self, 'osccalAddr'):
  58. if not hasattr(self, 'CMD_RESET_ADDRESS'):
  59. print("reset instruction is not supported")
  60. self.exitPM()
  61. self.enterPM()
  62. else:
  63. self.sendCommand(0, 0, 0, self.CMD_RESET_ADDRESS)
  64. self.PC = 0
  65. self.isInsideProgramMemoryArea = True