Skip to content

Commit ee057f7

Browse files
committed
wip
1 parent 00f5e36 commit ee057f7

File tree

6 files changed

+49
-83
lines changed

6 files changed

+49
-83
lines changed

chipflow_lib/config_models.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: BSD-2-Clause
22
import re
3+
from pprint import pformat
34
from typing import Dict, Optional, Literal, Any
45

56
from pydantic import BaseModel, model_validator, ValidationInfo, field_validator
@@ -21,6 +22,9 @@ def validate_loc_format(self):
2122

2223
@classmethod
2324
def validate_pad_dict(cls, v: dict, info: ValidationInfo):
25+
print(f"validate_pad_dict: info:\n{pformat(info)}")
26+
print(f"info.context:\n{pformat(info.context)}")
27+
print(f"info.data:\n{pformat(info.data)}")
2428
"""Custom validation for pad dicts from TOML that may not have all fields."""
2529
if isinstance(v, dict):
2630
# Handle legacy format - if 'type' is missing but should be inferred from context

chipflow_lib/platforms/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ def add_pad(self, name: str, defn: dict):
557557
case {"type": "power", "loc": loc}:
558558
self.power[name] = Port(type="power", pins=[loc], port_name=name)
559559
case {"type": "ground", "loc": loc}:
560-
self.power[name] = Port(type="ground", pins=[loc])
560+
self.power[name] = Port(type="ground", pins=[loc], port_name=name)
561561
case {"type": "power", "name": name, "voltage": voltage}:
562562
# Support for new power pin format
563563
# First, get the default pin from the package type

docs/chipflow-toml-guide.rst

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ The logic that synchronizes the reset signal with the clock will be generated au
105105
package = "pga144"
106106
107107
108-
The ``silicon`` section sets the Foundry ``process`` (i.e. PDK) that we are targeting for manufacturing, and the physical ``package`` (pad ring) we want to place our design inside.
108+
The ``silicon`` section sets the Foundry ``process`` (i.e. PDK) that we are targeting for manufacturing, and the physical ``package`` (including pad ring) we want to place our design inside.
109+
109110
You'll choose the ``process`` and ``package`` based in the requirements of your design.
110111

111112
Available processes
@@ -124,8 +125,8 @@ Available processes
124125
| ihp_sg13g2 | pga144 | IHP SG13G2 130nm SiGe |
125126
+------------+------------+---------------------------+
126127

127-
Available pad rings
128-
-------------------
128+
Available Package Definitions
129+
-----------------------------
129130

130131
+----------+-----------+--------------------+------------------------------------+
131132
| Pad ring | Pad count | Pad locations | Notes |
@@ -139,19 +140,37 @@ Available pad rings
139140
+----------+-----------+--------------------+------------------------------------+
140141

141142

142-
``[silicon.pads]``
143-
------------------
143+
``[silicon.power]``
144+
-------------------
144145

145-
The ``silicon.pads`` section lists special pads. In general you are unlikely to need to add to this.
146-
Each pad specified with the name used by the design and two parameters: :term:type and :term:`loc`.
146+
This section outlines the connection of pads to the power supply available for the selected process and package.
147+
These pads are declared with the :term:type parameter, along with a name and other optional information, like voltage.
147148

148-
.. code-block:: TOML
149+
Note that in this context, the :term:type parameter can only be ``ground`` or ``power``.
150+
151+
The package definition provides default locations for standard pins like power, ground, clocks, and resets. You only need to specify the name and properties.
152+
153+
[chipflow.silicon.power]
154+
vdd = { type = "power", name = "vdd", voltage = "1.8V" }
155+
gnd = { type = "ground", name = "gnd" }
156+
```
157+
158+
159+
``[silicon.power]``
160+
-------------------
161+
162+
This section outlines the connection of pads to the power supply available for the selected process and package.
163+
These pads are declared with the :term:type parameter, along with a name and other optional information, like voltage.
149164

150-
[chipflow.silicon.pads]
151-
sys_clk = { type = "clock", loc = "114" }
152-
sys_rst_n = { type = "reset", loc = "115" }
165+
Note that in this context, the :term:type parameter can only be ``ground`` or ``power``.
166+
167+
[chipflow.silicon.power]
168+
vdd = { type = "power", name = "vdd", voltage = "1.8V" }
169+
gnd = { type = "ground", name = "gnd" }
170+
```
171+
172+
In the new format, the package definition provides default locations for standard pins like power, ground, clocks, and resets. You only need to specify the name and properties.
153173

