@@ -30,7 +30,7 @@ def _chipflow_schema_uri(name: str, version: int) -> str:
3030
3131
3232class _PinAnnotationModel (BaseModel ):
33- model_config = ConfigDict (use_enum_values = True , export_values = True )
33+ model_config = ConfigDict (use_enum_values = True )
3434 direction : io .Direction
3535 width : int
3636
@@ -57,9 +57,7 @@ def origin(self): # type: ignore
5757 return self .model
5858
5959 def as_json (self ): # type: ignore
60- json_dict = self .model .model_dump ()
61- json_dict ["direction" ] = self .model .direction .name # Use .name to get short enum name
62- return json_dict
60+ return self .model .model_dump ()
6361
6462
6563PIN_ANNOTATION_SCHEMA = str (_chipflow_schema_uri ("pin-annotation" , 0 ))
@@ -87,7 +85,9 @@ def __init__(self, direction, width=1, init=None):
8785 super ().__init__ (sig )
8886
8987 def annotations (self , * args ):
90- return wiring .Signature .annotations (self , * args ) + (_PinAnnotation (direction = self ._direction , width = self ._width ),)
88+ annotations = wiring .Signature .annotations (self , * args )
89+ pin_annotation = _PinAnnotation (direction = self ._direction , width = self ._width )
90+ return annotations + (pin_annotation ,)
9191
9292 def __repr__ (self ):
9393 return f"PinSignature({ self ._direction } , { self ._width } )"
@@ -105,8 +105,9 @@ def BidirPinSignature(width, **kwargs):
105105 return PinSignature (io .Direction .Bidir , width = width , ** kwargs )
106106
107107
108- PinSet = Set [tuple ]
109- PinList = List [tuple ]
108+ Pin = Union [tuple , str ]
109+ PinSet = Set [Pin ]
110+ PinList = List [Pin ]
110111Pins = Union [PinSet , PinList ]
111112
112113
@@ -128,15 +129,17 @@ def _group_consecutive_items(ordering: PinList, lst: PinList) -> OrderedDict[int
128129 last = lst [0 ]
129130 current_group = [last ]
130131
132+ logger .debug (f"_group_consecutive_items starting with { current_group } " )
133+
131134 for item in lst [1 :]:
132135 idx = ordering .index (last )
133136 next = ordering [idx + 1 ] if idx < len (ordering ) - 1 else None
134- # logger.debug(f"inspecting {item}, index {idx}, next {next}")
137+ logger .debug (f"inspecting { item } , index { idx } , next { next } " )
135138 if item == next :
136139 current_group .append (item )
137- # logger.debug("found consecutive, adding to current group")
140+ logger .debug ("found consecutive, adding to current group" )
138141 else :
139- # logger.debug("found nonconsecutive, creating new group")
142+ logger .debug ("found nonconsecutive, creating new group" )
140143 grouped .append (current_group )
141144 current_group = [item ]
142145 last = item
@@ -212,7 +215,7 @@ def sortpins(self, pins: Pins) -> PinList:
212215 return list (pins ).sort ()
213216
214217
215- class _QuadPackageDef (_BasePackageDef ):
218+ class _BareDiePackageDef (_BasePackageDef ):
216219 """Definition of a package with pins on four sides, labelled north, south, east, west
217220 with an integer identifier within each side.
218221 """
@@ -223,22 +226,26 @@ class _QuadPackageDef(_BasePackageDef):
223226 width : int
224227 height : int
225228
229+ def model_post_init (self , __context ):
230+ self ._ordered_pins = sorted (
231+ list (itertools .product ((_Side .N , _Side .S ), range (self .width ))) +
232+ list (itertools .product ((_Side .W , _Side .E ), range (self .height ))))
233+ return super ().model_post_init (__context )
234+
226235 @property
227236 def pins (self ) -> PinSet :
228- return set (
229- itertools .product ((_Side .N , _Side .S ), range (self .width )) +
230- itertools .product ((_Side .W , _Side .E ), range (self .height )))
237+ return set (self ._ordered_pins )
231238
232239 def allocate (self , available : PinSet , width : int ) -> PinList :
233240 avail_n = self .sortpins (available )
234- logger .debug (f"QuadPackageDef .allocate { width } from { len (avail_n )} remaining" )
235- ret = _find_contiguous_sequence (avail_n , width )
236- logger .debug (f"QuadPackageDef .returned { ret } " )
241+ logger .debug (f"_BareDiePackageDef .allocate { width } from { len (avail_n )} remaining" )
242+ ret = _find_contiguous_sequence (self . _ordered_pins , avail_n , width )
243+ logger .debug (f"_BareDiePackageDef .returned { ret } " )
237244 assert len (ret ) == width
238245 return ret
239246
240247
241- class _PGAPackageDef (_BasePackageDef ):
248+ class _QuadPackageDef (_BasePackageDef ):
242249 """Definiton of a PGA package with `size` pins
243250
244251 This is package with `size` pins, numbered, with the assumption that adjacent pins
@@ -248,31 +255,38 @@ class _PGAPackageDef(_BasePackageDef):
248255 # Used by pydantic to differentate when deserialising
249256 type : Literal ["_PGAPackageDef" ] = "_PGAPackageDef"
250257
251- size : int
258+ width :int
259+ height : int
260+
261+ def model_post_init (self , __context ):
262+ self ._ordered_pins = sorted (
263+ [str (i ) for i in range (1 , self .width * 2 + self .height * 2 )])
264+ return super ().model_post_init (__context )
265+
252266
253267 @property
254- def pins (self ) -> Set [ str ] :
255- return set ([ str ( i ) for i in range ( self .size - 1 )] )
268+ def pins (self ) -> PinSet :
269+ return set (self ._ordered_pins )
256270
257271 def allocate (self , available : Set [str ], width : int ) -> List [str ]:
258- avail_n = sorted ([ int ( i ) for i in available ] )
259- logger .debug (f"PGAPackageDef .allocate { width } from { len (avail_n )} remaining" )
260- ret = _find_contiguous_sequence (avail_n , width )
261- logger .debug (f"PGAPackageDef .returned { ret } " )
272+ avail_n = sorted (available )
273+ logger .debug (f"QuadPackageDef .allocate { width } from { len (avail_n )} remaining: { available } " )
274+ ret = _find_contiguous_sequence (self . _ordered_pins , avail_n , width )
275+ logger .debug (f"QuadPackageDef .returned { ret } " )
262276 assert len (ret ) == width
263- return [ str ( i ) for i in ret ]
277+ return ret
264278
265279 def sortpins (self , pins : Union [List [str ], Set [str ]]) -> List [str ]:
266280 return sorted (list (pins ), key = int )
267281
268282
269283# Add any new package types to both PACKAGE_DEFINITIONS and the PackageDef union
270284PACKAGE_DEFINITIONS = {
271- "pga144" : _PGAPackageDef (name = "pga144" , size = 144 ),
272- "cf20" : _QuadPackageDef (name = "cf20" , width = 7 , height = 3 )
285+ "pga144" : _QuadPackageDef (name = "pga144" , width = 36 , height = 36 ),
286+ "cf20" : _BareDiePackageDef (name = "cf20" , width = 7 , height = 3 )
273287}
274288
275- PackageDef = Union [_PGAPackageDef , _BasePackageDef ]
289+ PackageDef = Union [_QuadPackageDef , _BasePackageDef ]
276290
277291
278292class Port (pydantic .BaseModel ):
0 commit comments