Skip to content

Commit 058057f

Browse files
committed
Implement RFC 70: unify naming of MemoryMap resources and windows.
Fixes #69.
1 parent f5d4453 commit 058057f

File tree

10 files changed

+172
-203
lines changed

10 files changed

+172
-203
lines changed

amaranth_soc/csr/bus.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -636,18 +636,16 @@ class Decoder(wiring.Component):
636636
Data width. See :class:`Interface`.
637637
alignment : int, power-of-2 exponent
638638
Window alignment. See :class:`..memory.MemoryMap`.
639-
name : :class:`str`
640-
Window name. Optional. See :class:`..memory.MemoryMap`.
641639
642640
Attributes
643641
----------
644642
bus : :class:`Interface`
645643
CSR bus providing access to subordinate buses.
646644
"""
647-
def __init__(self, *, addr_width, data_width, alignment=0, name=None):
645+
def __init__(self, *, addr_width, data_width, alignment=0):
648646
super().__init__({"bus": In(Signature(addr_width=addr_width, data_width=data_width))})
649647
self.bus.memory_map = MemoryMap(addr_width=addr_width, data_width=data_width,
650-
alignment=alignment, name=name)
648+
alignment=alignment)
651649
self._subs = dict()
652650

653651
def align_to(self, alignment):
@@ -657,10 +655,10 @@ def align_to(self, alignment):
657655
"""
658656
return self.bus.memory_map.align_to(alignment)
659657

660-
def add(self, sub_bus, *, addr=None):
658+
def add(self, sub_bus, *, name=None, addr=None):
661659
"""Add a window to a subordinate bus.
662660
663-
See :meth:`MemoryMap.add_resource` for details.
661+
See :meth:`MemoryMap.add_window` for details.
664662
"""
665663
if isinstance(sub_bus, wiring.FlippedInterface):
666664
sub_bus_unflipped = flipped(sub_bus)
@@ -673,7 +671,7 @@ def add(self, sub_bus, *, addr=None):
673671
raise ValueError(f"Subordinate bus has data width {sub_bus.data_width}, which is not "
674672
f"the same as decoder data width {self.bus.data_width}")
675673
self._subs[sub_bus.memory_map] = sub_bus
676-
return self.bus.memory_map.add_window(sub_bus.memory_map, addr=addr)
674+
return self.bus.memory_map.add_window(sub_bus.memory_map, name=name, addr=addr)
677675

678676
def elaborate(self, platform):
679677
m = Module()
@@ -682,7 +680,7 @@ def elaborate(self, platform):
682680
r_data_fanin = 0
683681

684682
with m.Switch(self.bus.addr):
685-
for sub_map, (sub_pat, sub_ratio) in self.bus.memory_map.window_patterns():
683+
for sub_map, sub_name, (sub_pat, sub_ratio) in self.bus.memory_map.window_patterns():
686684
assert sub_ratio == 1
687685

688686
sub_bus = self._subs[sub_map]

amaranth_soc/csr/event.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ class EventMonitor(wiring.Component):
4242
CSR bus data width. See :class:`..csr.Interface`.
4343
alignment : int, power-of-2 exponent
4444
CSR address alignment. See :class:`..memory.MemoryMap`.
45-
name : str
46-
Window name. Optional. See :class:`..memory.MemoryMap`.
4745
4846
Attributes
4947
----------
@@ -75,9 +73,7 @@ def __init__(self, event_map, *, trigger="level", data_width, alignment=0, name=
7573
"src": Out(self._monitor.src.signature),
7674
"bus": In(self._mux.bus.signature),
7775
})
78-
self.bus.memory_map = MemoryMap(addr_width=addr_width, data_width=data_width,
79-
alignment=alignment, name=name)
80-
self.bus.memory_map.add_window(self._mux.bus.memory_map)
76+
self.bus.memory_map = self._mux.bus.memory_map
8177

8278
def elaborate(self, platform):
8379
m = Module()