154-
In the above example two pads specified, ``sys_clk`` pad for clock input and ``sys_rst_n`` for reset.
155174

156175
.. glossary::
157176

@@ -168,13 +187,4 @@ In the above example two pads specified, ``sys_clk`` pad for clock input and ``s
168187
External reset input.
169188

170189

171-
``[silicon.power]``
172-
-------------------
173-
174-
This section outlines the connection of pads to the power supply available for the selected process and package.
175-
These pads are declared with the :term:type and :term:loc parameters, similar to the `[silicon.pads]`_ section.
176-
Note that in this context, the :term:type parameter can only be ``ground`` or ``power``.
177-
178-
This is a work in progress, and currently you can use the defaults provided by customer support.
179-
180190
.. _Caravel Harness: https://caravel-harness.readthedocs.io/en/latest/

docs/package_pins.md

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,14 @@ This document describes the package pin interface in ChipFlow, introduced to pro
77
The package pin interface provides definitions for various types of pins in a chip package:
88

99
- Power and ground pins
10-
- Clock pins
10+
- Clock pins
1111
- Reset pins
1212
- JTAG pins
1313
- Heartbeat pins
1414

1515
Each package type (PGA, bare die, etc.) defines its own implementation of these pin types, with appropriate pin numbering and allocation strategies.
1616

17-
## Configuration in TOML Files
18-
19-
### Legacy Format (still supported)
20-
```toml
21-
[chipflow.silicon.power]
22-
vdd = { type = "power", loc = "1" }
23-
gnd = { type = "ground", loc = "2" }
24-
25-
[chipflow.silicon.pads]
26-
reset = { type = "reset", loc = "3" }
27-
clock = { type = "clock", loc = "4" }
28-
```
29-
30-
### New Format
31-
```toml
32-
[chipflow.silicon.power]
33-
vdd = { type = "power", name = "vdd", voltage = "1.8V" }
34-
gnd = { type = "ground", name = "gnd" }
35-
```
36-
37-
In the new format, the package definition provides default locations for standard pins like power, ground, clocks, and resets. You only need to specify the name and properties.
38-
39-
## Using the Package Pin Interface in Code
17+
# Using the Package Pin Interface in Code
4018

4119
### Getting Default Pins
4220

@@ -100,4 +78,4 @@ Tests for the package pin interface can be run using:
10078

