Ports¶
The ports of a component are attributes with the name of the port, like gate.A and
gate.Y. Connect an output to an input with output.wire = input, and read or set a value
with port.value, either 0 or 1 (or a number for a bus), "X" when it is unknown, or "Z"
when it is not driven (high impedance).
Several outputs can drive the same input (see get_drivers()). The input has the value
that they drive, and "X" when they drive different values. A tristate port (see
set_tristate()), like the output of TristateBuffer, is "Z" when it doesn't drive, and
then the other drivers decide. When none drives, the input is "Z". An inout port
(PortInOut), like an inout port of a Verilog component, is both: it drives the ports it
is wired to, and other ports can drive it.
All port classes have the methods of Port. The other classes are used to write
your own components: they decide how a port updates its component and
the ports it drives.
Port
¶
Port(
parent: Component,
name: str,
width: int = 1,
output: bool = False,
)
Bases: ABC
The abstract base class for all ports
is_inout
¶
is_inout() -> bool
Return True if this port is bidirectional, an inout port: both an output and an input (see PortInOut)
set_tristate
¶
set_tristate(tristate: bool = True) -> None
Let the port drive "Z" (high impedance), when it doesn't drive its wires
is_tristate
¶
is_tristate() -> bool
Can the port drive "Z" (high impedance), when it doesn't drive its wires
is_rising_edge
¶
is_rising_edge() -> bool
Return True if a rising edge has occurred Note: This function can only be called once per 'update'
is_falling_edge
¶
is_falling_edge() -> bool
Return True if a falling edge has occurred Note: This function can only be called once per 'update'
PortIn
¶
PortIn(parent: Component, name: str, width: int = 1)
Bases: PortWire
The PortIn class: * The port wire will instantaneously update the driven wires upon change. * The port will update the parent component upon change.
PortWire
¶
PortWire(
parent: Component,
name: str,
width: int = 1,
output: bool = False,
)
Bases: Port
The PortWire class: * The port wire will instantaneously update the driven wires upon change.
PortOutDelta
¶
PortOutDelta(
parent: Component,
name: str,
width: int = 1,
delay_ns: int = 1,
)
Bases: Port
The PortOutDelta class: * The port wire will update the driven wires after a delta cycle. * The port will update the parent component if the _update_parent variable is set to true.
PortOutImmediate
¶
PortOutImmediate(
parent: Component, name: str, width: int = 1
)
Bases: PortOutDelta
The PortOutImmediate class: * A special version of the PortOutDelta used for direct components (button/switch/value) * The port driver will update the driven wires immediately * The port will update the parent component if the _update_parent variable is set to true.
PortMultiBitWire
¶
PortMultiBitWire(
parent: Component,
name: str,
width: int,
output: bool = False,
)
PortInOut
¶
PortInOut(parent: Component, name: str, width: int = 1)
Bases: Port
A bidirectional port of one or more bits, like an inout port of a Verilog module.
Like an output, it drives the ports it is wired to with what its component drives on it, "Z" (not driven) while the component doesn't. Like an input, other ports can drive it. The component reads the value of the wire, at each bit what it drives itself resolved with what the other ports drive (see resolve()), and only that is "X" when they drive different values.
The bits that the component drives are the drive bits, get_drive_bit(), and the bits it reads are get_bit(). The value of the port is what it drives, as for a tristate output, and read_value() is the value of the wire. A word of which only some bits are driven is "X" for the ports it drives.
Two inout ports on the same wire drive each other: a.wire = b and b.wire = a.
read_value
¶
read_value() -> VALUE_TYPE
The value of the wire, what the port drives resolved with what the other ports drive: "X" if they drive different values, or only some bits of a word are driven
Exceptions¶
PortConnectionError
¶
Bases: DigsimException
Exception for illegal connections