Skip to content

Commit ce54bdb

Browse files
committed
wip
1 parent 3c6509b commit ce54bdb

File tree

2 files changed

+48
-29
lines changed

2 files changed

+48
-29
lines changed

chipflow_lib/platforms/utils.py

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ class _BasePackageDef(pydantic.BaseModel, abc.ABC):
274274
@property
275275
@abc.abstractmethod
276276
def pins(self) -> PinSet:
277-
"Returns the full set of pins for the package"
277+
"Returns the full set of unallocated pins for the package"
278278
...
279279

280280
@abc.abstractmethod
@@ -349,9 +349,14 @@ class _BareDiePackageDef(_BasePackageDef):
349349
height: int
350350

351351
def model_post_init(self, __context):
352-
self._ordered_pins = sorted(
353-
list(itertools.product((_Side.N, _Side.S), range(self.width))) +
354-
list(itertools.product((_Side.W, _Side.E), range(self.height))))
352+
pins = (
353+
set(itertools.product((_Side.N, _Side.S), range(self.width)))
354+
+ set(itertools.product((_Side.W, _Side.E), range(self.height)))
355+
- set(self.power.values())
356+
- set(self.power.clocks.values())
357+
- set(self.power.jtag.values())
358+
)
359+
self._ordered_pins = sorted(pins)
355360
return super().model_post_init(__context)
356361

357362
@property
@@ -416,11 +421,29 @@ def heartbeat(self) -> Dict[int, Pin]:
416421
return {0: (_Side.S, 1)} # South side, pin 1
417422

418423

419-
class _PGAPackageDef(_BasePackageDef):
420-
"""Definiton of a PGA package with `size` pins
421-
422-
This is package with `size` pins, numbered, with the assumption that adjacent pins
423-
are numbered close together.
424+
class _QuadPackageDef(_BasePackageDef):
425+
"""Definiton of a package a row of 'width* pins on the top and bottom of the package and 'height' pins
426+
on the left and right
427+
428+
The pins are numbered anti-clockwise from the top left hand pin.
429+
430+
This includes the following types of package:
431+
.. csv-table:
432+
:header: "Package", "Description"
433+
"BQFP", "bumpered quad flat package"
434+
"BQFPH", "bumpered quad flat package with heat spreader"
435+
"CQFP", "ceramic quad flat package"
436+
"EQFP", "plastic enhanced quad flat package"
437+
"FQFP", "fine pitch quad flat package"
438+
"LQFP", "low profile quad flat package"
439+
"MQFP", "metric quad flat package"
440+
"NQFP", "near chip-scale quad flat package."
441+
"SQFP", "small quad flat package"
442+
"TQFP", "thin quad flat package"
443+
"VQFP", "very small quad flat package"
444+
"VTQFP", "very thin quad flat package"
445+
"TDFN", "thin dual flat no-lead package."
446+
"CERQUAD", "low-cost CQFP"
424447
"""
425448

426449
# Used by pydantic to differentate when deserialising
@@ -430,8 +453,13 @@ class _PGAPackageDef(_BasePackageDef):
430453
height: int
431454

432455
def model_post_init(self, __context):
433-
self._ordered_pins = sorted(
434-
[str(i) for i in range(1, self.width * 2 + self.height * 2)])
456+
pins =(
457+
set([str(i) for i in range(1, self.width * 2 + self.height * 2)])
458+
- set(self.power.values())
459+
- set(self.power.clocks.values())
460+
- set(self.power.jtag.values())
461+
)
462+
self._ordered_pins = sorted(pins)
435463
return super().model_post_init(__context)
436464

437465

@@ -517,14 +545,14 @@ def heartbeat(self) -> Dict[int, Pin]:
517545

518546
class Port(pydantic.BaseModel):
519547
type: str
520-
pins: List[str]
548+
pins: List[str] | None # None implies must be allocated at end
521549
port_name: str
522550
direction: Optional[str] = None
523551
options: Optional[dict] = None
524552

525553
@property
526554
def width(self):
527-
return len(self.pins)
555+
return len(self.pins) if self.pins else 0
528556

529557

530558
class Package(pydantic.BaseModel):
@@ -559,18 +587,13 @@ def add_pad(self, name: str, defn: dict):
559587
self.power[name] = Port(type="power", pins=[loc], port_name=name)
560588
case {"type": "ground", "loc": loc}:
561589
self.power[name] = Port(type="ground", pins=[loc], port_name=name)
562-
case {"type": "power", "name": name, "voltage": voltage}:
563-
# Support for new power pin format
564-
# First, get the default pin from the package type
565-
power_pin = self.package_type.power[PowerType.POWER]
566-
self.power[name] = Port(type="power", pins=[str(power_pin)], options={"voltage": voltage})
567-
case {"type": "ground", "name": name}:
568-
# Support for new ground pin format
569-
ground_pin = self.package_type.power[PowerType.GROUND]
570-
self.power[name] = Port(type="ground", pins=[str(ground_pin)])
571590
case _:
572591
pass
573592

593+
def add_power_domain(self, name: str, defn: dict):
594+
self.power[name] = Port(type="power", options=defn)
595+
self.power[name] = Port(type="ground", options=defn)
596+
574597
def initialize_from_package_type(self):
575598
"""Initialize standard pins from package type definitions"""
576599
# Set up clocks

tests/test_config_models.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@ def setUp(self):
2020
"top": {},
2121
"silicon": {
2222
"process": "sky130",
23-
"package": "cf20",
24-
"pads": {
25-
"sys_clk": {"type": "clock", "loc": "114"}
26-
},
23+
"package": "pga144",
2724
"power": {
28-
"vdd": {"type": "power", "loc": "1"}
25+
"vdd": {"type": "power"}
2926
}
3027
}
3128
}
@@ -35,7 +32,7 @@ def test_config_validation(self):
3532
"""Test that the Config model validates a known-good config."""
3633
config = Config.model_validate(self.valid_config_dict)
3734
self.assertEqual(config.chipflow.project_name, "test-chip")
38-
self.assertEqual(config.chipflow.silicon.package, "cf20")
35+
self.assertEqual(config.chipflow.silicon.package, "pga144")
3936
self.assertEqual(config.chipflow.silicon.process, Process.SKY130)
4037

4138
def test_pad_config(self):
@@ -66,4 +63,3 @@ def test_nested_structure(self):
6663
self.assertEqual(len(silicon.power), 1)
6764
power = silicon.power["vdd"]
6865
self.assertEqual(power.type, "power")
69-
self.assertEqual(power.loc, "1")

0 commit comments

Comments
 (0)