Skip to content

Commit 012742d

Browse files
committed
Fix wiring up of resets and clocks
1 parent ff8ec0f commit 012742d

File tree

7 files changed

+38
-21
lines changed

7 files changed

+38
-21
lines changed

chipflow_lib/platforms/sim.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: BSD-2-Clause
22

3+
import logging
34
import os
45
import sys
56
from pathlib import Path
@@ -14,6 +15,7 @@
1415

1516

1617
__all__ = ["SimPlatform"]
18+
logger = logging.getLogger(__name__)
1719

1820

1921
class SimPlatform:
@@ -42,6 +44,7 @@ def build(self, e):
4244
if port.direction is io.Direction.Bidir:
4345
ports.append((f"io${port_name}$oe", port.oe, PortDirection.Output))
4446

47+
print("elaborating design")
4548
output = rtlil.convert(e, name="sim_top", ports=ports, platform=self)
4649

4750
top_rtlil = Path(self.build_dir) / "sim_soc.il"
@@ -73,19 +76,26 @@ def instantiate_ports(self, m: Module):
7376
for component, iface in pinlock.port_map.ports.items():
7477
for k, v in iface.items():
7578
for name, port in v.items():
79+
logger.debug(f"Instantiating port {port.port_name}: {port}")
7680
invert = port.invert if port.invert else False
7781
self._ports[port.port_name] = io.SimulationPort(port.direction, port.width, invert=invert, name=f"{component}-{name}")
7882

7983
for clock in pinlock.port_map.get_clocks():
80-
setattr(m.domains, clock.port_name, ClockDomain(name=clock.port_name))
84+
assert 'clock_domain_o' in clock.iomodel
85+
domain = clock.iomodel['clock_domain_o']
86+
logger.debug(f"Instantiating clock buffer for {clock.port_name}, domain {domain}")
87+
setattr(m.domains, domain, ClockDomain(name=domain))
8188
clk_buffer = io.Buffer(clock.direction, self._ports[clock.port_name])
8289
setattr(m.submodules, "clk_buffer_" + clock.port_name, clk_buffer)
8390
m.d.comb += ClockSignal().eq(clk_buffer.i) # type: ignore[reportAttributeAccessIssue]
8491

8592
for reset in pinlock.port_map.get_resets():
93+
assert 'clock_domain_o' in reset.iomodel
94+
domain = reset.iomodel['clock_domain_o']
95+
logger.debug(f"Instantiating reset synchronizer for {reset.port_name}, domain {domain}")
8696
rst_buffer = io.Buffer(reset.direction, self._ports[clock.port_name])
8797
setattr(m.submodules, reset.port_name, rst_buffer)
88-
ffsync = FFSynchronizer(rst_buffer.i, ResetSignal(name=reset.port_name)) # type: ignore[reportAttributeAccessIssue]
98+
ffsync = FFSynchronizer(rst_buffer.i, ResetSignal()) # type: ignore[reportAttributeAccessIssue]
8999
setattr(m.submodules, reset.port_name + "_sync", ffsync)
90100

91101
self._pinlock = pinlock

chipflow_lib/platforms/utils.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -332,17 +332,16 @@ def width(self):
332332

333333
@property
334334
def direction(self):
335-
assert self.pins and 'direction' in self.iomodel
336-
assert len(self.pins) == self.iomodel['direction']
335+
assert 'direction' in self.iomodel
337336
return self.iomodel['direction']
338337

339338
@property
340-
def invert(self) -> Iterable[bool]:
341-
assert self.pins and 'invert' in self.iomodel
342-
print(type(self.iomodel['invert']))
343-
assert type(self.iomodel['invert']) is tuple
344-
assert len(self.pins) == len(self.iomodel['invert'])
345-
return self.iomodel['invert']
339+
def invert(self) -> Iterable[bool] | None:
340+
if 'invert' in self.iomodel:
341+
assert type(self.iomodel['invert']) is tuple
342+
return self.iomodel['invert']
343+
else:
344+
return None
346345

