From ad0dc1f8d28bbb4625dc9316932651a44f1a0a37 Mon Sep 17 00:00:00 2001 From: Michael Buesch Date: Fri, 26 Feb 2010 18:56:13 +0100 Subject: Add generic layout baseclass Signed-off-by: Michael Buesch --- libtoprammer/top2049/gnd_layouts.py | 45 ++------------ libtoprammer/top2049/shiftreg_layout.py | 100 -------------------------------- libtoprammer/top2049/vccx_layouts.py | 8 ++- libtoprammer/top2049/vpp_layouts.py | 8 ++- 4 files changed, 18 insertions(+), 143 deletions(-) delete mode 100644 libtoprammer/top2049/shiftreg_layout.py (limited to 'libtoprammer/top2049') diff --git a/libtoprammer/top2049/gnd_layouts.py b/libtoprammer/top2049/gnd_layouts.py index 2e72a7d..2516e20 100644 --- a/libtoprammer/top2049/gnd_layouts.py +++ b/libtoprammer/top2049/gnd_layouts.py @@ -20,15 +20,19 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. """ -from libtoprammer.util import * +import sys +if __name__ == "__main__": + sys.path.insert(0, sys.path[0] + "/../..") +from libtoprammer.generic_layout import * -class GNDLayout: +class GNDLayout(GenericLayout): # A list of valid ZIF GND pins (0=none) validPins = (0, 5, 14, 15, 16, 17, 18, 19, 20, 24, 26, 27, 28, 29, 33, 34, 35) def __init__(self, top=None): + GenericLayout.__init__(self, nrZifPins=48) self.top = top self.layouts = [] for pin in self.validPins: @@ -40,47 +44,10 @@ class GNDLayout: mask |= (1 << (pin - 1)) self.layouts.append( (id, mask) ) - def __repr__(self): - res = "" - for (id, zif_mask) in self.supportedLayouts(): - res += "Layout %d:\n" % id - res += " o---------o\n" - for pin in range(1, 25): - left = " " - right = "" - if (1 << (pin - 1)) & zif_mask: - left = "HOT >" - if (1 << (49 - pin - 1)) & zif_mask: - right = "< HOT" - res += "%s | %2d | %2d | %s\n" % (left, pin, 49 - pin, right) - res += " o---------o\n\n" - return res - def supportedLayouts(self): - """Returns a list of supported layouts. - Each entry is a tuple of (id, bitmask), where bitmask is - the ZIF layout. bit0 is ZIF-pin-1. A bit set means a hot pin.""" return self.layouts - def setLayoutPins(self, zifPinsList): - """Load a layout. zifPinsList is a list of hot ZIF pins. - The first ZIF pin is 1.""" - zifMask = 0 - for zifPin in zifPinsList: - assert(zifPin >= 1) - zifMask |= (1 << (zifPin - 1)) - self.setLayoutMask(zifMask) - - def setLayoutMask(self, zifMask): - "Load a ZIF mask." - for (layoutId, layoutMask) in self.layouts: - if layoutMask == zifMask: - self.setLayoutID(layoutId) - return - raise TOPException("GND layout mask impossible due to hardware constraints") - def setLayoutID(self, id): - "Load a specific layout ID." self.top.cmdLoadGNDLayout(id) if __name__ == "__main__": diff --git a/libtoprammer/top2049/shiftreg_layout.py b/libtoprammer/top2049/shiftreg_layout.py deleted file mode 100644 index edf839c..0000000 --- a/libtoprammer/top2049/shiftreg_layout.py +++ /dev/null @@ -1,100 +0,0 @@ -""" -# TOP2049 Open Source programming suite -# -# TOP2049 Shiftregister based layout definitions -# -# 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.util import * - - -class ShiftregLayout: - def __init__(self, nrShiftRegs): - assert(nrShiftRegs <= 4) - self.nrShiftRegs = nrShiftRegs - self.layouts = [] - for id in range(0, len(self.shiftreg_masks)): - shreg_mask = self.shiftreg_masks[id] - zif_mask = 0 - for bit in range(0, self.nrShiftRegs * 8): - if (shreg_mask & (1 << bit)) == 0: - continue - regId = self.__bitnr2shregId(bit) - zifPin = self.shreg2zif_map[regId] - zif_mask |= (1 << (zifPin - 1)) - if id == 0 or zif_mask != 0: - self.layouts.append( (id, zif_mask) ) - - def __bitnr2shregId(self, bitNr): - if bitNr >= 24: - register = 3 - pin = bitNr - 24 - elif bitNr >= 16: - register = 2 - pin = bitNr - 16 - elif bitNr >= 8: - register = 1 - pin = bitNr - 8 - else: - register = 0 - pin = bitNr - return "%d.%d" % (register, pin) - - def __repr__(self): - res = "" - for (id, zif_mask) in self.supportedLayouts(): - res += "Layout %d:\n" % id - res += " o---------o\n" - for pin in range(1, 25): - left = " " - right = "" - if (1 << (pin - 1)) & zif_mask: - left = "HOT >" - if (1 << (49 - pin - 1)) & zif_mask: - right = "< HOT" - res += "%s | %2d | %2d | %s\n" % (left, pin, 49 - pin, right) - res += " o---------o\n\n" - return res - - def supportedLayouts(self): - """Returns a list of supported layouts. - Each entry is a tuple of (id, bitmask), where bitmask is - the ZIF layout. bit0 is ZIF-pin-1. A bit set means a hot pin.""" - return self.layouts - - def setLayoutPins(self, zifPinsList): - """Load a layout. zifPinsList is a list of hot ZIF pins. - The first ZIF pin is 1.""" - zifMask = 0 - for zifPin in zifPinsList: - assert(zifPin >= 1) - zifMask |= (1 << (zifPin - 1)) - self.setLayoutMask(zifMask) - - def setLayoutMask(self, zifMask): - "Load a ZIF mask." - for (layoutId, layoutMask) in self.layouts: - if layoutMask == zifMask: - self.setLayoutID(layoutId) - return - raise TOPException("Layout mask impossible due to hardware constraints") - - def setLayoutID(self, id): - "Load a specific layout ID." - # Reimplement me in the subclass - raise Exception() diff --git a/libtoprammer/top2049/vccx_layouts.py b/libtoprammer/top2049/vccx_layouts.py index 88726b1..7560c27 100644 --- a/libtoprammer/top2049/vccx_layouts.py +++ b/libtoprammer/top2049/vccx_layouts.py @@ -20,7 +20,11 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. """ -from shiftreg_layout import * +import sys +if __name__ == "__main__": + sys.path.insert(0, sys.path[0] + "/../..") +from libtoprammer.shiftreg_layout import * + class VCCXLayout(ShiftregLayout): # "shiftreg_masks" is a dump of the VCCX shiftregister states. The array index @@ -131,7 +135,7 @@ class VCCXLayout(ShiftregLayout): } def __init__(self, top=None): - ShiftregLayout.__init__(self, 3) + ShiftregLayout.__init__(self, nrZifPins=48, nrShiftRegs=3) self.top = top def minVoltage(self): diff --git a/libtoprammer/top2049/vpp_layouts.py b/libtoprammer/top2049/vpp_layouts.py index 26c23aa..3653d79 100644 --- a/libtoprammer/top2049/vpp_layouts.py +++ b/libtoprammer/top2049/vpp_layouts.py @@ -20,7 +20,11 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. """ -from shiftreg_layout import * +import sys +if __name__ == "__main__": + sys.path.insert(0, sys.path[0] + "/../..") +from libtoprammer.shiftreg_layout import * + class VPPLayout(ShiftregLayout): # "shiftreg_masks" is a dump of the VPP shiftregister states. The array index @@ -140,7 +144,7 @@ class VPPLayout(ShiftregLayout): } def __init__(self, top=None): - ShiftregLayout.__init__(self, 4) + ShiftregLayout.__init__(self, nrZifPins=48, nrShiftRegs=4) self.top = top def minVoltage(self): -- cgit v1.2.3