You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/csr/action.rst
+63-6
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,76 @@
1
-
CSR field actions
2
-
-----------------
1
+
CSR fields
2
+
----------
3
3
4
-
.. warning::
4
+
.. py:module:: amaranth_soc.csr.action
5
5
6
-
This manual is a work in progress and is seriously incomplete!
6
+
The :mod:`amaranth_soc.csr.action` module provides built-in :class:`~amaranth_soc.csr.reg.FieldAction` implementations intended for common use cases, which are split in three categories: :ref:`basic fields <csr-action-basic>` for numerical values, :ref:`flag fields <csr-action-flag>` for arrays of bits, and :ref:`reserved fields <csr-action-reserved>` to serve as placeholders for compatibility.
7
7
8
-
.. py:module:: amaranth_soc.csr.action
8
+
.. _csr-action-basic:
9
9
10
-
The :mod:`amaranth_soc.csr.action` module provides built-in CSR field actions.
10
+
Basic fields
11
+
============
12
+
13
+
Such fields are either exclusively writable by a CSR bus initiator (e.g. :class:`W`, :class:`RW`) or the peripheral itself (e.g. :class:`R`). This effectively removes the possibility of a write conflict between a CSR bus initiator and the peripheral.
11
14
12
15
.. autoclass:: R()
13
16
.. autoclass:: W()
14
17
.. autoclass:: RW()
18
+
19
+
.. _csr-action-flag:
20
+
21
+
Flag fields
22
+
===========
23
+
24
+
Flag fields may be concurrently written by a CSR bus initiator and the peripheral. Each bit of a flag field may be set or cleared independently of others.
25
+
26
+
Suggested use cases
27
+
+++++++++++++++++++
28
+
29
+
- :class:`RW1C` flags may be used when a peripheral needs to notify the CPU of a given condition, such as an error or a pending interrupt. To acknowledge the notification, the CPU would then write 1 to the flag bit.
30
+
31
+
- :class:`RW1S` flags may be used for self-clearing bits, such as the enable bit of a one-shot timer. When the timer reaches its maximum value, it would automatically disable itself by clearing its enable bit.
32
+
33
+
- A pair of :class:`RW1C` and :class:`RW1S` flags may be used to target the same range of bits (e.g. that drives an array of GPIO pins). This allows a CSR bus initiator to set and clear bits in one write transaction (which is guaranteed to be atomic). If a single :class:`RW` field was used instead, a read-modify-write transaction would be needed, and would require locking to insure its atomicity in a multi-tasked environment.
34
+
15
35
.. autoclass:: RW1C()
16
36
.. autoclass:: RW1S()
37
+
38
+
.. _csr-action-reserved:
39
+
40
+
Reserved fields
41
+
===============
42
+
43
+
Reserved fields may be defined to provide placeholders for past, future or undocumented functions of a peripheral.
44
+
45
+
Suggested use cases
46
+
+++++++++++++++++++
47
+
48
+
Reserved for future use (as value)
49
+
..................................
50
+
51
+
A :class:`ResRAWL` field can be used as a placeholder to ensure forward compatibility of software binaries with future SoC revisions, where it may be replaced with a :ref:`basic field <csr-action-basic>`.
52
+
53
+
The value returned by reads (and written back) must have defined semantics (e.g. a no-op) that can be relied upon in future SoC revisions. When writing to this field, software drivers targeting the current SoC revision must set up an atomic read-modify-write transaction.
54
+
55
+
Reserved for future use (as flag)
56
+
.................................
57
+
58
+
If a field is expected to be implemented as a :ref:`flag <csr-action-flag>` in a future SoC revision, it can be defined as a :class:`ResRAW0` field in the current revision to ensure forward compatibility of software binaries.
59
+
60
+
Software drivers targeting the current SoC revision should ignore the value returned by reads. Writing a value of 0 must be a no-op if the field is implemented in a future SoC revision.
61
+
62
+
Defined but deprecated
63
+
......................
64
+
65
+
If a field was deprecated in a previous SoC revision, it can be replaced with a :class:`ResR0WA` field to ensure backward compatibility of software binaries.
66
+
67
+
The value of 0 returned by reads (and written back) must retain the semantics defined in the SoC revision where this field was deprecated.
68
+
69
+
Defined but unimplemented
70
+
.........................
71
+
72
+
If a field is only implemented in some variants of a peripheral, it can be replaced by a :class:`ResR0W0` field in the others.
Copy file name to clipboardExpand all lines: docs/csr/bus.rst
+27-18
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,17 @@ The :mod:`amaranth_soc.csr.bus` module contains primitives to implement and acce
19
19
Introduction
20
20
============
21
21
22
-
The CSR bus API provides unopinionated primitives for defining and connecting the *Control and Status Registers* of SoC peripherals, with an emphasis on safety and resource efficiency. It is composed of low-level :ref:`register interfaces <csr-bus-element>`, :ref:`register multiplexers <csr-bus-multiplexer>` that provide access to the registers of a peripheral, and :ref:`bus decoders <csr-bus-decoder>` that provide access to the registers of multiple peripherals.
22
+
Overview
23
+
++++++++
24
+
25
+
The CSR bus API provides unopinionated primitives for defining and connecting the *Control and Status Registers* of SoC peripherals, with an emphasis on safety and resource efficiency. It is composed of low-level :ref:`register interfaces <csr-bus-element>`, :ref:`multiplexers <csr-bus-multiplexer>` that provide access to the registers of a peripheral, and :ref:`bus decoders <csr-bus-decoder>` that provide access to subordinate bus interfaces.
26
+
27
+
This diagram shows a CSR bus decoder being used to provide access to the registers of two peripherals:
28
+
29
+
.. image:: _images/csr-bus.png
30
+
31
+
Examples
32
+
========
23
33
24
34
.. _csr-bus-element:
25
35
@@ -93,16 +103,15 @@ The following example shows a very basic timer peripheral with an 8-bit CSR bus
Registers are always accessed atomically, regardless of their size. Each register is split into chunks according to the CSR bus data width, and each chunk is assigned a consecutive address on the bus.
@@ -264,28 +273,28 @@ In the following example, a CSR decoder provides access to the registers of two
Although there is no functional difference between adding a group of registers directly to a :class:`Multiplexer` and adding them to multiple :class:`Multiplexer`\ s that are aggregated with a :class:`Decoder`, hierarchical CSR buses are useful for organizing a hierarchical design.
284
293
285
294
If many peripherals are directly served by a single :class:`Multiplexer`, a very large amount of ports will connect the peripheral registers to the multiplexer, and the cost of decoding logic would not be attributed to specific peripherals. With a :class:`Decoder`, only five signals per peripheral will be used, and the logic could be kept together with the peripheral.
0 commit comments