10179
```bash
10280
pdm run pytest tests/test_package_pins.py
103-
```
81+
```

tests/test_package_pins.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from unittest import mock
44

55
from chipflow_lib.platforms.utils import (
6-
_BareDiePackageDef, _QuadPackageDef,
6+
_BareDiePackageDef, _PGAPackageDef,
77
PowerType, JTAGWireName, Package
88
)
99

@@ -49,7 +49,7 @@ def test_heartbeat_pins(self):
4949

5050
class TestQuadPackage(unittest.TestCase):
5151
def setUp(self):
52-
self.package = _QuadPackageDef(name="test_package", width=36, height=36)
52+
self.package = _PGAPackageDef(name="test_package", width=36, height=36)
5353

5454
def test_pins_property(self):
5555
"""Test that pins property returns all pins"""

tests/test_utils_additional.py

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
_Side,
1717
_BasePackageDef,
1818
_BareDiePackageDef,
19-
_QuadPackageDef,
19+
_PGAPackageDef,
2020
Package,
2121
Port,
2222
PortMap,
@@ -210,9 +210,9 @@ def test_portmap_methods(self):
210210

211211
class TestPackageDef(unittest.TestCase):
212212
def test_quad_package_def(self):
213-
"""Test _QuadPackageDef class"""
213+
"""Test _PGAPackageDef class"""
214214
# Create instance
215-
quad_pkg = _QuadPackageDef(name="test_quad", width=5, height=5)
215+
quad_pkg = _PGAPackageDef(name="test_quad", width=5, height=5)
216216

217217
# Check properties
218218
self.assertEqual(quad_pkg.name, "test_quad")
@@ -232,33 +232,6 @@ def test_quad_package_def(self):
232232
mock_sorted = sorted(test_pins, key=int)
233233
self.assertEqual(mock_sorted, ["1", "2", "3", "4", "5"])
234234

235-
def test_base_package_def_sortpins_bug(self):
236-
"""Test _BasePackageDef sortpins method - documenting the bug"""
237-
# Create a minimal subclass of _BasePackageDef for testing
238-
class TestPackageDef(_BasePackageDef):
239-
@property
240-
def pins(self):
241-
return {"1", "2", "3"}
242-
243-
def allocate(self, available, width):
244-
return list(available)[:width]
245-
246-
# Create an instance
247-
pkg = TestPackageDef(name="test_pkg")
248-
249-
# Instead of using SiliconTop to test elaboratables, let's use a simple mock
250-
# This avoids the need to import and use SiliconTop which generates warnings
251-
elaboratable_mock = mock.MagicMock()
252-
elaboratable_mock.elaborate = mock.MagicMock(return_value=mock.MagicMock())
253-
254-
# Test sortpins method - THIS IS EXPECTED TO FAIL because of a bug
255-
# The method should return sorted(list(pins)) but actually returns None
256-
# because list.sort() sorts in-place and returns None
257-
result = pkg.sortpins(["3", "1", "2"])
258-
259-
# This test documents the bug - the method returns None instead of a sorted list
260-
self.assertIsNone(result, "This documents a bug in sortpins! It should return a sorted list.")
261-
262235
def test_bare_die_package_def(self):
263236
"""Test _BareDiePackageDef class"""
264237
# Create instance
@@ -307,7 +280,7 @@ class TestPackage(unittest.TestCase):
307280
def test_package_init(self):
308281
"""Test Package initialization"""
309282
# Create package type
310-
package_type = _QuadPackageDef(name="test_package", width=10, height=10)
283+
package_type = _PGAPackageDef(name="test_package", width=10, height=10)
311284

312285
# Create package
313286
package = Package(package_type=package_type)
@@ -321,7 +294,7 @@ def test_package_init(self):
321294
def test_package_add_pad(self):
322295
"""Test Package.add_pad method"""
323296
# Create package type
324-
package_type = _QuadPackageDef(name="test_package", width=10, height=10)
297+
package_type = _PGAPackageDef(name="test_package", width=10, height=10)
325298

326299
# Create package
327300
package = Package(package_type=package_type)
@@ -354,7 +327,7 @@ def test_package_add_pad(self):
354327
def test_package_check_pad(self):
355328
"""Test Package.check_pad method"""
356329
# Create package type
357-
package_type = _QuadPackageDef(name="test_package", width=10, height=10)
330+
package_type = _PGAPackageDef(name="test_package", width=10, height=10)
358331

359332
# Create package
360333
package = Package(package_type=package_type)
@@ -371,7 +344,8 @@ def test_package_check_pad(self):
371344
self.assertEqual(clock_port.pins, ["1"])
372345

373346
reset_port = package.check_pad("rst1", {"type": "reset"})
374-
self.assertIsNone(reset_port) # This is None due to a bug in the code
347+
self.assertIsNotNone(reset_port)
348+
self.assertEqual(reset_port.pins, ["2"])
375349

376350
power_port = package.check_pad("vdd", {"type": "power"})
377351
self.assertIsNotNone(power_port)

0 commit comments

Comments
 (0)