toprammer-layout 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #!/usr/bin/env python3
  2. """
  3. # TOP2049 Open Source programming suite
  4. #
  5. # ZIF socket layout generator
  6. #
  7. # Copyright (c) 2010 Michael Buesch <m@bues.ch>
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License along
  20. # with this program; if not, write to the Free Software Foundation, Inc.,
  21. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  22. """
  23. from libtoprammer.layout_generator import *
  24. from libtoprammer.main import *
  25. from libtoprammer.chip import *
  26. import getopt
  27. import sys
  28. class FakeTOP(object):
  29. def __init__(self, topType):
  30. self.topType = topType
  31. def getProgrammerType(self):
  32. return self.topType
  33. def usage():
  34. print("Toprammer ZIF socket layout generator v%s" % VERSION)
  35. print("")
  36. print("Usage: %s [OPTIONS]" % sys.argv[0])
  37. print("")
  38. print("Mandatory options:")
  39. print(" -d|--device TOPxxxx The TOPxxxx device that is used.")
  40. print(" Possible choices are: TOP2049")
  41. print(" -p|--package DIPxx The package type of the DUT.")
  42. print(" Package may also be the name of a supported chip.")
  43. print(" In this case, --vcc, --vpp and --gnd are ignored.")
  44. print(" -v|--vcc PIN Set VCC pin number, relative to the package.")
  45. print(" -P|--vpp PIN(s) Set VPP pin number(s), relative to the package.")
  46. print(" May be one pin number or a comma separated list of pin numbers.")
  47. print(" May be omitted or NONE, if no VPP pin is required.")
  48. print(" -g|--gnd PIN Set GND pin number, relative to the package.")
  49. print("")
  50. print("Optional:")
  51. print(" -h|--help Print this help text")
  52. print(" -I|--only-insert Only show insert-layout")
  53. print(" -S|--only-supply Only show supply-layout")
  54. def main(argv):
  55. package = None
  56. programmer = None
  57. vccPin = None
  58. vppPins = None
  59. gndPin = None
  60. showInsert = True
  61. showSupply = True
  62. try:
  63. (opts, args) = getopt.getopt(argv[1:],
  64. "d:p:hv:P:g:IS",
  65. [ "help", "device=", "package=", "vcc=", "vcc=", "vpp=", "gnd=",
  66. "only-insert", "only-supply", ])
  67. for (o, v) in opts:
  68. if o in ("-h", "--help"):
  69. usage()
  70. return 0
  71. if o in ("-d", "--device"):
  72. programmer = v
  73. if o in ("-p", "--package"):
  74. package = v
  75. if o in ("-v", "--vcc", "--vcc"):
  76. vccPin = int(v)
  77. if o in ("-P", "--vpp"):
  78. if v.upper() == "NONE":
  79. vppPins = None
  80. else:
  81. vppPins = []
  82. for v in v.split(","):
  83. vppPins.append(int(v))
  84. if o in ("-g", "--gnd"):
  85. gndPin = int(v)
  86. if o in ("-I", "--only-insert"):
  87. showInsert = True
  88. showSupply = False
  89. if o in ("-S", "--only-supply"):
  90. showInsert = False
  91. showSupply = True
  92. if not programmer:
  93. print("-d|--device is mandatory!\n")
  94. raise ValueError()
  95. if not package:
  96. print("-p|--package is mandatory!\n")
  97. raise ValueError()
  98. generator = None
  99. try:
  100. chipDesc = ChipDescription.findOne(
  101. package, allowBroken=True)
  102. chip = chipDesc.chipImplClass.createInstance(
  103. FakeTOP(programmer), chipDesc)
  104. except (TOPException) as e:
  105. chip = None
  106. if vccPin is None or gndPin is None:
  107. print("-v|--vcc and -g|--gnd " +\
  108. "are mandatory, if a package type is specified.\n")
  109. raise ValueError()
  110. except (getopt.GetoptError, ValueError, KeyError) as e:
  111. usage()
  112. return 1
  113. except (TOPException) as e:
  114. print(e)
  115. return 1
  116. try:
  117. if chip:
  118. try:
  119. generator = chip.generator
  120. except (AttributeError) as e:
  121. print("The chip %s does not have a layout autogenerator. "\
  122. "You must specify the package type, -v, -P and -g manually." %\
  123. package)
  124. return 1
  125. else:
  126. generator = createLayoutGenerator(package)
  127. generator.setProgrammerType(programmer.upper())
  128. generator.setPins(vccPin, vppPins, gndPin)
  129. generator.recalculate()
  130. if showInsert:
  131. print("Chip insert layout:\n")
  132. print(generator.zifLayoutAsciiArt())
  133. if showSupply:
  134. print("\nSupply voltage pins on the ZIF:\n")
  135. print(generator.zifPinAssignments())
  136. except (TOPException) as e:
  137. print(e)
  138. return 1
  139. return 0
  140. if __name__ == "__main__":
  141. sys.exit(main(sys.argv))