amaranth_soc/csr/reg.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,6 @@ class Builder:
596596
Data width.
597597
granularity : :class:`int`
598598
Granularity. Optional, defaults to 8 bits.
599-
name : :class:`str`
600-
Name of the address range. Optional.
601599
602600
Raises
603601
------
@@ -609,10 +607,8 @@ class Builder:
609607
If ``granularity`` is not a positive integer.
610608
:exc:`ValueError`
611609
If ``granularity`` is not a divisor of ``data_width``
612-
:exc:`TypeError`
613-
If ``name`` is not a string, or is empty.
614610
"""
615-
def __init__(self, *, addr_width, data_width, granularity=8, name=None):
611+
def __init__(self, *, addr_width, data_width, granularity=8):
616612
if not isinstance(addr_width, int) or addr_width <= 0:
617613
raise TypeError(f"Address width must be a positive integer, not {addr_width!r}")
618614
if not isinstance(data_width, int) or data_width <= 0:
@@ -624,13 +620,9 @@ def __init__(self, *, addr_width, data_width, granularity=8, name=None):
624620
raise ValueError(f"Granularity {granularity} is not a divisor of data width "
625621
f"{data_width}")
626622

627-
if name is not None and not (isinstance(name, str) and name):
628-
raise TypeError(f"Name must be a non-empty string, not {name!r}")
629-
630623
self._addr_width = addr_width
631624
self._data_width = data_width
632625
self._granularity = granularity
633-
self._name = name
634626

635627
self._registers = dict()
636628
self._scope_stack = []
@@ -648,10 +640,6 @@ def data_width(self):
648640
def granularity(self):
649641
return self._granularity
650642

651-
@property
652-
def name(self):
653-
return self._name
654-
655643
def freeze(self):
656644
"""Freeze the builder.
657645
@@ -765,16 +753,13 @@ def Index(self, index):
765753

766754
def as_memory_map(self):
767755
self.freeze()
768-
memory_map = MemoryMap(addr_width=self.addr_width, data_width=self.data_width,
769-
name=self.name)
756+
memory_map = MemoryMap(addr_width=self.addr_width, data_width=self.data_width)
770757
for reg, reg_name, reg_offset in self._registers.values():
771758
if reg_offset is not None:
772759
reg_addr = (reg_offset * self.granularity) // self.data_width
773760
else:
774761
reg_addr = None
775762
reg_size = (reg.element.width + self.data_width - 1) // self.data_width
776-
# TBD: should integers be allowed inside resource names?
777-
reg_name = tuple(str(part) for part in reg_name)
778763
memory_map.add_resource(reg, name=reg_name, addr=reg_addr, size=reg_size,
779764
alignment=ceil_log2(reg_size))
780765
memory_map.freeze()

amaranth_soc/csr/wishbone.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class WishboneCSRBridge(wiring.Component):
2929
CSR bus driven by the bridge.
3030
data_width : int
3131
Wishbone bus data width. Optional. If ``None``, defaults to ``csr_bus.data_width``.
32-
name : str
33-
Window name. Optional. See :class:`..memory.MemoryMap`.
32+
name : :class:`..memory.MemoryMap.Name`
33+
Window name. Optional.
3434
3535
Attributes
3636
----------
@@ -59,10 +59,10 @@ def __init__(self, csr_bus, *, data_width=None, name=None):
5959
super().__init__({"wb_bus": In(wb_sig)})
6060

6161
self.wb_bus.memory_map = MemoryMap(addr_width=csr_bus.addr_width,
62-
data_width=csr_bus.data_width, name=name)
62+
data_width=csr_bus.data_width)
6363
# Since granularity of the Wishbone interface matches the data width of the CSR bus,
6464
# no width conversion is performed, even if the Wishbone data width is greater.
65-
self.wb_bus.memory_map.add_window(csr_bus.memory_map)
65+
self.wb_bus.memory_map.add_window(csr_bus.memory_map, name=name)
6666

6767
self._csr_bus = csr_bus
6868

amaranth_soc/gpio.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,6 @@ def __init__(self, pin_count):
237237
CSR bus address width.
238238
data_width : :class:`int`
239239
CSR bus data width.
240-
name : :class:`str`
241-
CSR bus window name. Optional.
242240
input_stages : :class:`int`
243241
Number of synchronization stages between pin inputs and the :class:`~Peripheral.Input`
244242
register. Optional. Defaults to ``2``.
@@ -259,13 +257,13 @@ def __init__(self, pin_count):
259257
:exc:`TypeError`
260258
If ``input_stages`` is not a non-negative integer.
261259
"""
262-
def __init__(self, *, pin_count, addr_width, data_width, name=None, input_stages=2):
260+
def __init__(self, *, pin_count, addr_width, data_width, input_stages=2):
263261
if not isinstance(pin_count, int) or pin_count <= 0:
264262
raise TypeError(f"Pin count must be a positive integer, not {pin_count!r}")
265263
if not isinstance(input_stages, int) or input_stages < 0:
266264
raise TypeError(f"Input stages must be a non-negative integer, not {input_stages!r}")
267265

268-
regs = csr.Builder(addr_width=addr_width, data_width=data_width, name=name)
266+
regs = csr.Builder(addr_width=addr_width, data_width=data_width)
269267

270268
self._mode = regs.add("Mode", self.Mode(pin_count))
271269
self._input = regs.add("Input", self.Input(pin_count))

0 commit comments

Comments
 (0)