MultiPoolCreditToReadyValidAdapter<LogicType extends Logic> constructor
- required Logic clk,
- required Logic reset,
- required MultiPoolCreditInterface<
LogicType> upstream, - required List<
ReadyValidInterface< downstreams,LogicType> > - required int depthPerPool,
- List<
int> ? poolDepths, - String name = 'multi_pool_credit_to_ready_valid_adapter',
Creates a multi-pool buffered credit adapter.
Implementation
MultiPoolCreditToReadyValidAdapter(
{required Logic clk,
required Logic reset,
required MultiPoolCreditInterface<LogicType> upstream,
required List<ReadyValidInterface<LogicType>> downstreams,
required this.depthPerPool,
List<int>? poolDepths,
String name = 'multi_pool_credit_to_ready_valid_adapter'})
: poolCount = downstreams.length,
poolDepths = List.unmodifiable(
poolDepths ?? List.filled(downstreams.length, depthPerPool)),
super(
definitionName: 'MultiPoolCreditToReadyValidAdapter_N'
'${downstreams.length}_D'
'${poolDepths?.join('x') ?? depthPerPool}_'
'${upstream.data.name}_${payloadShapeIdentity(upstream.data)}_'
'${downstreams.map((port) {
final shape = payloadShapeIdentity(port.data);
return '${shape.length}_$shape';
}).join('_')}',
name: name) {
if (poolCount < 1) {
throw ArgumentError.value(
downstreams, 'downstreams', 'Must not be empty.');
}
if (depthPerPool < 1) {
throw ArgumentError.value(
depthPerPool, 'depthPerPool', 'Must be at least one.');
}
if (this.poolDepths.length != poolCount ||
this.poolDepths.any((depth) => depth < 1)) {
throw ArgumentError.value(poolDepths, 'poolDepths',
'Must provide one positive depth for each pool.');
}
if (upstream.poolCount != poolCount) {
throw ArgumentError(
'Upstream poolCount (${upstream.poolCount}) must match '
'downstreams length ($poolCount).');
}
if (downstreams.any((port) => !rohdPayloadsCompatible(
[upstream.data, port.data],
ignoreConstantNames: true))) {
throw ArgumentError('Adapter payload shapes must be compatible.');
}
final localClk = addInput('clk', clk);
final localReset = addInput('reset', reset);
addOutput('debit', width: poolCount);
addOutput('overflow', width: poolCount);
addOutput('invalidPool');
this.upstream = addPairInterface(
upstream,
PairRole.consumer,
uniquify: (original) => 'upstream_$original',
);
this.downstreams = UnmodifiableListView([
for (var pool = 0; pool < poolCount; pool++)
addPairInterfaceFrom(
IrrevocableReadyValidInterface<LogicType>(
downstreams[pool].data.cloneTyped()),
downstreams[pool],
PairRole.provider,
uniquify: (original) => 'downstream_${pool}_$original',
)
]);
final debitBits =
List.generate(poolCount, (pool) => Logic(name: 'debit_$pool'));
final overflowBits =
List.generate(poolCount, (pool) => Logic(name: 'overflow_$pool'));
final selectedPool = List.generate(
poolCount,
(pool) => this
.upstream
.pool
.eq(Const(pool, width: max(1, poolCount.log2Ceil)))
.named('${name}_selected_pool_$pool'));
final poolIsValid =
selectedPool.rconcat().or().named('${name}_pool_is_valid');
final creditReturnBits =
List.generate(poolCount, (pool) => Logic(name: 'credit_return_$pool'));
for (var pool = 0; pool < poolCount; pool++) {
final writeData = this.upstream.data.cloneTyped();
final writeEnable = Logic(name: '${name}_write_enable_$pool');
final readEnable = Logic(name: '${name}_read_enable_$pool');
final fifo = Fifo<LogicType>(localClk, localReset,
writeEnable: writeEnable,
readEnable: readEnable,
writeData: writeData,
depth: this.poolDepths[pool],
name: '${name}_fifo_$pool');
final downstreamAccepted = (this.downstreams[pool].ready & ~fifo.empty)
.named('${name}_downstream_accepted_$pool');
writeData <= this.upstream.data;
writeEnable <= this.upstream.valid & selectedPool[pool] & ~fifo.full;
readEnable <= downstreamAccepted;
this.downstreams[pool].valid <= ~fifo.empty;
this.downstreams[pool].data <= fifo.readData;
debitBits[pool] <= writeEnable;
overflowBits[pool] <=
this.upstream.valid & selectedPool[pool] & fifo.full;
creditReturnBits[pool] <= downstreamAccepted;
}
debit <= debitBits.rconcat();
overflow <= overflowBits.rconcat();
invalidPool <= this.upstream.valid & ~poolIsValid;
this.upstream.creditReturn <= creditReturnBits.rconcat();
}