summaryrefslogtreecommitdiffstats
path: root/toprammer-layout
blob: 781df9289c5952cdbede382e47e399a88bb0611a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env python
"""
#    TOP2049 Open Source programming suite
#
#    ZIF socket layout generator
#
#    Copyright (c) 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 libtoprammer.layout_generator import *
from libtoprammer.toprammer_main import *
from libtoprammer.chip import *
import getopt
import sys


def usage():
	print "Toprammer ZIF socket layout generator v%s" % VERSION
	print ""
	print "Usage: %s [OPTIONS]" % sys.argv[0]
	print ""
	print "Mandatory options:"
	print " -d|--device TOPxxxx    The TOPxxxx device that is used."
	print "                        Possible choices are: TOP2049"
	print " -p|--package DIPxx     The package type of the DUT."
	print "                        Package may also be the name of a supported chip."
	print "                        In this case, --vccx, --vpp and --gnd are ignored."
	print " -v|--vccx PIN          Set VCCX pin number, relative to the package."
	print " -P|--vpp PIN(s)        Set VPP pin number(s), relative to the package."
	print "                        May be one pin number or a comma separated list of pin numbers."
	print "                        May be omitted or NONE, if no VPP pin is required."
	print " -g|--gnd PIN           Set GND pin number, relative to the package."
	print ""
	print "Optional:"
	print " -h|--help              Print this help text"
	print " -I|--only-insert       Only show insert-layout"
	print " -S|--only-supply       Only show supply-layout"

def main(argv):
	programmer = None
	generator = None
	chip = None
	vccxPin = None
	vppPins = None
	gndPin = None
	showInsert = True
	showSupply = True
	try:
		(opts, args) = getopt.getopt(argv[1:],
			"d:p:hv:P:g:IS",
			[ "help", "device=", "package=", "vccx=", "vpp=", "gnd=",
			  "only-insert", "only-supply", ])
		for (o, v) in opts:
			if o in ("-h", "--help"):
				usage()
				return 0
			if o in ("-d", "--device"):
				programmer = v
			if o in ("-p", "--package"):
				result = RegisteredChip.find(v)
				if result:
					(unused, chip) = result
				else:
					generator = createLayoutGenerator(v)
			if o in ("-v", "--vccx"):
				vccxPin = int(v)
			if o in ("-P", "--vpp"):
				if v.upper() == "NONE":
					vppPins = None
				else:
					vppPins = []
					for v in v.split(","):
						vppPins.append(int(v))
			if o in ("-g", "--gnd"):
				gndPin = int(v)
			if o in ("-I", "--only-insert"):
				showInsert = True
				showSupply = False
			if o in ("-S", "--only-supply"):
				showInsert = False
				showSupply = True
		if not programmer:
			print "-d|--device is mandatory!\n"
			raise ValueError()
		if not generator and not chip:
			print "-p|--package is mandatory!\n"
			raise ValueError()
		if generator:
			if vccxPin is None or gndPin is None:
				print "-v|--vccx and  -g|--gnd  " +\
					"are mandatory, if a package type is specified.\n"
				raise ValueError()
	except (getopt.GetoptError, ValueError, KeyError), e:
		usage()
		return 1
	except (TOPException), e:
		print e
		return 1
	try:
		if chip:
			generator = chip.generator
		else:
			generator.setProgrammerType(programmer.upper())
			generator.setPins(vccxPin, vppPins, gndPin)
			generator.recalculate()
		if showInsert:
			print "Chip insert layout:\n"
			print generator.zifLayoutAsciiArt()
		if showSupply:
			print "\nSupply voltage pins on the ZIF:\n"
			print generator.zifPinAssignments()
	except (TOPException), e:
		print e
		return 1
	return 0

if __name__ == "__main__":
	sys.exit(main(sys.argv))
bues.ch cgit interface