summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libtoprammer/chip.py17
-rw-r--r--libtoprammer/chip_generic_sram.py130
-rw-r--r--libtoprammer/chip_hm62256dip28.py44
-rw-r--r--libtoprammer/chip_xxxx.py1
-rw-r--r--libtoprammer/toprammer_main.py15
-rwxr-xr-xtoprammer17
-rwxr-xr-xtoprammer-gui8
7 files changed, 228 insertions, 4 deletions
diff --git a/libtoprammer/chip.py b/libtoprammer/chip.py
index 99a3b26..791fe1a 100644
--- a/libtoprammer/chip.py
+++ b/libtoprammer/chip.py
@@ -36,6 +36,8 @@ class Chip:
SUPPORT_FUSEWRITE = (1 << 7)
SUPPORT_LOCKREAD = (1 << 8)
SUPPORT_LOCKWRITE = (1 << 9)
+ SUPPORT_RAMREAD = (1 << 10)
+ SUPPORT_RAMWRITE = (1 << 11)
@staticmethod
def chipSupportsAttr(chipImplClass, attribute):
@@ -72,6 +74,10 @@ class Chip:
flags |= Chip.SUPPORT_LOCKREAD
if Chip.chipSupportsAttr(chip, "writeLockbits"):
flags |= Chip.SUPPORT_LOCKWRITE
+ if Chip.chipSupportsAttr(chip, "readRAM"):
+ flags |= Chip.SUPPORT_RAMREAD
+ if Chip.chipSupportsAttr(chip, "writeRAM"):
+ flags |= Chip.SUPPORT_RAMWRITE
return flags
def __init__(self, chipPackage=None, chipPinVCCX=None, chipPinsVPP=None, chipPinGND=None):
@@ -225,6 +231,14 @@ class Chip:
# Override me in the subclass, if required.
raise TOPException("Lockbit writing not supported on " + self.chipID)
+ def readRAM(self):
+ # Override me in the subclass, if required.
+ raise TOPException("RAM reading not supported on " + self.chipID)
+
+ def writeRAM(self, image):
+ # Override me in the subclass, if required.
+ raise TOPException("RAM writing not supported on " + self.chipID)
+
__registeredChips = []
def getRegisteredChips():
@@ -242,6 +256,7 @@ class ChipDescription:
TYPE_EPROM = 1 # EPROM
TYPE_EEPROM = 2 # EEPROM
TYPE_GAL = 3 # PAL/GAL
+ TYPE_SRAM = 4 # Static RAM
TYPE_INTERNAL = 999 # For internal use only
def __init__(self, chipImplClass, bitfile, chipID="",
@@ -342,6 +357,8 @@ class ChipDescription:
(Chip.SUPPORT_FUSEWRITE, "Fuse bits writing"),
(Chip.SUPPORT_LOCKREAD, "Lock bits reading"),
(Chip.SUPPORT_LOCKWRITE, "Lock bits writing"),
+ (Chip.SUPPORT_RAMREAD, "RAM reading"),
+ (Chip.SUPPORT_RAMWRITE, "RAM writing"),
)
supportFlags = Chip.getSupportFlags(self.chipImplClass)
for (flag, description) in supportedFeatures:
diff --git a/libtoprammer/chip_generic_sram.py b/libtoprammer/chip_generic_sram.py
new file mode 100644
index 0000000..8a233b2
--- /dev/null
+++ b/libtoprammer/chip_generic_sram.py
@@ -0,0 +1,130 @@
+"""
+# TOP2049 Open Source programming suite
+#
+# Generic SRAM chip
+#
+# Copyright (c) 2011 Michael Buesch <mb@bu3sch.de>
+#
+# 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 chip import *
+
+
+class Chip_genericSRAM(Chip):
+ def __init__(self, chipPackage, chipPinVCCX, chipPinGND,
+ VCCXVoltage,
+ nrAddressBits, nrDataBits):
+ Chip.__init__(self,
+ chipPackage = chipPackage,
+ chipPinVCCX = chipPinVCCX,
+ chipPinGND = chipPinGND)
+ self.VCCXVoltage = VCCXVoltage
+ self.nrAddressBits = nrAddressBits
+ self.nrAddressBytes = int(math.ceil((float(self.nrAddressBits) - 0.1) / 8))
+ self.nrDataBits = nrDataBits
+ assert(nrDataBits == 8)
+
+ def shutdownChip(self):
+ self.printDebug("Shutdown chip")
+ self.top.cmdSetVCCXVoltage(self.VCCXVoltage)
+ self.applyVCCX(False)
+ self.applyVPP(False)
+ self.applyGND(False)
+
+ def erase(self):
+ self.writeRAM(chr(0) * self.__sizeBytes())
+
+ def __readBuffer(self, size):
+ if not size:
+ return ""
+ data = self.top.cmdReadBufferReg()
+ return data[0:size]
+
+ def readRAM(self):
+ image = []
+
+ self.progressMeterInit("Reading SRAM", self.__sizeBytes())
+ self.__turnOnChip()
+ self.__setControlPins(CE=0, OE=0, WE=1)
+ nrBytes = 0
+ for addr in range(0, self.__sizeBytes()):
+ self.progressMeter(addr)
+ self.__setAddress(addr)
+ self.__readData()
+ nrBytes += 1
+ if nrBytes == 64:
+ image.append(self.__readBuffer(nrBytes))
+ nrBytes = 0
+ image.append(self.__readBuffer(nrBytes))
+ self.__setControlPins(CE=1, OE=1, WE=1)
+ self.progressMeterFinish()
+
+ return "".join(image)
+
+ def writeRAM(self, image):
+ if len(image) > self.__sizeBytes():
+ self.throwError("Invalid memory image size %d (expected max %d)" %\
+ (len(image), self.__sizeBytes()))
+
+ self.progressMeterInit("Writing SRAM", self.__sizeBytes())
+ self.__turnOnChip()
+ self.__setControlPins(CE=0, OE=1, WE=1)
+ for addr in range(0, len(image)):
+ self.progressMeter(addr)
+ self.__setAddress(addr)
+ self.__writeData(image[addr])
+ self.__setControlPins(CE=0, OE=1, WE=0)
+ self.top.cmdDelay(0.00000007) # Delay at least 70 nsec
+ self.__setControlPins(CE=0, OE=1, WE=1)
+ self.__setControlPins(CE=1, OE=1, WE=1)
+ self.progressMeterFinish()
+
+ def __sizeBytes(self):
+ return (1 << self.nrAddressBits)
+
+ def __turnOnChip(self):
+ self.__setControlPins(CE=1, OE=1, WE=1)
+ self.top.cmdSetVCCXVoltage(self.VCCXVoltage)
+ self.applyGND(True)
+ self.applyVCCX(True)
+ self.lastAddress = None
+
+ def __setControlPins(self, CE=1, OE=1, WE=1):
+ value = 0
+ if CE:
+ value |= 1
+ if OE:
+ value |= 2
+ if WE:
+ value |= 4
+ self.top.cmdFPGAWrite(0x11, value)
+
+ def __writeData(self, data):
+ data = ord(data)
+ self.top.cmdFPGAWrite(0x10, data)
+
+ def __readData(self):
+ self.top.cmdFPGARead(0x10)
+
+ def __setAddress(self, addr):
+ for i in range(0, self.nrAddressBytes):
+ shift = 8 * i
+ mask = 0xFF << shift
+ if self.lastAddress is None or\
+ (self.lastAddress & mask) != (addr & mask):
+ self.top.cmdFPGAWrite(0x12 + i,
+ (addr & mask) >> shift)
+ self.lastAddress = addr
diff --git a/libtoprammer/chip_hm62256dip28.py b/libtoprammer/chip_hm62256dip28.py
new file mode 100644
index 0000000..1952377
--- /dev/null
+++ b/libtoprammer/chip_hm62256dip28.py
@@ -0,0 +1,44 @@
+"""
+# TOP2049 Open Source programming suite
+#
+# HM62256 DIP28 SRAM support
+#
+# Copyright (c) 2011 Michael Buesch <mb@bu3sch.de>
+#
+# 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 chip_generic_sram import *
+
+
+class Chip_HM62256DIP28(Chip_genericSRAM):
+ def __init__(self):
+ Chip_genericSRAM.__init__(self,
+ chipPackage = "DIP28",
+ chipPinVCCX = 28,
+ chipPinGND = 14,
+ VCCXVoltage = 5,
+ nrAddressBits = 15,
+ nrDataBits = 8,
+ )
+
+ChipDescription(
+ Chip_HM62256DIP28,
+ bitfile = "hm62256dip28",
+ runtimeID = (0x000A, 0x01),
+ chipType = ChipDescription.TYPE_SRAM,
+ description = "S@Tech HM62256 SRAM",
+ packages = ( ("DIP28", ""), )
+)
diff --git a/libtoprammer/chip_xxxx.py b/libtoprammer/chip_xxxx.py
index 1b35a54..8423186 100644
--- a/libtoprammer/chip_xxxx.py
+++ b/libtoprammer/chip_xxxx.py
@@ -5,6 +5,7 @@ from chip_atmega8dip28 import *
from chip_atmega88dip28 import *
from chip_attiny13dip8 import *
from chip_attiny26dip20 import *
+from chip_hm62256dip28 import *
from chip_m2764a import *
from chip_m8cissp import *
from chip_unitest import *
diff --git a/libtoprammer/toprammer_main.py b/libtoprammer/toprammer_main.py
index 68b9642..68071e8 100644
--- a/libtoprammer/toprammer_main.py
+++ b/libtoprammer/toprammer_main.py
@@ -381,6 +381,21 @@ class TOP:
self.chip.writeLockbits(image)
self.printDebug("Done writing image.")
+ def readRAM(self):
+ """Reads the RAM and returns it."""
+ self.printDebug("Reading RAM from chip...")
+ self.checkChip()
+ image = self.chip.readRAM()
+ self.printDebug("Done reading %d bytes." % len(image))
+ return image
+
+ def writeRAM(self, image):
+ """Writes the RAM image to the chip."""
+ self.printDebug("Writing %d bytes of RAM to the chip..." % len(image))
+ self.checkChip()
+ self.chip.writeRAM(image)
+ self.printDebug("Done writing the image.")
+
def __cmdDelay_4usec(self):
self.queueCommand(chr(0x00))
diff --git a/toprammer b/toprammer
index be3ea5d..dd42f07 100755
--- a/toprammer
+++ b/toprammer
@@ -50,6 +50,9 @@ def usage():
print " -l|--read-lock FILE Read the lock bits"
print " -L|--write-lock FILE Write the lock bits"
print ""
+ print " -r|--read-ram FILE Read the RAM"
+ print " -R|--write-ram FILE Write the RAM"
+ print ""
print "Optional:"
print " -t|--list Print a list of supported chips and exit."
print " Use -V|--verbose to control the list verbosity (1-4)"
@@ -121,11 +124,11 @@ def main(argv):
opt_outformat = "bin"
try:
(opts, args) = getopt.getopt(sys.argv[1:],
- "hc:d:V:Qs:xp:P:e:E:f:F:o:Ul:L:BtI:O:",
+ "hc:d:V:Qs:xp:P:e:E:f:F:o:Ul:L:r:R:BtI:O:",
[ "help", "chip-id=", "device=", "verbose=", "noqueue",
"read-sig=", "erase", "read-prog=", "write-prog=",
"read-eeprom=", "write-eeprom=", "read-fuse=", "write-fuse=",
- "read-lock=", "write-lock=",
+ "read-lock=", "write-lock=", "read-ram=", "write-ram=",
"force=", "force-upload", "broken", "list",
"in-format=", "out-format=", ])
for (o, v) in opts:
@@ -186,6 +189,12 @@ def main(argv):
if o in ("-L", "--write-lock"):
opt_action = "write-lock"
opt_file = v
+ if o in ("-r", "--read-ram"):
+ opt_action = "read-ram"
+ opt_file = v
+ if o in ("-R", "--write-ram"):
+ opt_action = "write-ram"
+ opt_file = v
except (getopt.GetoptError, ValueError), e:
usage()
return 1
@@ -232,6 +241,10 @@ def main(argv):
fileOut(opt_file, opt_outformat, top.readLockbits())
elif opt_action == "write-lock":
top.writeLockbits(fileIn(opt_file, opt_informat))
+ elif opt_action == "read-ram":
+ fileOut(opt_file, opt_outformat, top.readRAM())
+ elif opt_action == "write-ram":
+ top.writeRAM(fileIn(opt_file, opt_informat))
else:
assert(0)
top.shutdownChip()
diff --git a/toprammer-gui b/toprammer-gui
index efa8d19..1f4b242 100755
--- a/toprammer-gui
+++ b/toprammer-gui
@@ -1563,8 +1563,10 @@ class ChipSelectDialog(QDialog):
groupBox.layout().addWidget(self.eepromRadio, 2, 0)
self.galRadio = QRadioButton("PALs / GALs", groupBox)
groupBox.layout().addWidget(self.galRadio, 3, 0)
+ self.sramRadio = QRadioButton("Static RAM", groupBox)
+ groupBox.layout().addWidget(self.sramRadio, 4, 0)
self.showBroken = QCheckBox("Show broken implementations", groupBox)
- groupBox.layout().addWidget(self.showBroken, 4, 0)
+ groupBox.layout().addWidget(self.showBroken, 5, 0)
self.layout().addWidget(groupBox, 0, 2)
self.okButton = QPushButton("&Ok", self)
@@ -1584,7 +1586,8 @@ class ChipSelectDialog(QDialog):
self.connect(self.showBroken, SIGNAL("stateChanged(int)"),
self.typeToggled)
for radio in (self.mcuRadio, self.epromRadio,
- self.eepromRadio, self.galRadio):
+ self.eepromRadio, self.galRadio,
+ self.sramRadio):
self.connect(radio, SIGNAL("toggled(bool)"), self.typeToggled)
self.__updateList()
@@ -1595,6 +1598,7 @@ class ChipSelectDialog(QDialog):
ChipDescription.TYPE_EPROM : self.epromRadio,
ChipDescription.TYPE_EEPROM : self.eepromRadio,
ChipDescription.TYPE_GAL : self.galRadio,
+ ChipDescription.TYPE_SRAM : self.sramRadio,
}
self.chipList.clear()
chipsList = getRegisteredChips()[:]
bues.ch cgit interface