Skip to content

Commit 2d3d176

Browse files
committed
Revert "wishbone: restrict addr_width to positive integers."
This reverts commit 1b25700. Wishbone bus interfaces with 0-bit address widths are explicitly allowed by the specification, and may occur in some cases such as peripherals with FIFO-like interfaces.
1 parent 9ffaf94 commit 2d3d176

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

amaranth_soc/wishbone/bus.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def check_parameters(cls, *, addr_width, data_width, granularity, features):
183183
Raises
184184
------
185185
:exc:`TypeError`
186-
If ``addr_width`` is not an integer greater than to 0.
186+
If ``addr_width`` is not an integer greater than or equal to 0.
187187
:exc:`ValueError`
188188
If ``data_width`` is not 8, 16, 32 or 64.
189189
:exc:`ValueError`
@@ -193,8 +193,8 @@ def check_parameters(cls, *, addr_width, data_width, granularity, features):
193193
:exc:`ValueError`
194194
If ``features`` contains other values than :class:`Feature` members.
195195
"""
196-
if not isinstance(addr_width, int) or addr_width <= 0:
197-
raise TypeError(f"Address width must be a positive integer, not {addr_width!r}")
196+
if not isinstance(addr_width, int) or addr_width < 0:
197+
raise TypeError(f"Address width must be a non-negative integer, not {addr_width!r}")
198198
if data_width not in (8, 16, 32, 64):
199199
raise ValueError(f"Data width must be one of 8, 16, 32, 64, not {data_width!r}")
200200
if granularity not in (8, 16, 32, 64):

tests/test_wishbone_bus.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,45 +105,45 @@ def test_eq(self):
105105

106106
def test_wrong_addr_width(self):
107107
with self.assertRaisesRegex(TypeError,
108-
r"Address width must be a positive integer, not 0"):
109-
wishbone.Signature(addr_width=0, data_width=8)
108+
r"Address width must be a non-negative integer, not -1"):
109+
wishbone.Signature(addr_width=-1, data_width=8)
110110
with self.assertRaisesRegex(TypeError,
111-
r"Address width must be a positive integer, not 0"):
112-
wishbone.Signature.check_parameters(addr_width=0, data_width=8, granularity=8,
111+
r"Address width must be a non-negative integer, not -1"):
112+
wishbone.Signature.check_parameters(addr_width=-1, data_width=8, granularity=8,
113113
features=())
114114

115115
def test_wrong_data_width(self):
116116
with self.assertRaisesRegex(ValueError,
117117
r"Data width must be one of 8, 16, 32, 64, not 7"):
118-
wishbone.Signature(addr_width=1, data_width=7)
118+
wishbone.Signature(addr_width=0, data_width=7)
119119
with self.assertRaisesRegex(ValueError,
120120
r"Data width must be one of 8, 16, 32, 64, not 7"):
121-
wishbone.Signature.check_parameters(addr_width=1, data_width=7, granularity=7,
121+
wishbone.Signature.check_parameters(addr_width=0, data_width=7, granularity=7,
122122
features=())
123123

124124
def test_wrong_granularity(self):
125125
with self.assertRaisesRegex(ValueError,
126126
r"Granularity must be one of 8, 16, 32, 64, not 7"):
127-
wishbone.Signature(addr_width=1, data_width=32, granularity=7)
127+
wishbone.Signature(addr_width=0, data_width=32, granularity=7)
128128
with self.assertRaisesRegex(ValueError,
129129
r"Granularity must be one of 8, 16, 32, 64, not 7"):
130-
wishbone.Signature.check_parameters(addr_width=1, data_width=32, granularity=7,
130+
wishbone.Signature.check_parameters(addr_width=0, data_width=32, granularity=7,
131131
features=())
132132

133133
def test_wrong_granularity_wide(self):
134134
with self.assertRaisesRegex(ValueError,
135135
r"Granularity 32 may not be greater than data width 8"):
136-
wishbone.Signature(addr_width=1, data_width=8, granularity=32)
136+
wishbone.Signature(addr_width=0, data_width=8, granularity=32)
137137
with self.assertRaisesRegex(ValueError,
138138
r"Granularity 32 may not be greater than data width 8"):
139-
wishbone.Signature.check_parameters(addr_width=1, data_width=8, granularity=32,
139+
wishbone.Signature.check_parameters(addr_width=0, data_width=8, granularity=32,
140140
features=())
141141

142142
def test_wrong_features(self):
143143
with self.assertRaisesRegex(ValueError, r"'foo' is not a valid Feature"):
144-
wishbone.Signature(addr_width=1, data_width=8, features={"foo"})
144+
wishbone.Signature(addr_width=0, data_width=8, features={"foo"})
145145
with self.assertRaisesRegex(ValueError, r"'foo' is not a valid Feature"):
146-
wishbone.Signature.check_parameters(addr_width=1, data_width=8, granularity=8,
146+
wishbone.Signature.check_parameters(addr_width=0, data_width=8, granularity=8,
147147
features={"foo"})
148148

149149
def test_set_map(self):
@@ -203,15 +203,15 @@ def test_map(self):
203203
self.assertIs(iface.memory_map, memory_map)
204204

205205
def test_get_map_none(self):
206-
iface = wishbone.Interface(addr_width=1, data_width=8, path=("iface",))
206+
iface = wishbone.Interface(addr_width=0, data_width=8, path=("iface",))
207207
with self.assertRaisesRegex(AttributeError,
208208
r"wishbone.Signature\(.*\) does not have a memory map"):
209209
iface.memory_map
210210

211211
def test_wrong_map(self):
212212
with self.assertRaisesRegex(TypeError,
213213
r"Memory map must be an instance of MemoryMap, not 'foo'"):
214-
wishbone.Interface(addr_width=1, data_width=8, memory_map="foo")
214+
wishbone.Interface(addr_width=0, data_width=8, memory_map="foo")
215215

216216
def test_wrong_map_data_width(self):
217217
with self.assertRaisesRegex(ValueError,

0 commit comments

Comments
 (0)