skidl.bus module

Bus management in SKiDL.

This module provides the Bus class for creating and managing collections of related nets. Buses can be indexed to access individual nets, sliced to access multiple nets, interconnected with pins and other buses, and copied to create multiple instances. Buses are essential for handling multi-bit signals like data paths or address lines.

class skidl.bus.Bus(*args, **attribs)[source]

Bases: SkidlBaseObject

A collection of related nets that can be indexed and connected as a group.

Bus objects group nets to represent multi-bit signals like data buses, address buses, or other related collections of signals. Buses can be created from integer widths, existing nets, pins, or other buses. Individual nets in a bus can be accessed using integer indices, slices, or net names.

Parameters:
  • name (str, optional) – The name of the bus. If None, an implicit name will be generated.

  • *args – Various objects to create bus from - can include integers (for width), pins, nets, or other buses.

Keyword Arguments:
  • circuit (Circuit, optional) – The Circuit object this bus belongs to.

  • attribs – Various attributes to attach to the bus.

Examples

>>> data_bus = Bus('DATA', 8)  # Create 8-bit DATA bus
>>> addr_bus = Bus('ADDR', 16)  # Create 16-bit ADDR bus
>>> data_bus[0] += some_pin  # Connect a pin to bit 0
>>> byte_bus = data_bus[7:0]  # Create a slice of the bus
connect(*pins_nets_buses)[source]

Connect pins, nets, or buses to this bus.

Parameters:

*pins_nets_buses – Pins, nets, buses or lists/tuples of them to connect.

Returns:

The updated bus with the new connections.

Return type:

Bus

Examples

>>> b = Bus('B', 2)
>>> p = Pin()
>>> n = Net()
>>> b += p, n  # Connect pin to B[0] and net to B[1]
copy(num_copies=None, circuit=None, **attribs)[source]

Create one or more copies of this bus.

Parameters:
  • num_copies (int, optional) – Number of copies to create. If None, a single copy will be made.

  • circuit (Circuit, optional) – The circuit the copies will be added to.

  • **attribs – Attributes for the copies. If values are lists/tuples, each copy gets the corresponding value.

Returns:

A single Bus copy or list of copies.

Return type:

Bus or list[Bus]

Raises:

ValueError – If num_copies is not a non-negative integer.

Examples

>>> b = Bus('A', 8)
>>> b_copy = b(2)  # Get two copies
>>> b_array = 5 * Bus('A', 8)  # Create an array of 5 buses
extend(*objects)[source]

Extend the bus by adding nets to the end (MSB).

Parameters:

*objects – Objects to add - integers, nets, pins, or buses.

classmethod fetch(name, *args, **attribs)[source]

Get a bus by name from a circuit, or create it if it doesn’t exist.

This method is similar to get(), but will create a new bus if one with the given name is not found.

Parameters:
  • name (str) – Name of the bus to fetch or create.

  • *args – Arguments to pass to the Bus constructor if creation is needed.

  • **attribs – Keyword arguments to pass to the Bus constructor if creation is needed.

Returns:

An existing or newly created bus.

Return type:

Bus

classmethod get(name, circuit=None)[source]

Get a bus by name from a circuit.

Parameters:
  • name (str) – Name or alias of the bus to find.

  • circuit (Circuit, optional) – Circuit to search in. Defaults to default_circuit.

Returns:

The found bus object or None if not found.

Return type:

Bus or None

get_nets()[source]

Return the list of nets contained in this bus.

Returns:

Nets in this bus.

Return type:

list[Net]

get_pins()[source]

Raise an error since accessing all pins across a bus is not supported.

Raises:

Exception – Always raises an error.

insert(index, *objects)[source]

Insert objects into the bus starting at the given index.

Objects can be integers (to create N new nets), existing nets, pins, or buses. New nets will be given names based on the bus name and their position.

Parameters:
  • index (int) – Position to insert objects.

  • *objects – Objects to insert - integers, nets, pins, or buses.

Raises:

ValueError – If an unsupported object type is inserted.

is_implicit()[source]

Check if the bus name is implicitly generated.

Implicit bus names start with the BUS_PREFIX or NET_PREFIX.

Returns:

True if the bus has an implicitly generated name.

Return type:

bool

is_movable()[source]

Check if the bus can be moved to another circuit.

A bus is movable if all of its nets are movable.

Returns:

True if all nets in the bus are movable.

Return type:

bool

property name

Get the name of the bus.

When setting the name, if another bus with the same name exists in the circuit, the name will be adjusted to make it unique.

Returns:

The bus name.

Return type:

str

property netclasses
property pins

Get all pins connected to the bus.

Returns:

List of pins connected to the bus nets.

Return type:

list

Raises:

Exception – Always raises an error since accessing all pins across a bus is not supported.

propagate_netclasses()[source]
property width

Get the width of the bus (number of nets).

Returns:

The number of nets in the bus.

Return type:

int