generic_layout.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. """
  2. # TOP2049 Open Source programming suite
  3. #
  4. # Generic ZIF socket voltage layout
  5. #
  6. # Copyright (c) 2010 Michael Buesch <m@bues.ch>
  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.util import *
  23. class GenericLayout:
  24. def __init__(self, nrZifPins):
  25. self.nrZifPins = nrZifPins
  26. def getNrOfPins(self):
  27. "Returns the number of pins on the layout"
  28. return self.nrZifPins
  29. def __repr__(self):
  30. res = ""
  31. for (id, zif_mask) in self.supportedLayouts():
  32. res += "Layout %d:\n" % id
  33. res += " o---------o\n"
  34. for pin in range(1, self.nrZifPins // 2 + 1):
  35. left = " "
  36. right = ""
  37. if (1 << (pin - 1)) & zif_mask:
  38. left = "HOT >"
  39. if (1 << (self.nrZifPins - pin)) & zif_mask:
  40. right = "< HOT"
  41. res += "%s | %2d | %2d | %s\n" % \
  42. (left, pin, self.nrZifPins + 1 - pin, right)
  43. res += " o---------o\n\n"
  44. return res
  45. def supportedLayouts(self):
  46. """Returns a list of supported layouts.
  47. Each entry is a tuple of (id, bitmask), where bitmask is
  48. the ZIF layout. bit0 is ZIF-pin-1. A bit set means a hot pin."""
  49. # Reimplement me in the subclass
  50. raise Exception()
  51. def ID2mask(self, id):
  52. "Convert a layout ID to a layout mask"
  53. for (layoutId, layoutMask) in self.supportedLayouts():
  54. if id == layoutId:
  55. return layoutMask
  56. return None
  57. def ID2pinlist(self, id):
  58. "Convert a layout ID to a list of pins"
  59. pinlist = []
  60. mask = self.ID2mask(id)
  61. for i in range(0, self.nrZifPins):
  62. if mask & (1 << i):
  63. pinlist.append(i + 1)
  64. return pinlist
  65. def setLayoutPins(self, zifPinsList):
  66. """Load a layout. zifPinsList is a list of hot ZIF pins.
  67. The first ZIF pin is 1."""
  68. zifMask = 0
  69. for zifPin in zifPinsList:
  70. assert(zifPin >= 1)
  71. zifMask |= (1 << (zifPin - 1))
  72. self.setLayoutMask(zifMask)
  73. def setLayoutMask(self, zifMask):
  74. "Load a ZIF mask."
  75. for (layoutId, layoutMask) in self.supportedLayouts():
  76. if layoutMask == zifMask:
  77. self.setLayoutID(layoutId)
  78. return
  79. raise TOPException("Layout mask impossible due to hardware constraints")
  80. def setLayoutID(self, id):
  81. "Load a specific layout ID."
  82. # Reimplement me in the subclass
  83. raise Exception()