5c596635f8641f52b1a1be1d14fda49280c883c9
3 from copy
import deepcopy
4 from collections
import OrderedDict
7 def bond_int_to_ext(pin
, bank
):
8 """ note that internal numbering is 0-31 whereas the DISPLAY internal
9 numbering is 1-32. this uses the INTERNAL numbering.
13 outer ring numbers: the python list order of the outer pads
14 middle numbers: the package number wires (plus side they are on)
15 inner numbers: the IO pad *python internal (0-31)* numbers plus side
18 N102 N101 N100 99 N 68 N67 N66 N65
19 W29 W30 W31 N0 N N31 E29 E30 E31
25 W2 W1 W0 S0 S S31 E0 E1 E2
26 S1 S2 S3 4 S 35 S36 S37 S38
30 # returns side, order-on-the-side, pin number
32 return 'N', pin
+3, 99-pin
34 return 'S', pin
+3, 4+pin
36 if pin
>= 29: # 29, 30, 31
37 return 'N', pin
-29, 100+(31-pin
)
39 return 'S', 2-pin
, 3-pin
40 return 'W', pin
-3, 103+(28-pin
)
43 return 'N', pin
+6, 67-(pin
-29)
45 return 'S', pin
+35, 36+pin
46 return 'E', pin
-3, 39+(pin
-3)
49 def create_sv(fname
, pins
):
50 """unsophisticated drawer of an SVG
56 print ("WARNING, no SVG image, not producing image %s" % fname
)
59 # create internal to external map
60 bondmap
= {'N': {}, 'S': {}, 'E': {}, 'W': {} }
61 padside
= {'pads.north': 'N', 'pads.east': 'E', 'pads.south': 'S',
63 for pinpad
, bank
in padside
.items():
64 for ipin
in range(len(pins
[pinpad
])):
65 eside
, enum
, epinnum
= bond_int_to_ext(ipin
, bank
)
66 bondmap
[eside
][enum
] = (epinnum
, ipin
, bank
)
67 with
open("/tmp/bondmap.txt", "w") as f
:
68 for k
,v
in bondmap
.items():
70 for enum
, (epinnum
, ipin
, bank
) in v
.items():
71 f
.write(" %d %d -> %s %d\n" % (enum
, epinnum
, bank
, ipin
))
74 width
= len(pins
['pads.north']) * scale
75 height
= len(pins
['pads.east']) * scale
76 woffs
= scale
*40#-width/2
77 hoffs
= scale
*40#-height/2
79 dwg
= svgwrite
.Drawing(fname
, profile
='full',
80 size
=(width
+scale
*80, height
+scale
*80))
81 dwg
.add(dwg
.rect((woffs
-scale
*2, hoffs
-scale
*2),
82 (woffs
+width
-scale
*34, hoffs
+height
-scale
*34),
83 stroke
=svgwrite
.rgb(16, 255, 16, '%'),
84 stroke_width
=scale
/10.0))
86 dwg
.add(dwg
.text("Libre-SOC ls180 QFP-128",
87 insert
=(woffs
+width
/2-scale
*5, woffs
+height
/2),
89 dwg
.add(dwg
.text("In collaboration with LIP6.fr",
90 insert
=(woffs
+width
/2-scale
*5, woffs
+height
/2+scale
),
92 dwg
.add(dwg
.text("Cell Libraries by Chips4Makers",
93 insert
=(woffs
+width
/2-scale
*5, woffs
+height
/2+scale
*2),
96 for i
, pin
in enumerate(pins
['pads.west']):
97 ht
= hoffs
+ height
- (i
* scale
) + scale
*0.5
98 dwg
.add(dwg
.line((woffs
-scale
*2, ht
-scale
*0.5),
99 (woffs
-scale
*4.5, ht
-scale
*0.5),
100 stroke
=svgwrite
.rgb(16, 255, 16, '%'),
101 stroke_width
=scale
/10.0))
102 dwg
.add(dwg
.text(pin
.upper(), insert
=(woffs
-scale
*14, ht
),
104 dwg
.add(dwg
.text("W%d" % (i
+1), insert
=(woffs
-scale
*1.5, ht
),
107 for i
, pin
in enumerate(pins
['pads.east']):
108 ht
= hoffs
+ height
- (i
* scale
) + scale
*0.5
109 wd
= width
+ woffs
+ scale
*2
110 dwg
.add(dwg
.line((wd
+scale
*2, ht
-scale
*0.5),
111 (wd
+scale
*4.5, ht
-scale
*0.5),
112 stroke
=svgwrite
.rgb(16, 255, 16, '%'),
113 stroke_width
=scale
/10.0))
114 dwg
.add(dwg
.text(pin
.upper(), insert
=(wd
+scale
*5, ht
-scale
*0.25),
116 dwg
.add(dwg
.text("E%d" % (i
+1), insert
=(wd
, ht
-scale
*0.25),
119 for i
, pin
in enumerate(pins
['pads.north']):
120 wd
= woffs
+ i
* scale
+ scale
*1.5
121 dwg
.add(dwg
.line((wd
, hoffs
-scale
*2),
122 (wd
, hoffs
-scale
*4.5),
123 stroke
=svgwrite
.rgb(16, 255, 16, '%'),
124 stroke_width
=scale
/10.0))
125 pos
=(wd
, hoffs
-scale
*5.0)
126 txt
= dwg
.text(pin
.upper(), insert
=pos
, fill
='black')
129 pos
=(wd
+scale
*0.25, hoffs
-scale
*0.25)
130 txt
= dwg
.text("N%d" % (i
+1), insert
=pos
, fill
='white')
134 for i
, pin
in enumerate(pins
['pads.south']):
135 wd
= woffs
+ i
* scale
+ scale
*1.5
136 ht
= hoffs
+ height
+ scale
*2
137 dwg
.add(dwg
.line((wd
, ht
+scale
*2),
139 stroke
=svgwrite
.rgb(16, 255, 16, '%'),
140 stroke_width
=scale
/10.0))
141 pos
=(wd
-scale
*0.25, ht
+scale
*5.0)
142 txt
= dwg
.text(pin
.upper(), insert
=pos
, fill
='black')
145 pos
=(wd
-scale
*0.25, ht
+scale
*0.25)
146 txt
= dwg
.text("S%d" % (i
+1), insert
=pos
, fill
='white')
153 def display(of
, pins
, banksel
=None, muxwidth
=4):
155 | Pin | Mux0 | Mux1 | Mux2 | Mux3 |
156 | --- | ----------- | ----------- | ----------- | ----------- |
158 pinidx
= sorted(pins
.keys())
160 pdata
= pins
.get(pin
)
163 for mux
in range(muxwidth
):
166 name
, bank
= pdata
[mux
]
171 res
= '| %3d |' % pin
172 for mux
in range(muxwidth
):
176 name
, bank
= pdata
[mux
]
177 res
+= " %s %-9s |" % (bank
, name
)
178 of
.write("%s\n" % res
)
184 if not f
.startswith('FB_'):
188 return f2
[0], int(f2
[1])
191 while f
and not f
[0].isdigit():
194 return a
, int(f
) if f
else None
206 def find_fn(fname
, names
):
208 if fname
.startswith(n
):
211 def map_name(pinmap
, fn
, fblower
, pin
, rename
):
213 if pin
[:-1].isdigit():
214 print "map name digit", pin
, fn
, fblower
215 if fn
in ['PWM', 'EINT', 'VDD', 'VSS']:
216 return fn
.lower() + pin
.lower()
218 return 'gpio' + pin
[1:].lower()
222 pk
= '%s%s_%s' % (fblower
, pin
[0], pin
[:-1])
223 elif pin
[:-1].isdigit() and fn
!= 'EINT':
224 pk
= '%s%s_out' % (fblower
, pin
[:-1])
226 pk
= '%s_%s' % (fblower
, pin
[:-1])
227 print "map name", pk
, fblower
, pinmap
.has_key(pk
)
228 if not pinmap
.has_key(pk
):
230 remapped
= pinmap
[pk
]
231 uscore
= remapped
.find('_')
234 fn
, pin
= remapped
[:uscore
], remapped
[uscore
+1:] + pin
[-1]
237 def python_pindict(of
, pinmap
, pins
, function_names
, dname
, remap
):
240 of
.write("\n%s = OrderedDict()\n" % dname
)
242 for k
, pingroup
in pins
.byspec
.items():
243 (a
, n
) = k
.split(":")
247 of
.write("%s['%s'] = [ " % (dname
, fblower
))
250 for i
, p
in enumerate(pingroup
):
251 name
= map_name(pinmap
, k
[0], fblower
, p
, remap
)
252 res
[fblower
].append(name
)
253 of
.write("'%s', " % name
)
255 if count
== 4 and i
!= len(pingroup
)-1:
259 print " dict %s" % dname
, a
, n
, pingroup
263 def python_dict_fns(of
, pinmap
, pins
, function_names
):
264 of
.write("# auto-generated by Libre-SOC pinmux program: do not edit\n")
265 of
.write("# python src/pinmux_generator.py -v -s {spec} -o {output}\n")
266 of
.write("# use OrderedDict to fix stable order for JTAG Boundary Scan\n")
267 of
.write("from collections import OrderedDict\n")
269 fn_names
= function_names
.keys()
272 fnidx
= list(fns
.keys())
273 fnidx
.sort(key
=fnsplit
)
275 print "python fnames", function_names
276 print "python speckeys", pins
.byspec
.keys()
277 print "python dict fns", dir(pins
.gpio
)
278 print pins
.gpio
.pinfn('', '')
279 print pins
.pwm
.pinfn('', '')
280 print pins
.sdmmc
.pinfn('', '')
281 print "by spec", pins
.byspec
284 pd
= python_pindict(of
, {}, pins
, function_names
, 'pindict', False)
285 ld
= python_pindict(of
, pinmap
, pins
, function_names
, 'litexdict', True)
289 # process results and create name map
290 litexmap
= OrderedDict()
294 for pname
, lname
in zip(pl
, ll
):
295 pname
= "%s_%s" % (k
, pname
[:-1]) # strip direction +/-/*
296 lname
= lname
[:-1] # strip direction +/-/*
297 if k
in ['eint', 'pwm', 'gpio', 'vdd', 'vss']: # sigh
298 lname
= "%s_%s" % (k
, lname
)
299 litexmap
[pname
] = lname
300 print "litexmap", litexmap
301 of
.write("litexmap = {\n")
302 for k
, v
in litexmap
.items():
303 of
.write("\t'%s': '%s',\n" % (k
, v
))
308 def display_fns(of
, bankspec
, pins
, function_names
):
309 fn_names
= function_names
.keys()
311 for (pin
, pdata
) in pins
.items():
312 for mux
in range(0, 4): # skip GPIO for now
315 name
, bank
= pdata
[mux
]
316 assert name
is not None, str(bank
)
319 fns
[name
].append((pin
- bankspec
[bank
], mux
, bank
))
321 fnidx
= list(fns
.keys())
322 fnidx
.sort(key
=fnsplit
)
325 fnbase
= find_fn(fname
, fn_names
)
326 #fblower = fnbase.lower()
327 assert fnbase
in function_names
, "fn %s not in descriptions %s" % \
328 (fname
, str(function_names
.keys()))
329 #print "name", fname, fnbase
330 if fnbase
!= current_fn
:
331 if current_fn
is not None:
333 of
.write("## %s\n\n%s\n\n" % (fnbase
, function_names
[fnbase
]))
335 of
.write("* %-9s :" % fname
)
336 for (pin
, mux
, bank
) in fns
[fname
]:
337 of
.write(" %s%d/%d" % (bank
, pin
, mux
))
343 def check_functions(of
, title
, bankspec
, fns
, pins
, required
, eint
, pwm
,
346 pins
= deepcopy(pins
)
347 if descriptions
is None:
354 of
.write("# Pinmap for %s\n\n" % title
)
356 print "fn_idx", fnidx
358 print "fnspec", pins
.fnspec
.keys()
359 print "required", required
360 for name
in required
:
361 of
.write("## %s\n\n" % name
)
362 if descriptions
and name
in descriptions
:
363 of
.write("%s\n\n" % descriptions
[name
])
365 name
= name
.split(':')
367 findbank
= name
[0][0]
368 findmux
= int(name
[0][1:])
374 name
= name
.split('/')
385 if not fname
.startswith(name
):
387 for k
in pins
.fnspec
.keys():
388 if fname
.startswith(k
):
389 fk
= list(pins
.fnspec
[k
].keys())
392 #print fname, fn, dir(fn)
394 count
= len(fn
.pingroup
)
395 for pin
, mux
, bank
in fns
[fname
]:
396 if findbank
is not None:
401 pin_
= pin
+ bankspec
[bank
]
403 pinfound
[pin_
] = (fname
, pin_
, bank
, pin
, mux
)
405 pinidx
= sorted(pinfound
.keys())
409 print ("pinidx", pinidx
)
411 fname
, pin_
, bank
, pin
, mux
= pinfound
[pin_
]
415 if len(found
) > count
:
419 of
.write("* %s %d %s%d/%d\n" % (fname
, pin_
, bank
, pin
, mux
))
422 if removedcount
!= count
:
424 print "no match between required and available pins"
426 print ("not all found", name
, removedcount
, count
, title
, found
,
428 print ("pins found", pinfound
)
435 for name
in descriptions
.keys():
436 if not name
.startswith('GPIO'):
444 of
.write("## GPIO\n\n")
450 if descriptions
and fname
in descriptions
:
451 desc
= ': %s' % descriptions
[fname
]
454 pin_
= pin
+ bankspec
[bank
]
459 of
.write("* %-8s %d %s%-2d %s\n" % (fname
, pin_
, bank
, pin
, desc
))
463 display_group(of
, bankspec
, "EINT", eint
, fns
, pins
, descriptions
)
465 display_group(of
, bankspec
, "PWM", pwm
, fns
, pins
, descriptions
)
467 of
.write("## Unused Pinouts (spare as GPIO) for '%s'\n\n" % title
)
468 if descriptions
and 'GPIO' in descriptions
:
469 of
.write("%s\n\n" % descriptions
['GPIO'])
476 def display_group(of
, bankspec
, title
, todisplay
, fns
, pins
, descriptions
):
477 of
.write("## %s\n\n" % title
)
480 for fname
in todisplay
:
482 if descriptions
and fname
in descriptions
:
483 desc
= ': %s' % descriptions
[fname
]
484 fname
= fname
.split(':')
486 findbank
= fname
[0][0]
487 findmux
= int(fname
[0][1:])
493 for (pin
, mux
, bank
) in fns
[fname
]:
494 if findbank
is not None:
501 pin_
= pin
+ bankspec
[bank
]
506 of
.write("* %s %d %s%d/%d %s\n" %
507 (fname
, pin_
, bank
, pin
, mux
, desc
))
511 def display_fixed(of
, fixed
, offs
):
513 fkeys
= sorted(fixed
.keys())
516 for pin
, k
in enumerate(fkeys
):
517 of
.write("## %s\n\n" % k
)
520 for name
in fixed
[k
]:
524 if prevname
[:2] == name
[:2] and linecount
!= 0:
525 of
.write(" %s" % name
)
530 of
.write("* %d: %d %s" % (pin_
, pin
, name
))
532 res
.append((pin_
, name
))