summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Buesch <mb@bu3sch.de>2010-02-23 14:58:45 +0100
committerMichael Buesch <mb@bu3sch.de>2010-02-23 14:58:45 +0100
commit743d8855f93b9840c2934a44ea41166bf1de9b01 (patch)
treeba9a5343ef325bcaf74f8230e13fb37f1722bc77
parentf231b5737919ba141770777882f745f1ec64dd5b (diff)
downloadtoprammer-743d8855f93b9840c2934a44ea41166bf1de9b01.tar.xz
toprammer-743d8855f93b9840c2934a44ea41166bf1de9b01.zip
Use the auto-layout-generator in the chip implementations
Signed-off-by: Michael Buesch <mb@bu3sch.de>
-rw-r--r--libtoprammer/chip.py54
-rw-r--r--libtoprammer/chip_atmega32dip40.py7
-rw-r--r--libtoprammer/chip_atmega88dip28.py7
-rw-r--r--libtoprammer/chip_atmega8dip28.py7
-rw-r--r--libtoprammer/chip_atmega_common.py38
-rw-r--r--libtoprammer/chip_attiny26dip20.py41
-rw-r--r--libtoprammer/chip_m2764a.py31
-rw-r--r--libtoprammer/layout_generator.py17
-rw-r--r--libtoprammer/toprammer_main.py7
-rwxr-xr-xtoprammer11
-rwxr-xr-xtoprammer-layout7
11 files changed, 176 insertions, 51 deletions
diff --git a/libtoprammer/chip.py b/libtoprammer/chip.py
index 876c948..86f2764 100644
--- a/libtoprammer/chip.py
+++ b/libtoprammer/chip.py
@@ -21,17 +21,34 @@
"""
from util import *
+from layout_generator import *
supportedChips = []
class Chip:
- def __init__(self, chipID, broken=False):
- "The chipID is the ID string from the bitfile."
+ def __init__(self, chipID,
+ chipPackage=None, chipPinVCCX=None, chipPinVPP=None, chipPinGND=None,
+ broken=False):
+ """The chipID is the ID string from the bitfile.
+ chipPackage is the ID string for the package.
+ chipPinVCCX is the required VCCX pin on the package.
+ chipPinVPP is the required VPP pin on the package.
+ chipPinGND is the required GND pin on the package."""
+
self.chipID = chipID
self.broken = broken
self.printPrefix = True
+ if chipPackage:
+ # Initialize auto-layout
+ self.generator = createLayoutGenerator(chipPackage)
+ self.generator.setProgrammerType("TOP2049")#XXX Currently the only supported programmer
+ self.generator.setPins(vccxPin=chipPinVCCX,
+ vppPin=chipPinVPP,
+ gndPin=chipPinGND)
+ self.generator.recalculate()
+
def getID(self):
return self.chipID
@@ -62,6 +79,39 @@ class Chip:
def throwError(self, message):
raise TOPException(self.chipID + ": " + message)
+ def applyVCCX(self, on=True):
+ "Turn VCCX on, using the auto-layout."
+ if on:
+ try:
+ (vccxBitmask, vppBitmask, gndBitmask) = self.generator.getBitmasks()
+ except (AttributeError), e:
+ self.throwError("BUG: Using auto-layout, but did not initialize it.")
+ else:
+ vccxBitmask = 0
+ self.top.vccx.setLayoutMask(vccxBitmask)
+
+ def applyVPP(self, on=True):
+ "Turn VPP on, using the auto-layout."
+ if on:
+ try:
+ (vccxBitmask, vppBitmask, gndBitmask) = self.generator.getBitmasks()
+ except (AttributeError), e:
+ self.throwError("BUG: Using auto-layout, but did not initialize it.")
+ else:
+ vppBitmask = 0
+ self.top.vpp.setLayoutMask(vppBitmask)
+
+ def applyGND(self, on=True):
+ "Turn GND on, using the auto-layout."
+ if on:
+ try:
+ (vccxBitmask, vppBitmask, gndBitmask) = self.generator.getBitmasks()
+ except (AttributeError), e:
+ self.throwError("BUG: Using auto-layout, but did not initialize it.")
+ else:
+ gndBitmask = 0
+ self.top.gnd.setLayoutMask(gndBitmask)
+
def progressMeterInit(self, message, nrSteps):
self.progressNrSteps = nrSteps
self.progressHave25 = False
diff --git a/libtoprammer/chip_atmega32dip40.py b/libtoprammer/chip_atmega32dip40.py
index d82591f..94d7b3a 100644
--- a/libtoprammer/chip_atmega32dip40.py
+++ b/libtoprammer/chip_atmega32dip40.py
@@ -28,11 +28,12 @@ class Chip_ATMega32DIP40(Chip_ATMega_common):
def __init__(self):
Chip_ATMega_common.__init__(self,
chipID = "atmega32dip40",
+ chipPackage = "DIP40",
+ chipPinVCCX = 10,
+ chipPinVPP = 9,
+ chipPinGND = 11,
signature = "\x1E\x95\x02",
presenceCheckLayout = 0x0043FF000000,
- GNDLayout = (35,),
- VCCXLayout = (34,),
- VPPLayout = (5, 6, 7, 9, 11, 12, 13, 14, 15, 16, 18, 19, 24, 26, 30, 31, 32, 33),
flashPageSize = 64,
flashPages = 256,
eepromPageSize = 4,
diff --git a/libtoprammer/chip_atmega88dip28.py b/libtoprammer/chip_atmega88dip28.py
index baa498a..b0286cd 100644
--- a/libtoprammer/chip_atmega88dip28.py
+++ b/libtoprammer/chip_atmega88dip28.py
@@ -27,11 +27,12 @@ class Chip_ATMega88DIP28(Chip_ATMega_common):
def __init__(self):
Chip_ATMega_common.__init__(self,
chipID = "atmega88dip28",
+ chipPackage = "DIP28",
+ chipPinVCCX = 7,
+ chipPinVPP = 1,
+ chipPinGND = 8,
signature = "\x1E\x93\x0A",
presenceCheckLayout = 0x00031F801000,
- GNDLayout = (18,),
- VCCXLayout = (17,),
- VPPLayout = (5, 6, 7, 9, 11),
flashPageSize = 32,
flashPages = 128,
eepromPageSize = 4,
diff --git a/libtoprammer/chip_atmega8dip28.py b/libtoprammer/chip_atmega8dip28.py
index d0fc660..1a23f8d 100644
--- a/libtoprammer/chip_atmega8dip28.py
+++ b/libtoprammer/chip_atmega8dip28.py
@@ -27,11 +27,12 @@ class Chip_ATMega8DIP28(Chip_ATMega_common):
def __init__(self):
Chip_ATMega_common.__init__(self,
chipID = "atmega8dip28",
+ chipPackage = "DIP28",
+ chipPinVCCX = 7,
+ chipPinVPP = 1,
+ chipPinGND = 8,
signature = "\x1E\x93\x07",
presenceCheckLayout = 0x00031F801000,
- GNDLayout = (18,),
- VCCXLayout = (17,),
- VPPLayout = (5, 6, 7, 9, 11),
flashPageSize = 32,
flashPages = 128,
eepromPageSize = 4,
diff --git a/libtoprammer/chip_atmega_common.py b/libtoprammer/chip_atmega_common.py
index ac4d673..67b5dc0 100644
--- a/libtoprammer/chip_atmega_common.py
+++ b/libtoprammer/chip_atmega_common.py
@@ -35,18 +35,20 @@ class Chip_ATMega_common(Chip):
CMD_READFLASH = 0x02 # Read Flash
CMD_READEEPROM = 0x03 # Read EEPROM
- def __init__(self, chipID, signature,
+ def __init__(self, chipID,
+ chipPackage, chipPinVCCX, chipPinVPP, chipPinGND,
+ signature,
presenceCheckLayout,
- GNDLayout, VCCXLayout, VPPLayout,
flashPageSize, flashPages,
eepromPageSize, eepromPages,
):
- Chip.__init__(self, chipID)
+ Chip.__init__(self, chipID = chipID,
+ chipPackage = chipPackage,
+ chipPinVCCX = chipPinVCCX,
+ chipPinVPP = chipPinVPP,
+ chipPinGND = chipPinGND)
self.signature = signature
self.presenceCheckLayout = presenceCheckLayout
- self.GNDLayout = GNDLayout # List of GND ZIF pins
- self.VCCXLayout = VCCXLayout # List of VCCX ZIF pins
- self.VPPLayout = VPPLayout # List of VPP ZIF pins
self.flashPageSize = flashPageSize # Flash page size, in words
self.flashPages = flashPages # Nr of flash pages
self.eepromPageSize = eepromPageSize # EEPROM page size, in bytes
@@ -55,9 +57,9 @@ class Chip_ATMega_common(Chip):
def initializeChip(self):
self.printDebug("Initializing chip")
- self.top.gnd.setLayoutPins(self.GNDLayout)
- self.top.vccx.setLayoutPins( [] )
- self.top.vpp.setLayoutPins( [] )
+ self.applyGND(True)
+ self.applyVCCX(False)
+ self.applyVPP(False)
self.top.cmdSetVCCXVoltage(5)
self.top.cmdSetVPPVoltage(0)
self.top.cmdSetVPPVoltage(12)
@@ -66,9 +68,9 @@ class Chip_ATMega_common(Chip):
self.printDebug("Shutdown chip")
self.top.cmdSetVCCXVoltage(5)
self.top.cmdSetVPPVoltage(5)
- self.top.vccx.setLayoutPins( [] )
- self.top.vpp.setLayoutPins( [] )
- self.top.gnd.setLayoutPins( [] )
+ self.applyVCCX(False)
+ self.applyVPP(False)
+ self.applyGND(False)
def readSignature(self):
self.__initPins()
@@ -250,13 +252,13 @@ class Chip_ATMega_common(Chip):
def __initPins(self):
"""Initialize the pin voltages and logic."""
- self.top.vpp.setLayoutPins( [] )
- self.top.vccx.setLayoutPins( [] )
+ self.applyVPP(False)
+ self.applyVCCX(False)
self.top.queueCommand("\x0E\x28\x01\x00")
self.top.cmdFPGAWrite(0x1B, 0x00)
self.top.cmdSetVPPVoltage(0)
self.top.cmdSetVPPVoltage(12)
- self.top.gnd.setLayoutPins(self.GNDLayout)
+ self.applyGND(True)
self.top.cmdSetVCCXVoltage(4.4)
self.__setXA0(0)
@@ -265,8 +267,8 @@ class Chip_ATMega_common(Chip):
self.__setWR(0)
self.top.flushCommands()
- self.top.gnd.setLayoutPins(self.GNDLayout)
- self.top.vccx.setLayoutPins(self.VCCXLayout)
+ self.applyGND(True)
+ self.applyVCCX(True)
self.top.cmdFPGAReadRaw(0x16)
self.top.cmdFPGAReadRaw(0x17)
@@ -299,7 +301,7 @@ class Chip_ATMega_common(Chip):
self.top.queueCommand("\x19")
self.top.flushCommands()
- self.top.vpp.setLayoutPins(self.VPPLayout)
+ self.applyVPP(True)
self.top.queueCommand("\x34")
self.top.cmdFPGAWrite(0x12, 0x88)
diff --git a/libtoprammer/chip_attiny26dip20.py b/libtoprammer/chip_attiny26dip20.py
new file mode 100644
index 0000000..19eefe7
--- /dev/null
+++ b/libtoprammer/chip_attiny26dip20.py
@@ -0,0 +1,41 @@
+"""
+# TOP2049 Open Source programming suite
+#
+# Atmel Tiny26 DIP20 support
+#
+# Copyright (c) 2009-2010 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_atmega_common import *
+
+
+class Chip_ATTiny26DIP20(Chip_ATMega_common):
+ def __init__(self):
+ Chip_ATMega_common.__init__(self,
+ chipID = "attiny26dip20",
+ chipPackage = "DIP20",
+ chipPinVCCX = 5,
+ chipPinVPP = 10,
+ chipPinGND = 6,
+ signature = "\x1E\x91\x09",
+ presenceCheckLayout = 0x00031F801000,#FIXME
+ flashPageSize = 16,
+ flashPages = 64,
+ eepromPageSize = 4,
+ eepromPages = 32)
+
+supportedChips.append(Chip_ATTiny26DIP20())
diff --git a/libtoprammer/chip_m2764a.py b/libtoprammer/chip_m2764a.py
index ca1aff9..0b85737 100644
--- a/libtoprammer/chip_m2764a.py
+++ b/libtoprammer/chip_m2764a.py
@@ -29,13 +29,18 @@ class M2764A(Chip):
STAT_BUSY = 0x01 # Programmer is running a command
def __init__(self):
- Chip.__init__(self, "m2764a", broken=True)
+ Chip.__init__(self, "m2764a",
+ chipPackage = "DIP28",
+ chipPinVCCX = 28,
+ chipPinVPP = 1,
+ chipPinGND = 14,
+ broken=True)
def initializeChip(self):
self.printDebug("Initializing chip")
- self.top.vccx.setLayoutMask(0)
- self.top.vpp.setLayoutMask(0)
- self.top.gnd.setLayoutPins( [] )
+ self.applyVCCX(False)
+ self.applyVPP(False)
+ self.applyGND(False)
self.top.queueCommand("\x0E\x28\x01\x00")
self.top.cmdSetVCCXVoltage(5)
self.top.cmdSetVPPVoltage(0)
@@ -45,16 +50,16 @@ class M2764A(Chip):
self.printDebug("Shutdown chip")
self.top.cmdSetVCCXVoltage(5)
self.top.cmdSetVPPVoltage(5)
- self.top.vccx.setLayoutMask(0)
- self.top.vpp.setLayoutMask(0)
- self.top.gnd.setLayoutPins( [] )
+ self.applyVCCX(False)
+ self.applyVPP(False)
+ self.applyGND(False)
def readEEPROM(self):
self.top.cmdSetVCCXVoltage(5)
self.top.cmdSetVPPVoltage(5)
- self.top.vccx.setLayoutPins( (38,) )
- self.top.vpp.setLayoutPins( (5, 6, 7, 9, 11) )
- self.top.gnd.setLayoutPins( (24,) )
+ self.applyVCCX(True)
+ self.applyVPP(True)
+ self.applyGND(True)
image = ""
self.progressMeterInit("Reading EPROM", 0x2000)
@@ -74,9 +79,9 @@ class M2764A(Chip):
self.top.cmdSetVCCXVoltage(5)
self.top.cmdSetVPPVoltage(12)
- self.top.vccx.setLayoutPins( (38,) )
- self.top.vpp.setLayoutPins( (5, 6, 7, 9, 11) )
- self.top.gnd.setLayoutPins( (24,) )
+ self.applyVCCX(True)
+ self.applyVPP(True)
+ self.applyGND(True)
self.progressMeterInit("Writing EPROM", 0x2000)
self.__setEG(E=1, G=1)
diff --git a/libtoprammer/layout_generator.py b/libtoprammer/layout_generator.py
index caab7ec..0ff781a 100644
--- a/libtoprammer/layout_generator.py
+++ b/libtoprammer/layout_generator.py
@@ -86,6 +86,12 @@ class LayoutGenerator:
return
raise TOPException("Did not find a possible valid layout for the setup")
+ def getBitmasks(self):
+ "Returns a tuple of (vccxBitmask, vppBitmask, gndBitmask)."
+ return (self.result_vccxBitmask,
+ self.result_vppBitmask,
+ self.result_gndBitmask)
+
class LayoutGeneratorDIP(LayoutGenerator):
"Layout generator for DIP packages."
@@ -191,3 +197,14 @@ class LayoutGeneratorDIP(LayoutGenerator):
ret += ","
ret += str(bit + 1)
return ret
+
+def createLayoutGenerator(package):
+ p = package.upper()
+ try:
+ if p.startswith("DIP"):
+ nrPins = int(p[3:])
+ return LayoutGeneratorDIP(nrPins)
+ else:
+ raise ValueError()
+ except (ValueError), e:
+ raise TOPException("Unknown package type " + package)
diff --git a/libtoprammer/toprammer_main.py b/libtoprammer/toprammer_main.py
index a34033d..3eef1da 100644
--- a/libtoprammer/toprammer_main.py
+++ b/libtoprammer/toprammer_main.py
@@ -42,8 +42,9 @@ import top2049.gnd_layouts
from chip_atmega32dip40 import *
from chip_atmega8dip28 import *
from chip_atmega88dip28 import *
-from chip_m8cissp import *
+from chip_attiny26dip20 import *
from chip_m2764a import *
+from chip_m8cissp import *
from chip_unitest import *
@@ -287,6 +288,10 @@ class TOP:
self.chip.writeLockbits(image)
self.printDebug("Done writing image.")
+ def printZIFLayout(self):
+ """Prints the required ZIF layout."""
+ print self.chip.generator.zifLayoutAsciiArt()
+
def cmdFlush(self, count=1):
"""Send 'count' flush requests."""
assert(count >= 1)
diff --git a/toprammer b/toprammer
index e13c5c9..16265df 100755
--- a/toprammer
+++ b/toprammer
@@ -51,6 +51,9 @@ def usage():
print " -l|--read-lock FILE Read the lock bits"
print " -L|--write-lock FILE Write the lock bits"
print ""
+ print " -a|--layout-ascii-art Print an ascii-art of how to insert the"
+ print " chip into the programmer."
+ print ""
print "Optional:"
print " -t|--list Print a list of supported chips and exit"
print " -d|--device BUS.DEV Use the programmer at BUS.DEV"
@@ -229,11 +232,11 @@ def main(argv):
opt_outformat = "bin"
try:
(opts, args) = getopt.getopt(sys.argv[1:],
- "hb:d:V:Qs:xp:P:e:E:f:F:o:l:L:BtI:O:",
+ "hb:d:V:Qs:xp:P:e:E:f:F:o:l:L:BtI:O:a",
[ "help", "bitfile=", "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=", "layout-ascii-art",
"force=", "broken", "list", "in-format=", "out-format=", ])
for (o, v) in opts:
if o in ("-h", "--help"):
@@ -293,6 +296,8 @@ def main(argv):
if o in ("-L", "--write-lock"):
opt_action = "write-lock"
opt_file = v
+ if o in ("-a", "--layout-ascii-art"):
+ opt_action = "print-layout"
except (getopt.GetoptError, ValueError), e:
usage()
return 1
@@ -338,6 +343,8 @@ 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 == "print-layout":
+ top.printZIFLayout()
else:
assert(0)
top.shutdown()
diff --git a/toprammer-layout b/toprammer-layout
index 43a9ecb..b276b0a 100755
--- a/toprammer-layout
+++ b/toprammer-layout
@@ -58,12 +58,7 @@ def main(argv):
if o in ("-d", "--device"):
programmer = v
if o in ("-p", "--package"):
- if v.upper().startswith("DIP"):
- nrPins = int(v[3:])
- generator = LayoutGeneratorDIP(nrPins)
- else:
- print "Unknown package type\n"
- raise ValueError()
+ generator = createLayoutGenerator(v)
if o in ("-v", "--vccx"):
vccxPin = int(v)
if o in ("-P", "--vpp"):
bues.ch cgit interface