CreditToReadyValidAdapter<LogicType extends Logic> constructor

CreditToReadyValidAdapter<LogicType extends Logic>({
  1. required Logic clk,
  2. required Logic reset,
  3. required CreditInterface<LogicType> upstream,
  4. required ReadyValidInterface<LogicType> downstream,
  5. required int depth,
  6. String name = 'credit_to_ready_valid_adapter',
})

Creates a buffered credit-to-ready-valid adapter.

Implementation

CreditToReadyValidAdapter({
  required Logic clk,
  required Logic reset,
  required CreditInterface<LogicType> upstream,
  required ReadyValidInterface<LogicType> downstream,
  required this.depth,
  String name = 'credit_to_ready_valid_adapter',
}) : super(
        definitionName: 'CreditToReadyValidAdapter_D$depth'
            '_${upstream.data.name}_${payloadShapeIdentity(upstream.data)}_'
            '${payloadShapeIdentity(downstream.data)}',
        name: name,
      ) {
  if (depth < 1) {
    throw ArgumentError.value(depth, 'depth', 'Must be at least one.');
  }
  if (!rohdPayloadsCompatible([upstream.data, downstream.data],
      ignoreConstantNames: true)) {
    throw ArgumentError('Adapter payload shapes must be compatible.');
  }
  downstream.requireConsumerComposableWith(
    ReadyValidContract.irrevocable,
    providerName: name,
  );

  this.clk = addInput('clk', clk);
  this.reset = addInput('reset', reset);
  addOutput('occupancy', width: (depth + 1).log2Ceil);
  addOutput('overflow');
  this.upstream = addPairInterface(
    upstream,
    PairRole.consumer,
    uniquify: (original) => 'upstream_$original',
  );
  this.downstream = addPairInterfaceFrom(
    IrrevocableReadyValidInterface<LogicType>(
      downstream.data.cloneTyped(),
    ),
    downstream,
    PairRole.provider,
    uniquify: (original) => 'downstream_$original',
  );

  final writeData = this.upstream.data.cloneTyped();
  final writeEnable = Logic(name: '${name}_write_enable');
  final readEnable = Logic(name: '${name}_read_enable');
  final core = FifoCoreFunctor<LogicType>(
    depth: depth,
    generateOccupancy: true,
  );
  final binding = core.construct(
    FifoCoreRequest<LogicType>(
      clk: this.clk,
      reset: this.reset,
      enqueue: writeEnable,
      dequeue: readEnable,
      payload: writeData,
    ),
    name: '${name}_fifo',
  );
  CreditIngressAttachmentPolicy<LogicType>(
    capacity: depth,
    allowUnspecifiedContract: true,
  ).attach(
    upstream: this.upstream,
    canAccept: binding.canEnqueue,
    slotReleased: binding.slotReleased,
    accept: writeEnable,
    payload: writeData,
    overflow: overflow,
    name: '$name upstream',
  );
  ReadyValidEgressAttachmentPolicy<LogicType>().attach(
    downstream: this.downstream,
    offerValid: binding.outputValid,
    payload: binding.output,
    transfer: readEnable,
  );
  occupancy <= binding.occupancy!;
}