connectIO method
void
connectIO(})
Connects module
's inputs, outputs, and inOuts up to srcInterface
and
this Interface.
The srcInterface
should be an external instance of the Interface
passed in from outside the module
, and connectIO should be called on a
new instance of the Interface to be used by module
for all input and
output connectivity. For example:
MyMod(MyIntf srcIntf) {
srcIntf = MyIntf(args)..connectIO(this, srcIntf, inputTags: ... );
}
All signals in the interface with specified TagType
will be connected
to the Module via Module.addInput, Module.addOutput, or
Module.addInOut based on inputTags
, outputTags
, and inOutTags
,
respectively. uniquify
can be used to uniquifiy port names by
manipulating the original name of the port.
If inputTags
, outputTags
, or inOutTags
is not specified, then,
respectively, no inputs, outputs, or inOuts will be added.
Implementation
void connectIO(Module module, Interface<dynamic> srcInterface,
{Iterable<TagType>? inputTags,
Iterable<TagType>? outputTags,
Iterable<TagType>? inOutTags,
String Function(String original)? uniquify}) {
uniquify ??= (original) => original;
if (inputTags != null) {
for (final port in getPorts(inputTags).values) {
port <=
(port is LogicArray
? module.addInputArray(
uniquify(port.name),
srcInterface.port(port.name),
dimensions: port.dimensions,
elementWidth: port.elementWidth,
numUnpackedDimensions: port.numUnpackedDimensions,
)
: module.addInput(
uniquify(port.name),
srcInterface.port(port.name),
width: port.width,
));
}
}
if (outputTags != null) {
for (final port in getPorts(outputTags).values) {
final output = (port is LogicArray
? module.addOutputArray(
uniquify(port.name),
dimensions: port.dimensions,
elementWidth: port.elementWidth,
numUnpackedDimensions: port.numUnpackedDimensions,
)
: module.addOutput(
uniquify(port.name),
width: port.width,
));
output <= port;
srcInterface.port(port.name) <= output;
}
}
if (inOutTags != null) {
for (final port in getPorts(inOutTags).values) {
if (port is LogicArray) {
if (!port.isNet) {
throw PortTypeException(
port, 'LogicArray nets must be used for inOut array ports.');
}
} else if (port is! LogicNet) {
throw PortTypeException(
port, 'LogicNet must be used for inOut ports.');
}
port <=
(port is LogicArray
? module.addInOutArray(
uniquify(port.name),
srcInterface.port(port.name),
dimensions: port.dimensions,
elementWidth: port.elementWidth,
numUnpackedDimensions: port.numUnpackedDimensions,
)
: module.addInOut(
uniquify(port.name),
srcInterface.port(port.name),
width: port.width,
));
}
}
}