347346

348347
def _group_consecutive_items(ordering: PinList, lst: PinList) -> OrderedDict[int, List[PinList]]:
@@ -623,7 +622,7 @@ def _allocate_bringup(self, config: 'Config') -> Component:
623622
'sync-rst_n': Port(type='reset',
624623
pins=[self.bringup_pins.core_reset],
625624
port_name='sync-rst_n',
626-
iomodel=IOModel(width=1, direction=io.Direction.Input, clock_domain_o="sync",
625+
iomodel=IOModel(width=1, direction=io.Direction.Input, clock_domain_o="sync",
627626
invert=True)
628627
)
629628
}

chipflow_lib/software/soft_gen.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ def __init__(self, *, rom_start, rom_size, ram_start, ram_size):
1111
self.defines = []
1212
self.periphs = []
1313
self.extra_init = []
14+
print("initialed SoftwareGenerator")
1415

1516
def generate(self, out_dir):
1617
Path(out_dir).mkdir(parents=True, exist_ok=True)
18+
print(f"generating in {out_dir}")
1719
with open(Path(out_dir) / "start.S", "w") as f:
1820
f.write(self.start)
1921
with open(Path(out_dir) / "sections.lds", "w") as f:

chipflow_lib/steps/__init__.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,27 @@ def build_cli_parser(self, parser):
4141

4242
def run_cli(self, args):
4343
"Called when this step's is used from `chipflow` command"
44+
self.build()
45+
46+
def build(self, *args):
47+
"builds the design"
4448
...
4549

4650
def _wire_up_ports(m: Module, top, platform):
47-
logger.debug("wiring up ports")
48-
logger.debug("adding top:")
51+
logger.debug("Wiring up ports")
52+
logger.debug("-> Adding top components:")
4953
for n, t in top.items():
5054
logger.debug(f" > {n}, {t}")
5155
setattr(m.submodules, n, t)
52-
53-
logger.debug("wiring up:")
56+
print("Wiring up ports:")
5457
for component, iface in platform._pinlock.port_map.ports.items():
5558
if component.startswith('_'):
5659
logger.debug(f"Ignoring special component {component}")
5760
continue
5861

5962
for iface_name, member, in iface.items():
6063
for name, port in member.items():
61-
logger.debug(f" > {component}, {iface_name}, {member}")
62-
64+
logger.debug(f" > {component}, {iface_name}, {name}: {port}")
6365
iface = getattr(top[component], iface_name)
6466
wire = (iface if isinstance(iface.signature, IOSignature)
6567
else getattr(iface, name))

chipflow_lib/steps/board.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ def build_cli_parser(self, parser):
1414
def run_cli(self, args):
1515
self.build()
1616

17-
def build(self):
17+
def build(self, *args):
1818
"Build for the given platform"
19-
self.platform.build()
19+
self.platform.build(*args)

chipflow_lib/steps/sim.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ def __init__(self, config):
7777
self._platform = SimPlatform(config)
7878
self._config = config
7979

80-
def build(self):
80+
def build(self, *args):
81+
print("building sim")
8182
m = Module()
8283
self._platform.instantiate_ports(m)
8384

chipflow_lib/steps/software.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
from doit.doit_cmd import DoitMain
55

66
from . import StepBase
7+
from ..platforms import SimPlatform
78

89
class SoftwareStep(StepBase):
910
"""Base step to build the software."""
1011

1112
doit_build_module = None
1213

1314
def __init__(self, config):
15+
self._platform = SimPlatform(config)
1416
pass
1517

1618
def build_cli_parser(self, parser):
@@ -23,6 +25,7 @@ def doit_build(self):
2325
"Run the overridden doit_build_module"
2426
DoitMain(ModuleTaskLoader(self.doit_build_module)).run(["build_software"])
2527

26-
def build(self):
28+
def build(self, *args):
2729
"Build the software for your design"
30+
print("building software")
2831
self.doit_build()

0 commit comments

Comments
 (0)