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), or "X" when it is unknown.

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

is_output

is_output() -> bool

Return True if this port is an output port

has_driver abstractmethod

has_driver() -> bool

Return True if port has driver

get_driver

get_driver() -> Port | None

Get port driver

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

Exceptions

PortConnectionError

Bases: DigsimException

Exception for illegal connections