microchip8_singlePMarea.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. """
  2. # TOP2049 Open Source programming suite
  3. #
  4. # pic8_singlePMarea - file for older 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_common import *
  23. class microchip8_singlePMarea(Chip_Microchip8_common):
  24. CMD_BEGIN_PROGRAMMING = 0x08
  25. CMD_END_PROGRAMMING = 0x0E
  26. userIDLocationSize = 4
  27. hasSigBytes = False
  28. voltageVDD = 5
  29. voltageVPP = 13
  30. defaultWord = [b'\xFF', b'\x0F']
  31. def __init__(self,
  32. chipPackage, chipPinVCC, chipPinsVPP, chipPinGND,
  33. signature,
  34. flashPageSize, flashPages,
  35. eepromPageSize, eepromPages,
  36. fuseBytes
  37. ):
  38. Chip_Microchip8_common.__init__(self, chipPackage, chipPinVCC, chipPinsVPP, chipPinGND, signature, flashPageSize, flashPages, eepromPageSize, eepromPages, fuseBytes)
  39. self.initPcValue = self.logicalFlashSize - 1
  40. self.configWordAddr = self.logicalFlashSize - 1
  41. self.osccalAddr = self.flashPageSize - 1
  42. self.userIDLocationAddr = self.flashPageSize
  43. self.osccalBackupAddr = self.userIDLocationAddr + self.userIDLocationSize
  44. def getIHexInterpreter(self):
  45. inter = IHexInterpreter()
  46. inter.progmemRanges = [ AddressRange(0, 2 * self.flashPageSize) ]
  47. inter.fuseRanges = [ AddressRange(2 * self.configWordAddr,
  48. 2 * self.configWordAddr + 1),
  49. AddressRange(2 * 0xFFF,
  50. 2 * 0xFFF + 1) ]
  51. inter.uilRanges = [ AddressRange(2 * self.userIDLocationAddr,
  52. 2 * (self.userIDLocationAddr + self.userIDLocationSize) - 1) ]
  53. inter.progmemDefaultBytes = self.defaultWord[0] + self.defaultWord[1]
  54. inter.fuseDefaultBytes = self.defaultWord[0] + self.defaultWord[1]
  55. return inter
  56. def setPC(self, address):
  57. while(self.PC != address):
  58. self.incrementPC(1)
  59. def incrementPC(self, count):
  60. for address in range(0, count):
  61. self.sendCommand(0, 0, 0, self.CMD_INCREMENT_ADDRESS)
  62. self.PC += 1
  63. if (self.PC == self.logicalFlashSize):
  64. self.PC = 0
  65. def sendWriteFlashInstr(self):
  66. '''
  67. '''
  68. # self.loadCommand(self.PROGCMD_SENDDATA)
  69. # self.top.hostDelay(0.000005)
  70. self.sendCommand(0, 0, 0, self.CMD_BEGIN_PROGRAMMING)
  71. self.top.cmdDelay(self.delayTprog) # 025) #Tprog
  72. self.sendCommand(0, 0, 0, self.CMD_END_PROGRAMMING)
  73. self.top.cmdDelay(self.delayTdis) # Tdis
  74. def sendWriteFlashInstrDM(self):
  75. self.sendWriteFlashInstr()
  76. def sendWriteFlashInstrCW(self):
  77. self.sendWriteFlashInstr()
  78. def readProgmem(self):
  79. self.exitPM()
  80. return Chip_Microchip8_common.readProgmem(self)
  81. def readFuse(self):
  82. self.exitPM()
  83. return Chip_Microchip8_common.readFuse(self)
  84. def writeFuse(self, image):
  85. self.exitPM()
  86. Chip_Microchip8_common.writeFuse(self,image)