3 from spec
.pinfunctions
import pinspec
4 from copy
import deepcopy
6 def namesuffix(name
, suffix
, namelist
):
10 names
.append("%s%s_%s" % (name
, suffix
, n
))
12 names
.append("%s_%s" % (name
, suffix
))
17 """ a meta-helper which creates pins from the pinspec
18 and adds them to the pinouts.
20 __call__ is used to effectively create a lambda function, which
21 in combination with setattr (below) gives the function a name
22 in the Pinouts class, according to the pinspec.
24 def __init__(self
, pinouts
, fname
, pinfn
, bankspec
):
25 self
.pinouts
= pinouts
26 self
.bankspec
= bankspec
30 def __call__(self
, suffix
, offs
, bank
, mux
,
31 start
=None, limit
=None, spec
=None, origsuffix
=None):
32 pingroup
= self
.pinfn(suffix
, bank
)
33 if isinstance(pingroup
, tuple):
34 prefix
, pingroup
= pingroup
37 if start
and limit
: # limit turns into an offset from start
39 pingroup
= pingroup
[start
:limit
] # see comment in spec.pinfunctions
40 pins
= Pins(prefix
, pingroup
, self
.bankspec
,
41 suffix
, offs
, bank
, mux
,
42 spec
, origsuffix
=suffix
)
43 self
.pinouts
.pinmerge(pins
)
47 class Pinouts(object):
48 def __init__(self
, bankspec
):
49 self
.bankspec
= bankspec
52 for fname
, pinfn
in pinspec
:
53 if isinstance(pinfn
, tuple):
57 setattr(self
, name
, PinGen(self
, fname
, pinfn
, self
.bankspec
))
59 def __contains__(self
, k
):
65 def add_spec(self
, k
, v
):
68 def update(self
, pinidx
, v
):
69 if pinidx
not in self
.pins
:
73 assert k
not in self
.pins
[pinidx
], \
74 "pin %d position %d already taken\n%s\n%s" % \
75 (pinidx
, k
, str(v
), self
.pins
[pinidx
])
76 self
.pins
[pinidx
].update(v
)
79 return self
.pins
.keys()
82 return self
.pins
.items()
90 def __delitem__(self
, k
):
93 def __getitem__(self
, k
):
96 def pinmerge(self
, fn
):
97 # hack, store the function specs in the pins dict
99 suffix
= fn
.origsuffix
102 if not hasattr(self
, 'fnspec'):
106 assert 'EINT' not in self
107 if fname
not in self
.fnspec
:
108 self
.add_spec(fname
, {})
109 if suffix
or fname
== 'EINT' or fname
== 'PWM':
110 specname
= fname
+ suffix
113 #print "fname bank specname suffix ", fname, bank, specname, repr(
115 if specname
in self
.fnspec
[fname
]:
116 # ok so some declarations may bring in different
117 # names at different stages (EINT, PWM, flexbus1/2)
118 # so we have to merge the names in. main thing is
120 tomerge
= self
.fnspec
[fname
][specname
]
121 for p
in fn
.pingroup
:
122 if p
not in tomerge
.pingroup
:
123 tomerge
.pingroup
.append(p
)
124 tomerge
.pins
.update(fn
.pins
)
125 tomerge
.fntype
.update(fn
.fntype
)
127 self
.fnspec
[fname
][specname
] = deepcopy(fn
)
130 for (pinidx
, v
) in fn
.pins
.items():
131 self
.update(pinidx
, v
)
136 def __init__(self
, fname
, pingroup
, bankspec
, suffix
, offs
, bank
, mux
,
137 spec
=None, limit
=None, origsuffix
=None):
139 # function type can be in, out or inout, represented by - + *
140 # strip function type out of each pin name
142 for i
in range(len(pingroup
)):
147 if fntype
not in '+-*':
150 fntype
= {'-': 'in', '+': 'out', '*': 'inout'}[fntype
]
151 self
.fntype
[pname
] = fntype
155 self
.pingroup
= pingroup
156 self
.bankspec
= bankspec
158 self
.origsuffix
= origsuffix
or suffix
162 # create consistent name suffixes
163 pingroup
= namesuffix(fname
, suffix
, pingroup
)
169 for name
in pingroup
[:limit
]:
171 name_
= "%s_%s" % (name
, suffix
)
174 if spec
and name
in spec
:
176 pin
= {mux
: (name_
, bank
)}
177 offs_bank
, offs_
= offs
180 idx_
+= bankspec
[bank
]
183 for name
in pingroup
:
185 name_
= "%s_%s" % (name
, suffix
)
192 idx_
, mux_
, bank_
= spec
[name
]
194 pin
= {mux_
: (name_
, bank_
)}
196 res
[idx_
].update(pin
)