2 from ..hdl
.rec
import *
5 __all__
= ["pin_layout", "Pin"]
8 def pin_layout(width
, dir, xdr
=0):
10 Layout of the platform interface of a pin or several pins, which may be used inside
13 See :class:`Pin` for details.
15 if not isinstance(width
, int) or width
< 1:
16 raise TypeError("Width must be a positive integer, not {!r}"
18 if dir not in ("i", "o", "oe", "io"):
19 raise TypeError("Direction must be one of \"i\", \"o\", \"io\", or \"oe\", not {!r}"""
21 if not isinstance(xdr, int) or xdr < 0:
22 raise TypeError("Gearing ratio must be a non
-negative integer
, not {!r
}"
26 if dir in ("i
", "io
"):
28 fields.append(("i_clk
", 1))
30 fields.append(("i
", width))
33 fields.append(("i
{}".format(n), width))
34 if dir in ("o
", "oe
", "io
"):
36 fields.append(("o_clk
", 1))
38 fields.append(("o
", width))
41 fields.append(("o
{}".format(n), width))
42 if dir in ("oe
", "io
"):
43 fields.append(("oe
", 1))
49 An interface to an I/O buffer or a group of them that provides uniform access to input, output,
50 or tristate buffers that may include a 1:n gearbox. (A 1:2 gearbox is typically called "DDR
".)
52 A :class:`Pin` is identical to a :class:`Record` that uses the corresponding :meth:`pin_layout`
53 except that it allos accessing the parameters like ``width`` as attributes. It is legal to use
54 a plain :class:`Record` anywhere a :class:`Pin` is used, provided that these attributes are
60 Width of the ``i``/``iN`` and ``o``/``oN`` signals.
61 dir : ``"i
"``, ``"o
"``, ``"io
"``, ``"oe
"``
62 Direction of the buffers. If ``"i
"`` is specified, only the ``i``/``iN`` signals are
63 present. If ``"o
"`` is specified, only the ``o``/``oN`` signals are present. If ``"oe
"`` is
64 specified, the ``o``/``oN`` signals are present, and an ``oe`` signal is present.
65 If ``"io
"`` is specified, both the ``i``/``iN`` and ``o``/``oN`` signals are present, and
66 an ``oe`` signal is present.
68 Gearbox ratio. If equal to 0, the I/O buffer is combinatorial, and only ``i``/``o``
69 signals are present. If equal to 1, the I/O buffer is SDR, and only ``i``/``o`` signals are
70 present. If greater than 1, the I/O buffer includes a gearbox, and ``iN``/``oN`` signals
71 are present instead, where ``N in range(0, N)``. For example, if ``xdr=2``, the I/O buffer
72 is DDR; the signal ``i0`` reflects the value at the rising edge, and the signal ``i1``
73 reflects the value at the falling edge.
75 Name of the underlying record.
80 I/O buffer input clock. Synchronizes `i*`. Present if ``xdr`` is nonzero.
82 I/O buffer input, without gearing. Present if ``dir="i
"`` or ``dir="io
"``, and ``xdr`` is
84 i0, i1, ... : Signal, out
85 I/O buffer inputs, with gearing. Present if ``dir="i
"`` or ``dir="io
"``, and ``xdr`` is
88 I/O buffer output clock. Synchronizes `o*`, including `oe`. Present if ``xdr`` is nonzero.
90 I/O buffer output, without gearing. Present if ``dir="o
"`` or ``dir="io
"``, and ``xdr`` is
92 o0, o1, ... : Signal, in
93 I/O buffer outputs, with gearing. Present if ``dir="o
"`` or ``dir="io
"``, and ``xdr`` is
96 I/O buffer output enable. Present if ``dir="io
"`` or ``dir="oe
"``. Buffers generally
97 cannot change direction more than once per cycle, so at most one output enable signal
100 def __init__(self, width, dir, *, xdr=0, name=None, src_loc_at=0):
105 super().__init__(pin_layout(self.width, self.dir, self.xdr),
106 name=name, src_loc_at=src_loc_at + 1)