11
11
12
12
13
13
class Element (wiring .PureInterface ):
14
- """Peripheral-side CSR interface.
14
+ """CSR register interface.
15
15
16
16
A low-level interface to a single atomically readable and writable register in a peripheral.
17
17
This interface supports any register width and semantics, provided that both reads and writes
@@ -24,7 +24,7 @@ class Element(wiring.PureInterface):
24
24
access : :class:`Element.Access`
25
25
Register access mode.
26
26
path : iterable of :class:`str`
27
- Path to this CSR interface. Optional. See :class:`amaranth.lib.wiring.PureInterface`.
27
+ Path to this interface. Optional. See :class:`amaranth.lib.wiring.PureInterface`.
28
28
"""
29
29
30
30
class Access (enum .Enum ):
@@ -33,8 +33,14 @@ class Access(enum.Enum):
33
33
Coarse access mode for the entire register. Individual fields can have more restrictive
34
34
access mode, e.g. R/O fields can be a part of an R/W register.
35
35
"""
36
+
37
+ #: Read-only mode.
36
38
R = "r"
39
+
40
+ #: Write-only mode.
37
41
W = "w"
42
+
43
+ #: Read/write mode.
38
44
RW = "rw"
39
45
40
46
def readable (self ):
@@ -43,7 +49,7 @@ def readable(self):
43
49
Returns
44
50
-------
45
51
:class:`bool`
46
- ``True`` if `self` is equal to :attr:`R` or :attr:`RW`.
52
+ ``True`` if equal to :attr:`R` or :attr:`RW`.
47
53
"""
48
54
return self == self .R or self == self .RW
49
55
@@ -53,12 +59,12 @@ def writable(self):
53
59
Returns
54
60
-------
55
61
:class:`bool`
56
- ``True`` if `self` is equal to :attr:`W` or :attr:`RW`.
62
+ ``True`` if equal to :attr:`W` or :attr:`RW`.
57
63
"""
58
64
return self == self .W or self == self .RW
59
65
60
66
class Signature (wiring .Signature ):
61
- """Peripheral-side CSR signature.
67
+ """CSR register signature.
62
68
63
69
Arguments
64
70
---------
@@ -179,7 +185,7 @@ def __repr__(self):
179
185
180
186
181
187
class Signature (wiring .Signature ):
182
- """CPU-side CSR signature.
188
+ """CSR bus signature.
183
189
184
190
Arguments
185
191
---------
@@ -272,22 +278,10 @@ def __repr__(self):
272
278
273
279
274
280
class Interface (wiring .PureInterface ):
275
- """CPU-side CSR interface.
281
+ """CSR bus interface.
276
282
277
283
A low-level interface to a set of atomically readable and writable peripheral CSR registers.
278
284
279
- .. note::
280
-
281
- CSR registers mapped to the CSR bus are split into chunks according to the bus data width.
282
- Each chunk is assigned a consecutive address on the bus. This allows accessing CSRs of any
283
- size using any datapath width.
284
-
285
- When the first chunk of a register is read, the value of a register is captured, and reads
286
- from subsequent chunks of the same register return the captured values. When any chunk
287
- except the last chunk of a register is written, the written value is captured; a write to
288
- the last chunk writes the captured value to the register. This allows atomically accessing
289
- CSRs larger than datapath width.
290
-
291
285
Arguments
292
286
---------
293
287
addr_width : :class:`int`
@@ -326,11 +320,15 @@ def data_width(self):
326
320
def memory_map (self ):
327
321
"""Memory map of the bus.
328
322
329
- .. todo:: setter
330
-
331
323
Returns
332
324
-------
333
325
:class:`~.memory.MemoryMap` or ``None``
326
+
327
+ Raises
328
+ ------
329
+ :exc:`ValueError`
330
+ If set to a memory map that does not have the same address and data widths as the bus
331
+ interface.
334
332
"""
335
333
if self ._memory_map is None :
336
334
raise AttributeError (f"{ self !r} does not have a memory map" )
@@ -357,39 +355,33 @@ class Multiplexer(wiring.Component):
357
355
358
356
An address-based multiplexer for CSR registers implementing atomic updates.
359
357
360
- This implementation assumes the following from the CSR bus:
361
-
362
- * an initiator must have exclusive ownership over the multiplexer for the full duration of
363
- a register transaction;
364
- * an initiator must access a register in ascending order of addresses, but it may abort a
365
- transaction after any bus cycle.
366
-
367
358
Writes are registered, and are performed 1 cycle after ``w_stb`` is asserted.
368
359
369
360
.. note::
370
361
371
- Because the CSR bus conserves logic and routing resources, it is common to e.g. access
372
- a CSR bus with an *n*-bit data path from a CPU with a *k*-bit datapath (*k>n*) in cases
373
- where CSR access latency is less important than resource usage.
374
-
375
- In this case, two strategies are possible for connecting the CSR bus to the CPU:
376
-
377
- * The CPU could access the CSR bus directly (with no intervening logic other than
378
- simple translation of control signals). In this case, the register alignment should
379
- be set to 1 (i.e. ``memory_map.alignment`` should be set to 0), and each *w*-bit
380
- register would occupy *ceil(w/n)* addresses from the CPU perspective, requiring the
381
- same amount of memory instructions to access.
382
- * The CPU could also access the CSR bus through a width down-converter, which would
383
- issue *k/n* CSR accesses for each CPU access. In this case, the register alignment
384
- should be set to *k/n*, and each *w*-bit register would occupy *ceil(w/k)* addresses
385
- from the CPU perspective, requiring the same amount of memory instructions to access.
386
-
387
- If the register alignment (i.e. ``2 ** memory_map.alignment``) is greater than 1, it affects
388
- which CSR bus write is considered a write to the last register chunk. For example, if a 24-bit
389
- register is used with a 8-bit CSR bus and a CPU with a 32-bit datapath, a write to this
390
- register requires 4 CSR bus writes to complete, and the 4th write is the one that actually
391
- writes the value to the register. This allows determining write latency solely from the amount
392
- of addresses the register occupies in the CPU address space, and the width of the CSR bus.
362
+ Because the CSR bus conserves logic and routing resources, it is common to e.g. bridge a CSR
363
+ bus with a narrow *N*-bit datapath to a CPU with a wider *W*-bit datapath (*W>N*) in cases
364
+ where CSR access latency is less important than resource usage.
365
+
366
+ In this case, two strategies are possible for connecting the CSR bus to the CPU:
367
+
368
+ * The CPU could access the CSR bus directly (with no intervening logic other than simple
369
+ translation of control signals). The register alignment should be set to 1 (i.e.
370
+ ``memory_map.alignment`` should be 0), and each *R*-bit register would occupy
371
+ *ceil(R/N)* addresses from the CPU perspective, requiring the same amount of memory
372
+ instructions to access.
373
+
374
+ * The CPU could access the CSR bus through a width down-converter, which would issue
375
+ *W/N* CSR accesses for each CPU access. The register alignment should be set to *W/N*,
376
+ and each *R*-bit register would occupy *ceil(R/K)* addresses from the CPU perspective,
377
+ requiring the same amount of memory instructions to access.
378
+
379
+ If the register alignment is greater than 1, it affects which CSR bus write is considered a
380
+ write to the last register chunk. For example, if a 24-bit register is accessed through an
381
+ 8-bit CSR bus and a CPU with a 32-bit datapath, a write to this register requires 4 CSR bus
382
+ writes to complete, and the last write is the one that actually writes the value to the
383
+ register. This allows determining write latency solely from the amount of addresses occupied
384
+ by the register in the CPU address space, and the CSR bus data width.
393
385
394
386
Arguments
395
387
---------
@@ -681,19 +673,6 @@ class Decoder(wiring.Component):
681
673
682
674
An address decoder for subordinate CSR buses.
683
675
684
- .. note::
685
-
686
- Although there is no functional difference between adding a set of registers directly to
687
- a :class:`Multiplexer` and adding a set of registers to multiple :class:`Multiplexer`\\ s
688
- that are aggregated with a :class:`Decoder`, hierarchical CSR buses are useful for
689
- organizing a hierarchical design.
690
-
691
- If many peripherals are directly served by a single :class:`Multiplexer`, a very large
692
- amount of ports will connect the peripheral registers with the :class:`Decoder`, and the
693
- cost of decoding logic would not be attributed to specific peripherals. With a
694
- :class:`Decoder`, only five signals per peripheral will be used, and the logic could be
695
- kept together with the peripheral.
696
-
697
676
Arguments
698
677
---------
699
678
addr_width : :class:`int`
@@ -733,8 +712,6 @@ def add(self, sub_bus, *, addr=None):
733
712
734
713
See :meth:`~.memory.MemoryMap.add_window` for details.
735
714
736
- .. todo:: include exceptions raised in :meth:`~.memory.MemoryMap.add_window`
737
-
738
715
Returns
739
716
-------
740
717
:class:`tuple` of (:class:`int`, :class:`int`, :class:`int`)
0 commit comments