DataPortInterface<LogicType extends Logic> class

An interface to a simple memory that only needs enable, address, and data.

Can be used for either read or write direction by grouping signals using DataPortGroup. For a write port, drive en, addr, and data. For a read port, drive en and addr and consume data from the memory.

In a structural design, connect the ports to existing signals with <=:

final write = DataPortInterface<Logic>(32, 5);
final read = DataPortInterface<Logic>(32, 5);
RegisterFile<Logic>(clk, reset, [write], [read], numEntries: 20);

write.en <= writeEnable;
write.addr <= writeAddress;
write.data <= writeData;
read.en <= readEnable;
read.addr <= readAddress;
final readData = read.data;

Here clk, reset, and the request signals are supplied by the surrounding design. The address signals are 5 bits wide and the data signals are 32 bits wide. RegisterFile writes on the clock edge and reads combinationally when the read port is enabled.

In a testbench, drive values instead of connecting hardware signals:

final clk = Logic()..put(0);
final reset = Logic()..put(0);
final write = DataPortInterface<Logic>(32, 5);
final read = DataPortInterface<Logic>(32, 5);
final memory =
    RegisterFile<Logic>(clk, reset, [write], [read], numEntries: 20);
await memory.build();

write.en.put(1);
write.addr.put(3);
write.data.put(0xdeadbeef);
read.en.put(1);
read.addr.put(3);
await Simulator.tick();
clk.inject(1);
await Simulator.tick();
clk.inject(0);
await Simulator.tick();
assert(read.data.value == LogicValue.ofInt(0xdeadbeef, 32));

Other memory implementations can have different read latency and reset behavior. Use DataPortInterface.typed for a structured or otherwise specialized payload, and MaskedDataPortInterface for byte-enabled writes.

Inheritance
Implementers

Constructors

DataPortInterface(int dataWidth, int addrWidth)
Constructs a new interface of specified dataWidth and addrWidth for interacting with a memory in either the read or write direction.
DataPortInterface.typed(LogicType data, int addrWidth)
Constructs a memory port with a type-preserving clone of data.

Properties

addr → Logic
The "address" bit for a request when en is high.
no setter
addrWidth → int
The width of addresses in the memory.
final
data → LogicType
The data sent or received with the associated request.
no setter
dataWidth → int
The width of data in the memory.
final
en → Logic
The "enable" bit for this interface, enabling a request.
no setter
hashCode → int
The hash code for this object.
no setterinherited
ports → Map<String, Logic>
Maps from the Interface's defined port name to an instance of a Logic.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

clone() → DataPortInterface<LogicType>
Makes a copy of this Interface with matching configuration.
override
conditionalDriveOther(Interface<DataPortGroup> other, Iterable<DataPortGroup> tags) → Conditional
Makes this conditionally drive interface signals tagged with tags on other.
inherited
conditionalReceiveOther(Interface<DataPortGroup> other, Iterable<DataPortGroup> tags) → Conditional
Makes this signals tagged with tags be driven conditionally by other.
inherited
connectIO(Module module, Interface srcInterface, {Iterable<DataPortGroup>? inputTags, Iterable<DataPortGroup>? outputTags, Iterable<DataPortGroup>? inOutTags, String uniquify(String original)?}) → void
Connects module's inputs, outputs, and inOuts up to srcInterface and this Interface.
override
driveOther(Interface<DataPortGroup> other, Iterable<DataPortGroup> tags) → void
Makes this drive interface signals tagged with tags on other.
inherited
getPorts([Iterable<DataPortGroup>? tags]) → Map<String, Logic>
Returns all interface ports associated with the provided tags as a Map from the port name to the Logic port.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
port(String name) → Logic
Accesses a port named name.
inherited
receiveOther(Interface<DataPortGroup> other, Iterable<DataPortGroup> tags) → void
Makes this signals tagged with tags be driven by other.
inherited
setPorts(List<Logic> ports, [Iterable<DataPortGroup>? tags]) → void
Adds a collection of ports to this Interface, each associated with all of tags.
inherited
toString() → String
A string representation of this object.
inherited
tryPort(String name) → Logic?
Provides the port named name if it exists, otherwise null.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited