Skip to content

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

value property writable

value: VALUE_TYPE

Get the value of the port, can be "X"

width property

width: int

Get the bit-width of the port

wire property writable

wire: NoReturn

Need a property if to be able to have a setter...

wired_ports property

wired_ports: list[Port]

Get the ports that this port drives

name

name() -> str

Get port name

parent

parent() -> Component

Get parent component

path

path() -> str

Get port path, ...

is_input

is_input() -> bool

Return True if this port is an input port (or an inout port)

is_output

is_output() -> bool

Return True if this port is an output port

is_inout

is_inout() -> bool

Return True if this port is bidirectional, an inout port: both an output and an input (see PortInOut)

has_driver abstractmethod

has_driver() -> bool

Return True if port has driver

get_driver

get_driver() -> Port | None

Get port driver

get_drivers

get_drivers() -> list[Port]

The ports that drive this port: none, one, or several

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

disconnect

disconnect(port: Port) -> None

Disconnect 'port' if this port drives it

remove_wires

remove_wires() -> None

Remove wires port

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'

strval

strval() -> str

Return value as string

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.

update_parent

update_parent(update_parent: bool) -> None

Set if the port updates its parent when it changes

set_delay_ns

set_delay_ns(delay_ns: int) -> None

Set port propagation delay

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,
)

Bases: Port

The PortMultiBitWire class is used when several bits should be collected into a multi bit bus port. The PortMultiBitWire will add events to the circuit upon change to update vcd output.

get_bit

get_bit(bit_id: int) -> Port

Get bit port

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

get_bit

get_bit(bit_id: int) -> Port

The bit of the wire that the component reads, it drives the ports of the component

get_drive_bit

get_drive_bit(bit_id: int) -> Port

The bit that the component drives, ports of the component are wired to it

Exceptions

PortConnectionError

Bases: DigsimException

Exception for illegal connections