From 02395727ddc20346290b6b5dd2574537af5f3075 Mon Sep 17 00:00:00 2001 From: Michael Buesch Date: Fri, 13 Apr 2012 16:51:20 +0200 Subject: Add generic 27cXXX EPROM support Signed-off-by: Michael Buesch --- libtoprammer/chips/_27cxxx.py | 217 ++++++++++++++++++++++++++++++++++++++++ libtoprammer/chips/__init__.py | 3 +- libtoprammer/chips/at27c256r.py | 82 --------------- libtoprammer/chips/m2764a.py | 173 -------------------------------- 4 files changed, 218 insertions(+), 257 deletions(-) create mode 100644 libtoprammer/chips/_27cxxx.py delete mode 100644 libtoprammer/chips/at27c256r.py delete mode 100644 libtoprammer/chips/m2764a.py (limited to 'libtoprammer/chips') diff --git a/libtoprammer/chips/_27cxxx.py b/libtoprammer/chips/_27cxxx.py new file mode 100644 index 0000000..cdd2e37 --- /dev/null +++ b/libtoprammer/chips/_27cxxx.py @@ -0,0 +1,217 @@ +""" +# TOP2049 Open Source programming suite +# +# 27c16dip28 UV/OTP EPROM +# 27c32dip28 UV/OTP EPROM +# 27c64dip28 UV/OTP EPROM +# 27c128dip28 UV/OTP EPROM +# 27c256dip28 UV/OTP EPROM +# 27c512dip28 UV/OTP EPROM +# Various manufacturers +# +# Copyright (c) 2012 Michael Buesch +# +# 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 libtoprammer.chip import * +from libtoprammer.util import * + + +class Chip_27cXXX(Chip): + "Generic 27cXXX EPROM" + + CTYPE_16 = 0 + CTYPE_32 = 1 + CTYPE_64 = 2 + CTYPE_128 = 3 + CTYPE_256 = 4 + CTYPE_512 = 5 + + # Type to size (in bytes) + ctype2size = { + CTYPE_16 : 16 * 1024 // 8, + CTYPE_32 : 32 * 1024 // 8, + CTYPE_64 : 64 * 1024 // 8, + CTYPE_128 : 128 * 1024 // 8, + CTYPE_256 : 256 * 1024 // 8, + CTYPE_512 : 512 * 1024 // 8, + } + + def __init__(self, chipType, + chipPinVCC, chipPinVPP, chipPinGND): + Chip.__init__(self, chipPackage = "DIP28", + chipPinVCC = chipPinVCC, + chipPinsVPP = chipPinVPP, + chipPinGND = chipPinGND) + self.chipType = chipType + self.generic = GenericAlgorithms(self) + self.addrSetter = AddrSetter(self, 0, 1) + + def readEEPROM(self): + self.__turnOn() + return self.generic.simpleReadEPROM( + sizeBytes = self.ctype2size[self.chipType], + readData8Func = self.__dataRead, + addrSetter = self.addrSetter, + initFunc = lambda: self.__setFlags(oe=0, ce=0), + exitFunc = lambda: self.__setFlags(oe=1, ce=1) + ) + +# def writeEEPROM(self): +# pass#TODO + + def __turnOn(self): + self.__setType(self.chipType) + self.__setFlags() + self.generic.simpleVoltageSetup() + + def __setDataPins(self, value): + self.top.cmdFPGAWrite(2, value) + + def __setFlags(self, data_en=0, prog_en=0, ce=1, oe=1): + value = 0 + if data_en: + value |= (1 << 0) + if prog_en: + value |= (1 << 1) + if ce: + value |= (1 << 2) + if oe: + value |= (1 << 3) + self.top.cmdFPGAWrite(3, value) + + def __progPulse(self, usec): + value = roundup(usec, 100) // 100 + if value > 0x7F: + value = roundup(value, 8) // 8 + if value > 0x7F: + self.throwError("__progPulse time too big") + value |= 0x80 # Set "times 8" multiplier + self.top.cmdFPGAWrite(4, value) + + def __setType(self, typeNumber): + self.top.cmdFPGAWrite(5, typeNumber) + + def __dataRead(self): + self.top.cmdFPGARead(0) + +class Chip_27c16(Chip_27cXXX): + def __init__(self): + Chip_27cXXX.__init__(self, + chipType = Chip_27cXXX.CTYPE_16, + chipPinVCC = 26, + chipPinVPP = 23, + chipPinGND = 14) + +ChipDescription(Chip_27c16, + bitfile = "_27cxxxdip28", + chipID = "27c16", + runtimeID = (12, 1), + chipType = ChipDescription.TYPE_EPROM, + chipVendors = "Various", + description = "27c16 EPROM", + packages = ( ("DIP28", ""), ) +) + +class Chip_27c32(Chip_27cXXX): + def __init__(self): + Chip_27cXXX.__init__(self, + chipType = Chip_27cXXX.CTYPE_32, + chipPinVCC = 26, + chipPinVPP = 22, + chipPinGND = 14) + +ChipDescription(Chip_27c32, + bitfile = "_27cxxxdip28", + chipID = "27c32", + runtimeID = (12, 1), + chipType = ChipDescription.TYPE_EPROM, + chipVendors = "Various", + description = "27c32 EPROM", + packages = ( ("DIP28", ""), ) +) + +class Chip_27c64(Chip_27cXXX): + def __init__(self): + Chip_27cXXX.__init__(self, + chipType = Chip_27cXXX.CTYPE_64, + chipPinVCC = 28, + chipPinVPP = 1, + chipPinGND = 14) + +ChipDescription(Chip_27c64, + bitfile = "_27cxxxdip28", + chipID = "27c64", + runtimeID = (12, 1), + chipType = ChipDescription.TYPE_EPROM, + chipVendors = "Various", + description = "27c64 EPROM", + packages = ( ("DIP28", ""), ) +) + +class Chip_27c128(Chip_27cXXX): + def __init__(self): + Chip_27cXXX.__init__(self, + chipType = Chip_27cXXX.CTYPE_128, + chipPinVCC = 28, + chipPinVPP = 1, + chipPinGND = 14) + +ChipDescription(Chip_27c128, + bitfile = "_27cxxxdip28", + chipID = "27c128", + runtimeID = (12, 1), + chipType = ChipDescription.TYPE_EPROM, + chipVendors = "Various", + description = "27c128 EPROM", + packages = ( ("DIP28", ""), ) +) + +class Chip_27c256(Chip_27cXXX): + def __init__(self): + Chip_27cXXX.__init__(self, + chipType = Chip_27cXXX.CTYPE_256, + chipPinVCC = 28, + chipPinVPP = 1, + chipPinGND = 14) + +ChipDescription(Chip_27c256, + bitfile = "_27cxxxdip28", + chipID = "27c256", + runtimeID = (12, 1), + chipType = ChipDescription.TYPE_EPROM, + chipVendors = "Various", + description = "27c256 EPROM", + packages = ( ("DIP28", ""), ) +) + +class Chip_27c512(Chip_27cXXX): + def __init__(self): + Chip_27cXXX.__init__(self, + chipType = Chip_27cXXX.CTYPE_512, + chipPinVCC = 28, + chipPinVPP = 22, + chipPinGND = 14) + +ChipDescription(Chip_27c512, + bitfile = "_27cxxxdip28", + chipID = "27c512", + runtimeID = (12, 1), + chipType = ChipDescription.TYPE_EPROM, + chipVendors = "Various", + description = "27c512 EPROM", + packages = ( ("DIP28", ""), ) +) diff --git a/libtoprammer/chips/__init__.py b/libtoprammer/chips/__init__.py index 32ee95d..e43bd7c 100644 --- a/libtoprammer/chips/__init__.py +++ b/libtoprammer/chips/__init__.py @@ -1,6 +1,6 @@ # Import all chip modules in alphabetical order +from _27cxxx import * from _74hc4094 import * -from at27c256r import * from at89c2051dip20 import * from atmega32dip40 import * from atmega8dip28 import * @@ -9,7 +9,6 @@ from attiny13dip8 import * from attiny26dip20 import * from hm62256dip28 import * from m24cxxdip8 import * -from m2764a import * from m8cissp import * from unitest import * from w29ee011dip32 import * diff --git a/libtoprammer/chips/at27c256r.py b/libtoprammer/chips/at27c256r.py deleted file mode 100644 index 9dff427..0000000 --- a/libtoprammer/chips/at27c256r.py +++ /dev/null @@ -1,82 +0,0 @@ -""" -# TOP2049 Open Source programming suite -# -# Atmel AT27C256R EPROM -# -# Copyright (c) 2012 Michael Buesch -# -# 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 libtoprammer.chip import * - - -class Chip_at27c256r(Chip): - def __init__(self): - Chip.__init__(self, - chipPackage = "DIP28", - chipPinVCC = 28, - chipPinsVPP = 1, - chipPinGND = 14) - self.sizeBytes = 32 * 1024 - self.generic = GenericAlgorithms(self) - self.addrSetter = AddrSetter(self, 0x10, 0x11) - - def readEEPROM(self): - self.__turnOn() - return self.generic.simpleReadEPROM( - sizeBytes = self.sizeBytes, - readData8Func = self.__dataRead, - addrSetter = self.addrSetter, - initFunc = lambda: self.__setFlags(oe=0, ce=0), - exitFunc = lambda: self.__setFlags(oe=1, ce=1) - ) - -# def writeEEPROM(self): -# pass#TODO - - def __turnOn(self): - self.__setFlags() - self.generic.simpleVoltageSetup() - - def __setDataPins(self, value): - self.top.cmdFPGAWrite(0x12, value) - - def __setFlags(self, data_en=0, prog_en=0, ce=1, oe=1): - value = 0 - if data_en: - value |= (1 << 0) - if prog_en: - value |= (1 << 1) - if ce: - value |= (1 << 2) - if oe: - value |= (1 << 3) - self.top.cmdFPGAWrite(0x13, value) - - def __progPulse(self): - self.top.cmdFPGAWrite(0x14, 0) - - def __dataRead(self): - self.top.cmdFPGARead(0x10) - -ChipDescription(Chip_at27c256r, - bitfile = "at27c256r", - runtimeID = (0x000C, 0x01), - chipType = ChipDescription.TYPE_EPROM, - chipVendors = "Atmel", - description = "AT27C256R", - packages = ( ("DIP28", ""), ) -) diff --git a/libtoprammer/chips/m2764a.py b/libtoprammer/chips/m2764a.py deleted file mode 100644 index 7eecbb9..0000000 --- a/libtoprammer/chips/m2764a.py +++ /dev/null @@ -1,173 +0,0 @@ -""" -# TOP2049 Open Source programming suite -# -# M2764A EPROM programmer -# -# Copyright (c) 2010 Michael Buesch -# -# 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 libtoprammer.chip import * - - -class Chip_M2764A(Chip): - PROGCMD_PPULSE = 1 # Perform a P-pulse - - STAT_BUSY = 0x01 # Programmer is running a command - - def __init__(self): - Chip.__init__(self, - chipPackage = "DIP28", - chipPinVCC = 28, - chipPinsVPP = 1, - chipPinGND = 14) - - def __initChip(self): - self.applyVCC(False) - self.applyVPP(False) - self.applyGND(False) - self.top.cmdSetVCCVoltage(5) - self.top.cmdSetVPPVoltage(0) - self.top.cmdSetVPPVoltage(5) - - def readEEPROM(self): - self.__initChip() - self.top.cmdSetVCCVoltage(5) - self.top.cmdSetVPPVoltage(5) - self.applyVCC(True) - self.applyVPP(True) - self.applyGND(True) - - image = "" - self.progressMeterInit("Reading EPROM", 0x2000) - self.__setEG(E=1, G=1) - byteCount = 0 - for addr in range(0, 0x2000): - self.progressMeter(addr) - self.__readDataToStatusReg(addr) - byteCount += 1 - if byteCount == self.top.getBufferRegSize(): - image += self.top.cmdReadBufferReg(byteCount) - byteCount = 0 - image += self.top.cmdReadBufferReg(byteCount) - self.__setEG(E=1, G=1) - self.progressMeterFinish() - - return image - - def writeEEPROM(self, image): - if len(image) > 0x2000: - self.throwError("Invalid EPROM image size %d (expected <=%d)" %\ - (len(image), 0x2000)) - - self.__initChip() - self.top.cmdSetVCCVoltage(5) - self.top.cmdSetVPPVoltage(12) - self.applyVCC(True) - self.applyVPP(True) - self.applyGND(True) - - self.progressMeterInit("Writing EPROM", len(image)) - self.__setEG(E=1, G=1) - for addr in range(0, len(image)): - self.progressMeter(addr) - data = byte2int(image[addr]) - if data != 0xFF: - self.__writeData(addr, data) - self.__setEG(E=1, G=1) - self.progressMeterFinish() - - def __readDataToStatusReg(self, addr): - self.__loadAddr(addr) - self.__setEG(E=0, G=0) - self.top.cmdFPGARead(0x10) - - def __writeData(self, addr, data): - self.__setEG(E=0, G=1) - self.__loadAddr(addr) - self.__loadData(data) - self.__loadPPulseLen(1) - self.__runCommandSync(self.PROGCMD_PPULSE) - for i in range(0, 25): - self.__readDataToStatusReg(addr) - stat = self.top.cmdReadBufferReg() - r = byte2int(stat[0]) - if r == data: - break - self.__setEG(E=0, G=1) - self.__runCommandSync(self.PROGCMD_PPULSE) - else: - self.throwError("Failed to program 0x%04X (got 0x%02X, expected 0x%02X)" %\ - (addr, r, data)) - self.__setEG(E=0, G=1) - self.__loadPPulseLen(3 * (i + 1)) - self.__runCommandSync(self.PROGCMD_PPULSE) - - def __loadData(self, data): - self.top.cmdFPGAWrite(0x10, data) - - def __loadCommand(self, command): - self.top.cmdFPGAWrite(0x12, command & 0xFF) - - def __runCommandSync(self, command): - self.__loadCommand(command) - self.__busyWait() - - def __loadAddrLow(self, addrLow): - self.top.cmdFPGAWrite(0x13, addrLow & 0xFF) - - def __loadAddrHigh(self, addrHigh): - self.top.cmdFPGAWrite(0x14, addrHigh & 0xFF) - - def __loadAddr(self, addr): - self.__loadAddrLow(addr) - self.__loadAddrHigh(addr >> 8) - - def __loadPPulseLen(self, msec): - self.top.cmdFPGAWrite(0x15, msec) - - def __setEG(self, E, G): - data = 0 - if E: - data |= 1 - if G: - data |= 2 - self.top.cmdFPGAWrite(0x16, data) - - def __getStatusFlags(self): - self.top.cmdFPGARead(0x12) - stat = self.top.cmdReadBufferReg() - return byte2int(stat[0]) - - def __busy(self): - return bool(self.__getStatusFlags() & self.STAT_BUSY) - - def __busyWait(self): - for i in range(0, 100): - if not self.__busy(): - return - self.top.hostDelay(0.01) - self.throwError("Timeout in busywait.") - -ChipDescription( - Chip_M2764A, - bitfile = "m2764a", - runtimeID = (0x0006, 0x01), - chipType = ChipDescription.TYPE_EPROM, - description = "M2764A EPROM", - maintainer = None, - packages = ( ("DIP28", ""), ), -) -- cgit v1.2.3