MultiPoolCreditAsyncFifoBridge<LogicType extends Logic> constructor
- required Logic writeClk,
- required Logic readClk,
- required Logic writeReset,
- required Logic readReset,
- required MultiPoolCreditInterface<
LogicType> upstream, - required List<
ReadyValidInterface< downstreams,LogicType> > - required int depthPerPool,
- List<
int> ? poolDepths, - int? returnDepth,
- List<
int> ? returnDepths, - int syncStages = 2,
- String name = 'multi_pool_credit_async_fifo_bridge',
Creates an independent multi-pool credit CDC bridge.
Implementation
MultiPoolCreditAsyncFifoBridge(
{required Logic writeClk,
required Logic readClk,
required Logic writeReset,
required Logic readReset,
required MultiPoolCreditInterface<LogicType> upstream,
required List<ReadyValidInterface<LogicType>> downstreams,
required int depthPerPool,
List<int>? poolDepths,
int? returnDepth,
List<int>? returnDepths,
int syncStages = 2,
String name = 'multi_pool_credit_async_fifo_bridge'})
: poolCount = downstreams.length,
poolDepths =
poolDepths ?? List<int>.filled(downstreams.length, depthPerPool),
returnDepths = returnDepths ??
List<int>.filled(downstreams.length, returnDepth ?? depthPerPool),
super(
definitionName: _definitionName(
poolDepths,
returnDepths,
downstreams.length,
depthPerPool,
returnDepth,
syncStages,
upstream.data,
downstreams.map((port) => port.data)),
name: name) {
if (poolCount < 1) {
throw ArgumentError.value(
downstreams, 'downstreams', 'Must not be empty.');
}
if (upstream.poolCount != poolCount) {
throw ArgumentError('Upstream poolCount (${upstream.poolCount}) must '
'match downstream count ($poolCount).');
}
if (downstreams.any((port) => !rohdPayloadsCompatible(
[upstream.data, port.data],
ignoreConstantNames: true))) {
throw ArgumentError('CDC bridge payload shapes must be compatible.');
}
if (this.poolDepths.length != poolCount ||
this.returnDepths.length != poolCount) {
throw ArgumentError(
'Pool and return depths must have one entry per pool.');
}
for (final depth in [...this.poolDepths, ...this.returnDepths]) {
if (depth < 1) {
throw ArgumentError.value(
depth, 'depth', 'Async FIFO depths must be positive.');
}
}
final localWriteClk = addInput('writeClk', writeClk);
final localReadClk = addInput('readClk', readClk);
final localWriteReset = addInput('writeReset', writeReset);
final localReadReset = addInput('readReset', readReset);
addOutput('overflow');
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 selectedPool = List.generate(
poolCount,
(pool) => this
.upstream
.pool
.eq(Const(pool, width: this.upstream.pool.width))
.named('${name}_selected_pool_$pool'));
final poolIsValid =
selectedPool.rconcat().or().named('${name}_pool_is_valid');
final forwardFull = <Logic>[];
final returnBits = List<Logic>.generate(poolCount, (_) => Const(0));
for (var pool = 0; pool < poolCount; pool++) {
final forwardWrite = Logic(name: '${name}_forward_write_$pool');
final forwardRead = Logic(name: '${name}_forward_read_$pool');
final forward = AsyncFifo(
writeClk: localWriteClk,
readClk: localReadClk,
writeReset: localWriteReset,
readReset: localReadReset,
writeEnable: forwardWrite,
writeData: this.upstream.data,
readEnable: forwardRead,
depth: this.poolDepths[pool],
syncStages: syncStages,
name: '${name}_forward_$pool');
final returnWrite = Logic(name: '${name}_return_write_$pool');
final returnRead = Logic(name: '${name}_return_read_$pool');
final returns = AsyncFifo<Logic>(
writeClk: localReadClk,
readClk: localWriteClk,
writeReset: localReadReset,
readReset: localWriteReset,
writeEnable: returnWrite,
writeData: Const(1),
readEnable: returnRead,
depth: this.returnDepths[pool],
syncStages: syncStages,
name: '${name}_returns_$pool');
final downstreamAccepted =
(this.downstreams[pool].ready & ~forward.empty & ~returns.full)
.named('${name}_downstream_accepted_$pool');
forwardWrite <= this.upstream.valid & selectedPool[pool] & ~forward.full;
forwardRead <= downstreamAccepted;
returnWrite <= downstreamAccepted;
this.downstreams[pool].valid <= ~forward.empty & ~returns.full;
this.downstreams[pool].data <= forward.readData;
returnRead <= ~returns.empty;
returnBits[pool] = (~returns.empty).named('${name}_credit_return_$pool');
forwardFull.add(forward.full);
}
final selectedForwardFull = List.generate(
poolCount,
(pool) => (selectedPool[pool] & forwardFull[pool])
.named('${name}_selected_forward_full_$pool'))
.rconcat()
.or()
.named('${name}_selected_forward_full');
overflow <= this.upstream.valid & poolIsValid & selectedForwardFull;
invalidPool <= this.upstream.valid & ~poolIsValid;
this.upstream.creditReturn <= returnBits.rconcat();
}